Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
slag.C
Go to the documentation of this file.
1 {
2 
3  cout<<"slag starts..."<<endl;
4 
5  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);}
6 
7  //CWB::Toolbox TB;
8 
9  TB.checkFile(gSystem->Getenv("CWB_ROOTLOGON_FILE"));
10  TB.checkFile(gSystem->Getenv("CWB_PARAMETERS_FILE"));
11  TB.checkFile(gSystem->Getenv("CWB_UPARAMETERS_FILE"));
12  TB.checkFile(gSystem->Getenv("CWB_PPARAMETERS_FILE"));
13  TB.checkFile(gSystem->Getenv("CWB_UPPARAMETERS_FILE"));
14  TB.checkFile(gSystem->Getenv("CWB_EPPARAMETERS_FILE"));
15 
16  gStyle->SetTitleFillColor(kWhite);
17  gStyle->SetLineColor(kWhite);
18  gStyle->SetNumberContours(256);
19  gStyle->SetCanvasColor(kWhite);
20  gStyle->SetStatBorderSize(1);
21  gStyle->SetOptStat(kFALSE);
22 
23  // remove the red box around canvas
24  gStyle->SetFrameBorderMode(0);
25  gROOT->ForceStyle();
26 
27 
28  // ----------------------------------------------------------
29  // canvas
30  // ----------------------------------------------------------
31  TCanvas *c1 = new TCanvas("Slag", "Slag",32,55,750,502);
32  c1->Range(-0.75,-1.23433,6.75,8.17182);
33  c1->SetBorderSize(1);
34  c1->SetFillColor(0);
35  c1->SetGridx();
36  c1->SetGridy();
37  c1->SetFrameFillColor(0);
38  gStyle->SetPalette(1,0);
39 
40  TChain wave("waveburst");
41  TChain live("liveTime");
42 
43  wave.Add(net_file_name);
44  live.Add(liv_file_name);
45 
46  // check if slag is presents in liv tree
47  TBranch* branch;
48  bool slagFound=false;
49  TIter mynext(wave.GetListOfBranches());
50  while ((branch=(TBranch*)mynext())) {
51  if (TString("slag").CompareTo(branch->GetName())==0) slagFound=true;
52  }
53  mynext.Reset();
54  if(!slagFound) {cout << "slag.C : Error - wave tree does not contain slag leaf : " << net_file_name << endl;exit(1);}
55 
56  char fname[1024];
57 char cut[512];
58 char cut2[256];
59 
60 sprintf(cut,"rho[1]>%f",T_cut);
61 //test if vetoes are applied
63 if(!test_veto.IsNull())sprintf(cut,"%s && %s",cut,veto_not_vetoed);
64 sprintf(cut2,"!(lag[%d]==0&&slag[%d]==0)",nIFO,nIFO);
65  long int num = wave.GetEntries();
66  wave.SetEstimate(num);
67  // TString sel("slag[");
68  TString sel("slag[1]:slag[2]");
69  // sel+= TString::Itoa(nIFO-2,10);
70  // sel+="]:slag[";
71  // sel+=Itoa(nIFO-1,10);
72  // sel+="]";
73  if(nIFO==2) {sel.ReplaceAll("1","0");sel.ReplaceAll("2","1");}
74  // TString sel="slag[1]:slag[2]";
75  num=wave.Draw(sel,cut,"goff");
76  const int slag_entries = num;
77  cout<<"Number of Entries: "<<num<<endl;
78  double* slag1 = new double[slag_entries];
79  slag1 = wave.GetV1();
80  double* slag2 = new double[slag_entries];
81  slag2 = wave.GetV2();
82  char mytitle[256];
83  double SlagMax = wave.GetMaximum("slag")+segLen/2.;
84  double SlagMin = wave.GetMinimum("slag")-segLen/2.;
85  int NSlag = TMath::FloorNint((SlagMax-SlagMin)/segLen);
86  cout << "SLAG MAX : "<< wave.GetMaximum("slag")<< " s SLAG MIN : "<< wave.GetMinimum("slag")<< " s #SLAGS : "<<NSlag-1<<endl;
87 
88  if(NSlag==1){cout <<"Just one slag....Skipping further execution!"<<endl; exit(0);}
89 sprintf(mytitle,"FAR distribution over slags (post cat3 & rho>%f)",T_cut);
90  TH2F* Slag = new TH2F("SLAG",mytitle,NSlag,SlagMin/86400.,SlagMax/86400.,NSlag,SlagMin/86400.,SlagMax/86400.);
91  Slag->GetXaxis()->SetTitle("slag[1] shift [day]");
92 // Slag->GetXaxis()->SetNdivisions(10,kFALSE);
93  Slag->GetYaxis()->SetTitle("slag[2] shift [day]");
94 // Slag->GetYaxis()->SetNdivisions(10,kFALSE);
95  Slag->SetStats(kFALSE);
96 
97  TH2F* lSlag = new TH2F("LSLAG","Live time distribution over slags",NSlag,SlagMin/86400.,SlagMax/86400.,NSlag,SlagMin/86400.,SlagMax/86400.);
98  for(long int l=0; l<num; l++){
99  Slag->Fill(slag1[l]/86400.,slag2[l]/86400.);
100 // if(l%1000==0) {cout << scientific << (double)l <<" - ";}
101 
102  }
103 
104  float xlag[NIFO_MAX+1];
105  float xslag[NIFO_MAX+1];
106  double xlive;
107  live.SetBranchAddress("slag",xslag);
108  live.SetBranchAddress("lag",xlag);
109  live.SetBranchAddress("live",&xlive);
110  live.SetBranchStatus("gps",false);
111 
112  int ntrg = live.GetEntries();
113  for(int i=0; i<ntrg; i++) {
114  live.GetEntry(i);
115  lSlag->Fill(xslag[0]/86400.,xslag[1]/86400.,xlive);
116 
117  }
118 
119  Slag->Divide(lSlag);
120  c1->Clear();
121  Slag->Draw("colz");
122  sprintf(fname,"%s/slag.png",netdir);
123  c1->Update(); c1->SaveAs(fname);
124 
125  TH1D* lSlag2 = lSlag->ProjectionY();
126  lSlag2->GetXaxis()->SetTitle("slag shift [day]");
127  //lSlag2->GetXaxis()->SetNdivisions(10,kFALSE);
128  lSlag2->GetYaxis()->SetTitle("Live time [day]");
129  //lSlag2->GetYaxis()->SetNdivisions(10,kFALSE);
130  lSlag2->SetMarkerStyle(20);
131  lSlag2->Scale(1./86400); //Scaling to get the live time in days
132  sprintf(mytitle,"Live time (%d lags) over slag shift",lagSize);
133  lSlag2->SetTitle(mytitle);
134  lSlag2->Draw("P");
135  sprintf(fname,"%s/Live_vs_slagtime.png",netdir);
136  c1->Update(); c1->SaveAs(fname);
137 
138 
139  TAxis *xaxis = Slag->GetXaxis();
140  TAxis *yaxis = Slag->GetYaxis();
141  int mycount = 0;
142  double FAR[50000];
143  double LSlag[50000];
144  double eFAR[50000];
145  double D[50000];
146  double Dx[50000];
147  double Dy[50000];
148  for(int i =1 ;i<NSlag+1;i++){
149  for(int j =1 ;j<NSlag+1;j++){
150  if(Slag->GetBinContent(i,j)>=1.E-15){
151  FAR[mycount] = Slag->GetBinContent(i,j)*86400.*365;
152  LSlag[mycount] = lSlag->GetBinContent(i,j);
153  LSlag[mycount] = lSlag->GetBinContent(i,j);
154  Dx[mycount] = xaxis->GetBinCenter(i);
155  Dy[mycount] = yaxis->GetBinCenter(j);
156  D[mycount] = TMath::Sqrt(pow(Dx[mycount],2)+pow(Dy[mycount],2));
157  //D[mycount] = yaxis->GetBinCenter(j);
158  eFAR[mycount] = Slag->GetBinError(i,j)/lSlag->GetBinError(i,j)*86400.*365;
159  mycount++;
160  if(i*j%100==0){cout << "slag[1] :"<<xaxis->GetBinCenter(i)<<" slag[2] :"<<yaxis->GetBinCenter(j) <<" FAR :"<<FAR[mycount-1] << "+/-" <<eFAR[mycount-1] << " " <<endl;}
161  }
162 
163  }
164  }
165 
166 
167  cout << "Number of slags : " << mycount << endl;
168  double liveTot = lSlag->GetSumOfWeights();
169  double liveMax = lSlag->GetMaximum();
170  cout << "Total BKG live time : " << liveTot << endl;
171  //const int mycount2=mycount;
172  double* FAR2 = new double[mycount];
173  double* eFAR2 = new double[mycount];
174  double* N = new double[mycount];
175  double* Ny = new double[mycount];
176  double* eN = new double[mycount];
177  for(int i =0 ;i<mycount;i++){N[i]=D[i];}
178  Int_t *myindex = new Int_t[mycount];
179  TMath::Sort(mycount,Ny,myindex,false);
180  for(int i =0 ;i<mycount;i++){FAR2[i]=FAR[myindex[i]];eFAR2[i]=eFAR[myindex[i]];N[i]=D[myindex[i]];Ny[i]=Dy[myindex[i]];eN[i]=0.0;}
181  TGraphErrors* FarPlot= new TGraphErrors(mycount, N, FAR2, eN, eFAR2);
182  FarPlot->SetLineColor(kBlue);
183  FarPlot->SetMarkerColor(kBlue);
184  //FarPlot->GetHistogram()->GetYaxis()->SetRangeUser(1.e-9,1.e-7);
185  FarPlot->SetTitle("FAR vs slag distance");
186  FarPlot->SetMarkerStyle(20);
187  FarPlot->SetMarkerSize(1);
188  FarPlot->SetLineStyle(3);
189  //FarPlot->SetMinimum(0.5/liveMax);
190  FarPlot->GetHistogram()->SetXTitle("slag distance [day]");
191  FarPlot->GetHistogram()->SetYTitle("FAR, [1/year]");
192  c1->Clear();
193  c1->SetLogy(kFALSE);
194  gStyle->SetOptStat();
195  gStyle->SetOptFit();
196 
197  FarPlot->Draw("AP");
198  FarPlot->Fit("pol1");
199  sprintf(fname,"%s/FAR_vs_slag.png",netdir);
200  c1->Update(); c1->SaveAs(fname);
201  gStyle->SetOptStat(kFALSE);
202  gStyle->SetOptFit(kFALSE);
203 
204  // CWB::CBCTool cbcTool;
205  // cbcTool.domyPoissonPlot(nIFO, Wlag, Tlag, Rlag, netdir);
206 
207  TCanvas *c2 = new TCanvas("Slag2", "Slag2",32,55,1450,502);
208  //c1->Range(-0.75,-1.23433,6.75,8.17182);
209  c2->SetBorderSize(1);
210  c2->SetFillColor(0);
211  c2->SetGridx();
212  c2->SetGridy();
213  c2->SetFrameFillColor(0);
214 
215  // if(write_ascii){
216  sprintf(fname,"%s/FAR_vs_slag2.txt",netdir);
217  FILE* frate = fopen(fname,"w");
218  fprintf(frate,"#FAR[years^-1] eFAR Tshift[days]\n");
219  for(int i=0; i<mycount;i++){fprintf(frate,"%.4f %.4f %.4f\n",FAR[i],eFAR[i],Dy[i]);}
220  fclose(frate);
221 
222  // }
223 
224 
225  TGraphErrors* FarPlot2= new TGraphErrors(mycount, Dy, FAR, eN, eFAR);
226  FarPlot2->SetLineColor(kBlue);
227  FarPlot2->SetMarkerColor(kBlue);
228  //FarPlot2->SetTitle("False Alarm rate vs time shift");
229  FarPlot2->SetTitle("");
230  FarPlot2->SetMarkerStyle(20);
231  FarPlot2->SetMarkerSize(1);
232  FarPlot2->SetLineStyle(3);
233  //FarPlot2->SetMinimum(0.5/liveMax);
234  FarPlot2->GetHistogram()->GetXaxis()->SetRangeUser(TMath::FloorNint(SlagMin/86400.),TMath::CeilNint(SlagMax/86400.));
235  FarPlot2->GetHistogram()->SetXTitle("time shift [day]");
236  FarPlot2->GetHistogram()->SetYTitle("FAR [1/year]");
237  FarPlot2->GetHistogram()->GetXaxis()->SetTitleSize(0.05);
238  FarPlot2->GetHistogram()->GetYaxis()->SetTitleSize(0.05);
239  FarPlot2->GetHistogram()->GetXaxis()->SetLabelSize(0.05);
240  FarPlot2->GetHistogram()->GetYaxis()->SetLabelSize(0.05);
241  c2->Clear();
242  c2->SetLogy(kFALSE);
243 
244  FarPlot2->Draw("AP");
245  TF1 *g1 = new TF1("g1","pol1",0,SlagMax/86400.);
246  g1->SetLineColor(2);
247  g1->SetLineWidth(5);
248  TF1 *g2 = new TF1("g2","pol1",-SlagMax/86400.,0);
249  g2->SetLineColor(3);
250  g2->SetLineWidth(5);
251 // TF1 *total = new TF1("total","pol1(0)+pol1(2)",-SlagMax/86400.,SlagMax/86400.);
252  FarPlot2->Fit(g1,"R");
253  FarPlot2->Fit(g2,"R+","SAME");
254 // Double_t par[4];
255 // g1->GetParameters(&par[0]);
256  // g2->GetParameters(&par[2]);
257  legr = new TLegend(0.6,0.8,0.885,0.98,"","brNDC");
258  legl = new TLegend(0.15,0.8,0.4,0.98,"","brNDC");
259  char lab[256];
260  sprintf(lab,"#chi^{2}/ndf(right) : %3.3g / %d",g1->GetChisquare(),g1->GetNDF());
261  legr->AddEntry(g1, lab, "l");
262  sprintf(lab,"P0(right) : %.2f +/- %.2f",g1->GetParameters()[0],g1->GetParErrors()[0]);
263  legr->AddEntry("", lab, "a");
264  sprintf(lab,"P1(right) : %.2g +/- %.2g",g1->GetParameters()[1],g1->GetParErrors()[1]);
265  legr->AddEntry("", lab, "a");
266  legr->SetLineColor(1);
267 
268  sprintf(lab,"#chi^{2}/ndf(left) : %3.3g / %d",g2->GetChisquare(),g2->GetNDF());
269  legl->AddEntry(g2, lab, "l");
270  sprintf(lab,"P0(left) : %.2f +/- %.2f",g2->GetParameters()[0],g2->GetParErrors()[0]);
271  legl->AddEntry("", lab, "a");
272  sprintf(lab,"P1(left) : %.2g +/- %.2g",g2->GetParameters()[1],g2->GetParErrors()[1]);
273  legl->AddEntry("", lab, "a");
274  legl->SetLineColor(1);
275 
276  legr->Draw();
277  legl->Draw();
278 // total->SetParameters(par);
279  // FarPlot2->Fit(total,"R+");
280  g1->Draw("same");
281  g2->Draw("same");
282  sprintf(fname,"%s/FAR_vs_slag2.png",netdir);
283  c2->Update(); c2->SaveAs(fname);
284 // gStyle->SetOptStat(kFALSE);
285  // gStyle->SetOptFit(kFALSE);
286 
287  exit(0);
288 
289 }
TF1 * g2
Definition: slag.C:248
TH2F * lSlag
Definition: slag.C:97
double FAR[50000]
Definition: slag.C:142
double liveMax
Definition: slag.C:169
double LSlag[50000]
Definition: slag.C:143
TString("c")
s veto_not_vetoed
Definition: slag.C:63
char cut[512]
Definition: slag.C:57
TAxis * yaxis
Definition: slag.C:140
TChain live("liveTime")
int j
Definition: cwb_net.C:10
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:3956
#define N
CWB::Toolbox TB
Definition: ComputeSNR.C:5
legr
Definition: slag.C:257
sprintf(cut,"rho[1]>%f", T_cut)
bool slagFound
Definition: slag.C:48
double xlive
Definition: slag.C:106
TF1 * g1
Definition: slag.C:245
TGraphErrors * FarPlot2
Definition: slag.C:225
const int slag_entries
Definition: slag.C:76
#define nIFO
TCanvas * c1
Definition: slag.C:31
float xlag[NIFO_MAX+1]
Definition: slag.C:104
double eFAR[50000]
Definition: slag.C:144
double D[50000]
Definition: slag.C:145
fclose(frate)
char netdir[1024]
const int NIFO_MAX
Definition: wat.hh:4
double Dx[50000]
Definition: slag.C:146
segLen
Definition: cwb_eced.C:7
TChain wave("waveburst")
double Dy[50000]
Definition: slag.C:147
double liveTot
char fname[1024]
Definition: slag.C:56
TBranch * branch
Definition: slag.C:47
TString sel("slag[1]:slag[2]")
TH1D * lSlag2
Definition: slag.C:125
char net_file_name[256]
int ntrg
Definition: slag.C:112
TAxis * xaxis
Definition: slag.C:139
TString test_veto
Definition: slag.C:62
char liv_file_name[256]
exit(0)
long int num
Definition: slag.C:65
char lab[256]
Definition: slag.C:259
FILE * frate
Definition: slag.C:217
int l
Definition: cbc_plots.C:434
char cut2[256]
Definition: slag.C:58
TIter mynext(wave.GetListOfBranches())
fprintf(frate,"#FAR[years^-1] eFAR Tshift[days]\n")
double T_cut
TCanvas * c2
Definition: slag.C:207
float xslag[NIFO_MAX+1]
Definition: slag.C:105
legl
Definition: slag.C:258
int mycount
Definition: slag.C:141
size_t lagSize
Definition: test_config1.C:52