Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ClusterToFrameNew01_dtmin_approx_cent.C
Go to the documentation of this file.
1 //
2 // Convert netcluster principal components to NN (Neural Network) frames (NDIMxNDIM pixels)
3 // Author : Gabriele Vedovato
4 // Note : run with ACLiC -> root -l 'ClusterToFrameNew01_dtmin_approx_cent.C+("ifile.root","ofile.root")'
5 //
6 
7 #define XIFO 4
8 
9 #pragma GCC system_header
10 
11 #include "cwb.hh"
12 #include "config.hh"
13 #include "network.hh"
14 #include "wavearray.hh"
15 #include "TString.h"
16 #include "TObjArray.h"
17 #include "TObjString.h"
18 #include "TPaletteAxis.h"
19 #include "TRandom.h"
20 #include "TComplex.h"
21 #include "TMath.h"
22 #include "mdc.hh"
23 #include "watplot.hh"
24 #include <vector>
25 #include <algorithm>
26 #include "TTreeFormula.h"
27 TH2F* hist2D=NULL;
28 TCanvas* canvas;
29 #define REF 0.1
30 #define NPIX 20
31 #define NDIM 8
32 #define NBIN 20
33 #define MAXL 10
34 #define MINL 4
35 #define maxLayers 1025
36 
37 void PlotFrame(std::vector<double>* nn_frame, int cid);
38 
39 double ConvertToFrame(netcluster* pwc, int cid, int nifo, char type, int irate, double &dT,double &dF,double &Fc,int &ninf,std::vector<double>* nn_frame, std::vector<double>* dt);
40 
41 //#define WATPLOT // if defined the event monster plots are produced
42 //#define PLOT_FRAME // frame display
43 //#define distribution
44 
46 #ifdef WATPLOT
48 #endif
49 
50  // open input root file
51  TFile* ifile = new TFile(ifName);
52  if(ifile==NULL) {
53  cout << "ClusterToFrame - Error : error opening file : " << ifName.Data() << endl;
54  gSystem->Exit(1);
55  }
56 
57  // get waveburst tree
58  TTree* nn_itree = (TTree *) ifile->Get("waveburst");
59  if(nn_itree==NULL) {
60  cout << "ClusterToFrame - Error : tree waveburst not found !!!" << endl;
61  gSystem->Exit(1);
62  }
63 
64  netcluster* pwc = new netcluster();
65  nn_itree->SetBranchAddress("netcluster",&pwc);
66  int Ntot=nn_itree->GetEntries();
67 
68  // get number of detectors
69  int nIFO = nn_itree->GetUserInfo()->GetSize();
70  if(nIFO==0) {
71  cout<<"ClusterToFrame - Error : wrong user detector list in header tree"<<endl;
72  gSystem->Exit(1);
73  }
74 
75 // open output root file
76  TFile ofile(ofName,"RECREATE");
77 // create output tree
78  TTree* nn_otree = (TTree*)nn_itree->CloneTree(0);
79  //nn_otree->SetName("nn");
80  //nn_otree->SetTitle("nn");
81 
82 // add the NDIM*NDIM pixels vector (nn_frame) for NN analysis and the time vector (dt) which contains the time-duration of each selected pixel
83  std::vector<double>* nn_frame = new vector<double>;
84  std::vector<double>* dt = new vector<double>;
85  nn_frame->resize(NDIM*NDIM);
86  dt->resize(NPIX);
87 
88  int ind=0;
89  double dT=0.;
90  double dF=0.;
91  double Fc=0.;
92  double deltat[NPIX];
93 
94  for (int iu=0; iu<NPIX; iu++) deltat[iu]=0.;
95  int ninf=0;
96 
97 //defining brannces for adding other information
98  nn_otree->Branch("nnframe", &nn_frame, NDIM*NDIM, 0);
99  nn_otree->Branch("dt_corepixels",&dt,NPIX,0);
100  nn_otree->Branch("index",&ind,"ind/I");
101  nn_otree->Branch("t_duration",&dT,"duration/D");
102  nn_otree->Branch("f_duration",&dF,"f_duration/D");
103  nn_otree->Branch("central_f",&Fc,"central_f/D");
104 
105 // read nn_itree
106  int nn_isize = nn_itree->GetEntries();
107  cout << "nn_itree size : " << nn_isize << endl;
108  double SNRf=0.;
109 
110  for(int m=0;m<nn_isize;m++) {
111  if(m%100==0) cout << "ClusterToFrame -> " << m << "/" << nn_isize << endl;
112 
113  nn_itree->GetEntry(m);
114 
115 #ifdef WATPLOT // monster event display
116  WTS.canvas->cd();
117  char fname[1024];
118  sprintf(fname, "monster_event_display_%d.png",m);
119  cout << "write " << fname << endl;
120  WTS.plot(pwc, 1, nIFO, 'L', 0, const_cast<char*>("COLZ")); // use ID=1
121  WTS.canvas->Print(fname);
122  WTS.clear();
123 #endif
124 
125 // using the real conversion-function (ConvertToFrame)
126 
127  ind=m;
128  double SNRfi=0.;
129  int ID = 1; // ID=1 because each netcluster contains only 1 event
130 
131  for (int kk=0; kk<NDIM*NDIM; kk++) (*nn_frame)[kk]=0.;
132  for (int kk=0; kk<NPIX; kk++) (*dt)[kk]=0.;
133  SNRfi=ConvertToFrame(pwc, m, nIFO, 'L', 0, dT, dF, Fc,ninf, nn_frame,dt);
134  SNRf=SNRf+SNRfi; //evaluating the avarage weight of the latest pixel
135 
136 #ifdef PLOT_FRAME // frame display
137  PlotFrame(nn_frame, m);
138 #endif
139 
140 //filling the output tree
141  nn_otree->Fill();
142  }
143 
144 //write and close the output file
145  cout<<"nn_size: "<<nn_isize<<endl;
146  nn_otree->Write();
147  ofile.Close();
148  cout<<ofName<<endl;
149 
150  ifile->Close();
151  cout<<"number events with SNRfi<"<<REF<<": "<<ninf<<endl;
152  cout<<"media importanza ultimo bin: "<<SNRf/nn_isize<<endl;
153  gSystem->Exit(0);
154 }
155 
156 double
157 ConvertToFrame(netcluster* pwc, int n_ev, int nifo, char type, int irate,double &dT, double &dF, double &Fc,int &ninf, std::vector<double>* nn_frame, std::vector<double>* dt) {
158  int cid=1;
159  double FRAME[NDIM][NDIM];
160  if(type != 'L' && type != 'N') return 0.;
161 
162  double RATE = pwc->rate; // original rate>4096
163 
164  std::vector<int>* vint = &(pwc->cList[cid-1]); // pixel list
165 
166  int V = vint->size(); // cluster size
167  if(!V) return 0.;
168 
169  bool optrate=false;
170  if(irate==1) { // extract optimal rate
171  optrate=true;
172  std::vector<int>* pv = pwc->cRate.size() ? &(pwc->cRate[cid-1]) : NULL;
173  irate = pv!=NULL ? (*pv)[0] : 0;
174  }
175 
176  //Layers: number of pixels pixels contained in the frequency range (64-2048) in a particular level of decomposition
177 
178  // int minLayers=1000;
179  // int maxLayers=0;
180  double minTime=1e20;
181  double maxTime=0.;
182  double minFreq=1e20;
183  double maxFreq=0.;
184 
185  //in freq sta prendendo i centri dei pixels mentre nei tempi prendi i limite inf
186  int num_core=0;
187 
188 //loop over the pixels
189  for(int j=0; j<V; j++) { // loop over the pixels
190  netpixel* pix = pwc->getPixel(cid,j);
191  if(!pix->core) continue; // selection of the only core-pixels
192 
193  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
194 
195 // if(pix->layers<minLayers) minLayers=pix->layers;
196 // if(pix->layers>maxLayers) maxLayers=pix->layers;
197 
198 // int minLayers=pow(2,MINL)+1;
199 // int maxLayers=pow(2,MAXL)+1;
200 
201 
202  //deltat[j]=((pix->layers-1)/RATE);
203  int max_ind=0;
204  double rate = RATE/(pix->layers-1);
205  double time=((double)pix->time/rate)/pix->layers;
206  if(time<minTime) minTime=time;
207  if(time>maxTime) {maxTime=time;
208  //max_ind=j;
209  //max_amp=pow(pix->getdata(),2);
210  }
211  num_core=num_core+1;
212  //pix->frequency: nindice in freq
213  //rate/2=df
214  //siccome in freq inizio con pixels mezzi così(pix->frequency*rate/2.) arrivo alla freq centrale-> layers sono quindi sempre dispari
215  //pix->time=itime*(pix->layer)+ifreq {ifreq e itime idici interi di array}
216  //time=itime*dt[s]
217  //freq=ifreq*df[Hz]
218 
219  double freq = pix->frequency*rate/2.;
220  if(freq<minFreq) minFreq=freq;
221  if(freq>maxFreq) maxFreq=freq;
222  }
223  int const ncorepix=num_core;
224  double deltat[ncorepix];
225  for (int u=0;u<ncorepix;u++) deltat[u]=0.;
226  //cout<<"nPIX: "<<NPIX<<" size: "<<dt->size()<<endl;
227  //std::sort(dt->begin(),dt->begin()+NPIX);
228  // for (int u=0;u<NPIX;u++) cout<<"dt: "<<(*dt)[u+n_ev*NPIX]<<endl;
229  // for (int u=0;u<NPIX;u++) cout<<"evento numero "<<n_ev<<" pixel numero: "<<u<<" dt="<<deltat[u]<<endl;
230  //int minRate=RATE/(maxLayers-1);
231  // int maxRate=RATE/(minLayers-1);
232  int minRate=RATE/(pow(2,MAXL));
233  int maxRate=RATE/(pow(2,MINL));
234  dT=maxTime-minTime;
235  // cout<<" dT: "<<dT<<endl;
236  dF=maxFreq-minFreq;
237  // cout<<" dF: "<<dF<<endl;
238  Fc=(maxFreq+minFreq)/2;
239  // cout<<" Fc: "<<Fc<<endl;
240  double mindt = 1./maxRate;
241  double maxdt = 1./minRate;
242  double mindf = minRate/2.;
243  double maxdf = maxRate/2.;
244 
245  //cout << "minRate : " << minRate << "\t\t\t maxRate : " << maxRate << endl;
246  //cout << "minTime : " << minTime << "\t\t\t maxTime : " << maxTime << endl;
247  //cout << "minFreq : " << minFreq << "\t\t\t maxFreq : " << maxFreq << endl;
248  //cout << "mindt : " << mindt << "\t\t\t maxdt : " << maxdt << endl;
249  //cout << "mindf : " << mindf << "\t\t\t maxdf : " << maxdf << endl;
250 
251  int iminTime = int(minTime);
252  int imaxTime = int(maxTime+1);
253  int nTime = (imaxTime-iminTime)*maxRate;
254 
255  if(hist2D) { delete hist2D; hist2D=NULL; }
256  hist2D=new TH2F("WTF", "WTF", nTime, iminTime, imaxTime, 2*maxLayers-2, 0, RATE/2);
257  hist2D->SetXTitle("time, sec");
258  hist2D->SetYTitle("frequency, Hz");
259 
260  double dFreq = (maxFreq-minFreq)/10.>2*maxdf ? (maxFreq-minFreq)/10. : 2*maxdf ;
261  double mFreq = minFreq-dFreq<0 ? 0 : minFreq-dFreq;
262  double MFreq = maxFreq+dFreq>RATE/2 ? RATE/2 : maxFreq+dFreq;
263  hist2D->GetYaxis()->SetRangeUser(mFreq, MFreq);
264 
265  double dTime = (maxTime-minTime)/10.>2*maxdt ? (maxTime-minTime)/10. : 2*maxdt ;
266  double mTime = minTime-dTime<iminTime ? iminTime : minTime-dTime;
267  double MTime = maxTime+dTime>imaxTime ? imaxTime : maxTime+dTime;
268  hist2D->GetXaxis()->SetRangeUser(mTime,MTime);
269  int ncore=0;
270  int npix=0;
271  double Null2=0;
272  double Likelihood2=0;
273  double Null=0;
274  double Likelihood=0;
275  double amp=0.;
276  double ttime=0.;
277  TTree* tS=new TTree("Time_SNR","Time_SNR");
278  tS->Branch("amplitude",&amp,"amplitude/D");
279  tS->Branch("central_time",&ttime,"central_time/D");
280  for(int n=0; n<V; n++) {
281  netpixel* pix = pwc->getPixel(cid,n);
282  if(!pix->core) continue;
283  double rate = RATE/(pix->layers-1);
284  deltat[ncore]=1./rate;
285  ncore=ncore+1;
286  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
287  npix++;
288  double sSNR=0;
289  double wSNR=0;
290  for(int m=0; m<nifo; m++) {
291  sSNR += pow(pix->getdata('S',m),2); // snr whitened reconstructed signal 00
292  sSNR += pow(pix->getdata('P',m),2); // snr whitened reconstructed signal 90
293  wSNR += pow(pix->getdata('W',m),2); // snr whitened at the detector 00
294  wSNR += pow(pix->getdata('U',m),2); // snr whitened at the detector 90
295  }
296  double null = wSNR-sSNR;
297  amp=sSNR;
298  //cout<<"pixel n: "<<n<<" sSNR: "<<sSNR;
299  int iRATE = RATE/(pix->layers-1);
300  int M=maxRate/iRATE;
301  int K=2*(maxLayers-1)/(pix->layers-1);
302  double itime=((double)pix->time/(double)iRATE)/pix->layers;
303  ttime=itime;
304  //cout<<" ttime: "<<ttime<<endl;
305  tS->Fill();
306  int i=(itime-iminTime)*maxRate;
307  int j=pix->frequency*K;
308  if(iRATE!=irate && irate!=0) continue;
309  Null+=null;
310  Likelihood+=sSNR;
311  int L=0;int R=1;while (R < iRATE) {R*=2;L++;}
312  }
313  //cout<<"ncore: "<<ncore<<endl;
314  //cout<<"minTime: "<<minTime<<" maxTime "<<maxTime<<endl;
315  double deltaBIN=(maxTime-minTime)/(NBIN-1);
316  //cout<<"deltaBIN: "<<deltaBIN<<endl;
317  TH1D* h=new TH1D("SNR_distribution","SNR_distribution",NBIN,1,NBIN+1);
318  //double timec[NPIX];
319  double timec2[ncorepix];
320  // for (int u=0; u<NPIX;u++) timec[u]=0.;
321  char cuts[1024];
322  double time_bin[NBIN];
323  for (int nbin=0;nbin<NBIN;nbin++){
324  double mintime_bin=maxTime-(nbin)*deltaBIN;
325  if (nbin==0||nbin==NBIN-1) mintime_bin=mintime_bin-0.001;
326  time_bin[nbin]=mintime_bin;
327  // cout<<"numero bin "<<nbin<<" mintime_bin "<<mintime_bin<<endl;
328  sprintf(cuts,"central_time>%5.5f",mintime_bin);
329  TTreeFormula* treeformula=new TTreeFormula("cuts",cuts,tS);
330  int err = treeformula->Compile(cuts);
331  if(err) {
332  cout << "DisplayROC.C - wrong input cuts " << cuts << endl;
333  //return -1;
334  }
335  double ybin=0.;
336  tS->SetBranchAddress("central_time",&ttime);
337  tS->SetBranchAddress("amplitude",&amp);
338  for(int n=0;n<tS->GetEntries();n++) { // loop over the detected events
339  tS->GetEntry(n); // load event #n
340 // timec[n]=ttime;
341  timec2[n]=ttime;
342  // cout<<"ttime: "<<ttime<<" amp: "<<amp<<" di evento nume: "<<n+1<<" su "<<tS->GetEntries()<<endl;
343  if(treeformula!=NULL) {
344  if(treeformula->EvalInstance()==0) { // skip entry if it does not satisfy selection cuts
345  // cout << "Skip entry number : " << n << endl;
346  continue;
347  }
348  ybin=ybin+amp;
349  // cout<<"n "<<n<<" min time bin: "<<mintime_bin<<" central time: "<<ttime<<" amp: "<<amp<<" xBIN: "<<mintime_bin<<" yBIN: "<<ybin<<endl;
350  }
351  }
352  h->Fill(nbin+1,ybin);
353  ybin=0.;
354  }
355 std::sort(timec2,timec2+ncorepix);
356 //std::sort(timec,timec+NPIX);
357 int index[ncorepix];
358 TMath::Sort(ncorepix,timec2,index);
359  for (int u=0;u<NPIX;u++){
360  if(u<ncorepix) {
361  //dt->push_back(deltat[index[u]]);
362  (*dt)[u] = deltat[index[u]];
363  //cout<<"dt: "<<deltat[index[u]]<<" central_time "<<timec2[u]<<endl;
364  }
365  //else dt->push_back(0.);
366  else (*dt)[u] = 0.;
367 // cout<<""<<endl;
368 // cout<<"deltat "<<deltat[u]<<" dt: "<<(*dt)[u]<<endl;
369  }
370 #ifdef distribution
371 TCanvas* h_canv=new TCanvas("SNR","SNR",0,0,500,500);
372 h->Draw();
373 char h_char[512];
374 sprintf(h_char,"SNRisto/event%i.png",n_ev);
375 h_canv->SaveAs(h_char);
376 #endif
377 double SNRfi0=0.;
378 double SNRfi=0.;
379 int js=1;
380 while (h->GetBinContent(js)==0&&js<NBIN) js=js+1;
381 SNRfi0=(h->GetBinContent(js)/h->GetBinContent(NBIN));
382 int indtemp=0;
383 double ampTOT=0.;
384 double ampFin=0.;
385 double amp2[ncorepix];
386 for (int u=0;u<ncorepix;u++) amp2[u]=0.;
387 double t_limit=0.;
388  for(int iu=0;iu<ncorepix;iu++){
389  tS->SetBranchAddress("central_time",&ttime);
390  tS->SetBranchAddress("amplitude",&amp);
391  char cuts2[1024];
392  sprintf(cuts2,"central_time>%5.5f",timec2[ncorepix-1-iu]-0.001);
393  TTreeFormula* treeformula2=new TTreeFormula("cuts2",cuts2,tS);
394  int err2 = treeformula2->Compile(cuts2);
395  if(err2) {
396  cout << "DisplayROC.C - wrong input cuts " << cuts2 << endl;
397  //return -1;
398  break;
399  }
400  ampTOT=0.;
401  for(int n=0;n<tS->GetEntries();n++) { // loop over the detected events
402  tS->GetEntry(n); // load event #n
403  //cout<<"tempo limite analizzato "<<timec2[ncorepix-1-iu]<<" ttime "<<ttime<<" evento nume: "<<n+1<<" su "<<tS->GetEntries()<<endl;
404  if(treeformula2!=NULL) {
405  if(treeformula2->EvalInstance()==0) { // skip entry if it does not satisfy selection cuts
406  // cout << "Skip entry number : " << n << endl;
407  continue;
408  }
409  ampTOT=ampTOT+amp;
410  //cout<<"timec "<<timec2[ncorepix-1-iu]<< " ampTOT "<<ampTOT<<" amp "<<amp<<endl;
411  }
412  }
413  amp2[iu]=ampTOT;
414  //if(ampTOT>REF&&iu!=0) t_limit= timec2[ncorepix-iu];//così t_limit è l'ultimo da togliere
415  if((ampTOT/h->GetBinContent(NBIN))>REF) {
416  if(iu>0) ampFin=amp2[iu-1];
417  //cout<<"fial amplitude"<<ampFin<<endl;
418  t_limit= timec2[ncorepix-1-iu];//così t_limit è il primo da lasciare
419  //if(iu>0) cout<<"ultimo tempo da buttare:"<<timec2[ncorepix-iu];
420  break;
421  }
422  // if((ampTOT/h->GetBinContent(NBIN))>REF&&iu==0) t_limit=0.;
423 
424  }
425 //cout<<" primo timo da tenere:"<<t_limit<<endl;
426 //SNRfi=ampFin/(h->GetBinContent(NBIN-1));
427 SNRfi=ampFin/(h->GetBinContent(NBIN));
428 //cout<<"SNRfi0: "<<SNRfi0<<" SNRfi: "<<SNRfi<<endl;
429 
430  for(int n=0; n<V; n++) {
431  netpixel* pix = pwc->getPixel(cid,n);
432  if(!pix->core) continue;
433  if((irate)&&(irate != int(pix->rate+0.5))) continue; // if irate!=0 skip rate!=irate
434  double rate = RATE/(pix->layers-1);
435  double sSNR2=0;
436  double wSNR2=0;
437  //cout<<"limit time: "<<t_limit<<" time from direct pixel: "<<((double)pix->time/rate)/pix->layers<<endl;
438  //cout<<"likelihhod: "<<Likelihood2<<endl;
439  if (SNRfi>0.&&SNRfi<=REF&&(((double)pix->time/rate)/pix->layers)>t_limit) continue;
440  for(int m=0; m<nifo; m++) {
441  sSNR2 += pow(pix->getdata('S',m),2); // snr whitened reconstructed signal 00
442  sSNR2 += pow(pix->getdata('P',m),2); // snr whitened reconstructed signal 90
443  wSNR2 += pow(pix->getdata('W',m),2); // snr whitened at the detector 00
444  wSNR2 += pow(pix->getdata('U',m),2); // snr whitened at the detector 90
445  }
446  double null2 = wSNR2-sSNR2;
447  int iRATE = RATE/(pix->layers-1);
448  int M=maxRate/iRATE;
449  int K=2*(maxLayers-1)/(pix->layers-1);
450  double itime=((double)pix->time/(double)iRATE)/pix->layers;
451  ttime=itime;
452  int i=(itime-iminTime)*maxRate;
453  int j=pix->frequency*K;
454  if(iRATE!=irate && irate!=0) continue;
455  Null2+=null2;
456  Likelihood2+=sSNR2;
457  //cout<<"likelihood dopo aggiornamento: "<<Likelihood2<<endl;
458  int L=0;int R=1;while (R < iRATE) {R*=2;L++;}
459  for(int m=0;m<M;m++) {
460  for(int k=0;k<K;k++) {
461  double SNRsum=hist2D->GetBinContent(i+1+m,j+1+k-K/2);
462  if(type=='L') hist2D->SetBinContent(i+1+m,j+1+k-K/2,sSNR2+SNRsum);
463  else hist2D->SetBinContent(i+1+m,j+1+k-K/2,null2+SNRsum);
464  }
465  }
466  }
467 
468  int imin=hist2D->GetNbinsX();
469  int imax=0;
470  int jmin=hist2D->GetNbinsY();
471  int jmax=0;
472 
473  for (int i=0;i<=hist2D->GetNbinsX();i++) {
474  for (int j=0;j<=hist2D->GetNbinsY();j++) {
475  double X = hist2D->GetXaxis()->GetBinCenter(i)+hist2D->GetXaxis()->GetBinWidth(i)/2.;
476  double Y = hist2D->GetYaxis()->GetBinCenter(j)+hist2D->GetYaxis()->GetBinWidth(j)/2.;
477  double Z = hist2D->GetBinContent(i,j);
478  if(Z) {
479  if(i<imin) imin=i;
480  if(i>imax) imax=i;
481  if(j<jmin) jmin=j;
482  if(j>jmax) jmax=j;
483  }
484  //if(Z) cout << i << " " << j << " " << X << " " << Y << " " << Z << endl;
485  }
486  }
487 
488  //cout << "imin " << imin << " imax " << imax << endl;
489  //cout << "jmin " << jmin << " jmax " << jmax << endl;
490 
491 
492  int di = imax-imin+1;
493  int dj = jmax-jmin+1;
494 
495  //cout << "di " << di << " dj " << dj << endl;
496 
497  int ri = NDIM-di%NDIM;
498  int rj = NDIM-dj%NDIM;
499  if (di%NDIM==0) ri=0;
500  if (dj%NDIM==0) rj=0;
501 /* int lri = ri/2;
502  int rri = ri-lri;
503  //cout << "lri " << lri << " rri " << rri << endl;
504 
505  imin-=lri;
506  imax+=rri;
507 
508  int lrj = rj/2;
509  int rrj = rj-lrj;
510  //cout << "lrj " << lrj << " rrj " << rrj << endl;
511 
512  jmin-=lrj;
513  jmax+=rrj;
514 */
515 //cout << "di: " << di << " ri: " << ri << endl;
516 // cout << "dj: " << dj << " rj: " << rj << endl;
517 // cout << "imin " << imin << " imax " << imax << endl;
518 // cout << "jmin " << jmin << " jmax " << jmax << endl;
519  bool ripi=false;
520  bool ripj=false;
521 //cout<<"resto diverso da zero"<<endl;
522 
523  int lri = ri/2;
524  int rri = ri-lri;
525  int lrj = rj/2;
526  int rrj = rj-lrj;
527 
528 
529  if (ri<4 || di<=4){
530  di = di+ri;
531  imin-=lri;
532  imax+=rri;
533  //imin-=ri;
534  }
535 
536  else {
537  imin+=di%NDIM;
538  di = di-di%NDIM;
539  ripi=true;
540  }
541 
542  if (rj<4 || dj<=4){
543  dj = dj+rj;
544  jmin-=lrj;
545  jmax+=rrj;
546 
547  //jmax+=rj;
548  }
549  else {
550  jmax-=dj%NDIM;
551  dj = dj-dj%NDIM;
552  ripj=true;
553  }
554 
555 // cout << "imin " << imin << " imax " << imax << endl;
556 // cout << "jmin " << jmin << " jmax " << jmax << endl;
557 //cout<<" def limiti"<<endl;
558  int xdim = (imax-imin+1)/NDIM;
559  int ydim = (jmax-jmin+1)/NDIM;
560  //cout << "xdim " << xdim << " ydim " << ydim << endl;
561 //cout<<" def xdim,ydim"<<endl;
562 
563  for(int i=0;i<NDIM;i++) for(int j=0;j<NDIM;j++) FRAME[i][j]=0;
564 
565  for (int i=0;i<=hist2D->GetNbinsX();i++) {
566 //cout<<"i, j "<<i<<" "<<" i min "<<imin<<xmax<<" xdim "<<xdim<<" jmin "<<jmin<<" ydim "<<ydim<<endl;
567  for (int j=0;j<=hist2D->GetNbinsY();j++) {
568 
569  bool ripi2=false;
570  bool ripj2=false;
571 
572  double X = hist2D->GetXaxis()->GetBinCenter(i)+hist2D->GetXaxis()->GetBinWidth(i)/2.;
573  double Y = hist2D->GetYaxis()->GetBinCenter(j)+hist2D->GetYaxis()->GetBinWidth(j)/2.;
574  double Z = hist2D->GetBinContent(i,j);
575  if(i>imax) continue;
576  if(j<jmin) continue;
577 
578  // if((i<imin)&&(ri<4|| di<=4)) continue;
579  // if((j>jmax)&&(rj<4|| dj<=4)) continue;
580 
581  // if((i<imin)&&!(ri<4|| di<=4)) i=i+xdim;
582  // if((j>jmax)&&!(rj<4|| dj<=4)) j=j-ydim;
583 
584  if (i<imin && ripi==false) continue;
585  if (j<jmin && ripj==false) continue;
586 
587  if (i<imin && ripi==true) {i=i+xdim;ripi2=true;}
588  if (j<jmin && ripj==true) {j=j-ydim;ripj2=true;}
589 
590 //cout<<"i, j "<<i<<" "<<j<<" i min "<<imin<<" xdim "<<xdim<<" jmin "<<jmin<<" ydim "<<ydim<<endl;
591  int I = (i-imin)/xdim;
592  int J = (j-jmin)/ydim;
593 //cout << I << " " << J << endl;
594  FRAME[I][J]+=Z;
595 //cout << "sono ui" << endl;
596 
597  //if((i-xdim<imin)&&!(ri<4|| di<=4)) i=i-xdim;
598  //if((j+ydim>jmax)&&!(rj<4|| dj<=4)) j=j+ydim;
599 
600  if (ripi2==true) i=i-xdim;
601  if (ripj2==true) j=j+ydim;
602  //if(Z) cout << i << " " << j << " " << X << " " << Y << " " << Z << endl;
603  //if(Z) cout << I << " " << J << " " << FRAME[I][J] << endl;
604  }
605  }
606 
607  // fill nn frame
608  //for(int i=0;i<NDIM;i++) for(int j=0;j<NDIM;j++) nn_frame->push_back(FRAME[i][j]);
609  for(int i=0;i<NDIM;i++) for(int j=0;j<NDIM;j++) (*nn_frame)[i*NDIM+j] = FRAME[i][j];
610  // normalization
611  double norm=0;
612  int nn_size = nn_frame->size();
613  for(int i=0;i<nn_size;i++) norm+=(*nn_frame)[i];
614  for(int i=0;i<nn_size;i++) (*nn_frame)[i]/=norm;
615  if (SNRfi<=REF) ninf=ninf+1;
616  delete h;
617  return SNRfi0;
618 
619 //cout<<" fine funzione" <<endl;
620 }
621 
622 void
623 PlotFrame(std::vector<double>* nn_frame, int cid) {
624 
625  // get dimension of the frame
626  int nframe = nn_frame->size();
627  if(nframe != pow(int(sqrt(nframe)),2)) {
628  cout << "PlotFrame - Error : size is not a square number " << endl;
629  gSystem->Exit(1);
630  }
631  nframe = sqrt(nframe);
632 
633  if(hist2D) { delete hist2D; hist2D=NULL; }
634  hist2D=new TH2F("frame", "frame", nframe, 0, nframe, nframe, 0, nframe);
635 
636  hist2D->SetStats(kFALSE);
637  hist2D->SetTitleFont(12);
638  hist2D->SetFillColor(kWhite);
639 
640  hist2D->GetXaxis()->SetNdivisions(506);
641  hist2D->GetXaxis()->SetLabelFont(42);
642  hist2D->GetXaxis()->SetLabelOffset(0.014);
643  hist2D->GetXaxis()->SetTitleOffset(1.4);
644  hist2D->GetYaxis()->SetTitleOffset(1.2);
645  hist2D->GetYaxis()->SetNdivisions(506);
646  hist2D->GetYaxis()->SetLabelFont(42);
647  hist2D->GetYaxis()->SetLabelOffset(0.01);
648  hist2D->GetZaxis()->SetLabelFont(42);
649  hist2D->GetZaxis()->SetNoExponent(false);
650  hist2D->GetZaxis()->SetNdivisions(506);
651 
652  hist2D->GetXaxis()->SetTitleFont(42);
653  hist2D->GetXaxis()->SetTitle("Time");
654  hist2D->GetXaxis()->CenterTitle(true);
655  hist2D->GetYaxis()->SetTitleFont(42);
656  hist2D->GetYaxis()->SetTitle("Frequency");
657  hist2D->GetYaxis()->CenterTitle(true);
658 
659  hist2D->GetZaxis()->SetTitleOffset(0.6);
660  hist2D->GetZaxis()->SetTitleFont(42);
661  hist2D->GetZaxis()->CenterTitle(true);
662 
663  hist2D->GetXaxis()->SetLabelSize(0.03);
664  hist2D->GetYaxis()->SetLabelSize(0.03);
665  hist2D->GetZaxis()->SetLabelSize(0.03);
666 
667  for(int i=0;i<nframe;i++) {
668  for(int j=0;j<nframe;j++) {
669  //cout << i << " " << j << " " << (*nn_frame)[i*nframe+j] << endl;
670  hist2D->SetBinContent(i+1,j+1,(*nn_frame)[i*nframe+j]);
671  }
672  }
673 
674 
675  canvas= new TCanvas("mra", "mra", 200, 20, 600, 600);
676  canvas->Clear();
677  canvas->ToggleEventStatus();
678  canvas->SetGridx();
679  canvas->SetGridy();
680  canvas->SetFillColor(kWhite);
681  canvas->SetRightMargin(0.10);
682  canvas->SetLeftMargin(0.10);
683  canvas->SetBottomMargin(0.13);
684  canvas->SetBorderMode(0);
685 
686  // remove the red box around canvas
687  gStyle->SetFrameBorderMode(0);
688  gROOT->ForceStyle();
689 
690  gStyle->SetTitleH(0.050);
691  gStyle->SetTitleW(0.95);
692  gStyle->SetTitleY(0.98);
693  gStyle->SetTitleFont(12,"D");
694  gStyle->SetTitleColor(kBlue,"D");
695  gStyle->SetTextFont(12);
696  gStyle->SetTitleFillColor(kWhite);
697  gStyle->SetLineColor(kWhite);
698  gStyle->SetNumberContours(256);
699  gStyle->SetCanvasColor(kWhite);
700  gStyle->SetStatBorderSize(1);
701 
702  hist2D->Draw("COLZ");
703 
704  // change palette's width
705  canvas->Update();
706  TPaletteAxis *palette = (TPaletteAxis*)hist2D->GetListOfFunctions()->FindObject("palette");
707  palette->SetX1NDC(0.91);
708  palette->SetX2NDC(0.933);
709  palette->SetTitleOffset(0.92);
710  palette->GetAxis()->SetTickSize(0.01);
711  canvas->Modified();
712 
713  char fname[1024];
714  sprintf(fname, "nn_frame_display_%d.png",cid);
715  cout << "write " << fname << endl;
716  canvas->Print(fname);
717 }
718 
std::vector< vector_int > cRate
Definition: netcluster.hh:380
TString ofName
int irate
size_t frequency
Definition: netpixel.hh:93
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
int ID
Definition: TestMDC.C:70
netpixel pix(nifo)
netcluster * pwc
Definition: cwb_job_obj.C:20
void ClusterToFrameNew01_dtmin_approx_cent(TString ifName, TString ofName)
tuple treeformula
Definition: ReadFileWAVE.py:22
#define M
Definition: UniqSLagsList.C:3
size_t layers
Definition: netpixel.hh:94
int m
Definition: cwb_net.C:10
std::vector< vector_int > cList
Definition: netcluster.hh:379
char ofile[512]
int j
Definition: cwb_net.C:10
i drho i
double rate
Definition: netcluster.hh:360
int ncore
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 core
Definition: netpixel.hh:102
void clear()
Definition: watplot.hh:40
#define nIFO
TCanvas * canvas
Definition: watplot.hh:174
double time[6]
Definition: cbc_plots.C:435
wavearray< double > h
Definition: Regression_H1.C:25
watplot * WTS
Definition: ChirpMass.C:115
i() int(T_cor *100))
char fname[1024]
int k
void PlotFrame(std::vector< double > *nn_frame, int cid)
size_t time
Definition: netpixel.hh:92
TFile * ifile
netpixel * getPixel(size_t n, size_t i)
Definition: netcluster.hh:395
int npix
double dt
#define RATE
int nifo
wavearray< int > index
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double * itime
double dFreq
Definition: DrawPSD.C:17
double dT
Definition: testWDM_5.C:12
float rate
Definition: netpixel.hh:95
double getdata(char type='R', size_t n=0)
Definition: netpixel.hh:56
double ConvertToFrame(netcluster *pwc, int cid, int nifo, char type, int irate, double &dT, double &dF, double &Fc, int &ninf, std::vector< double > *nn_frame, std::vector< double > *dt)