10 |
#include <TString.h> |
#include <TString.h> |
11 |
#include <TBenchmark.h> |
#include <TBenchmark.h> |
12 |
#include <TFriendElement.h> |
#include <TFriendElement.h> |
13 |
|
#include <TObjectTable.h> |
14 |
|
|
15 |
#include <stdlib.h> |
#include <stdlib.h> |
16 |
#include <iostream> |
#include <iostream> |
34 |
// Functions to be provided externally |
// Functions to be provided externally |
35 |
//==================================== |
//==================================== |
36 |
bool Select(PamLevel2*); |
bool Select(PamLevel2*); |
37 |
void CreateHistos(); |
void CreateHistos(TFile *); |
38 |
void FillHistos(PamLevel2*); |
void FillHistos(PamLevel2*); |
39 |
void SaveHistos(TFile *); |
void SaveHistos(TFile *); |
40 |
|
|
58 |
//------------------------------ |
//------------------------------ |
59 |
// create output histos/trees |
// create output histos/trees |
60 |
//------------------------------ |
//------------------------------ |
61 |
if(fillHistos) CreateHistos(); |
if(fillHistos) CreateHistos(outfh); |
62 |
if(fillTree) event->CreateCloneTrees(tree); |
if(fillTree){ |
63 |
|
// outft->cd(); |
64 |
|
// event->CreateCloneTrees(tree,outft); |
65 |
|
event->CreateCloneTrees(outft); |
66 |
|
} |
67 |
|
// gDirectory->ls(); |
68 |
|
|
69 |
cout << "\nBegin() - done\n\n"; |
cout << "\nBegin() - done\n\n"; |
70 |
return 1; |
return 1; |
76 |
|
|
77 |
bool Process(int iev){ |
bool Process(int iev){ |
78 |
|
|
|
//------------------------------ |
|
|
// create output histos/trees |
|
|
//------------------------------ |
|
|
|
|
|
event->Clear(); |
|
|
tree->GetEntry(iev); |
|
79 |
|
|
80 |
if( !Select(event) )return false; |
if( !Select(event) )return false; |
81 |
// cout <<event->TrkLevel2::ntrk()<<endl; |
// cout <<event->TrkLevel2::ntrk()<<endl; |
82 |
|
|
83 |
|
|
84 |
// if(fillTree)event->FillCloneTrees(); |
if(fillTree)event->FillCloneTrees(); |
85 |
// if(fillHistos)FillHistos(event); |
if(fillHistos)FillHistos(event); |
86 |
|
|
87 |
return true; |
return true; |
88 |
|
|
112 |
//000000000000000000000000000000000000000000 |
//000000000000000000000000000000000000000000 |
113 |
//========================================== |
//========================================== |
114 |
Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ |
Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ |
115 |
|
|
116 |
|
// gObjectTable->Print(); |
117 |
|
|
118 |
if(options.Contains("fillTree"))fillTree=true; |
if(options.Contains("fillTree"))fillTree=true; |
119 |
if(options.Contains("fillHisto"))fillHistos=true; |
if(options.Contains("fillHisto"))fillHistos=true; |
162 |
command << " echo "<<list<<" > list-temp.txt"; |
command << " echo "<<list<<" > list-temp.txt"; |
163 |
cout << command.str().c_str() << endl; |
cout << command.str().c_str() << endl; |
164 |
gSystem->Exec(command.str().c_str()); |
gSystem->Exec(command.str().c_str()); |
165 |
tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,"list-temp.txt"),options); |
tree = event->GetPamTree(ddir,"list-temp.txt",options); |
166 |
}else{ |
}else{ |
167 |
tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,list),options); |
tree = event->GetPamTree(ddir,list,options); |
168 |
}; |
}; |
169 |
tree->SetCacheSize(0); |
tree->SetCacheSize(0); |
170 |
|
|
176 |
// ----------------- |
// ----------------- |
177 |
// loop over events |
// loop over events |
178 |
// ----------------- |
// ----------------- |
179 |
ULong64_t nevents = tree->GetEntriesFast(); |
ULong64_t nevents = tree->GetEntries(); |
180 |
if(!nmax)nmax = numeric_limits<ULong64_t>::max(); |
if(!nmax)nmax = numeric_limits<ULong64_t>::max(); |
181 |
if(nevents < nmax)nmax=nevents; |
if(nevents < nmax)nmax=nevents; |
182 |
|
|
183 |
cout << endl<<" Start loop over events: "<< nmax<<endl; |
cout << endl<<" Start loop over events: "<< nmax<<endl; |
184 |
Int_t ntrk=0; |
Int_t ntrk = 0; |
185 |
Int_t sel=0; |
Int_t sel = 0; |
186 |
|
Int_t get = 0; |
187 |
TBenchmark *benchmark = new TBenchmark(); |
TBenchmark *benchmark = new TBenchmark(); |
188 |
benchmark->Start("event-loop"); |
benchmark->Start("event-loop"); |
189 |
|
|
190 |
TString current_file = ""; |
TString current_file = ""; |
191 |
for(ULong64_t iev=60000; iev<nmax; iev++){ |
// gObjectTable->Print(); |
192 |
|
for(ULong64_t iev=0; iev<nmax; iev++){ |
193 |
|
|
194 |
// tree->GetEntry(iev); |
event->Clear(); |
195 |
if( Process(iev) )sel++; |
if( tree->GetEntry(iev) ){ |
196 |
|
get++; |
197 |
if(current_file.CompareTo(tree->GetFile()->GetName())){ |
if( Process(iev) ){ |
198 |
current_file=tree->GetFile()->GetName(); |
sel++; |
199 |
cout << iev<< " -> "<< current_file << endl; |
if(event->TrkLevel2::ntrk() >0)ntrk++; |
200 |
|
} |
201 |
|
if(current_file.CompareTo(tree->GetFile()->GetName())){ |
202 |
|
current_file=tree->GetFile()->GetName(); |
203 |
|
cout << iev<< " -> "<< current_file << endl; |
204 |
// cout << tree->GetFile()->GetName() << endl; |
// cout << tree->GetFile()->GetName() << endl; |
205 |
|
}; |
206 |
|
// if( fillTree && !(sel%10000) ) |
207 |
|
// if(event->TrkLevel2::ntrk() >0)ntrk++; |
208 |
|
}else{ |
209 |
|
cout << "Chain entry "<<iev<<" -- ERROR --"<<endl; |
210 |
}; |
}; |
211 |
|
// if(!(iev%100))cout << iev << endl; |
|
if(event->TrkLevel2::ntrk() >0)ntrk++; |
|
|
if(!(iev%100))cout << iev << endl; |
|
212 |
|
|
213 |
}; |
}; |
214 |
benchmark->Show("event-loop"); |
benchmark->Show("event-loop"); |
215 |
cout << ntrk <<" tracks over "<<nmax<<" events "; |
cout << sel <<" selected events over "<<get; |
216 |
if(nmax)cout<<"("<< 100*ntrk/nmax<<"%)"<<endl; |
if(get)cout<<" ("<< 100*sel/get<<"%)"<<endl; |
217 |
cout << "Selected events: "<<sel<<endl; |
// cout << "Fitted tracks: "<<ntrk<<endl; |
218 |
|
// gObjectTable->Print(); |
219 |
// -------------- |
// -------------- |
220 |
// close and exit |
// close and exit |
221 |
// -------------- |
// -------------- |
227 |
|
|
228 |
///////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////// |
229 |
|
|
230 |
#if !defined(__CINT__) |
#if !defined(__CINT__) |
231 |
|
|
232 |
// input parameters |
// input parameters |
233 |
Bool_t DEBUG; |
Bool_t DEBUG; |
234 |
TString DIR; |
TString DIR; |
235 |
TString LIST; |
TString LIST; |
236 |
|
TString OPTIONS; |
237 |
ULong64_t MAXEV; |
ULong64_t MAXEV; |
238 |
TString OUTFILE; |
TString OUTFILE; |
239 |
|
|
240 |
void usage(){ |
void usage(){ |
241 |
|
|
242 |
|
cout << "------------------------------------------------------------"<<endl; |
243 |
|
cout << "Loop over events (on one or more Level2-files), applying some selection cuts (defined in My-Selection.cpp), \n"; |
244 |
|
cout << "creating output histograms (defined in My-Histos.cpp) and/or trees with selected events. \n \n "; |
245 |
cout << "USAGE:"<<endl; |
cout << "USAGE:"<<endl; |
246 |
cout << "-processDir [DIR] - Level2/Level1 data directory \n"; |
cout << "-processDir DIR - Level2 data directory \n"; |
247 |
cout << "-processList [LIST] - list (txt) of names of files to be analysed \n"; |
cout << "-processList LIST - list of files (.txt) or single file (.root) to be analysed \n"; |
248 |
cout << "-outputFile [PATH] - name of the output file \n"; |
cout << "-outputFile PATH - name of the output file \n"; |
249 |
cout << "-NumEvents [XXX] - number of events to be analysed \n"; |
cout << "-NumEvents XXX - number of events to be analysed \n"; |
250 |
cout << "--debug, -g - debug mode \n"; |
cout << "--debug, -g - debug mode \n"; |
251 |
cout << "--help, -h - print this help \n"; |
cout << "--help, -h - print this help \n"; |
252 |
|
cout << "-options [ options ] - options: \n"; |
253 |
|
cout << " fillHistos --> create an output file with histograms \n"; |
254 |
|
cout << " fillTree --> create an output file with trees storing the selected events \n "; |
255 |
|
cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; |
256 |
|
cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; |
257 |
|
cout << "------------------------------------------------------------"<<endl; |
258 |
} |
} |
259 |
// |
// |
260 |
int HandleInputPar(int argc, char **argv){ |
int HandleInputPar(int argc, char **argv){ |
268 |
// ----------------------- |
// ----------------------- |
269 |
// Read input parameters |
// Read input parameters |
270 |
// ----------------------- |
// ----------------------- |
271 |
/* DEBUG = false; |
DEBUG = false; |
272 |
DIR = gSystem->WorkingDirectory(); |
DIR = gSystem->WorkingDirectory(); |
273 |
LIST = ""; |
LIST = ""; |
274 |
OUTFILE = "TrkLevel1Report_output.root"; |
OUTFILE = ""; |
275 |
MAXEV = numeric_limits<ULong64_t>::max(); |
OPTIONS = "+ALL fillTree"; |
276 |
*/ |
MAXEV = 0; |
277 |
|
|
278 |
|
|
279 |
for (int i = 1; i < argc; i++){ |
for (int i = 1; i < argc; i++){ |
306 |
continue; |
continue; |
307 |
} |
} |
308 |
// -----------------------------------------------------// |
// -----------------------------------------------------// |
309 |
|
else if (!strcmp(argv[i], "-options")){ |
310 |
|
if (++i >= argc) throw -1; |
311 |
|
OPTIONS = argv[i]; |
312 |
|
if( OPTIONS.Contains("[") ){ |
313 |
|
do{ |
314 |
|
if (++i >= argc) throw -1; |
315 |
|
OPTIONS.Append(argv[i]); |
316 |
|
}while(!OPTIONS.Contains("]")); |
317 |
|
}else cout << "wrong option format --> ignoring " << endl; |
318 |
|
} |
319 |
|
// -----------------------------------------------------// |
320 |
else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ |
else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ |
321 |
DEBUG = true; |
DEBUG = true; |
322 |
continue; |
continue; |
345 |
|
|
346 |
if( HandleInputPar(argc,argv) )return(1); |
if( HandleInputPar(argc,argv) )return(1); |
347 |
|
|
348 |
Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC fillHisto fillTree",OUTFILE); |
// Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC",OUTFILE); |
349 |
|
cout << "OPTIONS "<<OPTIONS<<endl; |
350 |
|
Loop(DIR,LIST,MAXEV,OPTIONS,OUTFILE); |
351 |
|
|
352 |
cout << "Back to main - end"<<endl; |
cout << "Back to main - end"<<endl; |
353 |
|
|