1 |
mocchiut |
1.1 |
// |
2 |
|
|
#include <stdlib.h> |
3 |
|
|
#include <iostream> |
4 |
|
|
// |
5 |
|
|
#include <TTree.h> |
6 |
|
|
#include <TChain.h> |
7 |
|
|
#include <TFile.h> |
8 |
|
|
#include <TList.h> |
9 |
|
|
#include <TROOT.h> |
10 |
|
|
#include <TString.h> |
11 |
|
|
#include <TBenchmark.h> |
12 |
|
|
#include <TFriendElement.h> |
13 |
|
|
#include <TObjectTable.h> |
14 |
|
|
// |
15 |
|
|
#include <PamLevel2.h> |
16 |
|
|
// |
17 |
|
|
using namespace std; |
18 |
|
|
|
19 |
|
|
//=================================== |
20 |
|
|
// global variables |
21 |
|
|
//=================================== |
22 |
|
|
Bool_t DEBUG; |
23 |
|
|
TString DIR; |
24 |
|
|
TString LIST; |
25 |
|
|
TString I_OPTIONS; |
26 |
|
|
TString O_OPTIONS; |
27 |
|
|
ULong64_t MINEV; |
28 |
|
|
ULong64_t MAXEV; |
29 |
|
|
TString OUTFILE; |
30 |
|
|
|
31 |
|
|
PamLevel2 *event = NULL; |
32 |
|
|
TFile *outfh = NULL; |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
//==================================== |
36 |
|
|
// Functions to be provided externally |
37 |
|
|
//==================================== |
38 |
|
|
bool Select(PamLevel2*); |
39 |
|
|
void CreateHistos(PamLevel2*, TString); |
40 |
|
|
void FindAverage(PamLevel2*,int); |
41 |
|
|
void FindMatrix(PamLevel2*,int); |
42 |
|
|
void SaveHistos(); |
43 |
|
|
void CalculateAverage(); |
44 |
|
|
|
45 |
|
|
//========================================== |
46 |
|
|
//000000000000000000000000000000000000000000 |
47 |
|
|
//========================================== |
48 |
|
|
bool Begin(TString outfile){ |
49 |
|
|
|
50 |
|
|
//------------------------------ |
51 |
|
|
// create output histos/trees |
52 |
|
|
//------------------------------ |
53 |
|
|
CreateHistos(event,outfile); |
54 |
|
|
cout << "\nBegin() - done\n\n"; |
55 |
|
|
return 1; |
56 |
|
|
|
57 |
|
|
} |
58 |
|
|
//========================================== |
59 |
|
|
//000000000000000000000000000000000000000000 |
60 |
|
|
//========================================== |
61 |
|
|
|
62 |
|
|
bool Process1(int iev){ |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
if( !Select(event) )return false; |
66 |
|
|
|
67 |
|
|
FindAverage(event,iev); |
68 |
|
|
|
69 |
|
|
return true; |
70 |
|
|
|
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
bool Process2(int iev){ |
74 |
|
|
|
75 |
|
|
if( !Select(event) )return false; |
76 |
|
|
|
77 |
|
|
FindMatrix(event,iev); |
78 |
|
|
|
79 |
|
|
return true; |
80 |
|
|
|
81 |
|
|
} |
82 |
|
|
//========================================== |
83 |
|
|
//000000000000000000000000000000000000000000 |
84 |
|
|
//========================================== |
85 |
|
|
|
86 |
|
|
bool Finish(){ |
87 |
|
|
|
88 |
|
|
SaveHistos(); |
89 |
|
|
cout << "Finish() - done\n"; |
90 |
|
|
|
91 |
|
|
return 1; |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
//========================================== |
95 |
|
|
//000000000000000000000000000000000000000000 |
96 |
|
|
//========================================== |
97 |
|
|
Int_t Loop(TString ddir,TString list, ULong64_t nmax, ULong64_t nmin, TString ioptions, TString ooptions, TString outfile){ |
98 |
|
|
|
99 |
|
|
// ------------------- |
100 |
|
|
// create output files |
101 |
|
|
// ------------------- |
102 |
|
|
TTree::SetMaxTreeSize(1000*Long64_t(2000000000)); //m 070308 + dimensione oltre la quale divide il file di uscita: 2TB |
103 |
|
|
|
104 |
|
|
// -------------------- |
105 |
|
|
// read input file/list |
106 |
|
|
// -------------------- |
107 |
|
|
event = new PamLevel2(ddir,list,ioptions); |
108 |
|
|
|
109 |
|
|
// tree->SetCacheSize(0); |
110 |
|
|
|
111 |
|
|
// --------------- |
112 |
|
|
// initializations |
113 |
|
|
// --------------- |
114 |
|
|
if( !Begin(outfile) )return 0;; |
115 |
|
|
|
116 |
|
|
// ----------------- |
117 |
|
|
// loop over events |
118 |
|
|
// ----------------- |
119 |
|
|
ULong64_t nevents = event->GetEntries(); |
120 |
|
|
if(!nmax)nmax = numeric_limits<ULong64_t>::max(); |
121 |
|
|
if(nevents < nmax)nmax=nevents; |
122 |
|
|
nmax=nmax-nmin; |
123 |
|
|
|
124 |
|
|
cout << endl<<" Start loop over events: "<< nmax <<endl; |
125 |
|
|
|
126 |
|
|
TString current_file = ""; |
127 |
|
|
|
128 |
|
|
for(ULong64_t iev=nmin; iev<nmin+nmax; iev++){ |
129 |
|
|
// |
130 |
|
|
event->Clear(); |
131 |
|
|
if( event->GetEntry(iev) ){ |
132 |
|
|
Process1(iev); |
133 |
|
|
}else{ |
134 |
|
|
cout << "Chain entry "<<iev<<" -- ERROR --"<<endl; |
135 |
|
|
}; |
136 |
|
|
|
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
CalculateAverage(); |
140 |
|
|
|
141 |
|
|
for(ULong64_t iev=nmin; iev<nmin+nmax; iev++){ |
142 |
|
|
// |
143 |
|
|
event->Clear(); |
144 |
|
|
if( event->GetEntry(iev) ){ |
145 |
|
|
Process2(iev); |
146 |
|
|
}else{ |
147 |
|
|
cout << "Chain entry "<<iev<<" -- ERROR --"<<endl; |
148 |
|
|
}; |
149 |
|
|
|
150 |
|
|
}; |
151 |
|
|
|
152 |
|
|
event->Clear(); |
153 |
|
|
// -------------- |
154 |
|
|
// close and exit |
155 |
|
|
// -------------- |
156 |
|
|
Finish(); |
157 |
|
|
|
158 |
|
|
return 0; |
159 |
|
|
|
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
///////////////////////////////////////////////////////////////// |
163 |
|
|
|
164 |
|
|
void usage(){ |
165 |
|
|
|
166 |
|
|
cout << "------------------------------------------------------------"<<endl; |
167 |
|
|
cout << "Loop over events (on one or more Level2-files), applying some selection cuts, \n"; |
168 |
|
|
cout << "creating output histograms and/or trees with selected events. \n \n "; |
169 |
|
|
cout << "USAGE:"<<endl; |
170 |
|
|
cout << "-processFile file - list of files (.txt) or single file (.root) to be analysed \n"; |
171 |
|
|
cout << "-outputFile PATH - name of the output file \n"; |
172 |
|
|
cout << "-NumEvents XXX - number of events to be analysed \n"; |
173 |
|
|
cout << "-FirstEvent XXX - first event to be analysed \n"; |
174 |
|
|
cout << "--debug, -g - debug mode \n"; |
175 |
|
|
cout << "--help, -h - print this help \n"; |
176 |
|
|
cout << "-input-options [ options ] - options: \n"; |
177 |
|
|
cout << " +(-)ALL --> inlcude(exclude) all default level1/level2 trees and branches \n " ; |
178 |
|
|
cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) level1/level2 trees and branches \n" ; |
179 |
|
|
cout << " +TRK0 +CAL0 +TOF0 --> include level0 branches \n" ; |
180 |
|
|
cout << "-output-options [ options ] - options: \n"; |
181 |
|
|
cout << " fillHistos --> create an output file with histograms \n"; |
182 |
|
|
cout << " fillTree --> create an output file with trees storing the selected events \n "; |
183 |
|
|
cout << " == NB == "<<endl; |
184 |
|
|
cout << " output level1/level2 tree is created with the same trees/branches as read from input file."<<endl; |
185 |
|
|
cout << " in order to modify the output structure use the following options:"<<endl; |
186 |
|
|
cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; |
187 |
|
|
cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; |
188 |
|
|
cout << "------------------------------------------------------------"<<endl; |
189 |
|
|
} |
190 |
|
|
// |
191 |
|
|
int HandleInputPar(int argc, char **argv){ |
192 |
|
|
|
193 |
|
|
if(argc>1){ |
194 |
|
|
|
195 |
|
|
if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ |
196 |
|
|
usage(); |
197 |
|
|
return(1); |
198 |
|
|
}; |
199 |
|
|
// ----------------------- |
200 |
|
|
// Read input parameters |
201 |
|
|
// ----------------------- |
202 |
|
|
DEBUG = false; |
203 |
|
|
DIR = gSystem->WorkingDirectory(); |
204 |
|
|
LIST = ""; |
205 |
|
|
OUTFILE = ""; |
206 |
|
|
I_OPTIONS = "+AUTO "; |
207 |
|
|
O_OPTIONS = "fillHistos"; |
208 |
|
|
MAXEV = 0; |
209 |
|
|
MINEV = 0; |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
for (int i = 1; i < argc; i++){ |
213 |
|
|
// -----------------------------------------------------// |
214 |
|
|
if (!strcmp(argv[i], "-processFile")){ |
215 |
|
|
if (++i >= argc) throw -1; |
216 |
|
|
LIST = argv[i]; |
217 |
|
|
cout << "processFile "<<LIST<<endl; |
218 |
|
|
continue; |
219 |
|
|
} |
220 |
|
|
// -----------------------------------------------------// |
221 |
|
|
else if (!strcmp(argv[i], "-processDir")){ |
222 |
|
|
if (++i >= argc) throw -1; |
223 |
|
|
DIR = argv[i]; |
224 |
|
|
cout << "processDir "<<DIR<<endl; |
225 |
|
|
continue; |
226 |
|
|
} |
227 |
|
|
// -----------------------------------------------------// |
228 |
|
|
else if (!strcmp(argv[i], "-outputFile")){ |
229 |
|
|
if (++i >= argc) throw -1; |
230 |
|
|
OUTFILE = argv[i]; |
231 |
|
|
cout << "outputFile "<<OUTFILE<<endl; |
232 |
|
|
continue; |
233 |
|
|
} |
234 |
|
|
// -----------------------------------------------------// |
235 |
|
|
else if (!strcmp(argv[i], "-FirstEvent")){ |
236 |
|
|
if (++i >= argc) throw -1; |
237 |
|
|
MINEV = atoi(argv[i]); |
238 |
|
|
cout << "FirstEvent "<<MINEV<<endl; |
239 |
|
|
continue; |
240 |
|
|
} |
241 |
|
|
// -----------------------------------------------------// |
242 |
|
|
else if (!strcmp(argv[i], "-NumEvents")){ |
243 |
|
|
if (++i >= argc) throw -1; |
244 |
|
|
MAXEV = atoi(argv[i]); |
245 |
|
|
cout << "NumEvents "<<MAXEV<<endl; |
246 |
|
|
continue; |
247 |
|
|
} |
248 |
|
|
// -----------------------------------------------------// |
249 |
|
|
else if (!strcmp(argv[i], "-input-options")){ |
250 |
|
|
if (++i >= argc) throw -1; |
251 |
|
|
I_OPTIONS = argv[i]; |
252 |
|
|
if( I_OPTIONS.Contains("[") ){ |
253 |
|
|
do{ |
254 |
|
|
if (++i >= argc) throw -1; |
255 |
|
|
I_OPTIONS.Append(argv[i]); |
256 |
|
|
}while(!I_OPTIONS.Contains("]")); |
257 |
|
|
}else cout << "wrong option format --> ignoring " << endl; |
258 |
|
|
} |
259 |
|
|
// -----------------------------------------------------// |
260 |
|
|
else if (!strcmp(argv[i], "-output-options")){ |
261 |
|
|
if (++i >= argc) throw -1; |
262 |
|
|
O_OPTIONS = argv[i]; |
263 |
|
|
if( O_OPTIONS.Contains("[") ){ |
264 |
|
|
do{ |
265 |
|
|
if (++i >= argc) throw -1; |
266 |
|
|
O_OPTIONS.Append(argv[i]); |
267 |
|
|
}while(!O_OPTIONS.Contains("]")); |
268 |
|
|
}else cout << "wrong option format --> ignoring " << endl; |
269 |
|
|
} |
270 |
|
|
// -----------------------------------------------------// |
271 |
|
|
else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ |
272 |
|
|
DEBUG = true; |
273 |
|
|
continue; |
274 |
|
|
} |
275 |
|
|
// -----------------------------------------------------// |
276 |
|
|
else{ |
277 |
|
|
cout << "Unidentified input parameter. Ignored."<< endl; |
278 |
|
|
}; |
279 |
|
|
}; |
280 |
|
|
}else{ |
281 |
|
|
usage(); |
282 |
|
|
return(1); |
283 |
|
|
}; |
284 |
|
|
// ----------------------- |
285 |
|
|
// Check input parameters |
286 |
|
|
// ----------------------- |
287 |
|
|
|
288 |
|
|
|
289 |
|
|
return(0); |
290 |
|
|
|
291 |
|
|
}; |
292 |
|
|
// |
293 |
|
|
|
294 |
|
|
int main(int argc, char **argv) |
295 |
|
|
{ |
296 |
|
|
|
297 |
|
|
if( HandleInputPar(argc,argv) )return(1); |
298 |
|
|
|
299 |
|
|
cout << "INPUT OPTIONS "<<I_OPTIONS<<endl; |
300 |
|
|
cout << "OUTPUT OPTIONS "<<O_OPTIONS<<endl; |
301 |
|
|
Loop(DIR,LIST,MAXEV,MINEV,I_OPTIONS,O_OPTIONS,OUTFILE); |
302 |
|
|
|
303 |
|
|
cout << "Back to main - end"<<endl; |
304 |
|
|
|
305 |
|
|
return 0; |
306 |
|
|
|
307 |
|
|
}; |
308 |
|
|
|