Logo coherent WaveBurst  
Library Reference Guide
Logo
Average.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 nIFO 3
43 #define nRHO 3
44 #define nANN 10
45 #define deltaANN 0.1
46 #define nCC 4
47 #define NPIX 20
48 #define RHOth 5.5
49 #define nth 10
50 #define rhomin 6
51 #define ccmin 0.6
52 #define iMc 1
53 using namespace std;
54 void graph(TString ifile);
55 void Annth(TString ifile);
58 //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){
59 
60 //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").
61 //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").
62 //TS, TB: numbers of events to test for each class.
63 //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
64 //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.
65 void Average(TString NN_FILE,TString NN_FILE2, TString NN_FILE3, TString NN_FILE4, TString NN_FILE5, TString NN_FILE6, TString NN_FILE7, TString NN_FILE8, TString TEST_FILE, TString NOMEtot_S, int TS=0, int TB=0, int s=0, int b=0, int uf=1, int consider_all=1){
66 int ni=0;
67 if(uf==0) ni=1;
68 else ni=0;
69 
70 if (uf!=0&&consider_all==0) ni=1;
71 
72 //COUNT THE ANNs
73 int n_NN=0;
74 if (NN_FILE.CompareTo("")){
75  n_NN=n_NN+1;
76  }
77 if (NN_FILE2.CompareTo("")){
78  n_NN=n_NN+1;
79  }
80 if (NN_FILE3.CompareTo("")){
81  n_NN=n_NN+1;
82  }
83 if (NN_FILE4.CompareTo("")){
84  n_NN=n_NN+1;
85  }
86 if (NN_FILE5.CompareTo("")){
87  n_NN=n_NN+1;
88  }
89 if (NN_FILE6.CompareTo("")){
90  n_NN=n_NN+1;
91  }
92 if (NN_FILE7.CompareTo("")){
93  n_NN=n_NN+1;
94  }
95 if (NN_FILE8.CompareTo("")){
96  n_NN=n_NN+1;
97  }
98 int const nNN=n_NN;
99 
100 // int p=0;
101  char NNi[nNN][1024];
102  char NNi2[nNN][1024];
103  sprintf(NNi2[0],"%s",NN_FILE.Data());
104  if(nNN>1) sprintf(NNi2[1],"%s",NN_FILE2.Data());
105  if(nNN>2) sprintf(NNi2[2],"%s",NN_FILE3.Data());
106  if(nNN>3) sprintf(NNi2[3],"%s",NN_FILE4.Data());
107  if(nNN>4) sprintf(NNi2[4],"%s",NN_FILE5.Data());
108  if(nNN>5) sprintf(NNi2[5],"%s",NN_FILE6.Data());
109  if(nNN>6) sprintf(NNi2[6],"%s",NN_FILE7.Data());
110  if(nNN>7) sprintf(NNi2[7],"%s",NN_FILE8.Data());
111 
112 //saving the ANN names
113  for (int u=0;u<nNN;u++){
114  int p=0;
115  while (NNi2[u][p]){
116  if (NNi2[u][p]=='N'){
117  if((NNi2[u][p+1]=='N')&&(NNi2[u][p+2]=='\/')) {
118  int hh=p+3;
119  while (NNi2[u][hh]!='\0'){NNi[u][hh-p-3]=NNi2[u][hh];hh=hh+1;}
120  break;
121  }
122  }
123  p=p+1;
124  }
125 }
126 
127 //saving the Test-file name
128 int q=0;
129  char Filei[1024];
130  char Filei2[1024];
131  sprintf(Filei2,"%s",TEST_FILE.Data());
132  while (Filei2[q]){
133  if(Filei2[q]=='n'&&Filei2[q+1]=='n'&&Filei2[q+2]=='T'&&Filei2[q+3]=='R'&&Filei2[q+4]=='E'&&(Filei2[q+5]=='E')&&(Filei2[q+6]=='\/')) {
134  int hh=q+7;
135  while (Filei2[hh]!='\0') {Filei[hh-q-7]=Filei2[hh];hh=hh+1;
136  }
137  for (int h0=hh-q-7;h0<1024;h0++) Filei[h0]='\0';
138  break;
139  }
140  q=q+1;
141  }
142 
143  cout<<Filei<<" original String: "<<Filei2<<endl;
144 
145 
146  TString NNi0[nNN];
147  NNi0[0]=NNi[0];
148  if(nNN>1) NNi0[1]=NNi[1];
149  if(nNN>2) NNi0[2]=NNi[2];
150  if(nNN>3) NNi0[3]=NNi[3];
151  if(nNN>4) NNi0[4]=NNi[4];
152  if(nNN>5) NNi0[5]=NNi[5];
153  if(nNN>6) NNi0[6]=NNi[6];
154  if(nNN>7) NNi0[7]=NNi[7];
155 
156  TString Filei0(Filei);
157 
158 //removing the extensions
159 for (int u=0;u<nNN;u++){
160  NNi0[u].ReplaceAll(".root","");
161  }
162  Filei0.ReplaceAll(".root","");
163 
164 //Definitions of some parameters
165  TFile *fnet[nNN];
166  TMultiLayerPerceptron* mlp[nNN];
167  TTree* infot[nNN];
168  int TotBg[nNN];
169  int FD0[nNN]; //FD=False Dismissal
170  int FA0[nNN]; //FA=False Alarm
171 
172  for (int yy=0; yy<nNN; yy++){TotBg[yy]=0;FA0[yy]=0;FD0[yy]=0;}
173 
174  int NNs[nNN]; //first SIG-event considered for ANN trainings
175  int NNb[nNN]; //first BKG-event considered for ANN trainings
176  int NNnTS[nNN]; //number of SIG-events considered for ANN trainings
177  int NNnTB[nNN]; //number of BKG-events considered for ANN trainings
178 
179 int min_NNb=5000000;
180 int min_NNs=5000000;
181 
182 //Extracting ANNs and information from the files
183 //if (uf!=0&&ni==0&&(TS!=0||TB!=0)){
184  for (int u=0;u<nNN;u++){
185  fnet[u]=TFile::Open(NNi2[u]);
186  mlp[u]=(TMultiLayerPerceptron*)fnet[u]->Get("TMultiLayerPerceptron");
187 
188  cout<<"dopo TMLP"<<endl;
189  if(mlp[u]==NULL) {cout << "Error getting mlp" << endl;exit(1);}
190  infot[u]=(TTree*)fnet[u]->Get("info");
191 
192  infot[u]->SetBranchAddress("Rand_start_Sig",&NNs[u]);
193  infot[u]->SetBranchAddress("Rand_start_Bg",&NNb[u]);
194  infot[u]->SetBranchAddress("#trainSig",&NNnTS[u]);
195  infot[u]->SetBranchAddress("#trainBg",&NNnTB[u]);
196  infot[u]->GetEntry(0);
197  cout<<"n "<<u<<" b "<<NNb[u]<<" min_NNb "<<min_NNb<<endl;
198 
199  if(NNs[u]<min_NNs) min_NNs=NNs[u];
200  if(NNb[u]<min_NNb) min_NNb=NNb[u];
201  cout<<"n "<<u<<" s "<<NNs[u]<<" b "<<NNb[u]<<" s fin "<<NNs[u]+NNnTS[u]<<" b fin "<<NNb[u]+NNnTB[u]<<" nTS "<<NNnTS[u]<<" nTB "<<NNnTB[u]<<endl;
202  }
203 
204 //check if b and s have correct values.
205 int b_ok=0;
206 int s_ok=0;
207 for (int u=0;u<nNN;u++){
208  if((NNb[u]<b||NNb[u]==b)&&b>NNb[u]+ NNnTB[u]) b_ok=1;
209  if((NNs[u]<s||NNs[u]==s)&&b>NNs[u]+ NNnTS[u]) s_ok=1;
210 
211 }
212 
213 //Changing b value to its sum to the first event considered for the training
214 //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;}
215 if (uf!=0&&ni==0&&(b_ok==0)){ b=min_NNb;cout<<" change b value to have BKG events used for training procedures, b="<<b<<endl;}
216 if (uf!=0&&ni==0&&(s_ok==0)){ s=min_NNs;cout<<" change s value to have SIG events used for training procedures s="<<s<<endl;}
217 cout<<" min_NNb "<<min_NNb<<" b "<<b<<endl;
218 cout<<"Def. tree e mlp"<<endl;
219 
220 //opening the Test-file
221  TFile* fTEST =TFile::Open(TEST_FILE.Data());
222  TTree* NNTree=(TTree*)fTEST->Get("nnTree");
223  int entries=NNTree->GetEntries();
224  cout<<"entries: "<<entries<<endl;
225 
226 //Extract information necessary for the tree which defines the mlp
227  int ndim;
228  int ninp;
229  int y;
230  int entriesTot;
231  int bg_entries;
232  int sig_entries;
233 
234  NNTree->SetBranchAddress("#Entries_type",&entriesTot);
235  NNTree->SetBranchAddress("Matrix_dim",&ndim);
236  NNTree->SetBranchAddress("#inputs",&ninp);
237  NNTree->SetBranchAddress("amplitude_mode",&y);
238 
239  NNTree->GetEntry(0);
240  sig_entries=entriesTot;
241  NNTree->GetEntry(entries-1);
242  bg_entries=entriesTot;
243 
244  int const NDIM=ndim;
245  int const nINP=ninp;
246 
247  cout<<"NDIM: "<<NDIM<<endl;
248  cout<<"nINP: "<<nINP<<endl;
249  cout<<"sig e: "<<sig_entries<<endl;
250  cout<<"bg e: "<<bg_entries<<endl;
251 
252 //defining the sample which has less events
253  int minevents=0;
254  if (sig_entries>bg_entries) minevents=bg_entries;
255  else minevents=sig_entries;
256 
257  //if(b==0) b=sig_entries;
258  if(TB==0 && TS==0){
259  TS=minevents;
260  TB=minevents;
261  }
262 
263 //defining compatible parameters
264  if (b<sig_entries){
265  int a =b;
266  b+=sig_entries;
267  cout<<"Error: Bg index<sig_entries: new set of b parameter-> b="<<b<<" instead of b="<<a<<endl;
268  //exit(0);
269 }
270 
271 //set TS and TB to their maximum posible values
272 if((TS>sig_entries-s||TB>(bg_entries-(b-sig_entries)))&&(TS==TB)) {TS=minevents-s;TB=minevents-(b-sig_entries);
273  if (TS<TB) TB=TS;
274  else TS=TB;
275  cout<<"Error:S>sig_entries or TB>bg_entries, to maintain ugual number of analysed events TS=TB="<<TB<<endl;
276  }
277  if((TS>sig_entries-s||TB>bg_entries-(b-sig_entries))&&(TS!=TB)) {
278  if(TS>sig_entries) TS=sig_entries-s;
279  if (TB>bg_entries) TB=bg_entries-(b-sig_entries);
280  cout<<"Error:TS>sig_entries or TB>bg_entries, new TS and TB values are thus define-> TS="<<TS<<" TB="<<TB<<endl;
281  }
282 
283 
284  char NOMEtot[1024];
285  sprintf(NOMEtot,"%s",NOMEtot_S.Data());
286  cout<<"output name: "<<NOMEtot<<endl;
287 
288 //extracting original files
289  TString SIG_FILE;
290  TString BG_FILE;
291  char FILE_NAME[516];
292  NNTree->SetBranchAddress("Files_name",&FILE_NAME);
293  NNTree->GetEntry(0);
294  SIG_FILE=FILE_NAME;
295  NNTree->GetEntry(entries-1);
296  BG_FILE=FILE_NAME;
297  cout<<"fine ifdef RHO_CC"<<endl;
298 
299 //extracting other information
300  TChain sigTree("waveburst");//search the Tree "waveburst" in files
301  sigTree.Add(SIG_FILE.Data());
302  netevent signal(&sigTree,nIFO);
303  int sig_entries2 = signal.GetEntries();
304  cout << "sig entries2 : " << sig_entries2 << endl;
305 
306  TChain bgTree("waveburst");
307  bgTree.Add(BG_FILE.Data());
308  netevent background(&bgTree,nIFO);
309  int bg_entries2 = background.GetEntries();
310  cout << "bg entries2 : " << bg_entries2 << endl;
311 
312  cout<<"b: "<<b<<endl;
313  cout<<"s: "<<s<<endl;
314 
315  // add leaf
316  Float_t x[nINP];
317  for (int jj=0; jj<nINP;jj++) x[jj]=0.;
318  char ilabel[nINP][16];
319 
320  // define a branch for each input
321  for(int i=0;i<nINP;i++) {
322  sprintf(ilabel[i],"x%i",i+1);
323  NNTree->SetBranchAddress(ilabel[i], &x[i]);
324  }
325 
326 char ofile[1024];
327 sprintf(ofile,"average_file/%s.root",NOMEtot);
328 TFile*f =new TFile(ofile,"RECREATE");
329  TTree* NNTree2=new TTree("Parameters","Parameters");
330  NNTree2->SetDirectory(f);
331 
332 // defining useful information
333  double average=0.;
334  double out[nNN];
335  for(int y=0; y<nNN; y++) out[y]=0.;
336  double Mc=0.;
337  double NNcc=0.;
338  double NNrho=0.;
339  double std=0.;
340 
341 //adding new information to the original tree
342  NNTree2->Branch("Average",&average,"Average/D");
343  NNTree2->Branch("StandardDevaition",&std,"StandardDeviation/D");
344  NNTree2->Branch("cc",&NNcc,"cc/D");
345  NNTree2->Branch("Mchirp",&Mc,"Mchirp/D");
346  NNTree2->Branch("rho",&NNrho,"rho/D");
347 
348  for(int u=0;u<nNN;u++){
349  char NNoutl[512];
350  char NNoutl2[512];
351  char NNnamel[512];
352  char NNnamel2[512];
353  sprintf(NNoutl,"NNout%i",u);
354  sprintf(NNoutl2,"NNout%i/D",u);
355  sprintf(NNnamel,"NNname%i",u);
356  sprintf(NNnamel2,"NNname%i/C",u);
357  NNTree2->Branch(NNoutl,&out[u],NNoutl2);
358  NNTree2->Branch(NNnamel,&NNi[u],NNnamel2);
359  }
360 
361  char Testf[1024];
362  NNTree2->Branch("TestFile",&Testf,"TestFile/C");
363  sprintf(Testf,"%s",TEST_FILE.Data());
364  int nTestS=0;
365 
366  NNTree2->Branch("#TestSig",&nTestS,"#TestSig/I");
367  cout<<"nTestS: "<<nTestS<<" TS: "<<TS<<endl;
368  cout<<"dopo def tree"<<endl;
369 
370 //defining how many examples to use
371  int scount=0;
372  if(uf==0) nTestS=TS;
373  else {
374  for(int n=s;n<s+TS;n++) {
375  int countNN=0;
376  for(int u=0;u<nNN;u++){
377  if (uf!=0&&n>NNs[u]&&n<(NNs[u]+NNnTS[u])) countNN=countNN+1;
378  }
379  if(countNN==1&&ni==0) scount=scount+1;
380  if(countNN<2&&ni!=0) scount=scount+1; //if you are indifferently intereseted in average on nNN or nNN-1
381  if(countNN>1){cout<<"Error: training non independent"<<n<<endl; exit(0);} //exit if the ANNs are training on dependent set of events
382  }
383  nTestS=scount;
384 }
385 
386 cout<<"s test "<<s<< " s+TS "<<s+TS<<" b "<<b<<" b+ TB "<<b+TB<<" nTestS "<<nTestS<<endl;
387 
388  double params[nINP];
389  int sig_05=0;
390  for (int i=0; i<nINP; i++) params[i]=0.;
391 
392  int S_eff=0;
393  int FD=0;
394 
395  for(int n=s;n<s+TS;n++) {
396  average=0.;
397  int indNN=-1;
398  int countNN=0;
399  for(int u=0;u<nNN;u++){
400  if (uf!=0&&n>=NNs[u]&&n<(NNs[u]+NNnTS[u])) { indNN=u;countNN=countNN+1;}
401  }
402  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
403  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
404  if(ni==0&&countNN==0)continue; //skip if any network is trained on the considered event
405  NNTree->GetEntry(n);
406  signal.GetEntry(n);
407 
408  // exracting parameters
409  NNcc=(double)signal.netcc[1];
410  NNrho=(double)signal.rho[0];
411  Mc=(double)signal.chirp[iMc];
412 
413  // evaluating the event
414  for (int i=0; i<nINP; i++){
415  params[i]=x[i];
416  }
417  for (int u=0;u<nNN;u++) {
418  cout<<" u "<<u<<" nNN "<<nNN<<endl;
419  double output=mlp[u]->Evaluate(0,params);
420  cout<<output<<endl;
421  out[u]=output;
422  }
423 
424 
425  cout<<"Dopo param"<<endl;
426 
427 //calculating the average and the standard deviation
428 
429  //wrong!!!
430  /*for (int u=0;u<nNN;u++){
431  if((u!=indNN&&ni==0)||ni!=0) {average=out[u]+average;std+=out[u]*out[u];if(out[u]<0.6) FD0[u]=FD0[u]+1;}
432  }*/
433  for (int u=0;u<nNN;u++){
434  if((u!=indNN&&ni==0)||uf==0) {average=out[u]+average;std+=out[u]*out[u];if(out[u]<0.6) FD0[u]=FD0[u]+1;}
435  }
436 
437 
438  if(nNN!=1&&ni==0) {average=average/(nNN-countNN); if((nNN-1-countNN)!=0)std=pow((std/(nNN-1-countNN)-average*average),0.5);else std=pow((std/(nNN-countNN)-average*average),0.5);}
439 
440 
441  //wrong!!!
442  //if(nNN!=1&&ni!=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);}
443  if(nNN!=1&&uf==0) {average=average/(nNN); if((nNN-1)!=0)std=pow((std/(nNN-1)-average*average),0.5);else std=pow((std/nNN-average*average),0.5);}
444  cout<<"average: "<<average<<endl;
445  cout<<"Mc "<<Mc<<endl;
446  if (average<0.6) FD=FD+1;
447  NNTree2->Fill();
448  S_eff=S_eff+1;
449 }
450 //closing the cycle on SIG events
451 
452 //defining BKG parameters
453 int B_eff=0;
454 int FA=0;
455 cout<<"riempito sig S_eff"<<S_eff<<endl;
456 int bg_05=0;
457 int cont_su=0;
458 int cont_su5=0;
459 int cont_su4=0;
460 int cont_su3=0;
461 
462 //opening the cycle on BKG events
463  for(int n=b;n<b+TB;n++) {
464  average=0.;
465  int indNN=-1;
466  int countNN=0;
467  for(int u=0;u<nNN;u++){
468  cout<<" uf "<<uf<<" n "<<n<<" u "<<u<<" NN b[u] "<<NNb[u]<<" NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
469  if (uf!=0&&n>=NNb[u]&&n<(NNb[u]+NNnTB[u])) { indNN=u;countNN=countNN+1; }
470  }
471 
472  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
473  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
474  if(ni==0&&countNN==0){ cout<<"countNN"<<countNN<<endl; continue;}
475 
476  NNTree->GetEntry(n);
477  cout<<"BKG->n: "<<n<<"Bg index"<<(n-sig_entries)<<endl;
478  background.GetEntry(n-sig_entries);
479  NNcc=(double)background.netcc[1];
480  NNrho=(double)background.rho[0];
481  Mc=(double)background.chirp[iMc];
482  for (int i=0; i<nINP; i++){
483  params[i]=x[i];
484  }
485 
486  for(int u=0;u<nNN;u++) {
487  double output=mlp[u]->Evaluate(0,params);
488  cout<<output<<endl;
489  out[u]=output;
490  }
491  int nnsu=0;
492  for (int u=0;u<nNN;u++){
493  if((u!=indNN&&ni==0)||ni!=0) { cout<<" u "<<u<<" n "<<n<<" FA0[u] "<<FA0[u]<<endl;average=out[u]+average;std=out[u]*out[u];TotBg[u]=TotBg[u]+1; if(out[u]>0.6) {FA0[u]=FA0[u]+1;nnsu=nnsu+1;}}
494  }
495  if(nnsu==6) cont_su=cont_su+1;
496  if(nnsu>4) cont_su5=cont_su5+1;
497  if(nnsu>3) cont_su4=cont_su4+1;
498  if(nnsu>2) cont_su3=cont_su3+1;
499 
500 //calculating the final average value
501  if(nNN!=1&&ni==0) {cout<<average<<endl;average=average/(nNN-countNN);
502  cout<<"ni==0"<<average<<endl; if((nNN-1-countNN)!=0)std=pow((std/(nNN-1-countNN)-average*average),0.5);else std=pow((std/(nNN-countNN)-average*average),0.5);}
503 
504  //if(nNN!=1&&ni!=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<<"ni!=0"<<average<<endl;}
505  //wrong!!!
506  //if(nNN!=1&&ni!=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<<"ni!=0"<<average<<endl;}
507 
508  if(nNN!=1&&uf==0) {cout<<average<<endl;average=average/(nNN);if((nNN-1)!=0)std=pow((std/(nNN-1)-average*average),0.5);else std=pow((std/nNN-average*average),0.5); cout<<"uf==0"<<average<<endl;}
509  cout<<"average: "<<average<<endl;
510 
511 //saving false alarms
512  if(average>0.6) FA=FA+1;
513 
514  NNTree2->Fill();
515  B_eff=B_eff+1;
516  }
517 cout<<"bkg filled"<<endl;
518 
519 NNTree2->Write();
520 f->Close();
521 
522 cout<<"closed file"<<endl;
523 cout<<ofile<<endl;
524 
525 int cont=0;
526 cout<<" S_eff "<<S_eff<<" B_eff "<<B_eff<<endl;
527 
528 double freq_c[nNN];
529 double meanf=0.;
530 double dev=0.;
531 
532 for (int yy=0; yy<nNN; yy++){
533  freq_c[yy]=0.;
534  cout<<" FA0[yy] "<<FA0[yy]<<" FD0[yy] "<<FD0[yy]<<" FD "<<FD<<" TotBg[yy] "<<TotBg[yy]<<endl;
535  if(TotBg[yy]!=0){freq_c[yy]=(double)FA0[yy]/TotBg[yy];cout<<" freq_c[yy] "<<freq_c[yy]<<endl;}
536  if(freq_c[yy]!=0) {meanf=freq_c[yy]+meanf;cont=cont+1;cout<<" cont "<<cont<<endl;}
537  dev=freq_c[yy]*freq_c[yy]+dev;
538 }
539 
540 if(cont==0) cout<<"Error cont==0"<<endl;
541 if(cont!=0) meanf=meanf/cont;
542 dev=0.;
543 for (int yy=0; yy<nNN; yy++){
544 cout<<" dev "<<dev<<endl;
545 cout<<"freq_c[yy] "<<freq_c[yy]<<" meanf "<<meanf<<endl;
546 if(freq_c[yy]!=0)dev+=(freq_c[yy]-meanf)*(freq_c[yy]-meanf);
547 }
548 Annth(ofile);
549 graph(ofile);
550 PlotsAv_cc(ofile);
551 PlotsAv_Mc(ofile);
552 if(cont!=0) dev=pow(dev/(cont-1),0.5);
553 cout<<"meanf "<<meanf<<" dev "<<dev<<endl;
554 cout<<" FA average "<<FA<<endl;
555 cout<<" cont_su "<<cont_su<<" cont_su5 "<<cont_su5<<" cont_su4 "<<cont_su4<<" cont_su3 "<<cont_su3<<endl;
556 
557 cout<<" FA0[1] "<<FA0[1]<<" TotBg[1] "<<TotBg[1]<<endl;
558 cout<<" FD0[1] "<<FD0[1]<<" TotBg[1] "<<TotBg[1]<<endl;
559 }
560 
562  TString name(ifile);
563  name.ReplaceAll("average_file/","");
564  TFile* fTEST =TFile::Open(ifile.Data());
565  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
566  double av;
567  double cc;
568  double rho;
569  int nSi;
570  NNTree2->SetBranchAddress("Average",&av);
571  NNTree2->SetBranchAddress("cc",&cc);
572  NNTree2->SetBranchAddress("rho",&rho);
573  NNTree2->SetBranchAddress("#TestSig",&nSi);
574  NNTree2->GetEntry(0);
575  int const nSig=nSi;
576  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
577  cout<<" BG: "<<NNTree2->GetEntries()-nSi<<endl;
578  int const ncurve=nANN*nCC;
579  cout<<"dentro funzione dopodef"<<endl;
580 //LOG(NBg)vs RHO------------------------------------------
581  double* rhoSig[ncurve];
582  for (int i=0;i<ncurve;i++) rhoSig[i]=new double[nSig];
583  cout<<"dopo def rhoSig"<<endl;
584  //double rhoSig[20][10];
585  int NSig[ncurve];
586 // int nBg=0;
587  int const nBg=NNTree2->GetEntries()-nSig;
588  for (int i=0;i<ncurve;i++) {
589  NSig[i]=0;
590  for (int j=0;j<nSig;j++) rhoSig[i][j]=0.;
591  }
592  cout<<"dopo def rhoSig"<<endl;
593  double* rhoBg[ncurve];
594  for (int i=0;i<ncurve;i++) rhoBg[i]=new double[nBg];
595  //double rhoBg[20][10];
596  int NBg[ncurve];
597  for (int i=0;i<ncurve;i++) {
598  NBg[i]=0;
599  for (int j=0;j<nBg;j++) rhoBg[i][j]=0.;
600  }
601  cout<<"dopo def rhoBg"<<endl;
602  double ccTh[nCC];
603  for (int i=0;i<nCC;i++) ccTh[i]=0.;
604  double NNTh[nANN];
605  for (int i=0;i<nANN;i++) NNTh[i]=0.;
606  double deltacc=0.;
607 // double deltaANN=0.;
608  deltacc=0.2/nCC;
609  //deltaANN=0.6/(nANN-1);
610 
611  cout<<NNTree2->GetEntries()<<endl;
612  for(int n=0;n<NNTree2->GetEntries();n++){
613  cout<<n<<endl;
614  NNTree2->GetEntry(n);
615  cout<<"rho "<<rho<<" cc "<<cc<<" av "<<av<<endl;
616  for(int i=0; i<nCC;i++){
617  ccTh[i]=0.5+i*deltacc;
618  if(cc<ccTh[i]) continue;
619  for(int j=0; j<nANN;j++){
620  if(j==0) NNTh[j]=-1000.;
621  //else NNTh[j]=0.5+(j-1)*deltaANN;
622  //else NNTh[j]=0.1+(j-1)*deltaANN;
623  else NNTh[j]=0.+(j)*deltaANN;
624  //else NNTh[j]=0.+(j-1)*deltaANN/1000.;
625  //else NNTh[j]=1.;
626  if(av<NNTh[j]) continue;
627  int ni=0;
628  if(n>nSig) {
629 
630  NBg[i*nANN+j]= NBg[i*nANN+j]+1;
631  while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
632  rhoBg[i*nANN+j][ni]=rho;
633  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
634 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
635  }
636  else {
637  NSig[i*nANN+j]= NSig[i*nANN+j]+1;
638  while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
639  rhoSig[i*nANN+j][ni]=rho;
640  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
641 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
642  }
643  // }
644  }
645  }
646  }
647  cout<<"dopo riempimento variabili"<<endl;
648  int* indexS[ncurve];
649  for (int i=0;i<ncurve;i++) indexS[i]=new int[nSig];
650 
651  TGraph * gS[ncurve];
652  for (int y=0;y<ncurve;y++) {
653  int igS=0;
654  int igS_p=0;
655  /* int indexS[nSig];
656  double rhoS[nSig];
657  for(int i=0;i<nSig;i++) {
658  rhoS[i]=0.;
659  indexS[i]=0;
660  }*/
661  // ig=1;
662  // for(int i=0;i<nSig;i++) rhoS[i]=rhoSig[y][i];
663  gS[y]=new TGraph();
664 // gS[y]->SetMarkerStyle(7);
665  TMath::Sort(nSig,rhoSig[y],indexS[y],false);
666 // cout<<"dopo Sort "<<y<<endl;
667  for (int k=0;k<nSig;k++) {
668  int ii=indexS[y][k];
669  int yy=0;
670  if (k>0){
671 // cout<<"k "<<k<<endl;
672  int ij=indexS[y][k-1];
673  //if(rhoSig[y][ii]!=0&&rhoSig[y][ii]!=rhoSig[y][ij]) {
674  if(rhoSig[y][ii]!=0) {
675  yy=NSig[y]-igS;
676  //gS[y]->SetPoint(igS,rhoSig[y][ii],yy);
677  if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
678  cout<<"igS"<<igS<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
679  igS=igS+1;
680  }
681  }
682  else {
683  if(rhoSig[y][ii]!=0){
684  yy=NSig[y]-igS;
685  gS[y]->SetPoint(0,rhoSig[y][ii],yy);
686  igS=igS+1;
687 // cout<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
688  }
689 
690  }
691  }
692  }
693  // cout<<"dopo inserimento puntiiS"<<endl;
694 // cout<<ncurve<<endl;
695  int* indexB[ncurve];
696  for (int i=0;i<ncurve;i++) indexB[i]=new int[nBg];
697 
698  TGraph * gB[ncurve];
699  for (int y=0;y<ncurve;y++) {
700  int igB=0;
701  int igB_p=0;
702  gB[y]=new TGraph();
703  TMath::Sort(nBg,rhoBg[y],indexB[y],false);
704 // cout<<"dopo Sort "<<y<<endl;
705  for (int k=0;k<nBg;k++) {
706  int ii=indexB[y][k];
707  int yy=0;
708  if (k>0){
709  int ij=indexB[y][k-1];
710  //if(rhoBg[y][ii]!=0&&rhoBg[y][ii]!=rhoBg[y][ij]) {
711  if(rhoBg[y][ii]!=0) {
712  yy=NBg[y]-igB;
713  //gB[y]->SetPoint(igB,rhoBg[y][ii],yy);
714  if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
715  igB=igB+1;
716 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
717  }
718  }
719  else {
720  if(rhoBg[y][ii]!=0) {
721  yy=NBg[y]-igB;
722  gB[y]->SetPoint(0,rhoBg[y][ii],yy);
723  igB=igB+1;
724 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
725  }
726  }
727  }
728  }
729  cout<<"dopo inserimento puntiB"<<endl;
730  //gB[1]->SetMarkerStyle(7);
731  //gB[1]->SetPoint(1,1,2);
732  TCanvas* cS=new TCanvas("Efficiency_vs_rho","Efficiency_vs_rho",0,0,1200,700);
733  cS->Divide(2,2);
734  cS->cd(1)->SetLogy();
735  TMultiGraph* mg1=new TMultiGraph();
736 // gS[0]->SetMarkerStyle(7);
737  gS[0]->SetMarkerColor(2);
738  gS[0]->SetLineColor(2);
739  mg1->SetTitle("cc=0.5;rho;#Events");
740  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
741 // gS[0]->Draw("apl");
742  for (int h=1;h<nANN;h++){
743  gS[h]->SetMarkerColor(3);
744  gS[h]->SetLineColor(3);
745 // gS[h]->SetMarkerStyle(h+1);
746  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
747  // gS[h]->Draw("apl,same");
748  }
749  mg1->Draw("apl");
750  cS->cd(2)->SetLogy();
751  TMultiGraph* mg2=new TMultiGraph();
752 // gS[nANN]->SetMarkerStyle(7);
753  gS[nANN]->SetMarkerColor(2);
754  gS[nANN]->SetLineColor(2);
755  mg2->SetTitle("cc=0.55;rho;#Events");
756  if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
757  for (int h=1;h<nANN;h++){
758  gS[nANN+h]->SetMarkerColor(3);
759  gS[nANN+h]->SetLineColor(3);
760 // gS[nANN+h]->SetMarkerStyle(h+1);
761  if(gS[nANN+h]->GetN()!=0) mg2->Add(gS[nANN+h]);
762  // gS[nANN+h]->Draw("apl,same");
763  }
764  mg2->Draw("apl");
765  cS->cd(3)->SetLogy();
766  TMultiGraph* mg3=new TMultiGraph();
767 // gS[nANN*2]->SetMarkerStyle(7);
768  gS[nANN*2]->SetMarkerColor(2);
769  gS[nANN*2]->SetLineColor(2);
770  mg3->SetTitle("cc=0.6;rho;#Events");
771  if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
772  for (int h=1;h<nANN;h++){
773  gS[2*nANN+h]->SetMarkerColor(3);
774  gS[2*nANN+h]->SetLineColor(3);
775 // gS[2*nANN+h]->SetMarkerStyle(h+1);
776  if(gS[2*nANN+h]->GetN()!=0) mg3->Add(gS[2*nANN+h]);
777  // gS[2*nANN+h]->Draw("apl,same");
778  }
779  mg3->Draw("apl");
780  cS->cd(4)->SetLogy();
781  TMultiGraph* mg4=new TMultiGraph();
782 // gS[nANN*3]->SetMarkerStyle(7);
783  gS[nANN*3]->SetMarkerColor(2);
784  gS[nANN*3]->SetLineColor(2);
785  mg4->SetTitle("cc=0.65;rho;#Events");
786  if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
787  // gS[nANN*3]->Draw("apl");
788  for (int h=1;h<nANN;h++){
789  gS[3*nANN+h]->SetMarkerColor(3);
790  gS[3*nANN+h]->SetLineColor(3);
791 // gS[3*nANN+h]->SetMarkerStyle(h+1);
792  if(gS[3*nANN+h]->GetN()!=0) mg4->Add(gS[3*nANN+h]);
793  // gS[3*nANN+h]->Draw("apl,same");
794  }
795  mg4->Draw("apl");
796  cout<<"nuovo canv"<<endl;
797  TCanvas* cB=new TCanvas("Number_vs_rho","Number_vs_rho",0,0,1200,700);
798  cB->Divide(2,2);
799  cB->cd(1)->SetLogy();
800  TMultiGraph* mg1B=new TMultiGraph();
801 // gB[0]->SetMarkerStyle(7);
802  gB[0]->SetMarkerColor(2);
803  gB[0]->SetLineColor(2);
804  mg1B->SetTitle("cc=0.5;rho;#Events");
805  if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
806  for (int h=1;h<nANN;h++){
807  gB[h]->SetMarkerColor(3);
808  gB[h]->SetLineColor(3);
809  // gB[h]>SetMarkerStyle(h+1);
810  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
811  //gB[h]->Draw("apl,same");
812  }
813  mg1B->Draw("apl");
814  cB->cd(2)->SetLogy();
815  TMultiGraph* mg2B=new TMultiGraph();
816  //gB[nANN]->SetMarkerStyle(7);
817  gB[nANN]->SetMarkerColor(2);
818  gB[nANN]->SetLineColor(2);
819  mg2B->SetTitle("cc=0.55;rho;#Events");
820  if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
821  for (int h=1;h<nANN;h++){
822  gB[nANN+h]->SetMarkerColor(3);
823  gB[nANN+h]->SetLineColor(3);
824  //gB[nANN+h]>SetMarkerStyle(h+1);
825  if(gB[nANN+h]->GetN()!=0) mg2B->Add(gB[nANN+h]);
826  //gB[h]->Draw("apl,same");
827  }
828  mg2B->Draw("apl");
829  cB->cd(3)->SetLogy();
830  TMultiGraph* mg3B=new TMultiGraph();
831 // gB[2*nANN]->SetMarkerStyle(7);
832  gB[2*nANN]->SetMarkerColor(2);
833  gB[2*nANN]->SetLineColor(2);
834  mg3B->SetTitle("cc=0.6;rho;#Events");
835  if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
836  for (int h=1;h<nANN;h++){
837  gB[2*nANN+h]->SetMarkerColor(3);
838  gB[2*nANN+h]->SetLineColor(3);
839 // gB[2*nANN+h]>SetMarkerStyle(h+1);
840  if(gB[2*nANN+h]->GetN()!=0) mg3B->Add(gB[2*nANN+h]);
841  //gB[h]->Draw("apl,same");
842  }
843  mg3B->Draw("apl");
844  cB->cd(4)->SetLogy();
845  TMultiGraph* mg4B=new TMultiGraph();
846 // gB[3*nANN]->SetMarkerStyle(7);
847  gB[3*nANN]->SetMarkerColor(2);
848  gB[3*nANN]->SetLineColor(2);
849  mg4B->SetTitle("cc=0.65;rho;#Events");
850  if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
851  for (int h=1;h<nANN;h++){
852  gB[3*nANN+h]->SetMarkerColor(3);
853  gB[3*nANN+h]->SetLineColor(3);
854 // gB[3*nANN+h]>SetMarkerStyle(h+1);
855  if(gB[3*nANN+h]->GetN()!=0) mg4B->Add(gB[3*nANN+h]);
856  //gB[h]->Draw("apl,same");
857  }
858  mg4B->Draw("apl");
859 
860 // cout<<"dopo Draw()"<<endl;
861  TString CnameS(name);
862  TString CnameB(name);
863  TString CnameSroot(name);
864  TString CnameBroot(name);
865  char CnameS2[1024];
866  char CnameB2[1024];
867  char CnameS2root[1024];
868  char CnameB2root[1024];
869  CnameS.ReplaceAll(".root",".png");
870  CnameB.ReplaceAll(".root",".png");
871  sprintf(CnameS2,"logN_rho_av/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameS.Data());
872  sprintf(CnameB2,"logN_rho_av/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameB.Data());
873  sprintf(CnameS2root,"logN_rho_av/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameSroot.Data());
874  sprintf(CnameB2root,"logN_rho_av/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameBroot.Data());
875  cS->SaveAs(CnameS2);
876  cB->SaveAs(CnameB2);
877  cS->Print(CnameS2root);
878  cB->Print(CnameB2root);
879 // cout<<"fine"<<endl;
880 
881 }
882 
883 
885  TString name(ifile);
886  name.ReplaceAll("average_file/","");
887  TFile* fTEST =TFile::Open(ifile.Data());
888  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
889  double av;
890  double cc;
891  double rho;
892  int nSi;
893  NNTree2->SetBranchAddress("Average",&av);
894  NNTree2->SetBranchAddress("cc",&cc);
895  NNTree2->SetBranchAddress("rho",&rho);
896  NNTree2->SetBranchAddress("#TestSig",&nSi);
897  NNTree2->GetEntry(0);
898  int const nSig=nSi;
899 // cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
900  int const ncurve2=nRHO*nCC;
901 
902 
903  double* ANNSig[ncurve2];
904  for (int i=0;i<ncurve2;i++) ANNSig[i]=new double[nSig];
905  //double rhoSig[20][10];
906  int NSig[ncurve2];
907 // int nBg=0;
908  int const nBg=NNTree2->GetEntries()-nSig;
909  for (int i=0;i<ncurve2;i++) {
910  NSig[i]=0;
911  for (int j=0;j<nSig;j++) ANNSig[i][j]=0.;
912  }
913  double* ANNBg[ncurve2];
914  for (int i=0;i<ncurve2;i++) ANNBg[i]=new double[nBg];
915 
916  //double rhoBg[20][10];
917  int NBg[ncurve2];
918  for (int i=0;i<ncurve2;i++) {
919  NBg[i]=0;
920  for (int j=0;j<nBg;j++) ANNBg[i][j]=0.;
921  }
922  double ccTh[nCC];
923  for (int i=0;i<nCC;i++) ccTh[i]=0.;
924  double rhoTh[nRHO];
925  for (int i=0;i<nRHO;i++) rhoTh[i]=0.;
926  double deltacc=0.;
927  double deltarho=0.;
928  deltacc=0.2/nCC;
929  deltarho=1./(nRHO);
930 
931 
932  for(int n=0;n<NNTree2->GetEntries();n++){
933  NNTree2->GetEntry(n);
934  cout<<"rho "<<rho<<" cc "<<cc<<" av "<<av<<endl;
935  for(int i=0; i<nCC;i++){
936  ccTh[i]=0.5+i*deltacc;
937  if(cc<ccTh[i]) continue;
938  for(int j=0; j<nRHO;j++){
939  rhoTh[j]=5+j*deltarho;
940  if(rho<rhoTh[j]) continue;
941  int ni=0;
942  if(n>nSig) {
943  NBg[i*nRHO+j]= NBg[i*nRHO+j]+1;
944  while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
945  ANNBg[i*nRHO+j][ni]=av;
946  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
947  }
948  else {
949  NSig[i*nRHO+j]= NSig[i*nRHO+j]+1;
950  while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
951  ANNSig[i*nRHO+j][ni]=av;
952  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
953  }
954  }
955  }
956  }
957 
958  int* indexS[ncurve2];
959  for (int i=0;i<ncurve2;i++) indexS[i]=new int[nSig];
960 
961  TGraph * gS[ncurve2];
962  for (int y=0;y<ncurve2;y++) {
963  int igS=0;
964  int igS_p=0;
965  gS[y]=new TGraph();
966  TMath::Sort(nSig,ANNSig[y],indexS[y],false);
967  for (int k=0;k<nSig;k++) {
968  int ii=indexS[y][k];
969  int yy=0;
970  if (k>0){
971  //cout<<"k "<<k<<endl;
972  int ij=indexS[y][k-1];
973  //if(ANNSig[y][ii]!=0&&ANNSig[y][ii]!=ANNSig[y][ij]) {
974  if(ANNSig[y][ii]!=0) {
975  yy=NSig[y]-igS;
976  //gS[y]->SetPoint(igS,ANNSig[y][ii],yy);
977  if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
978  // cout<<"igS"<<igS<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
979  igS=igS+1;
980 
981  }
982  }
983  else {
984  if(ANNSig[y][ii]!=0){
985  yy=NSig[y]-igS;
986  gS[y]->SetPoint(0,ANNSig[y][ii],yy);
987  igS=igS+1;
988  // cout<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
989  }
990 
991  }
992  }
993  }
994 
995 
996 
997  int* indexB[ncurve2];
998  for (int i=0;i<ncurve2;i++) indexB[i]=new int[nBg];
999 
1000  TGraph * gB[ncurve2];
1001  for (int y=0;y<ncurve2;y++) {
1002  int igB=0;
1003  int igB_p=0;
1004  gB[y]=new TGraph();
1005  TMath::Sort(nBg,ANNBg[y],indexB[y],false);
1006  // cout<<"dopo Sort "<<y<<endl;
1007  for (int k=0;k<nBg;k++) {
1008  int ii=indexB[y][k];
1009  int yy=0;
1010  if (k>0){
1011  int ij=indexB[y][k-1];
1012  //if(ANNBg[y][ii]!=0&&ANNBg[y][ii]!=ANNBg[y][ij]) {
1013  if(ANNBg[y][ii]!=0) {
1014  yy=NBg[y]-igB;
1015  //gB[y]->SetPoint(igB,ANNBg[y][ii],yy);
1016  if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
1017  igB=igB+1;
1018  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1019  }
1020  }
1021  else {
1022  if(ANNBg[y][ii]!=0) {
1023  yy=NBg[y]-igB;
1024  gB[y]->SetPoint(0,ANNBg[y][ii],yy);
1025  igB=igB+1;
1026  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1027  }
1028  }
1029  }
1030  }
1031 
1032 
1033  TCanvas* cS=new TCanvas("Efficiency_vs_ANN","Efficiency_vs_ANN",0,0,1200,700);
1034  cS->Divide(2,2);
1035  //cS->cd(1)->SetLogy();
1036  cS->cd(1);
1037  TMultiGraph* mg1=new TMultiGraph();
1038  mg1->SetTitle("cc=0.5;ANN;#Events");
1039  for (int h=0;h<nRHO;h++){
1040  gS[h]->SetLineColor(4);
1041  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
1042  }
1043  mg1->Draw("al");
1044  cS->cd(2);
1045  // cS->cd(2)->SetLogy();
1046  TMultiGraph* mg2=new TMultiGraph();
1047  mg2->SetTitle("cc=0.55;ANN;#Events");
1048  for (int h=0;h<nRHO;h++){
1049  gS[nRHO+h]->SetLineColor(4);
1050  if(gS[nRHO+h]->GetN()!=0) mg2->Add(gS[nRHO+h]);
1051  }
1052  mg2->Draw("al");
1053 
1054  //cS->cd(3)->SetLogy();
1055  cS->cd(3);
1056  TMultiGraph* mg3=new TMultiGraph();
1057  mg3->SetTitle("cc=0.6;ANN;#Events");
1058  for (int h=0;h<nRHO;h++){
1059  gS[2*nRHO+h]->SetLineColor(4);
1060  if(gS[2*nRHO+h]->GetN()!=0) mg3->Add(gS[2*nRHO+h]);
1061  }
1062  mg3->Draw("al");
1063  //cS->cd(4)->SetLogy();
1064  cS->cd(4);
1065  TMultiGraph* mg4=new TMultiGraph();
1066  mg4->SetTitle("cc=0.65;ANN;#Events");
1067  for (int h=0;h<nRHO;h++){
1068  gS[3*nRHO+h]->SetLineColor(4);
1069  if(gS[3*nRHO+h]->GetN()!=0) mg4->Add(gS[3*nRHO+h]);
1070  }
1071  mg4->Draw("al");
1072 
1073  TCanvas* cB=new TCanvas("Number_vs_ANN","Number_vs_ANN",0,0,1200,700);
1074  cB->Divide(2,2);
1075  cB->cd(1)->SetLogy();
1076  TMultiGraph* mg1B=new TMultiGraph();
1077  mg1B->SetTitle("cc=0.5;ANN;#Events");
1078  for (int h=0;h<nRHO;h++){
1079  gB[h]->SetLineColor(4);
1080  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1081  }
1082  mg1B->Draw("al");
1083  cB->cd(2)->SetLogy();
1084  TMultiGraph* mg2B=new TMultiGraph();
1085  mg2B->SetTitle("cc=0.55;ANN;#Events");
1086  for (int h=0;h<nRHO;h++){
1087  gB[nRHO+h]->SetLineColor(4);
1088  if(gB[nRHO+h]->GetN()!=0) mg2B->Add(gB[nRHO+h]);
1089  }
1090  mg2B->Draw("al");
1091  cB->cd(3)->SetLogy();
1092  TMultiGraph* mg3B=new TMultiGraph();
1093  mg3B->SetTitle("cc=0.6;ANN;#Events");
1094  for (int h=0;h<nRHO;h++){
1095  gB[2*nRHO+h]->SetLineColor(4);
1096  if(gB[2*nRHO+h]->GetN()!=0) mg3B->Add(gB[2*nRHO+h]);
1097  }
1098  mg3B->Draw("al");
1099  cB->cd(4)->SetLogy();
1100  TMultiGraph* mg4B=new TMultiGraph();
1101  mg4B->SetTitle("cc=0.6;ANN;#Events");
1102  for (int h=0;h<nRHO;h++){
1103  gB[3*nRHO+h]->SetLineColor(4);
1104  if(gB[3*nRHO+h]->GetN()!=0) mg4B->Add(gB[3*nRHO+h]);
1105  }
1106  mg4B->Draw("al");
1107 
1108 
1109  //cout<<"dopo Draw()"<<endl;
1110  TString CnameS(name);
1111  TString CnameB(name);
1112  TString CnameSroot(name);
1113  TString CnameBroot(name);
1114  char CnameS2[1024];
1115  char CnameB2[1024];
1116  char CnameS2root[1024];
1117  char CnameB2root[1024];
1118  CnameS.ReplaceAll(".root",".png");
1119  CnameB.ReplaceAll(".root",".png");
1120  sprintf(CnameS2,"ANNthres_av/N_ANN_S_%s",CnameS.Data());
1121  sprintf(CnameB2,"ANNthres_av/N_ANN_B_%s",CnameB.Data());
1122  sprintf(CnameS2root,"ANNthres_av/N_ANN_S_%s",CnameSroot.Data());
1123  sprintf(CnameB2root,"ANNthres_av/N_ANN_B_%s",CnameBroot.Data());
1124  cS->SaveAs(CnameS2);
1125  cB->SaveAs(CnameB2);
1126  cS->Print(CnameS2root);
1127  cB->Print(CnameB2root);
1128  //cout<<"fine"<<endl;
1129 
1130 //CARTELLA Annth
1131 
1132 
1133 
1134 }
1135 
1136 
1138  TString name(ifile);
1139  name.ReplaceAll("outfile/","");
1140  name.ReplaceAll("average_file/","");
1141  TFile* fTEST =TFile::Open(ifile.Data());
1142  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1143  //double outbis;
1144  double av;
1145  double out;
1146  double cc;
1147  double rho;
1148  int nSi;
1149 // NNTree2->SetBranchAddress("ANNout",&out);
1150  NNTree2->SetBranchAddress("Average",&av);
1151  NNTree2->SetBranchAddress("cc",&cc);
1152  NNTree2->SetBranchAddress("rho",&rho);
1153  NNTree2->SetBranchAddress("#TestSig",&nSi);
1154  NNTree2->GetEntry(0);
1155  int const nSig=nSi;
1156  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1157  int const nBg=NNTree2->GetEntries()-nSig;
1158  cout<<"nBg: "<<nBg<<" Entries: "<<NNTree2->GetEntries()<<endl;
1159 
1160  TGraph * gS[3];
1161  TGraph * gB[3];
1162  gB[0]=new TGraph();
1163  gS[0]=new TGraph();
1164 // cout<<"nSig: "<<nSig<<endl;
1165  for (int n = 0; n <NNTree2->GetEntries(); n++){
1166  NNTree2->GetEntry(n);
1167  if(n<nSig) {
1168  gS[0]->SetPoint(n,cc,av);
1169  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1170  }
1171  else {
1172  gB[0]->SetPoint(n-nSig,cc,av);
1173  cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1174  }
1175  }
1176 
1177 
1178  /*for (int a=0;a<nBg;a++){
1179  if(aRHOB[a]>=RHOth){
1180  for (int b=0;b<nth;b++){
1181  if(aCCB[a]>=cc1th[b]){
1182  for(int c=0;c<nth+1;c++){
1183  if(aANNB[a]>=ANN1th[c]) Z[b*nth+c]=Z[b*nth+c]+1;
1184  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1185  }
1186  }
1187  }
1188  }
1189  }*/
1190  //gS[0]->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1191  //gB[0]->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1192  //gS[0]->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1193  //gB[0]->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1194  gS[0]->SetMarkerColor(2);
1195  gB[0]->SetMarkerColor(4);
1196  gS[0]->SetMarkerStyle(6);
1197  gB[0]->SetMarkerStyle(7);
1198 
1199  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1200  c->Divide(1,2);
1201  c->cd(1);
1202  TMultiGraph* mg1=new TMultiGraph();
1203  mg1->SetTitle("Av_cc");
1204  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1205  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1206  mg1->Draw("ap");
1207  mg1->GetHistogram()->GetXaxis()->SetTitle("cc");
1208  mg1->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1209 // mg1->Draw("ap");
1210  c->cd(2);
1211  TMultiGraph* mg2=new TMultiGraph();
1212  mg2->SetTitle("Av_cc");
1213  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1214  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1215  mg2->Draw("ap");
1216  mg2->GetHistogram()->GetXaxis()->SetTitle("cc");
1217  mg2->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1218 
1219  cout<<" name "<<name<<endl;
1220  TString Cname(name);
1221  TString Cnameroot(name);
1222  char Cname2[1024];
1223  char Cname2root[1024];
1224  Cname.ReplaceAll(".root",".png");
1225  sprintf(Cname2,"average_png/out_Plots_%s",Cname.Data());
1226  sprintf(Cname2root,"average_png/out_Plots_%s",Cnameroot.Data());
1227  c->SaveAs(Cname2);
1228  c->Print(Cname2root);
1229 /*
1230  TCanvas* c2=new TCanvas("Plots_Bkg_on_Sig","Plots_Bkg_on_Sig",0,0,1200,700);
1231  c2->Divide(2,2);
1232  c2->cd(1);
1233  gS[0]->Draw("ap");
1234  gB[0]->Draw("p,same");
1235 
1236  c2->cd(2);
1237  gS[1]->Draw("ap");
1238  gB[1]->Draw("p,same");
1239  c2->cd(3);
1240  gS[2]->Draw("ap");
1241  gB[2]->Draw("p,same");
1242  c2->cd(4);
1243  TText* text2=new TText(0.37,0.0,"no cuts on ANN");
1244  hglitch->SetStats(0);
1245  hglitch->GetXaxis()->SetTitle("cc");
1246  hglitch->GetYaxis()->SetTitle("ANNoutput");
1247  hglitch->GetZaxis()->SetTitle("count");
1248  hglitch->Draw("colz");
1249  text2->Draw();
1250  gPad->SetLogz();
1251 
1252  TString Cname_2(name);
1253  TString Cname_2root(name);
1254  char Cname2_2[1024];
1255  char Cname2_2root[1024];
1256  Cname_2.ReplaceAll(".root",".png");
1257  sprintf(Cname2_2,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2.Data());
1258  sprintf(Cname2_2root,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2root.Data());
1259  c2->SaveAs(Cname2_2);
1260  c2->Print(Cname2_2root);
1261 
1262 //CARTELLA CCi_RHO_ANN_Plots */
1263 }
1265  TString name(ifile);
1266  name.ReplaceAll("outfile/","");
1267  name.ReplaceAll("average_file/","");
1268  TFile* fTEST =TFile::Open(ifile.Data());
1269  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1270  //double outbis;
1271  double av;
1272  double out;
1273  double cc;
1274  double Mc;
1275  double rho;
1276  int nSi;
1277 // NNTree2->SetBranchAddress("ANNout",&out);
1278  NNTree2->SetBranchAddress("Mchirp",&Mc);
1279  NNTree2->SetBranchAddress("Average",&av);
1280  NNTree2->SetBranchAddress("cc",&cc);
1281  NNTree2->SetBranchAddress("rho",&rho);
1282  NNTree2->SetBranchAddress("#TestSig",&nSi);
1283  NNTree2->GetEntry(0);
1284  int const nSig=nSi;
1285  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1286  int const nBg=NNTree2->GetEntries()-nSig;
1287 
1288  TGraph * gS[3];
1289  TGraph * gB[3];
1290  gB[0]=new TGraph();
1291  gS[0]=new TGraph();
1292 // cout<<"nSig: "<<nSig<<endl;
1293  for (int n = 0; n <NNTree2->GetEntries(); n++){
1294  NNTree2->GetEntry(n);
1295  if(n<nSig) {
1296  gS[0]->SetPoint(n,Mc,av);
1297  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1298  }
1299  else {
1300  gB[0]->SetPoint(n-nSig,Mc,av);
1301  cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1302  }
1303  }
1304 
1305 
1306  /*for (int a=0;a<nBg;a++){
1307  if(aRHOB[a]>=RHOth){
1308  for (int b=0;b<nth;b++){
1309  if(aCCB[a]>=cc1th[b]){
1310  for(int c=0;c<nth+1;c++){
1311  if(aANNB[a]>=ANN1th[c]) Z[b*nth+c]=Z[b*nth+c]+1;
1312  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1313  }
1314  }
1315  }
1316  }
1317  }*/
1318  gS[0]->SetMarkerColor(2);
1319  gB[0]->SetMarkerColor(4);
1320  gS[0]->SetMarkerStyle(6);
1321  gB[0]->SetMarkerStyle(7);
1322 
1323  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1324  c->Divide(1,2);
1325  c->cd(1);
1326  TMultiGraph* mg1=new TMultiGraph();
1327  mg1->SetTitle("Av_Mc");
1328  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1329  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1330  mg1->Draw("ap");
1331  mg1->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1332  mg1->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1333  c->cd(2);
1334  TMultiGraph* mg2=new TMultiGraph();
1335  mg2->SetTitle("Av_Mc");
1336  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1337  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1338  mg2->Draw("ap");
1339  mg2->GetHistogram()->GetXaxis()->SetTitle("Mchirp");
1340  mg2->GetHistogram()->GetYaxis()->SetTitle("Average on ANN ouputs");
1341 
1342  cout<<" name "<<name<<endl;
1343  TString Cname(name);
1344  TString Cnameroot(name);
1345  char Cname2[1024];
1346  char Cname2root[1024];
1347  Cname.ReplaceAll(".root",".png");
1348  sprintf(Cname2,"average_png/Mc_Plots_%s",Cname.Data());
1349  sprintf(Cname2root,"average_png/Mc_Plots_%s",Cnameroot.Data());
1350  c->SaveAs(Cname2);
1351  c->Print(Cname2root);
1352 }
char ofile[1024]
double rho
void graph(TString ifile)
Definition: Average.C:561
Float_t * rho
biased null statistics
Definition: netevent.hh:112
wavearray< double > a(hp.size())
par [0] name
int n
Definition: cwb_net.C:28
TString("c")
#define nRHO
Definition: Average.C:43
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
STL namespace.
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)
Definition: Average.C:65
int j
Definition: cwb_net.C:28
#define deltaANN
Definition: Average.C:45
i drho i
wavearray< double > hh
Definition: Regression_H1.C:73
void PlotsAv_Mc(TString ifile)
Definition: Average.C:1264
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
#define nCC
Definition: Average.C:46
wavearray< double > h
Definition: Regression_H1.C:25
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
char output[256]
int k
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:113
TFile * ifile
void PlotsAv_cc(TString ifile)
Definition: Average.C:1137
wavearray< double > yy
Definition: TestFrame5.C:12
#define nANN
Definition: Average.C:44
s s
Definition: cwb_net.C:155
void Annth(TString ifile)
Definition: Average.C:884
#define deltarho
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
#define iMc
Definition: Average.C:52
Int_t GetEntries()
Definition: netevent.cc:403
for(int i=0;i< 101;++i) Cos2[2][i]=0
pointers to detectors
#define nIFO
Definition: Average.C:42
wavearray< double > y
Definition: Test10.C:31
#define deltacc
Float_t * chirp
range to source: [0/1]-rec/inj
Definition: netevent.hh:128
exit(0)