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