3 #pragma GCC system_header
10 #include "TObjArray.h"
11 #include "TObjString.h"
12 #include "TPaletteAxis.h"
13 #include "TMultiLayerPerceptron.h"
14 #include "TMLPAnalyzer.h"
47 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){
52 if (uf!=0&&consider_all==0) ni=1;
56 if (NN_FILE.CompareTo(
"")){
59 if (NN_FILE2.CompareTo(
"")){
62 if (NN_FILE3.CompareTo(
"")){
65 if (NN_FILE4.CompareTo(
"")){
68 if (NN_FILE5.CompareTo(
"")){
71 if (NN_FILE6.CompareTo(
"")){
74 if (NN_FILE7.CompareTo(
"")){
77 if (NN_FILE8.CompareTo(
"")){
85 sprintf(NNi2[0],
"%s",NN_FILE.Data());
86 if(nNN>1)
sprintf(NNi2[1],
"%s",NN_FILE2.Data());
87 if(nNN>2)
sprintf(NNi2[2],
"%s",NN_FILE3.Data());
88 if(nNN>3)
sprintf(NNi2[3],
"%s",NN_FILE4.Data());
89 if(nNN>4)
sprintf(NNi2[4],
"%s",NN_FILE5.Data());
90 if(nNN>5)
sprintf(NNi2[5],
"%s",NN_FILE6.Data());
91 if(nNN>6)
sprintf(NNi2[6],
"%s",NN_FILE7.Data());
92 if(nNN>7)
sprintf(NNi2[7],
"%s",NN_FILE8.Data());
95 for (
int u=0;u<nNN;u++){
99 if((NNi2[u][p+1]==
'N')&&(NNi2[u][p+2]==
'\/')) {
101 while (NNi2[u][hh]!=
'\0'){NNi[u][hh-p-3]=NNi2[u][hh];hh=hh+1;}
113 sprintf(Filei2,
"%s",TEST_FILE.Data());
115 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]==
'\/')) {
117 while (Filei2[hh]!=
'\0') {Filei[hh-q-7]=Filei2[hh];hh=hh+1;
119 for (
int h0=hh-q-7;h0<1024;h0++) Filei[h0]=
'\0';
125 cout<<Filei<<
" original String: "<<Filei2<<endl;
130 if(nNN>1) NNi0[1]=NNi[1];
131 if(nNN>2) NNi0[2]=NNi[2];
132 if(nNN>3) NNi0[3]=NNi[3];
133 if(nNN>4) NNi0[4]=NNi[4];
134 if(nNN>5) NNi0[5]=NNi[5];
135 if(nNN>6) NNi0[6]=NNi[6];
136 if(nNN>7) NNi0[7]=NNi[7];
141 for (
int u=0;u<nNN;u++){
142 NNi0[u].ReplaceAll(
".root",
"");
144 Filei0.ReplaceAll(
".root",
"");
148 TMultiLayerPerceptron* mlp[nNN];
154 for (
int yy=0;
yy<nNN;
yy++){TotBg[
yy]=0;FA0[
yy]=0;FD0[
yy]=0;}
166 for (
int u=0;u<nNN;u++){
167 fnet[u]=TFile::Open(NNi2[u]);
168 mlp[u]=(TMultiLayerPerceptron*)fnet[u]->
Get(
"TMultiLayerPerceptron");
170 cout<<
"dopo TMLP"<<endl;
171 if(mlp[u]==NULL) {cout <<
"Error getting mlp" << endl;
exit(1);}
172 infot[u]=(TTree*)fnet[u]->
Get(
"info");
174 infot[u]->SetBranchAddress(
"Rand_start_Sig",&NNs[u]);
175 infot[u]->SetBranchAddress(
"Rand_start_Bg",&NNb[u]);
176 infot[u]->SetBranchAddress(
"#trainSig",&NNnTS[u]);
177 infot[u]->SetBranchAddress(
"#trainBg",&NNnTB[u]);
178 infot[u]->GetEntry(0);
179 cout<<
"n "<<u<<
" b "<<NNb[u]<<
" min_NNb "<<min_NNb<<endl;
181 if(NNs[u]<min_NNs) min_NNs=NNs[u];
182 if(NNb[u]<min_NNb) min_NNb=NNb[u];
183 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;
189 for (
int u=0;u<nNN;u++){
190 if((NNb[u]<b||NNb[u]==b)&&b>NNb[u]+ NNnTB[u]) b_ok=1;
191 if((NNs[u]<
s||NNs[u]==
s)&&b>NNs[u]+ NNnTS[u]) s_ok=1;
197 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;}
198 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;}
199 cout<<
" min_NNb "<<min_NNb<<
" b "<<b<<endl;
200 cout<<
"Def. tree e mlp"<<endl;
203 TFile* fTEST =TFile::Open(TEST_FILE.Data());
204 TTree* NNTree=(TTree*)fTEST->Get(
"nnTree");
205 int entries=NNTree->GetEntries();
206 cout<<
"entries: "<<entries<<endl;
216 NNTree->SetBranchAddress(
"#Entries_type",&entriesTot);
217 NNTree->SetBranchAddress(
"Matrix_dim",&ndim);
218 NNTree->SetBranchAddress(
"#inputs",&ninp);
219 NNTree->SetBranchAddress(
"amplitude_mode",&y);
222 sig_entries=entriesTot;
223 NNTree->GetEntry(entries-1);
224 bg_entries=entriesTot;
229 cout<<
"NDIM: "<<NDIM<<endl;
230 cout<<
"nINP: "<<nINP<<endl;
231 cout<<
"sig e: "<<sig_entries<<endl;
232 cout<<
"bg e: "<<bg_entries<<endl;
236 if (sig_entries>bg_entries) minevents=bg_entries;
237 else minevents=sig_entries;
249 cout<<
"Error: Bg index<sig_entries: new set of b parameter-> b="<<b<<
" instead of b="<<a<<endl;
254 if((TS>sig_entries-
s||
TB>(bg_entries-(b-sig_entries)))&&(TS==
TB)) {TS=minevents-
s;
TB=minevents-(b-sig_entries);
257 cout<<
"Error:S>sig_entries or TB>bg_entries, to maintain ugual number of analysed events TS=TB="<<
TB<<endl;
259 if((TS>sig_entries-
s||
TB>bg_entries-(b-sig_entries))&&(TS!=
TB)) {
260 if(TS>sig_entries) TS=sig_entries-
s;
261 if (
TB>bg_entries)
TB=bg_entries-(b-sig_entries);
262 cout<<
"Error:TS>sig_entries or TB>bg_entries, new TS and TB values are thus define-> TS="<<TS<<
" TB="<<
TB<<endl;
267 sprintf(NOMEtot,
"%s",NOMEtot_S.Data());
268 cout<<
"output name: "<<NOMEtot<<endl;
274 NNTree->SetBranchAddress(
"Files_name",&FILE_NAME);
277 NNTree->GetEntry(entries-1);
279 cout<<
"fine ifdef RHO_CC"<<endl;
282 TChain sigTree(
"waveburst");
283 sigTree.Add(SIG_FILE.Data());
286 cout <<
"sig entries2 : " << sig_entries2 << endl;
288 TChain bgTree(
"waveburst");
289 bgTree.Add(BG_FILE.Data());
292 cout <<
"bg entries2 : " << bg_entries2 << endl;
294 cout<<
"b: "<<b<<endl;
295 cout<<
"s: "<<
s<<endl;
299 for (
int jj=0; jj<nINP;jj++) x[jj]=0.;
300 char ilabel[nINP][16];
303 for(
int i=0;
i<nINP;
i++) {
305 NNTree->SetBranchAddress(ilabel[i], &x[i]);
309 sprintf(ofile,
"average_file/%s.root",NOMEtot);
310 TFile*
f =
new TFile(ofile,
"RECREATE");
311 TTree* NNTree2=
new TTree(
"Parameters",
"Parameters");
312 NNTree2->SetDirectory(f);
317 for(
int y=0; y<nNN; y++) out[y]=0.;
324 NNTree2->Branch(
"Average",&average,
"Average/D");
325 NNTree2->Branch(
"StandardDevaition",&std,
"StandardDeviation/D");
326 NNTree2->Branch(
"cc",&NNcc,
"cc/D");
327 NNTree2->Branch(
"Mchirp",&Mc,
"Mchirp/D");
328 NNTree2->Branch(
"rho",&NNrho,
"rho/D");
330 for(
int u=0;u<nNN;u++){
336 sprintf(NNoutl2,
"NNout%i/D",u);
338 sprintf(NNnamel2,
"NNname%i/C",u);
339 NNTree2->Branch(NNoutl,&out[u],NNoutl2);
340 NNTree2->Branch(NNnamel,&NNi[u],NNnamel2);
344 NNTree2->Branch(
"TestFile",&Testf,
"TestFile/C");
345 sprintf(Testf,
"%s",TEST_FILE.Data());
348 NNTree2->Branch(
"#TestSig",&nTestS,
"#TestSig/I");
349 cout<<
"nTestS: "<<nTestS<<
" TS: "<<TS<<endl;
350 cout<<
"dopo def tree"<<endl;
356 for(
int n=
s;
n<
s+TS;
n++) {
358 for(
int u=0;u<nNN;u++){
359 if (uf!=0&&
n>NNs[u]&&
n<(NNs[u]+NNnTS[u])) countNN=countNN+1;
361 if(countNN==1&&ni==0) scount=scount+1;
362 if(countNN<2&&ni!=0) scount=scount+1;
363 if(countNN>1){cout<<
"Error: training non independent"<<
n<<endl;
exit(0);}
368 cout<<
"s test "<<
s<<
" s+TS "<<
s+TS<<
" b "<<b<<
" b+ TB "<<b+
TB<<
" nTestS "<<nTestS<<endl;
372 for (
int i=0;
i<nINP;
i++) params[
i]=0.;
377 for(
int n=
s;
n<
s+TS;
n++) {
381 for(
int u=0;u<nNN;u++){
382 if (uf!=0&&
n>=NNs[u]&&
n<(NNs[u]+NNnTS[u])) { indNN=u;countNN=countNN+1;}
384 if (countNN>1){cout<<
"Error: training non independent";
exit(0);}
385 if(nNN==1){cout<<
"out==Averege:only 1NN is considered"<<endl;}
386 if(ni==0&&countNN==0)
continue;
391 NNcc=(double)signal.
netcc[1];
392 NNrho=(
double)signal.
rho[0];
396 for (
int i=0;
i<nINP;
i++){
399 for (
int u=0;u<nNN;u++) {
400 cout<<
" u "<<u<<
" nNN "<<nNN<<endl;
401 double output=mlp[u]->Evaluate(0,params);
407 cout<<
"Dopo param"<<endl;
415 for (
int u=0;u<nNN;u++){
416 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;}
420 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);}
425 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);}
426 cout<<
"average: "<<average<<endl;
427 cout<<
"Mc "<<Mc<<endl;
428 if (average<0.6) FD=FD+1;
437 cout<<
"riempito sig S_eff"<<S_eff<<endl;
445 for(
int n=b;
n<b+
TB;
n++) {
449 for(
int u=0;u<nNN;u++){
450 cout<<
" uf "<<uf<<
" n "<<
n<<
" u "<<u<<
" NN b[u] "<<NNb[u]<<
" NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
451 if (uf!=0&&
n>=NNb[u]&&
n<(NNb[u]+NNnTB[u])) { indNN=u;countNN=countNN+1; }
454 if (countNN>1){cout<<
"Error: training non independent";
exit(0);}
455 if(nNN==1){cout<<
"out==Averege:only 1NN is considered"<<endl;}
456 if(ni==0&&countNN==0){ cout<<
"countNN"<<countNN<<endl;
continue;}
459 cout<<
"BKG->n: "<<
n<<
"Bg index"<<(
n-sig_entries)<<endl;
461 NNcc=(double)background.
netcc[1];
462 NNrho=(
double)background.
rho[0];
464 for (
int i=0;
i<nINP;
i++){
468 for(
int u=0;u<nNN;u++) {
469 double output=mlp[u]->Evaluate(0,params);
474 for (
int u=0;u<nNN;u++){
475 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;}}
477 if(nnsu==6) cont_su=cont_su+1;
478 if(nnsu>4) cont_su5=cont_su5+1;
479 if(nnsu>3) cont_su4=cont_su4+1;
480 if(nnsu>2) cont_su3=cont_su3+1;
483 if(nNN!=1&&ni==0) {cout<<average<<endl;average=average/(nNN-countNN);
484 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);}
490 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;}
491 cout<<
"average: "<<average<<endl;
494 if(average>0.6) FA=FA+1;
499 cout<<
"bkg filled"<<endl;
504 cout<<
"closed file"<<endl;
508 cout<<
" S_eff "<<S_eff<<
" B_eff "<<B_eff<<endl;
514 for (
int yy=0;
yy<nNN;
yy++){
516 cout<<
" FA0[yy] "<<FA0[
yy]<<
" FD0[yy] "<<FD0[
yy]<<
" FD "<<FD<<
" TotBg[yy] "<<TotBg[
yy]<<endl;
517 if(TotBg[
yy]!=0){freq_c[
yy]=(double)FA0[
yy]/TotBg[
yy];cout<<
" freq_c[yy] "<<freq_c[
yy]<<endl;}
518 if(freq_c[
yy]!=0) {meanf=freq_c[
yy]+meanf;cont=cont+1;cout<<
" cont "<<cont<<endl;}
519 dev=freq_c[
yy]*freq_c[
yy]+dev;
522 if(cont==0) cout<<
"Error cont==0"<<endl;
523 if(cont!=0) meanf=meanf/cont;
525 for (
int yy=0;
yy<nNN;
yy++){
526 cout<<
" dev "<<dev<<endl;
527 cout<<
"freq_c[yy] "<<freq_c[
yy]<<
" meanf "<<meanf<<endl;
528 if(freq_c[
yy]!=0)dev+=(freq_c[
yy]-meanf)*(freq_c[
yy]-meanf);
534 if(cont!=0) dev=pow(dev/(cont-1),0.5);
535 cout<<
"meanf "<<meanf<<
" dev "<<dev<<endl;
536 cout<<
" FA average "<<FA<<endl;
537 cout<<
" cont_su "<<cont_su<<
" cont_su5 "<<cont_su5<<
" cont_su4 "<<cont_su4<<
" cont_su3 "<<cont_su3<<endl;
539 cout<<
" FA0[1] "<<FA0[1]<<
" TotBg[1] "<<TotBg[1]<<endl;
540 cout<<
" FD0[1] "<<FD0[1]<<
" TotBg[1] "<<TotBg[1]<<endl;
545 name.ReplaceAll(
"average_file/",
"");
546 TFile* fTEST =TFile::Open(ifile.Data());
547 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
552 NNTree2->SetBranchAddress(
"Average",&av);
553 NNTree2->SetBranchAddress(
"cc",&cc);
554 NNTree2->SetBranchAddress(
"rho",&rho);
555 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
556 NNTree2->GetEntry(0);
558 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
559 cout<<
" BG: "<<NNTree2->GetEntries()-nSi<<endl;
561 cout<<
"dentro funzione dopodef"<<endl;
563 double* rhoSig[ncurve];
564 for (
int i=0;
i<ncurve;
i++) rhoSig[
i]=
new double[nSig];
565 cout<<
"dopo def rhoSig"<<endl;
569 int const nBg=NNTree2->GetEntries()-nSig;
570 for (
int i=0;
i<ncurve;
i++) {
572 for (
int j=0;
j<nSig;
j++) rhoSig[
i][
j]=0.;
574 cout<<
"dopo def rhoSig"<<endl;
575 double* rhoBg[ncurve];
576 for (
int i=0;
i<ncurve;
i++) rhoBg[
i]=
new double[nBg];
579 for (
int i=0;
i<ncurve;
i++) {
581 for (
int j=0;
j<nBg;
j++) rhoBg[
i][
j]=0.;
583 cout<<
"dopo def rhoBg"<<endl;
585 for (
int i=0;
i<
nCC;
i++) ccTh[
i]=0.;
587 for (
int i=0;
i<
nANN;
i++) NNTh[
i]=0.;
593 cout<<NNTree2->GetEntries()<<endl;
594 for(
int n=0;
n<NNTree2->GetEntries();
n++){
596 NNTree2->GetEntry(
n);
597 cout<<
"rho "<<rho<<
" cc "<<cc<<
" av "<<av<<endl;
600 if(cc<ccTh[
i])
continue;
602 if(
j==0) NNTh[
j]=-1000.;
608 if(av<NNTh[
j])
continue;
612 NBg[i*nANN+
j]= NBg[i*nANN+
j]+1;
613 while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
614 rhoBg[i*nANN+
j][ni]=
rho;
619 NSig[i*nANN+
j]= NSig[i*nANN+
j]+1;
620 while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
621 rhoSig[i*nANN+
j][ni]=
rho;
629 cout<<
"dopo riempimento variabili"<<endl;
631 for (
int i=0;
i<ncurve;
i++) indexS[
i]=
new int[nSig];
634 for (
int y=0;
y<ncurve;
y++) {
647 TMath::Sort(nSig,rhoSig[
y],indexS[y],
false);
649 for (
int k=0;
k<nSig;
k++) {
654 int ij=indexS[
y][
k-1];
656 if(rhoSig[y][ii]!=0) {
659 if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[
y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
660 cout<<
"igS"<<igS<<
" x "<<rhoSig[
y][ii]<<
" y: "<<yy<<endl;
665 if(rhoSig[y][ii]!=0){
667 gS[
y]->SetPoint(0,rhoSig[y][ii],yy);
678 for (
int i=0;
i<ncurve;
i++) indexB[
i]=
new int[nBg];
681 for (
int y=0;
y<ncurve;
y++) {
685 TMath::Sort(nBg,rhoBg[
y],indexB[y],
false);
687 for (
int k=0;
k<nBg;
k++) {
691 int ij=indexB[
y][
k-1];
693 if(rhoBg[y][ii]!=0) {
696 if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[
y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
702 if(rhoBg[y][ii]!=0) {
704 gB[
y]->SetPoint(0,rhoBg[y][ii],yy);
711 cout<<
"dopo inserimento puntiB"<<endl;
714 TCanvas* cS=
new TCanvas(
"Efficiency_vs_rho",
"Efficiency_vs_rho",0,0,1200,700);
716 cS->cd(1)->SetLogy();
717 TMultiGraph* mg1=
new TMultiGraph();
719 gS[0]->SetMarkerColor(2);
720 gS[0]->SetLineColor(2);
721 mg1->SetTitle(
"cc=0.5;rho;#Events");
722 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
725 gS[
h]->SetMarkerColor(3);
726 gS[
h]->SetLineColor(3);
728 if(gS[
h]->GetN()!=0) mg1->Add(gS[
h]);
732 cS->cd(2)->SetLogy();
733 TMultiGraph* mg2=
new TMultiGraph();
735 gS[
nANN]->SetMarkerColor(2);
736 gS[
nANN]->SetLineColor(2);
737 mg2->SetTitle(
"cc=0.55;rho;#Events");
738 if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
740 gS[nANN+
h]->SetMarkerColor(3);
741 gS[nANN+
h]->SetLineColor(3);
743 if(gS[nANN+
h]->GetN()!=0) mg2->Add(gS[nANN+
h]);
747 cS->cd(3)->SetLogy();
748 TMultiGraph* mg3=
new TMultiGraph();
750 gS[nANN*2]->SetMarkerColor(2);
751 gS[nANN*2]->SetLineColor(2);
752 mg3->SetTitle(
"cc=0.6;rho;#Events");
753 if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
755 gS[2*nANN+
h]->SetMarkerColor(3);
756 gS[2*nANN+
h]->SetLineColor(3);
758 if(gS[2*nANN+
h]->GetN()!=0) mg3->Add(gS[2*nANN+
h]);
762 cS->cd(4)->SetLogy();
763 TMultiGraph* mg4=
new TMultiGraph();
765 gS[nANN*3]->SetMarkerColor(2);
766 gS[nANN*3]->SetLineColor(2);
767 mg4->SetTitle(
"cc=0.65;rho;#Events");
768 if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
771 gS[3*nANN+
h]->SetMarkerColor(3);
772 gS[3*nANN+
h]->SetLineColor(3);
774 if(gS[3*nANN+
h]->GetN()!=0) mg4->Add(gS[3*nANN+
h]);
778 cout<<
"nuovo canv"<<endl;
779 TCanvas* cB=
new TCanvas(
"Number_vs_rho",
"Number_vs_rho",0,0,1200,700);
781 cB->cd(1)->SetLogy();
782 TMultiGraph* mg1B=
new TMultiGraph();
784 gB[0]->SetMarkerColor(2);
785 gB[0]->SetLineColor(2);
786 mg1B->SetTitle(
"cc=0.5;rho;#Events");
787 if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
789 gB[
h]->SetMarkerColor(3);
790 gB[
h]->SetLineColor(3);
792 if(gB[
h]->GetN()!=0) mg1B->Add(gB[
h]);
796 cB->cd(2)->SetLogy();
797 TMultiGraph* mg2B=
new TMultiGraph();
799 gB[
nANN]->SetMarkerColor(2);
800 gB[
nANN]->SetLineColor(2);
801 mg2B->SetTitle(
"cc=0.55;rho;#Events");
802 if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
804 gB[nANN+
h]->SetMarkerColor(3);
805 gB[nANN+
h]->SetLineColor(3);
807 if(gB[nANN+
h]->GetN()!=0) mg2B->Add(gB[nANN+
h]);
811 cB->cd(3)->SetLogy();
812 TMultiGraph* mg3B=
new TMultiGraph();
814 gB[2*
nANN]->SetMarkerColor(2);
815 gB[2*
nANN]->SetLineColor(2);
816 mg3B->SetTitle(
"cc=0.6;rho;#Events");
817 if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
819 gB[2*nANN+
h]->SetMarkerColor(3);
820 gB[2*nANN+
h]->SetLineColor(3);
822 if(gB[2*nANN+
h]->GetN()!=0) mg3B->Add(gB[2*nANN+
h]);
826 cB->cd(4)->SetLogy();
827 TMultiGraph* mg4B=
new TMultiGraph();
829 gB[3*
nANN]->SetMarkerColor(2);
830 gB[3*
nANN]->SetLineColor(2);
831 mg4B->SetTitle(
"cc=0.65;rho;#Events");
832 if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
834 gB[3*nANN+
h]->SetMarkerColor(3);
835 gB[3*nANN+
h]->SetLineColor(3);
837 if(gB[3*nANN+
h]->GetN()!=0) mg4B->Add(gB[3*nANN+
h]);
849 char CnameS2root[1024];
850 char CnameB2root[1024];
851 CnameS.ReplaceAll(
".root",
".png");
852 CnameB.ReplaceAll(
".root",
".png");
853 sprintf(CnameS2,
"logN_rho_av/logN_rho_S_dANN%1.2f_%s",
deltaANN,CnameS.Data());
854 sprintf(CnameB2,
"logN_rho_av/logN_rho_B_dANN%1.2f_%s",
deltaANN,CnameB.Data());
855 sprintf(CnameS2root,
"logN_rho_av/logN_rho_S_dANN%1.2f_%s",
deltaANN,CnameSroot.Data());
856 sprintf(CnameB2root,
"logN_rho_av/logN_rho_B_dANN%1.2f_%s",
deltaANN,CnameBroot.Data());
859 cS->Print(CnameS2root);
860 cB->Print(CnameB2root);
868 name.ReplaceAll(
"average_file/",
"");
869 TFile* fTEST =TFile::Open(ifile.Data());
870 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
875 NNTree2->SetBranchAddress(
"Average",&av);
876 NNTree2->SetBranchAddress(
"cc",&cc);
877 NNTree2->SetBranchAddress(
"rho",&rho);
878 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
879 NNTree2->GetEntry(0);
885 double* ANNSig[ncurve2];
886 for (
int i=0;
i<ncurve2;
i++) ANNSig[
i]=
new double[nSig];
890 int const nBg=NNTree2->GetEntries()-nSig;
891 for (
int i=0;
i<ncurve2;
i++) {
893 for (
int j=0;
j<nSig;
j++) ANNSig[
i][
j]=0.;
895 double* ANNBg[ncurve2];
896 for (
int i=0;
i<ncurve2;
i++) ANNBg[
i]=
new double[nBg];
900 for (
int i=0;
i<ncurve2;
i++) {
902 for (
int j=0;
j<nBg;
j++) ANNBg[
i][
j]=0.;
905 for (
int i=0;
i<
nCC;
i++) ccTh[
i]=0.;
907 for (
int i=0;
i<
nRHO;
i++) rhoTh[
i]=0.;
914 for(
int n=0;
n<NNTree2->GetEntries();
n++){
915 NNTree2->GetEntry(
n);
916 cout<<
"rho "<<rho<<
" cc "<<cc<<
" av "<<av<<endl;
919 if(cc<ccTh[
i])
continue;
922 if(rho<rhoTh[
j])
continue;
925 NBg[i*nRHO+
j]= NBg[i*nRHO+
j]+1;
926 while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
927 ANNBg[i*nRHO+
j][ni]=av;
931 NSig[i*nRHO+
j]= NSig[i*nRHO+
j]+1;
932 while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
933 ANNSig[i*nRHO+
j][ni]=av;
940 int* indexS[ncurve2];
941 for (
int i=0;
i<ncurve2;
i++) indexS[
i]=
new int[nSig];
943 TGraph * gS[ncurve2];
944 for (
int y=0;
y<ncurve2;
y++) {
948 TMath::Sort(nSig,ANNSig[
y],indexS[y],
false);
949 for (
int k=0;
k<nSig;
k++) {
954 int ij=indexS[
y][
k-1];
956 if(ANNSig[y][ii]!=0) {
959 if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[
y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
966 if(ANNSig[y][ii]!=0){
968 gS[
y]->SetPoint(0,ANNSig[y][ii],yy);
979 int* indexB[ncurve2];
980 for (
int i=0;
i<ncurve2;
i++) indexB[
i]=
new int[nBg];
982 TGraph * gB[ncurve2];
983 for (
int y=0;
y<ncurve2;
y++) {
987 TMath::Sort(nBg,ANNBg[
y],indexB[y],
false);
989 for (
int k=0;
k<nBg;
k++) {
993 int ij=indexB[
y][
k-1];
995 if(ANNBg[y][ii]!=0) {
998 if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[
y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
1004 if(ANNBg[y][ii]!=0) {
1006 gB[
y]->SetPoint(0,ANNBg[y][ii],yy);
1015 TCanvas* cS=
new TCanvas(
"Efficiency_vs_ANN",
"Efficiency_vs_ANN",0,0,1200,700);
1019 TMultiGraph* mg1=
new TMultiGraph();
1020 mg1->SetTitle(
"cc=0.5;ANN;#Events");
1022 gS[
h]->SetLineColor(4);
1023 if(gS[
h]->GetN()!=0) mg1->Add(gS[
h]);
1028 TMultiGraph* mg2=
new TMultiGraph();
1029 mg2->SetTitle(
"cc=0.55;ANN;#Events");
1031 gS[nRHO+
h]->SetLineColor(4);
1032 if(gS[nRHO+
h]->GetN()!=0) mg2->Add(gS[nRHO+
h]);
1038 TMultiGraph* mg3=
new TMultiGraph();
1039 mg3->SetTitle(
"cc=0.6;ANN;#Events");
1041 gS[2*nRHO+
h]->SetLineColor(4);
1042 if(gS[2*nRHO+
h]->GetN()!=0) mg3->Add(gS[2*nRHO+
h]);
1047 TMultiGraph* mg4=
new TMultiGraph();
1048 mg4->SetTitle(
"cc=0.65;ANN;#Events");
1050 gS[3*nRHO+
h]->SetLineColor(4);
1051 if(gS[3*nRHO+
h]->GetN()!=0) mg4->Add(gS[3*nRHO+
h]);
1055 TCanvas* cB=
new TCanvas(
"Number_vs_ANN",
"Number_vs_ANN",0,0,1200,700);
1057 cB->cd(1)->SetLogy();
1058 TMultiGraph* mg1B=
new TMultiGraph();
1059 mg1B->SetTitle(
"cc=0.5;ANN;#Events");
1061 gB[
h]->SetLineColor(4);
1062 if(gB[
h]->GetN()!=0) mg1B->Add(gB[
h]);
1065 cB->cd(2)->SetLogy();
1066 TMultiGraph* mg2B=
new TMultiGraph();
1067 mg2B->SetTitle(
"cc=0.55;ANN;#Events");
1069 gB[nRHO+
h]->SetLineColor(4);
1070 if(gB[nRHO+
h]->GetN()!=0) mg2B->Add(gB[nRHO+
h]);
1073 cB->cd(3)->SetLogy();
1074 TMultiGraph* mg3B=
new TMultiGraph();
1075 mg3B->SetTitle(
"cc=0.6;ANN;#Events");
1077 gB[2*nRHO+
h]->SetLineColor(4);
1078 if(gB[2*nRHO+
h]->GetN()!=0) mg3B->Add(gB[2*nRHO+
h]);
1081 cB->cd(4)->SetLogy();
1082 TMultiGraph* mg4B=
new TMultiGraph();
1083 mg4B->SetTitle(
"cc=0.6;ANN;#Events");
1085 gB[3*nRHO+
h]->SetLineColor(4);
1086 if(gB[3*nRHO+
h]->GetN()!=0) mg4B->Add(gB[3*nRHO+
h]);
1098 char CnameS2root[1024];
1099 char CnameB2root[1024];
1100 CnameS.ReplaceAll(
".root",
".png");
1101 CnameB.ReplaceAll(
".root",
".png");
1102 sprintf(CnameS2,
"ANNthres_av/N_ANN_S_%s",CnameS.Data());
1103 sprintf(CnameB2,
"ANNthres_av/N_ANN_B_%s",CnameB.Data());
1104 sprintf(CnameS2root,
"ANNthres_av/N_ANN_S_%s",CnameSroot.Data());
1105 sprintf(CnameB2root,
"ANNthres_av/N_ANN_B_%s",CnameBroot.Data());
1106 cS->SaveAs(CnameS2);
1107 cB->SaveAs(CnameB2);
1108 cS->Print(CnameS2root);
1109 cB->Print(CnameB2root);
1121 name.ReplaceAll(
"outfile/",
"");
1122 name.ReplaceAll(
"average_file/",
"");
1123 TFile* fTEST =TFile::Open(ifile.Data());
1124 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
1132 NNTree2->SetBranchAddress(
"Average",&av);
1133 NNTree2->SetBranchAddress(
"cc",&cc);
1134 NNTree2->SetBranchAddress(
"rho",&rho);
1135 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
1136 NNTree2->GetEntry(0);
1138 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
1139 int const nBg=NNTree2->GetEntries()-nSig;
1140 cout<<
"nBg: "<<nBg<<
" Entries: "<<NNTree2->GetEntries()<<endl;
1147 for (
int n = 0;
n <NNTree2->GetEntries();
n++){
1148 NNTree2->GetEntry(
n);
1150 gS[0]->SetPoint(
n,cc,av);
1151 cout<<
"Sig_graph1: x="<<cc<<
" y: "<<av<<endl;
1154 gB[0]->SetPoint(
n-nSig,cc,av);
1155 cout<<
"Bg_graph1: x="<<cc<<
" y: "<<av<<endl;
1176 gS[0]->SetMarkerColor(2);
1177 gB[0]->SetMarkerColor(4);
1178 gS[0]->SetMarkerStyle(6);
1179 gB[0]->SetMarkerStyle(7);
1181 TCanvas*
c=
new TCanvas(
"Plots",
"Plots",0,0,1200,700);
1184 TMultiGraph* mg1=
new TMultiGraph();
1185 mg1->SetTitle(
"Av_cc");
1186 if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1187 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1189 mg1->GetHistogram()->GetXaxis()->SetTitle(
"cc");
1190 mg1->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1193 TMultiGraph* mg2=
new TMultiGraph();
1194 mg2->SetTitle(
"Av_cc");
1195 if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1196 if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1198 mg2->GetHistogram()->GetXaxis()->SetTitle(
"cc");
1199 mg2->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1201 cout<<
" name "<<name<<endl;
1205 char Cname2root[1024];
1206 Cname.ReplaceAll(
".root",
".png");
1207 sprintf(Cname2,
"average_png/out_Plots_%s",Cname.Data());
1208 sprintf(Cname2root,
"average_png/out_Plots_%s",Cnameroot.Data());
1210 c->Print(Cname2root);
1248 name.ReplaceAll(
"outfile/",
"");
1249 name.ReplaceAll(
"average_file/",
"");
1250 TFile* fTEST =TFile::Open(ifile.Data());
1251 TTree* NNTree2=(TTree*)fTEST->Get(
"Parameters");
1260 NNTree2->SetBranchAddress(
"Mchirp",&Mc);
1261 NNTree2->SetBranchAddress(
"Average",&av);
1262 NNTree2->SetBranchAddress(
"cc",&cc);
1263 NNTree2->SetBranchAddress(
"rho",&rho);
1264 NNTree2->SetBranchAddress(
"#TestSig",&nSi);
1265 NNTree2->GetEntry(0);
1267 cout<<
"nSig: "<<nSig<<
" nSi: "<<nSi<<endl;
1268 int const nBg=NNTree2->GetEntries()-nSig;
1275 for (
int n = 0;
n <NNTree2->GetEntries();
n++){
1276 NNTree2->GetEntry(
n);
1278 gS[0]->SetPoint(
n,Mc,av);
1279 cout<<
"Sig_graph1: x="<<cc<<
" y: "<<av<<endl;
1282 gB[0]->SetPoint(
n-nSig,Mc,av);
1283 cout<<
"Bg_graph1: x="<<cc<<
" y: "<<av<<endl;
1300 gS[0]->SetMarkerColor(2);
1301 gB[0]->SetMarkerColor(4);
1302 gS[0]->SetMarkerStyle(6);
1303 gB[0]->SetMarkerStyle(7);
1305 TCanvas*
c=
new TCanvas(
"Plots",
"Plots",0,0,1200,700);
1308 TMultiGraph* mg1=
new TMultiGraph();
1309 mg1->SetTitle(
"Av_Mc");
1310 if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1311 if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1313 mg1->GetHistogram()->GetXaxis()->SetTitle(
"Mchirp");
1314 mg1->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1316 TMultiGraph* mg2=
new TMultiGraph();
1317 mg2->SetTitle(
"Av_Mc");
1318 if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1319 if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1321 mg2->GetHistogram()->GetXaxis()->SetTitle(
"Mchirp");
1322 mg2->GetHistogram()->GetYaxis()->SetTitle(
"Average on ANN ouputs");
1324 cout<<
" name "<<name<<endl;
1328 char Cname2root[1024];
1329 Cname.ReplaceAll(
".root",
".png");
1330 sprintf(Cname2,
"average_png/Mc_Plots_%s",Cname.Data());
1331 sprintf(Cname2root,
"average_png/Mc_Plots_%s",Cnameroot.Data());
1333 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<< "\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
cout<<"Comparison bkg events above threshold: "<< entriesx<< endl;double *rhox=cnet.GetV1();comph=(TH1D *) gDirectory-> Get("hcomp")
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<< "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 \n");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
Float_t * chirp
range to source: [0/1]-rec/inj