Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_slag_bkg.C
Go to the documentation of this file.
1 {
2 #define NBINS 1100
3 #define BINMIN 4.50
4 #define BINMAX 114.5
5 #define REBIN_MIN_EVTS_PER_BIN 30.0
6 #define NSLAG_ORDER 5
7  //cout<<"slag starts..."<<endl;
8 
9  if(nIFO>3) {cout << "slag.C : Skipping plot production - wave tree should come from a 2- or 3-fold network : " << net_file_name << endl;exit(0);}
10 
11  int NSLAG = pow(2,NSLAG_ORDER);
12  //CWB::Toolbox TB;
13 
14  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
15  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
16  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
17  TB.checkFile(gSystem->Getenv("CWB_PPARAMETERS_FILE"));
18  TB.checkFile(gSystem->Getenv("CWB_UPPARAMETERS_FILE"));
19  TB.checkFile(gSystem->Getenv("CWB_EPPARAMETERS_FILE"));
20 
21  gStyle->SetTitleFillColor(kWhite);
22  gStyle->SetLineColor(kWhite);
23  gStyle->SetNumberContours(256);
24  gStyle->SetCanvasColor(kWhite);
25  gStyle->SetStatBorderSize(1);
26  gStyle->SetOptStat(kFALSE);
27 
28  // remove the red box around canvas
29  gStyle->SetFrameBorderMode(0);
30  gROOT->ForceStyle();
31 
32 
33  // ----------------------------------------------------------
34  // canvas
35  // ----------------------------------------------------------
36  TCanvas *c1 = new TCanvas("Slag", "Slag",32,55,750,502);
37  c1->Range(-0.75,-1.23433,6.75,8.17182);
38  c1->SetBorderSize(1);
39  c1->SetFillColor(0);
40  c1->SetGridx();
41  c1->SetGridy();
42  c1->SetFrameFillColor(0);
43  gStyle->SetPalette(1,0);
44 
45  TChain wave("waveburst");
46  TChain live("liveTime");
47 
48  wave.Add(net_file_name);
49  live.Add(liv_file_name);
50 
51  // check if slag is presents in liv tree
52  TBranch* branch;
53  bool slagFound=false;
54  TIter mynext(wave.GetListOfBranches());
55  while ((branch=(TBranch*)mynext())) {
56  if (TString("slag").CompareTo(branch->GetName())==0) slagFound=true;
57  }
58  mynext.Reset();
59  if(!slagFound) {cout << "slag.C : Error - wave tree does not contain slag leaf : " << net_file_name << endl;exit(1);}
60 
61  char fname[1024];
62 char cut[512];
63 char cut2[256];
64 
65 sprintf(cut,"rho[1]>%f",T_cut);
66 //test if vetoes are applied
68 if(!test_veto.IsNull())sprintf(cut,"%s && %s",cut,veto_not_vetoed);
69 sprintf(cut2,"!(lag[%d]==0&&slag[%d]==0)",nIFO,nIFO);
70 
71  int num = (int)wave.GetEntries(cut);
72  wave.SetEstimate(num);
73  TString sel("slag[1]:rho[1]");
74  //TString sel("slag[1]:slag[2]");
75  // sel+= TString::Itoa(nIFO-2,10);
76  // sel+="]:slag[";
77  // sel+=Itoa(nIFO-1,10);
78  // sel+="]";
79  // if(nIFO==2) {sel.ReplaceAll("1","0");sel.ReplaceAll("2","1");}
80  // TString sel="slag[1]:slag[2]";
81  wave.Draw(sel,cut,"goff");
82  cout<<"Number of Entries: "<<num<<endl;
83  double* slag1 = wave.GetV1();
84  double* rho = wave.GetV2();
85 
86 
87  int num2 = (int)live.GetEntries(cut2);
88  live.SetEstimate(num2);
89  //sel+=":live";
90  live.Draw("slag[1]:live",cut2,"goff");
91  double* lslag1 = live.GetV1();
92  //double* lslag2 = live.GetV2();
93  double* Live = live.GetV2();
94 
95  char mytitle[256];
96  double SlagMax = wave.GetMaximum("slag")+segLen/2.;
97  double SlagMin = wave.GetMinimum("slag")-segLen/2.;
98  int NSlag = TMath::FloorNint((SlagMax-SlagMin)/segLen);
99  cout << "SLAG MAX : "<< wave.GetMaximum("slag")<< " s SLAG MIN : "<< wave.GetMinimum("slag")<< " s #SLAGS : "<<NSlag-1<<endl;
100 sprintf(mytitle,"FAR distribution over slags (post cat3 & rho>%f)",T_cut);
101  TH2F* Slag = new TH2F("SLAG",mytitle,NBINS,BINMIN,BINMAX,NSLAG,SlagMin,SlagMax);
102  Slag->GetYaxis()->SetTitle("slag[1] shift [s]");
103  //Slag->GetXaxis()->SetNdivisions(10,kFALSE);
104  Slag->GetXaxis()->SetTitle("rho");
105  //Slag->GetYaxis()->SetNdivisions(10,kFALSE);
106  Slag->SetStats(kFALSE);
107  TH1F* lSlag = new TH1F("LSLAG","FAR distribution over slags",NSLAG,SlagMin,SlagMax);
108  for(int i =0 ;i<num;i++){
109  Slag->Fill(rho[i],slag1[i]);
110 
111  }
112  for(int i =0 ;i<num2;i++){
113  lSlag->Fill(lslag1[i],Live[i]);
114 
115  }
116 
117 TH1D* P0 = new TH1D("P0","P0",100,0.0,1.0);
118 //TH1D* P1 = new TH1D("P1","P1",NBINS,BINMIN,BINMAX);
119 double Pval[NSLAG-1];
120 int test = 0;
121 
122 for(int j =0 ;j<NSLAG/2;j++){
123  for(int i =1 ;i<NSLAG;i++){
124  TH1D* P1 = (TH1D*) Slag->ProjectionX("",i,i+j)->Clone();
125  //P[i-1]= (TH1D*)Px0->Clone();
126  //P1->Scale(1./lSlag->GetBinContent(i));
127  //TH1D* P2 = (TH1D*) Slag->ProjectionX("",i+1,i+1)->Clone();
128  //P[i]= (TH1D*)Px0->Clone();
129  //P2->Scale(1./lSlag->GetBinContent(i+1));
130  P1->AndersonDarlingTest(Slag->ProjectionX("",i+j+1,i+2*j+1));
131 // Pval= Slag->ProjectionX("",i,i)->AndersonDarlingTest(Slag->ProjectionX("",i+1,i+1));
132  cout <<j<<" "<<i<<" bins ["<<i<<","<<i+j<<"] bins ["<<i+j+1<<","<<i+2*j+1<<"]"<<endl;
133  // cout <<" Anderson-Darling test (no rescaling) "<<Pval<<endl;
134  // P0->Fill(Pval);
135  const Int_t nq = P1->GetEntries()/REBIN_MIN_EVTS_PER_BIN; cout<<"Rebinning to "<<nq<<" bins"<<endl;
136  Double_t* xq = new Double_t[nq]; // position where to compute the quantiles in [0,1]
137  Double_t* yq = new Double_t[nq];
138  Double_t* yq2 = new Double_t[nq+3];
139  for (Int_t k=0;k<nq;k++) xq[k] = Float_t(k+1)/nq;
140  P1->GetQuantiles(nq,yq,xq);
141 
142  for(int l=1;l<nq+2;l++){yq2[l]=yq[l-2];}
143  yq2[0]= BINMIN;
144  yq2[1]= T_cut;
145  yq2[nq+2]= BINMAX;
146 
147  TH1D *hnew2 = new TH1D("hnew2","rebinned",nq+2,yq2);
148  TH1D *hnew3 = new TH1D("hnew3","rebinned",nq+2,yq2);
149  TH1D* Sh3 = new TH1D("Sh3","Significance vs rho bin",nq+2,yq2);
150  TH1D* Sh4 = new TH1D("Sh4","Distribution of significance",200,-10.,10.);
151  TH1D* Shn = new TH1D("Shn","Normal Distribution",200,-10.,10.);
152  TRandom3 P;
153  P.SetSeed(1234.);
154  for(int m=0;m<num;m++){
155  if((slag1[m]>=Slag->GetYaxis()->GetBinLowEdge(i))&&(slag1[m]<Slag->GetYaxis()->GetBinUpEdge(i+j))) {hnew2->Fill(rho[m]);}
156  if((slag1[m]>=Slag->GetYaxis()->GetBinLowEdge(i+j+1))&&(slag1[m]<Slag->GetYaxis()->GetBinUpEdge(i+2*j+1))) {hnew3->Fill(rho[m]);}
157 
158  }
159 
160  cout<<"After Rebinning"<<endl;
161  // cout <<"Anderson-Darling test (no rescaling)"<<endl;
162  Pval[test]= hnew2->AndersonDarlingTest(hnew3,"D");
163  double w_tmp;
164  //double w[nq];
165  int count =0;
166  for(int n=0;n<nq;n++){
167  if((hnew2->GetBinContent(n+1)>0.0) ||(hnew3->GetBinContent(n+1)>0.0)){
168  w_tmp = (hnew2->GetBinContent(n+1)-hnew3->GetBinContent(n+1))/TMath::Sqrt(pow(hnew2->GetBinError(n+1),2)+pow(hnew3->GetBinError(n+1),2));
169  Sh3->SetBinContent(n+1,w_tmp);
170  Sh4->Fill(Sh3->GetBinContent(n+1));
171  // w[n]=w_tmp;
172  count++;
173  }
174  // else{Sh3->SetBinContent(n+1,0.0);w[n]=0.0;}
175  }
176  for(int n=0;n<count;n++){Shn->Fill(P.Gaus(0,1));}
177  cout <<"Anderson-Darling 2-sample test significance distribution vs Normal (no rescaling)"<<endl;
178  // Pval[test]=Sh4->AndersonDarlingTest(Shn,"D");
179  Sh4->AndersonDarlingTest(Shn,"D");
180 
181  //ROOT::Math::GoFTest* goftest_1 = new ROOT::Math::GoFTest(count, w, ROOT::Math::GoFTest::kGaussian);
182  //Double_t pvalueAD_1 = goftest_1-> AndersonDarlingTest();
183  //cout <<"Anderson-Darling 1-sample test significance distribution vs Normal (no rescaling) : "<<pvalueAD_1<<endl;
184  /*hnew2->Delete();
185  hnew3->Delete();
186  Sh3->Delete();
187  Sh4->Delete();
188  Shn->Delete();*/
189  //delete w;
190 
191  P0->Fill(Pval[test]);
192  test++;
193  i+=2*j+1;
194  //Slag->ProjectionX("",i,i)->AndersonDarlingTest(Slag->ProjectionX("",i+1,i+1),"D");
195  //P0->AndersonDarlingTest(P1,"D");
196  }
197  j+=j;
198 }
199 
200 Int_t *index = new Int_t[test];
201 TMath::Sort(test,Pval,index,false);
202 
203 float *pvals = new float[test];
204 float *rank = new float[test];
205 for(int i=0;i<test;i++){pvals[i]=Pval[index[i]];rank[i]=(i+1.)/test;cout<<pvals[i]<<" "<<rank[i]<<endl;}
206 TGraph Gr(test,rank,pvals);
207 Gr.Draw("alp");
208 //P0->Draw();
209 
210  //Slag->Divide(lSlag);
211  //c1->Clear();
212  //Slag->Draw("colz");
213  //sprintf(fname,"%s/slag.png",netdir);
214  //c1->Update(); c1->SaveAs(fname);
215 /*
216  TAxis *xaxis = Slag->GetXaxis();
217  TAxis *yaxis = Slag->GetYaxis();
218  int mycount = 0;
219  double FAR[1000];
220  double eFAR[1000];
221  double D[1000];
222  for(int i =1 ;i<NSlag+1;i++){
223  for(int j =1 ;j<NSlag+1;j++){
224  if(Slag->GetBinContent(i,j)>=1.E-15){
225  FAR[mycount] = Slag->GetBinContent(i,j);
226  D[mycount] = TMath::Sqrt(pow(xaxis->GetBinCenter(i),2)+pow(yaxis->GetBinCenter(j),2));
227  //D[mycount] = yaxis->GetBinCenter(j);
228  eFAR[mycount] = Slag->GetBinError(i,j)/lSlag->GetBinError(i,j);
229  mycount++;
230  cout << "slag[1] :"<<xaxis->GetBinCenter(i)<<" slag[2] :"<<yaxis->GetBinCenter(j) <<" FAR :"<<FAR[mycount-1] << "+/-" <<eFAR[mycount-1] << " " <<endl;
231  }
232 
233  }
234  }
235 
236 
237  cout << "Number of slags : " << mycount << endl;
238  double liveTot = lSlag->GetSumOfWeights();
239  double liveMax = lSlag->GetMaximum();
240  cout << "Total BKG live time : " << liveTot << endl;
241  //const int mycount2=mycount;
242  double* FAR2 = new double[mycount];
243  double* eFAR2 = new double[mycount];
244  double* N = new double[mycount];
245  double* eN = new double[mycount];
246  for(int i =0 ;i<mycount;i++){N[i]=D[i];}
247  Int_t *myindex = new Int_t[mycount];
248  TMath::Sort(mycount,N,myindex,false);
249  for(int i =0 ;i<mycount;i++){FAR2[i]=FAR[myindex[i]];eFAR2[i]=eFAR[myindex[i]];N[i]=D[myindex[i]];eN[i]=0.0;}
250  TGraphErrors* FarPlot= new TGraphErrors(mycount, N, FAR2, eN, eFAR2);
251  FarPlot->SetLineColor(kBlue);
252  FarPlot->SetMarkerColor(kBlue);
253  //FarPlot->GetHistogram()->GetYaxis()->SetRangeUser(1.e-9,1.e-7);
254  FarPlot->SetTitle("FAR vs slag distance");
255  FarPlot->SetMarkerStyle(20);
256  FarPlot->SetMarkerSize(1);
257  //FarPlot->SetMinimum(0.5/liveMax);
258  FarPlot->GetHistogram()->SetXTitle("#slag distance [s]");
259  FarPlot->GetHistogram()->SetYTitle("rate, Hz");
260  c1->Clear();
261  c1->SetLogy(kFALSE);
262  gStyle->SetOptStat();
263  gStyle->SetOptFit();
264 
265  FarPlot->Draw("AP");
266  FarPlot->Fit("pol1");
267  sprintf(fname,"%s/FAR_vs_slag.png",netdir);
268  c1->Update(); c1->SaveAs(fname);
269  gStyle->SetOptStat(kFALSE);
270  gStyle->SetOptFit(kFALSE);
271  exit(0);
272 */
273 }
TChain wave("waveburst")
double rho
char cut[512]
yq2[0]
Definition: compare_bkg.C:289
TCanvas * c1
double Live
float * rank
#define BINMAX
int n
Definition: cwb_net.C:10
TString("c")
int count
Definition: compare_bkg.C:373
TGraph Gr(test, rank, pvals)
#define BINMIN
TRandom3 P
Definition: compare_bkg.C:296
s veto_not_vetoed
int m
Definition: cwb_net.C:10
int j
Definition: cwb_net.C:10
i drho i
TIter mynext(wave.GetListOfBranches())
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
CWB::Toolbox TB
Definition: ComputeSNR.C:5
const Int_t nq
Definition: compare_bkg.C:281
#define nIFO
double Pval[NSLAG-1]
TH1D * hnew3
Definition: compare_bkg.C:292
bool slagFound
i() int(T_cor *100))
Int_t * index
TH1D * hnew2
Definition: compare_bkg.C:291
const Float_t * yq
segLen
Definition: cwb_eced.C:7
int k
TH1D * P0
int test
TH1F * lSlag
float * pvals
double w_tmp
Definition: compare_bkg.C:371
int num
char net_file_name[256]
sprintf(cut,"rho[1]>%f", T_cut)
char liv_file_name[256]
char cut2[256]
#define NBINS
TString test_veto
TString sel("slag[1]:rho[1]")
#define NSLAG_ORDER
char fname[1024]
TH1D * Sh3
Definition: compare_bkg.C:293
int l
Definition: cbc_plots.C:434
TBranch * branch
double T_cut
TH1D * Shn
Definition: compare_bkg.C:295
#define REBIN_MIN_EVTS_PER_BIN
TChain live("liveTime")
const Float_t xq[6]
exit(0)
TH1D * Sh4
Definition: compare_bkg.C:294