Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_setcuts.C
Go to the documentation of this file.
1 // apply selection on leaves to merged root file : used by the cwb_setcuts command
2 
3 {
4 
6 
7  int estat;
8  Long_t id,size,flags,mt;
9  char cmd[1024];
10 
11  cwb_merge_label = TString(gSystem->Getenv("CWB_MERGE_LABEL"));
12  TString cwb_jcuts_tree = TString(gSystem->Getenv("CWB_JCUTS_TREE"));
13  TString cwb_wcuts_tree = TString(gSystem->Getenv("CWB_WCUTS_TREE"));
14  TString cwb_cuts_label = TString(gSystem->Getenv("CWB_CUTS_LABEL"));
15  TString cwb_mcuts_tree = TString(gSystem->Getenv("CWB_MCUTS_TREE"));
16  TString cwb_lcuts_tree = TString(gSystem->Getenv("CWB_LCUTS_TREE"));
17  TString cwb_setcuts_options = TString(gSystem->Getenv("CWB_SETCUTS_OPTIONS"));
18 
20 
21  // check if cwb_setcuts_options contains '--' than cwb_setcuts_options
22  // is used to extract all setcuts parameters
25  if(cwb_setcuts_options.Contains("--")) {
26  TString option="";
27  // get the cwb_tcuts_tree
28  cwb_tcuts_tree = TB.getParameter(cwb_setcuts_options,"--tcuts");
29  // get the cwb_wcuts_tree
30  cwb_wcuts_tree = TB.getParameter(cwb_setcuts_options,"--wcuts");
31  // get the cwb_jcuts_tree
32  cwb_jcuts_tree = TB.getParameter(cwb_setcuts_options,"--jcuts");
33  // get the cwb_mcuts_tree
34  cwb_mcuts_tree = TB.getParameter(cwb_setcuts_options,"--mcuts");
35  // get the cwb_lcuts_tree
36  cwb_lcuts_tree = TB.getParameter(cwb_setcuts_options,"--lcuts");
37  // get the cwb_cuts_label
38  cwb_cuts_label = TB.getParameter(cwb_setcuts_options,"--label");
39  // get the cwb_unique_evt
40  cwb_unique_evt = TB.getParameter(cwb_setcuts_options,"--unique");
41  }
42  // if cwb_tcuts_tree!="" than cwb_tcuts_tree is added to cwb_wcuts_tree
43  if(cwb_tcuts_tree!="") {
44  // check if tcut is defined
45  TGlobal *global=(TGlobal*)gROOT->GetListOfGlobals()->FindObject(cwb_tcuts_tree.Data());
46  if(global==NULL) {
47  cout << "cwb_setcuts.C : Error - tcut " << cwb_tcuts_tree << " is not defined " << endl;
48  cout << " must be included in the user_pparameters.C file" << endl;
49  gSystem->Exit(1);
50  }
51  TCut *tcut = (TCut*)global->GetAddress();
52  if(TString(tcut->GetName())!=cwb_tcuts_tree) {
53  cout << "cwb_setcuts.C : Error - tcut " << cwb_tcuts_tree << " not correspond to global Tcut name" << endl;
54  cout << " must be included in the user_pparameters.C file" << endl;
55  gSystem->Exit(1);
56  }
57  cwb_tcuts_tree = tcut->GetTitle(); // extract TCut
58  cout << "cwb_tcuts_tree : " << cwb_tcuts_tree << endl;
59  if(cwb_wcuts_tree=="") {
60  cwb_wcuts_tree = cwb_tcuts_tree;
61  } else {
62  TString cwb_wcuts = cwb_tcuts_tree;
63  cwb_wcuts = TString("(")+cwb_wcuts_tree+")&&("+cwb_tcuts_tree+")";
64  cwb_wcuts_tree = cwb_wcuts;
65  }
66  cout << "cwb_wcuts_tree : " << cwb_wcuts_tree << endl;
67  }
68  // check if cwb_unique_evt can be applied
69  if((simulation==0)&&(cwb_unique_evt=="true")) {
70  cout << "cwb_setcuts.C : Error - unique option can be applied only to simulated data" << endl;
71  gSystem->Exit(1);
72  }
73  // check if cwb_cuts_label is defined
74  if((cwb_wcuts_tree!="")&&(cwb_cuts_label=="")) {
75  cout << "cwb_setcuts.C : Error - cuts label not defined" << endl;
76  gSystem->Exit(1);
77  }
78  // check if cwb_cuts_label contains '.'
79  if(cwb_cuts_label.Contains(".")) {
80  cout << "cwb_setcuts.C : Error - cwb_cuts_label " << cwb_cuts_label
81  << " can not contains '.'" << endl << endl;
82  gSystem->Exit(1);
83  }
84  // check if cwb_wcuts_tree contains run leaf
85  if(cwb_wcuts_tree.Contains("run")) {
86  cout << "cwb_setcuts.C : Error - cwb_wcuts_tree " << cwb_jcuts_tree
87  << " can not contains leaf : run" << endl << endl;
88  gSystem->Exit(1);
89  }
90  // check if cwb_wcuts_tree contains slag leaf
91  if(cwb_wcuts_tree.Contains("slag")) {
92  cout << "cwb_setcuts.C : Error - cwb_wcuts_tree " << cwb_jcuts_tree
93  << " can not contains leaf : slag" << endl << endl;
94  gSystem->Exit(1);
95  }
96  // check if cwb_wcuts_tree contains lag leaf
97  if(cwb_wcuts_tree.Contains("lag")) {
98  cout << "cwb_setcuts.C : Error - cwb_wcuts_tree " << cwb_jcuts_tree
99  << " can not contains leaf : lag" << endl << endl;
100  gSystem->Exit(1);
101  }
102  if(cwb_wcuts_tree=="") cwb_wcuts_tree="run>0";
103  if(cwb_jcuts_tree=="") cwb_jcuts_tree="run>0";
104 
105  // create wcuts
106  TString cwb_wcuts = cwb_wcuts_tree;
107  cwb_wcuts = TString("(")+cwb_wcuts_tree+")&&("+cwb_jcuts_tree+")";
108  if(cwb_lcuts_tree!="") cwb_wcuts = TString("(")+cwb_wcuts+")&&("+cwb_lcuts_tree+")";
109 
110  // create mcuts
111  TString cwb_mcuts = cwb_mcuts_tree;
112  if(cwb_mcuts!="")
113  cwb_mcuts = TString("(")+cwb_mcuts_tree+")&&("+cwb_jcuts_tree+")";
114  else
115  cwb_mcuts = cwb_jcuts_tree;
116 
117  // create input wave root cuts file name
118  char iwfname[1024];
119  sprintf(iwfname,"wave_%s.%s.root",data_label,cwb_merge_label.Data());
120 
121  // create output wave root cuts file name
122  TString uwfname = mdir+"/"+iwfname;
123  uwfname.ReplaceAll(".root",TString(".C_U.root"));
124 
125  // if cwb_unique_evt=true then create a wave root file with unique
126  // reconstructed events
127  if(cwb_unique_evt=="true") {
128  TB.setUniqueEvents(mdir+"/"+iwfname, uwfname, nIFO, pp_irho);
129  // create symbolic link of mdc file
130  char imfname[1024];
131  sprintf(imfname,"mdc_%s.%s.root",data_label,cwb_merge_label.Data());
132  TString omfname = uwfname;
133  omfname.ReplaceAll("wave_","mdc_");
134  omfname.Remove(0,omfname.Last('/')+1); // strip path
135  cout << omfname << endl;
136  estat = gSystem->GetPathInfo(mdir+"/"+imfname,&id,&size,&flags,&mt);
137  if(estat==0) {
138  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),imfname,omfname.Data());
139  cout << cmd << endl;
140  gSystem->Exec(cmd);
141  }
142  // create symbolic link of merge list file
143  char ilstfname[1024];
144  sprintf(ilstfname,"merge_%s.%s.lst",data_label,cwb_merge_label.Data());
145  TString olstfname = uwfname;
146  olstfname.ReplaceAll("wave_","merge_");
147  olstfname.ReplaceAll(".root",".lst");
148  olstfname.Remove(0,olstfname.Last('/')+1); // strip path
149  cout << olstfname << endl;
150  estat = gSystem->GetPathInfo(mdir+"/"+ilstfname,&id,&size,&flags,&mt);
151  if (estat==0) {
152  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilstfname,olstfname.Data());
153  cout << cmd << endl;
154  gSystem->Exec(cmd);
155  }
156  }
157  if((cwb_wcuts_tree="")&&(cwb_cuts_label=="")) exit(0);
158 
159  if(cwb_unique_evt=="true") {
160  sprintf(iwfname,"wave_%s.%s.C_U.root",data_label,cwb_merge_label.Data());
161  cwb_merge_label+=".C_U";
162  }
163 
164  // create output wave root cuts file name
165  TString owfname = mdir+"/"+iwfname;
166  owfname.ReplaceAll(".root",TString(".C_")+cwb_cuts_label+".root");
167 
168  // create a merge*.lst file name & run selection cuts
169  vector<int> jobList;
170  char ilstfname[1024];
171  sprintf(ilstfname,"merge_%s.%s.lst",data_label,cwb_merge_label.Data());
173  olstfname.ReplaceAll("wave_","merge_");
174  olstfname.ReplaceAll(".root",".lst");
175  olstfname.Remove(0,olstfname.Last('/')+1); // strip path
176  cout << olstfname << endl;
177  if(cwb_jcuts_tree=="") { // no jobs cuts -> create a symbolic link
178  estat = gSystem->GetPathInfo(mdir+"/"+ilstfname,&id,&size,&flags,&mt);
179  if (estat==0) {
180  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilstfname,olstfname.Data());
181  cout << cmd << endl;
182  gSystem->Exec(cmd);
183  }
184  } else {
185  // build list of selected jobs
186  vector<TString> jobFileList;
187  vector<int> jobList = CWB::Toolbox::getMergeJobList(mdir+"/"+ilstfname,jobFileList);
188  cout << "Number of jobs in the merged lists : " << jobList.size() << endl;
189  // create a dummy tree, fill with merged jobs, apply cuts, get selected jobs
190  TTree jtree("jtree","jtree");
191  int run; jtree.Branch("run",&run,"run/I");
192  TString *jfname = new TString();
193  jtree.Branch("jfname", &jfname);
194  // fill with merged jobs
195  for(int i=0;i<jobList.size();i++) {run=jobList[i]; *jfname=jobFileList[i]; jtree.Fill();}
196  // check cuts
197  TTreeFormula formula("trCuts", cwb_jcuts_tree.Data(), &jtree);
198  int err = formula.Compile(cwb_jcuts_tree.Data());
199  if(err) {
200  cout << "cwb_setcuts.C - wrong input cuts " << cwb_jcuts_tree << endl << endl;
201  gSystem->Exit(1);
202  }
203  // get selected jobs
204  jtree.Draw("Entry$",cwb_jcuts_tree.Data(),"goff");
205  int jsel = jtree.GetSelectedRows();
206  double* entry = jtree.GetV1(); // get selected jobs
207  jobList.clear();
208  jobFileList.clear();
209  for(int i=0;i<jsel;i++) {
210  jtree.GetEntry(entry[i]);
211  //cout << i << " " << run << " " << jfname->Data() << endl;
212  jobList.push_back(run); // list of selected jobs
213  jobFileList.push_back(jfname->Data()); // list of selected file jobs
214  }
215  CWB::Toolbox::dumpFileList(jobFileList,mdir+"/"+olstfname);
216  }
217 
218  // apply wcuts to wave file
219  int nsel = CWB::Toolbox::setCuts(iwfname,mdir,mdir,"waveburst",cwb_wcuts,cwb_cuts_label);
220  if(nsel<=0) {
221  cout << "cwb_setcuts.C : Error - Number of selected waveburst entries = " << nsel << endl << endl;
222  gSystem->Exit(1);
223  }
224  cout << "cwb_setcuts.C : Number of selected waveburst entries = " << nsel << endl;
225 
226  // apply mcuts to mdc file
227  if(simulation) {
228  char imfname[1024];
229  sprintf(imfname,"mdc_%s.%s.root",data_label,cwb_merge_label.Data());
230  int nsel = CWB::Toolbox::setCuts(imfname,mdir,mdir,"mdc",cwb_mcuts,cwb_cuts_label);
231  cout << "cwb_setcuts.C : Number of selected mdc entries = " << nsel << endl << endl;
232  if(nsel<0) { // create a symbolic link to mdc*.root file name
233  TString omfname = owfname;
234  omfname.ReplaceAll("wave_","mdc_");
235  omfname.Remove(0,omfname.Last('/')+1); // strip path
236  cout << omfname << endl;
237  estat = gSystem->GetPathInfo(mdir+"/"+imfname,&id,&size,&flags,&mt);
238  if(estat==0) {
239  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),imfname,omfname.Data());
240  cout << cmd << endl;
241  gSystem->Exec(cmd);
242  }
243  }
244  }
245 
246  // apply cuts to live file
247  if(!simulation) {
248  char ilfname[1024];
249  sprintf(ilfname,"live_%s.%s.root",data_label,cwb_merge_label.Data());
250  TString cwb_live_cuts = cwb_jcuts_tree;
251  if(cwb_lcuts_tree!="") cwb_live_cuts = TString("(")+cwb_live_cuts+")&&("+cwb_lcuts_tree+")";
252  int nsel = -1;
253  if(cwb_live_cuts!="run>0") {
254  nsel = CWB::Toolbox::setCuts(ilfname,mdir,mdir,"liveTime",cwb_live_cuts,cwb_cuts_label);
255  cout << "cwb_setcuts.C : Number of selected live entries = " << nsel << endl;
256  }
257  if(nsel<0) { // create a symbolic link to live*.root file name
258  TString olfname = owfname;
259  olfname.ReplaceAll("wave_","live_");
260  olfname.Remove(0,olfname.Last('/')+1); // strip path
261  cout << olfname << endl;
262  estat = gSystem->GetPathInfo(mdir+"/"+ilfname,&id,&size,&flags,&mt);
263  if(estat==0) {
264  sprintf(cmd,"cd %s;ln -sf %s %s",mdir.Data(),ilfname,olfname.Data());
265  cout << cmd << endl;
266  gSystem->Exec(cmd);
267  }
268  }
269  }
270 
271  exit(0);
272 }
static void setUniqueEvents(TString ifwave, TString ofwave, int nIFO, int pp_irho)
Definition: Toolbox.cc:3315
TString cwb_wcuts_tree
Definition: cwb_setcuts.C:13
CWB run(runID)
int estat
Definition: cwb_setcuts.C:3
TString("c")
Long_t size
Definition: cwb_setcuts.C:8
i drho i
TString owfname
Definition: cwb_setcuts.C:165
int jsel
Definition: cwb_setcuts.C:205
static vector< int > getMergeJobList(TString merge_dir, TString label, int version)
Definition: Toolbox.cc:1678
CWB::Toolbox TB
Definition: ComputeSNR.C:5
vector< int > jobList
Definition: cwb_setcuts.C:169
TString cwb_lcuts_tree
Definition: cwb_setcuts.C:16
#define nIFO
static int setCuts(TString ifName, TString idir, TString odir, TString trname, TString cuts, TString olabel)
Definition: Toolbox.cc:2856
char data_label[512]
Definition: test_config1.C:160
TGlobal * global
Definition: config.cc:5
char cmd[1024]
Definition: cwb_setcuts.C:9
static void dumpFileList(vector< TString > fileList, TString ofName)
Definition: Toolbox.cc:2749
TString olstfname
Definition: cwb_setcuts.C:172
Long_t flags
Definition: cwb_setcuts.C:8
Long_t mt
Definition: cwb_setcuts.C:8
char merge_dir[512]
Definition: test_config1.C:147
sprintf(ilstfname,"merge_%s.%s.lst", data_label, cwb_merge_label.Data())
TString cwb_unique_evt
Definition: cwb_setcuts.C:24
double * entry
Definition: cwb_setcuts.C:206
cwb_merge_label
Definition: cwb_setcuts.C:11
TString mdir
Definition: cwb_setcuts.C:19
char ilstfname[1024]
Definition: cwb_setcuts.C:170
static TString getParameter(TString options, TString param="")
Definition: Toolbox.cc:5943
Long_t id
Definition: cwb_setcuts.C:8
TString cwb_setcuts_options
Definition: cwb_setcuts.C:17
TString cwb_jcuts_tree
Definition: cwb_setcuts.C:12
TString cwb_tcuts_tree
Definition: cwb_setcuts.C:23
TString cwb_mcuts_tree
Definition: cwb_setcuts.C:15
char formula[256]
simulation
Definition: cwb_eced.C:9
TString cwb_cuts_label
Definition: cwb_setcuts.C:14
i drho pp_irho
int nsel
Definition: cwb_setcuts.C:219
exit(0)