/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloCore.cpp
ViewVC logotype

Annotation of /DarthVader/CalorimeterLevel2/src/CaloCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.48 - (hide annotations) (download)
Fri Jan 29 05:49:23 2010 UTC (14 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v9r00, v9r01
Changes since 1.47: +6 -6 lines
Check I/O problems while getting entry

1 mocchiut 1.1 //
2     // Given a calibration and a data file this program create an ntuple with LEVEL2 calorimeter variables - Emiliano Mocchiutti
3     //
4 mocchiut 1.3 // CaloCore.cxx version 3.05 (2006-05-30)
5 mocchiut 1.1 //
6     // The only input needed is the path to the directory created by YODA for the data file you want to analyze.
7     //
8     // Changelog:
9 mocchiut 1.3 //
10 mocchiut 1.11 // 3.08 (2006-11-13): Added high energy nuclei capability and "process all events" capability.
11     //
12 mocchiut 1.4 // 3.04 - 3.05 (2006-05-30): Qlast and nlast are now calculated using 4 (not 8) strips aournd the shower axis. Small bug fixed.
13 mocchiut 1.2 //
14     // 3.03 - 3.04 (2006-05-23): Forgot to put impx and impy in the PAMELA reference system, fixed.
15 mocchiut 1.1 //
16     // 3.02 - 3.03 (2006-05-18): updated to be called in DarthVader. Output dimension are now in cm and in the PAMELA reference system.
17     //
18     // 3.01 - 3.02 (2006-04-21): when copying entries get size of caclone and not of ca... (shouldn't matter). Fixed increasing file dimension bug when reprocessing.
19     // Added variable planemax[2], plane of maximum energy release (x and y) in final output. Use ItoRunInfo instead of RunInfo.
20     //
21     // 3.00 - 3.01 (2006-04-14): fixed small bug in tagging the track used to determine track-related variables, put in caloprocessing the opening of parameters files, fixed
22     // small bug in fortran routines
23     //
24     // 2.01 - 3.00 (2006-04-14): almost everything has changed. Now it can process one, all or some runs, introduced the final CaloLevel2 class+methods and the
25     // working class "CaloProcessing", linked to the preliminary tracker flight software v0r00, reads YODA unique output files,
26     // reduced the number of installed libraries, F77 programs splitted depending on the function contained, introduced the readout and
27     // processing of self-trigger events, if the tracker provides more than one track all calorimeter track-related variables are saved
28     // as many times as the number of tracks (via the TClonesArray object in the level2 rootple) and many other small changes.
29     //
30     // 2.00 - 2.01 (2006-01-26): bug: wrong calculation of baselines in some cases, fixed.
31     //
32     // 1.00 - 2.00 (2006-01-11): use TSQL ROOT classes instead of directly calling MySQL.
33     //
34     // 0.00 - 1.00 (2005-09-14): seems working.
35     //
36     // 0.00 (2005-09-09): clone of CaloLEVEL2.c .
37     //
38     // C/C++ headers
39     //
40     #include <fstream>
41     #include <string.h>
42     //
43     // ROOT headers
44     //
45     #include <TTree.h>
46     #include <TClassEdit.h>
47     #include <TObject.h>
48     #include <TList.h>
49 mocchiut 1.8 #include <TArrayI.h>
50 mocchiut 1.1 #include <TSystem.h>
51     #include <TSystemDirectory.h>
52     #include <TString.h>
53     #include <TFile.h>
54     #include <TClass.h>
55     #include <TCanvas.h>
56     #include <TH1.h>
57     #include <TH1F.h>
58     #include <TH2D.h>
59     #include <TLatex.h>
60     #include <TPad.h>
61     #include <TSQLServer.h>
62     #include <TSQLRow.h>
63     #include <TSQLResult.h>
64     #include <TClonesArray.h>
65     #include <TStreamerInfo.h>
66     //
67 mocchiut 1.20 // This program headers
68     //
69     #include <RunInfo.h>
70     //
71 mocchiut 1.1 // YODA headers
72     //
73     #include <PamelaRun.h>
74     #include <physics/trigger/TriggerEvent.h>
75     //
76     // This program headers
77     //
78     #include <CaloCore.h>
79 mocchiut 1.13 #include <CaloLevel1.h>
80 mocchiut 1.1 #include <CaloLevel2.h>
81 mocchiut 1.22 #include <CaloLevel0.h>
82 mocchiut 1.1 #include <CaloVerl2.h>
83     //
84     // Tracker classes headers and definitions
85     //
86     #include <TrkLevel2.h>
87     //
88     using namespace std;
89     //
90 mocchiut 1.47 // IsCaloSelfTrigger method from Nicola (adapted)
91     //
92     //===============================================================================
93     // The IsCaloSelfTrigger functions checks in the trigger pattern register
94     // whether the event has been triggered by the calorimeter or not.
95     // Since the calorimeter self trigger coincidences are slower than both
96     // TOF and S4 triggers the triggering condition is checked for these detectors
97     // before looking for a calorimeter coincidence
98     //===============================================================================
99     //Int_t IsCaloSelfTrigger(TrigLevel2* event)
100     Int_t IsCaloSelfTrigger(UInt_t tc, UInt_t *pt)
101     {
102     // UInt_t tc, *pt;
103     bool S1or, S2or, S3or;
104     bool S1and, S2and, S3and;
105    
106     // tc = event->trigconf;
107     // pt = event->patterntrig;
108    
109     if (tc & CCALIB_ON) return false; // calibration trigger
110    
111     S1or = S11(pt) || S12(pt);
112     S2or = S21(pt) || S22(pt);
113     S3or = S31(pt) || S32(pt);
114     S1and = S11(pt) && S12(pt);
115     S2and = S21(pt) && S22(pt);
116     S3and = S31(pt) && S32(pt);
117    
118     switch (tc & ~(CCALO | CS4 | CCALIB_ON)) {
119     case CTOF1:
120     if (S1or && S2or && S3or) return 0; // TOF1 trigger
121     break;
122     case CTOF2:
123     if (S1and && S2and && S3and) return 0; // TOF2 trigger
124     break;
125     case CTOF3:
126     if (S2or && S3or) return 0; // TOF3 trigger
127     break;
128     case CTOF4:
129     if (S2and && S3and) return 0; // TOF4 trigger
130     break;
131     case CTOF5:
132     if (S12(pt) && S2and) return 0; // TOF5 trigger
133     break;
134     case CTOF6:
135     if (S1or && S3or) return 0; // TOF6 trigger
136     break;
137     case CTOF7:
138     if (S1and && S3and) return 0; // TOF7 trigger
139     break;
140     default: // other trigger configuration
141     break;
142     }
143    
144     if ((tc & CS4) && PS4(pt)) return 2; // S4 trigger
145    
146     if (PCaloST(pt)) return 2; // calorimeter trigger
147    
148     return 2; // nobody gernerated the trigger?
149     }
150    
151     //
152 mocchiut 1.1 // CORE ROUTINE
153     //
154 mocchiut 1.32 int CaloCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t calargc, char *calargv[]){
155 mocchiut 1.1 //
156     // Set these to true to have a very verbose output.
157     //
158     Bool_t verbose = false;
159     Bool_t debug = false;
160     //
161 mocchiut 1.21 Bool_t crosst = true;
162 mocchiut 1.36 Bool_t ctground = false;
163 mocchiut 1.41 Bool_t usetable = true;
164     Bool_t noselfct = false;
165 mocchiut 1.21 //
166 mocchiut 1.11 Bool_t trackanyway = true;
167     //
168     Float_t rigdefault = 50.;
169 mocchiut 1.35 //
170 mocchiut 1.11 Bool_t hZn = true;
171     //
172     Bool_t withtrk = true;
173     //
174     Bool_t st = true;
175     //
176 mocchiut 1.13 Bool_t getl1 = true;
177     //
178 mocchiut 1.23 Bool_t mechal = false;
179     //
180 mocchiut 1.30 Bool_t checksimu = true;
181     //
182 mocchiut 1.47 Bool_t mask18 = false;
183     //
184 mocchiut 1.1 // Output directory is the working directoy.
185     //
186     const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
187     //
188     Int_t ri = 0;
189 mocchiut 1.26 TString processFolder = Form("calorimeterFolder_%u",run);
190 mocchiut 1.1 if ( calargc > 0 ){
191     ri = 0;
192     while ( ri < calargc ){
193     if ( !strcmp(calargv[ri],"-processFolder") ) {
194     if ( calargc < ri+1 ){
195     throw -3;
196     };
197     processFolder = (TString)calargv[ri+1];
198     ri++;
199     };
200     if ( !strcmp(calargv[ri],"-v") || !strcmp(calargv[ri],"--verbose") ) {
201     verbose = true;
202     };
203     if ( !strcmp(calargv[ri],"-g") || !strcmp(calargv[ri],"--debug") ) {
204 mocchiut 1.13 verbose = true;
205 mocchiut 1.1 debug = true;
206     };
207 mocchiut 1.11 if ( !strcmp(calargv[ri],"--alltracks") ) {
208     trackanyway = true;
209     };
210 mocchiut 1.23 if ( !strcmp(calargv[ri],"--use-default-alig") ) {
211     mechal = true;
212     };
213 mocchiut 1.21 if ( !strcmp(calargv[ri],"--no-crosstalk") ) {
214     crosst = false;
215     };
216 mocchiut 1.47 if ( !strcmp(calargv[ri],"--mask-plane18X") ) {
217     mask18 = true;
218     };
219     if ( !strcmp(calargv[ri],"--unmask-plane18X") ) {
220     mask18 = false;
221     };
222 mocchiut 1.34 if ( !strcmp(calargv[ri],"--flight-crosstalk") ) {
223     ctground = false;
224     };
225 mocchiut 1.41 if ( !strcmp(calargv[ri],"--ct-use-pulse") ) {
226     usetable = false;
227     };
228     if ( !strcmp(calargv[ri],"--ct-use-table") ) {
229     usetable = true;
230     };
231 mocchiut 1.34 if ( !strcmp(calargv[ri],"--ground-crosstalk") ) {
232     ctground = true;
233     };
234 mocchiut 1.41 if ( !strcmp(calargv[ri],"--no-self-crosstalk") ) {
235     noselfct = true;
236     };
237 mocchiut 1.11 if ( !strcmp(calargv[ri],"--no-tracker") ) {
238     withtrk = false;
239     };
240     if ( !strcmp(calargv[ri],"--with-tracker") ) {
241     withtrk = true;
242     };
243     if ( !strcmp(calargv[ri],"--defrig") ) {
244     if ( calargc < ri+1 ){
245     throw -3;
246     };
247     rigdefault = atof(calargv[ri+1]);
248     ri++;
249     };
250     if ( !strcmp(calargv[ri],"--no-alltracks") ) {
251     trackanyway = false;
252     };
253     if ( !strcmp(calargv[ri],"--highZnuclei") ) {
254     hZn = true;
255     };
256     if ( !strcmp(calargv[ri],"--no-highZnuclei") ) {
257     hZn = false;
258     };
259     if ( !strcmp(calargv[ri],"--selftrigger") ) {
260     st = true;
261     };
262     if ( !strcmp(calargv[ri],"--no-selftrigger") ) {
263     st = false;
264     };
265 mocchiut 1.13 if ( !strcmp(calargv[ri],"--no-level1") ) {
266     getl1 = false;
267     };
268 mocchiut 1.41 if ( !strcmp(calargv[ri],"--level1") ) {
269     getl1 = true;
270     };
271 mocchiut 1.30 if ( !strcmp(calargv[ri],"--ignore-h20") ) {
272     checksimu = false;
273     };
274 mocchiut 1.11 if ( !strcmp(calargv[ri],"--help") ) {
275     printf("\n\n CALORIMETER HELP CALLED\n\n");
276     printf(" CaloCore options: \n");
277     printf(" -v | --verbose be verbose\n");
278     printf(" -g | --debug be really verbose\n");
279     printf(" --defrig rig rig is the default rigidity in GV to be used to\n");
280     printf(" obtain calorimeter variables in the routines\n");
281     printf(" \"alltracks\" and \"higZnuclei\" [default = 50]\n");
282     printf(" --alltracks fill the track related variables even in the case\n");
283     printf(" of no tracks from tracker and no selftrigger event\n");
284 mocchiut 1.14 printf(" when we have a calorimeter fit for both views [default]\n");
285     printf(" --no-alltracks fill the track related variables only in the case\n");
286     printf(" of a good track from tracker or selftrigger\n");
287 mocchiut 1.11 printf(" --highZnuclei call the routine to analyze high Z nuclei\n");
288     printf(" selftrigger events [default]\n");
289     printf(" --no-highZnuclei do not call the routine to analyze high Z nuclei\n");
290     printf(" selftrigger events\n");
291     printf(" --no-tracker do not use tracker level2\n");
292     printf(" --with-tracker use tracker level2 [default]\n");
293 mocchiut 1.21 printf(" --no-crosstalk do not apply crosstalk corrections\n");
294 mocchiut 1.37 printf(" --ground-crosstalk apply ground crosstalk corrections\n");
295     printf(" --flight-crosstalk apply flight crosstalk corrections [default]\n");
296 mocchiut 1.41 printf(" --no-self-crosstalk do not apply preamplifiers crosstalk corrections to the strip itself\n");
297     printf(" --ct--use-pulse flight crosstalk corrections from pulse calibrations \n");
298     printf(" --ct--use-table flight crosstalk corrections from calibration table [default] \n");
299 mocchiut 1.11 printf(" --selftrigger process selftrigger events [default]\n");
300     printf(" --no-selftrigger skip selftrigger events\n");
301 mocchiut 1.13 printf(" --no-level1 do not save Level1 TBranch\n");
302 mocchiut 1.41 printf(" --level1 save Level1 TBranch [default] \n");
303 mocchiut 1.30 printf(" --ignore-h20 do not check if it is a file from simulations\n");
304 mocchiut 1.27 printf(" --use-default-alig use default mechanical alignement (defined in CaloLevel1.h)\n");
305 mocchiut 1.11 throw -114;
306     };
307 mocchiut 1.1 ri++;
308     };
309     };
310     //
311 mocchiut 1.13 if ( verbose ){
312     printf("\n");
313     if ( getl1 ) printf(" Saving calorimeter level1 data \n");
314     if ( st ) printf(" Calling selftrigger subroutine \n");
315     if ( hZn ) printf(" Calling high energy nuclei subroutine \n");
316     if ( trackanyway ) printf(" Filling track related variables for all the possible tracks \n");
317     if ( hZn || trackanyway ) printf(" => default assumed rigidity %f \n",rigdefault);
318     if ( withtrk ) printf(" Using tracker level2 data \n");
319 mocchiut 1.27 if ( mechal ) printf(" Using default mechanical alignement (defined in CaloLevel1.h)\n");
320 mocchiut 1.34 if ( crosst ){
321     printf(" Applying cross-talk corrections \n");
322     if ( ctground ){
323     printf(" => Using ground cross-talk coefficients \n");
324     } else {
325 mocchiut 1.41 printf(" => Using flight cross-talk coefficients... \n");
326     };
327     if ( usetable ){
328     printf(" ... coming from tables \n");
329     } else {
330     printf(" ... coming from pulse calibrations \n");
331 mocchiut 1.34 };
332     } else {
333     printf(" Do not applying cross-talk corrections \n");
334     };
335     if ( !checksimu ) printf(" Check on h20 TTree in level2 file skipped \n");
336 mocchiut 1.13 printf("\n");
337     };
338 mocchiut 1.11 //
339 mocchiut 1.1 // Working filename
340     //
341     TString outputfile;
342     stringstream name;
343     name.str("");
344     name << outdir << "/";
345     //
346     // Variables.
347     //
348     TTree *tracker = 0;
349     TTree *calo = 0;
350     TTree *caloclone = 0;
351     Bool_t reproc = false;
352     Bool_t reprocall = false;
353 mocchiut 1.8 UInt_t nevents = 0;
354 mocchiut 1.1 UInt_t nobefrun = 0;
355     UInt_t noaftrun = 0;
356     UInt_t numbofrun = 0;
357 mocchiut 1.8 UInt_t totnorun = 0;
358 mocchiut 1.1 //
359     Int_t code = 0;
360     Int_t sgnl;
361     //
362     // calorimeter level2 classes
363     //
364 mocchiut 1.13 CaloLevel1 *c1 = 0;
365     CaloLevel1 *c1clone = 0;
366     if ( getl1 ){
367     c1 = new CaloLevel1();
368     c1clone = new CaloLevel1();
369     };
370     //
371     // calorimeter level2 classes
372     //
373 mocchiut 1.1 CaloLevel2 *ca = new CaloLevel2();
374     CaloLevel2 *caclone = new CaloLevel2();
375     //
376     TrkLevel2 *trk = new TrkLevel2();
377 mocchiut 1.8 Int_t nevtrkl2 = 0;
378 mocchiut 1.1 //
379     UInt_t procev = 0;
380     //
381 mocchiut 1.8 // define variables where to store the absolute run header and run trailer times (unsigned long long integers, when set to a number use to store the correct number).
382 mocchiut 1.1 //
383 mocchiut 1.8 UInt_t runheadtime = 0;
384     UInt_t runtrailtime = 0;
385 mocchiut 1.1 UInt_t evfrom = 0;
386     UInt_t evto = 0;
387 mocchiut 1.8 UInt_t totfileentries = 0;
388     UInt_t idRun = 0;
389 mocchiut 1.1 Int_t id_reg_run=-1;
390     stringstream ftmpname;
391     TString fname;
392     //
393     // define variables for opening and reading level0 file
394     //
395     TFile *l0File = 0;
396     TTree *l0tr = 0;
397 mocchiut 1.24 TTree *softinfo = 0;
398 mocchiut 1.1 TBranch *l0head = 0;
399     TBranch *l0calo = 0;
400     TBranch *l0trig = 0;
401 mocchiut 1.8 pamela::EventHeader *eh = 0;
402     pamela::PscuHeader *ph = 0;
403 mocchiut 1.1 pamela::trigger::TriggerEvent *trig = 0;
404 mocchiut 1.24 Int_t yodaver = 0;
405 mocchiut 1.1 //
406     // Define some basic variables
407     //
408 mocchiut 1.22 CaloLevel0 *event = new CaloLevel0(); // NOTICE: very important to call here the constructor!
409 mocchiut 1.21 event->SetCrossTalk(crosst);
410 mocchiut 1.41 // event->SetCrossTalkType(ctground);
411     Int_t ict = -1;
412     if ( ctground ) ict = 0;
413     if ( !ctground ){
414     ict = 1;
415     };
416     if ( !ctground && noselfct ){
417     ict = 2;
418     };
419     event->SetCrossTalkType(ict);
420 mocchiut 1.1 stringstream file2;
421     stringstream file3;
422     stringstream qy;
423     // Bool_t imtrack = false;
424     Bool_t filled = false;
425     //
426 mocchiut 1.8 UInt_t caloevents = 0;
427 mocchiut 1.1 stringstream calfile;
428     stringstream aligfile;
429     //
430     Int_t i = -1;
431     Int_t itr = -1;
432     Int_t badevent = 0;
433     Int_t totevent = 0;
434     //
435 mocchiut 1.8 UInt_t atime = 0;
436 mocchiut 1.1 //
437 mocchiut 1.47 // Int_t S3 = 0;
438     // Int_t S2 = 0;
439     // Int_t S12 = 0;
440     // Int_t S11 = 0;
441 mocchiut 1.1 UInt_t re = 0;
442 mocchiut 1.9 UInt_t jumped = 0;
443 mocchiut 1.1 //
444     TString caloversion;
445     ItoRunInfo *runinfo = 0;
446 mocchiut 1.8 TArrayI *runlist = 0;
447 mocchiut 1.1 //
448 mocchiut 1.47 // Float_t tmptrigty = -1.;
449 mocchiut 1.1 Int_t ntrkentry = 0;
450     GL_PARAM *q4 = new GL_PARAM();
451 mocchiut 1.8 UInt_t tttrkpar1 = 0;
452 mocchiut 1.1 Bool_t trkpar1 = true;
453     GL_ROOT *glroot = new GL_ROOT();
454 mocchiut 1.8 GL_TIMESYNC *dbtime = 0;
455 mocchiut 1.1 //
456 mocchiut 1.15 Long64_t maxsize = 10000000000LL;
457     TTree::SetMaxTreeSize(maxsize);
458 mocchiut 1.1 //
459     //
460     TFile *tempfile = 0;
461     TTree *tempcalo = 0;
462 mocchiut 1.30 Bool_t myfold = false;
463 mocchiut 1.1 stringstream tempname;
464     stringstream calofolder;
465     tempname.str("");
466     tempname << outdir;
467     tempname << "/" << processFolder.Data();
468     calofolder.str("");
469     calofolder << tempname.str().c_str();
470     tempname << "/calotree_run";
471     tempname << run << ".root";
472     //
473     // As a first thing we must check what we have to do: if run = -1 we must process all events in the file has been passed
474     // if run != -1 we must process only that run but first we have to check if the branch calorimeter already exist in the file
475     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
476     //
477 mocchiut 1.8 if ( run == 0 ) reproc = true;
478 mocchiut 1.1 //
479     //
480     //
481     if ( !file->IsOpen() ){
482     if ( verbose ) printf(" CALORIMETER - ERROR: cannot open file for writing\n");
483     throw -101;
484     };
485     //
486 mocchiut 1.11 if ( withtrk ){
487     //
488     // Does it contain the Tracker tree?
489     //
490     tracker = (TTree*)file->Get("Tracker");
491     if ( !tracker ) {
492     if ( verbose ) printf(" CALORIMETER - ERROR: no tracker tree\n");
493     code = -102;
494     goto closeandexit;
495     };
496     tracker->SetBranchAddress("TrkLevel2",&trk);
497     nevtrkl2 = tracker->GetEntries();
498 mocchiut 1.1 };
499     //
500 mocchiut 1.30 // Is it a file from simulations?
501     //
502     if ( checksimu ){
503     TTree *h20 = (TTree*)file->Get("h20");
504     if ( h20 ){
505     //
506     // yes!
507     //
508     crosst = false;
509 mocchiut 1.34 ctground = true;
510 mocchiut 1.30 mechal = true;
511 mocchiut 1.47 mask18 = true;
512     if ( verbose ) printf("\n\n SIMULATION!!! Setting --use-default-alig and --no-crosstalk --mask-plane18X flags!\n\n");
513 mocchiut 1.30 h20->Delete();
514     };
515     };
516     //
517 mocchiut 1.1 // Call runinfo
518     //
519     sgnl = 0;
520     runinfo = new ItoRunInfo(file);
521     //
522     // update versioning information and retrieve informations about the run to be processed
523     //
524     caloversion = CaloInfo(false);
525     sgnl = runinfo->Update(run,"CALO",caloversion);
526     //
527     if ( sgnl ){
528     if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n");
529     code = sgnl;
530     goto closeandexit;
531     } else {
532     sgnl = 0;
533     };
534     //
535     // number of events in the file BEFORE the first event of our run
536     //
537     nobefrun = runinfo->GetFirstEntry();
538     //
539     // total number of events in the file
540     //
541     totfileentries = runinfo->GetFileEntries();
542     //
543     // first file entry AFTER the last event of our run
544     //
545     noaftrun = runinfo->GetLastEntry() + 1;
546     //
547     // number of run to be processed
548     //
549     numbofrun = runinfo->GetNoRun();
550     //
551     // number of runs in the file
552     //
553     totnorun = runinfo->GetRunEntries();
554     //
555     // Does it contain already a Calorimeter branch? if so we are reprocessing data, if not we must create it.
556     //
557     caloclone = (TTree*)file->Get("Calorimeter");
558     //
559     if ( !caloclone ){
560     reproc = false;
561 mocchiut 1.8 if ( run == 0 && verbose ) printf(" CALORIMETER - WARNING: you are reprocessing data but calorimeter tree does not exist!\n");
562     if ( runinfo->IsReprocessing() && run != 0 && verbose ) printf(" CALORIMETER - WARNING: it seems you are not reprocessing data but calorimeter\n versioning information already exists in RunInfo.\n");
563 mocchiut 1.1 //
564     } else {
565     //
566 mocchiut 1.15 caloclone->SetAutoSave(900000000000000LL);
567 mocchiut 1.1 reproc = true;
568     //
569     if ( verbose ) printf("\n Preparing the pre-processing...\n");
570     //
571 mocchiut 1.28 if ( run == 0 || totnorun == 1 ){
572 mocchiut 1.1 //
573     // if we are reprocessing everything we don't need to copy any old event and we can just create a new branch in the clone tree and jump steps 4/5/7.
574     //
575     if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing all runs in the file\n");
576     reprocall = true;
577     //
578     } else {
579     //
580     // we are reprocessing a single run
581     //
582 mocchiut 1.8 if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing run number %u \n",run);
583 mocchiut 1.1 reprocall = false;
584     //
585     //
586     //
587 mocchiut 1.30 gSystem->MakeDirectory(calofolder.str().c_str());
588     myfold = true;
589 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
590     tempcalo = caloclone->CloneTree(-1,"fast");
591     tempcalo->SetName("Calorimeter-old");
592     tempfile->Write();
593     tempfile->Close();
594     };
595     //
596     // delete old tree
597     //
598     caloclone->Delete("all");
599     //
600     if ( verbose ) printf("\n ...done!\n");
601     //
602     };
603     //
604     // create calorimeter tree calo
605     //
606     file->cd();
607     calo = new TTree("Calorimeter-new","PAMELA Level2 calorimeter data");
608 mocchiut 1.15 calo->SetAutoSave(900000000000000LL);
609 pam-fi 1.16 ca->Set();
610 mocchiut 1.1 calo->Branch("CaloLevel2","CaloLevel2",&ca);
611 mocchiut 1.13 if ( getl1 ) calo->Branch("CaloLevel1","CaloLevel1",&c1);
612 mocchiut 1.1 //
613     if ( reproc && !reprocall ){
614     //
615     //
616     //
617     tempfile = new TFile(tempname.str().c_str(),"READ");
618     caloclone = (TTree*)tempfile->Get("Calorimeter-old");
619 mocchiut 1.15 caloclone->SetAutoSave(900000000000000LL);
620 mocchiut 1.1 caloclone->SetBranchAddress("CaloLevel2",&caclone);
621 mocchiut 1.13 TBranch *havel1 = caloclone->GetBranch("CaloLevel1");
622     if ( !havel1 && getl1 ) throw -117;
623     if ( havel1 && !getl1 ) throw -118;
624     if ( getl1 ) caloclone->SetBranchAddress("CaloLevel1",&c1clone);
625 mocchiut 1.1 //
626     if ( nobefrun > 0 ){
627     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
628 mocchiut 1.8 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
629 mocchiut 1.1 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
630     for (UInt_t j = 0; j < nobefrun; j++){
631     //
632 mocchiut 1.48 if ( caloclone->GetEntry(j) <= 0 ) throw -36;
633 mocchiut 1.1 //
634     // copy caclone to ca
635     //
636 mocchiut 1.13 if ( getl1 ) memcpy(&c1,&c1clone,sizeof(c1clone));
637 mocchiut 1.1 memcpy(&ca,&caclone,sizeof(caclone));
638     //
639     // Fill entry in the new tree
640     //
641     calo->Fill();
642     //
643 mocchiut 1.13 if ( getl1 ) c1->Clear();
644 mocchiut 1.6 ca->Clear();
645     //
646 mocchiut 1.1 };
647     if ( verbose ) printf(" Finished successful copying!\n");
648     };
649     };
650     //
651     // Get the list of run to be processed
652     //
653     runlist = runinfo->GetRunList();
654     //
655     // Loop over the run to be processed
656     //
657     for (UInt_t irun=0; irun < numbofrun; irun++){
658     //
659     badevent = 0;
660     //
661     idRun = runlist->At(irun);
662     if ( verbose ) printf("\n\n\n ####################################################################### \n");
663 mocchiut 1.8 if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun);
664 mocchiut 1.1 if ( verbose ) printf(" ####################################################################### \n\n\n");
665     //
666     sgnl = runinfo->GetRunInfo(idRun);
667     if ( sgnl ){
668     if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n");
669     code = sgnl;
670     goto closeandexit;
671     } else {
672     sgnl = 0;
673     };
674 mocchiut 1.8 id_reg_run = runinfo->ID_ROOT_L0;
675 mocchiut 1.1 runheadtime = runinfo->RUNHEADER_TIME;
676     runtrailtime = runinfo->RUNTRAILER_TIME;
677 mocchiut 1.8 evfrom = runinfo->EV_FROM;
678     evto = runinfo->EV_TO;
679 mocchiut 1.1 //
680     if ( id_reg_run == -1 ){
681 mocchiut 1.8 if ( verbose ) printf("\n CALORIMETER - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
682 mocchiut 1.1 code = -5;
683     goto closeandexit;
684     };
685     //
686 mocchiut 1.8 // prepare the timesync for the db
687     //
688 mocchiut 1.32 TString host = glt->CGetHost();
689     TString user = glt->CGetUser();
690     TString psw = glt->CGetPsw();
691     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
692     if ( !dbc->IsConnected() ) throw -116;
693 mocchiut 1.33 stringstream myquery;
694     myquery.str("");
695     myquery << "SET time_zone='+0:00'";
696     dbc->Query(myquery.str().c_str());
697 mocchiut 1.32 //
698 mocchiut 1.31 // if ( !dbc->IsConnected() ) throw -116;
699 mocchiut 1.8 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
700     //
701 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
702     //
703 mocchiut 1.31 // if ( !dbc->IsConnected() ) throw -116;
704 mocchiut 1.8 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
705 mocchiut 1.1 //
706     ftmpname.str("");
707     ftmpname << glroot->PATH.Data() << "/";
708     ftmpname << glroot->NAME.Data();
709     fname = ftmpname.str().c_str();
710     //
711     // print out informations
712     //
713 mocchiut 1.8 totevent = runinfo->NEVENTS;
714 mocchiut 1.1 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
715 mocchiut 1.8 if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runheadtime);
716     if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runtrailtime);
717     if ( verbose ) printf(" %i events to be processed for run %u: from %i to %i (reg entries)\n\n",totevent,idRun,evfrom,evfrom+totevent);
718 mocchiut 1.1 //
719 mocchiut 1.43 // if ( !totevent ) goto closeandexit;
720 mocchiut 1.42 //
721 mocchiut 1.1 // Open Level0 file
722     //
723     l0File = new TFile(fname.Data());
724     if ( !l0File ) {
725     if ( verbose ) printf(" CALORIMETER - ERROR: problems opening Level0 file\n");
726     code = -6;
727     goto closeandexit;
728     };
729     l0tr = (TTree*)l0File->Get("Physics");
730     if ( !l0tr ) {
731     if ( verbose ) printf(" CALORIMETER - ERROR: no Physics tree in Level0 file\n");
732     l0File->Close();
733     code = -7;
734     goto closeandexit;
735     };
736     l0head = l0tr->GetBranch("Header");
737     if ( !l0head ) {
738     if ( verbose ) printf(" CALORIMETER - ERROR: no Header branch in Level0 tree\n");
739     l0File->Close();
740     code = -8;
741     goto closeandexit;
742     };
743     l0calo = l0tr->GetBranch("Calorimeter");
744     if ( !l0calo ) {
745     if ( verbose ) printf(" CALORIMETER - ERROR: no Calorimeter branch in Level0 tree\n");
746     l0File->Close();
747     code = -103;
748     goto closeandexit;
749     };
750     l0trig = l0tr->GetBranch("Trigger");
751     if ( !l0trig ) {
752     if ( verbose ) printf(" CALORIMETER - ERROR: no Trigger branch in Level0 tree\n");
753     l0File->Close();
754     code = -104;
755     goto closeandexit;
756     };
757     //
758     l0tr->SetBranchAddress("Trigger", &trig);
759 mocchiut 1.8 l0tr->SetBranchAddress("Header", &eh);
760 mocchiut 1.1 //
761 mocchiut 1.24 softinfo = (TTree*)l0File->Get("SoftInfo");
762     if ( softinfo ){
763     softinfo->SetBranchAddress("SoftInfo",&yodaver);
764 mocchiut 1.48 if ( softinfo->GetEntry(0) <= 0 ) throw -36;
765 mocchiut 1.24 };
766     if ( debug ) printf(" LEVEL0 FILE GENERATED WITH YODA VERSION %i \n",yodaver);
767     //
768 mocchiut 1.38 if ( withtrk ){
769     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runheadtime ) ){
770     trkpar1 = false;
771     Int_t glpar = q4->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc);
772     if ( glpar < 0 ){
773     code = glpar;
774     goto closeandexit;
775     };
776     tttrkpar1 = q4->TO_TIME;
777     // ----------------------------
778     // Read the magnetic field
779     // ----------------------------
780     if ( verbose ) printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data());
781     trk->LoadField(q4->PATH+q4->NAME);
782     if ( verbose ) printf("\n");
783     };
784     };
785     //
786     // Close DB connection
787     //
788     if ( dbc ){
789     dbc->Close();
790     delete dbc;
791     };
792     //
793     //
794 mocchiut 1.1 // Construct the event object, look for the calibration which include the first header
795     //
796     sgnl = 0;
797     if ( verbose ) printf(" Check for calorimeter calibrations and initialize event object \n");
798 mocchiut 1.31 // if ( !dbc->IsConnected() ) throw -116;
799 mocchiut 1.32 event->ProcessingInit(glt,runheadtime,sgnl,l0tr,debug,verbose);
800 mocchiut 1.47 if ( mask18 ){
801     event->MaskPlane18X();
802     } else {
803     event->UnMaskPlane18X();
804     };
805 mocchiut 1.1 if ( verbose ) printf("\n");
806     if ( sgnl == 100 ) {
807     code = sgnl;
808     if ( verbose ) printf(" CALORIMETER - WARNING: run header not included in any calibration interval\n");
809     sgnl = 0;
810     };
811     if ( sgnl ){
812     l0File->Close();
813     code = sgnl;
814     goto closeandexit;
815     };
816     //
817     qy.str("");
818     //
819 mocchiut 1.8 nevents = l0head->GetEntries();
820 mocchiut 1.1 caloevents = l0calo->GetEntries();
821     //
822 mocchiut 1.43 if ( nevents < 1 && totevent ) {
823 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - ERROR: Level0 file is empty\n\n");
824     l0File->Close();
825     code = -11;
826     goto closeandexit;
827     };
828     //
829 mocchiut 1.43 if ( evto > nevents-1 && totevent ) {
830 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - ERROR: too few entries in the registry tree\n");
831     l0File->Close();
832     code = -12;
833     goto closeandexit;
834     };
835     //
836     // Check if we have to load parameter files
837     //
838     sgnl = 0;
839 mocchiut 1.32 sgnl = event->ChkParam(glt,runheadtime,mechal); // calorimeter parameter files
840 mocchiut 1.1 if ( sgnl < 0 ){
841     code = sgnl;
842     l0File->Close();
843     goto closeandexit;
844     };
845     //
846 mocchiut 1.34 // Calculate the cross talk corrections needed for this run using calibration informations
847     //
848     if ( crosst && !ctground ){
849     sgnl = 0;
850 mocchiut 1.41 sgnl = event->CalcCrossTalkCorr(glt,runheadtime,usetable);
851 mocchiut 1.34 if ( sgnl < 0 ){
852     code = sgnl;
853     l0File->Close();
854     goto closeandexit;
855     };
856     };
857     //
858 mocchiut 1.1 // run over all the events of the run
859     //
860     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
861     //
862 mocchiut 1.19 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
863 mocchiut 1.44 // for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+5000); re++){
864 mocchiut 1.40 //for ( re = 92012+3400; re < 92012+3700; re++){
865 mocchiut 1.18 // printf(" i = %i \n",re-200241);
866 mocchiut 1.1 //
867     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
868     //
869 mocchiut 1.39 if ( debug ) printf("\n\n\n EVENT NUMBER %i \n",procev);
870     //
871 mocchiut 1.48 if ( l0head->GetEntry(re) <= 0 ) throw -36;
872 mocchiut 1.1 //
873     // absolute time of this event
874     //
875 mocchiut 1.8 ph = eh->GetPscuHeader();
876     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
877 mocchiut 1.1 //
878     //
879     //
880 mocchiut 1.8 if ( re > caloevents-1 ){
881 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - ERROR: no physics events with entry = %i in Level0 file\n",i);
882     l0File->Close();
883     code = -112;
884     goto closeandexit;
885     };
886     //
887 mocchiut 1.45 if ( atime > (runtrailtime+1) || atime < (runheadtime-1) ) {
888 mocchiut 1.1 if ( verbose ) printf(" CALORIMETER - WARNING: event at time outside the run time window, skipping it\n");
889 mocchiut 1.9 jumped++;
890 mocchiut 1.1 goto jumpev;
891     };
892     //
893     // retrieve tracker informations
894     //
895     if ( !reprocall ){
896 mocchiut 1.19 itr = nobefrun + (re - evfrom - jumped);
897     //itr = re-(46438+200241);
898 mocchiut 1.1 } else {
899 mocchiut 1.9 itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
900 mocchiut 1.1 };
901 mocchiut 1.11 //
902     if ( withtrk ){
903     if ( itr > nevtrkl2 ){
904     if ( verbose ) printf(" CALORIMETER - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
905     l0File->Close();
906     code = -113;
907     goto closeandexit;
908     };
909     //
910     trk->Clear();
911     //
912 mocchiut 1.48 if ( tracker->GetEntry(itr) <= 0 ) throw -36;
913 mocchiut 1.11 //
914 mocchiut 1.1 };
915 mocchiut 1.10 //
916 mocchiut 1.1 procev++;
917     //
918     // start processing
919     //
920 mocchiut 1.13 if ( getl1 ) c1->Clear();
921 mocchiut 1.6 ca->Clear();
922 mocchiut 1.1 //
923     // determine who generate the trigger for this event (TOF, S4/PULSER, CALO)
924     //
925 mocchiut 1.48 if ( l0trig->GetEntry(re) <= 0 ) throw -36;
926 mocchiut 1.47 // S3 = 0;
927     // S2 = 0;
928     // S12 = 0;
929     // S11 = 0;
930     // S3 = trig->patterntrig[2];
931     // S2 = trig->patterntrig[3];
932     // S12 = trig->patterntrig[4];
933     // S11 = trig->patterntrig[5];
934     // if ( trig->patterntrig[1] & (1<<0) ) tmptrigty = 1.;
935     // if ( trig->patterntrig[0] ) tmptrigty = 2.;
936     // if ( S3 || S2 || S12 || S11 ) tmptrigty = 0.;
937     // if ( !(trig->patterntrig[1] & (1<<0)) && !trig->patterntrig[0] && !S3 && !S2 && !S12 && !S11 ) tmptrigty = 1.;
938     // event->clevel2->trigty = tmptrigty;
939     event->clevel2->trigty = (Float_t)IsCaloSelfTrigger(trig->trigconf,(UInt_t*)trig->patterntrig);
940     if ( debug ) printf(" starting with trigty %f \n",event->clevel2->trigty);
941 mocchiut 1.1 //
942     // check if the calibration we are using is still good, if not load another calibration
943     //
944     sgnl = 0;
945 mocchiut 1.32 sgnl = event->ChkCalib(glt,atime);
946 mocchiut 1.1 if ( sgnl < 0 ){
947     code = sgnl;
948     goto closeandexit;
949     };
950     if ( sgnl == 100 ){
951     code = sgnl;
952     if ( verbose ) printf(" CALORIMETER - WARNING: data not associated to any calibration interval\n");
953     badevent++;
954     sgnl = 0;
955     };
956     //
957 mocchiut 1.11 // do we have at least one track from the tracker? this check has been disabled
958 mocchiut 1.1 //
959     event->clevel1->good2 = 1;
960 mocchiut 1.8 //
961 mocchiut 1.29 // use the whole calorimeter, 22 W planes
962     //
963     event->clevel1->npla = 22;
964     //
965     // Use the standard silicon planes shifting
966     //
967     event->clevel1->reverse = 0;
968     //
969 mocchiut 1.1 //
970 mocchiut 1.8 // Calibrate calorimeter event "re" and store output in the two structures that will be passed to fortran routine
971 mocchiut 1.1 //
972 mocchiut 1.11 event->Calibrate(re);
973 mocchiut 1.1 //
974     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract topological variables.
975     //
976     //
977     // Calculate variables common to all tracks (qtot, nstrip, etc.)
978     //
979     event->GetCommonVar();
980     //
981     // Fill common variables
982     //
983 mocchiut 1.13 event->FillCommonVar(c1,ca);
984 mocchiut 1.1 //
985     // Calculate variables related to tracks only if we have at least one track (from selftrigger and/or tracker)
986     //
987     ntrkentry = 0;
988     //
989     filled = false;
990     //
991 mocchiut 1.11 // Run over tracks (tracker or calorimeter )
992     //
993     if ( withtrk ){
994     for(Int_t nt=0; nt < trk->ntrk(); nt++){
995     //
996     event->clevel1->good2 = 1;
997     //
998     TrkTrack *ptt = trk->GetStoredTrack(nt);
999     //
1000     event->clevel1->trkchi2 = 0;
1001     //
1002     // Copy the alpha vector in the input structure
1003     //
1004     for (Int_t e = 0; e < 5 ; e++){
1005     event->clevel1->al_p[e][0] = ptt->al[e];
1006     };
1007     //
1008     // Get tracker related variables for this track
1009     //
1010     event->GetTrkVar();
1011     //
1012     // Save tracker track sequence number
1013     //
1014     event->trkseqno = nt;
1015     //
1016     // Copy values in the class ca from the structure clevel2
1017     //
1018     event->FillTrkVar(ca,ntrkentry);
1019     ntrkentry++;
1020     filled = true;
1021     //
1022     }; // loop on all the tracks
1023     };
1024     //
1025     // if no tracks found but there is the possibility to have a good track we should try to calculate anyway the track related variables using the calorimeter
1026     // fit of the track (to be used for example when TRK is off due to any reason like IPM3/5 off).
1027     // here we make an event selection so it must be done very carefully...
1028     //
1029     // conditions are: 0) no track from the tracker 1) we have a track fit both in x and y 2) no problems with calo for this event 3) no selftrigger event
1030     //
1031     if ( trackanyway && !filled && event->clevel2->npcfit[0] >= 2 && event->clevel2->npcfit[1] >= 2 && event->clevel2->good != 0 && event->clevel2->trigty < 2. ){
1032     if ( debug ) printf(" Event with a track not fitted by the tracker at entry %i \n",itr);
1033     //
1034     // Disable "track mode" in the fortran routine
1035     //
1036     event->clevel1->good2 = 0;
1037     event->clevel1->riginput = rigdefault;
1038     if ( debug ) printf(" Using as default rigidity: %f \n",event->clevel1->riginput);
1039     //
1040     // We have a selftrigger event to analyze.
1041     //
1042     for (Int_t e = 0; e < 5 ; e++){
1043     event->clevel1->al_p[e][0] = 0.;
1044     event->clevel1->al_p[e][1] = 0.;
1045     };
1046     event->clevel1->trkchi2 = 0;
1047     //
1048     event->GetTrkVar();
1049     //
1050     // if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on
1051 mocchiut 1.1 //
1052 mocchiut 1.11 if ( event->clevel1->good2 == 0 ) {
1053 mocchiut 1.1 //
1054 mocchiut 1.11 // In selftrigger mode the trkentry variable is set to -1
1055 mocchiut 1.1 //
1056 mocchiut 1.11 event->trkseqno = -3;
1057 mocchiut 1.1 //
1058 mocchiut 1.11 // Copy values in the class ca from the structure clevel2
1059 mocchiut 1.1 //
1060 mocchiut 1.46 if ( debug ) printf(" -3 begin \n");
1061 mocchiut 1.11 event->FillTrkVar(ca,ntrkentry);
1062 mocchiut 1.46 if ( debug ) printf(" -3 end \n");
1063 mocchiut 1.11 ntrkentry++;
1064     filled = true;
1065     //
1066     } else {
1067     if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr);
1068     };
1069     //
1070     };
1071     //
1072     // Call high energy nuclei routine
1073     //
1074     if ( hZn && event->clevel2->trigty >= 2. ){
1075     if ( debug ) printf(" Calling selftrigger high energy nuclei routine for entry %i \n",itr);
1076     //
1077     // Disable "track mode" in the fortran routine
1078     //
1079     event->clevel1->good2 = 0;
1080     //
1081     // Set high energy nuclei flag to one
1082     //
1083     event->clevel1->hzn = 1;
1084     event->clevel1->riginput = rigdefault;
1085     //
1086     // We have a selftrigger event to analyze.
1087     //
1088     for (Int_t e = 0; e < 5 ; e++){
1089     event->clevel1->al_p[e][0] = 0.;
1090     event->clevel1->al_p[e][1] = 0.;
1091 mocchiut 1.1 };
1092 mocchiut 1.11 event->clevel1->trkchi2 = 0;
1093     //
1094     event->GetTrkVar();
1095     //
1096     // if we had no problem (clevel1->good2 = 0, NOTICE zero, not one in this mode!), fill and go on
1097     //
1098     if ( event->clevel1->good2 == 0 ) {
1099     //
1100     // In selftrigger mode the trkentry variable is set to -1
1101     //
1102     event->trkseqno = -2;
1103     //
1104     // Copy values in the class ca from the structure clevel2
1105 mocchiut 1.1 //
1106 mocchiut 1.11 event->FillTrkVar(ca,ntrkentry);
1107     ntrkentry++;
1108     filled = true;
1109 mocchiut 1.1 //
1110 mocchiut 1.11 } else {
1111     if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr);
1112     };
1113     //
1114     };
1115     //
1116     // self trigger event
1117     //
1118     if ( st && event->clevel2->trigty >= 2. ){
1119     if ( verbose ) printf(" Selftrigger event at entry %i \n",itr);
1120     //
1121     // Disable "track mode" in the fortran routine
1122     //
1123     event->clevel1->good2 = 0;
1124     //
1125     // disable high enery nuclei flag;
1126     //
1127     event->clevel1->hzn = 0;
1128     //
1129     // We have a selftrigger event to analyze.
1130     //
1131     for (Int_t e = 0; e < 5 ; e++){
1132     event->clevel1->al_p[e][0] = 0.;
1133     event->clevel1->al_p[e][1] = 0.;
1134     };
1135     event->clevel1->trkchi2 = 0;
1136     //
1137     event->GetTrkVar();
1138     //
1139     // if we had no problem (clevel2->good = 0, NOTICE zero, not one in selftrigger mode!), fill and go on
1140     //
1141     if ( event->clevel1->good2 == 0 ) {
1142 mocchiut 1.1 //
1143 mocchiut 1.11 // In selftrigger mode the trkentry variable is set to -1
1144 mocchiut 1.1 //
1145 mocchiut 1.11 event->trkseqno = -1;
1146 mocchiut 1.1 //
1147 mocchiut 1.11 // Copy values in the class ca from the structure clevel2
1148 mocchiut 1.1 //
1149 mocchiut 1.11 event->FillTrkVar(ca,ntrkentry);
1150     ntrkentry++;
1151     filled = true;
1152 mocchiut 1.1 //
1153 mocchiut 1.11 } else {
1154     if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr);
1155 mocchiut 1.1 };
1156     };
1157     //
1158     if ( !filled ) badevent++;
1159     //
1160     // Clear structures used to communicate with fortran
1161     //
1162     event->ClearStructs();
1163     //
1164     // Fill the rootple
1165     //
1166     calo->Fill();
1167     //
1168 mocchiut 1.6 // delete ca;
1169 mocchiut 1.1 //
1170     jumpev:
1171 mocchiut 1.23 if ( !debug ) debug = false;
1172 mocchiut 1.1 //
1173     };
1174     //
1175     if ( verbose ) printf("\n SUMMARY:\n");
1176     if ( verbose ) printf(" Total number of events: %i \n",totevent);
1177     if ( verbose ) printf(" Events with at least one track: %i \n",totevent-badevent);
1178     if ( verbose ) printf(" Events without tracks: %i \n",badevent);
1179     //
1180     if ( badevent == totevent ){
1181 mocchiut 1.8 if ( verbose ) printf("\n CALORIMETER - WARNING no tracks or good events in run %u \n",idRun);
1182 mocchiut 1.1 code = 101;
1183     };
1184     //
1185 mocchiut 1.8 delete dbtime;
1186 mocchiut 1.1 //
1187     // Clear variables before processing another run (needed to have always the same result when reprocessing data with the same software).
1188     //
1189     event->RunClose();
1190     if ( l0File ) l0File->Close();
1191     //
1192     }; // process all the runs
1193     //
1194     if ( verbose ) printf("\n Finished processing data \n");
1195     //
1196     closeandexit:
1197     //
1198     if ( !reprocall && reproc && code >= 0 ){
1199     if ( totfileentries > noaftrun ){
1200     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
1201 mocchiut 1.8 if ( verbose ) printf(" Copying %u events in the file which are after the end of the run %u \n",(totfileentries-noaftrun),run);
1202     if ( verbose ) printf(" Start copying at event number %u end copying at event number %u \n",noaftrun,totfileentries);
1203 mocchiut 1.1 for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1204     //
1205     // Get entry from old tree
1206     //
1207 mocchiut 1.48 if ( caloclone->GetEntry(j) <= 0 ) throw -36;
1208 mocchiut 1.1 //
1209     // copy caclone to ca
1210     //
1211 mocchiut 1.13 if ( getl1 ) c1->Clear();
1212 mocchiut 1.6 ca->Clear();
1213 mocchiut 1.8 //
1214 mocchiut 1.13 if ( getl1 ) memcpy(&c1,&c1clone,sizeof(c1clone));
1215 mocchiut 1.1 memcpy(&ca,&caclone,sizeof(caclone));
1216     //
1217     // Fill entry in the new tree
1218     //
1219     calo->Fill();
1220     //
1221     };
1222     if ( verbose ) printf(" Finished successful copying!\n");
1223     };
1224     };
1225     //
1226     // Case of no errors: close files, delete old tree(s), write and close level2 file
1227     //
1228     if ( l0File ) l0File->Close();
1229     if ( tempfile ) tempfile->Close();
1230 mocchiut 1.30 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1231 mocchiut 1.1 if ( tracker ) tracker->Delete();
1232     //
1233     if ( code < 0 ) printf("\n CALORIMETER - ERROR: an error occurred, try to save anyway...\n");
1234     if ( verbose ) printf("\n Writing and closing rootple\n");
1235     if ( runinfo ) runinfo->Close();
1236     if ( calo ) calo->SetName("Calorimeter");
1237     if ( file ){
1238     file->cd();
1239     file->Write();
1240     };
1241     if ( calo ) calo->Delete();
1242     //
1243 mocchiut 1.30 if ( myfold ) gSystem->Unlink(calofolder.str().c_str());
1244 mocchiut 1.1 //
1245 mocchiut 1.7 if ( ca ) delete ca;
1246     if ( caclone ) delete caclone;
1247 mocchiut 1.13 if ( c1 ) delete c1;
1248     if ( c1clone ) delete c1clone;
1249 mocchiut 1.7 if ( trk ) delete trk;
1250     if ( q4 ) delete q4;
1251     if ( glroot ) delete glroot;
1252     if ( runinfo ) delete runinfo;
1253     //
1254 mocchiut 1.1 // the end
1255     //
1256     if ( verbose ) printf("\n Exiting...\n");
1257     if ( code < 0 ) throw code;
1258     return(code);
1259     }
1260    
1261    
1262    

  ViewVC Help
Powered by ViewVC 1.1.23