Logo coherent WaveBurst  
Library Reference Guide
Logo
Fisher_1.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 3
53 using namespace std;
54 void Fisher_ex(TString ifile, int nFs, int nFb, int Fs, int Fb);
56 //void Annth(TString ifile);
59 
60 
61 //uf !=0 means the Test file of events is the same used for train the network, ni==0 select the event used for the training, in this way we test the events alway for NNn-1 network, if ni!=0 also the events not used for the training are considered and there the average in made on all the nNN network
62 void Fisher_1(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 nFs, int nFb, int Fs=0, int Fb=0,int TS=0, int TB=0, int s=0, int b=0, int uf=1, int ni=0){
63 if(uf==0) ni=1;
64 int n_NN=0;
65 if (NN_FILE.CompareTo("")){
66  n_NN=n_NN+1;
67  }
68 if (NN_FILE2.CompareTo("")){
69  n_NN=n_NN+1;
70  }
71 if (NN_FILE3.CompareTo("")){
72  n_NN=n_NN+1;
73  }
74 if (NN_FILE4.CompareTo("")){
75  n_NN=n_NN+1;
76  }
77 if (NN_FILE5.CompareTo("")){
78  n_NN=n_NN+1;
79  }
80 if (NN_FILE6.CompareTo("")){
81  n_NN=n_NN+1;
82  }
83 if (NN_FILE7.CompareTo("")){
84  n_NN=n_NN+1;
85  }
86 if (NN_FILE8.CompareTo("")){
87  n_NN=n_NN+1;
88  }
89 int const nNN=n_NN;
90 
91 // int p=0;
92  char NNi[nNN][1024];
93  char NNi2[nNN][1024];
94  sprintf(NNi2[0],"%s",NN_FILE.Data());
95  if(nNN>1) sprintf(NNi2[1],"%s",NN_FILE2.Data());
96  if(nNN>2) sprintf(NNi2[2],"%s",NN_FILE3.Data());
97  if(nNN>3) sprintf(NNi2[3],"%s",NN_FILE4.Data());
98  if(nNN>4) sprintf(NNi2[4],"%s",NN_FILE5.Data());
99  if(nNN>5) sprintf(NNi2[5],"%s",NN_FILE6.Data());
100  if(nNN>6) sprintf(NNi2[6],"%s",NN_FILE7.Data());
101  if(nNN>7) sprintf(NNi2[7],"%s",NN_FILE8.Data());
102  for (int u=0;u<nNN;u++){
103  int p=0;
104  while (NNi2[u][p]){
105  //cout<<NNi2[p]<<endl;
106  if (NNi2[u][p]=='N'){
107 // cout<<p<<endl;
108  if((NNi2[u][p+1]=='N')&&(NNi2[u][p+2]=='\/')) {
109 // cout<<" dentro if"<<endl;
110  int hh=p+3;
111  while (NNi2[u][hh]!='\0'){NNi[u][hh-p-3]=NNi2[u][hh];hh=hh+1;}
112  break;
113  }
114  }
115  p=p+1;
116  }
117 }
118  int q=0;
119  char Filei[1024];
120  char Filei2[1024];
121  sprintf(Filei2,"%s",TEST_FILE.Data());
122  while (Filei2[q]){
123  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]=='\/')) {
124  int hh=q+7;
125  while (Filei2[hh]!='\0') {Filei[hh-q-7]=Filei2[hh];hh=hh+1;
126  }
127  for (int h0=hh-q-7;h0<1024;h0++) Filei[h0]='\0';
128  break;
129  }
130  q=q+1;
131  }
132 
133  cout<<Filei<<" original String: "<<Filei2<<endl;
134 
135 
136  TString NNi0[nNN];
137  NNi0[0]=NNi[0];
138  if(nNN>1) NNi0[1]=NNi[1];
139  if(nNN>2) NNi0[2]=NNi[2];
140  if(nNN>3) NNi0[3]=NNi[3];
141  if(nNN>4) NNi0[4]=NNi[4];
142  if(nNN>5) NNi0[5]=NNi[5];
143  if(nNN>6) NNi0[6]=NNi[6];
144  if(nNN>7) NNi0[7]=NNi[7];
145  TString Filei0(Filei);
146 cout<<"NN"<<endl;
147 int min_NNb=5000000;
148  for (int u=0;u<nNN;u++){
149  NNi0[u].ReplaceAll(".root","");
150  }
151  Filei0.ReplaceAll(".root","");
152 
153  TFile *fnet[nNN];
154  TMultiLayerPerceptron* mlp[nNN];
155  TTree* infot[nNN];
156  int NNs[nNN];
157  int NNb[nNN];
158  int NNnTS[nNN];
159  int NNnTB[nNN];
160  for (int u=0;u<nNN;u++){
161  fnet[u]=TFile::Open(NNi2[u]);
162  cout<<NNi2[u]<<endl;
163  cout<<"dopo file"<<endl;
164  mlp[u]=(TMultiLayerPerceptron*)fnet[u]->Get("TMultiLayerPerceptron");
165 
166  cout<<"dopo TMLP"<<endl;
167  if(mlp[u]==NULL) {cout << "Error getting mlp" << endl;exit(1);}
168  infot[u]=(TTree*)fnet[u]->Get("info");
169  infot[u]->SetBranchAddress("Rand_start_Sig",&NNs[u]);
170  infot[u]->SetBranchAddress("Rand_start_Bg",&NNb[u]);
171  infot[u]->SetBranchAddress("#trainSig",&NNnTS[u]);
172  infot[u]->SetBranchAddress("#trainBg",&NNnTB[u]);
173  infot[u]->GetEntry(0);
174  if(NNb[u]<min_NNb) min_NNb=NNb[u];
175  cout<<"n "<<u<<" b "<<NNb[u]<<" min_NNb "<<min_NNb<<endl;
176 
177  cout<<"da Tree"<<endl;
178  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;
179  }
180 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;}
181 //exit(0);
182 cout<<"Def. tree e mlp"<<endl;
183  TFile* fTEST =TFile::Open(TEST_FILE.Data());
184  TTree* NNTree=(TTree*)fTEST->Get("nnTree");
185  int entries=NNTree->GetEntries();
186  cout<<"entries: "<<entries<<endl;
187 
188 //estraggo le info che servono anche al tree di def dell'mlp
189  int ndim;
190  int ninp;
191  int y;
192  int entriesTot;
193  int bg_entries;
194  int sig_entries;
195 
196  NNTree->SetBranchAddress("#Entries_type",&entriesTot);
197  NNTree->SetBranchAddress("Matrix_dim",&ndim);
198  NNTree->SetBranchAddress("#inputs",&ninp);
199  NNTree->SetBranchAddress("amplitude_mode",&y);
200 
201  NNTree->GetEntry(0);
202  sig_entries=entriesTot;
203  NNTree->GetEntry(entries-1);
204  bg_entries=entriesTot;
205 
206  int const NDIM=ndim;
207  int const nINP=ninp;
208 
209  cout<<"NDIM "<<NDIM<<endl;
210  cout<<"nINP"<<nINP<<endl;
211  cout<<"sig e "<<sig_entries<<endl;
212  cout<<"bg e "<<bg_entries<<endl;
213  int minevents=0;
214  if (sig_entries>bg_entries) minevents=bg_entries;
215  else minevents=sig_entries;
216 
217  if(b==0) b=sig_entries;
218  if(TB==0 && TS==0){
219  TS=minevents;
220  TB=minevents;
221  }
222  if (b<sig_entries){
223  cout<<"Error: Bg index<sig_entries"<<endl;
224  exit(0);
225  }
226  if((TS>sig_entries||TB>bg_entries)&&(TS==TB)) {TS=minevents-s;TB=minevents-b+sig_entries;}
227  if((TS>sig_entries||TB>bg_entries)&&(TS!=TB)) {TS=sig_entries-s;TB=bg_entries-b+sig_entries;}
228 
229 
230  char NOMEtot[1024];
231  sprintf(NOMEtot,"%s",NOMEtot_S.Data());
232  cout<<"nome: "<<NOMEtot<<endl;
233 
234  TString SIG_FILE;
235  TString BG_FILE;
236  char FILE_NAME[516];
237  NNTree->SetBranchAddress("Files_name",&FILE_NAME);
238  NNTree->GetEntry(0);
239  SIG_FILE=FILE_NAME;
240  NNTree->GetEntry(entries-1);
241  BG_FILE=FILE_NAME;
242  cout<<"fine ifdef RHO_CC"<<endl;
243 
244  TChain sigTree("waveburst");//cerca il Tree "waveburst nei file
245  sigTree.Add(SIG_FILE.Data());//determina i file
246  netevent signal(&sigTree,nIFO);
247  int sig_entries2 = signal.GetEntries();
248  cout << "sig entries2 : " << sig_entries2 << endl;
249 
250  TChain bgTree("waveburst");
251  bgTree.Add(BG_FILE.Data());
252  netevent background(&bgTree,nIFO);
253  int bg_entries2 = background.GetEntries();
254  cout << "bg entries2 : " << bg_entries2 << endl;
255 
256  cout<<"b: "<<b<<endl;
257  cout<<"s: "<<s<<endl;
258 
259  // add leaf
260  Float_t x[nINP];
261  for (int jj=0; jj<nINP;jj++) x[jj]=0.;
262  char ilabel[nINP][16];
263 
264  //costruzione una foglia per ogni input
265  for(int i=0;i<nINP;i++) {
266  sprintf(ilabel[i],"x%i",i+1);
267  NNTree->SetBranchAddress(ilabel[i], &x[i]);
268  }
269 
270 char ofile[1024];
271 sprintf(ofile,"average_file/%s.root",NOMEtot);
272 TFile*f =new TFile(ofile,"RECREATE");
273  TTree* NNTree2=new TTree("Parameters","Parameters");
274  NNTree2->SetDirectory(f);
275  double average=0.;
276  double out[nNN];
277  for(int y=0; y<nNN; y++) out[y]=0.;
278  double Mc=0.;
279  double NNcc=0.;
280  double NNrho=0.;
281  double std=0.;
282  NNTree2->Branch("Average",&average,"Average/D");
283  NNTree2->Branch("StandardDevaition",&std,"StandardDeviation/D");
284  NNTree2->Branch("cc",&NNcc,"cc/D");
285  NNTree2->Branch("Mchirp",&Mc,"Mchirp/D");
286  NNTree2->Branch("rho",&NNrho,"rho/D");
287  for(int u=0;u<nNN;u++){
288  char NNoutl[512];
289  char NNoutl2[512];
290  char NNnamel[512];
291  char NNnamel2[512];
292  sprintf(NNoutl,"NNout%i",u);
293  sprintf(NNoutl2,"NNout%i/D",u);
294  sprintf(NNnamel,"NNname%i",u);
295  sprintf(NNnamel2,"NNname%i/C",u);
296  NNTree2->Branch(NNoutl,&out[u],NNoutl2);
297  NNTree2->Branch(NNnamel,&NNi[u],NNnamel2);}
298  char Testf[1024];
299  NNTree2->Branch("TestFile",&Testf,"TestFile/C");
300  sprintf(Testf,"%s",TEST_FILE.Data());
301  int nTestS=0;
302  NNTree2->Branch("#TestSig",&nTestS,"#TestSig/I");
303  cout<<"nTestS: "<<nTestS<<" TS: "<<TS<<endl;
304  cout<<"dopo def tree"<<endl;
305 int scount=0;
306  if(uf==0) nTestS=TS;
307  else {
308 for(int n=s;n<s+TS;n++) {
309  int countNN=0;
310  for(int u=0;u<nNN;u++){
311  if (uf!=0&&n>=NNs[u]&&n<(NNs[u]+NNnTS[u])) countNN=countNN+1;
312  }
313  //if(nNN==1){ni=1;cout<<"out==Averege:only 1NN is considered"<<endl;}
314  if(countNN==1&&ni==0) scount=scount+1;
315  if(countNN<2&&ni!=0) scount=scount+1;
316  if(countNN>1){cout<<"Error: training non independent"; exit(0);}
317  }
318 nTestS=scount;
319 }
320 
321 cout<<"s test "<<s<< " s+TS "<<s+TS<<" b "<<b<<" b+ TB "<<b+TB<<" nTestS "<<nTestS<<endl;
322 //exit(0);
323  double params[nINP];
324  int sig_05=0;
325  for (int i=0; i<nINP; i++) params[i]=0.;
326  //for(int n=0;n<entryS.GetEntries();n++) {
327 
328  int S_eff=0;
329  int TD=0;
330  for(int n=s;n<s+TS;n++) {
331  average=0.;
332  int indNN=-1;
333  int countNN=0;
334  for(int u=0;u<nNN;u++){
335  if (uf!=0&&n>=NNs[u]&&n<(NNs[u]+NNnTS[u])) { indNN=u;countNN=countNN+1;}
336  }
337  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
338  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
339  if(ni==0&&countNN==0)continue;
340  NNTree->GetEntry(n);
341  signal.GetEntry(n);
342  NNcc=(double)signal.netcc[1];
343  NNrho=(double)signal.rho[0];
344  Mc=(double)signal.chirp[iMc];
345  for (int i=0; i<nINP; i++){
346  params[i]=x[i];
347  }
348  for (int u=0;u<nNN;u++) {
349  double output=mlp[u]->Evaluate(0,params);
350  cout<<output<<endl;
351  out[u]=output;
352  }
353  for (int u=0;u<nNN;u++){
354  if((u!=indNN&&ni==0)||ni!=0) {average=out[u]+average;std+=out[u]*out[u];}
355  }
356  //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);}
357  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);}
358  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);}
359  cout<<"average: "<<average<<endl;
360  // cout<<"Mc "<<Mc<<endl;
361  if (average<0.6) TD=TD+1;
362  //if (outbis<0.5) sig_05=sig_05+1;
363  //if (outbis>0.5&&outbis<0.6) if(out<0.1) sig_05=sig_05+1;
364  // if (outbis<0.5 || out<0.5) sig_05=sig_05+1;
365  //if (outbis<0.6) sig_05=sig_05+1;
366  // cout<<"rho: "<<signal.rho[0]<<" cc "<<signal.netcc[1]<<" out: "<<out<<" outbis "<<outbis<<endl;
367  NNTree2->Fill();
368  S_eff=S_eff+1;
369  }
370 int B_eff=0;
371 int FA=0;
372 cout<<"riempito sig"<<endl;
373 int bg_05=0;
374 cout<<"b "<<b<<" TB "<<TB<<endl;
375 //for(int n=b;n<b+TB;n++) {
376 //for(int u=0;u<nNN;u++){
377  // cout<<" u "<<u<<" NN b[u] "<<NNb[u]<<" NNnTB[u] "<<NNnTB[u]<<" NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
378  // }
379 //}
380 //exit(0);
381 cout<<" prima ciclo fro bg"<<endl;
382  //for(int n=sig_entries+b;n<sig_entries+b+TB;n++) {
383  for(int n=b;n<b+TB;n++) {
384  cout<<n<<endl;
385  average=0.;
386  int indNN=-1;
387  int countNN=0;
388  for(int u=0;u<nNN;u++){
389  cout<<" uf "<<uf<<" n "<<n<<" u "<<u<<" NN b[u] "<<NNb[u]<<" (primo non preso) NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
390  if (uf!=0&&n>=NNb[u]&&n<(NNb[u]+NNnTB[u])) { indNN=u;countNN=countNN+1;
391  // cout<<"n "<<n<<" u "<<u<<" NN b[u] "<<NNb[u]<<" (primo non preso)NNb[u]+NNnTB[u]"<<NNb[u]+NNnTB[u]<<endl;
392  }
393  }
394  if (countNN>1){cout<<"Error: training non independent"; exit(0);}
395  if(nNN==1){cout<<"out==Averege:only 1NN is considered"<<endl;}
396  if(ni==0&&countNN==0){
397  cout<<"countNN"<<countNN<<endl;
398  continue;}
399  //if (uf!=0&&(n>=NNb&&n<=(NNb+NNnTB) || n>=NNbbis&&n<=(NNbbis+NNnTBbis))) continue;
400  NNTree->GetEntry(n);
401  cout<<"n: "<<n<<"Bg index"<<(n-sig_entries)<<endl;
402  background.GetEntry(n-sig_entries);
403  NNcc=(double)background.netcc[1];
404  NNrho=(double)background.rho[0];
405  Mc=(double)background.chirp[iMc];
406  for (int i=0; i<nINP; i++){
407  //x[i]=(*frameS)[i];
408  params[i]=x[i];
409  }
410 
411  for(int u=0;u<nNN;u++) {
412  double output=mlp[u]->Evaluate(0,params);
413  cout<<output<<endl;
414  out[u]=output;
415  }
416  for (int u=0;u<nNN;u++){
417  if((u!=indNN&&ni==0)||ni!=0) { average=out[u]+average;std=out[u]*out[u];}
418  }
419  if(nNN!=1&&ni==0) {cout<<average<<endl;average=average/(nNN-countNN);
420 //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);}
421 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);}
422 
423  //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;}
424  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;}
425  cout<<"average: "<<average<<" nNN-1-countNN "<<nNN-1-countNN<<endl;
426  if(average>0.6) FA=FA+1;
427 /* d uble output=mlp->Evaluate(0,params);
428  out=output;
429  double outputbis=mlpbis->Evaluate(0,params);
430  outbis=outputbis;*/
431 // if(outbis>0.6) bg_05=bg_05+1;
432 // if(outbis<=0.6&&outbis>0.5) if(out>0.1)bg_05=bg_05+1;
433 
434 // if(outbis>0.5 && out>0.5) bg_05=bg_05+1;
435  //if(outbis>0.6) bg_05=bg_05+1;
436 
437 // cout<<"rho: "<<background.rho[0]<<" cc "<<background.netcc[1]<<" out: "<<out<<endl;
438  NNTree2->Fill();
439  B_eff=B_eff+1;
440  }
441 cout<<"riempito bg"<<endl;
442 //TFile*f0 =new TFile(ofile,"RECREATE");
443 //NNTree2->SetDirectory(f0);
444 NNTree2->Write();
445 f->Close();
446 //f0->Close();
447 cout<<"chiuso file"<<endl;
448 
449 
450 //graph(ofile.Data());
451 //graph(ofile);
452 cout<<ofile<<endl;
453 cout<<"dopo richiamo funzione"<<endl;
454 Fisher_ex(ofile,nFs,nFb,Fs,Fb);
455 //Annth(ofile);
456 //exit(0);
457 graph_Fish(ofile);
458 //PlotsAv_cc(ofile);
459 //PlotsAv_Mc(ofile);
460 cout<<" S_eff "<<S_eff<<" B_eff "<<B_eff<<endl;
461 cout<<" FA>0.6 "<<FA<<" TD<0.6 "<<TD<<" FA/tot_BG "<<FA/B_eff<<" TD/tot_S "<<TD/S_eff<<endl;
462 //cout<<" Sig with out<06: "<<sig_05<<endl;
463 //cout<<" Bg with double threshold "<<bg_05<<endl;
464 }
465 
466 
467 void Fisher_ex(TString ifile, int nFs, int nFb, int Fs, int Fb){
468 
469 
470 TString name(ifile);
471  name.ReplaceAll("average_file/","");
472  TFile* fTEST =TFile::Open(ifile.Data());
473  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
474  double av;
475  double cc;
476  int nSi;
477  NNTree2->SetBranchAddress("Average",&av);
478  NNTree2->SetBranchAddress("cc",&cc);
479  NNTree2->SetBranchAddress("#TestSig",&nSi);
480  NNTree2->GetEntry(0);
481 
482 //INIZIO DISCRIMINAZIONE FISHER
483 
484 double qS_o=0.;
485 double qS_c=0.;
486 double sS_co=0.;
487 double mS_o=0.;
488 double mS_c=0.;
489 double mB_o=0.;
490 double mB_c=0.;
491 double qB_c=0.;
492 double qB_o=0.;
493 double sB_co=0.;
494 
495 if (nFs+Fs>nSi){ Fs=0; if(nFs>nSi) nFs=nSi; cout<<" change: Fs "<<Fs<<" nFs "<<nFs<<endl;}
496 if(Fb==0)Fb=nSi;
497 if (Fb<nSi) {Fb=nSi+Fb; cout<<" change: Fb "<<Fb<<endl;}
498 
499 for(int n=Fs; n<Fs+nFs;n++){
500  NNTree2->GetEntry(n);
501  mS_o+=av;
502  mS_c+=cc;
503  qS_o+=av*av;
504  qS_c+=cc*cc;
505  sS_co=av*cc;
506 
507 }
508 mS_o=mS_o/nFs;
509 mS_c=mS_c/nFs;
510 
511 int const TOTent=NNTree2->GetEntries();
512 int const nBg=NNTree2->GetEntries()-nSi;
513 cout<<"nSi "<<nSi<<" nBg "<<nBg<<" entries "<<TOTent<<endl;
514 
515 if (nFb+Fb>TOTent){ Fb=nSi; if(nFs>nBg) nFb=nBg; cout<<" change: Fb "<<Fb<<" nFb "<<nFb<<endl;}
516 
517 for(int n=Fb; n<Fb+nFb;n++){
518  NNTree2->GetEntry(n);
519  mB_o+=av;
520  mB_c+=cc;
521  qB_o+=av*av;
522  qB_c+=cc*cc;
523  sB_co=av*cc;
524 
525 }
526 mB_o=mB_o/nFb;
527 mB_c=mB_c/nFb;
528 
529 //ELEMENTS OF WITHIN MATRIX
530 double a_s=0.;
531 double b_s=0.;
532 double d_s=0.;
533 double a_b=0.;
534 double b_b=0.;
535 double d_b=0.;
536 
537 a_b=qB_c-nFb*(mB_c*mB_c);
538 d_b=qB_o-nFb*(mB_o*mB_o);
539 b_b=sB_co-nFb*(mB_c*mB_o);
540 
541 cout<<"a_b "<<a_b<<endl;
542 cout<<"d_b "<<d_b<<endl;
543 cout<<"a_s "<<a_s<<endl;
544 cout<<"d_s "<<d_s<<endl;
545 a_s=qS_c-nFs*(mS_c*mS_c);
546 d_s=qS_o-nFs*(mS_o*mS_o);
547 b_s=sS_co-nFs*(mS_c*mS_o);
548 
549 
550 double a=0.;
551 double b=0.;
552 double d=0.;
553 
554 a=a_b+a_s;
555 b=b_b+b_s;
556 d=d_b+d_s;
557 
558 //ELEMENT OF THE INVERSE WITHIN MATRIX
559 
560 double det=0.;
561 double a_i=0.;
562 double b_i=0.;
563 double d_i=0.;
564 
565 det=a*d-b*b;
566 cout<<"ca standard deviation cc bg "<<pow(a_b/nFb,0.5)<<" ca standard deviation out bg "<<pow(d_b/nFb,0.5)<<" det "<<det<<" media cc bg "<<mB_c<<" media out bg "<<mB_o<<endl;
567 cout<<"ca standard deviation cc sig "<<pow(a_s/nFs,0.5)<<" ca standard deviation out sig "<<pow(d_s/nFs,0.5)<<" det "<<det<<" media cc sig "<<mS_c<<" media out sig "<<mS_o<<endl;
568 if(det==0){cout<<"Problem: det==0"<<endl;exit(0);}
569 a_i=d/det;
570 b_i=-b/det;
571 d_i=a/det;
572 
573 //DIFFERENCES OF THE AVERAGES
574 double dm_o=0.;
575 double dm_c=0.;
576 dm_c=mS_c-mB_c;
577 dm_o=mS_o-mB_o;
578 cout<<" a_i "<<a_i<<" d_i "<<d_i<<" b_i "<<b_i<<" dm_c "<<dm_c<<" dm_o "<<dm_o<<endl;
579 //w1 and w2
580 double w_c=0.;
581 double w_o=0.;
582 w_c=a_i*dm_c+b_i*dm_o;
583 w_o=b_i*dm_c+d_i*dm_o;
584 
585 //FINDING THE THRESHOLD
586 TGraph *ms=new TGraph();
587 TGraph *mb=new TGraph();
588 TGraph *pg=new TGraph();
589 TGraph *g=new TGraph();
590 TGraph *g0=new TGraph();
591 TGraph *g1=new TGraph();
592 int count=0;
593 double w0=0.;
594 for(int n=Fs; n<Fs+nFs;n++){
595  NNTree2->GetEntry(n);
596 // w0*=-(w_c*cc+w_o*av);
597  cout<<" sig"<<n<<" "<<w_c*cc+w_o*av<<endl;
598  g0->SetPoint(count,cc,av);
599  count=count+1;
600 
601 }
602 cout<<"count sig "<<count<<endl;
603 count=0;
604 /*for(int n=Fb; n<Fb+nFb;n++){
605  NNTree2->GetEntry(n);
606  // w0+=-(w_c*cc+w_o*av);
607 count=0;*/
608 for(int n=Fb; n<Fb+nFb;n++){
609  NNTree2->GetEntry(n);
610  // w0+=-(w_c*cc+w_o*av);
611  cout<<" bg"<<n<<" "<<w_c*cc+w_o*av<<endl;
612  g1->SetPoint(count,cc,av);
613  count=count+1;
614 }
615 double mb0=w_c*(mB_c)+w_o*(mB_o);
616 mb0=mb0/2;
617 
618 double ms0=w_c*(mS_c)+w_o*(mS_o);
619 ms0=ms0/2;
620 
621 w0=w_c*(mS_c+mB_c)+w_o*(mS_o+mB_o);
622 cout<<" mS_c+mB_c "<<mS_c+mB_c<<" mS_o+mB_o "<<mS_o+mB_o<<endl;
623 w0=w0/2.;
624 cout<<" count bg "<<count<<endl;
625 double x_ms=0.;
626 double y_ms=0.;
627 double x_mb=0.;
628 double y_mb=0.;
629 double x_thres=0.;
630 double y_thres=0.;
631 /*x_mb=pow(mb0*mb0/(1+(w_c*w_c/(w_o*w_o))),0.5);
632 y_mb=-w_c/w_o*x_mb;
633 x_ms=pow(ms0*ms0/(1+(w_c*w_c/(w_o*w_o))),0.5);
634 y_ms=-w_c/w_o*x_ms;*/
635 x_thres=pow(w0*w0/(1+(w_c*w_c/(w_o*w_o))),0.5);
636 y_thres=-w_c/w_o*x_thres;
637 pg->SetPoint(0,x_thres,y_thres);
638 TF1 retta_ms("retta_p","[1]*x+[0]",-0.5,1.);
639 TF1 retta_mb("retta","[1]*x+[0]",-0.5,1.);
640 TF1 retta_p("retta_p","[1]*x+[0]",-0.5,1.);
641 TF1 retta("retta","[1]*x+[0]",-0.5,1.);
642 retta.SetParameter(0,0.);
643 double c_ang=0.;
644 c_ang=-w_c/w_o;
645 retta.SetParameter(1,c_ang);
646 double c_ang_p=-1./c_ang;
647 retta_p.SetParameter(1,c_ang_p);
648 double q_p=0.;
649 q_p=(mS_o+mB_o)/2.-c_ang_p*(mS_c+mB_c)/2.;
650 //q_p=y_thres-c_ang_p*x_thres;
651 retta_p.SetParameter(0,q_p);
652 retta_ms.SetParameter(1,c_ang_p);
653 double q_ms=0.;
654 //q_ms=y_ms-c_ang_p*x_ms;
655 q_ms=mS_o-c_ang_p*mS_c;
656 retta_ms.SetParameter(0,q_ms);
657 retta_mb.SetParameter(1,c_ang_p);
658 double q_mb=0.;
659 //q_mb=y_mb-c_ang_p*x_mb;
660 q_mb=mB_o-c_ang_p*mB_c;
661 retta_mb.SetParameter(0,q_mb);
662 cout<<"q_mb "<<q_mb<<" q_ms "<<q_ms<<" mS_o "<<mS_o<<" mS_c"<<mS_c<<" mB_o "<<mB_o<<" mB_c"<<mB_c<<endl;
663 cout<<" wc "<<w_c<<" w_o "<<w_o<<" coef ang "<<c_ang<<" x_thres "<<x_thres<<" y_thres "<<y_thres<<" w0 "<<w0<<" q_p "<<q_p<<" c_ang_p"<<c_ang_p<<endl;
664 TCanvas *canv=new TCanvas("reg_wErr_woErr_media","reg_wErr_woErr_media",0,0,600,400);
665 g1->SetMarkerStyle(6);
666 g1->SetMarkerColor(4);
667 g0->SetMarkerStyle(7);
668 g0->SetMarkerColor(2);
669 g->SetPoint(0,1,1.3);
670 g->SetPoint(1,-0.3,-0.3);
671 g->SetMarkerColor(10);
672 g->Draw("ap");
673 g0->Draw("p,same");
674 g1->Draw("p,same");
675 pg->SetMarkerStyle(29);
676 pg->SetMarkerColor(1);
677 retta_ms.SetLineColor(3);
678 retta_mb.SetLineColor(3);
679 retta_p.SetLineColor(6);
680 retta_ms.Draw("same");
681 retta_mb.Draw("same");
682 retta_p.Draw("same");
683 retta.SetLineColor(1);
684 retta.Draw("same");
685 //retta.Draw("al");
686 char nomec[1024];
687 char nomecroot[1024];
688 sprintf(nomec,"Fisher_png/%s_.png",name.Data());
689 sprintf(nomecroot,"Fisher_png/%s_.root",name.Data());
690 canv->SaveAs(nomec);
691 canv->SaveAs(nomecroot);
692 canv->Close();
693 fTEST->Close();
694 
695 TString NOMEtot(ifile);
696 NOMEtot.ReplaceAll("average_file/","");
697 NOMEtot.ReplaceAll(".root","");
698 char namefF[1024];
699 sprintf(namefF,"Fisher_file/%s_Fisher.root",NOMEtot.Data());
700 cout<<" namefF "<<namefF<<" NOMEtot "<<NOMEtot.Data()<<endl;
701 TFile* Fishf =new TFile(namefF,"RECREATE");
702  TTree* TreeFis=new TTree("Fisher_Discriminant","Fisher_Discriminant");
703  TreeFis->SetDirectory(Fishf);
704  double wc=0.;
705  double wo=0.;
706  TreeFis->Branch("Fish_coef_cc",&wc,"Fish_coef_cc/D");
707  TreeFis->Branch("Fish_coef_ANNout",&wo,"Fish_coef_ANNout/D");
708  TreeFis->Branch("nFs",&nFs,"nFs/I");
709  TreeFis->Branch("nFb",&nFb,"nFb/I");
710  TreeFis->Branch("Fb_start",&Fb,"Fb_start/I");
711  TreeFis->Branch("Fs_start",&Fs,"Fs_start/I");
712  char nomeif[2048];
713  sprintf(nomeif,"%s",ifile.Data());
714  TreeFis->Branch("File_name",&nomeif,"File_name/C");
715 
716  wo=w_o;
717  wc=w_c;
718  TreeFis->Fill();
719  cout<<" wc "<<wc<<" wo "<<wo<<endl;
720  cout<<" entries "<<TreeFis->GetEntries()<<endl;
721  TreeFis->Write();
722 
723 Fishf->Close();
724 
725 }
726 
727 
729  TString name(ifile);
730  name.ReplaceAll("average_file/","Fisher_file/");
731  TFile* fTEST =TFile::Open(ifile.Data());
732  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
733 
734  double w_o;
735  double w_c;
736  int nFs;
737  int nFb;
738  int Fs;
739  int Fb;
740 
741  TString namefF(name);
742  namefF.ReplaceAll(".root","_Fisher.root");
743  TFile* fF =TFile::Open(namefF.Data());
744  TTree* FTree= (TTree*)fF->Get("Fisher_Discriminant");
745  FTree->SetBranchAddress("Fs_start",&Fs);
746  FTree->SetBranchAddress("Fb_start",&Fb);
747  FTree->SetBranchAddress("nFs",&nFs);
748  FTree->SetBranchAddress("nFb",&nFb);
749  FTree->SetBranchAddress("Fish_coef_cc",&w_c);
750  FTree->SetBranchAddress("Fish_coef_ANNout",&w_o);
751  FTree->GetEntry(0);
752  double w_i=0.;
753  int ind=0;
754  FTree->Branch("w_i",&w_i,"w_i/D");
755  FTree->Branch("index",&ind,"index/I");
756 
757  //fF->Close();
758  name.ReplaceAll("Fisher_file/","");
759 
760  double av;
761  double cc;
762  double rho;
763  int nSi;
764  NNTree2->SetBranchAddress("Average",&av);
765  NNTree2->SetBranchAddress("cc",&cc);
766  NNTree2->SetBranchAddress("rho",&rho);
767  NNTree2->SetBranchAddress("#TestSig",&nSi);
768  NNTree2->GetEntry(0);
769 
770  int const nSig=nSi;
771  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
772  cout<<" BG: "<<NNTree2->GetEntries()-nSi<<endl;
773  int nBgi=NNTree2->GetEntries()-nSi;
774  double minw_i=10000000;
775  double maxw_i=0.;
776 
777  for(int u=0;u<nSi;u++ ){
778  if (u>=Fs&&u<(Fs+nFs))continue;
779  ind=u;
780  NNTree2->GetEntry(u);
781  cout<<" u "<<u<<endl;
782  w_i=w_c*cc+w_o*av;
783  FTree->Fill();
784  if(w_i<minw_i)minw_i=w_i;
785  if(w_i>maxw_i)maxw_i=w_i;
786  }
787  int const nSigF=FTree->GetEntries();
788  cout<<" nSigF "<<nSigF<<endl;
789  for(int u=nSi;u<nSi+nBgi;u++ ){
790  if (u>=Fb&&u<(Fb+nFb))continue;
791  ind=u;
792  NNTree2->GetEntry(u);
793  cout<<" u "<<u<<endl;
794  w_i=w_c*cc+w_o*av;
795  FTree->Fill();
796  if(w_i<minw_i)minw_i=w_i;
797  if(w_i>maxw_i)maxw_i=w_i;
798  }
799 
800  cout<<"F Entries "<<FTree->GetEntries()<<endl;
801 
802  double deltaw=0.;
803  deltaw=(maxw_i-minw_i)/50.;
804  TH1D *hbg=new TH1D("Hbg", "projection[0]", 50, minw_i-deltaw, maxw_i+ deltaw);
805  TH1D *hsig=new TH1D("Hsig", "projection[0]", 50, minw_i-deltaw, maxw_i+deltaw);
806  hsig->SetDirectory(0);
807  hbg->SetDirectory(0);
808 
809 
810 
811  for( int u=0; u<FTree->GetEntries()-1;u++){ // //-1 perchèxk hai tot c'è in npiù l'uno da Fisher_ex: i nuovi branches ripartono da zero
812  FTree->GetEntry(u);
813  cout<<" u "<<u<<" ind "<<ind<<" w_i "<<w_i<<" nSigF-1 "<<nSigF-1<<endl;
814  if(u<nSigF-1) hsig->Fill(w_i);
815  else hbg->Fill(w_i);
816  }
817 
818 //exit(0);
819 //Efficiency_vs_rho","Efficiency_vs_rho",0,0,1200,700
820  TCanvas *c_histo= new TCanvas("Histogram_Fisher", "Histogram_Fisher", 0,0,900,600);
821  hbg->SetLineColor(kBlue);
822  hbg->SetFillStyle(3008); hbg->SetFillColor(kBlue);
823  hsig->SetLineColor(kRed);
824  hsig->SetFillStyle(3003); hsig->SetFillColor(kRed);
825  hsig->SetStats(0);
826  hbg->SetStats(0);
827 // isig->GetYaxis()->SetRangeUser(0,maxTrain/2);
828 // ibg->GetYaxis()->SetRangeUser(0,maxTrain/2);
829  hsig->Draw();
830  hbg->Draw("same");
831  TLegend *hlegend = new TLegend(.75, .80, .95, .95);
832  hlegend->AddEntry(hbg, "Background");
833  hlegend->AddEntry(hsig, "Signal");
834  hlegend->Draw();
835  char namech[2048];
836  char namechroot[2048];
837  TString namch(name);
838  namch.ReplaceAll(".root",".png");
839  sprintf(namech,"Fisher_png/Histog_%s",namch.Data());
840  sprintf(namechroot,"Fisher_png/Histog_%s",name.Data());
841  c_histo->SaveAs(namech);
842  c_histo->SaveAs(namechroot);
843 
844 /* int const ncurve=nANN*nCC;
845  cout<<"dentro funzione dopodef"<<endl;
846 //LOG(NBg)vs RHO------------------------------------------
847  double* rhoSig[ncurve];
848  for (int i=0;i<ncurve;i++) rhoSig[i]=new double[nSig];
849  cout<<"dopo def rhoSig"<<endl;
850  //double rhoSig[20][10];
851  int NSig[ncurve];
852 // int nBg=0;
853  int const nBg=NNTree2->GetEntries()-nSig;
854  for (int i=0;i<ncurve;i++) {
855  NSig[i]=0;
856  for (int j=0;j<nSig;j++) rhoSig[i][j]=0.;
857  }
858  cout<<"dopo def rhoSig"<<endl;
859  double* rhoBg[ncurve];
860  for (int i=0;i<ncurve;i++) rhoBg[i]=new double[nBg];
861  //double rhoBg[20][10];
862  int NBg[ncurve];
863  for (int i=0;i<ncurve;i++) {
864  NBg[i]=0;
865  for (int j=0;j<nBg;j++) rhoBg[i][j]=0.;
866  }
867  cout<<"dopo def rhoBg"<<endl;
868  double ccTh[nCC];
869  for (int i=0;i<nCC;i++) ccTh[i]=0.;
870  double NNTh[nANN];
871  for (int i=0;i<nANN;i++) NNTh[i]=0.;
872  double deltacc=0.;
873  double deltaANN=0.;
874  deltacc=0.2/nCC;
875  //deltaANN=0.6/(nANN-1);
876  deltaANN=(maxw_i-minw_i)/nANN;
877 
878  cout<<NNTree2->GetEntries()<<endl;
879  for(int n=0;n<NNTree2->GetEntries();n++){
880  cout<<n<<endl;
881  NNTree2->GetEntry(n);
882  w_i=w_c*cc+w_o*av;
883  cout<<"rho "<<rho<<" cc "<<cc<<" w_i "<<w_i<<endl;
884  for(int i=0; i<nCC;i++){
885  ccTh[i]=0.5+i*deltacc;
886  if(cc<ccTh[i]) continue;
887  for(int j=0; j<nANN;j++){
888  if(j==0) NNTh[j]=-1000.;
889  //else NNTh[j]=0.5+(j-1)*deltaANN;
890  //else NNTh[j]=0.1+(j-1)*deltaANN;
891  //else NNTh[j]=0.+(j)*deltaANN;
892  else NNTh[j]=minw_i+(j)*deltaANN;
893  //else NNTh[j]=0.+(j-1)*deltaANN/1000.;
894  //else NNTh[j]=1.;
895  if(w_i<NNTh[j]) continue;
896  int ni=0;
897  if(n>nSig) {
898 
899  NBg[i*nANN+j]= NBg[i*nANN+j]+1;
900  while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
901  rhoBg[i*nANN+j][ni]=rho;
902  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
903 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
904  }
905  else {
906  NSig[i*nANN+j]= NSig[i*nANN+j]+1;
907  while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
908  rhoSig[i*nANN+j][ni]=rho;
909  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
910 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
911  }
912  // }
913  }
914  }
915  }
916  cout<<"dopo riempimento variabili"<<endl;
917  int* indexS[ncurve];
918  for (int i=0;i<ncurve;i++) indexS[i]=new int[nSig];
919 
920  TGraph * gS[ncurve];
921  for (int y=0;y<ncurve;y++) {
922  int igS=0;
923  int igS_p=0;
924 // int indexS[nSig];
925 // double rhoS[nSig];
926 // for(int i=0;i<nSig;i++) {
927 // rhoS[i]=0.;
928 // indexS[i]=0;
929 // }
930  // ig=1;
931  // for(int i=0;i<nSig;i++) rhoS[i]=rhoSig[y][i];
932  gS[y]=new TGraph();
933 // gS[y]->SetMarkerStyle(7);
934  TMath::Sort(nSig,rhoSig[y],indexS[y],false);
935 // cout<<"dopo Sort "<<y<<endl;
936  for (int k=0;k<nSig;k++) {
937  int ii=indexS[y][k];
938  int yy=0;
939  if (k>0){
940 // cout<<"k "<<k<<endl;
941  int ij=indexS[y][k-1];
942  //if(rhoSig[y][ii]!=0&&rhoSig[y][ii]!=rhoSig[y][ij]) {
943  if(rhoSig[y][ii]!=0) {
944  yy=NSig[y]-igS;
945  //gS[y]->SetPoint(igS,rhoSig[y][ii],yy);
946  if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
947  cout<<"igS"<<igS<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
948  igS=igS+1;
949  }
950  }
951  else {
952  if(rhoSig[y][ii]!=0){
953  yy=NSig[y]-igS;
954  gS[y]->SetPoint(0,rhoSig[y][ii],yy);
955  igS=igS+1;
956 // cout<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
957  }
958 
959  }
960  }
961  }
962  // cout<<"dopo inserimento puntiiS"<<endl;
963 // cout<<ncurve<<endl;
964  int* indexB[ncurve];
965  for (int i=0;i<ncurve;i++) indexB[i]=new int[nBg];
966 
967  TGraph * gB[ncurve];
968  for (int y=0;y<ncurve;y++) {
969  int igB=0;
970  int igB_p=0;
971  gB[y]=new TGraph();
972  TMath::Sort(nBg,rhoBg[y],indexB[y],false);
973 // cout<<"dopo Sort "<<y<<endl;
974  for (int k=0;k<nBg;k++) {
975  int ii=indexB[y][k];
976  int yy=0;
977  if (k>0){
978  int ij=indexB[y][k-1];
979  //if(rhoBg[y][ii]!=0&&rhoBg[y][ii]!=rhoBg[y][ij]) {
980  if(rhoBg[y][ii]!=0) {
981  yy=NBg[y]-igB;
982  //gB[y]->SetPoint(igB,rhoBg[y][ii],yy);
983  if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
984  igB=igB+1;
985 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
986  }
987  }
988  else {
989  if(rhoBg[y][ii]!=0) {
990  yy=NBg[y]-igB;
991  gB[y]->SetPoint(0,rhoBg[y][ii],yy);
992  igB=igB+1;
993 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
994  }
995  }
996  }
997  }
998  cout<<"dopo inserimento puntiB"<<endl;
999  fTEST->Close();
1000  fF->Close();
1001  //gB[1]->SetMarkerStyle(7);
1002  //gB[1]->SetPoint(1,1,2);
1003  TCanvas* cS=new TCanvas("Efficiency_vs_rho","Efficiency_vs_rho",0,0,1200,700);
1004  cS->Divide(2,2);
1005  cS->cd(1)->SetLogy();
1006  TMultiGraph* mg1=new TMultiGraph();
1007 // gS[0]->SetMarkerStyle(7);
1008  gS[0]->SetMarkerColor(2);
1009  gS[0]->SetLineColor(2);
1010  mg1->SetTitle("cc=0.5;rho;#Events");
1011  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1012 // gS[0]->Draw("apl");
1013  for (int h=1;h<nANN;h++){
1014  gS[h]->SetMarkerColor(3);
1015  gS[h]->SetLineColor(3);
1016 // gS[h]->SetMarkerStyle(h+1);
1017  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
1018  // gS[h]->Draw("apl,same");
1019  }
1020  mg1->Draw("apl");
1021  cS->cd(2)->SetLogy();
1022  TMultiGraph* mg2=new TMultiGraph();
1023 // gS[nANN]->SetMarkerStyle(7);
1024  gS[nANN]->SetMarkerColor(2);
1025  gS[nANN]->SetLineColor(2);
1026  mg2->SetTitle("cc=0.55;rho;#Events");
1027  if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
1028  for (int h=1;h<nANN;h++){
1029  gS[nANN+h]->SetMarkerColor(3);
1030  gS[nANN+h]->SetLineColor(3);
1031 // gS[nANN+h]->SetMarkerStyle(h+1);
1032  if(gS[nANN+h]->GetN()!=0) mg2->Add(gS[nANN+h]);
1033  // gS[nANN+h]->Draw("apl,same");
1034  }
1035  mg2->Draw("apl");
1036  cS->cd(3)->SetLogy();
1037  TMultiGraph* mg3=new TMultiGraph();
1038 // gS[nANN*2]->SetMarkerStyle(7);
1039  gS[nANN*2]->SetMarkerColor(2);
1040  gS[nANN*2]->SetLineColor(2);
1041  mg3->SetTitle("cc=0.6;rho;#Events");
1042  if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
1043  for (int h=1;h<nANN;h++){
1044  gS[2*nANN+h]->SetMarkerColor(3);
1045  gS[2*nANN+h]->SetLineColor(3);
1046 // gS[2*nANN+h]->SetMarkerStyle(h+1);
1047  if(gS[2*nANN+h]->GetN()!=0) mg3->Add(gS[2*nANN+h]);
1048  // gS[2*nANN+h]->Draw("apl,same");
1049  }
1050  mg3->Draw("apl");
1051  cS->cd(4)->SetLogy();
1052  TMultiGraph* mg4=new TMultiGraph();
1053 // gS[nANN*3]->SetMarkerStyle(7);
1054  gS[nANN*3]->SetMarkerColor(2);
1055  gS[nANN*3]->SetLineColor(2);
1056  mg4->SetTitle("cc=0.65;rho;#Events");
1057  if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
1058  // gS[nANN*3]->Draw("apl");
1059  for (int h=1;h<nANN;h++){
1060  gS[3*nANN+h]->SetMarkerColor(3);
1061  gS[3*nANN+h]->SetLineColor(3);
1062 // gS[3*nANN+h]->SetMarkerStyle(h+1);
1063  if(gS[3*nANN+h]->GetN()!=0) mg4->Add(gS[3*nANN+h]);
1064  // gS[3*nANN+h]->Draw("apl,same");
1065  }
1066  mg4->Draw("apl");
1067  cout<<"nuovo canv"<<endl;
1068  TCanvas* cB=new TCanvas("Number_vs_rho","Number_vs_rho",0,0,1200,700);
1069  cB->Divide(2,2);
1070  cB->cd(1)->SetLogy();
1071  TMultiGraph* mg1B=new TMultiGraph();
1072 // gB[0]->SetMarkerStyle(7);
1073  gB[0]->SetMarkerColor(2);
1074  gB[0]->SetLineColor(2);
1075  mg1B->SetTitle("cc=0.5;rho;#Events");
1076  if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
1077  for (int h=1;h<nANN;h++){
1078  gB[h]->SetMarkerColor(3);
1079  gB[h]->SetLineColor(3);
1080  // gB[h]>SetMarkerStyle(h+1);
1081  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1082  //gB[h]->Draw("apl,same");
1083  }
1084  mg1B->Draw("apl");
1085  cB->cd(2)->SetLogy();
1086  TMultiGraph* mg2B=new TMultiGraph();
1087  //gB[nANN]->SetMarkerStyle(7);
1088  gB[nANN]->SetMarkerColor(2);
1089  gB[nANN]->SetLineColor(2);
1090  mg2B->SetTitle("cc=0.55;rho;#Events");
1091  if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
1092  for (int h=1;h<nANN;h++){
1093  gB[nANN+h]->SetMarkerColor(3);
1094  gB[nANN+h]->SetLineColor(3);
1095  //gB[nANN+h]>SetMarkerStyle(h+1);
1096  if(gB[nANN+h]->GetN()!=0) mg2B->Add(gB[nANN+h]);
1097  //gB[h]->Draw("apl,same");
1098  }
1099  mg2B->Draw("apl");
1100  cB->cd(3)->SetLogy();
1101  TMultiGraph* mg3B=new TMultiGraph();
1102 // gB[2*nANN]->SetMarkerStyle(7);
1103  gB[2*nANN]->SetMarkerColor(2);
1104  gB[2*nANN]->SetLineColor(2);
1105  mg3B->SetTitle("cc=0.6;rho;#Events");
1106  if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
1107  for (int h=1;h<nANN;h++){
1108  gB[2*nANN+h]->SetMarkerColor(3);
1109  gB[2*nANN+h]->SetLineColor(3);
1110 // gB[2*nANN+h]>SetMarkerStyle(h+1);
1111  if(gB[2*nANN+h]->GetN()!=0) mg3B->Add(gB[2*nANN+h]);
1112  //gB[h]->Draw("apl,same");
1113  }
1114  mg3B->Draw("apl");
1115  cB->cd(4)->SetLogy();
1116  TMultiGraph* mg4B=new TMultiGraph();
1117 // gB[3*nANN]->SetMarkerStyle(7);
1118  gB[3*nANN]->SetMarkerColor(2);
1119  gB[3*nANN]->SetLineColor(2);
1120  mg4B->SetTitle("cc=0.65;rho;#Events");
1121  if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
1122  for (int h=1;h<nANN;h++){
1123  gB[3*nANN+h]->SetMarkerColor(3);
1124  gB[3*nANN+h]->SetLineColor(3);
1125 // gB[3*nANN+h]>SetMarkerStyle(h+1);
1126  if(gB[3*nANN+h]->GetN()!=0) mg4B->Add(gB[3*nANN+h]);
1127  //gB[h]->Draw("apl,same");
1128  }
1129  mg4B->Draw("apl");
1130 
1131 // cout<<"dopo Draw()"<<endl;
1132  TString CnameS(name);
1133  TString CnameB(name);
1134  TString CnameSroot(name);
1135  TString CnameBroot(name);
1136  char CnameS2[1024];
1137  char CnameB2[1024];
1138  char CnameS2root[1024];
1139  char CnameB2root[1024];
1140  CnameS.ReplaceAll(".root",".png");
1141  CnameB.ReplaceAll(".root",".png");
1142  sprintf(CnameS2,"logN_rho_Fish/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameS.Data());
1143  sprintf(CnameB2,"logN_rho_Fish/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameB.Data());
1144  sprintf(CnameS2root,"logN_rho_Fish/logN_rho_S_dANN%1.2f_%s",deltaANN,CnameSroot.Data());
1145  sprintf(CnameB2root,"logN_rho_Fish/logN_rho_B_dANN%1.2f_%s",deltaANN,CnameBroot.Data());
1146  cS->SaveAs(CnameS2);
1147  cB->SaveAs(CnameB2);
1148  cS->Print(CnameS2root);
1149  cB->Print(CnameB2root);
1150 // cout<<"fine"<<endl;
1151  */
1152 }
1153 
1154 /*
1155 void Annth(TString ifile){
1156  TString name(ifile);
1157  name.ReplaceAll("average_file/","Fisher_file/");
1158  TFile* fTEST =TFile::Open(ifile.Data());
1159  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1160 
1161  double w_o;
1162  double w_c;
1163  int nFs;
1164  int nFb;
1165  int Fs;
1166  int Fb;
1167 
1168  TString namefF(name);
1169  namefF.ReplaceAll(".root","_Fisher.root");
1170  TFile* fF =TFile::Open(namefF.Data());
1171  TTree* FTree= (TTree*)fF->Get("Fisher_Discriminant");
1172  FTree->SetBranchAddress("Fs_start",&Fs);
1173  FTree->SetBranchAddress("Fb_start",&Fb);
1174  FTree->SetBranchAddress("nFs",&nFs);
1175  FTree->SetBranchAddress("nFb",&nFb);
1176  FTree->SetBranchAddress("Fish_coef_cc",&w_c);
1177  FTree->SetBranchAddress("Fish_coef_ANNout",&w_o);
1178  FTree->GetEntry(0);
1179  double w_i;
1180  int ind;
1181  FTree->SetBranchAddress("w_i",&w_i,"w_i/D");
1182  FTree->SetBranchAddress("index",&ind,"index/I");
1183 
1184  //TString name(ifile);
1185  //name.ReplaceAll("average_file/","");
1186  //TFile* fTEST =TFile::Open(ifile.Data());
1187  //TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1188  double av;
1189  double cc;
1190  double rho;
1191  int nSi;
1192  NNTree2->SetBranchAddress("Average",&av);
1193  NNTree2->SetBranchAddress("cc",&cc);
1194  NNTree2->SetBranchAddress("rho",&rho);
1195  NNTree2->SetBranchAddress("#TestSig",&nSi);
1196  NNTree2->GetEntry(0);
1197  int const nSig=nSi;
1198 // cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1199  int const ncurve2=nRHO*nCC;
1200 
1201 
1202  double* ANNSig[ncurve2];
1203  for (int i=0;i<ncurve2;i++) ANNSig[i]=new double[nSig];
1204  //double rhoSig[20][10];
1205  int NSig[ncurve2];
1206 // int nBg=0;
1207  int const nBg=NNTree2->GetEntries()-nSig;
1208  for (int i=0;i<ncurve2;i++) {
1209  NSig[i]=0;
1210  for (int j=0;j<nSig;j++) ANNSig[i][j]=0.;
1211  }
1212  double* ANNBg[ncurve2];
1213  for (int i=0;i<ncurve2;i++) ANNBg[i]=new double[nBg];
1214 
1215  //double rhoBg[20][10];
1216  int NBg[ncurve2];
1217  for (int i=0;i<ncurve2;i++) {
1218  NBg[i]=0;
1219  for (int j=0;j<nBg;j++) ANNBg[i][j]=0.;
1220  }
1221  double ccTh[nCC];
1222  for (int i=0;i<nCC;i++) ccTh[i]=0.;
1223  double rhoTh[nRHO];
1224  for (int i=0;i<nRHO;i++) rhoTh[i]=0.;
1225  double deltacc=0.;
1226  double deltarho=0.;
1227  deltacc=0.2/nCC;
1228  deltarho=1./(nRHO);
1229 
1230 
1231  for(int n=0;n<FTree->GetEntries();n++){
1232  FTree->GetEntry(n)
1233  NNTree2->GetEntry(ind);
1234  cout<<"rho "<<rho<<" cc "<<cc<<" w_i "<<w_i<<endl;
1235  for(int i=0; i<nCC;i++){
1236  ccTh[i]=0.5+i*deltacc;
1237  if(cc<ccTh[i]) continue;
1238  for(int j=0; j<nRHO;j++){
1239  rhoTh[j]=5+j*deltarho;
1240  if(rho<rhoTh[j]) continue;
1241  int ni=0;
1242  if(n>nSig) {
1243  NBg[i*nRHO+j]= NBg[i*nRHO+j]+1;
1244  while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
1245  ANNBg[i*nRHO+j][ni]=w_i;
1246  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1247  }
1248  else {
1249  NSig[i*nRHO+j]= NSig[i*nRHO+j]+1;
1250  while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
1251  ANNSig[i*nRHO+j][ni]=w_i;
1252  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
1253  }
1254  }
1255  }
1256  }
1257 
1258  int* indexS[ncurve2];
1259  for (int i=0;i<ncurve2;i++) indexS[i]=new int[nSig];
1260 
1261  TGraph * gS[ncurve2];
1262  for (int y=0;y<ncurve2;y++) {
1263  int igS=0;
1264  int igS_p=0;
1265  gS[y]=new TGraph();
1266  TMath::Sort(nSig,ANNSig[y],indexS[y],false);
1267  for (int k=0;k<nSig;k++) {
1268  int ii=indexS[y][k];
1269  int yy=0;
1270  if (k>0){
1271  //cout<<"k "<<k<<endl;
1272  int ij=indexS[y][k-1];
1273  //if(ANNSig[y][ii]!=0&&ANNSig[y][ii]!=ANNSig[y][ij]) {
1274  if(ANNSig[y][ii]!=0) {
1275  yy=NSig[y]-igS;
1276  //gS[y]->SetPoint(igS,ANNSig[y][ii],yy);
1277  if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
1278  // cout<<"igS"<<igS<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1279  igS=igS+1;
1280 
1281  }
1282  }
1283  else {
1284  if(ANNSig[y][ii]!=0){
1285  yy=NSig[y]-igS;
1286  gS[y]->SetPoint(0,ANNSig[y][ii],yy);
1287  igS=igS+1;
1288  // cout<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
1289  }
1290 
1291  }
1292  }
1293  }
1294 
1295 
1296 
1297  int* indexB[ncurve2];
1298  for (int i=0;i<ncurve2;i++) indexB[i]=new int[nBg];
1299 
1300  TGraph * gB[ncurve2];
1301  for (int y=0;y<ncurve2;y++) {
1302  int igB=0;
1303  int igB_p=0;
1304  gB[y]=new TGraph();
1305  TMath::Sort(nBg,ANNBg[y],indexB[y],false);
1306  // cout<<"dopo Sort "<<y<<endl;
1307  for (int k=0;k<nBg;k++) {
1308  int ii=indexB[y][k];
1309  int yy=0;
1310  if (k>0){
1311  int ij=indexB[y][k-1];
1312  //if(ANNBg[y][ii]!=0&&ANNBg[y][ii]!=ANNBg[y][ij]) {
1313  if(ANNBg[y][ii]!=0) {
1314  yy=NBg[y]-igB;
1315  //gB[y]->SetPoint(igB,ANNBg[y][ii],yy);
1316  if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
1317  igB=igB+1;
1318  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1319  }
1320  }
1321  else {
1322  if(ANNBg[y][ii]!=0) {
1323  yy=NBg[y]-igB;
1324  gB[y]->SetPoint(0,ANNBg[y][ii],yy);
1325  igB=igB+1;
1326  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
1327  }
1328  }
1329  }
1330  }
1331 
1332 
1333  TCanvas* cS=new TCanvas("Efficiency_vs_ANN","Efficiency_vs_ANN",0,0,1200,700);
1334  cS->Divide(2,2);
1335  //cS->cd(1)->SetLogy();
1336  cS->cd(1);
1337  TMultiGraph* mg1=new TMultiGraph();
1338  mg1->SetTitle("cc=0.5;ANN;#Events");
1339  for (int h=0;h<nRHO;h++){
1340  gS[h]->SetLineColor(4);
1341  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
1342  }
1343  mg1->Draw("al");
1344  cS->cd(2);
1345  // cS->cd(2)->SetLogy();
1346  TMultiGraph* mg2=new TMultiGraph();
1347  mg2->SetTitle("cc=0.55;ANN;#Events");
1348  for (int h=0;h<nRHO;h++){
1349  gS[nRHO+h]->SetLineColor(4);
1350  if(gS[nRHO+h]->GetN()!=0) mg2->Add(gS[nRHO+h]);
1351  }
1352  mg2->Draw("al");
1353 
1354  //cS->cd(3)->SetLogy();
1355  cS->cd(3);
1356  TMultiGraph* mg3=new TMultiGraph();
1357  mg3->SetTitle("cc=0.6;ANN;#Events");
1358  for (int h=0;h<nRHO;h++){
1359  gS[2*nRHO+h]->SetLineColor(4);
1360  if(gS[2*nRHO+h]->GetN()!=0) mg3->Add(gS[2*nRHO+h]);
1361  }
1362  mg3->Draw("al");
1363  //cS->cd(4)->SetLogy();
1364  cS->cd(4);
1365  TMultiGraph* mg4=new TMultiGraph();
1366  mg4->SetTitle("cc=0.65;ANN;#Events");
1367  for (int h=0;h<nRHO;h++){
1368  gS[3*nRHO+h]->SetLineColor(4);
1369  if(gS[3*nRHO+h]->GetN()!=0) mg4->Add(gS[3*nRHO+h]);
1370  }
1371  mg4->Draw("al");
1372 
1373  TCanvas* cB=new TCanvas("Number_vs_ANN","Number_vs_ANN",0,0,1200,700);
1374  cB->Divide(2,2);
1375  cB->cd(1)->SetLogy();
1376  TMultiGraph* mg1B=new TMultiGraph();
1377  mg1B->SetTitle("cc=0.5;ANN;#Events");
1378  for (int h=0;h<nRHO;h++){
1379  gB[h]->SetLineColor(4);
1380  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
1381  }
1382  mg1B->Draw("al");
1383  cB->cd(2)->SetLogy();
1384  TMultiGraph* mg2B=new TMultiGraph();
1385  mg2B->SetTitle("cc=0.55;ANN;#Events");
1386  for (int h=0;h<nRHO;h++){
1387  gB[nRHO+h]->SetLineColor(4);
1388  if(gB[nRHO+h]->GetN()!=0) mg2B->Add(gB[nRHO+h]);
1389  }
1390  mg2B->Draw("al");
1391  cB->cd(3)->SetLogy();
1392  TMultiGraph* mg3B=new TMultiGraph();
1393  mg3B->SetTitle("cc=0.6;ANN;#Events");
1394  for (int h=0;h<nRHO;h++){
1395  gB[2*nRHO+h]->SetLineColor(4);
1396  if(gB[2*nRHO+h]->GetN()!=0) mg3B->Add(gB[2*nRHO+h]);
1397  }
1398  mg3B->Draw("al");
1399  cB->cd(4)->SetLogy();
1400  TMultiGraph* mg4B=new TMultiGraph();
1401  mg4B->SetTitle("cc=0.6;ANN;#Events");
1402  for (int h=0;h<nRHO;h++){
1403  gB[3*nRHO+h]->SetLineColor(4);
1404  if(gB[3*nRHO+h]->GetN()!=0) mg4B->Add(gB[3*nRHO+h]);
1405  }
1406  mg4B->Draw("al");
1407 
1408 
1409  //cout<<"dopo Draw()"<<endl;
1410  TString CnameS(name);
1411  TString CnameB(name);
1412  TString CnameSroot(name);
1413  TString CnameBroot(name);
1414  char CnameS2[1024];
1415  char CnameB2[1024];
1416  char CnameS2root[1024];
1417  char CnameB2root[1024];
1418  CnameS.ReplaceAll(".root",".png");
1419  CnameB.ReplaceAll(".root",".png");
1420  sprintf(CnameS2,"ANNthres_Fish/N_ANN_S_%s",CnameS.Data());
1421  sprintf(CnameB2,"ANNthres_Fish/N_ANN_B_%s",CnameB.Data());
1422  sprintf(CnameS2root,"ANNthres_Fish/N_ANN_S_%s",CnameSroot.Data());
1423  sprintf(CnameB2root,"ANNthres_Fish/N_ANN_B_%s",CnameBroot.Data());
1424  cS->SaveAs(CnameS2);
1425  cB->SaveAs(CnameB2);
1426  cS->Print(CnameS2root);
1427  cB->Print(CnameB2root);
1428  //cout<<"fine"<<endl;
1429 
1430 //CARTELLA Annth
1431 
1432 
1433 
1434 }
1435 
1436 */
1438  TString name(ifile);
1439  name.ReplaceAll("outfile/","");
1440  name.ReplaceAll("average_file/","");
1441  TFile* fTEST =TFile::Open(ifile.Data());
1442  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1443  //double outbis;
1444  double av;
1445  double out;
1446  double cc;
1447  double rho;
1448  int nSi;
1449 // NNTree2->SetBranchAddress("ANNout",&out);
1450  NNTree2->SetBranchAddress("Average",&av);
1451  NNTree2->SetBranchAddress("cc",&cc);
1452  NNTree2->SetBranchAddress("rho",&rho);
1453  NNTree2->SetBranchAddress("#TestSig",&nSi);
1454  NNTree2->GetEntry(0);
1455  int const nSig=nSi;
1456  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1457  int const nBg=NNTree2->GetEntries()-nSig;
1458  cout<<"nBg: "<<nBg<<" Entries: "<<NNTree2->GetEntries()<<endl;
1459 
1460  TGraph * gS[3];
1461  TGraph * gB[3];
1462  gB[0]=new TGraph();
1463  gS[0]=new TGraph();
1464 // cout<<"nSig: "<<nSig<<endl;
1465  for (int n = 0; n <NNTree2->GetEntries(); n++){
1466  NNTree2->GetEntry(n);
1467  if(n<nSig) {
1468  gS[0]->SetPoint(n,cc,av);
1469  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1470  }
1471  else {
1472  gB[0]->SetPoint(n-nSig,cc,av);
1473  cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1474  }
1475  }
1476 
1477 
1478  /*for (int a=0;a<nBg;a++){
1479  if(aRHOB[a]>=RHOth){
1480  for (int b=0;b<nth;b++){
1481  if(aCCB[a]>=cc1th[b]){
1482  for(int c=0;c<nth+1;c++){
1483  if(aANNB[a]>=ANN1th[c]) Z[b*nth+c]=Z[b*nth+c]+1;
1484  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1485  }
1486  }
1487  }
1488  }
1489  }*/
1490  gS[0]->SetMarkerColor(2);
1491  gB[0]->SetMarkerColor(4);
1492  gS[0]->SetMarkerStyle(6);
1493  gB[0]->SetMarkerStyle(7);
1494 
1495  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1496  c->Divide(1,2);
1497  c->cd(1);
1498  TMultiGraph* mg1=new TMultiGraph();
1499  mg1->SetTitle("Av_cc");
1500  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1501  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1502  mg1->Draw("ap");
1503  c->cd(2);
1504  TMultiGraph* mg2=new TMultiGraph();
1505  mg2->SetTitle("Av_cc");
1506  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1507  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1508  mg2->Draw("ap");
1509 
1510  cout<<" name "<<name<<endl;
1511  TString Cname(name);
1512  TString Cnameroot(name);
1513  char Cname2[1024];
1514  char Cname2root[1024];
1515  Cname.ReplaceAll(".root",".png");
1516  sprintf(Cname2,"average_png/out_Plots_%s",Cname.Data());
1517  sprintf(Cname2root,"average_png/out_Plots_%s",Cnameroot.Data());
1518  c->SaveAs(Cname2);
1519  c->Print(Cname2root);
1520 /*
1521  TCanvas* c2=new TCanvas("Plots_Bkg_on_Sig","Plots_Bkg_on_Sig",0,0,1200,700);
1522  c2->Divide(2,2);
1523  c2->cd(1);
1524  gS[0]->Draw("ap");
1525  gB[0]->Draw("p,same");
1526 
1527  c2->cd(2);
1528  gS[1]->Draw("ap");
1529  gB[1]->Draw("p,same");
1530  c2->cd(3);
1531  gS[2]->Draw("ap");
1532  gB[2]->Draw("p,same");
1533  c2->cd(4);
1534  TText* text2=new TText(0.37,0.0,"no cuts on ANN");
1535  hglitch->SetStats(0);
1536  hglitch->GetXaxis()->SetTitle("cc");
1537  hglitch->GetYaxis()->SetTitle("ANNoutput");
1538  hglitch->GetZaxis()->SetTitle("count");
1539  hglitch->Draw("colz");
1540  text2->Draw();
1541  gPad->SetLogz();
1542 
1543  TString Cname_2(name);
1544  TString Cname_2root(name);
1545  char Cname2_2[1024];
1546  char Cname2_2root[1024];
1547  Cname_2.ReplaceAll(".root",".png");
1548  sprintf(Cname2_2,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2.Data());
1549  sprintf(Cname2_2root,"CC_RHO_ANN_Plots/CC_RHO_ANN_Plots_BoS_%s",Cname_2root.Data());
1550  c2->SaveAs(Cname2_2);
1551  c2->Print(Cname2_2root);
1552 
1553 //CARTELLA CCi_RHO_ANN_Plots */
1554 }
1556  TString name(ifile);
1557  name.ReplaceAll("outfile/","");
1558  name.ReplaceAll("average_file/","");
1559  TFile* fTEST =TFile::Open(ifile.Data());
1560  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
1561  //double outbis;
1562  double av;
1563  double out;
1564  double cc;
1565  double Mc;
1566  double rho;
1567  int nSi;
1568 // NNTree2->SetBranchAddress("ANNout",&out);
1569  NNTree2->SetBranchAddress("Mchirp",&Mc);
1570  NNTree2->SetBranchAddress("Average",&av);
1571  NNTree2->SetBranchAddress("cc",&cc);
1572  NNTree2->SetBranchAddress("rho",&rho);
1573  NNTree2->SetBranchAddress("#TestSig",&nSi);
1574  NNTree2->GetEntry(0);
1575  int const nSig=nSi;
1576  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
1577  int const nBg=NNTree2->GetEntries()-nSig;
1578 
1579  TGraph * gS[3];
1580  TGraph * gB[3];
1581  gB[0]=new TGraph();
1582  gS[0]=new TGraph();
1583 // cout<<"nSig: "<<nSig<<endl;
1584  for (int n = 0; n <NNTree2->GetEntries(); n++){
1585  NNTree2->GetEntry(n);
1586  if(n<nSig) {
1587  gS[0]->SetPoint(n,Mc,av);
1588  cout<<"Sig_graph1: x="<<cc<<" y: "<<av<<endl;
1589  }
1590  else {
1591  gB[0]->SetPoint(n-nSig,Mc,av);
1592  cout<<"Bg_graph1: x="<<cc<<" y: "<<av<<endl;
1593  }
1594  }
1595 
1596 
1597  /*for (int a=0;a<nBg;a++){
1598  if(aRHOB[a]>=RHOth){
1599  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1600  }
1601  }
1602  }
1603  }
1604  }*/
1605  gS[0]->SetMarkerColor(2);
1606  gB[0]->SetMarkerColor(4);
1607  gS[0]->SetMarkerStyle(6);
1608  gB[0]->SetMarkerStyle(7);
1609 
1610  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1611  c->Divide(1,2);
1612  c->cd(1);
1613  TMultiGraph* mg1=new TMultiGraph();
1614  mg1->SetTitle("Av_Mc");
1615  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1616  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1617  mg1->Draw("ap");
1618  c->cd(2);
1619  TMultiGraph* mg2=new TMultiGraph();
1620  mg2->SetTitle("Av_Mc");
1621  if(gS[0]->GetN()!=0) mg2->Add(gS[0]);
1622  if(gB[0]->GetN()!=0) mg2->Add(gB[0]);
1623  mg2->Draw("ap");
1624 
1625  cout<<" name "<<name<<endl;
1626  TString Cname(name);
1627  TString Cnameroot(name);
1628  char Cname2[1024];
1629  char Cname2root[1024];
1630  Cname.ReplaceAll(".root",".png");
1631  sprintf(Cname2,"average_png/Mc_Plots_%s",Cname.Data());
1632  sprintf(Cname2root,"average_png/Mc_Plots_%s",Cnameroot.Data());
1633  c->SaveAs(Cname2);
1634  c->Print(Cname2root);
1635 }
char ofile[1024]
double rho
Float_t * rho
biased null statistics
Definition: netevent.hh:112
static double g(double e)
Definition: GNGen.cc:116
wavearray< double > a(hp.size())
par [0] name
int n
Definition: cwb_net.C:28
TString("c")
ofstream out
Definition: cwb_merge.C:214
void graph_Fish(TString ifile)
Definition: Fisher_1.C:728
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.
i drho i
wavearray< double > hh
Definition: Regression_H1.C:73
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
TF1 * g1
void PlotsAv_cc(TString ifile)
Definition: Fisher_1.C:1437
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]
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:113
TFile * ifile
void Fisher_ex(TString ifile, int nFs, int nFb, int Fs, int Fb)
Definition: Fisher_1.C:467
s s
Definition: cwb_net.C:155
void Fisher_1(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 nFs, int nFb, int Fs=0, int Fb=0, int TS=0, int TB=0, int s=0, int b=0, int uf=1, int ni=0)
Definition: Fisher_1.C:62
void PlotsAv_Mc(TString ifile)
Definition: Fisher_1.C:1555
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
netcluster wc
#define nIFO
Definition: Fisher_1.C:42
#define iMc
Definition: Fisher_1.C:52
Int_t GetEntries()
Definition: netevent.cc:403
for(int i=0;i< 101;++i) Cos2[2][i]=0
pointers to detectors
wavearray< double > y
Definition: Test10.C:31
Float_t * chirp
range to source: [0/1]-rec/inj
Definition: netevent.hh:128
exit(0)