Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DrawSearchAreaPRC.C
Go to the documentation of this file.
1 //
2 // Draw PRC Search Area
3 // Note : this macro is used to generate the PRC report (cwb_report merge_label prc)
4 // Author : Gabriele Vedovato
5 
6 #include "TROOT.h"
7 #include "TSystem.h"
8 #include "TFile.h"
9 #include "TTree.h"
10 #include <fstream>
11 #include <iostream>
12 #include "TGraph.h"
13 #include "TMultiGraph.h"
14 #include "TCanvas.h"
15 #include "TH1F.h"
16 #include "TMath.h"
17 #include "TH1F.h"
18 #include "TH2F.h"
19 #include <TComplex.h>
20 #include <TStyle.h>
21 #include <TRandom.h>
22 #include "TVector3.h"
23 #include "TRotation.h"
24 #include "Math/Vector3Dfwd.h"
25 #include "Math/Rotation3D.h"
26 
27 TH1F* sa_hist;
28 TCanvas* sa_canvas;
29 
30 void
32  int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar) {
33 
34  using namespace ROOT::Math;
35 
36  char wave_file_name[1024];
37  sprintf(wave_file_name,"merge/wave_%s.%s.root",data_label.Data(),merge_label.Data());
38 
39  TFile* ifile = TFile::Open(wave_file_name);
40  TTree* itree = (TTree *) gROOT->FindObject("waveburst");
41 
42  char cut[1024];
43  char tmp[1024];
44  sprintf(cut,"abs(time[0]-time[%d])<%f && netcc[%d]>%f && rho[%d]>%f",
45  nIFO,T_win,pp_inetcc,T_cor,pp_irho,T_cut);
46  if(T_vED>0) {strcpy(tmp,cut);sprintf(cut,"%s && neted[0]/ecor<%f",tmp,T_vED);}
47  if(T_pen>0) {strcpy(tmp,cut);sprintf(cut,"%s && penalty>%f",tmp,T_pen);}
48  if(T_ifar>0) {strcpy(tmp,cut);sprintf(cut,"%s && ifar>(24.*3600.*365.)*%f",tmp,T_ifar);}
49 
50  itree->Draw("erA[0]",cut,"goff");
51  int size = itree->GetSelectedRows();
52  cout << "detected events : " << size << endl;
53 
54  double* erA0 = itree->GetV1();
55  Int_t *index = new Int_t[size];
56 
57  TMath::Sort(size,itree->GetV1(),index,false);
58 
59  double area_min = pow(erA0[index[0]],2);
60  double area_max = pow(erA0[index[size-1]],2);
61  area_min = area_min ? area_min : 0.1;
62  int nbin = TMath::Ceil(area_max/area_min);
63 
64  sa_hist = new TH1F("sa_hist","sa_hist",nbin,area_min,area_max);
65 
66  for(int i=0;i<size;i++) {
67  double sarea = erA0[index[i]]*erA0[index[i]];
68  sa_hist->Fill(sarea);
69  }
70 
71  // Normalization
72  double integral = 0;
73  for (int i=0;i<=sa_hist->GetNbinsX();i++) integral+=sa_hist->GetBinContent(i);
74  for (int i=0;i<=sa_hist->GetNbinsX();i++) sa_hist->SetBinContent(i,sa_hist->GetBinContent(i)/integral);
75  for (int i=2;i<=sa_hist->GetNbinsX();i++) sa_hist->SetBinContent(i,sa_hist->GetBinContent(i)+sa_hist->GetBinContent(i-1));
76  // find area at 50%
77  double search_area50=0;
78  for (int i=0;i<=sa_hist->GetNbinsX();i++) if(sa_hist->GetBinContent(i)>0.5) {search_area50=sa_hist->GetBinCenter(i);break;}
79  cout << "search_area50 : " << search_area50 << endl;
80  // find area at 90%
81  double search_area90=0;
82  for (int i=0;i<=sa_hist->GetNbinsX();i++) if(sa_hist->GetBinContent(i)>0.9) {search_area90=sa_hist->GetBinCenter(i);break;}
83  cout << "search_area90 : " << search_area90 << endl;
84 
85  char title[256];
86  sprintf(title,"Ndet = %d",size);
87  sa_hist->SetTitle(title);
88  sa_hist->GetXaxis()->SetTitle("search area (deg^{2})");
89  sa_hist->GetYaxis()->SetTitle("cumulative probability");
90  sa_hist->GetXaxis()->SetRangeUser(area_min,area_max);
91  sa_hist->GetYaxis()->SetRangeUser(0,1);
92 
93  sa_hist->SetStats(kFALSE);
94  sa_canvas = new TCanvas("fom", "PRC", 300,40, 600, 600);
95  sa_canvas->SetGridx();
96  sa_canvas->SetGridy();
97  sa_canvas->SetLogx();
98  //sa_canvas->SetLogy();
99 
100  gStyle->SetTitleH(0.062);
101  gStyle->SetTitleW(0.98);
102  gStyle->SetTitleY(0.98);
103  gStyle->SetTitleFont(72);
104  gStyle->SetLineColor(kWhite);
105 
106  sa_hist->Draw();
107  sa_hist->GetXaxis()->SetTitleOffset(1.35);
108  sa_hist->GetYaxis()->SetTitleOffset(1.35);
109  sa_hist->GetXaxis()->CenterTitle(true);
110  sa_hist->GetYaxis()->CenterTitle(true);
111  sa_hist->GetXaxis()->SetLabelFont(42);
112  sa_hist->GetXaxis()->SetTitleFont(42);
113  sa_hist->GetYaxis()->SetLabelFont(42);
114  sa_hist->GetYaxis()->SetTitleFont(42);
115 
116  // draw the legend
117  TLegendEntry* entry;
118  TLegend *legend = new TLegend(0.3708054,0.174216,0.8892617,0.2770035,NULL,"brNDC");
119  legend->SetTextFont(42);
120  legend->SetTextSize(0.03);
121  legend->SetLineColor(kBlack);
122  legend->SetFillColor(kWhite);
123  char label[256];
124  sprintf(label,"search area 50%% : %0.2f (deg^{2})",search_area50);
125  legend->AddEntry(sa_hist,label,"lp");
126  sprintf(label,"search area 90%% : %0.2f (deg^{2})",search_area90);
127  legend->AddEntry(sa_hist,label,"lp");
128  legend->Draw();
129 
130  char ofname[1024];
131  sprintf(ofname,"%s/search_area.gif",odir.Data());
132  sa_canvas->Print(ofname);
133  char cmd[1024];
134  TString pfname(ofname);
135  pfname.ReplaceAll(".gif",".png");
136  sprintf(cmd,"convert %s %s",ofname,pfname.Data());
137  cout << cmd << endl;
138  gSystem->Exec(cmd);
139  sprintf(cmd,"rm %s",ofname);
140  cout << cmd << endl;
141  gSystem->Exec(cmd);
142  //exit(0);
143 
144 }
145 
char cut[512]
double T_ifar
double T_pen
char cmd[1024]
TString("c")
double T_cor
char odir[1024]
i pp_inetcc
Long_t size
i drho i
#define nIFO
char data_label[512]
Definition: test_config1.C:160
TString label
Definition: MergeTrees.C:21
double * tmp
Definition: testWDM_5.C:31
void DrawSearchAreaPRC(TString data_label, TString odir, TString merge_label, int nIFO, float T_win, int pp_inetcc, float T_cor, int pp_irho, float T_cut, float T_vED, float T_pen, float T_ifar)
TString merge_label
double * entry
Definition: cwb_setcuts.C:206
TFile * ifile
TCanvas * sa_canvas
char title[256]
Definition: SSeriesExample.C:1
wavearray< int > index
double T_win
strcpy(RunLabel, RUN_LABEL)
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
double T_cut
TTree * itree
TH1F * sa_hist
double T_vED
i drho pp_irho