Logo coherent WaveBurst  
Library Reference Guide
Logo
Test0_Mchirp.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 deltaMc 1
46 #define nCC 4
47 #define NPIX 20
48 #define RHOth 5.5
49 #define nth 10
50 #define iMc 1
51 using namespace std;
52 void graph(TString ifile);
53 void Annth(TString ifile);
54 void Plots(TString ifile);
55 //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){
56 void Test0_Mchirp(TString NN_FILE,TString TEST_FILE, int TS=0, int TB=0, int s=0, int b=0, int uf=0){
57 
58  int p=0;
59  char NNi[1024];
60  char NNi2[1024];
61  sprintf(NNi2,"%s",NN_FILE.Data());
62  while (NNi2[p]){
63  //cout<<NNi2[p]<<endl;
64  if (NNi2[p]=='N'){
65 // cout<<p<<endl;
66  if((NNi2[p+1]=='N')&&(NNi2[p+2]=='\/')) {
67 // cout<<" dentro if"<<endl;
68  int hh=p+3;
69  while (NNi2[hh]!='\0'){NNi[hh-p-3]=NNi2[hh];hh=hh+1;}
70  break;
71  }
72  }
73  p=p+1;
74  }
75 
76  int q=0;
77  char Filei[1024];
78 // for (int i=0;i<1024;i++)Filei[i]='';
79  char Filei2[1024];
80  sprintf(Filei2,"%s",TEST_FILE.Data());
81  while (Filei2[q]){
82 // cout<<Filei2[q]<<endl;
83  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]=='\/')) {
84  int hh=q+7;
85  //while (Filei2[hh]!='\0') {Filei[hh-p-8]=Filei2[hh];hh=hh+1;cout<<Filei2[hh]<<endl;}
86  while (Filei2[hh]!='\0') {Filei[hh-p-7]=Filei2[hh];hh=hh+1;
87  //cout<<Filei2[hh]<<endl;
88  }
89  for (int h0=hh-p-7;h0<1024;h0++) Filei[h0]='\0';
90  break;
91  }
92  q=q+1;
93  }
94 
95  cout<<NNi<<" original String: "<<NNi2<<endl;
96  cout<<Filei<<" original String: "<<Filei2<<endl;
97 
98  TString NNi0(NNi);
99  TString Filei0(Filei);
100 
101  NNi0.ReplaceAll(".root","");
102  Filei0.ReplaceAll(".root","");
103 
104 
105  TFile* fnet =TFile::Open(NN_FILE.Data());
106  TMultiLayerPerceptron *mlp = (TMultiLayerPerceptron*)fnet->Get("TMultiLayerPerceptron");
107  if(mlp==NULL) {cout << "Error getting mlp" << endl;exit(1);}
108  TTree* infot=(TTree*)fnet->Get("info");
109  int NNs;
110  int NNb;
111  int NNnTS;
112  int NNnTB;
113  infot->SetBranchAddress("Rand_start_Sig",&NNs);
114  infot->SetBranchAddress("Rand_start_Bg",&NNb);
115  infot->SetBranchAddress("#trainSig",&NNnTS);
116  infot->SetBranchAddress("#trainBg",&NNnTB);
117  infot->GetEntry(0);
118 
119  TFile* fTEST =TFile::Open(TEST_FILE.Data());
120  TTree* NNTree=(TTree*)fTEST->Get("nnTree");
121  int entries=NNTree->GetEntries();
122  cout<<"entries: "<<entries<<endl;
123 
124 //estraggo le info che servono anche al tree di def dell'mlp
125  int ndim;
126  int ninp;
127  int y;
128  int entriesTot;
129  int bg_entries;
130  int sig_entries;
131 
132  NNTree->SetBranchAddress("#Entries_type",&entriesTot);
133  NNTree->SetBranchAddress("Matrix_dim",&ndim);
134  NNTree->SetBranchAddress("#inputs",&ninp);
135  NNTree->SetBranchAddress("amplitude_mode",&y);
136 
137  NNTree->GetEntry(0);
138  sig_entries=entriesTot;
139  NNTree->GetEntry(entries-1);
140  bg_entries=entriesTot;
141 
142  int const NDIM=ndim;
143  int const nINP=ninp;
144 
145  cout<<"NDIM "<<NDIM<<endl;
146  cout<<"nINP"<<nINP<<endl;
147  cout<<"sig e "<<sig_entries<<endl;
148  cout<<"bg e "<<bg_entries<<endl;
149  int minevents=0;
150  if (sig_entries>bg_entries) minevents=bg_entries;
151  else minevents=sig_entries;
152 
153  if(b==0) b=sig_entries;
154  if(TB==0 && TS==0){
155  TS=minevents;
156  TB=minevents;
157  }
158  if (b<sig_entries){
159  cout<<"Error: Bg index<sig_entries"<<endl;
160  exit(0);
161  }
162  if((TS>sig_entries||TB>bg_entries)&&(TS==TB)) {TS=minevents-s;TB=minevents-b+sig_entries;}
163  if((TS>sig_entries||TB>bg_entries)&&(TS!=TB)) {TS=sig_entries-s;TB=bg_entries-b+sig_entries;}
164 
165 
166  char NOMEtot[1024];
167  cout<<deltaMc<<endl;
168  //sprintf(NOMEtot,"NN_%s_FILE_%s_TS%i_TB%i_st%i_bt%i_dMc%1.2f_uf%i",NNi0.Data(),Filei0.Data(),TS,TB,s,b,deltaMc,uf);
169  sprintf(NOMEtot,"NN_%s_FILE_%s_TS%i_TB%i_st%i_bt%i_uf%i_dMc%i",NNi0.Data(),Filei0.Data(),TS,TB,s,b,uf,deltaMc);
170  cout<<"nome: "<<NOMEtot<<endl;
171 
172  TString SIG_FILE;
173  TString BG_FILE;
174  char FILE_NAME[516];
175  NNTree->SetBranchAddress("Files_name",&FILE_NAME);
176  NNTree->GetEntry(0);
177  SIG_FILE=FILE_NAME;
178  NNTree->GetEntry(entries-1);
179  BG_FILE=FILE_NAME;
180  cout<<"fine ifdef RHO_CC"<<endl;
181 
182  TChain sigTree("waveburst");//cerca il Tree "waveburst nei file
183  sigTree.Add(SIG_FILE.Data());//determina i file
184  netevent signal(&sigTree,nIFO);
185  int sig_entries2 = signal.GetEntries();
186  cout << "sig entries2 : " << sig_entries2 << endl;
187 
188  TChain bgTree("waveburst");
189  bgTree.Add(BG_FILE.Data());
190  netevent background(&bgTree,nIFO);
191  int bg_entries2 = background.GetEntries();
192  cout << "bg entries2 : " << bg_entries2 << endl;
193 
194  cout<<"b: "<<b<<endl;
195  cout<<"s: "<<s<<endl;
196 
197  // add leaf
198  Float_t x[nINP];
199  for (int jj=0; jj<nINP;jj++) x[jj]=0.;
200  char ilabel[nINP][16];
201 
202  //costruzione una foglia per ogni input
203  for(int i=0;i<nINP;i++) {
204  sprintf(ilabel[i],"x%i",i+1);
205  NNTree->SetBranchAddress(ilabel[i], &x[i]);
206  }
207 
208 char ofile[1024];
209 sprintf(ofile,"outfile_Mc/%s.root",NOMEtot);
210 //TFile*f=new TFile(ofile.Data(),"RECREATE");
211 TFile*f=new TFile(ofile,"RECREATE");
212  TTree* NNTree2=new TTree("Parameters","Parameters");
213 NNTree2->SetDirectory(f);
214  double out=0.;
215  double NNcc=0.;
216  double NNrho=0.;
217  double Mc=0.;
218  NNTree2->Branch("Mchirp",&Mc,"Mchirp/D");
219  NNTree2->Branch("ANNout",&out,"ANNout/D");
220  NNTree2->Branch("cc",&NNcc,"cc/D");
221  NNTree2->Branch("rho",&NNrho,"rho/D");
222  char NNfilename[1024];
223  NNTree2->Branch("NNname",&NNfilename,"NNname/C");
224  sprintf(NNfilename,"%s",NN_FILE.Data());
225  char Testf[1024];
226  NNTree2->Branch("TestFile",&Testf,"TestFile/C");
227  sprintf(Testf,"%s",TEST_FILE.Data());
228  int nTestS;
229  NNTree2->Branch("#TestSig",&nTestS,"#TestSig/I");
230 // nTestS=TS;
231  cout<<"nTestS: "<<nTestS<<" TS: "<<TS<<endl;
232  cout<<"dopo def tree"<<endl;
233 /* TChain TreeS("waveburst");//cerca il Tree "waveburst nei file
234  TreeS.Add(TEST_FILE.Data());//determina i file
235  netevent entryS(&TreeS,nIFO);
236  int entriesTot=0;
237  entriesTot = entryS.GetEntries();
238  cout << "Sig entries : " << entriesTot << endl;
239  std::vector<double>* frameS = new vector<double>;
240  entryS.fChain->SetBranchAddress("nnframe", &frameS);//fa esattamente come ha fatto per le altre variabili nella macro netevent.cc
241 
242  //cout<<"cc"<<(double)entryS.netcc[1]<<endl;
243 */ //cout<<"rho"<<(double)entryS.rho[0]<<endl;
244 
245 int scount=0;
246  if(uf==0) nTestS=TS;
247  else {
248 for(int n=s;n<s+TS;n++) {
249  if (uf!=0&&n>=NNs&&n<=(NNs+NNnTS)) continue;
250  scount=scount+1;
251  }
252 nTestS=scount;
253 }
254 
255  double params[nINP];
256  int sig_05=0;
257  for (int i=0; i<nINP; i++) params[i]=0.;
258 // int ent0=0;
259 // ent0=
260  //for(int n=0;n<entryS.GetEntries();n++) {
261  for(int n=s;n<s+TS;n++) {
262  cout<<"n "<<n<<endl;
263  if (uf!=0&&n>=NNs&&n<=(NNs+NNnTS)) continue;
264  NNTree->GetEntry(n);
265  signal.GetEntry(n);
266  NNcc=(double)signal.netcc[1];
267  NNrho=(double)signal.rho[0];
268  Mc=(double)signal.chirp[iMc];
269  for (int i=0; i<nINP; i++){
270  //x[i]=(*frameS)[i];
271  params[i]=x[i];
272  }
273  double output=mlp->Evaluate(0,params);
274  out=output;
275  if (out<0.6) sig_05=sig_05+1;
276  cout<<"rho: "<<signal.rho[0]<<" cc "<<signal.netcc[1]<<" Mc: "<<Mc<<endl;
277  NNTree2->Fill();
278  }
279 int entSig1=0;
280 entSig1=NNTree2->GetEntries();
281 cout<<entSig1<<endl;
282 cout<<"riempito sig"<<endl;
283 cout<<"NNb"<<NNb<<endl;
284 cout<<"b "<<b<<endl;
285 int bg_05=0;
286  //for(int n=sig_entries+b;n<sig_entries+b+TB;n++) {
287  for(int n=b;n<b+TB;n++) {
288  if (uf!=0&&n>=NNb&&n<=(NNb+NNnTB)) continue;
289  NNTree->GetEntry(n);
290  cout<<"n: "<<n<<"Bg index"<<(n-sig_entries)<<endl;
291  background.GetEntry(n-sig_entries);
292  NNcc=(double)background.netcc[1];
293  NNrho=(double)background.rho[0];
294  Mc=(double)background.chirp[iMc];
295  for (int i=0; i<nINP; i++){
296  //x[i]=(*frameS)[i];
297  params[i]=x[i];
298  }
299 
300  double output=mlp->Evaluate(0,params);
301  out=output;
302  if(out>0.6) bg_05=bg_05+1;
303  cout<<"rho: "<<background.rho[0]<<" cc "<<background.netcc[1]<<" Mc: "<<Mc<<endl;
304  NNTree2->Fill();
305  }
306 cout<<"riempito bg"<<endl;
307 int Realentries=0;
308 Realentries=NNTree2->GetEntries();
309 NNTree2->Write();
310 f->Close();
311 cout<<"chiuso file"<<endl;
312 
313 //graph(ofile.Data());
314 graph(ofile);
315 cout<<"dopo richiamo funzione"<<endl;
316 Annth(ofile);
317 Plots(ofile);
318 //cout<<" Sig with out<06: "<<sig_05<<endl;
319 //cout<<" Bg with out>06: "<<bg_05<<endl;
320 cout<<" Realentries "<<Realentries<<" entSig: "<<entSig1<<endl;
321 
322 }
323 
325  TString name(ifile);
326  name.ReplaceAll("outfile_Mc/","");
327  TFile* fTEST =TFile::Open(ifile.Data());
328  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
329  double Mc;
330  double out;
331  double cc;
332  double rho;
333  int nSi;
334  NNTree2->SetBranchAddress("Mchirp",&Mc);
335  NNTree2->SetBranchAddress("ANNout",&out);
336  NNTree2->SetBranchAddress("cc",&cc);
337  NNTree2->SetBranchAddress("rho",&rho);
338  NNTree2->SetBranchAddress("#TestSig",&nSi);
339  NNTree2->GetEntry(0);
340  int const nSig=nSi;
341  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
342  int const ncurve=nANN*nCC;
343  cout<<"dentro funzione dopodef"<<endl;
344 //LOG(NBg)vs RHO------------------------------------------
345  double* rhoSig[ncurve];
346  for (int i=0;i<ncurve;i++) rhoSig[i]=new double[nSig];
347  cout<<"dopo def rhoSig"<<endl;
348  //double rhoSig[20][10];
349  int NSig[ncurve];
350 // int nBg=0;
351  int const nBg=NNTree2->GetEntries()-nSig;
352  for (int i=0;i<ncurve;i++) {
353  NSig[i]=0;
354  for (int j=0;j<nSig;j++) rhoSig[i][j]=0.;
355  }
356  cout<<"dopo def rhoSig"<<endl;
357  double* rhoBg[ncurve];
358  for (int i=0;i<ncurve;i++) rhoBg[i]=new double[nBg];
359  // cout<<"ciao"<<endl;
360  //double rhoBg[20][10];
361  int NBg[ncurve];
362  for (int i=0;i<ncurve;i++) {
363  NBg[i]=0;
364  for (int j=0;j<nBg;j++) rhoBg[i][j]=0.;
365  }
366  cout<<"dopo def rhoBg"<<endl;
367  double ccTh[nCC];
368  for (int i=0;i<nCC;i++) ccTh[i]=0.;
369  double NNTh[nANN];
370  for (int i=0;i<nANN;i++) NNTh[i]=0.;
371  double deltacc=0.;
372 // double deltaANN=0.;
373  deltacc=0.2/nCC;
374  //deltaANN=0.6/(nANN-1);
375 
376  cout<<NNTree2->GetEntries()<<endl;
377  for(int n=0;n<NNTree2->GetEntries();n++){
378  cout<<n<<endl;
379  NNTree2->GetEntry(n);
380  cout<<"rho "<<rho<<" cc "<<cc<<" out "<<out<<endl;
381  for(int i=0; i<nCC;i++){
382  ccTh[i]=0.5+i*deltacc;
383  if(cc<ccTh[i]) continue;
384  for(int j=0; j<nANN;j++){
385  if(j==0) NNTh[j]=-100000000.;
386  //else NNTh[j]=0.5+(j-1)*deltaANN;
387  //else NNTh[j]=0.1+(j-1)*deltaANN;
388  //else NNTh[j]=0.+(j)*deltaANN;
389  else NNTh[j]=0.+(j)*deltaMc;
390  //else NNTh[j]=0.+(j-1)*deltaANN/1000.;
391  //else NNTh[j]=1.;
392  if(Mc<NNTh[j]) continue;
393  int ni=0;
394  if(n>nSig) {
395  NBg[i*nANN+j]= NBg[i*nANN+j]+1;
396  while(rhoBg[i*nANN+j][ni]!=0)ni=ni+1;
397  rhoBg[i*nANN+j][ni]=rho;
398  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
399 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
400  }
401  else {
402  NSig[i*nANN+j]= NSig[i*nANN+j]+1;
403  while(rhoSig[i*nANN+j][ni]!=0)ni=ni+1;
404  rhoSig[i*nANN+j][ni]=rho;
405  // cout<<"rho: "<<rho<<" colonna "<<i*nANN+j<<" riga "<<ni<<endl;
406 // cout<<" soglia_cc "<<ccTh[i]<<" soglia_ANN "<<NNTh[j]<<endl;
407  }
408  // }
409  }
410  }
411  }
412  cout<<"dopo riempimento variabili"<<endl;
413  int* indexS[ncurve];
414  for (int i=0;i<ncurve;i++) indexS[i]=new int[nSig];
415  TGraph * gS[ncurve];
416  for (int y=0;y<ncurve;y++) {
417  int igS=0;
418  int igS_p=0;
419  /* int indexS[nSig];
420  double rhoS[nSig];
421  for(int i=0;i<nSig;i++) {
422  rhoS[i]=0.;
423  indexS[i]=0;
424  }*/
425  // ig=1;
426  // for(int i=0;i<nSig;i++) rhoS[i]=rhoSig[y][i];
427  gS[y]=new TGraph();
428 // gS[y]->SetMarkerStyle(7);
429  TMath::Sort(nSig,rhoSig[y],indexS[y],false);
430 // cout<<"dopo Sort "<<y<<endl;
431  for (int k=0;k<nSig;k++) {
432  int ii=indexS[y][k];
433  int yy=0;
434  if (k>0){
435 // cout<<"k "<<k<<endl;
436  int ij=indexS[y][k-1];
437  //if(rhoSig[y][ii]!=0&&rhoSig[y][ii]!=rhoSig[y][ij]) {
438  if(rhoSig[y][ii]!=0) {
439  yy=NSig[y]-igS;
440  //gS[y]->SetPoint(igS,rhoSig[y][ii],yy);
441  if(rhoSig[y][ii]!=rhoSig[y][ij]) gS[y]->SetPoint(igS_p++,rhoSig[y][ii],yy);
442  cout<<"igS"<<igS<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
443  igS=igS+1;
444  }
445  }
446  else {
447  if(rhoSig[y][ii]!=0){
448  yy=NSig[y]-igS;
449  gS[y]->SetPoint(0,rhoSig[y][ii],yy);
450  igS=igS+1;
451 // cout<<" x "<<rhoSig[y][ii]<<" y: "<<yy<<endl;
452  }
453 
454  }
455  }
456  }
457  // cout<<"dopo inserimento puntiiS"<<endl;
458 // cout<<ncurve<<endl;
459  int* indexB[ncurve];
460  for (int i=0;i<ncurve;i++) indexB[i]=new int[nBg];
461 
462  TGraph * gB[ncurve];
463  for (int y=0;y<ncurve;y++) {
464  int igB=0;
465  int igB_p=0;
466  gB[y]=new TGraph();
467  TMath::Sort(nBg,rhoBg[y],indexB[y],false);
468 // cout<<"dopo Sort "<<y<<endl;
469  for (int k=0;k<nBg;k++) {
470  int ii=indexB[y][k];
471  int yy=0;
472  if (k>0){
473  int ij=indexB[y][k-1];
474  //if(rhoBg[y][ii]!=0&&rhoBg[y][ii]!=rhoBg[y][ij]) {
475  if(rhoBg[y][ii]!=0) {
476  yy=NBg[y]-igB;
477  //gB[y]->SetPoint(igB,rhoBg[y][ii],yy);
478  if(rhoBg[y][ii]!=rhoBg[y][ij]) gB[y]->SetPoint(igB_p++,rhoBg[y][ii],yy);
479  igB=igB+1;
480 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
481  }
482  }
483  else {
484  if(rhoBg[y][ii]!=0) {
485  yy=NBg[y]-igB;
486  gB[y]->SetPoint(0,rhoBg[y][ii],yy);
487  igB=igB+1;
488 // cout<<"igB"<<igB<<" x "<<rhoBg[y][ii]<<" y: "<<yy<<endl;
489  }
490  }
491  }
492  }
493  cout<<"dopo inserimento puntiB"<<endl;
494  //gB[1]->SetMarkerStyle(7);
495  //gB[1]->SetPoint(1,1,2);
496  TCanvas* cS=new TCanvas("Efficiency_vs_rho","Efficiency_vs_rho",0,0,1200,700);
497  cS->Divide(2,2);
498  cS->cd(1)->SetLogy();
499  TMultiGraph* mg1=new TMultiGraph();
500 // gS[0]->SetMarkerStyle(7);
501  gS[0]->SetMarkerColor(2);
502  gS[0]->SetLineColor(2);
503  mg1->SetTitle("cc=0.5;rho;#Events");
504  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
505 // gS[0]->Draw("apl");
506  for (int h=1;h<nANN;h++){
507  gS[h]->SetMarkerColor(3);
508  gS[h]->SetLineColor(3);
509 // gS[h]->SetMarkerStyle(h+1);
510  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
511  // gS[h]->Draw("apl,same");
512  }
513  mg1->Draw("apl");
514  cS->cd(2)->SetLogy();
515  TMultiGraph* mg2=new TMultiGraph();
516 // gS[nANN]->SetMarkerStyle(7);
517  gS[nANN]->SetMarkerColor(2);
518  gS[nANN]->SetLineColor(2);
519  mg2->SetTitle("cc=0.55;rho;#Events");
520  if(gS[nANN]->GetN()!=0) mg2->Add(gS[nANN]);
521  for (int h=1;h<nANN;h++){
522  gS[nANN+h]->SetMarkerColor(3);
523  gS[nANN+h]->SetLineColor(3);
524 // gS[nANN+h]->SetMarkerStyle(h+1);
525  if(gS[nANN+h]->GetN()!=0) mg2->Add(gS[nANN+h]);
526  // gS[nANN+h]->Draw("apl,same");
527  }
528  mg2->Draw("apl");
529  cS->cd(3)->SetLogy();
530  TMultiGraph* mg3=new TMultiGraph();
531 // gS[nANN*2]->SetMarkerStyle(7);
532  gS[nANN*2]->SetMarkerColor(2);
533  gS[nANN*2]->SetLineColor(2);
534  mg3->SetTitle("cc=0.6;rho;#Events");
535  if(gS[nANN*2]->GetN()!=0) mg3->Add(gS[nANN*2]);
536  for (int h=1;h<nANN;h++){
537  gS[2*nANN+h]->SetMarkerColor(3);
538  gS[2*nANN+h]->SetLineColor(3);
539 // gS[2*nANN+h]->SetMarkerStyle(h+1);
540  if(gS[2*nANN+h]->GetN()!=0) mg3->Add(gS[2*nANN+h]);
541  // gS[2*nANN+h]->Draw("apl,same");
542  }
543  mg3->Draw("apl");
544  cS->cd(4)->SetLogy();
545  TMultiGraph* mg4=new TMultiGraph();
546 // gS[nANN*3]->SetMarkerStyle(7);
547  gS[nANN*3]->SetMarkerColor(2);
548  gS[nANN*3]->SetLineColor(2);
549  mg4->SetTitle("cc=0.65;rho;#Events");
550  if(gS[nANN*3]->GetN()!=0) mg4->Add(gS[nANN*3]);
551  // gS[nANN*3]->Draw("apl");
552  for (int h=1;h<nANN;h++){
553  gS[3*nANN+h]->SetMarkerColor(3);
554  gS[3*nANN+h]->SetLineColor(3);
555 // gS[3*nANN+h]->SetMarkerStyle(h+1);
556  if(gS[3*nANN+h]->GetN()!=0) mg4->Add(gS[3*nANN+h]);
557  // gS[3*nANN+h]->Draw("apl,same");
558  }
559  mg4->Draw("apl");
560  cout<<"nuovo canv"<<endl;
561  TCanvas* cB=new TCanvas("Number_vs_rho","Number_vs_rho",0,0,1200,700);
562  cB->Divide(2,2);
563  cB->cd(1)->SetLogy();
564  TMultiGraph* mg1B=new TMultiGraph();
565 // gB[0]->SetMarkerStyle(7);
566  gB[0]->SetMarkerColor(2);
567  gB[0]->SetLineColor(2);
568  cout<<"ci sono"<<endl;
569  mg1B->SetTitle("cc=0.5;rho;#Events");
570  if(gB[0]->GetN()!=0) mg1B->Add(gB[0]);
571  for (int h=1;h<nANN;h++){
572  gB[h]->SetMarkerColor(3);
573  gB[h]->SetLineColor(3);
574  // gB[h]>SetMarkerStyle(h+1);
575  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
576  //gB[h]->Draw("apl,same");
577  }
578  mg1B->Draw("apl");
579  cB->cd(2)->SetLogy();
580  TMultiGraph* mg2B=new TMultiGraph();
581  //gB[nANN]->SetMarkerStyle(7);
582  gB[nANN]->SetMarkerColor(2);
583  gB[nANN]->SetLineColor(2);
584  mg2B->SetTitle("cc=0.55;rho;#Events");
585  if(gB[nANN]->GetN()!=0) mg2B->Add(gB[nANN]);
586  for (int h=1;h<nANN;h++){
587  gB[nANN+h]->SetMarkerColor(3);
588  gB[nANN+h]->SetLineColor(3);
589  //gB[nANN+h]>SetMarkerStyle(h+1);
590  if(gB[nANN+h]->GetN()!=0) mg2B->Add(gB[nANN+h]);
591  //gB[h]->Draw("apl,same");
592  }
593  mg2B->Draw("apl");
594  cB->cd(3)->SetLogy();
595  TMultiGraph* mg3B=new TMultiGraph();
596 // gB[2*nANN]->SetMarkerStyle(7);
597  gB[2*nANN]->SetMarkerColor(2);
598  gB[2*nANN]->SetLineColor(2);
599  mg3B->SetTitle("cc=0.6;rho;#Events");
600  if(gB[2*nANN]->GetN()!=0) mg3B->Add(gB[2*nANN]);
601  for (int h=1;h<nANN;h++){
602  gB[2*nANN+h]->SetMarkerColor(3);
603  gB[2*nANN+h]->SetLineColor(3);
604 // gB[2*nANN+h]>SetMarkerStyle(h+1);
605  if(gB[2*nANN+h]->GetN()!=0) mg3B->Add(gB[2*nANN+h]);
606  //gB[h]->Draw("apl,same");
607  }
608  mg3B->Draw("apl");
609  cB->cd(4)->SetLogy();
610  TMultiGraph* mg4B=new TMultiGraph();
611 // gB[3*nANN]->SetMarkerStyle(7);
612  gB[3*nANN]->SetMarkerColor(2);
613  gB[3*nANN]->SetLineColor(2);
614  mg4B->SetTitle("cc=0.65;rho;#Events");
615  if(gB[3*nANN]->GetN()!=0) mg4B->Add(gB[3*nANN]);
616  for (int h=1;h<nANN;h++){
617  gB[3*nANN+h]->SetMarkerColor(3);
618  gB[3*nANN+h]->SetLineColor(3);
619 // gB[3*nANN+h]>SetMarkerStyle(h+1);
620  if(gB[3*nANN+h]->GetN()!=0) mg4B->Add(gB[3*nANN+h]);
621  //gB[h]->Draw("apl,same");
622  }
623  mg4B->Draw("apl");
624 
625 // cout<<"dopo Draw()"<<endl;
626  cout<<name<<endl;
627  TString CnameS(name);
628  TString CnameB(name);
629  TString CnameSroot(name);
630  TString CnameBroot(name);
631  char CnameS2[1024];
632  char CnameB2[1024];
633  char CnameS2root[1024];
634  char CnameB2root[1024];
635  cout<<"e ora non più"<<endl;
636  CnameS.ReplaceAll(".root",".png");
637  CnameB.ReplaceAll(".root",".png");
638  cout<<CnameS.Data()<<endl;
639  //sprintf(CnameS2,"logMc_rho/logN_rho_S_dMc%1.2f",deltaMc);
640  sprintf(CnameS2,"logMc_rho/logN_rho_S_dMc%i",deltaMc);
641  //cout<<"e ora non più"<<endl;
642  cout<<CnameS2<<endl;
643  //sprintf(CnameS2,"logMc_rho/logN_rho_S_dMc%1.2f_%s",deltaMc,CnameS.Data());
644  sprintf(CnameS2,"logMc_rho/logN_rho_S_dMc%i_%s",deltaMc,CnameS.Data());
645  cout<<CnameS2<<endl;
646  //sprintf(CnameB2,"logMc_rho/logN_rho_B_dMc%1.2f_%s",deltaMc,CnameB.Data());
647  sprintf(CnameB2,"logMc_rho/logN_rho_B_dMc%i_%s",deltaMc,CnameB.Data());
648  cout<<CnameB2<<endl;
649  //sprintf(CnameS2root,"logMc_rho/logN_rho_S_dMc%1.2f_%s",deltaMc,CnameSroot.Data());
650  sprintf(CnameS2root,"logMc_rho/logN_rho_S_dMc%i_%s",deltaMc,CnameSroot.Data());
651  cout<<CnameS2root<<endl;
652  //sprintf(CnameB2root,"logMc_rho/logN_rho_B_dMc%1.2f_%s",deltaMc,CnameBroot.Data());
653  sprintf(CnameB2root,"logMc_rho/logN_rho_B_dMc%i_%s",deltaMc,CnameBroot.Data());
654  cout<<CnameB2root<<endl;
655  cout<<"e ora non più"<<endl;
656  cS->SaveAs(CnameS2);
657  cB->SaveAs(CnameB2);
658  cS->Print(CnameS2root);
659  cB->Print(CnameB2root);
660  cout<<"e ora non più"<<endl;
661 // cout<<"fine"<<endl;
662 
663 }
664 
665 
667  TString name(ifile);
668  name.ReplaceAll("outfile_Mc/","");
669  TFile* fTEST =TFile::Open(ifile.Data());
670  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
671  double Mc;
672  double out;
673  double cc;
674  double rho;
675  int nSi;
676  NNTree2->SetBranchAddress("Mchirp",&Mc);
677  NNTree2->SetBranchAddress("ANNout",&out);
678  NNTree2->SetBranchAddress("cc",&cc);
679  NNTree2->SetBranchAddress("rho",&rho);
680  NNTree2->SetBranchAddress("#TestSig",&nSi);
681  NNTree2->GetEntry(0);
682  int const nSig=nSi;
683 // cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
684  int const ncurve2=nRHO*nCC;
685 
686 
687  double* ANNSig[ncurve2];
688  for (int i=0;i<ncurve2;i++) ANNSig[i]=new double[nSig];
689  //double rhoSig[20][10];
690  int NSig[ncurve2];
691 // int nBg=0;
692  int const nBg=NNTree2->GetEntries()-nSig;
693  for (int i=0;i<ncurve2;i++) {
694  NSig[i]=0;
695  for (int j=0;j<nSig;j++) ANNSig[i][j]=0.;
696  }
697  double* ANNBg[ncurve2];
698  for (int i=0;i<ncurve2;i++) ANNBg[i]=new double[nBg];
699 
700  //double rhoBg[20][10];
701  int NBg[ncurve2];
702  for (int i=0;i<ncurve2;i++) {
703  NBg[i]=0;
704  for (int j=0;j<nBg;j++) ANNBg[i][j]=0.;
705  }
706  double ccTh[nCC];
707  for (int i=0;i<nCC;i++) ccTh[i]=0.;
708  double rhoTh[nRHO];
709  for (int i=0;i<nRHO;i++) rhoTh[i]=0.;
710  double deltacc=0.;
711  double deltarho=0.;
712  deltacc=0.2/nCC;
713  deltarho=1./(nRHO);
714 
715 
716  for(int n=0;n<NNTree2->GetEntries();n++){
717  NNTree2->GetEntry(n);
718  cout<<"rho "<<rho<<" cc "<<cc<<"Mc "<<Mc<<endl;
719  for(int i=0; i<nCC;i++){
720  ccTh[i]=0.5+i*deltacc;
721  if(cc<ccTh[i]) continue;
722  for(int j=0; j<nRHO;j++){
723  rhoTh[j]=5+j*deltarho;
724  if(rho<rhoTh[j]) continue;
725  int ni=0;
726  if(n>nSig) {
727  NBg[i*nRHO+j]= NBg[i*nRHO+j]+1;
728  while(ANNBg[i*nRHO+j][ni]!=0)ni=ni+1;
729  // ANNBg[i*nRHO+j][ni]=out;
730  ANNBg[i*nRHO+j][ni]=Mc;
731  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
732  }
733  else {
734  NSig[i*nRHO+j]= NSig[i*nRHO+j]+1;
735  while(ANNSig[i*nRHO+j][ni]!=0)ni=ni+1;
736  //ANNSig[i*nRHO+j][ni]=out;
737  ANNSig[i*nRHO+j][ni]=Mc;
738  // cout<<" soglia_cc "<<ccTh[i]<<" soglia_RHO "<<rhoTh[j]<<endl;
739  }
740  }
741  }
742  }
743 
744  int* indexS[ncurve2];
745  for (int i=0;i<ncurve2;i++) indexS[i]=new int[nSig];
746 
747  TGraph * gS[ncurve2];
748  for (int y=0;y<ncurve2;y++) {
749  int igS=0;
750  int igS_p=0;
751  gS[y]=new TGraph();
752  TMath::Sort(nSig,ANNSig[y],indexS[y],false);
753  for (int k=0;k<nSig;k++) {
754  int ii=indexS[y][k];
755  int yy=0;
756  if (k>0){
757  //cout<<"k "<<k<<endl;
758  int ij=indexS[y][k-1];
759  //if(ANNSig[y][ii]!=0&&ANNSig[y][ii]!=ANNSig[y][ij]) {
760  if(ANNSig[y][ii]!=0) {
761  yy=NSig[y]-igS;
762  //gS[y]->SetPoint(igS,ANNSig[y][ii],yy);
763  if(ANNSig[y][ii]!=ANNSig[y][ij]) gS[y]->SetPoint(igS_p++,ANNSig[y][ii],yy);
764  // cout<<"igS"<<igS<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
765  igS=igS+1;
766 
767  }
768  }
769  else {
770  if(ANNSig[y][ii]!=0){
771  yy=NSig[y]-igS;
772  gS[y]->SetPoint(0,ANNSig[y][ii],yy);
773  igS=igS+1;
774  // cout<<" x "<<ANNSig[y][ii]<<" y: "<<yy<<endl;
775  }
776 
777  }
778  }
779  }
780 
781 
782 
783  int* indexB[ncurve2];
784  for (int i=0;i<ncurve2;i++) indexB[i]=new int[nBg];
785 
786  TGraph * gB[ncurve2];
787  for (int y=0;y<ncurve2;y++) {
788  int igB=0;
789  int igB_p=0;
790  gB[y]=new TGraph();
791  TMath::Sort(nBg,ANNBg[y],indexB[y],false);
792  // cout<<"dopo Sort "<<y<<endl;
793  for (int k=0;k<nBg;k++) {
794  int ii=indexB[y][k];
795  int yy=0;
796  if (k>0){
797  int ij=indexB[y][k-1];
798  //if(ANNBg[y][ii]!=0&&ANNBg[y][ii]!=ANNBg[y][ij]) {
799  if(ANNBg[y][ii]!=0) {
800  yy=NBg[y]-igB;
801  //gB[y]->SetPoint(igB,ANNBg[y][ii],yy);
802  if(ANNBg[y][ii]!=ANNBg[y][ij]) gB[y]->SetPoint(igB_p++,ANNBg[y][ii],yy);
803  igB=igB+1;
804  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
805  }
806  }
807  else {
808  if(ANNBg[y][ii]!=0) {
809  yy=NBg[y]-igB;
810  gB[y]->SetPoint(0,ANNBg[y][ii],yy);
811  igB=igB+1;
812  // cout<<"igB"<<igB<<" x "<<ANNBg[y][ii]<<" y: "<<yy<<endl;
813  }
814  }
815  }
816  }
817 
818 
819  TCanvas* cS=new TCanvas("Efficiency_vs_ANN","Efficiency_vs_ANN",0,0,1200,700);
820  cS->Divide(2,2);
821  //cS->cd(1)->SetLogy();
822  cS->cd(1);
823  TMultiGraph* mg1=new TMultiGraph();
824  mg1->SetTitle("cc=0.5;ANN;#Events");
825  for (int h=0;h<nRHO;h++){
826  gS[h]->SetLineColor(4);
827  if(gS[h]->GetN()!=0) mg1->Add(gS[h]);
828  }
829  mg1->Draw("al");
830  cS->cd(2);
831  // cS->cd(2)->SetLogy();
832  TMultiGraph* mg2=new TMultiGraph();
833  mg2->SetTitle("cc=0.55;ANN;#Events");
834  for (int h=0;h<nRHO;h++){
835  gS[nRHO+h]->SetLineColor(4);
836  if(gS[nRHO+h]->GetN()!=0) mg2->Add(gS[nRHO+h]);
837  }
838  mg2->Draw("al");
839 
840  //cS->cd(3)->SetLogy();
841  cS->cd(3);
842  TMultiGraph* mg3=new TMultiGraph();
843  mg3->SetTitle("cc=0.6;Mc;#Events");
844  for (int h=0;h<nRHO;h++){
845  gS[2*nRHO+h]->SetLineColor(4);
846  if(gS[2*nRHO+h]->GetN()!=0) mg3->Add(gS[2*nRHO+h]);
847  }
848  mg3->Draw("al");
849  //cS->cd(4)->SetLogy();
850  cS->cd(4);
851  TMultiGraph* mg4=new TMultiGraph();
852  mg4->SetTitle("cc=0.65;Mc;#Events");
853  for (int h=0;h<nRHO;h++){
854  gS[3*nRHO+h]->SetLineColor(4);
855  if(gS[3*nRHO+h]->GetN()!=0) mg4->Add(gS[3*nRHO+h]);
856  }
857  mg4->Draw("al");
858 
859  TCanvas* cB=new TCanvas("Number_vs_Mc","Number_vs_Mc",0,0,1200,700);
860  cB->Divide(2,2);
861  cB->cd(1)->SetLogy();
862  TMultiGraph* mg1B=new TMultiGraph();
863  mg1B->SetTitle("cc=0.5;Mc;#Events");
864  for (int h=0;h<nRHO;h++){
865  gB[h]->SetLineColor(4);
866  if(gB[h]->GetN()!=0) mg1B->Add(gB[h]);
867  }
868  mg1B->Draw("al");
869  cB->cd(2)->SetLogy();
870  TMultiGraph* mg2B=new TMultiGraph();
871  mg2B->SetTitle("cc=0.55;Mc;#Events");
872  for (int h=0;h<nRHO;h++){
873  gB[nRHO+h]->SetLineColor(4);
874  if(gB[nRHO+h]->GetN()!=0) mg2B->Add(gB[nRHO+h]);
875  }
876  mg2B->Draw("al");
877  cB->cd(3)->SetLogy();
878  TMultiGraph* mg3B=new TMultiGraph();
879  mg3B->SetTitle("cc=0.6;Mc;#Events");
880  for (int h=0;h<nRHO;h++){
881  gB[2*nRHO+h]->SetLineColor(4);
882  if(gB[2*nRHO+h]->GetN()!=0) mg3B->Add(gB[2*nRHO+h]);
883  }
884  mg3B->Draw("al");
885  cB->cd(4)->SetLogy();
886  TMultiGraph* mg4B=new TMultiGraph();
887  mg4B->SetTitle("cc=0.6;Mc;#Events");
888  for (int h=0;h<nRHO;h++){
889  gB[3*nRHO+h]->SetLineColor(4);
890  if(gB[3*nRHO+h]->GetN()!=0) mg4B->Add(gB[3*nRHO+h]);
891  }
892  mg4B->Draw("al");
893 
894 
895  //cout<<"dopo Draw()"<<endl;
896  TString CnameS(name);
897  TString CnameB(name);
898  TString CnameSroot(name);
899  TString CnameBroot(name);
900  char CnameS2[1024];
901  char CnameB2[1024];
902  char CnameS2root[1024];
903  char CnameB2root[1024];
904  CnameS.ReplaceAll(".root",".png");
905  CnameB.ReplaceAll(".root",".png");
906  sprintf(CnameS2,"Mcthres/N_Mc_S_%s",CnameS.Data());
907  sprintf(CnameB2,"Mcthres/N_Mc_B_%s",CnameB.Data());
908  sprintf(CnameS2root,"Mcthres/N_Mc_S_%s",CnameSroot.Data());
909  sprintf(CnameB2root,"Mcthres/N_Mc_B_%s",CnameBroot.Data());
910  cS->SaveAs(CnameS2);
911  cB->SaveAs(CnameB2);
912  cS->Print(CnameS2root);
913  cB->Print(CnameB2root);
914  //cout<<"fine"<<endl;
915 
916 //CARTELLA Annth
917 
918 
919 
920 }
921 
922 
924  TString name(ifile);
925  name.ReplaceAll("outfile/","");
926  TFile* fTEST =TFile::Open(ifile.Data());
927  TTree* NNTree2=(TTree*)fTEST->Get("Parameters");
928  double Mc;
929  double out;
930  double cc;
931  double rho;
932  int nSi;
933  NNTree2->SetBranchAddress("Mchirp",&Mc);
934  NNTree2->SetBranchAddress("ANNout",&out);
935  NNTree2->SetBranchAddress("cc",&cc);
936  NNTree2->SetBranchAddress("rho",&rho);
937  NNTree2->SetBranchAddress("#TestSig",&nSi);
938  NNTree2->GetEntry(0);
939  int const nSig=nSi;
940  cout<<"nSig: "<<nSig<<" nSi: "<<nSi<<endl;
941  int const nBg=NNTree2->GetEntries()-nSig;
942 
943 /* TH2D* hglitch=new TH2D("Purezza","Purezza",NCC,minCC,maxCC,NRHO,minRHO,maxRHO);
944  TH2D* h2BgO_R=new TH2D("rho_cc_out","rho_cc_out",50,0.,50,50,-0.5,1.5);
945  TH2D* h2SigO_R=new TH2D("rho_cc_out","rho_cc_out",50,0.,50,50,-0.5,1.5);
946  TH2D* h2BgR_C=new TH2D("rho_cc_out","rho_cc_out",50,0.,1.2,50,0.,50);
947  TH2D* h2SigR_C=new TH2D("rho_cc_out","rho_cc_out",50,0.,1.2,50,0.,50);
948  TH2D* h2Bg=new TH2D("rho_cc_out","rho_cc_out",50,0.,1.2,50,-0.5,1.5);
949  TH2D* h2Sig=new TH2D("rho_cc_out","rho_cc_out",50,0.,1.2,50,-0.5,1.5);
950  h2BgO_R->SetDirectory(0);
951  h2SigO_R->SetDirectory(0);
952  h2BgR_C->SetDirectory(0);
953  h2SigR_C->SetDirectory(0);
954  h2Bg->SetDirectory(0);
955  h2Sig->SetDirectory(0);
956  hglitch->SetDirectory(0);
957 */
958 
959  TGraph * gS[3];
960  TGraph * gB[3];
961  gB[0]=new TGraph();
962  gS[0]=new TGraph();
963  gB[1]=new TGraph();
964  gS[1]=new TGraph();
965  gB[2]=new TGraph();
966  gS[2]=new TGraph();
967  double aANNS[nSig];
968  double aRHOS[nSig];
969  double aCCS[nSig];
970  for (int i=0;i<nSig;i++){
971  aCCS[i]=0.;
972  aRHOS[i]=0.;
973  aANNS[i]=0.;
974  }
975  double aANNB[nBg];
976  double aRHOB[nBg];
977  double aCCB[nBg];
978  for (int i=0;i<nBg;i++){
979  aCCB[i]=0.;
980  aRHOB[i]=0.;
981  aANNB[i]=0.;
982  }
983 // cout<<"nSig: "<<nSig<<endl;
984  for (int n = 0; n <NNTree2->GetEntries(); n++){
985  NNTree2->GetEntry(n);
986  if(n<nSig) {
987  aRHOS[n]=rho;
988  //aANNS[n]=out;
989  aANNS[n]=Mc;
990  aCCS[n]=cc;
991 /* gS[0]->SetPoint(n,cc,rho);
992  gS[1]->SetPoint(n,cc,out);
993  gS[2]->SetPoint(n,rho,out);
994  cout<<"Sig_graph1: x="<<cc<<" y: "<<rho<<endl;
995  cout<<"Sig_graph2: x="<<cc<<" y: "<<out<<endl;
996  cout<<"Sig_graph3: x="<<rho<<" y: "<<out<<endl;
997 */
998  }
999  else {
1000  aRHOB[n-nSig]=rho;
1001  //aANNB[n-nSig]=out;
1002  aANNB[n-nSig]=Mc;
1003  aCCB[n-nSig]=cc;
1004 /* gB[0]->SetPoint(n-nSig,cc,rho);
1005  gB[1]->SetPoint(n-nSig,cc,out);
1006  gB[2]->SetPoint(n-nSig,rho,out);
1007  cout<<"Bg_graph1: x="<<cc<<" y: "<<rho<<endl;
1008  cout<<"Bg_graph2: x="<<cc<<" y: "<<out<<endl;
1009  cout<<"Bg_graph3: x="<<rho<<" y: "<<out<<endl;
1010 */
1011  }
1012  }
1013 
1014  int indexB[nBg];
1015  for (int k=0;k<nBg;k++)indexB[k]=0;
1016  TMath::Sort(nBg,aRHOB,indexB,false);
1017  int Z[(nth+1)*nth];
1018  for (int k=0;k<(nth+1)*nth;k++)Z[k]=0;
1019  double cc1th[nth];
1020  double ANN1th[nth+1];
1021  ANN1th[0]=0.;
1022  for (int k=0;k<(nth);k++){
1023  ANN1th[k+1]=0.;
1024  cc1th[k]=0.;
1025  }
1026  double dANNth=0.;
1027  double dccth=0.;
1028 // dANNth=1./nth;
1029  dccth=0.5/nth;
1030  ANN1th[0]=-100.;
1031  for (int k=0;k<(nth);k++){
1032  //ANN1th[k+1]=0.+dANNth*(k+1);
1033  ANN1th[k+1]=0.+deltaMc*(k+1);
1034  cc1th[k]=0.5+dccth*k;
1035  }
1036 
1037  /*for (int a=0;a<nBg;a++){
1038  if(aRHOB[a]>=RHOth){
1039  for (int b=0;b<nth;b++){
1040  if(aCCB[a]>=cc1th[b]){
1041  for(int c=0;c<nth+1;c++){
1042  if(aANNB[a]>=ANN1th[c]) Z[b*nth+c]=Z[b*nth+c]+1;
1043  if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*nth+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1044  }
1045  }
1046  }
1047  }
1048  }*/
1049  for (int a=0;a<nBg;a++){
1050  cout<<"tutti: a "<<a<<" rho "<<aRHOB[a]<<" aNNB "<<aANNB[a]<<" cc "<<aCCB[a]<<endl;
1051  if(aRHOB[a]<RHOth)continue;
1052  cout<<"dopo rho: a "<<a<<" rho "<<aRHOB[a]<<" aNNB "<<aANNB[a]<<" cc "<<aCCB[a]<<endl;
1053  for (int b=0;b<nth;b++){
1054  if(aCCB[a]<cc1th[b])continue;
1055  cout<<"dopo cc: "<<cc1th[b]<<"a "<<a<<" rho "<<aRHOB[a]<<" aNNB "<<aANNB[a]<<" cc "<<aCCB[a]<<endl;
1056  for(int c=0;c<nth+1;c++){
1057  if(aANNB[a]<ANN1th[c]) continue;
1058  cout<<"dopo ANN:"<<ANN1th[c]<<" a "<<a<<" rho "<<aRHOB[a]<<" aNNB "<<aANNB[a]<<" cc "<<aCCB[a]<<endl;
1059  Z[b*(nth+1)+c]=Z[b*(nth+1)+c]+1;
1060  cout<<"Zindex: "<<b*(nth+1)+c<<" Z: "<<Z[b*(nth+1)+c]<<endl;
1061 
1062  //if(c=10) cout<<" ANN "<<ANN1th[c]<<" Zcount: "<<Z[b*(nth+1)+c]<<" aNNB "<<aANNB[a]<<" a "<<a<<" b "<<b<<endl;
1063  }
1064 
1065  }
1066 
1067  }
1068 
1069  //TH2D* hglitch=new TH2D("Survived_glitches(RHO_cut:5.5)","Survived_glitches(RHO_cut:5.5)",nth,0.5,1,nth+1,-1,1);
1070  double bins[nth+1];
1071  for (int d=0; d<nth+1;d++) bins[d]=0.;
1072  //bins[0]=0.;
1073  //for (int d=0; d<nth+1;d++) bins[d+1]=0.+(d+1)*dANNth;
1074  for (int d=0; d<nth+1;d++) bins[d+1]=0.+(d+1)*deltaMc;
1075  TH2D* hglitch=new TH2D("Survived_glitches(RHO_cut:5.5)","Survived_glitches(RHO_cut:5.5)",nth,0.5,1,nth+1,bins);
1076 // TH2D* hglitch=new TH2D("Survived_glitches(RHO_cut:5.5)","Survived_glitches(RHO_cut:5.5)",nth,0.5,1,nth+1,0.,1.);
1077  hglitch->SetDirectory(0);
1078  //if(tot[NRHO*ii+ji]>0) hglitch->Fill(cc1[ji]+deltacc/2,rho1[ii]+deltarho/2,pur[NRHO*ii+ji]);
1079  for (int b=0;b<nth;b++) for(int c=0;c<nth+1;c++) {
1080  //hglitch->Fill(cc1th[b]+dccth/2.,ANN1th[c]+dANNth/2.,Z[(nth+1)*b+c]);
1081  //hglitch->Fill(cc1th[b]+dccth/2.,bins[c]+dANNth/2.,Z[(nth+1)*b+c]);
1082  hglitch->Fill(cc1th[b]+dccth/2.,bins[c]+deltaMc/2.,Z[(nth+1)*b+c]);
1083  cout<<" Zindex: "<<(nth+1)*b+c<< " x: "<<cc1th[b]<<" y: "<<ANN1th[c]<<" z: "<<Z[(nth+1)*b+c]<<endl;
1084  }
1085 
1086  gB[0]=new TGraph(nBg,aCCB,aRHOB);
1087  gS[0]=new TGraph(nSig,aCCS,aRHOS);
1088  gB[1]=new TGraph(nBg,aCCB,aANNB);
1089  gS[1]=new TGraph(nSig,aCCS,aANNS);
1090  gB[2]=new TGraph(nBg,aRHOB,aANNB);
1091  gS[2]=new TGraph(nSig,aRHOS,aANNS);
1092 
1093  for(int i=0;i<3;i++){
1094  gS[i]->SetMarkerColor(2);
1095  gB[i]->SetMarkerColor(4);
1096  gS[i]->SetMarkerStyle(6);
1097  gB[i]->SetMarkerStyle(7);
1098  }
1099 
1100  TCanvas* c=new TCanvas("Plots","Plots",0,0,1200,700);
1101  c->Divide(2,2);
1102  c->cd(1);
1103  TMultiGraph* mg1=new TMultiGraph();
1104  mg1->SetTitle("cc_rho;cc;rho");
1105  if(gB[0]->GetN()!=0) mg1->Add(gB[0]);
1106  if(gS[0]->GetN()!=0) mg1->Add(gS[0]);
1107  mg1->Draw("ap");
1108  c->cd(2);
1109  TMultiGraph* mg2=new TMultiGraph();
1110  mg2->SetTitle("cc_Mcoutput;cc;Mcoutput");
1111  if(gB[1]->GetN()!=0) mg2->Add(gB[1]);
1112  if(gS[1]->GetN()!=0) mg2->Add(gS[1]);
1113  mg2->Draw("ap");
1114  c->cd(3);
1115  TMultiGraph* mg3=new TMultiGraph();
1116  mg3->SetTitle("rho_Mcoutput;rho;Mcoutput");
1117  if(gB[2]->GetN()!=0) mg3->Add(gB[2]);
1118  if(gS[2]->GetN()!=0) mg3->Add(gS[2]);
1119  mg3->Draw("ap");
1120  c->cd(4);
1121  TText* text=new TText(0.37,0.0,"no cuts on Mc");
1122  hglitch->SetStats(0);
1123  hglitch->GetXaxis()->SetTitle("cc");
1124  hglitch->GetYaxis()->SetTitle("Mcoutput");
1125  hglitch->GetZaxis()->SetTitle("count");
1126  hglitch->Draw("colz");
1127  text->Draw();
1128  gPad->SetLogz();
1129 
1130  TString Cname(name);
1131  TString Cnameroot(name);
1132  char Cname2[1024];
1133  char Cname2root[1024];
1134  Cnameroot.ReplaceAll("outfile_Mc/","");
1135  Cname.ReplaceAll("outfile_Mc/","");
1136  Cname.ReplaceAll(".root",".png");
1137  sprintf(Cname2,"CC_RHO_Mc_Plots/CC_RHO_Mc_Plots_%s",Cname.Data());
1138  sprintf(Cname2root,"CC_RHO_Mc_Plots/CC_RHO_Mc_Plots_%s",Cnameroot.Data());
1139  c->SaveAs(Cname2);
1140  c->Print(Cname2root);
1141 
1142  TCanvas* c2=new TCanvas("Plots_Bkg_on_Sig","Plots_Bkg_on_Sig",0,0,1200,700);
1143  c2->Divide(2,2);
1144  c2->cd(1);
1145  gS[0]->Draw("ap");
1146  gB[0]->Draw("p,same");
1147 
1148  c2->cd(2);
1149  gS[1]->Draw("ap");
1150  gB[1]->Draw("p,same");
1151  c2->cd(3);
1152  gS[2]->Draw("ap");
1153  gB[2]->Draw("p,same");
1154  c2->cd(4);
1155  TText* text2=new TText(0.37,0.0,"no cuts on Mc");
1156  hglitch->SetStats(0);
1157  hglitch->GetXaxis()->SetTitle("cc");
1158  hglitch->GetYaxis()->SetTitle("Mcoutput");
1159  hglitch->GetZaxis()->SetTitle("count");
1160  hglitch->Draw("colz");
1161  text2->Draw();
1162  gPad->SetLogz();
1163 
1164  TString Cname_2(name);
1165  TString Cname_2root(name);
1166  char Cname2_2[1024];
1167  char Cname2_2root[1024];
1168  Cname_2.ReplaceAll("outfile_Mc/","");
1169  Cname_2root.ReplaceAll("outfile_Mc/","");
1170  Cname_2.ReplaceAll(".root",".png");
1171  sprintf(Cname2_2,"CC_RHO_Mc_Plots/CC_RHO_Mc_Plots_BoS_%s",Cname_2.Data());
1172  sprintf(Cname2_2root,"CC_RHO_Mc_Plots/CC_RHO_Mc_Plots_BoS_%s",Cname_2root.Data());
1173  c2->SaveAs(Cname2_2);
1174  c2->Print(Cname2_2root);
1175 
1176 //CARTELLA CCi_RHO_ANN_Plots
1177 }
1178 
char ofile[1024]
void Test0_Mchirp(TString NN_FILE, TString TEST_FILE, int TS=0, int TB=0, int s=0, int b=0, int uf=0)
Definition: Test0_Mchirp.C:56
double rho
Float_t * rho
biased null statistics
Definition: netevent.hh:112
#define nIFO
Definition: Test0_Mchirp.C:42
#define RHOth
Definition: Test0_Mchirp.C:48
TCanvas * c2
wavearray< double > a(hp.size())
par [0] name
int n
Definition: cwb_net.C:28
TString("c")
#define nth
Definition: Test0_Mchirp.C:49
#define nCC
Definition: Test0_Mchirp.C:46
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.
int j
Definition: cwb_net.C:28
i drho i
cout<< fileout<< endl;out.open(fileout, ios::out);if(!out.good()) { cout<< "cwb_mkhtml_cbc.C : Error Opening File : "<< fileout<< endl;exit(1);} out<< "<br><br><< endl; MakePlotsHtmlCellTable(&out, "Sensitive distance for M< sub > total</sub > bins
wavearray< double > hh
Definition: Regression_H1.C:73
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
#define nANN
Definition: Test0_Mchirp.C:44
void Plots(TString ifile)
Definition: Test0_Mchirp.C:923
TText * text
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
void Annth(TString ifile)
Definition: Test0_Mchirp.C:666
char output[256]
int k
Float_t * netcc
effective correlated SNR
Definition: netevent.hh:113
TFile * ifile
wavearray< double > yy
Definition: TestFrame5.C:12
s s
Definition: cwb_net.C:155
void graph(TString ifile)
Definition: Test0_Mchirp.C:324
#define nRHO
Definition: Test0_Mchirp.C:43
#define deltarho
#define deltaMc
Definition: Test0_Mchirp.C:45
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
#define iMc
Definition: Test0_Mchirp.C:50
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
#define deltacc
Float_t * chirp
range to source: [0/1]-rec/inj
Definition: netevent.hh:128
exit(0)