Logo coherent WaveBurst  
Library Reference Guide
Logo
Average_FAout_moreGraphs_3.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Serena Vinciguerra
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 #define XIFO 4
20 
21 #pragma GCC system_header
22 
23 #include "cwb.hh"
24 #include "config.hh"
25 #include "network.hh"
26 #include "wavearray.hh"
27 #include "TString.h"
28 #include "TObjArray.h"
29 #include "TObjString.h"
30 #include "TPaletteAxis.h"
31 #include "TMultiLayerPerceptron.h"
32 #include "TMLPAnalyzer.h"
33 #include "TRandom.h"
34 #include "TComplex.h"
35 #include "TMath.h"
36 #include "mdc.hh"
37 #include "watplot.hh"
38 #include <vector>
39 
40 
41 //#define nINP 64
42 #define Ncc3D 50
43 #define maxCC 1
44 #define minCC 0
45 #define nIFO 3
46 #define nRHO 3
47 #define nANN 10
48 #define deltaANN 0.1
49 #define deltacc 0.05
50 #define deltarho 1
51 #define nCC 4
52 #define NPIX 20
53 #define RHOth 5.5
54 #define nth 10
55 #define rhomin 6
56 #define ccmin 0.6
57 #define iMc 1
58 #define NMc_inj 50
59 #define minMc_inj 0
60 #define maxMc_inj 100
61 #define NMc_r 50
62 #define maxMc_r 40
63 #define minMc_r -5
64 #define NANN_av 50
65 #define minANN_av -0.2
66 #define maxANN_av 1.5
67 
68 //definition parameters for SNR_plots
69 #define N_ANNth 50
70 #define N_RHOth 50
71 #define ANNth_max 1.5
72 #define ANNth_min -0.5
73 #define RHOth_max 10.0
74 #define RHOth_min 4.5
75 
76 using namespace std;
77 void graph(TString ifile);
78 void Annth(TString ifile, int &FAth_n, int &FDth_n, double &thresFA);
79 void Mcth(TString ifile, int &McFAth_n, int &McFDth_n, double &McthresFA);
82 void SNR_plots(TString ifile);
83 void CoG_plots(TString ifile);
85 //void Test0(TString NN_FILE,TString TEST_FILE,TString ofile, int TS=0, int TB=0, int s=0, int b=0, int uf=0){
86 
87 //NN_FILE-NN_FILE8: name of the files where the interested ANNs are saved (!!they must become from a directory whose name ends in "NN").
88 //TEST_FILE: name of the file which contains the events you are going to analyse (!!they must become from a directory whose name ends in "nnTREE").
89 //TS, TB: numbers of events to test for each class.
90 //s, b: index values of the first events considered for both the classes. If b < #SIG_events, b is newly set to b=b+#SIG_events
91 //uf !=0 means the Test file of events is the same used to train the network, in this case ni==0. It means that the events used for the training are analysed only by the other ANNs, in this way we test the events with at least NNn-1 networks. If uf==0 the Test and Train files are different, in this case ni!=0 and all the events can beanalysed by all the nNN networks.
92 //consider_all=1(0): the events not used for the training procedure are (aren't) considered for the test.
93 //ni: =0 excludes from the test the training set of events
94 void Average_FAout_moreGraphs_3(double FAdes, 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=0, int av_on_nNN=0){
95 int ni=0;
96 if (uf==0&&av_on_nNN!=0) cout<<"all events were not used for the training procedure"<<endl;
97 if(uf==0) {ni=1; consider_all=1; av_on_nNN=0;}
98 else ni=0; //events used for the training not considered for the ANN trained on them
99 
100 int TS0=0;
101 TS0=TS;
102 int TB0=0;
103 TB0=TB;
104 //if(uf!=0&&consider_all==0) ni=1;
105 
106 //COUNT THE ANNs
107 int n_NN=0;
108 if (NN_FILE.CompareTo("")){
109  n_NN=n_NN+1;
110  }
111 if (NN_FILE2.CompareTo("")){
112  n_NN=n_NN+1;
113  }
114 if (NN_FILE3.CompareTo("")){
115  n_NN=n_NN+1;
116  }
117 if (NN_FILE4.CompareTo("")){
118  n_NN=n_NN+1;
119  }
120 if (NN_FILE5.CompareTo("")){
121  n_NN=n_NN+1;
122  }
123 if (NN_FILE6.CompareTo("")){
124  n_NN=n_NN+1;
125  }
126 if (NN_FILE7.CompareTo("")){
127  n_NN=n_NN+1;
128  }
129 if (NN_FILE8.CompareTo("")){
130  n_NN=n_NN+1;
131  }
132 int const nNN=n_NN;
133 
134 // int p=0;
135  char NNi[nNN][1024];
136  char NNi2[nNN][1024];
137  sprintf(NNi2[0],"%s",NN_FILE.Data());
138  if(nNN>1) sprintf(NNi2[1],"%s",NN_FILE2.Data());
139  if(nNN>2) sprintf(NNi2[2],"%s",NN_FILE3.Data());
140  if(nNN>3) sprintf(NNi2[3],"%s",NN_FILE4.Data());
141  if(nNN>4) sprintf(NNi2[4],"%s",NN_FILE5.Data());
142  if(nNN>5) sprintf(NNi2[5],"%s",NN_FILE6.Data());
143  if(nNN>6) sprintf(NNi2[6],"%s",NN_FILE7.Data());
144  if(nNN>7) sprintf(NNi2[7],"%s",NN_FILE8.Data());
145 
146 if(nNN==1) {av_on_nNN=1; consider_all=0; ni=0;}
147 //saving the ANN names
148  for (int u=0;u<nNN;u++){
149  int p=0;
150  while (NNi2[u][p]){
151  if (NNi2[u][p]=='N'){
152  if((NNi2[u][p+1]=='N')&&(NNi2[u][p+2]=='\/')) {
153  int hh=p+3;
154  while (NNi2[u][hh]!='\0'){NNi[u][hh-p-3]=NNi2[u][hh];hh=hh+1;}
155  break;
156  }
157  }
158  p=p+1;
159  }
160 }
161 
162 //saving the Test-file name
163 int q=0;
164  char Filei[1024];
165  char Filei2[1024];
166  sprintf(Filei2,"%s",TEST_FILE.Data());
167  while (Filei2[q]){
168  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]=='\/')) {
169  int hh=q+7;
170  while (Filei2[hh]!='\0') {Filei[hh-q-7]=Filei2[hh];hh=hh+1;
171  }
172  for (int h0=hh-q-7;h0<1024;h0++) Filei[h0]='\0';
173  break;
174  }
175  q=q+1;
176  }
177 
178  cout<<Filei<<" original String: "<<Filei2<<endl;
179 
180 
181  TString NNi0[nNN];
182  NNi0[0]=NNi[0];
183  if(nNN>1) NNi0[1]=NNi[1];
184  if(nNN>2) NNi0[2]=NNi[2];
185  if(nNN>3) NNi0[3]=NNi[3];
186  if(nNN>4) NNi0[4]=NNi[4];
187  if(nNN>5) NNi0[5]=NNi[5];
188  if(nNN>6) NNi0[6]=NNi[6];
189  if(nNN>7) NNi0[7]=NNi[7];
190 
191  TString Filei0(Filei);
192 
193 //removing the extensions
194 for (int u=0;u<nNN;u++){
195  NNi0[u].ReplaceAll(".root","");
196  }
197  Filei0.ReplaceAll(".root","");
198 
199 //Definitions of some parameters
200  TFile *fnet[nNN];
201  TMultiLayerPerceptron* mlp[nNN];
202  TTree* infot[nNN];
203  int TotBg[nNN];
204  int FD0[nNN]; //FD=False Dismissal
205  int FA0[nNN]; //FA=False Alarm
206 
207  for (int yy=0; yy<nNN; yy++){TotBg[yy]=0;FA0[yy]=0;FD0[yy]=0;}
208 
209  int NNs[nNN]; //first SIG-event considered for ANN trainings
210  int NNb[nNN]; //first BKG-event considered for ANN trainings
211  int NNnTS[nNN]; //number of SIG-events considered for ANN trainings
212  int NNnTB[nNN]; //number of BKG-events considered for ANN trainings
213 
214 int min_NNb=5000000;
215 int min_NNs=5000000;
216 int max_NNb=0;
217 int max_NNs=0;
218 
219 //Extracting ANNs and information from the files
220 //if (uf!=0&&ni==0&&(TS!=0||TB!=0)){
221  for (int u=0;u<nNN;u++){
222  fnet[u]=TFile::Open(NNi2[u]);
223  mlp[u]=(TMultiLayerPerceptron*)fnet[u]->Get("TMultiLayerPerceptron");
224 
225  cout<<"dopo TMLP"<<endl;
226  if(mlp[u]==NULL) {cout << "Error getting mlp" << endl;exit(1);}
227  infot[u]=(TTree*)fnet[u]->Get("info");
228 
229  infot[u]->SetBranchAddress("Rand_start_Sig",&NNs[u]);
230  infot[u]->SetBranchAddress("Rand_start_Bg",&NNb[u]);
231  infot[u]->SetBranchAddress("#trainSig",&NNnTS[u]);
232  infot[u]->SetBranchAddress("#trainBg",&NNnTB[u]);
233  infot[u]->GetEntry(0);
234  cout<<"n "<<u<<" b "<<NNb[u]<<" min_NNb "<<min_NNb<<endl;
235 
236  if(NNs[u]<min_NNs) min_NNs=NNs[u];
237  if(NNb[u]<min_NNb) min_NNb=NNb[u];
238  if(NNs[u]>max_NNs) max_NNs=NNs[u];
239  if(NNb[u]>max_NNb) max_NNb=NNb[u];
240  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;
241  }
242 
243 //Changing b value to its sum to the first event considered for the training
244 //if (uf!=0&&ni==0&&(b<min_NNb)&&(TS!=0||TB!=0)){ b+=min_NNb;cout<<" change in b value to have BKG events: "<<b<<endl;}
245 /*if (uf!=0&&ni==0&&(b<min_NNb)){ b+=min_NNb;cout<<" change in b value to have BKG events: "<<b<<endl;}
246 if (uf!=0&&ni==0&&(s<min_NNs)){ s+=min_NNs;cout<<" change in s value to have SIG events: "<<s<<endl;}*/
247 //if (uf!=0&&consider_all==0&&av_on_nNN==0&&(b<min_NNb)){ b+=min_NNb;cout<<" change in b value to have BKG events: "<<b<<endl;}
248 //if (uf!=0&&consider_all==0&&av_on_nNN==0&&(s<min_NNs)){ s+=min_NNs;cout<<" change in s value to have SIG events: "<<s<<endl;}
249 
250 //if (uf!=0&&av_on_nNN!=0&&(b>min_NNb)&&(b<))
251 cout<<" min_NNb "<<min_NNb<<" b "<<b<<endl;
252 cout<<"Def. tree e mlp"<<endl;
253 
254 //opening the Test-file
255  TFile* fTEST =TFile::Open(TEST_FILE.Data());
256 cout<<"Def. tree e mlp"<<endl;
257  TTree* NNTree=(TTree*)fTEST->Get("nnTree");
258 cout<<"Def. tree e mlp"<<endl;
259  int entries=NNTree->GetEntries();
260 // int entries=0;
261 
262  cout<<"entries: "<<entries<<endl;
263  cout<<" NNTree->GetEntries() "<<NNTree->GetEntries()<<endl;
264 //exit(0);
265 //Extract information necessary for the tree which defines the mlp
266  int ndim;
267  int ninp;
268  int y;
269  int entriesTot;
270  int bg_entries;
271  int sig_entries;
272 
273  NNTree->SetBranchAddress("#Entries_type",&entriesTot);
274  NNTree->SetBranchAddress("Matrix_dim",&ndim);
275  NNTree->SetBranchAddress("#inputs",&ninp);
276  NNTree->SetBranchAddress("amplitude_mode",&y);
277 
278  NNTree->GetEntry(0);
279  sig_entries=entriesTot;
280  NNTree->GetEntry(entries-1);
281  bg_entries=entriesTot;
282  cout<<"sig "<<sig_entries<<" bg "<<bg_entries<<endl;
283  int const NDIM=ndim;
284  int const nINP=ninp;
285  cout<<"NDIM: "<<NDIM<<endl;
286  cout<<"nINP: "<<nINP<<endl;
287  cout<<"sig e: "<<sig_entries<<endl;
288  cout<<"bg e: "<<bg_entries<<endl;
289 
290 //defining the sample which has less events
291  int minevents=0;
292  if (sig_entries>bg_entries) minevents=bg_entries;
293  else minevents=sig_entries;
294 
295  //if(b==0) b=sig_entries;
296  if(TB==0 && TS==0){
297  TS=minevents;
298  TB=minevents;
299  }
300 cout<<"TS "<<TS<<" TB "<<TB<<" minevents "<<minevents<<endl;
301 //defining compatible parameters
302  if (b<sig_entries){
303  int a =b;
304  b+=sig_entries;
305  cout<<"Error: Bg index<sig_entries: new set of b parameter-> b="<<b<<" instead of b="<<a<<endl;
306  //exit(0);
307 }
308  if(s>sig_entries){
309  int a=s;
310  s-=sig_entries;
311  cout<<"Error: Sig index>sig_entries: new set of s parameter-> s="<<b<<" instead of s="<<a<<endl;
312 }
313 if((TS>sig_entries-s||TB>(bg_entries-(b-sig_entries)))&&(TS==TB)) {TS=minevents-s;TB=minevents-(b-sig_entries);
314  if (TS<TB) TB=TS;
315  else TS=TB;
316  cout<<"Error:S>sig_entries or TB>bg_entries, to maintain ugual number of analysed events TS=TB="<<TB<<endl;
317  }
318  if((TS>sig_entries-s||TB>bg_entries-(b-sig_entries))&&(TS!=TB)) {
319  if(TS>sig_entries) TS=sig_entries-s;
320  if (TB>bg_entries) TB=bg_entries-(b-sig_entries);
321  cout<<"Error:S>sig_entries or TB>bg_entries, new TS and TB values are thus define-> TS="<<TS<<" TB="<<TB<<endl;
322  }
323 
324 
325  char NOMEtot[1024];
326  sprintf(NOMEtot,"%s",NOMEtot_S.Data());
327  cout<<"output name: "<<NOMEtot<<endl;
328 
329 //extracting original files
330  TString SIG_FILE;
331  TString BG_FILE;
332  char FILE_NAME[516];
333  NNTree->SetBranchAddress("Files_name",&FILE_NAME);
334  NNTree->GetEntry(0);
335  SIG_FILE=FILE_NAME;
336  NNTree->GetEntry(entries-1);
337  BG_FILE=FILE_NAME;
338  cout<<"fine ifdef RHO_CC"<<endl;
339 
340 //extracting other information
341  TChain sigTree("waveburst");//search the Tree "waveburst" in files
342  sigTree.Add(SIG_FILE.Data());
343  netevent signal(&sigTree,nIFO);
344  int sig_entries2 = signal.GetEntries();
345  cout << "sig entries2 : " << sig_entries2 << endl;
346 
347  TChain bgTree("waveburst");
348  bgTree.Add(BG_FILE.Data());
349  netevent background(&bgTree,nIFO);
350  int bg_entries2 = background.GetEntries();
351  cout << "bg entries2 : " << bg_entries2 << endl;
352 
353  cout<<"b: "<<b<<endl;
354  cout<<"s: "<<s<<endl;
355 
356  // add leaf
357  Float_t x[nINP];
358  for (int jj=0; jj<nINP;jj++) x[jj]=0.;
359  char ilabel[nINP][16];
360 
361  // define a branch for each input
362  for(int i=0;i<nINP;i++) {
363  sprintf(ilabel[i],"x%i",i+1);
364  NNTree->SetBranchAddress(ilabel[i], &x[i]);
365  }
366 
367 char ofile[1024];
368 sprintf(ofile,"average_file/%s.root",NOMEtot);
369 TFile*f =new TFile(ofile,"RECREATE");
370  TTree* NNTree2=new TTree("Parameters","Parameters");
371  NNTree2->SetDirectory(f);
372 double DtTree;
373  //NNTree->SetBranchAddress("t_duration", &DtTree);
374  NNTree->SetBranchAddress("duration", &DtTree);
375 // defining useful information
376  double average=0.;
377  double out[nNN];
378  for(int y=0; y<nNN; y++) out[y]=0.;
379  double Mc=0.;
380  double NNcc=0.;
381  double NNrho=0.;
382  double Mc_inj=0.;
383  double Dt=0.;
384  //Float_t Dt=0.;
385  double std=0.;
386  int ev_ind=0;
387  int CoG=0;
388  // int ev_ind;
389  int index_ev=0;
390  char TestFile[1024];
391 //adding new information to the original tree
392  NNTree2->Branch("Center_of_Gravity",&CoG,"Center_of_Gravity/I");
393  NNTree2->Branch("duration",&Dt,"duration/D");
394  //NNTree2->Branch("duration",&Dt,"duration/F");
395  NNTree2->Branch("Average",&average,"Average/D");
396  NNTree2->Branch("StandardDevaition",&std,"StandardDeviation/D");
397  NNTree2->Branch("cc",&NNcc,"cc/D");
398  NNTree2->Branch("Mchirp",&Mc,"Mchirp/D");
399  NNTree2->Branch("Mchirp_injected",&Mc_inj,"Mchirp_injected/D");
400  NNTree2->Branch("rho",&NNrho,"rho/D");
401  NNTree2->Branch("index",&index_ev,"index/I");
402 
403 // NNTree2->Branch("event_index",&ev_ind,"event_index/I");
404  NNTree2->Branch("Test_file",&TestFile,"Test_file/C");
405 
406  for(int u=0;u<nNN;u++){
407  char NNoutl[512];
408  char NNoutl2[512];
409  char NNnamel[512];
410  char NNnamel2[512];
411  sprintf(NNoutl,"NNout%i",u);
412  sprintf(NNoutl2,"NNout%i/D",u);
413  sprintf(NNnamel,"NNname%i",u);
414  sprintf(NNnamel2,"NNname%i/C",u);
415  NNTree2->Branch(NNoutl,&out[u],NNoutl2);
416  NNTree2->Branch(NNnamel,&NNi[u],NNnamel2);
417  }
418 
419  char Testf[1024];
420  NNTree2->Branch("TestFile",&Testf,"TestFile/C");
421  sprintf(Testf,"%s",TEST_FILE.Data());
422  int nTestS=0;
423 
424 
425 //defining how many examples to use
426  int scount=0;
427  if(uf==0) nTestS=TS;
428  else {
429  //for(int n=s;n<s+TS;n++) {
430  for(int n=s;n<sig_entries;n++) {
431  int countNN=0;
432  for(int u=0;u<nNN;u++){
433  if (uf!=0&&n>NNs[u]&&n<(NNs[u]+NNnTS[u])) countNN=countNN+1;
434  }
435 
436  // if(consider_all==0&&av_on_nNN==0&&countNN==0)continue; //skip if no network is trained on the considered event
437  // if(consider_all==0&&av_on_nNN!=0&&countNN!=0) {sigskip=sigskip+1; continue; }
438 
439  if(countNN==0&&av_on_nNN!=0) scount=scount+1;
440  else{
441  //if(nNN==1&&countNN==1&&av_on_nNN!=0) scount=scount+1;
442  if(countNN==1&&consider_all==0&&av_on_nNN==0) scount=scount+1;
443  if(countNN<2&&consider_all!=0) scount=scount+1; //if you are indifferently intereseted in average on nNN or nNN-1
444  if(countNN>1){cout<<"Error: training non independent"<<n<<endl; exit(0);} //exit if the ANNs are training on dependent set of events
445  cout<<"n "<<n<<"; countNN "<<countNN<<"; scount "<< scount<<"; consider_all "<<consider_all<<"; av_on_nNN "<<av_on_nNN<<endl;
446  if(scount==TS) break;}
447  }
448  nTestS=scount;
449 }
450 cout<<" nTestS "<< nTestS<<" TS "<<TS<<endl;
451 //exit(0);
452 int B_eff=0;
453 int FA=0;
454 int bg_05=0;
455 int cont_su=0;
456 int cont_su5=0;
457 int cont_su4=0;
458 int cont_su3=0;
459 
460 int nTestB=0;
461  int bcount=0;
462  if(uf==0) nTestB=TB;
463  else {
464  //for(int n=b;n<b+TB;n++) {
465  for(int n=b;n<sig_entries+bg_entries;n++) {
466  int countNN=0;
467  for(int u=0;u<nNN;u++){
468  if (uf!=0&&n>NNb[u]&&n<(NNb[u]+NNnTB[u])) countNN=countNN+1;
469  }
470  if(countNN==0&&av_on_nNN!=0) bcount=bcount+1;
471  //if(nNN==1&&countNN==1&&av_on_nNN!=0) bcount=bcount+1;
472  if(countNN==1&&consider_all==0&&av_on_nNN==0) bcount=bcount+1;
473  if(countNN<2&&consider_all!=0) bcount=bcount+1; //if you are indifferently intereseted in average on nNN or nNN-1
474  if(countNN>1){cout<<"Error: training non independent"<<n<<endl; exit(0);} //exit if the ANNs are training on dependent set of events
475  if(bcount==TB) break;
476  }
477  nTestB=bcount;
478 }
479 
480 if(uf!=0) nTestS=nTestS-1;
481 if(uf!=0) nTestB=nTestB-1;
482 //TB=TB-1;
483 //TS=TS-1;
484 cout<<"TS "<<TS<<" TB "<<TB<<" nTestS "<<nTestS<<" nTestB "<<nTestB<<endl;
485 if(TS0==0&&TB0==0) {
486  if(nTestB>nTestS) {nTestB=nTestS; TB=nTestS; TS=nTestS;}
487  else {nTestS=nTestB; TB=nTestB; TS=nTestB;}
488  }
489 
490 if(nTestS<TS) TS= nTestS;
491 else nTestS=TS;
492 
493 // NNTree2->Branch("#TestSig",&TS,"#TestSig/I");
494  NNTree2->Branch("#TestSig",&TS,"#TestSig/I");
495  //NNTree2->Branch("#TestSig",&nTestS,"#TestSig/I");
496  cout<<"nTestS: "<<nTestS<<" TS: "<<TS<<endl;
497  cout<<"dopo def tree"<<endl;
498 cout<<"s test "<<s<< " s+TS "<<s+TS<<" b "<<b<<" b+ TB "<<b+TB<<" nTestS "<<nTestS<<" TB "<<TB<<" nTestB "<<nTestB<<endl;
499 double params[nINP];
500  int sig_05=0;
501  for (int i=0; i<nINP; i++) params[i]=0.;
502 
503  int S_eff=0;
504  int FD=0;
505 int sigskip=0;
506 
507  TString txt_originaldata(NOMEtot_S);
508  txt_originaldata.ReplaceAll(".root","_originalData.txt");
509  //txt_originaldata.ReplaceAll(".root","_originalData.txt");
510  char txt_originaldata_c[1024];
511  sprintf(txt_originaldata_c,"txt_files/%s.txt",txt_originaldata.Data());
512  ofstream od_txt(txt_originaldata_c);
513 
514 
515  //for(int n=s;n<s+TS;n++) {
516  for(int n=s;n<sig_entries;n++) {
517 double ti_0=0;
518 double fi_0=0;
519 
520  index_ev=n;
521  average=0.;
522  int indNN=-1;
523  int countNN=0;
524  for(int u=0;u<nNN;u++){
525  if (uf!=0&&n>=NNs[u]&&n<(NNs[u]+NNnTS[u])) { indNN=u;countNN=countNN+1;}
526  }
527  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
528  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
529  if(consider_all==0&&av_on_nNN==0&&countNN==0)continue; //skip if no network is trained on the considered event
530  if(consider_all==0&&av_on_nNN!=0&&countNN!=0) {sigskip=sigskip+1; continue; }
531  NNTree->GetEntry(n);
532  signal.GetEntry(n);
533  char line_od[1024];
534 
535  // exracting parameters
536  NNcc=(double)signal.netcc[0];
537  NNrho=(double)signal.rho[1];
538  Mc=(double)signal.chirp[iMc];
539  Mc_inj=(double)signal.chirp[0];
540  Dt=(double)signal.duration[0];
541  //Dt=DtTree;
542  cout<<"DtTree "<<DtTree<<endl;
543  //Dt=(double)signal.duration[0];
544  sprintf(TestFile,"%s",TEST_FILE.Data());
545 // cout<<"background.duration[0] "<<signal.duration[0]<<" background.duration[1] "<<signal.duration[1]<<" background.duration[2] "<<signal.duration[2]<<endl;
546  //exit(0);
547  sprintf(line_od,"%i \n",n);
548  od_txt<<line_od;
549  char line_od2[1024];
550  // evaluating the event
551  for (int i=0; i<nINP; i++){
552  params[i]=x[i];
553 
554  int ti_i=0;
555  int fi_i=0;
556  ti_i=i/NDIM;
557  fi_i=i-ti_i*NDIM;
558  ti_0+=(double)x[i]*ti_i;
559  fi_0+=(double)x[i]*fi_i;
560  sprintf(line_od2,"%s %1.5f",line_od2, x[i]);
561  }
562  sprintf(line_od2,"%s \n",line_od2);
563 
564  if (ti_0<fi_0) CoG=1;
565  else CoG=0;
566 
567 //cout<<" ti_0 "<<ti_0<<" fi_0 "<<fi_0<<" CoG "<<CoG<<endl;
568  od_txt<<line_od2;
569  for (int u=0;u<nNN;u++) {
570 // cout<<" u "<<u<<" nNN "<<nNN<<endl;
571  double output=mlp[u]->Evaluate(0,params);
572 // cout<<output<<endl;
573  out[u]=output;
574  }
575 
576 // cout<<"Dopo param"<<endl;
577 
578 //calculating the average and the standard deviation
579 
580  int c_nNN0=0;
581  for (int u=0;u<nNN;u++){
582  if((u!=indNN&&ni==0)||uf==0) {average=out[u]+average;std+=out[u]*out[u];c_nNN0=c_nNN0+1; if(out[u]<0.6) FD0[u]=FD0[u]+1;}
583  }
584 
585  average=average/(c_nNN0);
586  if((c_nNN0)!=1)std=pow((std/(nNN-1-countNN)-average*average),0.5);
587  else std=-1;
588 
589  char line_od3[1024];
590  sprintf(line_od3,"ev_ind %i average %1.5f Mc %1.5f Mc_inj %1.5f n %i \n",index_ev, average,Mc,Mc_inj,n);
591  od_txt<<line_od3;
592 
593  if (average<0.6) FD=FD+1;
594  NNTree2->Fill();
595  S_eff=S_eff+1;
596  if(S_eff==1) s=n;
597  if(S_eff==TS) break;
598  cout<<" cc "<<NNcc<<" NNrho "<<NNrho<<" Mc_inj "<< Mc_inj<<endl;
599 }
600 //exit(0);
601 od_txt.close();
602 //exit(0);
603 cout<<txt_originaldata_c<<endl;
604 //exit(0);
605 //closing the cycle on SIG events
606 cout<<" S_eff "<<S_eff<<" s "<<s<<" b "<<b<<" sigskip "<<sigskip<<endl;
607 //exit(0);
608 //defining BKG parameters
609 
610 int bgskip=0;
611 //opening the cycle on BKG events
612  for(int n=b;n<sig_entries+bg_entries;n++) {
613 double ti_0=0;
614 double fi_0=0;
615  index_ev=0;
616  index_ev=n;
617  average=0.;
618  int indNN=-1;
619  int countNN=0;
620  for(int u=0;u<nNN;u++){
621  cout<<" uf "<<uf<<" n "<<n<<" u "<<u<<" NN b[u] "<<NNb[u]<<" NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
622  if (uf!=0&&n>=NNb[u]&&n<(NNb[u]+NNnTB[u])) { indNN=u;countNN=countNN+1; }
623  }
624  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
625  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
626  cout<<"consider_all "<<consider_all<<" av_on_nNN "<<av_on_nNN<<" countNN "<<countNN<<" indNN "<<indNN<<endl;
627  if(consider_all==0&&av_on_nNN==0&&countNN==0)continue; //skip if no network is trained on the considered event
628  if(consider_all==0&&av_on_nNN!=0&&countNN!=0) { cout<<" n skipped "<<n<<endl; bgskip=bgskip+1; continue;}
629  NNTree->GetEntry(n);
630  cout<<"BKG->n: "<<n<<"Bg index"<<(n-sig_entries)<<endl;
631  background.GetEntry(n-sig_entries);
632  //NNcc=(double)background.netcc[1];
633  NNcc=(double)background.netcc[0];
634  //NNrho=(double)background.rho[0];
635  NNrho=(double)background.rho[1];
636  Mc=(double)background.chirp[iMc];
637  Mc_inj=(double)background.chirp[0];
638  //Dt=(double)background.t_duration;
639  //Dt=DtTree;
640  Dt=(double)background.duration[0];
641  cout<<"background.duration[0] "<<background.duration[0]<<" background.duration[1] "<<background.duration[1]<<" background.duration[2] "<<background.duration[2]<<endl;
642  /*int hn=0;
643  ev_ind=0;
644  hn=n;
645  ev_ind=hn;*/
646  sprintf(TestFile,"%s",TEST_FILE.Data());
647 
648 for (int i=0; i<nINP; i++){
649  params[i]=x[i];
650  int ti_i=0;
651  int fi_i=0;
652  ti_i=i/NDIM;
653  fi_i=i-ti_i*NDIM;
654  ti_0+=(double)x[i]*ti_i;
655  fi_0+=(double)x[i]*fi_i;
656 
657  }
658  if (ti_0<fi_0) CoG=1;
659  else CoG=0;
660 
661  for(int u=0;u<nNN;u++) {
662  double output=mlp[u]->Evaluate(0,params);
663  cout<<output<<endl;
664  out[u]=output;
665  }
666 
667  int c_nNN0=0;
668  int nnsu=0;
669  for (int u=0;u<nNN;u++){
670  if((u!=indNN&&ni==0)||uf==0) {average=out[u]+average;std+=out[u]*out[u];c_nNN0=c_nNN0+1; TotBg[u]=TotBg[u]+1;if(out[u]>0.6) {FA0[u]=FA0[u]+1;nnsu=nnsu+1;}}
671  }
672 
673 
674  average=average/(c_nNN0);
675  if((c_nNN0)!=1)std=pow((std/(nNN-1-countNN)-average*average),0.5);
676  else std=-1;
677 
678  if(nnsu==6) cont_su=cont_su+1;
679  if(nnsu>4) cont_su5=cont_su5+1;
680  if(nnsu>3) cont_su4=cont_su4+1;
681  if(nnsu>2) cont_su3=cont_su3+1;
682 
683 //calculating the final average value
684 
685 
686 //saving false alarms
687  if(average>0.6) FA=FA+1;
688 
689  NNTree2->Fill();
690  B_eff=B_eff+1;
691  if(B_eff==1) b=n;
692  if(B_eff==TB) break;
693  }
694 //cout<<"bkg filled"<<endl;
695 
696 NNTree2->Write();
697 f->Close();
698 cout<<"B_eff "<<B_eff<<" TB "<<TB<<endl;
699 //cout<<"closed file"<<endl;
700 cout<<ofile<<endl;
701 
702 int cont=0;
703 
704 double freq_c[nNN];
705 double meanf=0.;
706 double dev=0.;
707 
708 for (int yy=0; yy<nNN; yy++){
709  freq_c[yy]=0.;
710 // cout<<" FA0[yy] "<<FA0[yy]<<" FD0[yy] "<<FD0[yy]<<" FD "<<FD<<" TotBg[yy] "<<TotBg[yy]<<endl;
711  if(TotBg[yy]!=0){freq_c[yy]=(double)FA0[yy]/TotBg[yy];
712  //cout<<" freq_c[yy] "<<freq_c[yy]<<endl;
713  }
714  if(freq_c[yy]!=0) {meanf=freq_c[yy]+meanf;cont=cont+1;
715  //cout<<" cont "<<cont<<endl;
716  }
717  dev=freq_c[yy]*freq_c[yy]+dev;
718 }
719 
720 if(cont==0) cout<<"Error cont==0"<<endl;
721 if(cont!=0) meanf=meanf/cont;
722 dev=0.;
723 for (int yy=0; yy<nNN; yy++){
724 //cout<<" dev "<<dev<<endl;
725 //cout<<"freq_c[yy] "<<freq_c[yy]<<" meanf "<<meanf<<endl;
726 if(freq_c[yy]!=0)dev+=(freq_c[yy]-meanf)*(freq_c[yy]-meanf);
727 }
728 double McFAdes=FAdes;
729 int FAth_n=FAdes*B_eff;
730 int McFAth_n=FAdes*B_eff;
731 cout<<"FAth_n "<<FAth_n<<" FAdes*B_eff "<<FAdes*B_eff<<endl;
732 int FDth_n=-1;
733 int McFDth_n=-1;
734 double thresFA=-1;
735 double McthresFA=-1;
736 Annth(ofile, FAth_n, FDth_n, thresFA);
737 Mcth(ofile, McFAth_n, McFDth_n, McthresFA);
738 graph(ofile);
739 PlotsAv_cc(ofile);
740 PlotsAv_Mc(ofile);
741 SNR_plots(ofile);
742 CoG_plots(ofile);
743 duration_plot(ofile);
744 
745 if(cont!=0) dev=pow(dev/(cont-1),0.5);
746 cout<<"meanf "<<meanf<<" dev "<<dev<<endl;
747 cout<<" FA average "<<FA<<endl;
748 cout<<" cont_su "<<cont_su<<" cont_su5 "<<cont_su5<<" cont_su4 "<<cont_su4<<" cont_su3 "<<cont_su3<<endl;
749 
750 cout<<" S_eff "<<S_eff<<" B_eff "<<B_eff<<" s "<<s<<" b "<<b<<" bgskip "<<bgskip<<" sigskip "<<sigskip<<endl;
751 cout<<" FA0[1] "<<FA0[1]<<" TotBg[1] "<<TotBg[1]<<endl;
752 cout<<" FD0[1] "<<FD0[1]<<" TotBg[1] "<<TotBg[1]<<endl;
753 //double S_eff2=(double
754 double FDdes=(double)FDth_n/S_eff;
755 double McFDdes=(double)McFDth_n/S_eff;
756 FAdes=(double)FAth_n/B_eff;
757 McFAdes=(double)McFAth_n/B_eff;
758 cout<<"FAth_n "<<FAth_n<<" FAdes: "<<FAdes<<" ANN_av_FDdes "<<FDdes<<" ANN_av_FDth_n "<<FDth_n<<" ANN_av_thresFA "<<thresFA<<endl;
759 cout<<"McFAth_n "<<McFAth_n<<" McFAdes: "<<McFAdes<<" Mc_FDdes "<<McFDdes<<" McFDth_n "<<McFDth_n<<" McthresFA "<<McthresFA<<endl;
760 }
761 
763  TString name(ifile);
764  name.ReplaceAll("average_file/","");
765  TFile* fTEST =TFile::Open(ifile.Data());
766  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
767  double av;
768  double cc;
769  double rho;
770  int nSi;
771  NNTree2->SetBranchAddress("Average",&av);
772  NNTree2->SetBranchAddress("cc",&cc);
773  NNTree2->SetBranchAddress("rho",&rho);
774  NNTree2->SetBranchAddress("#TestSig",&nSi);
775  NNTree2->GetEntry(0);
776  int const nSig=nSi;
777  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
778  cout<<" BG: "<<NNTree2->GetEntries()-nSi<<endl;
779  int const ncurve=nANN*nCC;
780  cout<<"dentro funzione dopodef"<<endl;
781 //LOG(NBg)vs RHO------------------------------------------
782  double* rhoSig[ncurve];
783  for (int i=0;i<ncurve;i++) rhoSig[i]=new double[nSig];
784  cout<<"dopo def rhoSig"<<endl;
785  //double rhoSig[20][10];
786  int NSig[ncurve];
787 // int nBg=0;
788  int const nBg=NNTree2->GetEntries()-nSig;
789  for (int i=0;i<ncurve;i++) {
790  NSig[i]=0;
791  for (int j=0;j<nSig;j++) rhoSig[i][j]=0.;
792  }
793  cout<<"dopo def rhoSig"<<endl;
794  double* rhoBg[ncurve];
795  for (int i=0;i<ncurve;i++) rhoBg[i]=new double[nBg];
796  //double rhoBg[20][10];
797  int NBg[ncurve];
798  for (int i=0;i<ncurve;i++) {
799  NBg[i]=0;
800  for (int j=0;j<nBg;j++) rhoBg[i][j]=0.;
801  }
802  cout<<"dopo def rhoBg"<<endl;
803  double ccTh[nCC];
804  for (int i=0;i<nCC;i++) ccTh[i]=0.;
805  double NNTh[nANN];
806  for (int i=0;i<nANN;i++) NNTh[i]=0.;
807  //double deltacc=0.;
808 // double deltaANN=0.;
809 // deltacc=0.2/nCC;
810  //deltaANN=0.6/(nANN-1);
811 
812  cout<<NNTree2->GetEntries()<<endl;
813  for(int n=0;n<NNTree2->GetEntries();n++){
814  cout<<n<<endl;
815  NNTree2->GetEntry(n);
816  cout<<"rho "<<rho<<" cc "<<cc<<" av "<<av<<endl;
817  for(int i=0; i<nCC;i++){
818  ccTh[i]=0.5+i*deltacc;
819  if(cc<ccTh[i]) continue;
820  for(int j=0; j<nANN;j++){
821  if(j==0) NNTh[j]=-1000.;
822  //else NNTh[j]=0.5+(j-1)*deltaANN;
823  //else NNTh[j]=0.1+(j-1)*deltaANN;
824  else NNTh[j]=0.+(j)*deltaANN;
825  //else NNTh[j]=0.+(j-1)*deltaANN/1000.;
826  //else NNTh[j]=1.;
827  if(av<NNTh[j]) continue;
828  int ni=0;
829  if(n>=nSig) {
830 
831  NBg[i*nANN+j]= NBg[i*nANN+j]+1;
832  while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
833  rhoBg[i*nANN+j][ni]=rho;
834  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
835 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
836  }
837  else {
838  NSig[i*nANN+j]= NSig[i*nANN+j]+1;
839  while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
840  rhoSig[i*nANN+j][ni]=rho;
841  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
842 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
843  }
844  // }
845  }
846  }
847  }
848  cout<<"dopo riempimento variabili"<<endl;
849  int* indexS[ncurve];
850  for (int i=0;i<ncurve;i++) indexS[i]=new int[nSig];
851 
852  TGraph * gS[ncurve];
853  for (int y=0;y<ncurve;y++) {
854  int igS=0;
855  int igS_p=0;
856  /* int indexS[nSig];
857  double rhoS[nSig];
858  for(int i=0;i<nSig;i++) {
859  rhoS[i]=0.;
860  indexS[i]=0;
861  }*/
862  // ig=1;
863  // for(int i=0;i<nSig;i++) rhoS[i]=rhoSig[y][i];
864  gS[y]=new TGraph();
865 // gS[y]->SetMarkerStyle(7);
866  TMath::Sort(nSig,rhoSig[y],indexS[y],false);
867 // cout<<"dopo Sort "<<y<<endl;
868  for (int k=0;k<nSig;k++) {
869  int ii=indexS[y][k];
870  int yy=0;
871  if (k>0){
872 // cout<<"k "<<k<<endl;
873  int ij=indexS[y][k-1];
874  //if(rhoSig[y][ii]!=0&&rhoSig[y][ii]!=rhoSig[y][ij]) {
875  if(rhoSig[y][ii]!=0) {
876  yy=NSig[y]-igS;
877  //gS[y]->SetPoint(igS,rhoSig[y][ii],yy);
878  if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
879  cout<<"igS"<<igS<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
880  igS=igS+1;
881  }
882  }
883  else {
884  if(rhoSig[y][ii]!=0){
885  yy=NSig[y]-igS;
886  gS[y]->SetPoint(0,rhoSig[y][ii],yy);
887  igS=igS+1;
888 // cout<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
889  }
890 
891  }
892  }
893  }
894  // cout<<"dopo inserimento puntiiS"<<endl;
895 // cout<<ncurve<<endl;
896  int* indexB[ncurve];
897  for (int i=0;i<ncurve;i++) indexB[i]=new int[nBg];
898 
899  TGraph * gB[ncurve];
900  for (int y=0;y<ncurve;y++) {
901  int igB=0;
902  int igB_p=0;
903  gB[y]=new TGraph();
904  TMath::Sort(nBg,rhoBg[y],indexB[y],false);
905 // cout<<"dopo Sort "<<y<<endl;
906  for (int k=0;k<nBg;k++) {
907  int ii=indexB[y][k];
908  int yy=0;
909  if (k>0){
910  int ij=indexB[y][k-1];
911  //if(rhoBg[y][ii]!=0&&rhoBg[y][ii]!=rhoBg[y][ij]) {
912  if(rhoBg[y][ii]!=0) {
913  yy=NBg[y]-igB;
914  //gB[y]->SetPoint(igB,rhoBg[y][ii],yy);
915  if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
916  igB=igB+1;
917 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
918  }
919  }
920  else {
921  if(rhoBg[y][ii]!=0) {
922  yy=NBg[y]-igB;
923  gB[y]->SetPoint(0,rhoBg[y][ii],yy);
924  igB=igB+1;
925 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
926  }
927  }
928  }
929  }
930  cout<<"dopo inserimento puntiB"<<endl;
931  //gB[1]->SetMarkerStyle(7);
932  //gB[1]->SetPoint(1,1,2);
933  TCanvas* cS=new TCanvas("Efficiency_vs_rho","Efficiency_vs_rho",0,0,1200,700);
934  cS->Divide(2,2);
935  //cS->cd(1)->SetLogy();
936  cS->cd(1);
937  TMultiGraph* mg1=new TMultiGraph();
938 // gS[0]->SetMarkerStyle(7);
939  gS[0]->SetMarkerColor(2);
940  gS[0]->SetLineColor(2);
941  mg1->SetTitle("cc=0.5;rho;#Events");
942  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
943 // gS[0]->Draw("apl");
944  for (int h=1;h<nANN;h++){
945  gS[h]->SetMarkerColor(3);
946  gS[h]->SetLineColor(3);
947 // gS[h]->SetMarkerStyle(h+1);
948  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
949  // gS[h]->Draw("apl,same");
950  }
951  mg1->Draw("apl");
952  //cS->cd(2)->SetLogy();
953  cS->cd(2);
954  TMultiGraph* mg2=new TMultiGraph();
955 // gS[nANN]->SetMarkerStyle(7);
956  gS[nANN]->SetMarkerColor(2);
957  gS[nANN]->SetLineColor(2);
958  mg2->SetTitle("cc=0.55;rho;#Events");
959  if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
960  for (int h=1;h<nANN;h++){
961  gS[nANN+h]->SetMarkerColor(3);
962  gS[nANN+h]->SetLineColor(3);
963 // gS[nANN+h]->SetMarkerStyle(h+1);
964  if(gS[nANN+h]->GetN()!=0) mg2->Add(gS[nANN+h]);
965  // gS[nANN+h]->Draw("apl,same");
966  }
967  mg2->Draw("apl");
968  //cS->cd(3)->SetLogy();
969  cS->cd(3);
970  TMultiGraph* mg3=new TMultiGraph();
971 // gS[nANN*2]->SetMarkerStyle(7);
972  gS[nANN*2]->SetMarkerColor(2);
973  gS[nANN*2]->SetLineColor(2);
974  mg3->SetTitle("cc=0.6;rho;#Events");
975  if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
976  for (int h=1;h<nANN;h++){
977  gS[2*nANN+h]->SetMarkerColor(3);
978  gS[2*nANN+h]->SetLineColor(3);
979 // gS[2*nANN+h]->SetMarkerStyle(h+1);
980  if(gS[2*nANN+h]->GetN()!=0) mg3->Add(gS[2*nANN+h]);
981  // gS[2*nANN+h]->Draw("apl,same");
982  }
983  mg3->Draw("apl");
984  //cS->cd(4)->SetLogy();
985  cS->cd(4);
986  TMultiGraph* mg4=new TMultiGraph();
987 // gS[nANN*3]->SetMarkerStyle(7);
988  gS[nANN*3]->SetMarkerColor(2);
989  gS[nANN*3]->SetLineColor(2);
990  mg4->SetTitle("cc=0.65;rho;#Events");
991  if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
992  // gS[nANN*3]->Draw("apl");
993  for (int h=1;h<nANN;h++){
994  gS[3*nANN+h]->SetMarkerColor(3);
995  gS[3*nANN+h]->SetLineColor(3);
996 // gS[3*nANN+h]->SetMarkerStyle(h+1);
997  if(gS[3*nANN+h]->GetN()!=0) mg4->Add(gS[3*nANN+h]);
998  // gS[3*nANN+h]->Draw("apl,same");
999  }
1000  mg4->Draw("apl");
1001  cout<<"nuovo canv"<<endl;
1002  TCanvas* cB=new TCanvas("Number_vs_rho","Number_vs_rho",0,0,1200,700);
1003  cB->Divide(2,2);
1004  cB->cd(1)->SetLogy();
1005  TMultiGraph* mg1B=new TMultiGraph();
1006 // gB[0]->SetMarkerStyle(7);
1007  gB[0]->SetMarkerColor(2);
1008  gB[0]->SetLineColor(2);
1009  mg1B->SetTitle("cc=0.5;rho;#Events");
1010  if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
1011  for (int h=1;h<nANN;h++){
1012  gB[h]->SetMarkerColor(3);
1013  gB[h]->SetLineColor(3);
1014  // gB[h]>SetMarkerStyle(h+1);
1015  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1016  //gB[h]->Draw("apl,same");
1017  }
1018  mg1B->Draw("apl");
1019  cB->cd(2)->SetLogy();
1020  TMultiGraph* mg2B=new TMultiGraph();
1021  //gB[nANN]->SetMarkerStyle(7);
1022  gB[nANN]->SetMarkerColor(2);
1023  gB[nANN]->SetLineColor(2);
1024  mg2B->SetTitle("cc=0.55;rho;#Events");
1025  if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
1026  for (int h=1;h<nANN;h++){
1027  gB[nANN+h]->SetMarkerColor(3);
1028  gB[nANN+h]->SetLineColor(3);
1029  //gB[nANN+h]>SetMarkerStyle(h+1);
1030  if(gB[nANN+h]->GetN()!=0) mg2B->Add(gB[nANN+h]);
1031  //gB[h]->Draw("apl,same");
1032  }
1033  mg2B->Draw("apl");
1034  cB->cd(3)->SetLogy();
1035  TMultiGraph* mg3B=new TMultiGraph();
1036 // gB[2*nANN]->SetMarkerStyle(7);
1037  gB[2*nANN]->SetMarkerColor(2);
1038  gB[2*nANN]->SetLineColor(2);
1039  mg3B->SetTitle("cc=0.6;rho;#Events");
1040  if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
1041  for (int h=1;h<nANN;h++){
1042  gB[2*nANN+h]->SetMarkerColor(3);
1043  gB[2*nANN+h]->SetLineColor(3);
1044 // gB[2*nANN+h]>SetMarkerStyle(h+1);
1045  if(gB[2*nANN+h]->GetN()!=0) mg3B->Add(gB[2*nANN+h]);
1046  //gB[h]->Draw("apl,same");
1047  }
1048  mg3B->Draw("apl");
1049  cB->cd(4)->SetLogy();
1050  TMultiGraph* mg4B=new TMultiGraph();
1051 // gB[3*nANN]->SetMarkerStyle(7);
1052  gB[3*nANN]->SetMarkerColor(2);
1053  gB[3*nANN]->SetLineColor(2);
1054  mg4B->SetTitle("cc=0.65;rho;#Events");
1055  if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
1056  for (int h=1;h<nANN;h++){
1057  gB[3*nANN+h]->SetMarkerColor(3);
1058  gB[3*nANN+h]->SetLineColor(3);
1059 // gB[3*nANN+h]>SetMarkerStyle(h+1);
1060  if(gB[3*nANN+h]->GetN()!=0) mg4B->Add(gB[3*nANN+h]);
1061  //gB[h]->Draw("apl,same");
1062  }
1063  mg4B->Draw("apl");
1064 
1065 // cout<<"dopo Draw()"<<endl;
1066  TString CnameS(name);
1067  TString CnameB(name);
1068  TString CnameSroot(name);
1069  TString CnameBroot(name);
1070  char CnameS2[1024];
1071  char CnameB2[1024];
1072  char CnameS2root[1024];
1073  char CnameB2root[1024];
1074  CnameS.ReplaceAll(".root",".png");
1075  CnameB.ReplaceAll(".root",".png");
1076  sprintf(CnameS2,"logN_rho_av/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameS.Data());
1077  sprintf(CnameB2,"logN_rho_av/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameB.Data());
1078  sprintf(CnameS2root,"logN_rho_av/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameSroot.Data());
1079  sprintf(CnameB2root,"logN_rho_av/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameBroot.Data());
1080  cS->SaveAs(CnameS2);
1081  cB->SaveAs(CnameB2);
1082  cS->Print(CnameS2root);
1083  cB->Print(CnameB2root);
1084 // cout<<"fine"<<endl;
1085 
1086 }
1087 
1088 
1089 void Annth(TString ifile, int &FAth_n, int &FDth_n, double &thresFA){
1090  TString name(ifile);
1091  name.ReplaceAll("average_file/","");
1092  TFile* fTEST =TFile::Open(ifile.Data());
1093  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1094  double av;
1095  double cc;
1096  double rho;
1097  int nSi;
1098  NNTree2->SetBranchAddress("Average",&av);
1099  NNTree2->SetBranchAddress("cc",&cc);
1100  NNTree2->SetBranchAddress("rho",&rho);
1101  NNTree2->SetBranchAddress("#TestSig",&nSi);
1102  NNTree2->GetEntry(0);
1103  int const nSig=nSi;
1104  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1105  int const ncurve2=nRHO*nCC;
1106 
1107 
1108  double* ANNSig[ncurve2];
1109  for (int i=0;i<ncurve2;i++) ANNSig[i]=new double[nSig];
1110  //double rhoSig[20][10];
1111  int NSig[ncurve2];
1112 // int nBg=0;
1113  int const nBg=NNTree2->GetEntries()-nSig;
1114  for (int i=0;i<ncurve2;i++) {
1115  NSig[i]=0;
1116  for (int j=0;j<nSig;j++) ANNSig[i][j]=0.;
1117  }
1118  double* ANNBg[ncurve2];
1119  for (int i=0;i<ncurve2;i++) ANNBg[i]=new double[nBg];
1120 
1121  //double rhoBg[20][10];
1122  int NBg[ncurve2];
1123  for (int i=0;i<ncurve2;i++) {
1124  NBg[i]=0;
1125  for (int j=0;j<nBg;j++) ANNBg[i][j]=0.;
1126  }
1127  double ccTh[nCC];
1128  for (int i=0;i<nCC;i++) ccTh[i]=0.;
1129  double rhoTh[nRHO];
1130  for (int i=0;i<nRHO;i++) rhoTh[i]=0.;
1131  // double deltacc=0.;
1132  // double deltarho=0.;
1133  // deltacc=0.2/nCC;
1134 // deltarho=1./(nRHO);
1135 
1136 //int thresFA=-1;
1137  for(int n=0;n<NNTree2->GetEntries();n++){
1138  NNTree2->GetEntry(n);
1139  cout<<"rho "<<rho<<" cc "<<cc<<" av "<<av<<endl;
1140  for(int i=0; i<nCC;i++){
1141  ccTh[i]=0.5+i*deltacc;
1142  ccTh[0]=0.;
1143  if(cc<ccTh[i]) continue;
1144  for(int j=0; j<nRHO;j++){
1145  rhoTh[j]=5+j*deltarho;
1146  rhoTh[0]=0.;
1147  if(rho<rhoTh[j]) continue;
1148  int ni=0;
1149  if(n>=nSig) {
1150  NBg[i*nRHO+j]= NBg[i*nRHO+j]+1;
1151  if(i*nRHO+j==0) cout<<" NBg[i*nRHO+j] "<<NBg[i*nRHO+j]<<endl;
1152  while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
1153  ANNBg[i*nRHO+j][ni]=av;
1154  // if (NBg[0]==FAth_n) thresFA=av;
1155  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1156  }
1157  else {
1158  NSig[i*nRHO+j]= NSig[i*nRHO+j]+1;
1159  if(i*nRHO+j==0) cout<<" NSig[i*nRHO+j] "<<NSig[i*nRHO+j]<<endl;
1160  while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
1161  ANNSig[i*nRHO+j][ni]=av;
1162  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1163  }
1164  }
1165  }
1166  }
1167  int* indexS[ncurve2];
1168  for (int i=0;i<ncurve2;i++) indexS[i]=new int[nSig];
1169 
1170  TGraph * gS[ncurve2];
1171  for (int y=0;y<ncurve2;y++) {
1172  int igS=0;
1173  int igS_p=0;
1174  gS[y]=new TGraph();
1175  TMath::Sort(nSig,ANNSig[y],indexS[y],false);
1176  for (int k=0;k<nSig;k++) {
1177  int ii=indexS[y][k];
1178  int yy=0;
1179  if (k>0){
1180  //cout<<"k "<<k<<endl;
1181  int ij=indexS[y][k-1];
1182  //if(ANNSig[y][ii]!=0&&ANNSig[y][ii]!=ANNSig[y][ij]) {
1183  if(ANNSig[y][ii]!=0) {
1184  yy=NSig[y]-igS;
1185  //gS[y]->SetPoint(igS,ANNSig[y][ii],yy);
1186  if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
1187  // cout<<"igS"<<igS<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1188  igS=igS+1;
1189 
1190  }
1191  }
1192  else {
1193  if(ANNSig[y][ii]!=0){
1194  yy=NSig[y]-igS;
1195  gS[y]->SetPoint(0,ANNSig[y][ii],yy);
1196  igS=igS+1;
1197  // cout<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1198  }
1199 
1200  }
1201  }
1202  }
1203 
1204 
1205 int thres_ind=0;
1206  int* indexB[ncurve2];
1207  for (int i=0;i<ncurve2;i++) indexB[i]=new int[nBg];
1208 
1209  TGraph * gB[ncurve2];
1210  for (int y=0;y<ncurve2;y++) {
1211  int igB=0;
1212  int igB_p=0;
1213  gB[y]=new TGraph();
1214  TMath::Sort(nBg,ANNBg[y],indexB[y],false);
1215  // cout<<"dopo Sort "<<y<<endl;
1216  for (int k=0;k<nBg;k++) {
1217  int ii=indexB[y][k];
1218  int ik=indexB[y][k-1];
1219  int yy=0;
1220  if (k>0){
1221  int ij=indexB[y][k-1];
1222  //if(ANNBg[y][ii]!=0&&ANNBg[y][ii]!=ANNBg[y][ij]) {
1223  if(ANNBg[y][ii]!=0) {
1224  yy=NBg[y]-igB;
1225  if(y==0 && yy==FAth_n+1) {thresFA=ANNBg[y][ii];}
1226  if (y==0 && yy<FAth_n+1) if(ANNBg[y][ii]==ANNBg[y][ik]){FAth_n=FAth_n-1;}
1227  if(y==0) cout<<"yy "<<yy<<" y "<<y<<" FAth_n "<<FAth_n<<" thresFA "<<thresFA<<" ANNBg[y][ii] "<<ANNBg[y][ii]<<endl;
1228  //gB[y]->SetPoint(igB,ANNBg[y][ii],yy);
1229  if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
1230  igB=igB+1;
1231  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1232  }
1233  }
1234  else {
1235  if(ANNBg[y][ii]!=0) {
1236  yy=NBg[y]-igB;
1237  gB[y]->SetPoint(0,ANNBg[y][ii],yy);
1238  igB=igB+1;
1239  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1240  }
1241  }
1242  }
1243  }
1244 //int FDth_n=0;
1245 //for(int i=0; i<nCC;i++){
1246 // for(int j=0; j<nRHO;j++){
1247 FDth_n=0;
1248  for(int ni=1;ni<nSig;ni++){
1249  cout<<"FAth_n "<<FAth_n<<" thresFA "<<thresFA<<" ANNSig[0][indexS[0][ni]] "<<ANNSig[0][indexS[0][ni]]<<" FDth_n "<<FDth_n<<" NSig[0]-(ni-1 )"<<NSig[0]-(ni-1)<<" NSig[0] "<<NSig[0]<<endl;
1250 // if (ANNSig[0][indexS[0][ni]]==thresFA || (ANNSig[0][indexS[0][ni-1]]<thresFA && ANNSig[0][indexS[0][ni]]>thresFA)) FDth_n=NSig[0]-(ni-1);
1251  if (ANNSig[0][indexS[0][ni]]<=thresFA) FDth_n=FDth_n+1;
1252  }
1253 // }
1254 //}
1255 //exit(0);
1256  TCanvas* cS=new TCanvas("Efficiency_vs_ANN","Efficiency_vs_ANN",0,0,1200,700);
1257  cS->Divide(2,2);
1258  //cS->cd(1)->SetLogy();
1259  cS->cd(1);
1260  TMultiGraph* mg1=new TMultiGraph();
1261  mg1->SetTitle("cc: no_cut;ANN;#Events");
1262  for (int h=0;h<nRHO;h++){
1263  gS[h]->SetLineColor(4);
1264  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
1265  }
1266  mg1->Draw("al");
1267  cS->cd(2);
1268  // cS->cd(2)->SetLogy();
1269  TMultiGraph* mg2=new TMultiGraph();
1270  mg2->SetTitle("cc=0.55;ANN;#Events");
1271  for (int h=0;h<nRHO;h++){
1272  gS[nRHO+h]->SetLineColor(4);
1273  if(gS[nRHO+h]->GetN()!=0) mg2->Add(gS[nRHO+h]);
1274  }
1275  mg2->Draw("al");
1276 
1277  //cS->cd(3)->SetLogy();
1278  cS->cd(3);
1279  TMultiGraph* mg3=new TMultiGraph();
1280  mg3->SetTitle("cc=0.6;ANN;#Events");
1281  for (int h=0;h<nRHO;h++){
1282  gS[2*nRHO+h]->SetLineColor(4);
1283  if(gS[2*nRHO+h]->GetN()!=0) mg3->Add(gS[2*nRHO+h]);
1284  }
1285  mg3->Draw("al");
1286  //cS->cd(4)->SetLogy();
1287  cS->cd(4);
1288  TMultiGraph* mg4=new TMultiGraph();
1289  mg4->SetTitle("cc=0.65;ANN;#Events");
1290  for (int h=0;h<nRHO;h++){
1291  gS[3*nRHO+h]->SetLineColor(4);
1292  if(gS[3*nRHO+h]->GetN()!=0) mg4->Add(gS[3*nRHO+h]);
1293  }
1294  mg4->Draw("al");
1295 
1296  TCanvas* cB=new TCanvas("Number_vs_ANN","Number_vs_ANN",0,0,1200,700);
1297  cB->Divide(2,2);
1298  cB->cd(1)->SetLogy();
1299  TMultiGraph* mg1B=new TMultiGraph();
1300  mg1B->SetTitle("cc: no_cut;ANN;#Events");
1301  for (int h=0;h<nRHO;h++){
1302  gB[h]->SetLineColor(4);
1303  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1304  }
1305  mg1B->Draw("al");
1306  cB->cd(2)->SetLogy();
1307  TMultiGraph* mg2B=new TMultiGraph();
1308  mg2B->SetTitle("cc=0.55;ANN;#Events");
1309  for (int h=0;h<nRHO;h++){
1310  gB[nRHO+h]->SetLineColor(4);
1311  if(gB[nRHO+h]->GetN()!=0) mg2B->Add(gB[nRHO+h]);
1312  }
1313  mg2B->Draw("al");
1314  cB->cd(3)->SetLogy();
1315  TMultiGraph* mg3B=new TMultiGraph();
1316  mg3B->SetTitle("cc=0.6;ANN;#Events");
1317  for (int h=0;h<nRHO;h++){
1318  gB[2*nRHO+h]->SetLineColor(4);
1319  if(gB[2*nRHO+h]->GetN()!=0) mg3B->Add(gB[2*nRHO+h]);
1320  }
1321  mg3B->Draw("al");
1322  cB->cd(4)->SetLogy();
1323  TMultiGraph* mg4B=new TMultiGraph();
1324  mg4B->SetTitle("cc=0.65;ANN;#Events");
1325  for (int h=0;h<nRHO;h++){
1326  gB[3*nRHO+h]->SetLineColor(4);
1327  if(gB[3*nRHO+h]->GetN()!=0) mg4B->Add(gB[3*nRHO+h]);
1328  }
1329  mg4B->Draw("al");
1330 
1331 
1332  //cout<<"dopo Draw()"<<endl;
1333  TString CnameS(name);
1334  TString CnameB(name);
1335  TString CnameSroot(name);
1336  TString CnameBroot(name);
1337  char CnameS2[1024];
1338  char CnameB2[1024];
1339  char CnameS2root[1024];
1340  char CnameB2root[1024];
1341  CnameS.ReplaceAll(".root",".png");
1342  CnameB.ReplaceAll(".root",".png");
1343  sprintf(CnameS2,"ANNthres_av/N_ANN_S_%s",CnameS.Data());
1344  sprintf(CnameB2,"ANNthres_av/N_ANN_B_%s",CnameB.Data());
1345  sprintf(CnameS2root,"ANNthres_av/N_ANN_S_%s",CnameSroot.Data());
1346  sprintf(CnameB2root,"ANNthres_av/N_ANN_B_%s",CnameBroot.Data());
1347  cS->SaveAs(CnameS2);
1348  cB->SaveAs(CnameB2);
1349  cS->Print(CnameS2root);
1350  cB->Print(CnameB2root);
1351  //cout<<"fine"<<endl;
1352 
1353 //CARTELLA Annth
1354 
1355 
1356 
1357 }
1358 
1359 void Mcth(TString ifile, int &McFAth_n, int &McFDth_n, double &McthresFA){
1360 TString name(ifile);
1361  name.ReplaceAll("outfile/","");
1362  name.ReplaceAll("average_file/","");
1363  TFile* fTEST =TFile::Open(ifile.Data());
1364  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1365  //double outbis;
1366  double av;
1367  double out;
1368  double cc;
1369  double Mc;
1370  double Mc_inj;
1371  double rho;
1372  int nSi;
1373 // NNTree2->SetBranchAddress("ANNout",&out);
1374  NNTree2->SetBranchAddress("Mchirp",&Mc);
1375  NNTree2->SetBranchAddress("Average",&av);
1376  NNTree2->SetBranchAddress("cc",&cc);
1377  NNTree2->SetBranchAddress("rho",&rho);
1378  NNTree2->SetBranchAddress("Mchirp_injected",&Mc_inj);
1379  NNTree2->SetBranchAddress("#TestSig",&nSi);
1380  NNTree2->GetEntry(0);
1381  int const nSig=nSi;
1382  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1383  int const ncurve2=nRHO*nCC;
1384 
1385  double* McSig[ncurve2];
1386  for (int i=0;i<ncurve2;i++) McSig[i]=new double[nSig];
1387  //double rhoSig[20][10];
1388  int NSig[ncurve2];
1389 // int nBg=0;
1390  int const nBg=NNTree2->GetEntries()-nSig;
1391  for (int i=0;i<ncurve2;i++) {
1392  NSig[i]=0;
1393  for (int j=0;j<nSig;j++) McSig[i][j]=0.;
1394  }
1395  double* McBg[ncurve2];
1396  for (int i=0;i<ncurve2;i++) McBg[i]=new double[nBg];
1397 
1398  //double rhoBg[20][10];
1399  int NBg[ncurve2];
1400  for (int i=0;i<ncurve2;i++) {
1401  NBg[i]=0;
1402  for (int j=0;j<nBg;j++) McBg[i][j]=0.;
1403  }
1404  double ccTh[nCC];
1405  for (int i=0;i<nCC;i++) ccTh[i]=0.;
1406  double rhoTh[nRHO];
1407  for (int i=0;i<nRHO;i++) rhoTh[i]=0.;
1408 // double deltacc=0.;
1409 // double deltarho=0.;
1410 // deltacc=0.2/nCC;
1411 // deltarho=1./(nRHO);
1412 
1413  for(int n=0;n<NNTree2->GetEntries();n++){
1414  NNTree2->GetEntry(n);
1415  cout<<"rho "<<rho<<" cc "<<cc<<" av "<<av<<endl;
1416  for(int i=0; i<nCC;i++){
1417  ccTh[i]=0.5+i*deltacc;
1418  ccTh[0]=0.;
1419  if(cc<ccTh[i]) continue;
1420  for(int j=0; j<nRHO;j++){
1421  rhoTh[j]=5+j*deltarho;
1422  rhoTh[0]=0.;
1423  if(rho<rhoTh[j]) continue;
1424  int ni=0;
1425  if(n>=nSig) {
1426  NBg[i*nRHO+j]= NBg[i*nRHO+j]+1;
1427  if(i*nRHO+j==0) cout<<" NBg[i*nRHO+j] "<<NBg[i*nRHO+j]<<endl;
1428  while(McBg[i*nRHO+j][ni]!=0)ni=ni+1;
1429  McBg[i*nRHO+j][ni]=Mc;
1430  // if (NBg[0]==FAth_n) thresFA=av;
1431  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1432  }
1433  else {
1434  NSig[i*nRHO+j]= NSig[i*nRHO+j]+1;
1435  if(i*nRHO+j==0) cout<<" NSig[i*nRHO+j] "<<NSig[i*nRHO+j]<<endl;
1436  while(McSig[i*nRHO+j][ni]!=0)ni=ni+1;
1437  McSig[i*nRHO+j][ni]=Mc;
1438  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1439  }
1440  }
1441  }
1442  }
1443 
1444  int* indexS[ncurve2];
1445  for (int i=0;i<ncurve2;i++) indexS[i]=new int[nSig];
1446 
1447  TGraph * gS[ncurve2];
1448  for (int y=0;y<ncurve2;y++) {
1449  int igS=0;
1450  int igS_p=0;
1451  gS[y]=new TGraph();
1452  TMath::Sort(nSig,McSig[y],indexS[y],false);
1453  for (int k=0;k<nSig;k++) {
1454  int ii=indexS[y][k];
1455  int yy=0;
1456  if (k>0){
1457  //cout<<"k "<<k<<endl;
1458  int ij=indexS[y][k-1];
1459  //if(ANNSig[y][ii]!=0&&ANNSig[y][ii]!=ANNSig[y][ij]) {
1460  if(McSig[y][ii]!=0) {
1461  yy=NSig[y]-igS;
1462  //gS[y]->SetPoint(igS,ANNSig[y][ii],yy);
1463  if(McSig[y][ii]!=McSig[y][ij]) gS[y]->SetPoint(igS_p++,McSig[y][ii],yy);
1464  // cout<<"igS"<<igS<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1465  igS=igS+1;
1466 
1467  }
1468  }
1469  else {
1470  if(McSig[y][ii]!=0){
1471  yy=NSig[y]-igS;
1472  gS[y]->SetPoint(0,McSig[y][ii],yy);
1473  igS=igS+1;
1474  // cout<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1475  }
1476 
1477  }
1478  }
1479  }
1480 
1481 int thres_ind=0;
1482  int* indexB[ncurve2];
1483  for (int i=0;i<ncurve2;i++) indexB[i]=new int[nBg];
1484 
1485  TGraph * gB[ncurve2];
1486  for (int y=0;y<ncurve2;y++) {
1487  int igB=0;
1488  int igB_p=0;
1489  gB[y]=new TGraph();
1490  TMath::Sort(nBg,McBg[y],indexB[y],false);
1491  // cout<<"dopo Sort "<<y<<endl;
1492  for (int k=0;k<nBg;k++) {
1493  int ii=indexB[y][k];
1494  int ik=indexB[y][k-1];
1495  int yy=0;
1496  if (k>0){
1497  int ij=indexB[y][k-1];
1498  //if(ANNBg[y][ii]!=0&&ANNBg[y][ii]!=ANNBg[y][ij]) {
1499  if(McBg[y][ii]!=0) {
1500  yy=NBg[y]-igB;
1501  if(y==0 && yy==McFAth_n+1) {McthresFA=McBg[y][ii];
1502  }
1503  if (y==0 && yy<McFAth_n+1) { cout<<"dentro primo if"<<endl;
1504  //if(McBg[y][ii]==McBg[y][ik]){McFAth_n=McFAth_n-1; cout<<"dentro secondo if"<<endl;}
1505  if(McBg[y][ii]>McBg[y][ik]){McFAth_n=McFAth_n;cout<<"maggiore ii "<<" diff"<<(McBg[y][ii]-McBg[y][ik])<<endl;}
1506  if(McBg[y][ii]<McBg[y][ik]){McFAth_n=McFAth_n;cout<<"minore ii"<<endl;}
1507  if(McBg[y][ii]==McBg[y][ik]){McFAth_n=McFAth_n-1;cout<<"uguale"<<endl;}
1508  //else { McFAth_n=McFAth_n-1;cout<<"dentro secondo if"<<endl;}
1509 }
1510  if(y==0) cout<<"ii "<<ii<<" yy "<<yy<<" y "<<y<<" McFAth_n "<<McFAth_n<<"McthresFA "<<McthresFA<<" McBg[y][ii] "<<McBg[y][ii]<<" McBg[y][indexB[y][k-1] "<<McBg[y][indexB[y][k-1]]<<endl;
1511  //gB[y]->SetPoint(igB,ANNBg[y][ii],yy);
1512  if(McBg[y][ii]!=McBg[y][ij]) gB[y]->SetPoint(igB_p++,McBg[y][ii],yy);
1513  igB=igB+1;
1514  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1515  }
1516  }
1517  else {
1518  if(McBg[y][ii]!=0) {
1519  yy=NBg[y]-igB;
1520  gB[y]->SetPoint(0,McBg[y][ii],yy);
1521  igB=igB+1;
1522  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1523  }
1524  }
1525  }
1526  }
1527 
1528 McFDth_n=0;
1529  for(int ni=1;ni<nSig;ni++){
1530  cout<<"McFAth_n "<<McFAth_n<<" McthresFA "<<McthresFA<<" McSig[0][indexS[0][ni]] "<<McSig[0][indexS[0][ni]]<<" McFDth_n "<<McFDth_n<<" NSig[0]-(ni-1 )"<<NSig[0]-(ni-1)<<" NSig[0] "<<NSig[0]<<endl;
1531 // if (ANNSig[0][indexS[0][ni]]==thresFA || (ANNSig[0][indexS[0][ni-1]]<thresFA && ANNSig[0][indexS[0][ni]]>thresFA)) FDth_n=NSig[0]-(ni-1);
1532  if (McSig[0][indexS[0][ni]]<=McthresFA) McFDth_n=McFDth_n+1;
1533  }
1534 
1535 
1536  TCanvas* cS=new TCanvas("Efficiency_vs_Mchirp","Efficiency_vs_Mchirp",0,0,1200,700);
1537  cS->Divide(2,2);
1538  //cS->cd(1)->SetLogy();
1539  cS->cd(1);
1540  TMultiGraph* mg1=new TMultiGraph();
1541  mg1->SetTitle("cc: no_cut;Mchirp;#Events");
1542  for (int h=0;h<nRHO;h++){
1543  gS[h]->SetLineColor(4);
1544  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
1545  }
1546  mg1->Draw("al");
1547  cS->cd(2);
1548  // cS->cd(2)->SetLogy();
1549  TMultiGraph* mg2=new TMultiGraph();
1550  mg2->SetTitle("cc=0.55;Mchirp;#Events");
1551  for (int h=0;h<nRHO;h++){
1552  gS[nRHO+h]->SetLineColor(4);
1553  if(gS[nRHO+h]->GetN()!=0) mg2->Add(gS[nRHO+h]);
1554  }
1555  mg2->Draw("al");
1556 
1557  //cS->cd(3)->SetLogy();
1558  cS->cd(3);
1559  TMultiGraph* mg3=new TMultiGraph();
1560  mg3->SetTitle("cc=0.6;Mchirp;#Events");
1561  for (int h=0;h<nRHO;h++){
1562  gS[2*nRHO+h]->SetLineColor(4);
1563  if(gS[2*nRHO+h]->GetN()!=0) mg3->Add(gS[2*nRHO+h]);
1564  }
1565  mg3->Draw("al");
1566  //cS->cd(4)->SetLogy();
1567  cS->cd(4);
1568  TMultiGraph* mg4=new TMultiGraph();
1569  mg4->SetTitle("cc=0.65;Mchirp;#Events");
1570  for (int h=0;h<nRHO;h++){
1571  gS[3*nRHO+h]->SetLineColor(4);
1572  if(gS[3*nRHO+h]->GetN()!=0) mg4->Add(gS[3*nRHO+h]);
1573  }
1574  mg4->Draw("al");
1575 
1576  TCanvas* cB=new TCanvas("Number_vs_Mchirp","Number_vs_Mchirp",0,0,1200,700);
1577  cB->Divide(2,2);
1578  cB->cd(1)->SetLogy();
1579  TMultiGraph* mg1B=new TMultiGraph();
1580  mg1B->SetTitle("cc: no_cut;Mchirp;#Events");
1581  for (int h=0;h<nRHO;h++){
1582  gB[h]->SetLineColor(4);
1583  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1584  }
1585  mg1B->Draw("al");
1586  cB->cd(2)->SetLogy();
1587  TMultiGraph* mg2B=new TMultiGraph();
1588  mg2B->SetTitle("cc=0.55;Mchirp;#Events");
1589  for (int h=0;h<nRHO;h++){
1590  gB[nRHO+h]->SetLineColor(4);
1591  if(gB[nRHO+h]->GetN()!=0) mg2B->Add(gB[nRHO+h]);
1592  }
1593  mg2B->Draw("al");
1594  cB->cd(3)->SetLogy();
1595  TMultiGraph* mg3B=new TMultiGraph();
1596  mg3B->SetTitle("cc=0.6;Mchirp;#Events");
1597  for (int h=0;h<nRHO;h++){
1598  gB[2*nRHO+h]->SetLineColor(4);
1599  if(gB[2*nRHO+h]->GetN()!=0) mg3B->Add(gB[2*nRHO+h]);
1600  }
1601  mg3B->Draw("al");
1602  cB->cd(4)->SetLogy();
1603  TMultiGraph* mg4B=new TMultiGraph();
1604  mg4B->SetTitle("cc=0.6;Mchirp;#Events");
1605  for (int h=0;h<nRHO;h++){
1606  gB[3*nRHO+h]->SetLineColor(4);
1607  if(gB[3*nRHO+h]->GetN()!=0) mg4B->Add(gB[3*nRHO+h]);
1608  }
1609  mg4B->Draw("al");
1610 
1611 
1612  TString CnameS(name);
1613  TString CnameB(name);
1614  TString CnameSroot(name);
1615  TString CnameBroot(name);
1616  char CnameS2[1024];
1617  char CnameB2[1024];
1618  char CnameS2root[1024];
1619  char CnameB2root[1024];
1620  CnameS.ReplaceAll(".root",".png");
1621  CnameB.ReplaceAll(".root",".png");
1622  sprintf(CnameS2,"Mcthres/N_Mc_S_%s",CnameS.Data());
1623  sprintf(CnameB2,"Mcthres/N_Mc_B_%s",CnameB.Data());
1624  sprintf(CnameS2root,"Mcthres/N_Mc_S_%s",CnameSroot.Data());
1625  sprintf(CnameB2root,"Mcthres/N_Mc_B_%s",CnameBroot.Data());
1626  cS->SaveAs(CnameS2);
1627  cB->SaveAs(CnameB2);
1628  cS->Print(CnameS2root);
1629  cB->Print(CnameB2root);
1630 
1631 
1632 }
1633 
1635  TString name(ifile);
1636  name.ReplaceAll("outfile/","");
1637  name.ReplaceAll("average_file/","");
1638  TFile* fTEST =TFile::Open(ifile.Data());
1639  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1640  //double outbis;
1641  double av;
1642  double out;
1643  double cc;
1644  double rho;
1645  int nSi;
1646 // NNTree2->SetBranchAddress("ANNout",&out);
1647  NNTree2->SetBranchAddress("Average",&av);
1648  NNTree2->SetBranchAddress("cc",&cc);
1649  NNTree2->SetBranchAddress("rho",&rho);
1650  NNTree2->SetBranchAddress("#TestSig",&nSi);
1651  NNTree2->GetEntry(0);
1652  int const nSig=nSi;
1653  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1654  int const nBg=NNTree2->GetEntries()-nSig;
1655  cout<<"nBg: "<<nBg<<" Entries: "<<NNTree2->GetEntries()<<endl;
1656 
1657  TGraph * gS[3];
1658  TGraph * gB[3];
1659  gB[0]=new TGraph();
1660  gS[0]=new TGraph();
1661 // cout<<"nSig: "<<nSig<<endl;
1662  for (int n = 0; n <NNTree2->GetEntries(); n++){
1663  NNTree2->GetEntry(n);
1664  if(n<nSig) {
1665  gS[0]->SetPoint(n,cc,av);
1666  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1667  }
1668  else {
1669  gB[0]->SetPoint(n-nSig,cc,av);
1670  cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1671  }
1672  }
1673 
1674 
1675  /*for (int a=0;a<nBg;a++){
1676  if(aRHOB[a]>=RHOth){
1677  for (int b=0;b<nth;b++){
1678  if(aCCB[a]>=cc1th[b]){
1679  for(int c=0;c<nth+1;c++){
1680  if(aANNB[a]>=ANN1th[c]) Z[b*nth+c]=Z[b*nth+c]+1;
1681  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1682  }
1683  }
1684  }
1685  }
1686  }*/
1687  //gS[0]->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1688  //gB[0]->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1689  //gS[0]->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1690  //gB[0]->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1691  gS[0]->SetMarkerColor(2);
1692  gB[0]->SetMarkerColor(4);
1693  gS[0]->SetMarkerStyle(6);
1694  gB[0]->SetMarkerStyle(7);
1695 
1696  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1697  c->Divide(1,2);
1698  c->cd(1);
1699  TMultiGraph* mg1=new TMultiGraph();
1700  mg1->SetTitle("Av_cc");
1701  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1702  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1703  mg1->Draw("ap");
1704  mg1->GetHistogram()->GetXaxis()->SetTitle("cc");
1705  mg1->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1706 // mg1->Draw("ap");
1707  c->cd(2);
1708  TMultiGraph* mg2=new TMultiGraph();
1709  mg2->SetTitle("Av_cc");
1710  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1711  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1712  mg2->Draw("ap");
1713  mg2->GetHistogram()->GetXaxis()->SetTitle("cc");
1714  mg2->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1715 
1716  cout<<" name "<<name<<endl;
1717  TString Cname(name);
1718  TString Cnameroot(name);
1719  char Cname2[1024];
1720  char Cname2root[1024];
1721  Cname.ReplaceAll(".root",".png");
1722  sprintf(Cname2,"average_png/out_Plots_%s",Cname.Data());
1723  sprintf(Cname2root,"average_png/out_Plots_%s",Cnameroot.Data());
1724  c->SaveAs(Cname2);
1725  c->Print(Cname2root);
1726 /*
1727  TCanvas* c2=new TCanvas("Plots_Bkg_on_Sig","Plots_Bkg_on_Sig",0,0,1200,700);
1728  c2->Divide(2,2);
1729  c2->cd(1);
1730  gS[0]->Draw("ap");
1731  gB[0]->Draw("p,same");
1732 
1733  c2->cd(2);
1734  gS[1]->Draw("ap");
1735  gB[1]->Draw("p,same");
1736  c2->cd(3);
1737  gS[2]->Draw("ap");
1738  gB[2]->Draw("p,same");
1739  c2->cd(4);
1740  TText* text2=new TText(0.37,0.0,"no cuts on ANN");
1741  hglitch->SetStats(0);
1742  hglitch->GetXaxis()->SetTitle("cc");
1743  hglitch->GetYaxis()->SetTitle("ANNoutput");
1744  hglitch->GetZaxis()->SetTitle("count");
1745  hglitch->Draw("colz");
1746  text2->Draw();
1747  gPad->SetLogz();
1748 
1749  TString Cname_2(name);
1750  TString Cname_2root(name);
1751  char Cname2_2[1024];
1752  char Cname2_2root[1024];
1753  Cname_2.ReplaceAll(".root",".png");
1754  sprintf(Cname2_2,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2.Data());
1755  sprintf(Cname2_2root,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2root.Data());
1756  c2->SaveAs(Cname2_2);
1757  c2->Print(Cname2_2root);
1758 
1759 //CARTELLA CCi_RHO_ANN_Plots */
1760 }
1762  TString name(ifile);
1763  name.ReplaceAll("outfile/","");
1764  name.ReplaceAll("average_file/","");
1765  TFile* fTEST =TFile::Open(ifile.Data());
1766  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1767  //double outbis;
1768  double av;
1769  double out;
1770  double cc;
1771  double Mc;
1772  double Mc_inj;
1773  double rho;
1774  int nSi;
1775 // NNTree2->SetBranchAddress("ANNout",&out);
1776  NNTree2->SetBranchAddress("Mchirp",&Mc);
1777  NNTree2->SetBranchAddress("Average",&av);
1778  NNTree2->SetBranchAddress("cc",&cc);
1779  NNTree2->SetBranchAddress("rho",&rho);
1780  NNTree2->SetBranchAddress("Mchirp_injected",&Mc_inj);
1781  NNTree2->SetBranchAddress("#TestSig",&nSi);
1782  NNTree2->GetEntry(0);
1783  int const nSig=nSi;
1784  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1785  //exit(0);
1786  int const nBg=NNTree2->GetEntries()-nSig;
1787 
1788  TGraph * gS[3];
1789  TGraph * gB[3];
1790  gB[0]=new TGraph();
1791  gS[0]=new TGraph();
1792 
1793 
1794  TCanvas* ANN_Mc_c3D=new TCanvas("ANN_average_vs_Mc_reconstructed","ANN_average_vs_Mc_reconstructed",0,0,1200,700);
1795  ANN_Mc_c3D->Divide(1,2);
1796  TH2D* ANN_Mc_SIG3D=new TH2D("ANN_average_vs_Mc_recostructed_sig","ANN_average_vs_Mc_recostructed_sig",NMc_r,minMc_r,maxMc_r,NANN_av,minANN_av,maxANN_av);
1797  TH2D* ANN_Mc_BKG3D=new TH2D("ANN_average_vs_Mc_recostructed_bkg","ANN_average_vs_Mc_recostructed_bkg",NMc_r,minMc_r,maxMc_r,NANN_av,minANN_av,maxANN_av);
1798  // Mc_inj_g->SetPoint(0,rhoSig[y][ii],yy);
1799  ANN_Mc_BKG3D->SetDirectory(0);
1800  ANN_Mc_BKG3D->SetStats(0);
1801  ANN_Mc_SIG3D->SetDirectory(0);
1802  ANN_Mc_SIG3D->SetStats(0);
1803 
1804  TCanvas* ANN_cc_c3D=new TCanvas("ANN_average_vs_cc","ANN_average_vs_cc",0,0,1200,700);
1805  ANN_cc_c3D->Divide(1,2);
1806  TH2D* ANN_cc_SIG3D=new TH2D("ANN_average_vs_cc_SIG","ANN_average_vs_cc_SIG",Ncc3D, minCC, maxCC,NANN_av,minANN_av,maxANN_av);
1807  TH2D* ANN_cc_BKG3D=new TH2D("ANN_average_vs_cc_BKG","ANN_average_vs_cc_BKG",Ncc3D, minCC, maxCC,NANN_av,minANN_av,maxANN_av);
1808  ANN_cc_SIG3D->SetDirectory(0);
1809  ANN_cc_SIG3D->SetStats(0);
1810  ANN_cc_BKG3D->SetDirectory(0);
1811  ANN_cc_BKG3D->SetStats(0);
1812  double deltacc3D=0;
1813  deltacc3D=(maxCC-minCC)/(Ncc3D);
1814 
1815 
1816  TCanvas* Mc_inj_c=new TCanvas("ANN_vs_Mc_injected","ANN_vs_Mc_injected",0,0,1200,700);
1817  Mc_inj_c->Divide(1,2);
1818  TH2D* Mc_inj_gMc=new TH2D("Mc_injected_Mc_recostructed","Mc_injected_recostructed",NMc_inj,minMc_inj,maxMc_inj,NMc_r,minMc_r,maxMc_r);
1819  TH2D* Mc_inj_g=new TH2D("Mc_injected_comparison","Mc_injected_comparison",NMc_inj,minMc_inj,maxMc_inj,NANN_av,minANN_av,maxANN_av);
1820  // Mc_inj_g->SetPoint(0,rhoSig[y][ii],yy);
1821  Mc_inj_gMc->SetDirectory(0);
1822  Mc_inj_gMc->SetStats(0);
1823  Mc_inj_g->SetDirectory(0);
1824  Mc_inj_g->SetStats(0);
1825  double deltaMc_inj=0;
1826  deltaMc_inj=(maxMc_inj-minMc_inj)/(NMc_inj);
1827  double deltaANN_av_M=0;
1828  deltaANN_av_M=(maxANN_av-minANN_av)/(NANN_av);
1829  double deltaMc_r=0;
1830  deltaMc_r=(maxMc_r-minMc_r)/(NMc_r);
1831 
1832 
1833  TString txt_name0(name);
1834  txt_name0.ReplaceAll(".root",".txt");
1835  char txt_name[1024];
1836  sprintf(txt_name,"txt_files/%s",txt_name0.Data());
1837  ofstream file_txt_out(txt_name);
1838 
1839 
1840 // cout<<"nSig: "<<nSig<<endl;
1841  int aa1=0;
1842  int bb1=0;
1843  for (int n = 0; n <NNTree2->GetEntries(); n++){
1844  NNTree2->GetEntry(n);
1845  char line[2048];
1846  if(n<nSig&&n!=nSig) {
1847  Mc_inj_gMc->Fill(Mc_inj,Mc);
1848  Mc_inj_g->Fill(Mc_inj,av);
1849  gS[0]->SetPoint(n,Mc,av);
1850  cout<<" n "<<n<<" Mc "<<Mc<<" av "<<av<<" M_inj "<<Mc_inj<<endl;
1851  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1852  aa1=aa1+1;
1853  ANN_Mc_SIG3D->Fill(Mc,av);
1854  ANN_cc_SIG3D->Fill(cc,av);
1855  sprintf(line,"SIG:Average_%1.5f; Mc_rec_%1.5f; Mc_inj_%1.5f; event %i; count_%i; nSig_%i\n",av,Mc,Mc_inj,n,aa1,nSig);
1856  file_txt_out<<line;
1857  cout<<" n "<<n<<" nSig "<<nSig<<endl;
1858  }
1859  else {
1860  bb1=bb1+1;
1861  gB[0]->SetPoint(n-nSig,Mc,av);
1862  ANN_Mc_BKG3D->Fill(Mc,av);
1863  ANN_cc_BKG3D->Fill(cc,av);
1864  // cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1865  sprintf(line,"BKG:Average %1.5f; Mc_rec %1.5f; Mc_inj_%1.5f; event %i; count_%i\n",av,Mc,Mc_inj,n,bb1);
1866  file_txt_out<<line;
1867 
1868  }
1869  }
1870  //exit(0);
1871 
1872 
1873  gS[0]->SetMarkerColor(2);
1874  gB[0]->SetMarkerColor(4);
1875  gS[0]->SetMarkerStyle(6);
1876  gB[0]->SetMarkerStyle(7);
1877 
1878  ANN_Mc_c3D->cd(1);
1879  ANN_Mc_SIG3D->GetXaxis()->SetTitle("SIG:Mchirp_reconstructed");
1880  ANN_Mc_SIG3D->GetYaxis()->SetTitle("SIG:ANN_average");
1881  ANN_Mc_SIG3D->GetZaxis()->SetTitle("count");
1882  ANN_Mc_SIG3D->Draw("colz");
1883  ANN_Mc_c3D->cd(2);
1884  ANN_Mc_BKG3D->GetXaxis()->SetTitle("BKG:Mchirp_reconstructed");
1885  ANN_Mc_BKG3D->GetYaxis()->SetTitle("BKG:ANN_average");
1886  ANN_Mc_BKG3D->GetZaxis()->SetTitle("count");
1887  ANN_Mc_BKG3D->Draw("colz");
1888 
1889 
1890  TString ANN_Mc_name3D(name);
1891  TString ANN_Mc_rootname3D(name);
1892  char ANN_Mc_cname23D[1024];
1893  char ANN_Mc_crootname23D[1024];
1894  ANN_Mc_name3D.ReplaceAll(".root",".png");
1895  sprintf(ANN_Mc_cname23D,"average_png/nSig%i_nBg%i_3DMc_ANNav_Plots_%s",nSig,nBg,ANN_Mc_name3D.Data());
1896  sprintf(ANN_Mc_crootname23D,"average_png/nSig%i_nBg%i_3DMc_ANNav_Plots_%s",nSig,nBg,ANN_Mc_rootname3D.Data());
1897  ANN_Mc_c3D->SaveAs(ANN_Mc_cname23D);
1898  ANN_Mc_c3D->Print(ANN_Mc_crootname23D);
1899 
1900 
1901  ANN_cc_c3D->cd(1);
1902  ANN_cc_SIG3D->GetXaxis()->SetTitle("SIG:cc");
1903  ANN_cc_SIG3D->GetYaxis()->SetTitle("SIG:ANN_average");
1904  ANN_cc_SIG3D->GetZaxis()->SetTitle("count");
1905  ANN_cc_SIG3D->Draw("colz");
1906  ANN_cc_c3D->cd(2);
1907  ANN_cc_BKG3D->GetXaxis()->SetTitle("BKG:cc");
1908  ANN_cc_BKG3D->GetYaxis()->SetTitle("BKG:ANN_average");
1909  ANN_cc_BKG3D->GetZaxis()->SetTitle("count");
1910  ANN_cc_BKG3D->Draw("colz");
1911 
1912 
1913  TString ANN_cc_cname3D(name);
1914  TString ANN_cc_crootname3D(name);
1915  char ANN_cc_cname23D[1024];
1916  char ANN_cc_crootname23D[1024];
1917  ANN_cc_cname3D.ReplaceAll(".root",".png");
1918  sprintf(ANN_cc_cname23D,"average_png/nSig%i_nBg%i_3DANNav_cc_Plots_%s",nSig,nBg,ANN_cc_cname3D.Data());
1919  sprintf(ANN_cc_crootname23D,"average_png/nSig%i_nBg%i_3DANNav_cc_Plots_%s",nSig,nBg,ANN_cc_crootname3D.Data());
1920  ANN_cc_c3D->SaveAs(ANN_cc_cname23D);
1921  ANN_cc_c3D->Print(ANN_cc_crootname23D);
1922 
1923  Mc_inj_c->cd(1);
1924  Mc_inj_g->GetXaxis()->SetTitle("Mchirp_injected");
1925  Mc_inj_g->GetYaxis()->SetTitle("ANN_average");
1926  Mc_inj_g->GetZaxis()->SetTitle("count");
1927  Mc_inj_g->Draw("colz");
1928  Mc_inj_c->cd(2);
1929  Mc_inj_gMc->GetXaxis()->SetTitle("Mchirp_injected");
1930  Mc_inj_gMc->GetYaxis()->SetTitle("Mchirp_reconstructed");
1931  Mc_inj_gMc->GetZaxis()->SetTitle("count");
1932  Mc_inj_gMc->Draw("colz");
1933 
1934 
1935  TString Mc_inj_cname(name);
1936  TString Mc_inj_crootname(name);
1937  char Mc_inj_cname2[1024];
1938  char Mc_inj_crootname2[1024];
1939  Mc_inj_cname.ReplaceAll(".root",".png");
1940  sprintf(Mc_inj_cname2,"average_png/nSig%i_nBg%i_Mc_inj_Plots_%s",nSig,nBg,Mc_inj_cname.Data());
1941  sprintf(Mc_inj_crootname2,"average_png/nSig%i_nBg%i_Mc_inj_Plots_%s",nSig,nBg,Mc_inj_crootname.Data());
1942  Mc_inj_c->SaveAs(Mc_inj_cname2);
1943  Mc_inj_c->Print(Mc_inj_crootname2);
1944 
1945 
1946  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1947  c->Divide(1,2);
1948  c->cd(1);
1949  TMultiGraph* mg1=new TMultiGraph();
1950  mg1->SetTitle("Av_Mc");
1951  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1952  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1953  mg1->Draw("ap");
1954  mg1->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1955  mg1->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1956  c->cd(2);
1957  TMultiGraph* mg2=new TMultiGraph();
1958  mg2->SetTitle("Av_Mc");
1959  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1960  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1961  mg2->Draw("ap");
1962  mg2->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1963  mg2->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1964 
1965  cout<<" name "<<name<<endl;
1966  TString Cname(name);
1967  TString Cnameroot(name);
1968  char Cname2[1024];
1969  char Cname2root[1024];
1970  Cname.ReplaceAll(".root",".png");
1971  sprintf(Cname2,"average_png/nSig%i_nBg%i_Mc_Plots_%s",nSig,nBg,Cname.Data());
1972  sprintf(Cname2root,"average_png/nSig%i_nBg%i_Mc_Plots_%s",nSig,nBg,Cnameroot.Data());
1973  cout<<"Cname2 "<<Cname2<<endl;
1974  c->SaveAs(Cname2);
1975  c->Print(Cname2root);
1976  cout<<" gS[0]->GetN() "<<gS[0]->GetN()<<endl;
1977  //cout<<"entries "<<mg1->GetHistogram()->GetEntries()<<endl;
1978  cout<<" nSig "<<nSig<<" nBg "<<nBg<<" aa1 "<<aa1<<endl;
1979 }
1980 
1981 
1983 
1984  TString name(ifile);
1985  name.ReplaceAll("outfile/","");
1986  name.ReplaceAll("average_file/","");
1987  TFile* fTEST =TFile::Open(ifile.Data());
1988  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1989  double av;
1990  double out;
1991  double cc;
1992  double Mc;
1993  double Mc_inj;
1994  double rho;
1995  int nSi;
1996  NNTree2->SetBranchAddress("Mchirp",&Mc);
1997  NNTree2->SetBranchAddress("Average",&av);
1998  NNTree2->SetBranchAddress("cc",&cc);
1999  NNTree2->SetBranchAddress("rho",&rho);
2000  NNTree2->SetBranchAddress("Mchirp_injected",&Mc_inj);
2001  NNTree2->SetBranchAddress("#TestSig",&nSi);
2002  NNTree2->GetEntry(0);
2003  int const nSig=nSi;
2004  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
2005  int const nBg=NNTree2->GetEntries()-nSig;
2006  int const nTot=NNTree2->GetEntries();
2007  int const n_points=N_ANNth*N_RHOth;
2008  int nBgSur[3][n_points];
2009  int nSigSur[3][n_points];
2010  double zax[3][n_points];
2011 
2012  for (int i=0; i<3; i++) for (int u=0; u<n_points; u++) {nBgSur[i][u]=0; nSigSur[i][u]=0;zax[i][u]=0.;}
2013 
2014  double pANNth[N_ANNth];
2015  double pRHOth[N_RHOth];
2016 
2017  double pCCth[3];
2018 
2019  pCCth[0]=0.;
2020  pCCth[1]=0.;
2021  pCCth[2]=0.;
2022 
2023  pCCth[0]=0.5;
2024  pCCth[1]=0.6;
2025  pCCth[2]=0.7;
2026 
2027  double deltaANNth=0.;
2028  double deltaRHOth=0.;
2029 
2030  deltaANNth=(double)(ANNth_max-ANNth_min)/N_ANNth;
2031  deltaRHOth=(double)(RHOth_max-RHOth_min)/N_RHOth;
2032 
2033 
2034  TCanvas* SNR_c=new TCanvas("SIG-BKG_reduction","SIG-BKG_reduction",0,0,1200,700);
2035  SNR_c->Divide(1,3);
2036 
2037  TH2D* SNR3Dcc0=new TH2D("cc=0.5","cc=0.5",N_ANNth,ANNth_min,ANNth_max,N_RHOth,RHOth_min,RHOth_max);
2038  TH2D* SNR3Dcc1=new TH2D("cc=0.6","cc=0.6",N_ANNth,ANNth_min,ANNth_max,N_RHOth,RHOth_min,RHOth_max);
2039  TH2D* SNR3Dcc2=new TH2D("cc=0.7","cc=0.7",N_ANNth,ANNth_min,ANNth_max,N_RHOth,RHOth_min,RHOth_max);
2040  SNR3Dcc0->SetDirectory(0);
2041  SNR3Dcc0->SetStats(0);
2042  SNR3Dcc1->SetDirectory(0);
2043  SNR3Dcc1->SetStats(0);
2044  SNR3Dcc2->SetDirectory(0);
2045  SNR3Dcc2->SetStats(0);
2046 
2047  for (int u=0; u<N_ANNth; u++) { pANNth[u]=0.; pANNth[u]=ANNth_min+u*deltaANNth; cout<<" pANNth[u] "<<pANNth[u]<<" u "<<u<<endl;}
2048  for (int u=0; u<N_RHOth; u++) { pRHOth[u]=0.; pRHOth[u]=RHOth_min+u*deltaRHOth; cout<<" pRHOth[u] "<<pRHOth[u]<<" u "<<u<<endl;}
2049 
2050 cout<<"fino def cose"<<endl;
2051 /*
2052  for (int u=0; u<nTot; u++){
2053  NNTree2->GetEntry(u);
2054  cout<<" cc "<<cc<<" av "<<av<<" rho "<< rho<<endl;
2055  for (int y=2; y>-1; y--){
2056  // cout<<" cc "<<cc<<" pCCth "<<pCCth[y]<<" y "<<y<<endl;
2057  if(cc>pCCth[y]) {
2058  for (int i=N_ANNth-1; i>-1; i--){
2059  // cout<<" av "<<av<<" pANNth[i] "<<pANNth[i]<<" i "<<i<<endl;
2060  if(av>pANNth[i]){
2061  for (int j=N_RHOth-1; j>-1; j++){
2062  //cout<<" rho "<<rho<<" pRHOth[j] "<<pRHOth[j]<<" j "<<j<<" nSig "<<nSig<<" u "<<u<<endl;
2063  if(rho>pRHOth[j]){
2064  for(int yy=y; yy>-1;yy--) for (int ii=i; ii>-1; ii--) for (int jj=j; jj>-1;jj--){
2065  if(u<nSig) nSigSur[yy][jj+N_ANNth*ii]=nSigSur[yy][jj+N_ANNth*ii]+1;
2066  else nBgSur[yy][jj+N_ANNth*ii]=nBgSur[yy][jj+N_ANNth*ii]+1;
2067  // cout<<" yy "<<yy<<" ii "<<ii<<" jj "<<jj<<" nBgSur[yy][jj+N_ANNth*ii] "<<nBgSur[yy][jj+N_ANNth*ii]<<" nSigSur[yy][jj+N_ANNth*ii] "<<nSigSur[yy][jj+N_ANNth*ii]<<endl;
2068  }
2069  break;
2070  }
2071  else continue;
2072  }
2073  break;
2074  }
2075  else continue;
2076  }
2077  break;
2078  }
2079  else continue;
2080  }
2081  }
2082 //exit(0);
2083 cout<<"dopo ciclo"<<endl;
2084 */
2085 for (int u=0; u<nTot; u++){
2086  NNTree2->GetEntry(u);
2087  for (int y=0; y<3; y++){
2088  if(cc>pCCth[y]){
2089  for (int i=0; i<N_ANNth; i++){
2090  if(av>pANNth[i]) {
2091  for (int j=0; j<N_RHOth; j++){
2092  if(rho>pRHOth[j]){
2093  if(u<nSig) nSigSur[y][j+N_ANNth*i]=nSigSur[y][j+N_ANNth*i]+1;
2094  else nBgSur[y][j+N_ANNth*i]=nBgSur[y][j+N_ANNth*i]+1;
2095  }
2096  else continue;
2097  }
2098  }
2099  else continue;
2100  }
2101  }
2102  else continue;
2103  }
2104  }
2105 
2106 
2107 //exit(0);
2108 int nBgSur0=0;
2109 nBgSur0=nBgSur[0][0];
2110 int nSigSur0=0;
2111 nSigSur0=nSigSur[0][0];
2112 if(nBgSur0==0){nBgSur0=nBg;}
2113 if(nSigSur0==0){nSigSur0=nSig;}
2114 int count_zax=0;
2115 cout<<"dopo ciclo"<<" nSigSur0 "<<nSigSur0<<" nBgSur0 "<<nBgSur0<<endl;
2116 for (int u=0; u<3; u++) for (int j=0; j<N_RHOth; j++) for (int i=0; i<N_ANNth; i++) {
2117  //cout<<" u "<<u<<" j "<<j<<" i "<<i<<" nSigSur[u][i+j*N_ANNth] "<<nSigSur[u][i+j*N_ANNth]<<endl;
2118  //if(nSigSur[u][i+j*N_ANNth]!=0){zax[u][i+j*N_ANNth]=(nBgSur[u][i+j*N_ANNth]/nBgSur0)/(nSigSur[u][i+j*N_ANNth]/nSigSur0);};
2119  if(nSigSur[u][i+j*N_ANNth]==0) {
2120  if (nSigSur[u][i+j*N_ANNth]==0 && nBgSur[u][i+j*N_ANNth]==0) zax[u][i+j*N_ANNth]=-1;
2121  else zax[u][i+j*N_ANNth]=-2;
2122  }
2123  else {
2124  double num=0.;
2125  double den=0.;
2126  num=(double)nBgSur[u][i+j*N_ANNth]/nBgSur0;
2127  den=(double)nSigSur0/nSigSur[u][i+j*N_ANNth];
2128  zax[u][i+j*N_ANNth]=(double)num/den; count_zax=count_zax+1;
2129  cout<<(double)(nBgSur[u][i+j*N_ANNth]/nBgSur0)*(nSigSur0/nSigSur[u][i+j*N_ANNth])<<endl;
2130  }
2131 // cout<<" nBgSur[yy][jj+N_ANNth*ii] "<<nBgSur[u][j+N_ANNth*i]<<" nSigSur[y][j+N_ANNth*i] "<<nSigSur[u][j+N_ANNth*i]<<" zax[u][i+j*N_ANNth] "<<zax[u][i+j*N_ANNth]<<endl;
2132  //else zax[u][i+j*N_ANNth]=(nBgSur[u][i+j*N_ANNth]/nBgSur0)/(nSigSur[u][i+j*N_ANNth]/nSigSur0);
2133  if(u==2){
2134  /*cout<<" zax[0][i+j*N_ANNth] "<<zax[0][i+j*N_ANNth]<<endl;
2135  cout<<" zax[1][i+j*N_ANNth] "<<zax[1][i+j*N_ANNth]<<endl;
2136  cout<<" zax[2][i+j*N_ANNth] "<<zax[2][i+j*N_ANNth]<<endl;*/
2137  SNR3Dcc0->Fill(pANNth[i]+ deltaANNth/2.,pRHOth[j]+ deltaRHOth/2.,zax[0][i+j*N_ANNth]);
2138  SNR3Dcc1->Fill(pANNth[i]+ deltaANNth/2.,pRHOth[j]+ deltaRHOth/2.,zax[1][i+j*N_ANNth]);
2139  SNR3Dcc2->Fill(pANNth[i]+ deltaANNth/2.,pRHOth[j]+ deltaRHOth/2.,zax[2][i+j*N_ANNth]);
2140  }
2141 }
2142 for(int yy=0; yy<3;yy++) {
2143  cout<<" pCCth "<<pCCth[yy]<<endl;
2144  for (int ii=N_ANNth-1; ii>-1; ii--) {
2145  cout<<" pANNth[i] "<<pANNth[ii]<<endl;
2146  for (int jj=N_RHOth-1; jj>-1;jj--){
2147  cout<<" pRHOth[jj] "<<pRHOth[jj]<<endl;
2148  cout<<" nBgSur[yy][ii+N_ANNth*jj] "<<nBgSur[yy][ii+N_ANNth*jj]<<endl;
2149  cout<<" nSigSur[yy][ii+N_ANNth*jj] "<<nSigSur[yy][ii+N_ANNth*jj]<<endl;
2150  cout<<" zax[0][i+j*N_ANNth]"<<zax[yy][ii+jj*N_ANNth]<<endl;
2151  cout<<" (double)(nBgSur[u][i+j*N_ANNth]/nBgSur0)"<<(double)nBgSur[yy][ii+jj*N_ANNth]/nBgSur0<<endl;
2152  //cout<<" yy "<<yy<<" ii "<<ii<<" jj "<<jj<<" nBgSur[yy][jj+N_ANNth*ii] "<<nBgSur[yy][jj+N_ANNth*ii]<<" nSigSur[yy][jj+N_ANNth*ii] "<<nSigSur[yy][jj+N_ANNth*ii]<<endl;
2153  }
2154  }
2155  }
2156 cout<<"coutn_zax "<<count_zax<<endl;
2157  SNR_c->cd(1);
2158  SNR3Dcc0->GetXaxis()->SetTitle("ANN_average_thresholds");
2159  SNR3Dcc0->GetYaxis()->SetTitle("RHO_thresholds");
2160  SNR3Dcc0->GetZaxis()->SetTitle("normBKG/normSIG");
2161  SNR3Dcc0->Draw("colz");
2162 
2163  SNR_c->cd(2);
2164  SNR3Dcc1->GetXaxis()->SetTitle("ANN_average_thresholds");
2165  SNR3Dcc1->GetYaxis()->SetTitle("RHO_thresholds");
2166  SNR3Dcc1->GetZaxis()->SetTitle("normBKG/normSIG");
2167  SNR3Dcc1->Draw("colz");
2168 
2169  SNR_c->cd(3);
2170  SNR3Dcc2->GetXaxis()->SetTitle("ANN_average_thresholds");
2171  SNR3Dcc2->GetYaxis()->SetTitle("RHO_thresholds");
2172  SNR3Dcc2->GetZaxis()->SetTitle("normBKG/normSIG");
2173  SNR3Dcc2->Draw("colz");
2174 
2175  TString SNR_n(name);
2176  TString SNR_nroot(name);
2177  char SNR_c_n[1024];
2178  char SNR_c_nroot[1024];
2179  SNR_n.ReplaceAll(".root",".png");
2180  sprintf(SNR_c_n,"SNR_plots/nSig%i_nBg%i_invSNR_Plots_%s",nSig,nBg,SNR_n.Data());
2181  sprintf(SNR_c_nroot,"SNR_plots/nSig%i_nBg%i_invSNR_Plots_%s",nSig,nBg,SNR_nroot.Data());
2182  SNR_c->SaveAs(SNR_c_n);
2183  SNR_c->Print(SNR_c_nroot);
2184 
2185 
2186 }
2187 
2189 
2190  TString name(ifile);
2191  name.ReplaceAll("outfile/","");
2192  name.ReplaceAll("average_file/","");
2193  TFile* fTEST =TFile::Open(ifile.Data());
2194  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
2195  double av;
2196  double out;
2197  double cc;
2198  double Mc;
2199  double Mc_inj;
2200  double rho;
2201  int nSi;
2202  int CoG;
2203  NNTree2->SetBranchAddress("Center_of_Gravity",&CoG);
2204  NNTree2->SetBranchAddress("Mchirp",&Mc);
2205  NNTree2->SetBranchAddress("Average",&av);
2206  NNTree2->SetBranchAddress("cc",&cc);
2207  NNTree2->SetBranchAddress("rho",&rho);
2208  NNTree2->SetBranchAddress("Mchirp_injected",&Mc_inj);
2209  NNTree2->SetBranchAddress("#TestSig",&nSi);
2210  NNTree2->GetEntry(0);
2211  int const nSig=nSi;
2212  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
2213  int const nTot=NNTree2->GetEntries();
2214  int const nBg=nTot-nSig;
2215 
2216  TCanvas* CoG_c=new TCanvas("SIG-BKG_reduction","SIG-BKG_reduction",0,0,1200,700);
2217 
2218  TH1D* imp=new TH1D("Center_of_Gravity_VS_ANN","Center_of_Gravity_VS_ANN",N_ANNth,ANNth_min,ANNth_max);
2219  TH1D* CoG1Sig=new TH1D("Center_of_Gravity_VS_ANN","Center_of_Gravity_VS_ANN",N_ANNth,ANNth_min,ANNth_max);
2220  TH1D* CoG1Bg=new TH1D("Center_of_Gravity_VS_ANN","Center_of_Gravity_VS_ANN",N_ANNth,ANNth_min,ANNth_max);
2221  TH1D* CoG0Sig=new TH1D("Center_of_Gravity_VS_ANN","Center_of_Gravity_VS_ANN",N_ANNth,ANNth_min,ANNth_max);
2222  TH1D* CoG0Bg=new TH1D("Center_of_Gravity_VS_ANN","Center_of_Gravity_VS_ANN",N_ANNth,ANNth_min,ANNth_max);
2223  TH1D* ibkgCC=new TH1D("Number_of_events_vs_CC","Number_of_events_vs_CC",50,0.,1.);
2224  TH1D* isigCC=new TH1D("Number_of_events_vs_CC","Number_of_events_vs_CC",50,0.,1.);
2225  TH1D* ibkgRHO=new TH1D("Number_of_events_vs_RHO","Number_of_events_vs_RHO",50,0.,50.);
2226  TH1D* isigRHO=new TH1D("Number_of_events_vs_RHO","Number_of_events_vs_RHO",50,0.,50.);
2227  TH1D* ibkgANN=new TH1D("Number_of_events_vs_ANN","Number_of_events_vs_ANN",50,-0.2,1.2);
2228  TH1D* isigANN=new TH1D("Number_of_events_vs_ANN","Number_of_events_vs_ANN",50,-0.2,1.2);
2229 
2230  CoG1Sig->SetDirectory(0);
2231  CoG1Sig->SetStats(0);
2232  CoG0Sig->SetDirectory(0);
2233  CoG0Sig->SetStats(0);
2234  CoG1Bg->SetDirectory(0);
2235  CoG1Bg->SetStats(0);
2236  CoG0Bg->SetDirectory(0);
2237  CoG0Bg->SetStats(0);
2238  ibkgCC->SetDirectory(0);
2239  ibkgCC->SetStats(0);
2240  isigRHO->SetDirectory(0);
2241  isigRHO->SetStats(0);
2242  ibkgANN->SetDirectory(0);
2243  ibkgANN->SetStats(0);
2244  isigCC->SetDirectory(0);
2245  isigCC->SetStats(0);
2246  ibkgRHO->SetDirectory(0);
2247  ibkgRHO->SetStats(0);
2248  isigANN->SetDirectory(0);
2249  isigANN->SetStats(0);
2250 
2251  for (int n=0; n<nTot; n++){
2252  NNTree2->GetEntry(n);
2253  if (n<nSig) {
2254  if(CoG==0) {CoG0Sig->Fill(av);}
2255  else {CoG1Sig->Fill(av);}
2256  isigCC->Fill(cc);
2257  isigRHO->Fill(rho);
2258  isigANN->Fill(av);
2259  }
2260  else {
2261  if(CoG==0) {CoG0Bg->Fill(av);}
2262  else {CoG1Bg->Fill(av);}
2263  ibkgCC->Fill(cc);
2264  ibkgRHO->Fill(rho);
2265  ibkgANN->Fill(av);
2266 
2267  }
2268  cout<<" CoG "<<CoG<<endl;
2269  }
2270 
2271  imp->SetDirectory(0);
2272  imp->SetStats(0);
2273  int max_n=0;
2274  // if(nBg>nSig) max_n=nBg;
2275  // else max_n=nSig;
2276 
2277  int max[4];
2278  for(int i=0; i<4; i++) max[i]=0;
2279 
2280  max[0]=CoG1Sig->GetMaximum();
2281  max[1]=CoG0Sig->GetMaximum();
2282  max[2]=CoG1Bg->GetMaximum();
2283  max[3]=CoG0Bg->GetMaximum();
2284 
2285 
2286 max_n=max[0];
2287  for(int i=0; i<4; i++) if(max_n<max[i]) max_n=max[i] ;
2288 
2289  imp->Fill(ANNth_min,max_n);
2290  imp->SetLineColor(10);
2291  imp->SetBins(N_ANNth,ANNth_min,ANNth_max);
2292  imp->GetXaxis()->SetTitle("ANN");
2293  imp->GetYaxis()->SetTitle("Count");
2294  imp->Draw();
2295 
2296  isigCC->SetFillStyle(3018);
2297  isigRHO->SetFillStyle(3018);
2298  isigANN->SetFillStyle(3018);
2299  ibkgCC->SetFillStyle(3004);
2300  ibkgRHO->SetFillStyle(3004);
2301  ibkgANN->SetFillStyle(3004);
2302  CoG1Sig->SetFillStyle(3018);
2303  CoG0Sig->SetFillStyle(3018);
2304  CoG0Bg->SetFillStyle(3004);
2305  CoG1Bg->SetFillStyle(3004);
2306  ibkgCC->SetLineColor(4);//blu
2307  ibkgANN->SetLineColor(4);//blu
2308  ibkgRHO->SetLineColor(4);//blu
2309  isigCC->SetLineColor(2);//rosso
2310  isigANN->SetLineColor(2);//rosso
2311  isigRHO->SetLineColor(2);//rosso
2312  ibkgCC->SetFillColor(4);//blu
2313  ibkgANN->SetFillColor(4);//blu
2314  ibkgRHO->SetFillColor(4);//blu
2315  isigCC->SetFillColor(2);//rosso
2316  isigANN->SetFillColor(2);//rosso
2317  isigRHO->SetFillColor(2);//rosso
2318  CoG1Sig->SetFillColor(2);//rosso
2319  CoG0Sig->SetFillColor(6);//fucsia
2320  CoG0Bg->SetFillColor(4);//blu
2321  CoG1Bg->SetFillColor(9);//violaceo
2322  CoG1Sig->SetLineColor(2);
2323  CoG0Sig->SetLineColor(6);
2324  CoG0Bg->SetLineColor(4);
2325  CoG1Bg->SetLineColor(9);
2326  // CoG1Sig->SetBins(N_ANNth,ANNth_min,ANNth_max);
2327  // CoG1Sig->GetXaxis()->SetTitle("ANN");
2328  // CoG1Sig->GetYaxis()->SetTitle("Count");
2329 CoG_c->cd(1);
2330  CoG1Sig->Draw("same");
2331  CoG0Sig->Draw("same");
2332  CoG0Bg->Draw("same");
2333  CoG1Bg->Draw("same");
2334 
2335 
2336 
2337  TString CoG_n(name);
2338  TString CoG_nroot(name);
2339  char CoG_c_n[1024];
2340  char CoG_c_nroot[1024];
2341  CoG_n.ReplaceAll(".root",".png");
2342  sprintf(CoG_c_n,"CoG_plots/nSig%i_nBg%i_CoG_Plots_%s",nSig,nBg,CoG_n.Data());
2343  sprintf(CoG_c_nroot,"CoG_plots/nSig%i_nBg%i_CoG_Plots_%s",nSig,nBg,CoG_nroot.Data());
2344  CoG_c->SaveAs(CoG_c_n);
2345  CoG_c->Print(CoG_c_nroot);
2346 
2347 TCanvas* Istogram=new TCanvas("SIG-BKG_reduction","SIG-BKG_reduction",0,0,1200,400);
2348 
2349 Istogram->Divide(3,1);
2350 Istogram->cd(1);
2351  if (ibkgCC->GetMaximum()>isigCC->GetMaximum()) {ibkgCC->GetXaxis()->SetTitle("Network Correlation Coefficient"); ibkgCC->GetYaxis()->SetTitle("Count"); ibkgCC->Draw(); isigCC->Draw("same");}
2352  else {isigCC->GetXaxis()->SetTitle("Network Correlation Coefficient"); isigCC->GetXaxis()->SetTitle("Count"); isigCC->Draw();ibkgCC->Draw("same");}
2353 Istogram->cd(2);
2354  if (ibkgRHO->GetMaximum()>isigRHO->GetMaximum()) {ibkgRHO->GetXaxis()->SetTitle("Effective Correlated SNR"); ibkgRHO->GetYaxis()->SetTitle("Count"); ibkgCC->Draw(); ibkgRHO->Draw(); isigRHO->Draw("same");}
2355  else {isigRHO->GetXaxis()->SetTitle("Effective Correlated SNR"); isigRHO->GetXaxis()->SetTitle("Count"); isigRHO->Draw();ibkgRHO->Draw("same");}
2356 Istogram->cd(3);
2357  if (ibkgANN->GetMaximum()>isigANN->GetMaximum()) {ibkgANN->GetXaxis()->SetTitle("ANN parameter"); ibkgANN->GetYaxis()->SetTitle("Count"); ibkgANN->Draw(); isigANN->Draw("same");}
2358  else {isigANN->GetXaxis()->SetTitle("ANN parameter"); isigANN->GetYaxis()->SetTitle("Count"); isigANN->Draw();ibkgANN->Draw("same");}
2359 
2360  TString isto_n(name);
2361  TString isto_nroot(name);
2362  char isto_c_n[1024];
2363  char isto_c_nroot[1024];
2364  isto_n.ReplaceAll(".root",".png");
2365  sprintf(isto_c_n,"Istograms/nSig%i_nBg%i_istograms_%s",nSig,nBg,isto_n.Data());
2366  sprintf(isto_c_nroot,"Istograms/nSig%i_nBg%i_istograms_%s",nSig,nBg,isto_nroot.Data());
2367  Istogram->SaveAs(isto_c_n);
2368  Istogram->Print(isto_c_nroot);
2369 
2370 }
2371 
2373 TString name(ifile);
2374  name.ReplaceAll("outfile/","");
2375  name.ReplaceAll("average_file/","");
2376  TFile* fTEST =TFile::Open(ifile.Data());
2377  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
2378  double av;
2379  double out;
2380  double cc;
2381  double Mc;
2382  double Mc_inj;
2383  double rho;
2384  int nSi;
2385  int CoG;
2386  double Dt;
2387 // float Dt;
2388 
2389  NNTree2->SetBranchAddress("Center_of_Gravity",&CoG);
2390  NNTree2->SetBranchAddress("duration",&Dt);
2391  NNTree2->SetBranchAddress("Mchirp",&Mc);
2392  NNTree2->SetBranchAddress("Average",&av);
2393  NNTree2->SetBranchAddress("cc",&cc);
2394  NNTree2->SetBranchAddress("rho",&rho);
2395  NNTree2->SetBranchAddress("Mchirp_injected",&Mc_inj);
2396  NNTree2->SetBranchAddress("#TestSig",&nSi);
2397  NNTree2->GetEntry(0);
2398  int const nSig=nSi;
2399  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
2400  int const nTot=NNTree2->GetEntries();
2401  int const nBg=nTot-nSig;
2402 
2403  TCanvas* Dt_c=new TCanvas("Duration","Duration",0,0,1200,700);
2404  double maxDt=0.;
2405  double minDt=0.;
2406  maxDt=Dt;
2407  minDt=Dt;
2408  cout<<"maxDt "<<maxDt<<" minDt "<<minDt<<endl;
2409 
2410  for( int i=0; i<nTot; i++){
2411  NNTree2->GetEntry(i);
2412  if(Dt>maxDt) maxDt=Dt;
2413  if(Dt<minDt) minDt=Dt;
2414  }
2415 
2416  /*TH1D* imp=new TH1D("Duration","Duration",100,minDt,maxDt);
2417  TH1D* Dt_hB=new TH1D("Duration","Duration",100,minDt,maxDt);
2418  TH1D* Dt_hS=new TH1D("Duration","Duration",100,minDt,maxDt);*/
2419  TH1D* imp=new TH1D("Duration","Duration",100,0.,2.);
2420  TH1D* Dt_hB=new TH1D("Duration","Duration",100,0.,2.);
2421  TH1D* Dt_hS=new TH1D("Duration","Duration",100,0.,2.);
2422 
2423  imp->SetDirectory(0);
2424  imp->SetStats(0);
2425  Dt_hS->SetDirectory(0);
2426  Dt_hS->SetStats(0);
2427  Dt_hB->SetDirectory(0);
2428  Dt_hB->SetStats(0);
2429 
2430  for (int n=0; n<nTot; n++){
2431  NNTree2->GetEntry(n);
2432  if (n<nSig) Dt_hS->Fill(Dt);
2433  else Dt_hB->Fill(Dt);
2434  }
2435 
2436  Dt_hS->SetFillStyle(3018);
2437  Dt_hB->SetFillStyle(3004);
2438  Dt_hS->SetFillColor(2);
2439  Dt_hB->SetFillColor(4);
2440  Dt_hS->SetLineColor(2);
2441  Dt_hB->SetLineColor(4);
2442 
2443  int max_n=0;
2444  int max[2];
2445  for(int i=0; i<2; i++) max[i]=0;
2446 
2447  max[0]=Dt_hS->GetMaximum();
2448  max[1]=Dt_hB->GetMaximum();
2449 
2450  max_n=max[0];
2451  for(int i=0; i<2; i++) if(max_n<max[i]) max_n=max[i] ;
2452 
2453  imp->Fill(minDt,max_n);
2454  imp->SetLineColor(10);
2455 // imp->SetBins(N_ANNth,ANNth_min,ANNth_max);
2456  imp->GetXaxis()->SetTitle("Duration");
2457  imp->GetYaxis()->SetTitle("Count");
2458  imp->Draw();
2459  Dt_hS->Draw("same");
2460  Dt_hB->Draw("same");
2461 
2462  TString CoG_n(name);
2463  TString CoG_nroot(name);
2464  char CoG_c_n[1024];
2465  char CoG_c_nroot[1024];
2466  CoG_n.ReplaceAll(".root",".png");
2467  sprintf(CoG_c_n,"Duration_plots/nSig%i_nBg%i_invSNR_Plots_%s",nSig,nBg,CoG_n.Data());
2468  sprintf(CoG_c_nroot,"Duration_plots/nSig%i_nBg%i_invSNR_Plots_%s",nSig,nBg,CoG_nroot.Data());
2469  Dt_c->SaveAs(CoG_c_n);
2470  Dt_c->Print(CoG_c_nroot);
2471 
2472 }
char ofile[1024]
#define nCC
#define minCC
double rho
#define NMc_r
#define Ncc3D
#define nRHO
Float_t * rho
biased null statistics
Definition: netevent.hh:112
Float_t * duration
max cluster time relative to segment start
Definition: netevent.hh:98
wavearray< double > a(hp.size())
par [0] name
int n
Definition: cwb_net.C:28
void Mcth(TString ifile, int &McFAth_n, int &McFDth_n, double &McthresFA)
TString("c")
ofstream out
Definition: cwb_merge.C:214
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
Int_t GetEntry(Int_t)
Definition: netevent.cc:409
CWB::Toolbox TB
#define deltaANN
void SNR_plots(TString ifile)
STL namespace.
int j
Definition: cwb_net.C:28
i drho i
wavearray< double > hh
Definition: Regression_H1.C:73
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
void graph(TString ifile)
#define maxMc_inj
wavearray< double > h
Definition: Regression_H1.C:25
#define RHOth_min
#define nANN
void PlotsAv_Mc(TString ifile)
#define iMc
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
#define ANNth_max
char output[256]
int k
#define minMc_inj
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:113
void CoG_plots(TString ifile)
TFile * ifile
wavearray< double > yy
Definition: TestFrame5.C:12
#define maxMc_r
s s
Definition: cwb_net.C:155
#define minANN_av
#define NANN_av
void Annth(TString ifile, int &FAth_n, int &FDth_n, double &thresFA)
#define deltarho
long int num
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
#define nIFO
#define RHOth_max
#define minMc_r
void PlotsAv_cc(TString ifile)
Int_t GetEntries()
Definition: netevent.cc:403
char line[1024]
#define N_ANNth
#define N_RHOth
void Average_FAout_moreGraphs_3(double FAdes, 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=0, int av_on_nNN=0)
wavearray< double > y
Definition: Test10.C:31
#define ANNth_min
#define NMc_inj
#define deltacc
Float_t * chirp
range to source: [0/1]-rec/inj
Definition: netevent.hh:128
void duration_plot(TString ifile)
exit(0)
#define maxANN_av
#define maxCC