/[PAMELA software]/calo/flight/CaloFranzini/src/CaloCreateMatrix.cpp
ViewVC logotype

Contents of /calo/flight/CaloFranzini/src/CaloCreateMatrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Thu Jan 3 10:02:27 2008 UTC (16 years, 11 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +34 -2 lines
A lot of upgrades

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

  ViewVC Help
Powered by ViewVC 1.1.23