9 #pragma GCC system_header
16 #include "TObjArray.h"
17 #include "TObjString.h"
18 #include "TPaletteAxis.h"
26 #include "TTreeFormula.h"
35 #define maxLayers 1025
37 void PlotFrame(std::vector<double>* nn_frame,
int cid);
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);
51 TFile*
ifile =
new TFile(ifName);
53 cout <<
"ClusterToFrame - Error : error opening file : " << ifName.Data() << endl;
58 TTree* nn_itree = (TTree *) ifile->Get(
"waveburst");
60 cout <<
"ClusterToFrame - Error : tree waveburst not found !!!" << endl;
65 nn_itree->SetBranchAddress(
"netcluster",&pwc);
66 int Ntot=nn_itree->GetEntries();
69 int nIFO = nn_itree->GetUserInfo()->GetSize();
71 cout<<
"ClusterToFrame - Error : wrong user detector list in header tree"<<endl;
76 TFile
ofile(ofName,
"RECREATE");
78 TTree* nn_otree = (TTree*)nn_itree->CloneTree(0);
83 std::vector<double>* nn_frame =
new vector<double>;
84 std::vector<double>*
dt =
new vector<double>;
94 for (
int iu=0; iu<
NPIX; iu++) deltat[iu]=0.;
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");
106 int nn_isize = nn_itree->GetEntries();
107 cout <<
"nn_itree size : " << nn_isize << endl;
110 for(
int m=0;
m<nn_isize;
m++) {
111 if(
m%100==0) cout <<
"ClusterToFrame -> " <<
m <<
"/" << nn_isize << endl;
113 nn_itree->GetEntry(
m);
115 #ifdef WATPLOT // monster event display
118 sprintf(fname,
"monster_event_display_%d.png",
m);
119 cout <<
"write " << fname << endl;
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);
136 #ifdef PLOT_FRAME // frame display
145 cout<<
"nn_size: "<<nn_isize<<endl;
151 cout<<
"number events with SNRfi<"<<
REF<<
": "<<ninf<<endl;
152 cout<<
"media importanza ultimo bin: "<<SNRf/nn_isize<<endl;
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) {
160 if(type !=
'L' && type !=
'N')
return 0.;
164 std::vector<int>* vint = &(pwc->
cList[cid-1]);
166 int V = vint->size();
172 std::vector<int>* pv = pwc->
cRate.size() ? &(pwc->
cRate[cid-1]) : NULL;
173 irate = pv!=NULL ? (*pv)[0] : 0;
189 for(
int j=0;
j<V;
j++) {
191 if(!pix->
core)
continue;
193 if((irate)&&(irate !=
int(pix->
rate+0.5)))
continue;
206 if(time<minTime) minTime=
time;
207 if(time>maxTime) {maxTime=
time;
220 if(freq<minFreq) minFreq=freq;
221 if(freq>maxFreq) maxFreq=freq;
223 int const ncorepix=num_core;
224 double deltat[ncorepix];
225 for (
int u=0;u<ncorepix;u++) deltat[u]=0.;
232 int minRate=RATE/(pow(2,
MAXL));
233 int maxRate=RATE/(pow(2,
MINL));
238 Fc=(maxFreq+minFreq)/2;
240 double mindt = 1./maxRate;
241 double maxdt = 1./minRate;
242 double mindf = minRate/2.;
243 double maxdf = maxRate/2.;
251 int iminTime =
int(minTime);
252 int imaxTime =
int(maxTime+1);
253 int nTime = (imaxTime-iminTime)*maxRate;
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");
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);
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);
272 double Likelihood2=0;
277 TTree* tS=
new TTree(
"Time_SNR",
"Time_SNR");
278 tS->Branch(
"amplitude",&,
"amplitude/D");
279 tS->Branch(
"central_time",&ttime,
"central_time/D");
280 for(
int n=0;
n<V;
n++) {
282 if(!pix->
core)
continue;
286 if((irate)&&(irate !=
int(pix->
rate+0.5)))
continue;
296 double null = wSNR-sSNR;
299 int iRATE = RATE/(pix->
layers-1);
306 int i=(itime-iminTime)*maxRate;
308 if(iRATE!=irate && irate!=0)
continue;
311 int L=0;
int R=1;
while (R < iRATE) {R*=2;L++;}
315 double deltaBIN=(maxTime-minTime)/(
NBIN-1);
317 TH1D*
h=
new TH1D(
"SNR_distribution",
"SNR_distribution",
NBIN,1,
NBIN+1);
319 double timec2[ncorepix];
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;
328 sprintf(cuts,
"central_time>%5.5f",mintime_bin);
329 TTreeFormula*
treeformula=
new TTreeFormula(
"cuts",cuts,tS);
330 int err = treeformula->Compile(cuts);
332 cout <<
"DisplayROC.C - wrong input cuts " << cuts << endl;
336 tS->SetBranchAddress(
"central_time",&ttime);
337 tS->SetBranchAddress(
"amplitude",&);
338 for(
int n=0;
n<tS->GetEntries();
n++) {
343 if(treeformula!=NULL) {
344 if(treeformula->EvalInstance()==0) {
352 h->Fill(nbin+1,ybin);
355 std::sort(timec2,timec2+ncorepix);
358 TMath::Sort(ncorepix,timec2,index);
359 for (
int u=0;u<
NPIX;u++){
362 (*dt)[u] = deltat[index[u]];
371 TCanvas* h_canv=
new TCanvas(
"SNR",
"SNR",0,0,500,500);
374 sprintf(h_char,
"SNRisto/event%i.png",n_ev);
375 h_canv->SaveAs(h_char);
380 while (h->GetBinContent(js)==0&&js<
NBIN) js=js+1;
381 SNRfi0=(h->GetBinContent(js)/h->GetBinContent(NBIN));
385 double amp2[ncorepix];
386 for (
int u=0;u<ncorepix;u++) amp2[u]=0.;
388 for(
int iu=0;iu<ncorepix;iu++){
389 tS->SetBranchAddress(
"central_time",&ttime);
390 tS->SetBranchAddress(
"amplitude",&);
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);
396 cout <<
"DisplayROC.C - wrong input cuts " << cuts2 << endl;
401 for(
int n=0;
n<tS->GetEntries();
n++) {
404 if(treeformula2!=NULL) {
405 if(treeformula2->EvalInstance()==0) {
415 if((ampTOT/h->GetBinContent(NBIN))>
REF) {
416 if(iu>0) ampFin=amp2[iu-1];
418 t_limit= timec2[ncorepix-1-iu];
427 SNRfi=ampFin/(h->GetBinContent(NBIN));
430 for(
int n=0;
n<V;
n++) {
432 if(!pix->
core)
continue;
433 if((irate)&&(irate !=
int(pix->
rate+0.5)))
continue;
439 if (SNRfi>0.&&SNRfi<=
REF&&(((
double)pix->
time/rate)/pix->
layers)>t_limit)
continue;
441 sSNR2 += pow(pix->
getdata(
'S',
m),2);
442 sSNR2 += pow(pix->
getdata(
'P',
m),2);
443 wSNR2 += pow(pix->
getdata(
'W',
m),2);
444 wSNR2 += pow(pix->
getdata(
'U',
m),2);
446 double null2 = wSNR2-sSNR2;
447 int iRATE = RATE/(pix->
layers-1);
452 int i=(itime-iminTime)*maxRate;
454 if(iRATE!=irate && irate!=0)
continue;
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);
468 int imin=
hist2D->GetNbinsX();
470 int jmin=
hist2D->GetNbinsY();
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);
492 int di = imax-imin+1;
493 int dj = jmax-jmin+1;
499 if (di%
NDIM==0) ri=0;
500 if (dj%
NDIM==0) rj=0;
558 int xdim = (imax-imin+1)/
NDIM;
559 int ydim = (jmax-jmin+1)/
NDIM;
565 for (
int i=0;
i<=
hist2D->GetNbinsX();
i++) {
567 for (
int j=0;
j<=
hist2D->GetNbinsY();
j++) {
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);
584 if (
i<imin && ripi==
false)
continue;
585 if (
j<jmin && ripj==
false)
continue;
587 if (
i<imin && ripi==
true) {
i=
i+xdim;ripi2=
true;}
588 if (
j<jmin && ripj==
true) {
j=
j-ydim;ripj2=
true;}
591 int I = (
i-imin)/xdim;
592 int J = (
j-jmin)/ydim;
600 if (ripi2==
true)
i=
i-xdim;
601 if (ripj2==
true)
j=
j+ydim;
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;
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;
631 nframe = sqrt(nframe);
634 hist2D=
new TH2F(
"frame",
"frame", nframe, 0, nframe, nframe, 0, nframe);
638 hist2D->SetFillColor(kWhite);
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);
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);
659 hist2D->GetZaxis()->SetTitleOffset(0.6);
660 hist2D->GetZaxis()->SetTitleFont(42);
661 hist2D->GetZaxis()->CenterTitle(
true);
663 hist2D->GetXaxis()->SetLabelSize(0.03);
664 hist2D->GetYaxis()->SetLabelSize(0.03);
665 hist2D->GetZaxis()->SetLabelSize(0.03);
667 for(
int i=0;
i<nframe;
i++) {
668 for(
int j=0;
j<nframe;
j++) {
670 hist2D->SetBinContent(
i+1,
j+1,(*nn_frame)[
i*nframe+
j]);
675 canvas=
new TCanvas(
"mra",
"mra", 200, 20, 600, 600);
677 canvas->ToggleEventStatus();
680 canvas->SetFillColor(kWhite);
681 canvas->SetRightMargin(0.10);
682 canvas->SetLeftMargin(0.10);
683 canvas->SetBottomMargin(0.13);
687 gStyle->SetFrameBorderMode(0);
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);
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);
714 sprintf(fname,
"nn_frame_display_%d.png",cid);
715 cout <<
"write " << fname << endl;
std::vector< vector_int > cRate
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
void ClusterToFrameNew01_dtmin_approx_cent(TString ifName, TString ofName)
std::vector< vector_int > cList
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
void PlotFrame(std::vector< double > *nn_frame, int cid)
netpixel * getPixel(size_t n, size_t i)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double getdata(char type='R', size_t n=0)
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)