Logo coherent WaveBurst  
Library Reference Guide
Logo
MakeWaveTestCombineCBC.C
Go to the documentation of this file.
1 //
2 // This macro is used to test the command cwb_combine_cbc
3 //
4 // Author : Gabriele Vedovato
5 //
6 // Combined IFAR -> the IFAR of any event reconstructed by the BBH and IMBHB searches is defined in the table below
7 //
8 // -----------------------------------------------------------------------------------------------------------------
9 // Case 1 -> IMBHB band (IMBHB BBH), BBH band ( ) -> IFAR = IFAR(IMBHB) TRIALS=1
10 // Case 2 -> IMBHB band ( ), BBH band (IMBHB BBH) -> IFAR = IFAR(BBH ) TRIALS=1
11 // Case 3 -> IMBHB band (IMBHB ), BBH band ( BBH) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
12 // Case 4 -> IMBHB band ( BBH), BBH band (IMBHB ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
13 // Case 5 -> IMBHB band (IMBHB ), BBH band ( ) -> IFAR = max IFAR(IMBHB,BBH) TRIALS=1
14 // Case 6 -> IMBHB band ( BBH), BBH band ( ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
15 // Case 7 -> IMBHB band ( ), BBH band (IMBHB ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
16 // Case 8 -> IMBHB band ( ), BBH band ( BBH) -> IFAR = max IFAR(IMBHB,BBH) TRIALS=1
17 // -----------------------------------------------------------------------------------------------------------------
18 //
19 // Ex: root -b -l 'MakeWaveTestCombineCBC.C("BBH","test_combine",8)'
20 //
21 
22 // must be used a wave output root file, after the pp-cuts, the unique selection and the ifar set
23 #define IWAVE_FILE "merge/wave_O3_K02_C00_LH_BBH_SIM_NR-MIX_tst1.M1.C_U.S_bin1_cut_nodq_sk8.root"
24 
25 #define MAX_TREE_SIZE 100000000000LL
26 
27 #define nIFO 2
28 
29 #define YEAR (24.*3600.*365.)
30 
31 void MakeWaveTestCombineCBC(TString osearch, TString otag, int Case) {
32 
33  if(Case<1 || Case>8) {
34  cout << "Error - The allowed cases are 1...8" << endl << endl;
35  gSystem->Exit(1);
36  }
37 
38  // check if cwb_combine_osearch is defined
39  if(osearch!="IMBHB" && osearch!="BBH") {
40  cout << "Error - osearch not defined, valid values are: IMBHB,BBH" << endl << endl;
41  gSystem->Exit(1);
42  }
43 
44  // check it ifwave exist
47 
48  // check if output files exist
49  TString ofwave = IWAVE_FILE;
50  ofwave.ReplaceAll(".root","_"+osearch+"_"+otag+".root");
51  bool overwrite = CWB::Toolbox::checkFile(ofwave,true);
52  if(!overwrite) gSystem->Exit(1);
53 
54  TFile *iwwave = TFile::Open(ifwave);
55  TTree* iwtree = (TTree*)iwwave->Get("waveburst");
56 
57  int isize = iwtree->GetEntries();
58  cout << "isize " << isize << endl;
59 
60  bool check_ifar=false;
61  TBranch* branch;
62  TIter next(iwtree->GetListOfBranches());
63  while ((branch=(TBranch*)next())) {
64  if(TString(branch->GetName())=="ifar") {
65  check_ifar=true;
66  TLeaf* leaf = branch->FindLeaf("ifar");
67  //cout << branch->GetName() << "\t" << leaf->GetTypeName() << endl;
68  }
69  }
70  next.Reset();
71  if(check_ifar==false) {
72  cout << "Error: ifar not present in : " << IWAVE_FILE << endl;
73  exit(1);
74  }
75 
76  float iIFAR;
77  double* iTIME = new double[2*nIFO];
78  float* iFREQ = new float[nIFO];
79  iwtree->SetBranchAddress("ifar",&iIFAR);
80  iwtree->SetBranchAddress("time",iTIME);
81  iwtree->SetBranchAddress("frequency",iFREQ);
82 
83  // create output wave root file
84  TFile* owroot = new TFile(ofwave,"RECREATE");
85  TTree* owtree = (TTree*)iwtree->CloneTree(0);
86  owtree->SetMaxTreeSize(MAX_TREE_SIZE);
87 
88  float oIFAR;
89  double* oTIME = new double[2*nIFO];
90  float* oFREQ = new float[nIFO];
91  owtree->SetBranchAddress("ifar",&oIFAR);
92  owtree->SetBranchAddress("time",oTIME);
93  owtree->SetBranchAddress("frequency",oFREQ);
94 
95  for(int i=0;i<isize;i++) {
96  iwtree->GetEntry(i);
97 
98  oIFAR = iIFAR;
99  for(int n=0;n<2*nIFO;n++) oTIME[n] = iTIME[n];
100  for(int n=0;n<nIFO;n++) oFREQ[n] = iFREQ[n];
101 
102 // Case 1 -> IMBHB band (IMBHB BBH), BBH band ( ) -> IFAR = IFAR(IMBHB) TRIALS=1
103  if(Case==1) {
104  if(osearch=="IMBHB") {
105  oIFAR = 100.;
106  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
107  }
108  if(osearch=="BBH") {
109  oIFAR = 200.;
110  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
111  }
112  }
113 
114 // Case 2 -> IMBHB band ( ), BBH band (IMBHB BBH) -> IFAR = IFAR(BBH ) TRIALS=1
115  if(Case==2) {
116  if(osearch=="IMBHB") {
117  oIFAR = 100.;
118  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
119  }
120  if(osearch=="BBH") {
121  oIFAR = 200.;
122  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
123  }
124  }
125 
126 // Case 3 -> IMBHB band (IMBHB ), BBH band ( BBH) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
127  if(Case==3) {
128  if(osearch=="IMBHB") {
129  oIFAR = 100.;
130  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
131  }
132  if(osearch=="BBH") {
133  oIFAR = 200.;
134  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
135  }
136  }
137 
138 // Case 4 -> IMBHB band ( BBH), BBH band (IMBHB ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
139  if(Case==4) {
140  if(osearch=="IMBHB") {
141  oIFAR = 100.;
142  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
143  }
144  if(osearch=="BBH") {
145  oIFAR = 200.;
146  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
147  }
148  }
149 
150 // Case 5 -> IMBHB band (IMBHB ), BBH band ( ) -> IFAR = max IFAR(IMBHB,BBH) TRIALS=1
151  if(Case==5) {
152  if(osearch=="IMBHB") {
153  oIFAR = 100.;
154  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
155  }
156  if(osearch=="BBH") { // not detected
157  oIFAR = 0.;
158  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
159  }
160  }
161 
162 // Case 6 -> IMBHB band ( BBH), BBH band ( ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
163  if(Case==6) {
164  if(osearch=="IMBHB") { // not detected
165  oIFAR = 0.;
166  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
167  }
168  if(osearch=="BBH") {
169  oIFAR = 200.;
170  for(int n=0;n<nIFO;n++) oFREQ[n] = 70;
171  }
172  }
173 
174 // Case 7 -> IMBHB band ( ), BBH band (IMBHB ) -> IFAR = max IFAR(IMBHB,BBH)/2 TRIALS=2
175  if(Case==7) {
176  if(osearch=="IMBHB") {
177  oIFAR = 100.;
178  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
179  }
180  if(osearch=="BBH") { // not detected
181  oIFAR = 0.;
182  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
183  }
184  }
185 
186 // Case 8 -> IMBHB band ( ), BBH band ( BBH) -> IFAR = max IFAR(IMBHB,BBH) TRIALS=1
187  if(Case==8) {
188  if(osearch=="IMBHB") { // not detected
189  oIFAR = 0.;
190  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
191  }
192  if(osearch=="BBH") {
193  oIFAR = 200.;
194  for(int n=0;n<nIFO;n++) oFREQ[n] = 90;
195  }
196  }
197 
198  owtree->Fill();
199  }
200 
201  owroot->cd();
202  owtree->Write();
203  owroot->Close();
204 
205  // create output mdc file -> symbolic link
206  TString ofmdc;
207  TString odir = gSystem->DirName(ofwave);
208  // create symbolic link to live root file
209  TString ifmdc = ifwave;
210  ifmdc.ReplaceAll("wave_","mdc_");
211  ifmdc.Remove(0,ifmdc.Last('/')+1); // strip path
212  ofmdc = ofwave;
213  ofmdc.ReplaceAll("wave_","mdc_");
214  ofmdc.Remove(0,ofmdc.Last('/')+1); // strip path
215  cout << odir << endl;
216  //cout << ofmdc << endl;
217  Long_t id,size,flags,mt;
218  int estat = gSystem->GetPathInfo(odir+"/"+ifmdc,&id,&size,&flags,&mt);
219  if(estat==0) {
220  char cmd[1024];
221  sprintf(cmd,"cd %s;ln -sf %s %s",odir.Data(),ifmdc.Data(),ofmdc.Data());
222  //cout << cmd << endl;
223  gSystem->Exec(cmd);
224  }
225 
226  // create output merge list combine file name
227  TString ofmerge = ofwave;
228  ofmerge.ReplaceAll("wave_","merge_");
229  ofmerge.ReplaceAll(".root",".lst");
230  char cmd[1024]; sprintf(cmd,"touch %s",ofmerge.Data());
231  gSystem->Exec(cmd);
232 
233  // write history intooutput wave file
234  CWB::History* history = (CWB::History*)iwwave->Get("history");
235  if(history!=NULL) {
236  TFile owfile(ofwave,"UPDATE");
237  history->Write("history");
238  owfile.Close();
239  }
240  delete history;
241 
242  // output files
243  cout << endl;
244  cout << "Output Combined files : " << endl;
245  cout << ofwave << endl;
246  cout << odir+"/"+ofmdc << endl;
247  cout << ofmerge << endl;
248  cout << endl;
249 
250  exit(0);
251 }
int n
Definition: cwb_net.C:28
TString("c")
char odir[1024]
TString ofmerge
Long_t flags
CWB::History * history
Long_t size
#define nIFO
i drho i
static bool checkFile(TString fName, bool question=false, TString message="")
Definition: Toolbox.cc:4670
int isize
ifwave[0]
TIter next(twave->GetListOfBranches())
#define IWAVE_FILE
#define MAX_TREE_SIZE
TBranch * branch
char cmd[1024]
int estat
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
Long_t mt
bool overwrite
Definition: cwb_dump_inj.C:100
Long_t id
void MakeWaveTestCombineCBC(TString osearch, TString otag, int Case)
exit(0)