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