Logo coherent WaveBurst  
Library Reference Guide
Logo
cwb_setifar.C
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Gabriele Vedovato
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 // adds a new ifar (inverse alse alarm rate) leaf to the selected entries in the merged wave root file
20 // for each selected entry a new leaf is created "ifar" which value is obtained from the CWB_SETFAR_FILE
21 // CWB_SETFAR_FILE is a text file which contains a corrispondence between rho and far (from background)
22 
23 {
24  int estat;
25  Long_t id,size,flags,mt;
26  char cmd[1024];
27 
28  cwb_merge_label = TString(gSystem->Getenv("CWB_MERGE_LABEL"));
29  TString cwb_setifar_tsel = TString(gSystem->Getenv("CWB_SETIFAR_TSEL"));
30  TString cwb_setifar_file = TString(gSystem->Getenv("CWB_SETIFAR_FILE"));
31  TString cwb_setifar_label = TString(gSystem->Getenv("CWB_SETIFAR_LABEL"));
32  TString cwb_setifar_mode = TString(gSystem->Getenv("CWB_SETIFAR_MODE"));
33  TString cwb_setifar_options = TString(gSystem->Getenv("CWB_SETIFAR_OPTIONS"));
34 
36 
37  if(cwb_setifar_options.Contains("--")) {
38  TString option="";
39  // get the cwb_setifar_tsel
40  cwb_setifar_tsel = CWB::Toolbox::getParameter(cwb_setifar_options,"--tsel");
41  if(cwb_setifar_tsel=="") {
42  // look if the explicit tsel definition is defined
43  cwb_setifar_tsel = CWB::Toolbox::getParameter(cwb_setifar_options,"--xtsel");
44  if(cwb_setifar_tsel=="") {
45  cout << "cwb_setifar.C : Error - (--tsel) or (--xtsel) is not defined !!!" << endl << endl;
46  gSystem->Exit(1);
47  }
48  } else {
49  // search global definition (defined in *.hh pp cuts file)
50  // check if cwb_setifar_tsel is defined
51 
53 
54  cwb_setifar_tsel.ReplaceAll("&&"," ");
55  cwb_setifar_tsel.ReplaceAll("||"," ");
56  cwb_setifar_tsel.ReplaceAll("("," ");
57  cwb_setifar_tsel.ReplaceAll(")"," ");
58  cwb_setifar_tsel.ReplaceAll("!"," ");
59 
60  TObjArray* token = TString(cwb_setifar_tsel).Tokenize(TString(' '));
61  for(int j=0;j<token->GetEntries();j++){
62 
63  TObjString* tok = (TObjString*)token->At(j);
64  TString stok = tok->GetString();
65 
66  // check if tsel is defined
67  TGlobal *global=(TGlobal*)gROOT->GetListOfGlobals()->FindObject(stok.Data());
68  if(global==NULL) {
69  cout << "cwb_setifar.C : Error - tsel \'" << stok << "\' -> wrong syntax or it is not defined " << endl;
70  cout << " must be included in the user_pparameters.C file" << endl << endl;
71  gSystem->Exit(1);
72  }
73  TCut *tsel = (TCut*)global->GetAddress();
74  if(TString(tsel->GetName())!=stok) {
75  cout << "cwb_setifar.C : Error - tsel \'" << stok << "\' not correspond to global Tcut name" << endl;
76  cout << " must be included in the user_pparameters.C file" << endl << endl;
77  gSystem->Exit(1);
78  }
79 
80  TSEL.ReplaceAll(stok,TString::Format("(%s)",tsel->GetTitle()));
81  }
82 
83  cwb_setifar_tsel = TSEL; // extract TCut
84  cout << "cwb_setifar_tsel : " << cwb_setifar_tsel << endl;
85  }
86 
87  // get the cwb_setifar_file
88  cwb_setifar_file = CWB::Toolbox::getParameter(cwb_setifar_options,"--file");
89  if(cwb_setifar_file=="") {
90  // look if the explicit file path definition is defined
91  cwb_setifar_file = CWB::Toolbox::getParameter(cwb_setifar_options,"--xfile");
92  if(cwb_setifar_file=="") {
93  cout << "cwb_setifar.C : Error - (--file) or (--xfile) is not defined !!!" << endl << endl;
94  gSystem->Exit(1);
95  }
96  } else {
97  // search global definition far vs rho file
98  // check if cwb_setifar_file is defined
99 
100  // check if cwb_setifar_file is an index of an array, ex: file_list[3]
101  int beg_bracket = cwb_setifar_file.Index("[");
102  int end_bracket = cwb_setifar_file.Index("]");
103  int len_bracket = end_bracket-beg_bracket+1;
104  bool is_bracket=true;
105  if(end_bracket!=cwb_setifar_file.Sizeof()-2) is_bracket=false;
106  if(len_bracket<=0) is_bracket=false;
107  TString sindx = cwb_setifar_file(beg_bracket+1,len_bracket-2);
108  if(!sindx.IsDigit()) is_bracket=false;
109  // extract array index
110  int indx = is_bracket ? sindx.Atoi() : -1;
111  if(indx>=0) cwb_setifar_file=cwb_setifar_file(0,beg_bracket);
112 
113  TGlobal *global=(TGlobal*)gROOT->GetListOfGlobals()->FindObject(cwb_setifar_file.Data());
114  if(global==NULL) {
115  cout << "cwb_setifar.C : Error - setifar_file \'" << cwb_setifar_file << "\' -> wrong syntax or is not defined " << endl;
116  cout << " must be included in the user_pparameters.C file" << endl << endl;
117  gSystem->Exit(1);
118  }
119  int adim = global->GetArrayDim();
120  if(adim==0) { // string
121  cwb_setifar_file = *(TString*)global->GetAddress();
122  }
123  if(adim==1) { // array of strings dim=1
124  int asize = global->GetMaxIndex(0);
125  if(indx<0 || indx>=asize) {
126  cout << "cwb_setifar.C : Error - setifar_file \'" << cwb_setifar_file << "\' input array index not declared or not allowed, max=" << asize-1 << endl;
127  cout << " check user_pparameters.C file" << endl << endl;
128  gSystem->Exit(1);
129  }
130  TString* afile = (TString*)global->GetAddress();
131  cwb_setifar_file = afile[indx];
132  }
133  if(adim>1) { // array of strings dim>1 (not allowed)
134  cout << "cwb_setifar.C : Error - setifar_file \'" << cwb_setifar_file << "\' array dimension > 1 not allowed " << endl;
135  cout << " check user_pparameters.C file" << endl << endl;
136  gSystem->Exit(1);
137  }
138  cout << "cwb_setifar_file : " << cwb_setifar_file << endl;
139  }
140 
141  // get the cwb_setifar_mode
142  cwb_setifar_mode = CWB::Toolbox::getParameter(cwb_setifar_options,"--mode");
143  if(cwb_setifar_mode=="") {
144  cout << "cwb_setifar.C : Error - --mode is not defined !!!" << endl;
145  gSystem->Exit(1);
146  }
147 
148  // get the cwb_setifar_label
149  cwb_setifar_label = CWB::Toolbox::getParameter(cwb_setifar_options,"--label");
150  if(cwb_setifar_label=="") {
151  cout << "cwb_setifar.C : Error - --label is not defined !!!" << endl;
152  gSystem->Exit(1);
153  }
154  }
155 
156  // set inclusive mode
157  bool inclusive=true;
158  cwb_setifar_mode.ToUpper();
159  if(cwb_setifar_mode.BeginsWith("I")) inclusive=true;
160  if(cwb_setifar_mode.BeginsWith("E")) inclusive=false;
161 
162  // check if cwb_ifar_label is defined
163  if(cwb_setifar_label=="") {
164  cout << "cwb_setifar.C : Error - ifar label not defined" << endl;
165  gSystem->Exit(1);
166  }
167  // check if cwb_setifar_label contains '.'
168  if(cwb_setifar_label.Contains(".")) {
169  cout << "cwb_setifar.C : Error - cwb_setifar_label " << cwb_setifar_label
170  << " can not contains '.'" << endl << endl;
171  gSystem->Exit(1);
172  }
173  if(cwb_setifar_tsel=="") cwb_wcuts_tree="run>0";
174 
175  // create input wave root wave file name
176  char iwfname[1024];
177  sprintf(iwfname,"wave_%s.%s.root",data_label,cwb_merge_label.Data());
178 
179  // create output wave root cuts file name
180  TString owfname = mdir+"/"+iwfname;
181  owfname.ReplaceAll(".root",TString(".S_")+cwb_setifar_label+".root");
182 
183  // apply setifar to the selected entries in the wave file
184  int nsel = CWB::Toolbox::setIFAR(iwfname,mdir,mdir,"waveburst",cwb_setifar_tsel,
185  cwb_setifar_file,pp_irho,cwb_setifar_label,inclusive);
186  if(nsel<=0) {
187  cout << "cwb_setifar.C : Warninig - Number of selected waveburst entries = " << nsel << endl << endl;
188  //gSystem->Exit(1);
189  }
190  cout << "cwb_setifar.C : Number of selected waveburst entries = " << nsel << endl;
191 
192  // if cwb_setifar_label=same the original wave root file is overwrite
193  if(cwb_setifar_label=="same") {
194  sprintf(cmd,"/bin/mv %s %s/%s", owfname.Data(), mdir.Data(), iwfname);
195  cout << cmd << endl;
196  gSystem->Exec(cmd);
197  exit(0);
198  }
199 
200  // create a merge*.lst file name & run selection cuts
201  vector<int> jobList;
202  char ilstfname[1024];
203  sprintf(ilstfname,"merge_%s.%s.lst",data_label,cwb_merge_label.Data());
205  olstfname.ReplaceAll("wave_","merge_");
206  olstfname.ReplaceAll(".root",".lst");
207  olstfname.Remove(0,olstfname.Last('/')+1); // strip path
208  cout << olstfname << endl;
209  estat = gSystem->GetPathInfo(mdir+"/"+ilstfname,&id,&size,&flags,&mt);
210  if (estat==0) {
211  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilstfname,olstfname.Data());
212  cout << cmd << endl;
213  gSystem->Exec(cmd);
214  }
215 
216  // for simulation!=0 create a symbolic link to mdc*.root file name
218  char ilfname[1024];
219  sprintf(ilfname,"mdc_%s.%s.root",data_label,cwb_merge_label.Data());
220  TString olfname = owfname;
221  olfname.ReplaceAll("wave_","mdc_");
222  olfname.Remove(0,olfname.Last('/')+1); // strip path
223  cout << olfname << endl;
224  estat = gSystem->GetPathInfo(mdir+"/"+ilfname,&id,&size,&flags,&mt);
225  if(estat==0) {
226  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilfname,olfname.Data());
227  cout << cmd << endl;
228  gSystem->Exec(cmd);
229  }
230  }
231 
232  // for simulation=0 create a symbolic link to live*.root file name
233  if(!simulation) {
234  char ilfname[1024];
235  sprintf(ilfname,"live_%s.%s.root",data_label,cwb_merge_label.Data());
236  TString olfname = owfname;
237  olfname.ReplaceAll("wave_","live_");
238  olfname.Remove(0,olfname.Last('/')+1); // strip path
239  cout << olfname << endl;
240  estat = gSystem->GetPathInfo(mdir+"/"+ilfname,&id,&size,&flags,&mt);
241  if(estat==0) {
242  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilfname,olfname.Data());
243  cout << cmd << endl;
244  gSystem->Exec(cmd);
245  }
246  }
247 
248  exit(0);
249 }
TString cwb_wcuts_tree
Definition: cwb_setcuts.C:31
static int setIFAR(TString ifName, TString idir, TString odir, TString trname, TString sels, TString farFile, int irho, TString olabel, bool inclusive=true)
Definition: Toolbox.cc:2990
TString cwb_setifar_label
Definition: cwb_setifar.C:31
TString cwb_setifar_mode
Definition: cwb_setifar.C:32
TString("c")
Long_t id
Definition: cwb_setifar.C:23
TString cwb_setifar_options
Definition: cwb_setifar.C:33
int j
Definition: cwb_net.C:28
Long_t size
Definition: cwb_setifar.C:23
exit(0)
char data_label[512]
Definition: test_config1.C:160
TGlobal * global
Definition: config.cc:23
TString mdir
Definition: cwb_setifar.C:35
vector< int > jobList
Definition: cwb_setifar.C:201
TString olstfname
Definition: cwb_setifar.C:204
char merge_dir[512]
Definition: test_config1.C:147
Long_t mt
Definition: cwb_setifar.C:23
cwb_merge_label
Definition: cwb_setifar.C:28
TObjArray * token
char cmd[1024]
Definition: cwb_setifar.C:26
TString cwb_setifar_file
Definition: cwb_setifar.C:30
TString cwb_setifar_tsel
Definition: cwb_setifar.C:29
sprintf(ilstfname,"merge_%s.%s.lst", data_label, cwb_merge_label.Data())
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:6727
bool inclusive
Definition: cwb_setifar.C:157
Long_t flags
Definition: cwb_setifar.C:23
int estat
simulation
Definition: cwb_eced.C:26
i drho pp_irho
int nsel
Definition: cwb_setcuts.C:237
char ilstfname[1024]
Definition: cwb_setifar.C:202
TString owfname
Definition: cwb_setchunk.C:73