Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
watplot.cc
Go to the documentation of this file.
1 #define WATPLOT_CC
2 #include <iostream>
3 #include <stdexcept>
4 #include <fstream>
5 #include "watplot.hh"
6 #include "WDM.hh"
7 #include "TSystem.h"
8 #include "TObjArray.h"
9 #include "TObjString.h"
10 #include "TPaletteAxis.h"
11 
12 ClassImp(watplot) // used by THtml doc
13 
14 
15 //______________________________________________________________________________
16 /* Begin_Html
17 <center><h2>watlpot class</h2></center>
18 The class watlpot is used to plot different objects types (wavearray, WSeries, skymap, netcluster, ...)
19 
20 <p>
21 <h3><a name="example">Example</a></h3>
22 <p>
23 The macro <a href="./tutorials/wat/testWDM_3.C.html">testWDM_3.C</a> is an example which shown how to plot wavearray object.<br>
24 <p>
25 
26 End_Html
27 
28 Begin_Macro
29 testWDM_3.C
30 End_Macro
31 
32 Begin_Html
33 The macro <a href="./tutorials/wat/testWDM_1.C.html">testWDM_1.C</a> is an example which shown how to plot WSeries object.<br>
34 <p>
35 
36 End_Html
37 
38 Begin_Macro
39 testWDM_1.C
40 End_Macro
41 
42 Begin_Html
43 The macro <a href="./tutorials/wat/DrawSkymapWithSkyplot.C.html">DrawSkymapWithSkyplot.C</a> is an example which shown how to plot skymap object.<br>
44 <p>
45 
46 End_Html
47 
48 Begin_Macro
49 DrawSkymapWithSkyplot.C
50 End_Macro
51 
52 Begin_Html
53 The macro <a href="./tutorials/wat/DrawClusterWithSkyplot.C.html">DrawClusterWithSkyplot.C</a> is an example which shown how to plot netcluster object.<br>
54 <p>
55 
56 End_Html
57 
58 Begin_Macro
59 DrawClusterWithSkyplot.C
60 End_Macro */
61 
62 
63 // ++++++++++++++++++++++++++++++++++++++++++++++
64 // S. Klimenko, University of Florida
65 // WAT plot class
66 // ++++++++++++++++++++++++++++++++++++++++++++++
67 
68 watplot::watplot(char* name, int i1, int i2, int i3, int i4) {
69 //
70 // Default constructor
71 //
72 // Input parameters are used to create a new canvas.
73 //
74 // i1,i2 are the pixel coordinates of the top left corner of
75 // the canvas (if i1 < 0) the menubar is not shown)
76 // i3 is the canvas size in pixels along X
77 // i4 is the canvas size in pixels along Y
78 //
79 // default values are : name=NULL, i1=200, i2=20, i3=800, i4=600
80 //
81 
82  this->title = "";
83  this->xtitle = "";
84  this->ytitle = "";
85  this->ncol = 0;
86  this->opt = "";
87  this->col = 1;
88  this->t1 = 0.;
89  this->t2 = 0.;
90  this->fft = false;
91  this->f1 = 0.;
92  this->f2 = 0.;
93  this->hist2D = NULL;
94 
95  char defn[16] = "watplot";
96  if (name && gROOT->FindObject(name)!=NULL) {
97  printf("watplot : Error Canvas Name %s already exist",name);
98  exit(1);
99  }
100 
101  null();
102  if(!name) name = defn;
103  canvas= new TCanvas(name, name, i1, i2, i3, i4);
104  canvas->Clear();
105  canvas->ToggleEventStatus();
106  canvas->SetGridx();
107  canvas->SetGridy();
108  canvas->SetFillColor(kWhite);
109  canvas->SetRightMargin(0.10);
110  canvas->SetLeftMargin(0.10);
111  canvas->SetBottomMargin(0.13);
112  canvas->SetBorderMode(0);
113 
114  // remove the red box around canvas
115  gStyle->SetFrameBorderMode(0);
116  gROOT->ForceStyle();
117 
118  gStyle->SetTitleH(0.050);
119  gStyle->SetTitleW(0.95);
120  gStyle->SetTitleY(0.98);
121  gStyle->SetTitleFont(12,"D");
122  gStyle->SetTitleColor(kBlue,"D");
123  gStyle->SetTextFont(12);
124  gStyle->SetTitleFillColor(kWhite);
125  gStyle->SetLineColor(kWhite);
126  gStyle->SetNumberContours(256);
127  gStyle->SetCanvasColor(kWhite);
128  gStyle->SetStatBorderSize(1);
129 
130 }
131 
132 void watplot::plot(wavearray<double> &td, char* opt, int col,
133  double t1, double t2, bool fft, float f1, float f2, bool psd, float t3, bool oneside) {
134 //
135 // Plot wavearray<double> time series
136 //
137 // td : wavearray time series
138 // opt : TGraph::Draw options
139 // col : set TGraph line color
140 // t1 : start of time interval in seconds
141 // t2 : end of time interval in seconds
142 // fft : true -> plot fft
143 // f1 : set begin frequency (Hz)
144 // f2 : set end frequency (Hz)
145 // psd : true -> plot psd using blackmanharris window
146 // t3 : is the chunk length (sec) used to produce the psd
147 // oneside : true/false -> oneside/doubleside
148 //
149 
150  if ( t2 < t1) {
151  printf(" Plot error: t2 must be greater then t1.\n");
152  return;
153  }
154  if ( f2 < f1) {
155  printf(" Plot error: f2 must be greater then f1.\n");
156  return;
157  }
158 
159  if(t2==0.) { t1 = td.start(); t2 = t1+td.size()/td.rate(); }
160 
161  double Ts = (td.rate() == 0)? 1.: 1./td.rate();
162  int i1 = int((t1-td.start())/Ts);
163  int i2 = (t2 == 0.)? td.size() : int((t2-td.start())/Ts);
164  //int nmax = i2-i1;
165  int nmax = (i2-i1)-(i2-i1)%2; // nmax even
166  wavearray<double> _x(nmax);
167  wavearray<double> _y(nmax);
168  double xmin, xmax;
169  double ymin, ymax;
170  xmin=0.;
171  xmax=(nmax-1)*Ts;
172  ymin=1.e40;
173  ymax=0.;
174  double x0 = i1*Ts+td.start();
175  TGraph* G;
176 
177  for (int i=0; i < nmax; i++) {
178  _x.data[i] = x0 + Ts*i - 0.;
179  _y.data[i] = td.data[i+i1];
180  if (ymin > _y.data[i]) ymin=_y.data[i];
181  if (ymax < _y.data[i]) ymax=_y.data[i];
182  }
183 
184  if(fft) {
185  if(f2==0.) { f1 = 0.; f2 = td.rate()/2.; }
186  if(psd) { // power spectrum density
187  t3 = t3<0. ? 0. : t3;
188  t3 = t3<(_y.size()/td.rate()) ? t3 : (_y.size()/td.rate());
189  int bsize = t3*td.rate();
190  bsize-=bsize%2;
191  int loops = int(_y.size()/bsize)==0 ? 1 : int(_y.size()/bsize);
192  double Fs=(double)td.rate()/(double)bsize;
193  wavearray<double> w(bsize);
194  wavearray<double> u(bsize);
195  wavearray<double> psd(bsize); psd=0;
196  blackmanharris(w);
197  for (int n=0;n<loops;n++) {
198  int shift=n*bsize;
199  //cout << "shift: " << shift << endl;
200  for (int i=0;i<bsize;i++) u[i]=_y[i+shift];
201  for (int i=0;i<bsize;i++) u[i]*=w[i];
202  u.FFTW(1);
203  for (int i=0;i<bsize;i+=2) psd[i/2]+=pow(u[i],2)+pow(u[i+1],2);
204  }
205  for (int i=0;i<bsize/2; i++) psd[i]=sqrt(psd[i]/(double)loops)*sqrt(1./Fs); // double side spectra 1/sqrt(Hz);
206  if(oneside) psd*=sqrt(2.); // one side spectra *sqrt(2);
207  _y=psd;nmax=bsize;
208  _x.resize(nmax);
209  for (int i=0;i<nmax/2;i++) _x.data[i]=i*Fs;
210  } else {
211  wavearray<double> _z(nmax);
212  double Fs=(double)td.rate()/(double)_y.size();
213  _y.FFTW(1);
214  for (int i=0;i<nmax;i+=2) _z.data[i/2]=sqrt(pow(_y.data[i],2)+pow(_y.data[i+1],2));
215  for (int i=0;i<nmax/2;i++) _y.data[i]=_z.data[i]*(1./Fs); // double side spectra 1/Hz
216  for (int i=0;i<nmax/2;i++) _x.data[i]=i*Fs;
217  if(oneside) for(int i=0;i<nmax/2;i++) _y.data[i]*=sqrt(2.); // one side spectra 1/Hz
218  }
219  nmax/=2;
220  ymin=1.e40;
221  ymax=0.;
222  for (int i=0;i<nmax;i++) {
223  if ((_x.data[i]>f1)&&(_x.data[i]<f2)) {
224  if (ymin > _y.data[i]) ymin=_y.data[i];
225  if (ymax < _y.data[i]) ymax=_y.data[i];
226  }
227  }
228  }
229 
230  G = new TGraph(nmax,_x.data,_y.data);
231  G->SetLineColor(col);
232  G->SetMarkerColor(col);
233 // G->Draw(opt);
234 // canvas->Update();
235  G->GetHistogram()->SetTitle("");
236  G->SetFillColor(kWhite);
237 
238  //G->GetXaxis()->SetNdivisions(70318);
239  G->GetXaxis()->SetTitleFont(42);
240  G->GetXaxis()->SetLabelFont(42);
241  G->GetXaxis()->SetLabelOffset(0.012);
242  G->GetXaxis()->SetTitleOffset(1.5);
243 
244  //G->GetYaxis()->SetNdivisions(508);
245  G->GetYaxis()->SetTitleFont(42);
246  G->GetYaxis()->SetLabelFont(42);
247  G->GetYaxis()->SetLabelOffset(0.01);
248  G->GetYaxis()->SetTitleOffset(1.4);
249 //
250  if(fft) {
251  G->GetHistogram()->GetXaxis()->SetRangeUser(f1,f2);
252  //G->GetHistogram()->GetYaxis()->SetRangeUser(ymin/2.,ymax*10.);
253  G->GetHistogram()->GetYaxis()->SetRangeUser(ymin/2.,ymax*1.1);
254  G->GetHistogram()->SetXTitle("freq, hz");
255  } else {
256  G->GetHistogram()->SetXTitle("time, s");
257  }
258  G->GetHistogram()->SetYTitle("magnitude");
259  G->Draw(opt);
260  graph.push_back(G);
261 // graph->Fit("fit","VMR");
262 
263  return;
264 }
265 
266 void watplot::plsmooth(WSeries<double> &w, int sfact, double t1, double t2, char* opt, int pal, int palId)
267 {
268 
269  t1 = t1==0. ? w.start() : t1;
270  t2 = t2==0. ? w.start()+w.size()/w.rate() : t2;
271 
272  int ni = 1<<w.pWavelet->m_Level;
273  int nb = int((t1-w.start())*w.rate()/ni);
274  int nj = int((t2-t1)*w.rate())/ni;
275  int ne = nb+nj;
276  double rate=w.rate();
277  double freq=rate/2/ni;
278  rate = rate/ni;
279 
280  double** iw = new double*[nj];
281  for(int j=0;j<nj;j++) iw[j] = new double[ni];
282 
283 // double wmax=0.;
285  for(int i=0;i<ni;i++) {
286  w.getLayer(wl,i);
287 // for(int j=nb;j<ne;j++) iw[j-nb][i] = fabs(wl.data[j]);
288 
289  for(int j=nb;j<ne;j++) {
290 //printf("DEB14 %d %d,%d,%d %d\n",j,j-nb,i,nj,wl.size());
291  iw[j-nb][i] = wl.data[j]*wl.data[j];
292 // if(wmax<iw[j-nb][i]) wmax=iw[j-nb][i];
293  }
294 
295  }
296 
297  int smfact=1;
298  for(int n=0;n<sfact;n++) smfact*=3;
299  double** sw = NULL;
300  int sni=ni;
301  int snj=nj;
302 
303  if(sfact==0) {
304  sw = new double*[snj];
305  for(int j=0;j<snj;j++) sw[j] = new double[sni];
306  for(int i=0;i<sni;i++) {
307  for(int j=0;j<snj;j++) {
308  sw[j][i] = iw[j][i];
309  }
310  }
311  }
312 
313  for(int n=1;n<=sfact;n++) {
314  if(sw!=NULL) {
315  for(int j=0;j<snj;j++) delete [] sw[j];
316  delete [] sw;
317  }
318  sni*=3;
319  snj*=3;
320  sw = new double*[snj];
321  for(int j=0;j<snj;j++) sw[j] = new double[sni];
322  for(int i=0;i<sni;i++) for(int j=0;j<snj;j++) sw[j][i] = 0.;
323  for(int i=1;i<sni-1;i++) {
324  for(int j=1;j<snj-1;j++) {
325  for(int j3=j-1;j3<=j+1;j3++) {
326  for(int i3=i-1;i3<=i+1;i3++) {
327 //printf("%d %d %d %d\n",i,j,i3/3,j3/3);
328  sw[j][i] += iw[(j3-j3%3)/3][(i3-i3%3)/3];
329  }
330  }
331  sw[j][i]/=9.;
332  }
333  }
334  for(int j=0;j<nj;j++) delete [] iw[j];
335  delete [] iw;
336  iw = new double*[snj];
337  for(int j=0;j<snj;j++) iw[j] = new double[sni];
338  for(int i=0;i<sni;i++) {
339  for(int j=0;j<snj;j++) {
340  iw[j][i] = sw[j][i];
341  }
342  }
343  }
344 
345  for(int j=0;j<snj;j++) delete [] iw[j];
346  delete [] iw;
347 
348  if(hist2D) { delete hist2D; hist2D=NULL; }
349  //hist2D=new TH2F("WTF","", snj, t1-w.start(), t2-w.start(), sni, 0., freq*ni);
350  hist2D=new TH2F("WTF","", snj, 0., t2-t1, sni, 0., freq*ni);
351  hist2D->SetXTitle("time, sec");
352  hist2D->SetYTitle("frequency, Hz");
353 
354  Int_t colors[30]={101,12,114,13,115,14,117,15,16,17,166,18,19,
355  167,0,0,167,19,18,166,17,16,15,117,14,115,13,114,12,101};
356  if(pal==0) gStyle->SetPalette(30,colors);
357  else if(pal<0) {SetPlotStyle(palId,pal);}
358  else {gStyle->SetPalette(1,0);gStyle->SetNumberContours(pal);}
359 /*
360  double swmax=0.;
361  for(int i=0;i<sni;i++) {
362  for(int j=0;j<snj;j++) {
363  if(swmax<sw[j][i]) swmax=sw[j][i];
364  }
365  }
366 */
367 
368  int snb=smfact*nb;
369  int sne=smfact*ne;
370  double srate=smfact*rate;
371  double sfreq=freq/smfact;
372  for(int i=0;i<sni;i++) {
373  for(int j=snb;j<sne;j++) {
374  double x = sw[j-snb][i];
375  //double x = sw[j-snb][i]*wmax/swmax;
376  //double x = sqrt(sw[j-snb][i]);
377  //double x = sqrt(sw[j-snb][i]*wmax/swmax);
378  //hist2D->Fill(double(j)/srate,(i+0.5)*sfreq,x);
379  hist2D->Fill(double(j-snb)/srate,(i+0.5)*sfreq,x);
380  }
381  }
382 
383  for(int j=0;j<snj;j++) delete [] sw[j];
384  delete [] sw;
385 
386  hist2D->SetStats(kFALSE);
387  hist2D->SetFillColor(kWhite);
388  hist2D->GetXaxis()->SetTitleFont(42);
389  hist2D->GetXaxis()->SetLabelFont(42);
390  hist2D->GetXaxis()->SetLabelOffset(0.012);
391  hist2D->GetXaxis()->SetTitleOffset(1.1);
392  hist2D->GetYaxis()->SetTitleFont(42);
393  hist2D->GetYaxis()->SetLabelFont(42);
394  hist2D->GetYaxis()->SetLabelOffset(0.01);
395  hist2D->GetZaxis()->SetLabelFont(42);
396  hist2D->SetTitleOffset(1.3,"Y");
397  if(opt) hist2D->Draw(opt);
398  else hist2D->Draw("COLZ");
399 
400  // change palette's width
401  canvas->Update();
402  TPaletteAxis *palette = (TPaletteAxis*)hist2D->GetListOfFunctions()->FindObject("palette");
403  palette->SetX1NDC(0.91);
404  palette->SetX2NDC(0.933);
405  palette->SetTitleOffset(0.92);
406  palette->GetAxis()->SetTickSize(0.01);
407  canvas->Modified();
408 
409  return;
410 }
411 
412 
413 double watplot::getmax(WSeries<double> &w, double t1, double t2)
414 {
415 //
416 // return max value of WSeries w object
417 //
418 // t1 : start of time interval in seconds
419 // t2 : end of time interval in seconds
420 //
421 
422  float x;
423 
424  t1 = t1==0. ? w.start() : t1;
425  t2 = t2==0. ? w.start()+w.size()/w.rate() : t2;
426 
427  int ni = 1<<w.pWavelet->m_Level;
428  int nb = int((t1-w.start())*w.rate()/ni);
429  int nj = int((t2-t1)*w.rate())/ni;
430  int ne = nb+nj;
431  double rate=w.rate();
432  rate = rate/ni;
433 
435  double xmax;
436 
437  for(int i=0;i<ni;i++) {
438  w.getLayer(wl,i);
439  for(int j=nb;j<ne;j++) {
440  x=fabs(wl.data[j]);
441  if(x>xmax) xmax=x;
442  }
443  }
444  return xmax;
445 }
446 
447 void watplot::plot(WSeries<double> &w, int mode, double t1, double t2, char* opt, int pal, int palId)
448 {
449 //
450 // Plot TF series
451 //
452 // w : WSeries<double> object
453 // mode : plot type
454 // if WSeries is WDM
455 // 0 : sqrt((E00+E90)/2)
456 // 1 : (E00+E90)/2
457 // 2 : sqrt((E00+E90)/2)
458 // 3 : amplitude:00
459 // 4 : energy:00
460 // 5 : |amplitude:00|
461 // 6 : amplitude:90
462 // 7 : energy:90
463 // 8 : |amplitude:90|
464 // if WSeries is wavelet
465 // 0 : amplitude
466 // 1 : energy
467 // 2 : |amplitude|
468 //
469 // t1 : start of time interval in seconds
470 // t2 : end of time interval in seconds
471 // opt : root draw options
472 // pal : palette
473 //
474 
475  t1 = t1==0. ? w.start() : t1;
476  t2 = t2==0. ? w.start()+w.size()/w.rate() : t2;
477 
478  if(t2 <= t1) {
479  printf("watplot::plot error: t2 must be greater then t1.\n");
480  exit(1);
481  }
482  if((t1 < w.start()) || (t1 > w.start()+w.size()/w.rate())) {
483  printf("watplot::plot error: t1 must be in this range [%0.12g,%0.12g]\n",
484  w.start(),w.start()+w.size()/w.rate());
485  exit(1);
486  }
487  if((t2 < w.start()) || (t2 > w.start()+w.size()/w.rate())) {
488  printf("watplot::plot error: t2 must be in this range [%0.12g,%0.12g]\n",
489  w.start(),w.start()+w.size()/w.rate());
490  exit(1);
491  }
492 
493  float x;
494  TString ztitle("");
495 
496  if(w.isWDM()) {
497 
498  double A00=1;
499  double A90=1;
500 
501  if(mode==0) mode=2;
502  if(mode==1) {ztitle="(E00+E90)/2";}
503  if(mode==2) {ztitle="sqrt((E00+E90)/2)";}
504 
505  if(mode==3) {ztitle="amplitude:00";A90=0;}
506  if(mode==4) {ztitle="energy:00";A00=sqrt(2.);A90=0;}
507  if(mode==5) {ztitle="|amplitude:00|";A90=0;}
508 
509  if(mode==6) {ztitle="amplitude:90";A00=0;}
510  if(mode==7) {ztitle="energy:90";A00=0;A90=sqrt(2.);}
511  if(mode==8) {ztitle="|amplitude:90|";A00=0;}
512 
513  mode*=-1;
514 
516  int M = w.getLevel();
517  double* map00 = wdm->pWWS;
518  double tsRate = w.rate();
519  int mF = int(w.size()/wdm->nSTS);
520  int nTC = w.size()/(M+1)/mF; // # of Time Coefficients
521  double* map90 = map00 + (mF-1)*(M+1)*nTC;
522 
523  //printf("nTC = %d, rate = %d M = %d\n", nTC, (int)w.rate(), M);
524 
525  // make Y bins:
526  double* yBins = new double[M+2];
527  double dF = tsRate/M/2.;
528  yBins[0] = 0;
529  yBins[1] = dF/2;
530  for(int i=2; i<=M; ++i) yBins[i] = yBins[1] + (i-1)*dF;
531  yBins[M+1] = tsRate/2.;
532 
533  const double scale = 1./w.wrate();
534  if(hist2D) { delete hist2D; hist2D=NULL; }
535  hist2D=new TH2F("WTF", "", 2*nTC, 0., nTC*scale, M+1, yBins);
536  hist2D->SetXTitle("time, sec");
537  hist2D->SetYTitle("frequency, Hz");
538  hist2D->GetXaxis()->SetRangeUser(t1-w.start(),t2-w.start());
539 
540  double v;
541  int it1 = (t1-w.start())/scale + 1;
542  int it2 = (t2-w.start())/scale + 1;
543  if(it2<=it1 || it2>nTC)it2 = nTC;
544 
545  map00+=it1*(M+1); map90+=it1*(M+1);
546  for(int i=it1; i<it2; ++i){
547  if(i){
548  v = procOpt(mode%3, A00*map00[0], A90*map90[0]); //first half-band
549  hist2D->SetBinContent( 2*i , 1, v);
550  hist2D->SetBinContent( 2*i+1 , 1, v);
551 
552  v = procOpt(mode%3, A00*map00[M], A90*map90[M]); //last half-band
553  hist2D->SetBinContent( 2*i , M+1, v);
554  hist2D->SetBinContent( 2*i+1 , M+1, v);
555  }
556  for(int j=1; j<M; ++j){
557  v = procOpt(mode%3, A00*map00[j], A90*map90[j]);
558  hist2D->SetBinContent( 2*i , j+1, v);
559  hist2D->SetBinContent( 2*i+1 , j+1, v);
560  }
561  map00+=M+1; map90+=M+1;
562  }
563 
564  delete [] yBins;
565 
566  } else {
567 
568  if(mode==0) ztitle="amplitude";
569  if(mode==1) ztitle="energy";
570  if(mode==2) ztitle="|amplitude|";
571 
572  int ni = 1<<w.pWavelet->m_Level;
573  int nb = int((t1-w.start())*w.rate()/ni);
574  int nj = int((t2-t1)*w.rate())/ni;
575  int ne = nb+nj;
576  double rate=w.rate();
577  double freq=rate/2/ni;
578  rate = rate/ni;
579 
580 // cout<<rate<<endl;
581 
582  if(hist2D) { delete hist2D; hist2D=NULL; }
583  hist2D=new TH2F("WTF","", nj, t1-w.start(), t2-w.start(), ni, 0., freq*ni);
584  hist2D->SetXTitle("time, sec");
585  hist2D->SetYTitle("frequency, Hz");
586 
587  Int_t colors[30]={101,12,114,13,115,14,117,15,16,17,166,18,19,
588  167,0,0,167,19,18,166,17,16,15,117,14,115,13,114,12,101};
589  if(pal==0) gStyle->SetPalette(30,colors);
590  else if(pal<0) {SetPlotStyle(palId,pal);}
591  else {gStyle->SetPalette(1,0);gStyle->SetNumberContours(pal);}
592 
594  double avr,rms;
595 
596  if(mode==0)
597  for(int i=0;i<ni;i++) {
598  w.getLayer(wl,i);
599  for(int j=nb;j<=ne;j++) {
600  x=wl.data[j];
601  hist2D->Fill((j+0.5)/rate,(i+0.5)*freq,x);
602  }
603  }
604 
605  if(mode==1)
606  for(int i=0;i<ni;i++) {
607  w.getLayer(wl,i);
608  for(int j=nb;j<=ne;j++) {
609  x=wl.data[j]*wl.data[j];
610  hist2D->Fill((j+0.5)/rate,(i+0.5)*freq,x);
611  }
612  }
613 
614  if(mode==2)
615  for(int i=0;i<ni;i++) {
616  w.getLayer(wl,i);
617  for(int j=nb;j<=ne;j++) {
618  x = fabs(wl.data[j]);
619  hist2D->Fill((j+0.5)/rate,(i+0.5)*freq,x);
620  }
621  }
622 
623  if(mode==4)
624  for(int i=0;i<ni;i++) {
625  w.getLayer(wl,i);
626  for(int j=nb;j<=ne;j++) {
627  x=(wl.data[j] > 0.) ? 1. : -1.;
628  hist2D->Fill((j+0.5)/rate,(i+0.5)*freq,x);
629  }
630  }
631 
632  if(mode==5)
633  for(int i=0;i<ni;i++) {
634  w.getLayer(wl,i);
635  for(int j=nb;j<=ne;j++) {
636  x=(wl.data[j] > 0.) ? 1. : -1.;
637  if(wl.data[j] == 0.) x=0.;
638  hist2D->Fill((j+0.5)/rate,(i+0.5)*freq,x);
639  }
640  }
641 
642  double sum = 0.;
643  int nsum = 0;
644 
645  if(mode==3){
646  for(int i=0;i<ni;i++) {
647  w.getLayer(wl,i);
648  wl.getStatistics(avr,rms);
649  for(int j=nb;j<ne-0;j++) {
650  x=(wl.data[j]-avr)/rms;
651  x*=x;
652  if(x>1){ sum += x; nsum++; }
653  hist2D->Fill(j/rate,(i+0.5)*freq,x);
654  }
655  }
656  }
657  }
658 
659  hist2D->SetStats(kFALSE);
660  hist2D->SetTitleFont(12);
661  hist2D->SetFillColor(kWhite);
662 
663  char title[256];
664  sprintf(title,"Scalogram (%s)",ztitle.Data());
665  hist2D->SetTitle(title);
666 
667  hist2D->GetXaxis()->SetNdivisions(506);
668  hist2D->GetXaxis()->SetLabelFont(42);
669  hist2D->GetXaxis()->SetLabelOffset(0.014);
670  hist2D->GetXaxis()->SetTitleOffset(1.4);
671  hist2D->GetYaxis()->SetTitleOffset(1.2);
672  hist2D->GetYaxis()->SetNdivisions(506);
673  hist2D->GetYaxis()->SetLabelFont(42);
674  hist2D->GetYaxis()->SetLabelOffset(0.01);
675  hist2D->GetZaxis()->SetLabelFont(42);
676  hist2D->GetZaxis()->SetNoExponent(false);
677  hist2D->GetZaxis()->SetNdivisions(506);
678 
679  hist2D->GetXaxis()->SetTitleFont(42);
680  hist2D->GetXaxis()->SetTitle("Time (sec)");
681  hist2D->GetXaxis()->CenterTitle(true);
682  hist2D->GetYaxis()->SetTitleFont(42);
683  hist2D->GetYaxis()->SetTitle("Frequency (Hz)");
684  hist2D->GetYaxis()->CenterTitle(true);
685 
686  hist2D->GetZaxis()->SetTitleOffset(0.6);
687  hist2D->GetZaxis()->SetTitleFont(42);
688  //hist2D->GetZaxis()->SetTitle(ztitle);
689  hist2D->GetZaxis()->CenterTitle(true);
690 
691  hist2D->GetXaxis()->SetLabelSize(0.03);
692  hist2D->GetYaxis()->SetLabelSize(0.03);
693  hist2D->GetZaxis()->SetLabelSize(0.03);
694 
695 
696  if(opt) hist2D->Draw(opt);
697  else hist2D->Draw("COLZ");
698 
699  // change palette's width
700  canvas->Update();
701  TPaletteAxis *palette = (TPaletteAxis*)hist2D->GetListOfFunctions()->FindObject("palette");
702  palette->SetX1NDC(0.91);
703  palette->SetX2NDC(0.933);
704  palette->SetTitleOffset(0.92);
705  palette->GetAxis()->SetTickSize(0.01);
706  canvas->Modified();
707 
708  return;
709 }
710 
711 void watplot::plot(skymap &sm, char* opt, int pal) {
712 //
713 // Draw skymap
714 //
715 // sm : skymap object
716 // opt : root draw options
717 // pal : palette
718 //
719 
720  int ni = sm.size(0); // number of theta layers
721  int nj = 0; // number of phi collumns
722 
723  for(int i=1; i<=ni; i++) if(nj<int(sm.size(i))) nj = sm.size(i);
724 
725  double t1 = sm.theta_1;
726  double t2 = sm.theta_2;
727  double p1 = sm.phi_1;
728  double p2 = sm.phi_2;
729  double dt = ni>1 ? (t2-t1)/(ni-1) : 0.;
730  double dp = nj>0 ? (p2-p1)/nj : 0.;
731 
732  if(hist2D) { delete hist2D; hist2D=NULL; }
733  hist2D=new TH2F("WTS","", nj,p1,p2, ni,90.-t2,90.-t1);
734  hist2D->SetXTitle("phi, deg.");
735  hist2D->SetYTitle("theta, deg.");
736 
737  Int_t colors[30]={101,12,114,13,115,14,117,15,16,17,166,18,19,
738  167,0,0,167,19,18,166,17,16,15,117,14,115,13,114,12,101};
739  if(pal==0) gStyle->SetPalette(30,colors);
740  else {gStyle->SetPalette(1,0);gStyle->SetNumberContours(pal);}
741 
743  double theta, phi;
744 
745  for(int i=0; i<ni; i++) {
746  theta = (t2+t1)/2.+(i-ni/2)*dt;
747  for(int j=0; j<nj; j++) {
748  phi = (p2+p1)/2.+(j-nj/2)*dp;
749  hist2D->Fill(phi,90.-theta,sm.get(theta,phi));
750  }
751  }
752 
753  hist2D->SetStats(kFALSE);
754  hist2D->SetFillColor(kWhite);
755 
756  //hist2D->GetXaxis()->SetNdivisions(70318);
757  hist2D->GetXaxis()->SetTitleFont(42);
758  hist2D->GetXaxis()->SetLabelFont(42);
759  hist2D->GetXaxis()->SetLabelOffset(0.012);
760  hist2D->GetXaxis()->SetTitleOffset(1.1);
761 
762  //hist2D->GetYaxis()->SetNdivisions(508);
763  hist2D->GetYaxis()->SetTitleFont(42);
764  hist2D->GetYaxis()->SetLabelFont(42);
765  hist2D->GetYaxis()->SetLabelOffset(0.01);
766 
767  hist2D->GetZaxis()->SetLabelFont(42);
768 //
769  if(opt) hist2D->Draw(opt);
770  else hist2D->Draw("COLZ");
771 
772  // change palette's width
773  canvas->Update();
774  TPaletteAxis *palette = (TPaletteAxis*)hist2D->GetListOfFunctions()->FindObject("palette");
775  palette->SetX1NDC(0.91);
776  palette->SetX2NDC(0.933);
777  palette->SetTitleOffset(0.92);
778  palette->GetAxis()->SetTickSize(0.01);
779  canvas->Modified();
780 
781  return;
782 }
783 
784 void watplot::plot(netcluster* pwc, int cid, int nifo, char type, int irate, char* opt, int pal, bool wp) {
785 //
786 // monster event display (only for 2G analysis)
787 // display pixels of all resolution levels
788 //
789 // pwc : pointer to netcluster object
790 // cid : cluster id
791 // nifo : number of detectors
792 // type : 'L' -> plot event likelihood pixels, 'N' -> plot event null pixels
793 // irate : select pixel rate
794 // 0 : all rates
795 // 1 : optimal rate
796 // x : rate x
797 // opt : root draw options
798 // pal : palette
799 // wp : true -> wavelet packet
800 //
801 
802  bool isPCs = std::isupper(type); // are Principal Components ?
803  type = std::toupper(type);
804 
805  if(type != 'L' && type != 'N') return;
806 
807  double RATE = pwc->rate; // original rate
808 
809  std::vector<int>* vint = &(pwc->cList[cid-1]); // pixel list
810 
811  int V = vint->size(); // cluster size
812  if(!V) return;
813 
814  // check if WDM (2G), else exit
815  netpixel* pix = pwc->getPixel(cid,0);
816  int mp= size_t(pwc->rate/pix->rate+0.1);
817  int mm= pix->layers; // number of wavelet layers
818  if(mm==mp) { // wavelet
819  cout << "watplot::plot - Error : monster event display is enabled only for WDM (2G)" << endl;
820  exit(1);
821  }
822 
823  bool optrate=false;
824  if(irate==1) { // extract optimal rate
825  optrate=true;
826  vector_int* pv = pwc->cRate.size() ? &(pwc->cRate[cid-1]) : NULL;
827  irate = pv!=NULL ? (*pv)[0] : 0;
828  }
829 
830  int minLayers=1000;
831  int maxLayers=0;
832  double minTime=1e20;
833  double maxTime=0.;
834  double minFreq=1e20;
835  double maxFreq=0.;
836  for(int j=0; j<V; j++) { // loop over the pixels
837  netpixel* pix = pwc->getPixel(cid,j);
838  if(!pix->core) continue;
839 
840  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
841 
842  if(pix->layers<minLayers) minLayers=pix->layers;
843  if(pix->layers>maxLayers) maxLayers=pix->layers;
844 
845  double dt = 1./pix->rate;
846  double time = int(pix->time/pix->layers)/double(pix->rate); // central bin time
847  time -= dt/2.; // begin bin time
848  if(time<minTime) minTime=time;
849  if(time+dt>maxTime) maxTime=time+dt;
850 
851  double freq = pix->frequency*pix->rate/2.;
852  if(freq<minFreq) minFreq=freq;
853  if(freq>maxFreq) maxFreq=freq;
854  }
855 
856  int minRate=RATE/(maxLayers-1);
857  int maxRate=RATE/(minLayers-1);
858 
859  double mindt = 1./maxRate;
860  double maxdt = 1./minRate;
861  double mindf = minRate/2.;
862  double maxdf = maxRate/2.;
863 
864  //cout << "minRate : " << minRate << "\t\t\t maxRate : " << maxRate << endl;
865  //cout << "minTime : " << minTime << "\t\t\t maxTime : " << maxTime << endl;
866  //cout << "minFreq : " << minFreq << "\t\t\t maxFreq : " << maxFreq << endl;
867  //cout << "mindt : " << mindt << "\t\t\t maxdt : " << maxdt << endl;
868  //cout << "mindf : " << mindf << "\t\t\t maxdf : " << maxdf << endl;
869 
870  double iminTime = minTime-maxdt;
871  double imaxTime = maxTime+maxdt;
872  int nTime = (imaxTime-iminTime)*maxRate;
873 
874  if(hist2D) { delete hist2D; hist2D=NULL; }
875  hist2D=new TH2F("WTF", "WTF", nTime, iminTime, imaxTime, 2*(maxLayers-1), 0, RATE/2);
876  hist2D->SetXTitle("time, sec");
877  hist2D->SetYTitle("frequency, Hz");
878 
879  Int_t colors[30]={101,12,114,13,115,14,117,15,16,17,166,18,19,
880  167,0,0,167,19,18,166,17,16,15,117,14,115,13,114,12,101};
881  if(pal==0) gStyle->SetPalette(30,colors);
882  else {gStyle->SetPalette(1,0);gStyle->SetNumberContours(pal);}
883 
884  hist2D->SetStats(kFALSE);
885  hist2D->SetTitleFont(12);
886  hist2D->SetFillColor(kWhite);
887 
888  hist2D->GetXaxis()->SetNdivisions(506);
889  hist2D->GetXaxis()->SetLabelFont(42);
890  hist2D->GetXaxis()->SetLabelOffset(0.014);
891  hist2D->GetXaxis()->SetTitleOffset(1.4);
892  hist2D->GetYaxis()->SetTitleOffset(1.2);
893  hist2D->GetYaxis()->SetNdivisions(506);
894  hist2D->GetYaxis()->SetLabelFont(42);
895  hist2D->GetYaxis()->SetLabelOffset(0.01);
896  hist2D->GetZaxis()->SetLabelFont(42);
897  hist2D->GetZaxis()->SetNoExponent(false);
898  hist2D->GetZaxis()->SetNdivisions(506);
899 
900  hist2D->GetXaxis()->SetTitleFont(42);
901  hist2D->GetXaxis()->SetTitle("Time (sec)");
902  hist2D->GetXaxis()->CenterTitle(true);
903  hist2D->GetYaxis()->SetTitleFont(42);
904  hist2D->GetYaxis()->SetTitle("Frequency (Hz)");
905  hist2D->GetYaxis()->CenterTitle(true);
906 
907  hist2D->GetZaxis()->SetTitleOffset(0.6);
908  hist2D->GetZaxis()->SetTitleFont(42);
909  hist2D->GetZaxis()->CenterTitle(true);
910 
911  hist2D->GetXaxis()->SetLabelSize(0.03);
912  hist2D->GetYaxis()->SetLabelSize(0.03);
913  hist2D->GetZaxis()->SetLabelSize(0.03);
914 
915  double dFreq = (maxFreq-minFreq)/10.>2*maxdf ? (maxFreq-minFreq)/10. : 2*maxdf ;
916  double mFreq = minFreq-dFreq<0 ? 0 : minFreq-dFreq;
917  double MFreq = maxFreq+dFreq>RATE/2 ? RATE/2 : maxFreq+dFreq;
918  hist2D->GetYaxis()->SetRangeUser(mFreq, MFreq);
919 
920  double dTime = (maxTime-minTime)/10.>2*maxdt ? (maxTime-minTime)/10. : 2*maxdt ;
921  double mTime = minTime-dTime<iminTime ? iminTime : minTime-dTime;
922  double MTime = maxTime+dTime>imaxTime ? imaxTime : maxTime+dTime;
923  hist2D->GetXaxis()->SetRangeUser(mTime,MTime);
924 
925  int npix=0;
926  double Null=0;
927  double Likelihood=0;
928  for(int n=0; n<V; n++) {
929  netpixel* pix = pwc->getPixel(cid,n);
930  if(!pix->core) continue;
931 
932  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
933 
934  double like=0;
935  double null=0;
936  if(wp) { // likelihoodWP
937  like = pix->likelihood>0. ? pix->likelihood : 0.;
938  null = pix->null>0. ? pix->null : 0.;
939  } else { // likelihood2G
940  double sSNR=0;
941  double wSNR=0;
942  for(int m=0; m<nifo; m++) {
943  sSNR += pow(pix->getdata('S',m),2); // snr whitened reconstructed signal 00
944  sSNR += pow(pix->getdata('P',m),2); // snr whitened reconstructed signal 90
945  wSNR += pow(pix->getdata('W',m),2); // snr whitened at the detector 00
946  wSNR += pow(pix->getdata('U',m),2); // snr whitened at the detector 90
947  }
948  if(!isPCs) {sSNR/=2;wSNR/=2;} // if not principal components we use (00+90)/2
949  like = sSNR;
950  null = wSNR-sSNR;
951  }
952 
953  int iRATE = int(pix->rate+0.5);
954  int M=maxRate/iRATE;
955  int K=2*(maxLayers-1)/(pix->layers-1);
956  double dt = 1./pix->rate;
957  double itime = int(pix->time/pix->layers)/double(pix->rate); // central bin time
958  itime -= dt/2.; // begin bin time
959  int i=(itime-iminTime)*maxRate;
960  int j=pix->frequency*K;
961  if(iRATE!=irate && irate!=0) continue;
962  Null+=null;
963  Likelihood+=like;
964  int L=0;int R=1;while (R < iRATE) {R*=2;L++;}
965  for(int m=0;m<M;m++) {
966  for(int k=0;k<K;k++) {
967  if(null<0) null=0;
968  double A = hist2D->GetBinContent(i+1+m,j+1+k-K/2);
969  if(type=='L') hist2D->SetBinContent(i+1+m,j+1+k-K/2,like+A);
970  else hist2D->SetBinContent(i+1+m,j+1+k-K/2,null+A);
971  }
972  }
973 
974  npix++;
975  }
976 
977  char gtitle[256];
978  if(type=='L') sprintf(gtitle,"Likelihood %3.0f - dt(ms) [%.6g:%.6g] - df(hz) [%.6g:%.6g] - npix %d",
979  Likelihood,1000*mindt,1000*maxdt,mindf,maxdf,npix);
980  else sprintf(gtitle,"Null %3.0f - dt(ms) [%.6g:%.6g] - df(hz) [%.6g:%.6g] - npix %d",
981  Null,1000*mindt,1000*maxdt,mindf,maxdf,npix);
982 
983  hist2D->SetTitle(gtitle);
984 
985  //cout << "Event Likelihood : " << Likelihood << endl;
986  //cout << "Event Null : " << Null << endl;
987 
988  if(opt) hist2D->Draw(opt);
989  else hist2D->Draw("COLZ");
990 
991  // change palette's width
992  canvas->Update();
993  TPaletteAxis *palette = (TPaletteAxis*)hist2D->GetListOfFunctions()->FindObject("palette");
994  palette->SetX1NDC(0.91);
995  palette->SetX2NDC(0.933);
996  palette->SetTitleOffset(0.92);
997  palette->GetAxis()->SetTickSize(0.01);
998  canvas->Modified();
999 
1000  return;
1001 }
1002 
1003 void watplot::plot(clusterdata* pcd, double inj_mchirp) {
1004 //
1005 // chirp event display (only for 2G analysis) : WARNING : Add check 2G !!!
1006 // display frequency vs time
1007 //
1008 // pcd : pointer to clusterdata structure
1009 // inj_mchirp : injected mchirp value
1010 //
1011 
1012  static TGraphErrors egraph;
1013 
1014  double x,y;
1015  double ex,ey;
1016  int np = pcd->chirp.GetN();
1017  egraph.Set(np);
1018  for(int i=0;i<np;i++) {
1019  pcd->chirp.GetPoint(i,x,y);
1020  ex=pcd->chirp.GetErrorX(i);
1021  ey=pcd->chirp.GetErrorY(i);
1022  egraph.SetPoint(i,x,y);
1023  egraph.SetPointError(i,ex,ey);
1024  }
1025  TF1* fit = &(pcd->fit);
1026 
1027  char title[256];
1028  if(inj_mchirp) {
1029  sprintf(title,"chirp mass : rec = %3.3f [%3.2f] inj = %3.3f , chi2 = %3.2f",
1030  pcd->mchirp,pcd->mchirperr,inj_mchirp,pcd->chi2chirp);
1031  } else {
1032  sprintf(title,"chirp mass : rec = %3.3f [%3.2f] , chi2 = %3.2f",
1033  pcd->mchirp,pcd->mchirperr,pcd->chi2chirp);
1034  }
1035  egraph.SetTitle(title);
1036  egraph.GetHistogram()->SetStats(kFALSE);
1037  egraph.GetHistogram()->SetTitleFont(12);
1038  egraph.SetFillColor(kWhite);
1039  egraph.SetLineColor(kBlack);
1040  egraph.GetXaxis()->SetNdivisions(506);
1041  egraph.GetXaxis()->SetLabelFont(42);
1042  egraph.GetXaxis()->SetLabelOffset(0.014);
1043  egraph.GetXaxis()->SetTitleOffset(1.4);
1044  egraph.GetYaxis()->SetTitleOffset(1.2);
1045  egraph.GetYaxis()->SetNdivisions(506);
1046  egraph.GetYaxis()->SetLabelFont(42);
1047  egraph.GetYaxis()->SetLabelOffset(0.01);
1048  egraph.GetXaxis()->SetTitleFont(42);
1049  egraph.GetXaxis()->SetTitle("Time (sec)");
1050  egraph.GetXaxis()->CenterTitle(true);
1051  egraph.GetYaxis()->SetTitleFont(42);
1052  egraph.GetYaxis()->SetTitle("Frequency^{-8/3}");
1053  egraph.GetYaxis()->CenterTitle(true);
1054  egraph.GetXaxis()->SetLabelSize(0.03);
1055  egraph.GetYaxis()->SetLabelSize(0.03);
1056 
1057  egraph.Draw("AP");
1058  fit->Draw("same");
1059 
1060  return;
1061 }
1062 
1063 void watplot::SetPlotStyle(int paletteId, int NCont) {
1064 //
1065 // set palette type
1066 //
1067 
1068  const Int_t NRGBs = 5;
1069 // const Int_t NCont = 255;
1070  NCont=abs(NCont);
1071 
1072  if (fabs(paletteId)==1) {
1073  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
1074  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
1075  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
1076  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
1077  if (paletteId<0) {
1078  TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
1079  } else {
1080  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
1081  }
1082  } else
1083  if (fabs(paletteId)==2) {
1084  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
1085  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
1086  //Double_t red[NRGBs] = { 0.00, 0.00, 0.00, 1.00, 1.00 };
1087  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
1088  //Double_t green[NRGBs] = { 0.00, 1.00, 1.00, 1.00, 0.00 };
1089  Double_t blue[NRGBs] = { 1.00, 1.00, 0.00, 0.00, 0.00 };
1090  if (paletteId<0) {
1091  TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
1092  } else {
1093  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
1094  }
1095  } else
1096  if (fabs(paletteId)==3) {
1097  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
1098  Double_t red[NRGBs] = { 0.00, 0.09, 0.18, 0.09, 0.00 };
1099  Double_t green[NRGBs] = { 0.01, 0.02, 0.39, 0.68, 0.97 };
1100  Double_t blue[NRGBs] = { 0.17, 0.39, 0.62, 0.79, 0.97 };
1101  if (paletteId<0) {
1102  TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
1103  } else {
1104  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
1105  }
1106  } else
1107  if (fabs(paletteId)==4) {
1108  Double_t stops[NRGBs] = { 0.00, 0.50, 0.75, 0.875, 1.00 };
1109  Double_t red[NRGBs] = { 1.00, 1.00, 1.00, 1.00, 1.00 };
1110  Double_t green[NRGBs] = { 1.00, 0.75, 0.50, 0.25, 0.00 };
1111  Double_t blue[NRGBs] = { 0.00, 0.00, 0.00, 0.00, 0.00 };
1112  if (paletteId<0) {
1113  TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
1114  } else {
1115  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
1116  }
1117  } else
1118  if (fabs(paletteId)==5) { // Greyscale palette
1119  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
1120  Double_t red[NRGBs] = { 1.00, 0.84, 0.61, 0.34, 0.00 };
1121  Double_t green[NRGBs] = { 1.00, 0.84, 0.61, 0.34, 0.00 };
1122  Double_t blue[NRGBs] = { 1.00, 0.84, 0.61, 0.34, 0.00 };
1123  if (paletteId<0) {
1124  TColor::CreateGradientColorTable(NRGBs, stops, blue, green, red, NCont);
1125  } else {
1126  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
1127  }
1128  }
1129  gStyle->SetNumberContours(NCont);
1130 
1131  return;
1132 }
1133 
1134 // wavescan (2D histogram)
1135 /*
1136 void watplot::scan(wavearray<double>& x, int M1, int M2, double=t1, double=t2, char* =c, int=nc)
1137 {
1138  int i,j,k;
1139  WDM<double>* wdm[10];
1140 
1141  if(M2-M1 > 10) M2 = M1+9;
1142  for(i=M1; i<=M2; i++) wdm[i-M1] = new WDM<double>(i,i);
1143 
1144 
1145  for(i=M1; i<=M2; i++) delete wdm[i-M1];
1146 
1147 }
1148 */
1149 
1150 
1151 void
1153 //
1154 // blackmanharris window
1155 //
1156 // w : in/out wavearray - must be initialized with w.size() & w.rate()
1157 //
1158 
1159  int size = (int)w.size();
1160 
1161  for (int i = 0; i < size; i++)
1162  {
1163  double f = 0.0;
1164  f = ((double) i) / ((double) (size - 1));
1165  w[i] = 0.35875 -
1166  0.48829 * cos(2.0 * TMath::Pi() * f) +
1167  0.14128 * cos(4.0 * TMath::Pi() * f) -
1168  0.01168 * cos(6.0 * TMath::Pi() * f);
1169  }
1170 
1171  double norm = 0;
1172  for (int i=0;i<size;i++) norm += pow(w[i],2);
1173  norm /= size;
1174  for (int i=0;i<size;i++) w[i] /= sqrt(norm);
1175 }
1176 
1177 void
1179 //
1180 // Save plot with name -> fname
1181 //
1182 
1183  if(canvas!=NULL && fname!="") {
1184  if(fname.Contains(".png")) {
1185  TString gname(fname);
1186  gname.ReplaceAll(".png",".gif");
1187  canvas->Print(gname);
1188  char cmd[1024];
1189  sprintf(cmd,"convert %s %s",gname.Data(),fname.Data());
1190  //cout << cmd << endl;
1191  gSystem->Exec(cmd);
1192  sprintf(cmd,"rm %s",gname.Data());
1193  //cout << cmd << endl;
1194  gSystem->Exec(cmd);
1195  } else {
1196  canvas->Print(fname);
1197  }
1198  }
1199 }
1200 
1201 void
1202 watplot::goptions(char* opt, int col, double t1, double t2, bool fft, float f1, float f2, bool psd, float t3, bool oneside) {
1203 //
1204 // Set graphical options
1205 //
1206 // opt : TGraph::Draw options
1207 // col : set TGraph line color
1208 // t1 : start of time interval in seconds
1209 // t2 : end of time interval in seconds
1210 // fft : true -> plot fft
1211 // f1 : set begin frequency (Hz)
1212 // f2 : set end frequency (Hz)
1213 // psd : true -> plot psd using blackmanharris window
1214 // t3 : is the chunk length (sec) used to produce the psd
1215 // oneside : true/false -> oneside/doubleside
1216 //
1217 
1218  this->ncol= 0;
1219  this->opt = opt;
1220  this->col = col;
1221  this->t1 = t1;
1222  this->t2 = t2;
1223  this->fft = fft;
1224  this->f1 = f1;
1225  this->f2 = f2;
1226  this->psd = psd;
1227  this->t3 = t3;
1228  this->oneside = oneside;
1229 
1230  for(size_t i=0; i<graph.size(); i++) {
1231  if(graph[i]) delete graph[i];
1232  }
1233  graph.clear();
1234 }
1235 
1236 void
1238 //
1239 // Set TGraph titles
1240 //
1241 // title : graph title
1242 // xtitle : x axis name
1243 // ytitle : y axis name
1244 //
1245 
1246  this->title=title;
1247  this->xtitle=xtitle;
1248  this->ytitle=ytitle;
1249  if(graph.size()>0) {
1250  if(title!="") graph[0]->SetTitle(title);
1251  if(xtitle!="") graph[0]->GetHistogram()->SetXTitle(xtitle);
1252  if(ytitle!="") graph[0]->GetHistogram()->SetYTitle(ytitle);
1253  canvas->Update();
1254  }
1255 }
1256 
1258 //
1259 // assignement operator
1260 //
1261 // graph >> x : fill x wavearray with watplot object graph with values
1262 //
1263 
1264  x=graph.data;
1265  return x;
1266 }
1267 
1269 //
1270 // assignement operator
1271 //
1272 // x >> graph : fill watplot object graph with x wavearray values
1273 //
1274 
1275  if(x.size()==0) {
1276  cout << "watplot::operator(>>) : input array with size=0" << endl;
1277  exit(1);
1278  }
1279 
1280  graph.opt.ToUpper();
1281  bool logx = false; if(graph.opt.Contains("LOGX")) {logx=true;graph.opt.ReplaceAll("LOGX","");}
1282  bool logy = false; if(graph.opt.Contains("LOGY")) {logy=true;graph.opt.ReplaceAll("LOGY","");}
1283 
1284  double t1 = graph.t1==0. ? x.start() : graph.t1;
1285  double t2 = graph.t2==0. ? x.start()+x.size()/x.rate() : graph.t2;
1286  double f1 = graph.f1==0. ? 0. : graph.f1;
1287  double f2 = graph.f2==0. ? x.rate()/2. : graph.f2;
1288 
1289  TString opt = graph.ncol ? "SAME" : graph.opt;
1290 
1291  graph.data=x;
1292  if(logx) graph.canvas->SetLogx();
1293  if(logy) graph.canvas->SetLogy();
1294  graph.plot(x, const_cast<char*>(opt.Data()), graph.col+graph.ncol, t1, t2, graph.fft, f1, f2, graph.psd, graph.t3, graph.oneside);
1295  if(graph.graph.size()>0) {
1296  if(graph.title!="") graph.graph[0]->SetTitle(graph.title);
1297  if(graph.xtitle!="") graph.graph[0]->GetHistogram()->SetXTitle(graph.xtitle);
1298  if(graph.ytitle!="") graph.graph[0]->GetHistogram()->SetYTitle(graph.ytitle);
1299  graph.canvas->Update();
1300  }
1301  graph.ncol++;
1302  return graph;
1303 }
1304 
1306 //
1307 // print operator
1308 //
1309 // graph >> fname : save watplot graph to fname file
1310 //
1311 
1312  if(graph.graph.size()==0) {
1313  cout << "watplot::operator (>>) - Error : No graph in the object" << endl;
1314  return fname;
1315  }
1316  TString name = fname;
1317  name.ReplaceAll(" ","");
1318 
1319  TObjArray* token = TString(name).Tokenize(TString("."));
1320  TObjString* ext_tok = (TObjString*)token->At(token->GetEntries()-1);
1321  TString ext = ext_tok->GetString();
1322  if(ext=="txt") {
1323 
1324  ofstream out;
1325  out.open(name.Data(),ios::out);
1326  if (!out.good()) {cout << "watplot::operator (>>) - Error : Opening File : " << name.Data() << endl;exit(1);}
1327 
1328  double x,y;
1329  int size=graph.graph[0]->GetN();
1330  for (int j=0;j<size;j++) {
1331  graph.graph[0]->GetPoint(j,x,y);
1332  if(x>graph.f1 && x<graph.f2) out << x << "\t" << y << endl;
1333  }
1334 
1335  out.close();
1336  } else {
1337  graph.print(name);
1338  }
1339  return fname;
1340 }
1341 
1343 //
1344 // print operator
1345 //
1346 // graph >> fname : save watplot graph to fname file
1347 //
1348 
1349  TString name = fname;
1350  graph >> name;
1351  return fname;
1352 }
#define NRGBs
void graph(TString ifile)
Definition: Average.C:543
std::vector< int > vector_int
Definition: cluster.hh:17
double f1
Definition: watplot.hh:189
virtual size_t size() const
Definition: wavearray.hh:127
std::vector< vector_int > cRate
Definition: netcluster.hh:380
void gtitle(TString title="", TString xtitle="", TString ytitle="")
Definition: watplot.cc:1237
char xtitle[1024]
Double_t green[nRGBs]
bool oneside
Definition: watplot.hh:193
tuple f
Definition: cwb_online.py:91
printf("total live time: non-zero lags = %10.1f \n", liveTot)
char cmd[1024]
virtual void rate(double r)
Definition: wavearray.hh:123
int irate
#define np
size_t frequency
Definition: netpixel.hh:93
float likelihood
Definition: netpixel.hh:96
WSeries< float > v[nIFO]
Definition: cwb_net.C:62
par[0] name
int n
Definition: cwb_net.C:10
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
TString("c")
int palette
Definition: DrawGnetwork2.C:17
double getStatistics(double &mean, double &rms) const
Definition: wavearray.cc:2105
double t3
Definition: watplot.hh:192
float mchirp
Definition: netcluster.hh:66
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
TString title
Definition: watplot.hh:180
float theta
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
wavearray< double > psd(33)
netpixel pix(nifo)
netcluster * pwc
Definition: cwb_job_obj.C:20
std::vector< TGraph * > graph
Definition: watplot.hh:176
return wmap canvas
Double_t blue[nRGBs]
double procOpt(int opt, double val00, double val90=0.)
Definition: watplot.hh:157
double theta_1
Definition: skymap.hh:303
Long_t size
Color_t colors[16]
watplot p1(const_cast< char * >("TFMap1"))
#define M
Definition: UniqSLagsList.C:3
size_t layers
Definition: netpixel.hh:94
int m
Definition: cwb_net.C:10
DataType_t * pWWS
Definition: WaveDWT.hh:123
std::vector< vector_int > cList
Definition: netcluster.hh:379
virtual void start(double s)
Definition: wavearray.hh:119
int j
Definition: cwb_net.C:10
i drho i
double rate
Definition: netcluster.hh:360
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:132
bool psd
Definition: watplot.hh:191
bool core
Definition: netpixel.hh:102
double theta_2
Definition: skymap.hh:304
TH2F * hist2D
Definition: watplot.hh:175
#define NCont
size_t mode
wavearray< double > w
Definition: Test1.C:27
void wrate(double r)
Definition: wseries.hh:102
ofstream out
Definition: cwb_merge.C:196
TCanvas * canvas
Definition: watplot.hh:174
int getLevel()
Definition: wseries.hh:91
float phi
Double_t stops[nRGBs]
bool fft
Definition: watplot.hh:188
double time[6]
Definition: cbc_plots.C:435
double G
Definition: DrawEBHH.C:12
unsigned long nSTS
Definition: WaveDWT.hh:125
i() int(T_cor *100))
bool isWDM()
Definition: wseries.hh:190
double Pi
TF1 * f2
Definition: cbc_plots.C:1710
double t2
Definition: watplot.hh:187
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
Definition: wseries.cc:175
char fname[1024]
double getmax(WSeries< double > &w, double t1, double t2)
Definition: watplot.cc:413
void goptions(char *opt=NULL, int col=1, double t1=0., double t2=0., bool fft=false, float f1=0., float f2=0., bool psd=false, float t3=0., bool oneside=false)
Definition: watplot.cc:1202
int k
TString xtitle
Definition: watplot.hh:181
static double A
Definition: geodesics.cc:8
TObjArray * token
float chi2chirp
Definition: netcluster.hh:68
void plsmooth(WSeries< double > &, int=0, double=0., double=0., char *=NULL, int=256, int=0)
Definition: watplot.cc:266
int m_Level
Definition: Wavelet.hh:97
size_t time
Definition: netpixel.hh:92
Definition: skymap.hh:45
int col
Definition: watplot.hh:185
double f2
Definition: watplot.hh:190
netpixel * getPixel(size_t n, size_t i)
Definition: netcluster.hh:395
int npix
wavearray< double > data
Definition: watplot.hh:179
double dt
virtual void FFTW(int=1)
Definition: wavearray.cc:878
Double_t x0
#define RATE
float mchirperr
Definition: netcluster.hh:67
int nifo
char title[256]
Definition: SSeriesExample.C:1
TGraphErrors chirp
chirp fit parameters (don't remove ! fix crash when exit from CINT)
Definition: netcluster.hh:75
watplot p2(const_cast< char * >("TFMap2"))
void print(TString fname)
Definition: watplot.cc:1178
TString ytitle
Definition: watplot.hh:182
double fabs(const Complex &x)
Definition: numpy.cc:37
void blackmanharris(wavearray< double > &w)
Definition: watplot.cc:1152
void null()
Definition: watplot.hh:53
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
plot hist2D
void SetPlotStyle(int paletteId, int NCont=255)
Definition: watplot.cc:1063
double phi_2
Definition: skymap.hh:306
DataType_t * data
Definition: wavearray.hh:301
double * itime
TH1 * t1
double dFreq
Definition: DrawPSD.C:17
double phi_1
Definition: skymap.hh:305
double get(size_t i)
param: sky index
Definition: skymap.cc:681
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
double t1
Definition: watplot.hh:186
float rate
Definition: netpixel.hh:95
size_t size()
Definition: skymap.hh:118
double getdata(char type='R', size_t n=0)
Definition: netpixel.hh:56
double shift[NIFO_MAX]
virtual void resize(unsigned int)
Definition: wavearray.cc:445
wavearray< double > y
Definition: Test10.C:31
wavearray< double > & operator>>(watplot &graph, wavearray< double > &x)
Definition: watplot.cc:1257
float null
Definition: netpixel.hh:97
Double_t red[nRGBs]
TString opt
Definition: watplot.hh:184
int ncol
Definition: watplot.hh:183
exit(0)
double avr