21 #pragma GCC system_header 28 #include "TObjArray.h" 29 #include "TObjString.h" 30 #include "TPaletteAxis.h" 31 #include "TMultiLayerPerceptron.h" 32 #include "TMLPAnalyzer.h" 65 void Average(
TString NN_FILE,
TString NN_FILE2,
TString NN_FILE3,
TString NN_FILE4,
TString NN_FILE5,
TString NN_FILE6,
TString NN_FILE7,
TString NN_FILE8,
TString TEST_FILE,
TString NOMEtot_S,
int TS=0,
int TB=0,
int s=0,
int b=0,
int uf=1,
int consider_all=1){
70 if (uf!=0&&consider_all==0) ni=1;
74 if (NN_FILE.CompareTo(
"")){
77 if (NN_FILE2.CompareTo(
"")){
80 if (NN_FILE3.CompareTo(
"")){
83 if (NN_FILE4.CompareTo(
"")){
86 if (NN_FILE5.CompareTo(
"")){
89 if (NN_FILE6.CompareTo(
"")){
92 if (NN_FILE7.CompareTo(
"")){
95 if (NN_FILE8.CompareTo(
"")){
102 char NNi2[nNN][1024];
103 sprintf(NNi2[0],
"%s",NN_FILE.Data());
104 if(nNN>1)
sprintf(NNi2[1],
"%s",NN_FILE2.Data());
105 if(nNN>2)
sprintf(NNi2[2],
"%s",NN_FILE3.Data());
106 if(nNN>3)
sprintf(NNi2[3],
"%s",NN_FILE4.Data());
107 if(nNN>4)
sprintf(NNi2[4],
"%s",NN_FILE5.Data());
108 if(nNN>5)
sprintf(NNi2[5],
"%s",NN_FILE6.Data());
109 if(nNN>6)
sprintf(NNi2[6],
"%s",NN_FILE7.Data());
110 if(nNN>7)
sprintf(NNi2[7],
"%s",NN_FILE8.Data());
113 for (
int u=0;u<nNN;u++){
116 if (NNi2[u][p]==
'N'){
117 if((NNi2[u][p+1]==
'N')&&(NNi2[u][p+2]==
'\/')) {
119 while (NNi2[u][hh]!=
'\0'){NNi[u][hh-p-3]=NNi2[u][
hh];hh=hh+1;}
131 sprintf(Filei2,
"%s",TEST_FILE.Data());
133 if(Filei2[q]==
'n'&&Filei2[q+1]==
'n'&&Filei2[q+2]==
'T'&&Filei2[q+3]==
'R'&&Filei2[q+4]==
'E'&&(Filei2[q+5]==
'E')&&(Filei2[q+6]==
'\/')) {
135 while (Filei2[hh]!=
'\0') {Filei[hh-q-7]=Filei2[
hh];hh=hh+1;
137 for (
int h0=hh-q-7;h0<1024;h0++) Filei[h0]=
'\0';
143 cout<<Filei<<
" original String: "<<Filei2<<endl;
148 if(nNN>1) NNi0[1]=NNi[1];
149 if(nNN>2) NNi0[2]=NNi[2];
150 if(nNN>3) NNi0[3]=NNi[3];
151 if(nNN>4) NNi0[4]=NNi[4];
152 if(nNN>5) NNi0[5]=NNi[5];
153 if(nNN>6) NNi0[6]=NNi[6];
154 if(nNN>7) NNi0[7]=NNi[7];
159 for (
int u=0;u<nNN;u++){
160 NNi0[u].ReplaceAll(
".root",
"");
162 Filei0.ReplaceAll(
".root",
"");
166 TMultiLayerPerceptron* mlp[nNN];
172 for (
int yy=0;
yy<nNN;
yy++){TotBg[
yy]=0;FA0[
yy]=0;FD0[
yy]=0;}
184 for (
int u=0;u<nNN;u++){
185 fnet[u]=TFile::Open(NNi2[u]);
186 mlp[u]=(TMultiLayerPerceptron*)fnet[u]->Get(
"TMultiLayerPerceptron");
188 cout<<
"dopo TMLP"<<endl;
189 if(mlp[u]==NULL) {cout <<
"Error getting mlp" << endl;
exit(1);}
190 infot[u]=(TTree*)fnet[u]->Get(
"info");
192 infot[u]->SetBranchAddress(
"Rand_start_Sig",&NNs[u]);
193 infot[u]->SetBranchAddress(
"Rand_start_Bg",&NNb[u]);
194 infot[u]->SetBranchAddress(
"#trainSig",&NNnTS[u]);
195 infot[u]->SetBranchAddress(
"#trainBg",&NNnTB[u]);
196 infot[u]->GetEntry(0);
197 cout<<
"n "<<u<<
" b "<<NNb[u]<<
" min_NNb "<<min_NNb<<endl;
199 if(NNs[u]<min_NNs) min_NNs=NNs[u];
200 if(NNb[u]<min_NNb) min_NNb=NNb[u];
201 cout<<
"n "<<u<<
" s "<<NNs[u]<<
" b "<<NNb[u]<<
" s fin "<<NNs[u]+NNnTS[u]<<
" b fin "<<NNb[u]+NNnTB[u]<<
" nTS "<<NNnTS[u]<<
" nTB "<<NNnTB[u]<<endl;
207 for (
int u=0;u<nNN;u++){
208 if((NNb[u]<b||NNb[u]==b)&&b>NNb[u]+ NNnTB[u]) b_ok=1;
209 if((NNs[u]<
s||NNs[u]==
s)&&b>NNs[u]+ NNnTS[u]) s_ok=1;
215 if (uf!=0&&ni==0&&(b_ok==0)){ b=min_NNb;cout<<
" change b value to have BKG events used for training procedures, b="<<b<<endl;}
216 if (uf!=0&&ni==0&&(s_ok==0)){
s=min_NNs;cout<<
" change s value to have SIG events used for training procedures s="<<
s<<endl;}
217 cout<<
" min_NNb "<<min_NNb<<
" b "<<b<<endl;
218 cout<<
"Def. tree e mlp"<<endl;
221 TFile* fTEST =TFile::Open(TEST_FILE.Data());
222 TTree* NNTree=(TTree*)fTEST->Get(
"nnTree");
223 int entries=NNTree->GetEntries();
224 cout<<
"entries: "<<entries<<endl;
234 NNTree->SetBranchAddress(
"#Entries_type",&entriesTot);
235 NNTree->SetBranchAddress(
"Matrix_dim",&ndim);
236 NNTree->SetBranchAddress(
"#inputs",&ninp);
237 NNTree->SetBranchAddress(
"amplitude_mode",&y);
240 sig_entries=entriesTot;
241 NNTree->GetEntry(entries-1);
242 bg_entries=entriesTot;
247 cout<<
"NDIM: "<<NDIM<<endl;
248 cout<<
"nINP: "<<nINP<<endl;
249 cout<<
"sig e: "<<sig_entries<<endl;
250 cout<<
"bg e: "<<bg_entries<<endl;
254 if (sig_entries>bg_entries) minevents=bg_entries;
255 else minevents=sig_entries;
267 cout<<
"Error: Bg index<sig_entries: new set of b parameter-> b="<<b<<
" instead of b="<<a<<endl;
272 if((TS>sig_entries-
s||
TB>(bg_entries-(b-sig_entries)))&&(TS==
TB)) {TS=minevents-
s;
TB=minevents-(b-sig_entries);
275 cout<<
"Error:S>sig_entries or TB>bg_entries, to maintain ugual number of analysed events TS=TB="<<
TB<<endl;
277 if((TS>sig_entries-
s||
TB>bg_entries-(b-sig_entries))&&(TS!=
TB)) {
278 if(TS>sig_entries) TS=sig_entries-
s;
279 if (
TB>bg_entries)
TB=bg_entries-(b-sig_entries);
280 cout<<
"Error:TS>sig_entries or TB>bg_entries, new TS and TB values are thus define-> TS="<<TS<<
" TB="<<
TB<<endl;
285 sprintf(NOMEtot,
"%s",NOMEtot_S.Data());
286 cout<<
"output name: "<<NOMEtot<<endl;
292 NNTree->SetBranchAddress(
"Files_name",&FILE_NAME);
295 NNTree->GetEntry(entries-1);
297 cout<<
"fine ifdef RHO_CC"<<endl;
300 TChain sigTree(
"waveburst");
301 sigTree.Add(SIG_FILE.Data());
304 cout <<
"sig entries2 : " << sig_entries2 << endl;
306 TChain bgTree(
"waveburst");
307 bgTree.Add(BG_FILE.Data());
310 cout <<
"bg entries2 : " << bg_entries2 << endl;
312 cout<<
"b: "<<b<<endl;
313 cout<<
"s: "<<
s<<endl;
317 for (
int jj=0; jj<nINP;jj++) x[jj]=0.;
318 char ilabel[nINP][16];
321 for(
int i=0;
i<nINP;
i++) {
323 NNTree->SetBranchAddress(ilabel[i], &x[i]);
327 sprintf(ofile,
"average_file/%s.root",NOMEtot);
328 TFile*
f =
new TFile(ofile,
"RECREATE");
329 TTree* NNTree2=
new TTree(
"Parameters",
"Parameters");
330 NNTree2->SetDirectory(f);
335 for(
int y=0; y<nNN; y++) out[y]=0.;
342 NNTree2->Branch(
"Average",&average,
"Average/D");
343 NNTree2->Branch(
"StandardDevaition",&std,
"StandardDeviation/D");
344 NNTree2->Branch(
"cc",&NNcc,
"cc/D");
345 NNTree2->Branch(
"Mchirp",&Mc,
"Mchirp/D");
346 NNTree2->Branch(
"rho",&NNrho,
"rho/D");
348 for(
int u=0;u<nNN;u++){
354 sprintf(NNoutl2,
"NNout%i/D",u);
356 sprintf(NNnamel2,
"NNname%i/C",u);
357 NNTree2->Branch(NNoutl,&out[u],NNoutl2);
358 NNTree2->Branch(NNnamel,&NNi[u],NNnamel2);
362 NNTree2->Branch(
"TestFile",&Testf,
"TestFile/C");
363 sprintf(Testf,
"%s",TEST_FILE.Data());
366 NNTree2->Branch(
"#TestSig",&nTestS,
"#TestSig/I");
367 cout<<
"nTestS: "<<nTestS<<
" TS: "<<TS<<endl;
368 cout<<
"dopo def tree"<<endl;
374 for(
int n=
s;
n<
s+TS;
n++) {
376 for(
int u=0;u<nNN;u++){
377 if (uf!=0&&
n>NNs[u]&&
n<(NNs[u]+NNnTS[u])) countNN=countNN+1;
379 if(countNN==1&&ni==0) scount=scount+1;
380 if(countNN<2&&ni!=0) scount=scount+1;
381 if(countNN>1){cout<<
"Error: training non independent"<<
n<<endl;
exit(0);}
386 cout<<
"s test "<<
s<<
" s+TS "<<
s+TS<<
" b "<<b<<
" b+ TB "<<b+
TB<<
" nTestS "<<nTestS<<endl;
390 for (
int i=0;
i<nINP;
i++) params[
i]=0.;
395 for(
int n=
s;
n<
s+TS;
n++) {
399 for(
int u=0;u<nNN;u++){
400 if (uf!=0&&
n>=NNs[u]&&
n<(NNs[u]+NNnTS[u])) { indNN=u;countNN=countNN+1;}
402 if (countNN>1){cout<<
"Error: training non independent";
exit(0);}
403 if(nNN==1){cout<<
"out==Averege:only 1NN is considered"<<endl;}
404 if(ni==0&&countNN==0)
continue;
409 NNcc=(double)signal.
netcc[1];
410 NNrho=(
double)signal.
rho[0];
414 for (
int i=0;
i<nINP;
i++){
417 for (
int u=0;u<nNN;u++) {
418 cout<<
" u "<<u<<
" nNN "<<nNN<<endl;
419 double output=mlp[u]->Evaluate(0,params);
425 cout<<
"Dopo param"<<endl;
433 for (
int u=0;u<nNN;u++){
434 if((u!=indNN&&ni==0)||uf==0) {average=out[u]+average;std+=out[u]*out[u];
if(out[u]<0.6) FD0[u]=FD0[u]+1;}
438 if(nNN!=1&&ni==0) {average=average/(nNN-countNN);
if((nNN-1-countNN)!=0)std=pow((std/(nNN-1-countNN)-average*average),0.5);
else std=pow((std/(nNN-countNN)-average*average),0.5);}
443 if(nNN!=1&&uf==0) {average=average/(nNN);
if((nNN-1)!=0)std=pow((std/(nNN-1)-average*average),0.5);
else std=pow((std/nNN-average*average),0.5);}
444 cout<<
"average: "<<average<<endl;
445 cout<<
"Mc "<<Mc<<endl;
446 if (average<0.6) FD=FD+1;
455 cout<<
"riempito sig S_eff"<<S_eff<<endl;
463 for(
int n=b;
n<b+
TB;
n++) {
467 for(
int u=0;u<nNN;u++){
468 cout<<
" uf "<<uf<<
" n "<<
n<<
" u "<<u<<
" NN b[u] "<<NNb[u]<<
" NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
469 if (uf!=0&&
n>=NNb[u]&&
n<(NNb[u]+NNnTB[u])) { indNN=u;countNN=countNN+1; }
472 if (countNN>1){cout<<
"Error: training non independent";
exit(0);}
473 if(nNN==1){cout<<
"out==Averege:only 1NN is considered"<<endl;}
474 if(ni==0&&countNN==0){ cout<<
"countNN"<<countNN<<endl;
continue;}
477 cout<<
"BKG->n: "<<
n<<
"Bg index"<<(
n-sig_entries)<<endl;
479 NNcc=(double)background.
netcc[1];
480 NNrho=(
double)background.
rho[0];
482 for (
int i=0;
i<nINP;
i++){
486 for(
int u=0;u<nNN;u++) {
487 double output=mlp[u]->Evaluate(0,params);
492 for (
int u=0;u<nNN;u++){
493 if((u!=indNN&&ni==0)||ni!=0) { cout<<
" u "<<u<<
" n "<<
n<<
" FA0[u] "<<FA0[u]<<endl;average=out[u]+average;std=out[u]*out[u];TotBg[u]=TotBg[u]+1;
if(out[u]>0.6) {FA0[u]=FA0[u]+1;nnsu=nnsu+1;}}
495 if(nnsu==6) cont_su=cont_su+1;
496 if(nnsu>4) cont_su5=cont_su5+1;
497 if(nnsu>3) cont_su4=cont_su4+1;
498 if(nnsu>2) cont_su3=cont_su3+1;
501 if(nNN!=1&&ni==0) {cout<<average<<endl;average=average/(nNN-countNN);
502 cout<<
"ni==0"<<average<<endl;
if((nNN-1-countNN)!=0)std=pow((std/(nNN-1-countNN)-average*average),0.5);
else std=pow((std/(nNN-countNN)-average*average),0.5);}
508 if(nNN!=1&&uf==0) {cout<<average<<endl;average=average/(nNN);
if((nNN-1)!=0)std=pow((std/(nNN-1)-average*average),0.5);
else std=pow((std/nNN-average*average),0.5); cout<<
"uf==0"<<average<<endl;}
509 cout<<
"average: "<<average<<endl;
512 if(average>0.6) FA=FA+1;
517 cout<<
"bkg filled"<<endl;
522 cout<<
"closed file"<<endl;
526 cout<<
" S_eff "<<S_eff<<
" B_eff "<<B_eff<<endl;
532 for (
int yy=0;
yy<nNN;
yy++){
534 cout<<
" FA0[yy] "<<FA0[
yy]<<
" FD0[yy] "<<FD0[
yy]<<
" FD "<<FD<<
" TotBg[yy] "<<TotBg[
yy]<<endl;
535 if(TotBg[
yy]!=0){freq_c[
yy]=(double)FA0[
yy]/TotBg[
yy];cout<<
" freq_c[yy] "<<freq_c[
yy]<<endl;}
536 if(freq_c[
yy]!=0) {meanf=freq_c[
yy]+meanf;cont=cont+1;cout<<
" cont "<<cont<<endl;}
537 dev=freq_c[
yy]*freq_c[
yy]+dev;
540 if(cont==0) cout<<
"Error cont==0"<<endl;
541 if(cont!=0) meanf=meanf/cont;
543 for (
int yy=0;
yy<nNN;
yy++){
544 cout<<
" dev "<<dev<<endl;
545 cout<<
"freq_c[yy] "<<freq_c[
yy]<<
" meanf "<<meanf<<endl;
546 if(freq_c[
yy]!=0)dev+=(freq_c[
yy]-meanf)*(freq_c[
yy]-meanf);
552 if(cont!=0) dev=pow(dev/(cont-1),0.5);
553 cout<<
"meanf "<<meanf<<
" dev "<<dev<<endl;
554 cout<<
" FA average "<<FA<<endl;
555 cout<<
" cont_su "<<cont_su<<
" cont_su5 "<<cont_su5<<
" cont_su4 "<<cont_su4<<
" cont_su3 "<<cont_su3<<endl;
557 cout<<
" FA0[1] "<<FA0[1]<<
" TotBg[1] "<<TotBg[1]<<endl;
558 cout<<
" FD0[1] "<<FD0[1]<<
" TotBg[1] "<<TotBg[1]<<endl;
563 name.ReplaceAll(
"average_file/",
"");
564 TFile* fTEST =TFile::Open(ifile.Data());
565 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
570 NNTree2->SetBranchAddress(
"Average",&av);
571 NNTree2->SetBranchAddress(
"cc",&cc);
572 NNTree2->SetBranchAddress(
"rho",&rho);
573 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
574 NNTree2->GetEntry(0);
576 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
577 cout<<
" BG: "<<NNTree2->GetEntries()-nSi<<endl;
579 cout<<
"dentro funzione dopodef"<<endl;
581 double* rhoSig[ncurve];
582 for (
int i=0;
i<ncurve;
i++) rhoSig[
i]=
new double[nSig];
583 cout<<
"dopo def rhoSig"<<endl;
587 int const nBg=NNTree2->GetEntries()-nSig;
588 for (
int i=0;
i<ncurve;
i++) {
590 for (
int j=0;
j<nSig;
j++) rhoSig[
i][
j]=0.;
592 cout<<
"dopo def rhoSig"<<endl;
593 double* rhoBg[ncurve];
594 for (
int i=0;
i<ncurve;
i++) rhoBg[
i]=
new double[nBg];
597 for (
int i=0;
i<ncurve;
i++) {
599 for (
int j=0;
j<nBg;
j++) rhoBg[
i][
j]=0.;
601 cout<<
"dopo def rhoBg"<<endl;
603 for (
int i=0;
i<
nCC;
i++) ccTh[
i]=0.;
605 for (
int i=0;
i<
nANN;
i++) NNTh[
i]=0.;
611 cout<<NNTree2->GetEntries()<<endl;
612 for(
int n=0;
n<NNTree2->GetEntries();
n++){
614 NNTree2->GetEntry(
n);
615 cout<<
"rho "<<rho<<
" cc "<<cc<<
" av "<<av<<endl;
618 if(cc<ccTh[
i])
continue;
620 if(
j==0) NNTh[
j]=-1000.;
626 if(av<NNTh[
j])
continue;
630 NBg[i*nANN+
j]= NBg[i*nANN+
j]+1;
631 while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
632 rhoBg[i*nANN+
j][ni]=
rho;
637 NSig[i*nANN+
j]= NSig[i*nANN+
j]+1;
638 while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
639 rhoSig[i*nANN+
j][ni]=
rho;
647 cout<<
"dopo riempimento variabili"<<endl;
649 for (
int i=0;
i<ncurve;
i++) indexS[
i]=
new int[nSig];
652 for (
int y=0;
y<ncurve;
y++) {
665 TMath::Sort(nSig,rhoSig[
y],indexS[y],
false);
667 for (
int k=0;
k<nSig;
k++) {
672 int ij=indexS[
y][
k-1];
674 if(rhoSig[y][ii]!=0) {
677 if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[
y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
678 cout<<
"igS"<<igS<<
" x "<<rhoSig[
y][ii]<<
" y: "<<yy<<endl;
683 if(rhoSig[y][ii]!=0){
685 gS[
y]->SetPoint(0,rhoSig[y][ii],yy);
696 for (
int i=0;
i<ncurve;
i++) indexB[
i]=
new int[nBg];
699 for (
int y=0;
y<ncurve;
y++) {
703 TMath::Sort(nBg,rhoBg[
y],indexB[y],
false);
705 for (
int k=0;
k<nBg;
k++) {
709 int ij=indexB[
y][
k-1];
711 if(rhoBg[y][ii]!=0) {
714 if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[
y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
720 if(rhoBg[y][ii]!=0) {
722 gB[
y]->SetPoint(0,rhoBg[y][ii],yy);
729 cout<<
"dopo inserimento puntiB"<<endl;
732 TCanvas* cS=
new TCanvas(
"Efficiency_vs_rho",
"Efficiency_vs_rho",0,0,1200,700);
734 cS->cd(1)->SetLogy();
735 TMultiGraph* mg1=
new TMultiGraph();
737 gS[0]->SetMarkerColor(2);
738 gS[0]->SetLineColor(2);
739 mg1->SetTitle(
"cc=0.5;rho;#Events");
740 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
743 gS[
h]->SetMarkerColor(3);
744 gS[
h]->SetLineColor(3);
746 if(gS[
h]->GetN()!=0) mg1->Add(gS[
h]);
750 cS->cd(2)->SetLogy();
751 TMultiGraph* mg2=
new TMultiGraph();
753 gS[
nANN]->SetMarkerColor(2);
754 gS[
nANN]->SetLineColor(2);
755 mg2->SetTitle(
"cc=0.55;rho;#Events");
756 if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
758 gS[nANN+
h]->SetMarkerColor(3);
759 gS[nANN+
h]->SetLineColor(3);
761 if(gS[nANN+
h]->GetN()!=0) mg2->Add(gS[nANN+
h]);
765 cS->cd(3)->SetLogy();
766 TMultiGraph* mg3=
new TMultiGraph();
768 gS[nANN*2]->SetMarkerColor(2);
769 gS[nANN*2]->SetLineColor(2);
770 mg3->SetTitle(
"cc=0.6;rho;#Events");
771 if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
773 gS[2*nANN+
h]->SetMarkerColor(3);
774 gS[2*nANN+
h]->SetLineColor(3);
776 if(gS[2*nANN+
h]->GetN()!=0) mg3->Add(gS[2*nANN+
h]);
780 cS->cd(4)->SetLogy();
781 TMultiGraph* mg4=
new TMultiGraph();
783 gS[nANN*3]->SetMarkerColor(2);
784 gS[nANN*3]->SetLineColor(2);
785 mg4->SetTitle(
"cc=0.65;rho;#Events");
786 if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
789 gS[3*nANN+
h]->SetMarkerColor(3);
790 gS[3*nANN+
h]->SetLineColor(3);
792 if(gS[3*nANN+
h]->GetN()!=0) mg4->Add(gS[3*nANN+
h]);
796 cout<<
"nuovo canv"<<endl;
797 TCanvas* cB=
new TCanvas(
"Number_vs_rho",
"Number_vs_rho",0,0,1200,700);
799 cB->cd(1)->SetLogy();
800 TMultiGraph* mg1B=
new TMultiGraph();
802 gB[0]->SetMarkerColor(2);
803 gB[0]->SetLineColor(2);
804 mg1B->SetTitle(
"cc=0.5;rho;#Events");
805 if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
807 gB[
h]->SetMarkerColor(3);
808 gB[
h]->SetLineColor(3);
810 if(gB[
h]->GetN()!=0) mg1B->Add(gB[
h]);
814 cB->cd(2)->SetLogy();
815 TMultiGraph* mg2B=
new TMultiGraph();
817 gB[
nANN]->SetMarkerColor(2);
818 gB[
nANN]->SetLineColor(2);
819 mg2B->SetTitle(
"cc=0.55;rho;#Events");
820 if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
822 gB[nANN+
h]->SetMarkerColor(3);
823 gB[nANN+
h]->SetLineColor(3);
825 if(gB[nANN+
h]->GetN()!=0) mg2B->Add(gB[nANN+
h]);
829 cB->cd(3)->SetLogy();
830 TMultiGraph* mg3B=
new TMultiGraph();
832 gB[2*
nANN]->SetMarkerColor(2);
833 gB[2*
nANN]->SetLineColor(2);
834 mg3B->SetTitle(
"cc=0.6;rho;#Events");
835 if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
837 gB[2*nANN+
h]->SetMarkerColor(3);
838 gB[2*nANN+
h]->SetLineColor(3);
840 if(gB[2*nANN+
h]->GetN()!=0) mg3B->Add(gB[2*nANN+
h]);
844 cB->cd(4)->SetLogy();
845 TMultiGraph* mg4B=
new TMultiGraph();
847 gB[3*
nANN]->SetMarkerColor(2);
848 gB[3*
nANN]->SetLineColor(2);
849 mg4B->SetTitle(
"cc=0.65;rho;#Events");
850 if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
852 gB[3*nANN+
h]->SetMarkerColor(3);
853 gB[3*nANN+
h]->SetLineColor(3);
855 if(gB[3*nANN+
h]->GetN()!=0) mg4B->Add(gB[3*nANN+
h]);
867 char CnameS2root[1024];
868 char CnameB2root[1024];
869 CnameS.ReplaceAll(
".root",
".png");
870 CnameB.ReplaceAll(
".root",
".png");
871 sprintf(CnameS2,
"logN_rho_av/logN_rho_S_dANN%1.2f_%s",
deltaANN,CnameS.Data());
872 sprintf(CnameB2,
"logN_rho_av/logN_rho_B_dANN%1.2f_%s",
deltaANN,CnameB.Data());
873 sprintf(CnameS2root,
"logN_rho_av/logN_rho_S_dANN%1.2f_%s",
deltaANN,CnameSroot.Data());
874 sprintf(CnameB2root,
"logN_rho_av/logN_rho_B_dANN%1.2f_%s",
deltaANN,CnameBroot.Data());
877 cS->Print(CnameS2root);
878 cB->Print(CnameB2root);
886 name.ReplaceAll(
"average_file/",
"");
887 TFile* fTEST =TFile::Open(ifile.Data());
888 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
893 NNTree2->SetBranchAddress(
"Average",&av);
894 NNTree2->SetBranchAddress(
"cc",&cc);
895 NNTree2->SetBranchAddress(
"rho",&rho);
896 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
897 NNTree2->GetEntry(0);
903 double* ANNSig[ncurve2];
904 for (
int i=0;
i<ncurve2;
i++) ANNSig[
i]=
new double[nSig];
908 int const nBg=NNTree2->GetEntries()-nSig;
909 for (
int i=0;
i<ncurve2;
i++) {
911 for (
int j=0;
j<nSig;
j++) ANNSig[
i][
j]=0.;
913 double* ANNBg[ncurve2];
914 for (
int i=0;
i<ncurve2;
i++) ANNBg[
i]=
new double[nBg];
918 for (
int i=0;
i<ncurve2;
i++) {
920 for (
int j=0;
j<nBg;
j++) ANNBg[
i][
j]=0.;
923 for (
int i=0;
i<
nCC;
i++) ccTh[
i]=0.;
925 for (
int i=0;
i<
nRHO;
i++) rhoTh[
i]=0.;
932 for(
int n=0;
n<NNTree2->GetEntries();
n++){
933 NNTree2->GetEntry(
n);
934 cout<<
"rho "<<rho<<
" cc "<<cc<<
" av "<<av<<endl;
937 if(cc<ccTh[
i])
continue;
940 if(rho<rhoTh[
j])
continue;
943 NBg[i*nRHO+
j]= NBg[i*nRHO+
j]+1;
944 while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
945 ANNBg[i*nRHO+
j][ni]=av;
949 NSig[i*nRHO+
j]= NSig[i*nRHO+
j]+1;
950 while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
951 ANNSig[i*nRHO+
j][ni]=av;
958 int* indexS[ncurve2];
959 for (
int i=0;
i<ncurve2;
i++) indexS[
i]=
new int[nSig];
961 TGraph * gS[ncurve2];
962 for (
int y=0;
y<ncurve2;
y++) {
966 TMath::Sort(nSig,ANNSig[
y],indexS[y],
false);
967 for (
int k=0;
k<nSig;
k++) {
972 int ij=indexS[
y][
k-1];
974 if(ANNSig[y][ii]!=0) {
977 if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[
y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
984 if(ANNSig[y][ii]!=0){
986 gS[
y]->SetPoint(0,ANNSig[y][ii],yy);
997 int* indexB[ncurve2];
998 for (
int i=0;
i<ncurve2;
i++) indexB[
i]=
new int[nBg];
1000 TGraph * gB[ncurve2];
1001 for (
int y=0;
y<ncurve2;
y++) {
1005 TMath::Sort(nBg,ANNBg[
y],indexB[y],
false);
1007 for (
int k=0;
k<nBg;
k++) {
1008 int ii=indexB[
y][
k];
1011 int ij=indexB[
y][
k-1];
1013 if(ANNBg[y][ii]!=0) {
1016 if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[
y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
1022 if(ANNBg[y][ii]!=0) {
1024 gB[
y]->SetPoint(0,ANNBg[y][ii],yy);
1033 TCanvas* cS=
new TCanvas(
"Efficiency_vs_ANN",
"Efficiency_vs_ANN",0,0,1200,700);
1037 TMultiGraph* mg1=
new TMultiGraph();
1038 mg1->SetTitle(
"cc=0.5;ANN;#Events");
1040 gS[
h]->SetLineColor(4);
1041 if(gS[
h]->GetN()!=0) mg1->Add(gS[
h]);
1046 TMultiGraph* mg2=
new TMultiGraph();
1047 mg2->SetTitle(
"cc=0.55;ANN;#Events");
1049 gS[nRHO+
h]->SetLineColor(4);
1050 if(gS[nRHO+
h]->GetN()!=0) mg2->Add(gS[nRHO+
h]);
1056 TMultiGraph* mg3=
new TMultiGraph();
1057 mg3->SetTitle(
"cc=0.6;ANN;#Events");
1059 gS[2*nRHO+
h]->SetLineColor(4);
1060 if(gS[2*nRHO+
h]->GetN()!=0) mg3->Add(gS[2*nRHO+
h]);
1065 TMultiGraph* mg4=
new TMultiGraph();
1066 mg4->SetTitle(
"cc=0.65;ANN;#Events");
1068 gS[3*nRHO+
h]->SetLineColor(4);
1069 if(gS[3*nRHO+
h]->GetN()!=0) mg4->Add(gS[3*nRHO+
h]);
1073 TCanvas* cB=
new TCanvas(
"Number_vs_ANN",
"Number_vs_ANN",0,0,1200,700);
1075 cB->cd(1)->SetLogy();
1076 TMultiGraph* mg1B=
new TMultiGraph();
1077 mg1B->SetTitle(
"cc=0.5;ANN;#Events");
1079 gB[
h]->SetLineColor(4);
1080 if(gB[
h]->GetN()!=0) mg1B->Add(gB[
h]);
1083 cB->cd(2)->SetLogy();
1084 TMultiGraph* mg2B=
new TMultiGraph();
1085 mg2B->SetTitle(
"cc=0.55;ANN;#Events");
1087 gB[nRHO+
h]->SetLineColor(4);
1088 if(gB[nRHO+
h]->GetN()!=0) mg2B->Add(gB[nRHO+
h]);
1091 cB->cd(3)->SetLogy();
1092 TMultiGraph* mg3B=
new TMultiGraph();
1093 mg3B->SetTitle(
"cc=0.6;ANN;#Events");
1095 gB[2*nRHO+
h]->SetLineColor(4);
1096 if(gB[2*nRHO+
h]->GetN()!=0) mg3B->Add(gB[2*nRHO+
h]);
1099 cB->cd(4)->SetLogy();
1100 TMultiGraph* mg4B=
new TMultiGraph();
1101 mg4B->SetTitle(
"cc=0.6;ANN;#Events");
1103 gB[3*nRHO+
h]->SetLineColor(4);
1104 if(gB[3*nRHO+
h]->GetN()!=0) mg4B->Add(gB[3*nRHO+
h]);
1116 char CnameS2root[1024];
1117 char CnameB2root[1024];
1118 CnameS.ReplaceAll(
".root",
".png");
1119 CnameB.ReplaceAll(
".root",
".png");
1120 sprintf(CnameS2,
"ANNthres_av/N_ANN_S_%s",CnameS.Data());
1121 sprintf(CnameB2,
"ANNthres_av/N_ANN_B_%s",CnameB.Data());
1122 sprintf(CnameS2root,
"ANNthres_av/N_ANN_S_%s",CnameSroot.Data());
1123 sprintf(CnameB2root,
"ANNthres_av/N_ANN_B_%s",CnameBroot.Data());
1124 cS->SaveAs(CnameS2);
1125 cB->SaveAs(CnameB2);
1126 cS->Print(CnameS2root);
1127 cB->Print(CnameB2root);
1139 name.ReplaceAll(
"outfile/",
"");
1140 name.ReplaceAll(
"average_file/",
"");
1141 TFile* fTEST =TFile::Open(ifile.Data());
1142 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
1150 NNTree2->SetBranchAddress(
"Average",&av);
1151 NNTree2->SetBranchAddress(
"cc",&cc);
1152 NNTree2->SetBranchAddress(
"rho",&rho);
1153 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
1154 NNTree2->GetEntry(0);
1156 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
1157 int const nBg=NNTree2->GetEntries()-nSig;
1158 cout<<
"nBg: "<<nBg<<
" Entries: "<<NNTree2->GetEntries()<<endl;
1165 for (
int n = 0;
n <NNTree2->GetEntries();
n++){
1166 NNTree2->GetEntry(
n);
1168 gS[0]->SetPoint(
n,cc,av);
1169 cout<<
"Sig_graph1: x="<<cc<<
" y: "<<av<<endl;
1172 gB[0]->SetPoint(
n-nSig,cc,av);
1173 cout<<
"Bg_graph1: x="<<cc<<
" y: "<<av<<endl;
1194 gS[0]->SetMarkerColor(2);
1195 gB[0]->SetMarkerColor(4);
1196 gS[0]->SetMarkerStyle(6);
1197 gB[0]->SetMarkerStyle(7);
1199 TCanvas*
c=
new TCanvas(
"Plots",
"Plots",0,0,1200,700);
1202 TMultiGraph* mg1=
new TMultiGraph();
1203 mg1->SetTitle(
"Av_cc");
1204 if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1205 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1207 mg1->GetHistogram()->GetXaxis()->SetTitle(
"cc");
1208 mg1->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1211 TMultiGraph* mg2=
new TMultiGraph();
1212 mg2->SetTitle(
"Av_cc");
1213 if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1214 if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1216 mg2->GetHistogram()->GetXaxis()->SetTitle(
"cc");
1217 mg2->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1219 cout<<
" name "<<name<<endl;
1223 char Cname2root[1024];
1224 Cname.ReplaceAll(
".root",
".png");
1225 sprintf(Cname2,
"average_png/out_Plots_%s",Cname.Data());
1226 sprintf(Cname2root,
"average_png/out_Plots_%s",Cnameroot.Data());
1228 c->Print(Cname2root);
1266 name.ReplaceAll(
"outfile/",
"");
1267 name.ReplaceAll(
"average_file/",
"");
1268 TFile* fTEST =TFile::Open(ifile.Data());
1269 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
1278 NNTree2->SetBranchAddress(
"Mchirp",&Mc);
1279 NNTree2->SetBranchAddress(
"Average",&av);
1280 NNTree2->SetBranchAddress(
"cc",&cc);
1281 NNTree2->SetBranchAddress(
"rho",&rho);
1282 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
1283 NNTree2->GetEntry(0);
1285 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
1286 int const nBg=NNTree2->GetEntries()-nSig;
1293 for (
int n = 0;
n <NNTree2->GetEntries();
n++){
1294 NNTree2->GetEntry(
n);
1296 gS[0]->SetPoint(
n,Mc,av);
1297 cout<<
"Sig_graph1: x="<<cc<<
" y: "<<av<<endl;
1300 gB[0]->SetPoint(
n-nSig,Mc,av);
1301 cout<<
"Bg_graph1: x="<<cc<<
" y: "<<av<<endl;
1318 gS[0]->SetMarkerColor(2);
1319 gB[0]->SetMarkerColor(4);
1320 gS[0]->SetMarkerStyle(6);
1321 gB[0]->SetMarkerStyle(7);
1323 TCanvas*
c=
new TCanvas(
"Plots",
"Plots",0,0,1200,700);
1326 TMultiGraph* mg1=
new TMultiGraph();
1327 mg1->SetTitle(
"Av_Mc");
1328 if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1329 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1331 mg1->GetHistogram()->GetXaxis()->SetTitle(
"Mchirp");
1332 mg1->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1334 TMultiGraph* mg2=
new TMultiGraph();
1335 mg2->SetTitle(
"Av_Mc");
1336 if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1337 if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1339 mg2->GetHistogram()->GetXaxis()->SetTitle(
"Mchirp");
1340 mg2->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1342 cout<<
" name "<<name<<endl;
1346 char Cname2root[1024];
1347 Cname.ReplaceAll(
".root",
".png");
1348 sprintf(Cname2,
"average_png/Mc_Plots_%s",Cname.Data());
1349 sprintf(Cname2root,
"average_png/Mc_Plots_%s",Cnameroot.Data());
1351 c->Print(Cname2root);
void graph(TString ifile)
Float_t * rho
biased null statistics
wavearray< double > a(hp.size())
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<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ 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
void Average(TString NN_FILE, TString NN_FILE2, TString NN_FILE3, TString NN_FILE4, TString NN_FILE5, TString NN_FILE6, TString NN_FILE7, TString NN_FILE8, TString TEST_FILE, TString NOMEtot_S, int TS=0, int TB=0, int s=0, int b=0, int uf=1, int consider_all=1)
void PlotsAv_Mc(TString ifile)
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
cout<< "Injected signals: "<< mdc.GetEntries()<< endl;cout<< "Injected signals in histogram factor_events_inj: "<< NEVTS<< endl;float myifar, ecor, m1, m2, netcc[3], neted, penalty;float rho[2];float chirp[6];float range[2];float frequency[2];float iSNR[3], sSNR[3];sim.SetBranchAddress("mass", mass);sim.SetBranchAddress("factor", &factor);sim.SetBranchAddress("range", range);sim.SetBranchAddress("chirp", chirp);sim.SetBranchAddress("rho", rho);sim.SetBranchAddress("netcc", netcc);sim.SetBranchAddress("neted", &neted);sim.SetBranchAddress("ifar", &myifar);sim.SetBranchAddress("ecor", &ecor);sim.SetBranchAddress("penalty", &penalty);sim.SetBranchAddress("time", mytime);sim.SetBranchAddress("iSNR", iSNR);sim.SetBranchAddress("sSNR", sSNR);sim.SetBranchAddress("spin", spin);sim.SetBranchAddress("frequency", frequency);float **volume=new float *[NBINS_mass1];float **volume_first_shell=new float *[NBINS_mass1];float **radius=new float *[NBINS_mass1];float **error_volume=new float *[NBINS_mass1];float **error_volume_first_shell=new float *[NBINS_mass1];float **error_radius=new float *[NBINS_mass1];for(int i=0;i< NBINS_mass1;i++) { volume[i]=new float[NBINS_mass2];volume_first_shell[i]=new float[NBINS_mass2];radius[i]=new float[NBINS_mass2];error_volume[i]=new float[NBINS_mass2];error_volume_first_shell[i]=new float[NBINS_mass2];error_radius[i]=new float[NBINS_mass2];for(int j=0;j< NBINS_mass2;j++) { volume[i][j]=0.;volume_first_shell[i][j]=0.;radius[i][j]=0.;error_volume[i][j]=0.;error_volume_first_shell[i][j]=0.;error_radius[i][j]=0.;} } float **spin_mtot_volume=new float *[NBINS_MTOT+1];float **spin_mtot_radius=new float *[NBINS_MTOT+1];float **error_spin_mtot_volume=new float *[NBINS_MTOT+1];float **error_spin_mtot_radius=new float *[NBINS_MTOT+1];for(int i=0;i< NBINS_MTOT+1;i++) { spin_mtot_volume[i]=new float[NBINS_SPIN+1];spin_mtot_radius[i]=new float[NBINS_SPIN+1];error_spin_mtot_volume[i]=new float[NBINS_SPIN+1];error_spin_mtot_radius[i]=new float[NBINS_SPIN+1];for(int j=0;j< NBINS_SPIN+1;j++) { spin_mtot_volume[i][j]=0.;error_spin_mtot_volume[i][j]=0.;spin_mtot_radius[i][j]=0.;error_spin_mtot_radius[i][j]=0.;} } char fname[1024];sprintf(fname, "%s/recovered_signals.txt", netdir);ofstream fev;fev.open(fname, std::ofstream::out);sprintf(line, "#GPS@L1 FAR[Hz] eFAR[Hz] Pval " "ePval factor rho frequency iSNR sSNR \");fev<< line<< endl;ofstream *fev_single=new ofstream[nfactor];for(int l=1;l< nfactor+1;l++) { sprintf(fname, "%s/recovered_signals_%d.txt", netdir, l);fev_single[l - 1].open(fname, std::ofstream::out);fev_single[l - 1]<< line<< endl;} double Vrho[RHO_NBINS], eVrho[RHO_NBINS], Rrho[RHO_NBINS], eRrho[RHO_NBINS], Trho[RHO_NBINS];for(int i=0;i< RHO_NBINS;i++) { Vrho[i]=0.;eVrho[i]=0.;Rrho[i]=0.;eRrho[i]=0.;Trho[i]=RHO_MIN+i *RHO_BIN;} double dV, dV1, dV_spin_mtot, nevts, internal_volume;int nT;int countv=0;int cnt=0;int cnt2=0;int cntfreq=0;bool bcut=false;double liveTot=sim.GetMaximum("ifar");double BKG_LIVETIME_yr=liveTot/CYS;double BKG_LIVETIME_Myr=BKG_LIVETIME_yr/(1.e6);cout.precision(14);cout<< "Total live time ---> background
Float_t * netcc
effective correlated SNR
void PlotsAv_cc(TString ifile)
void Annth(TString ifile)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
for(int i=0;i< 101;++i) Cos2[2][i]=0
pointers to detectors
Float_t * chirp
range to source: [0/1]-rec/inj