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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.62 - (show annotations) (download)
Tue Oct 14 14:07:08 2014 UTC (10 years, 1 month ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, v10REDr01, HEAD
Changes since 1.61: +2 -1 lines
10RED: lost sync bug fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23