/[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.7 - (hide annotations) (download)
Fri Aug 4 10:31:26 2006 UTC (18 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.6: +7 -0 lines
Small memory leaks fixed

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.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.
11 mocchiut 1.2 //
12     // 3.03 - 3.04 (2006-05-23): Forgot to put impx and impy in the PAMELA reference system, fixed.
13 mocchiut 1.1 //
14     // 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.
15     //
16     // 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.
17     // Added variable planemax[2], plane of maximum energy release (x and y) in final output. Use ItoRunInfo instead of RunInfo.
18     //
19     // 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
20     // small bug in fortran routines
21     //
22     // 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
23     // working class "CaloProcessing", linked to the preliminary tracker flight software v0r00, reads YODA unique output files,
24     // reduced the number of installed libraries, F77 programs splitted depending on the function contained, introduced the readout and
25     // processing of self-trigger events, if the tracker provides more than one track all calorimeter track-related variables are saved
26     // as many times as the number of tracks (via the TClonesArray object in the level2 rootple) and many other small changes.
27     //
28     // 2.00 - 2.01 (2006-01-26): bug: wrong calculation of baselines in some cases, fixed.
29     //
30     // 1.00 - 2.00 (2006-01-11): use TSQL ROOT classes instead of directly calling MySQL.
31     //
32     // 0.00 - 1.00 (2005-09-14): seems working.
33     //
34     // 0.00 (2005-09-09): clone of CaloLEVEL2.c .
35     //
36     // C/C++ headers
37     //
38     #include <fstream>
39     #include <string.h>
40     //
41     // ROOT headers
42     //
43     #include <TTree.h>
44     #include <TClassEdit.h>
45     #include <TObject.h>
46     #include <TList.h>
47     #include <TArrayL.h>
48     #include <TSystem.h>
49     #include <TSystemDirectory.h>
50     #include <TString.h>
51     #include <TFile.h>
52     #include <TClass.h>
53     #include <TCanvas.h>
54     #include <TH1.h>
55     #include <TH1F.h>
56     #include <TH2D.h>
57     #include <TLatex.h>
58     #include <TPad.h>
59     #include <TSQLServer.h>
60     #include <TSQLRow.h>
61     #include <TSQLResult.h>
62     #include <TClonesArray.h>
63     #include <TStreamerInfo.h>
64     //
65     // YODA headers
66     //
67     #include <PamelaRun.h>
68     #include <RegistryEvent.h>
69     #include <physics/trigger/TriggerEvent.h>
70     //
71     // This program headers
72     //
73     #include <RunInfo.h>
74     #include <CaloCore.h>
75     #include <CaloLevel2.h>
76     #include <CaloProcessing.h>
77     #include <CaloVerl2.h>
78     //
79     // Tracker classes headers and definitions
80     //
81     #include <TrkLevel2.h>
82     //
83     using namespace std;
84     //
85     // CORE ROUTINE
86     //
87     int CaloCore(ULong64_t run, TFile *file, TSQLServer *dbc, Int_t calargc, char *calargv[]){
88     //
89     // Set these to true to have a very verbose output.
90     //
91     Bool_t verbose = false;
92     Bool_t debug = false;
93     //
94     // Output directory is the working directoy.
95     //
96     const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
97     //
98     Int_t ri = 0;
99     TString processFolder = "calorimeterFolder";
100     if ( calargc > 0 ){
101     ri = 0;
102     while ( ri < calargc ){
103     if ( !strcmp(calargv[ri],"-processFolder") ) {
104     if ( calargc < ri+1 ){
105     throw -3;
106     };
107     processFolder = (TString)calargv[ri+1];
108     ri++;
109     };
110     if ( !strcmp(calargv[ri],"-v") || !strcmp(calargv[ri],"--verbose") ) {
111     verbose = true;
112     };
113     if ( !strcmp(calargv[ri],"-g") || !strcmp(calargv[ri],"--debug") ) {
114     debug = true;
115     };
116     ri++;
117     };
118     };
119     //
120     // Working filename
121     //
122     TString outputfile;
123     stringstream name;
124     name.str("");
125     name << outdir << "/";
126     //
127     // Variables.
128     //
129     // TFile *file = 0;
130     TTree *tracker = 0;
131     TTree *calo = 0;
132     TTree *caloclone = 0;
133     Bool_t reproc = false;
134     Bool_t reprocall = false;
135     Long64_t nevents = 0LL;
136     UInt_t nobefrun = 0;
137     UInt_t noaftrun = 0;
138     UInt_t numbofrun = 0;
139     Long64_t totnorun = 0LL;
140     //
141     Int_t code = 0;
142     Int_t sgnl;
143     //
144     // calorimeter level2 classes
145     //
146     CaloLevel2 *ca = new CaloLevel2();
147     CaloLevel2 *caclone = new CaloLevel2();
148     //
149     TrkLevel2 *trk = new TrkLevel2();
150     Long64_t nevtrkl2 = 0;
151     //
152     UInt_t procev = 0;
153     //
154     // define variables where to store the absolute run header and run trailer times (unsigned long long integers, when set to a number use ULL to store the correct number).
155     //
156     ULong64_t runheadtime = 0ULL;
157     ULong64_t runtrailtime = 0ULL;
158     UInt_t evfrom = 0;
159     UInt_t evto = 0;
160     Long64_t totfileentries = 0LL;
161     Long64_t idRun = 0LL;
162     Int_t id_reg_run=-1;
163     stringstream ftmpname;
164     TString fname;
165     //
166     // define variables for opening and reading level0 file
167     //
168     TFile *l0File = 0;
169     TTree *l0tr = 0;
170     TBranch *l0head = 0;
171     TBranch *l0registry = 0;
172     TBranch *l0calo = 0;
173     TBranch *l0trig = 0;
174     pamela::RegistryEvent *l0reg=0;
175     pamela::trigger::TriggerEvent *trig = 0;
176     //
177     // Define some basic variables
178     //
179     CaloProcessing *event = new CaloProcessing(); // NOTICE: very important to call here the constructor!
180     stringstream file2;
181     stringstream file3;
182     stringstream qy;
183     // Bool_t imtrack = false;
184     Bool_t filled = false;
185     //
186     Long64_t caloevents = 0LL;
187     stringstream calfile;
188     stringstream aligfile;
189     //
190     Int_t i = -1;
191     Int_t itr = -1;
192     Int_t badevent = 0;
193     Int_t totevent = 0;
194     //
195     ULong64_t atime = 0ULL;
196     //
197     Int_t ei = 0;
198     Int_t S3 = 0;
199     Int_t S2 = 0;
200     Int_t S12 = 0;
201     Int_t S11 = 0;
202     UInt_t re = 0;
203     //
204     TString caloversion;
205     ItoRunInfo *runinfo = 0;
206     TArrayL *runlist = 0;
207     //
208     Float_t tmptrigty = -1.;
209     Int_t ntrkentry = 0;
210     GL_PARAM *q4 = new GL_PARAM();
211     ULong64_t tttrkpar1 = 0ULL;
212     Bool_t trkpar1 = true;
213     GL_ROOT *glroot = new GL_ROOT();
214     //
215     //
216     //
217     TFile *tempfile = 0;
218     TTree *tempcalo = 0;
219     stringstream tempname;
220     stringstream calofolder;
221     tempname.str("");
222     tempname << outdir;
223     tempname << "/" << processFolder.Data();
224     calofolder.str("");
225     calofolder << tempname.str().c_str();
226     gSystem->MakeDirectory(calofolder.str().c_str());
227     tempname << "/calotree_run";
228     tempname << run << ".root";
229     //
230     // 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
231     // if run != -1 we must process only that run but first we have to check if the branch calorimeter already exist in the file
232     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
233     //
234     if ( run == 0ULL ) reproc = true;
235     //
236     //
237     //
238     if ( !file->IsOpen() ){
239     if ( verbose ) printf(" CALORIMETER - ERROR: cannot open file for writing\n");
240     throw -101;
241     };
242     //
243     // Does it contain the Tracker tree?
244     //
245     tracker = (TTree*)file->Get("Tracker");
246     if ( !tracker ) {
247     if ( verbose ) printf(" CALORIMETER - ERROR: no tracker tree\n");
248     code = -102;
249     goto closeandexit;
250     };
251     tracker->SetBranchAddress("TrkLevel2",&trk);
252     nevtrkl2 = tracker->GetEntries();
253     //
254     // Call runinfo
255     //
256     sgnl = 0;
257     runinfo = new ItoRunInfo(file);
258     //
259     // update versioning information and retrieve informations about the run to be processed
260     //
261     caloversion = CaloInfo(false);
262     sgnl = runinfo->Update(run,"CALO",caloversion);
263     //
264     if ( sgnl ){
265     if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n");
266     code = sgnl;
267     goto closeandexit;
268     } else {
269     sgnl = 0;
270     };
271     //
272     // number of events in the file BEFORE the first event of our run
273     //
274     nobefrun = runinfo->GetFirstEntry();
275     //
276     // total number of events in the file
277     //
278     totfileentries = runinfo->GetFileEntries();
279     //
280     // first file entry AFTER the last event of our run
281     //
282     noaftrun = runinfo->GetLastEntry() + 1;
283     //
284     // number of run to be processed
285     //
286     numbofrun = runinfo->GetNoRun();
287     //
288     // number of runs in the file
289     //
290     totnorun = runinfo->GetRunEntries();
291     //
292     // Does it contain already a Calorimeter branch? if so we are reprocessing data, if not we must create it.
293     //
294     caloclone = (TTree*)file->Get("Calorimeter");
295     //
296     if ( !caloclone ){
297     reproc = false;
298     if ( run == 0ULL && verbose ) printf(" CALORIMETER - WARNING: you are reprocessing data but calorimeter tree does not exist!\n");
299     if ( runinfo->IsReprocessing() && run != 0ULL && verbose ) printf(" CALORIMETER - WARNING: it seems you are not reprocessing data but calorimeter\n versioning information already exists in RunInfo.\n");
300     //
301     } else {
302     //
303     reproc = true;
304     //
305     if ( verbose ) printf("\n Preparing the pre-processing...\n");
306     //
307     // if ( run == 0ULL || totnorun == numbofrun ){
308     if ( run == 0ULL ){
309     //
310     // 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.
311     //
312     if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing all runs in the file\n");
313     reprocall = true;
314     //
315     } else {
316     //
317     // we are reprocessing a single run
318     //
319     if ( verbose ) printf("\n CALORIMETER - WARNING: Reprocessing run number %llu \n",run);
320     reprocall = false;
321     //
322     //
323     //
324     tempfile = new TFile(tempname.str().c_str(),"RECREATE");
325     tempcalo = caloclone->CloneTree(-1,"fast");
326     tempcalo->SetName("Calorimeter-old");
327     tempfile->Write();
328     tempfile->Close();
329     };
330     //
331     // delete old tree
332     //
333     caloclone->Delete("all");
334     //
335     if ( verbose ) printf("\n ...done!\n");
336     //
337     };
338     //
339     // create calorimeter tree calo
340     //
341     file->cd();
342     calo = new TTree("Calorimeter-new","PAMELA Level2 calorimeter data");
343     calo->Branch("CaloLevel2","CaloLevel2",&ca);
344     //
345     if ( reproc && !reprocall ){
346     //
347     //
348     //
349     tempfile = new TFile(tempname.str().c_str(),"READ");
350     caloclone = (TTree*)tempfile->Get("Calorimeter-old");
351     caloclone->SetBranchAddress("CaloLevel2",&caclone);
352     //
353     if ( nobefrun > 0 ){
354     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
355     if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %llu \n",nobefrun,run);
356     if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
357     for (UInt_t j = 0; j < nobefrun; j++){
358     //
359     caloclone->GetEntry(j);
360     //
361     // copy caclone to ca
362     //
363     memcpy(&ca,&caclone,sizeof(caclone));
364     //
365     // Fill entry in the new tree
366     //
367     calo->Fill();
368     //
369 mocchiut 1.6 ca->Clear();
370     //
371 mocchiut 1.1 };
372     if ( verbose ) printf(" Finished successful copying!\n");
373     };
374     };
375     //
376     // Get the list of run to be processed
377     //
378     runlist = runinfo->GetRunList();
379     //
380     // Loop over the run to be processed
381     //
382     for (UInt_t irun=0; irun < numbofrun; irun++){
383     //
384     badevent = 0;
385     //
386     idRun = runlist->At(irun);
387     if ( verbose ) printf("\n\n\n ####################################################################### \n");
388     if ( verbose ) printf(" PROCESSING RUN NUMBER %llu \n",idRun);
389     if ( verbose ) printf(" ####################################################################### \n\n\n");
390     //
391     sgnl = runinfo->GetRunInfo(idRun);
392     if ( sgnl ){
393     if ( verbose ) printf(" CALORIMETER - ERROR: RunInfo exited with non-zero status\n");
394     code = sgnl;
395     goto closeandexit;
396     } else {
397     sgnl = 0;
398     };
399     id_reg_run = runinfo->ID_REG_RUN;
400     runheadtime = runinfo->RUNHEADER_TIME;
401     runtrailtime = runinfo->RUNTRAILER_TIME;
402     evfrom = runinfo->EV_REG_PHYS_FROM;
403     evto = runinfo->EV_REG_PHYS_TO;
404     //
405     if ( id_reg_run == -1 ){
406     if ( verbose ) printf("\n CALORIMETER - ERROR: no run with ID_RUN = %llu \n\n Exiting... \n\n",idRun);
407     code = -5;
408     goto closeandexit;
409     };
410     //
411     // Search in the DB the path and name of the LEVEL0 file to be processed.
412     //
413     glroot->Query_GL_ROOT(runinfo->ID_REG_RUN,dbc);
414     //
415     ftmpname.str("");
416     ftmpname << glroot->PATH.Data() << "/";
417     ftmpname << glroot->NAME.Data();
418     fname = ftmpname.str().c_str();
419     //
420     // print out informations
421     //
422     totevent = evto - evfrom + 1;
423     if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
424     if ( verbose ) printf(" RUN HEADER absolute time is: %llu \n",runheadtime);
425     if ( verbose ) printf(" RUN TRAILER absolute time is: %llu \n",runtrailtime);
426     if ( verbose ) printf(" %i events to be processed for run %llu: from %i to %i (reg entries)\n\n",totevent,idRun,evfrom,evto);
427     //
428     // Open Level0 file
429     //
430     l0File = new TFile(fname.Data());
431     if ( !l0File ) {
432     if ( verbose ) printf(" CALORIMETER - ERROR: problems opening Level0 file\n");
433     code = -6;
434     goto closeandexit;
435     };
436     l0tr = (TTree*)l0File->Get("Physics");
437     if ( !l0tr ) {
438     if ( verbose ) printf(" CALORIMETER - ERROR: no Physics tree in Level0 file\n");
439     l0File->Close();
440     code = -7;
441     goto closeandexit;
442     };
443     l0head = l0tr->GetBranch("Header");
444     if ( !l0head ) {
445     if ( verbose ) printf(" CALORIMETER - ERROR: no Header branch in Level0 tree\n");
446     l0File->Close();
447     code = -8;
448     goto closeandexit;
449     };
450     l0registry = l0tr->GetBranch("Registry");
451     if ( !l0registry ) {
452     if ( verbose ) printf(" CALORIMETER - ERROR: no Registry branch in Level0 tree\n");
453     l0File->Close();
454     code = -9;
455     goto closeandexit;
456     };
457     l0calo = l0tr->GetBranch("Calorimeter");
458     if ( !l0calo ) {
459     if ( verbose ) printf(" CALORIMETER - ERROR: no Calorimeter branch in Level0 tree\n");
460     l0File->Close();
461     code = -103;
462     goto closeandexit;
463     };
464     l0trig = l0tr->GetBranch("Trigger");
465     if ( !l0trig ) {
466     if ( verbose ) printf(" CALORIMETER - ERROR: no Trigger branch in Level0 tree\n");
467     l0File->Close();
468     code = -104;
469     goto closeandexit;
470     };
471     //
472     l0tr->SetBranchAddress("Trigger", &trig);
473     l0tr->SetBranchAddress("Registry", &l0reg);
474     //
475     // Construct the event object, look for the calibration which include the first header
476     //
477     sgnl = 0;
478     if ( verbose ) printf(" Check for calorimeter calibrations and initialize event object \n");
479     event->ProcessingInit(dbc,runheadtime,sgnl,l0tr,debug,verbose);
480     if ( verbose ) printf("\n");
481     if ( sgnl == 100 ) {
482     code = sgnl;
483     if ( verbose ) printf(" CALORIMETER - WARNING: run header not included in any calibration interval\n");
484     sgnl = 0;
485     };
486     if ( sgnl ){
487     l0File->Close();
488     code = sgnl;
489     goto closeandexit;
490     };
491     //
492     qy.str("");
493     //
494     nevents = l0registry->GetEntries();
495     caloevents = l0calo->GetEntries();
496     //
497     if ( nevents < 1 ) {
498     if ( verbose ) printf(" CALORIMETER - ERROR: Level0 file is empty\n\n");
499     l0File->Close();
500     code = -11;
501     goto closeandexit;
502     };
503     //
504     if ( evto > nevents-1 ) {
505     if ( verbose ) printf(" CALORIMETER - ERROR: too few entries in the registry tree\n");
506     l0File->Close();
507     code = -12;
508     goto closeandexit;
509     };
510     //
511     // Check if we have to load parameter files
512     //
513     sgnl = 0;
514     sgnl = event->ChkParam(dbc,runheadtime); // calorimeter parameter files
515     if ( sgnl < 0 ){
516     code = sgnl;
517     l0File->Close();
518     goto closeandexit;
519     };
520     //
521     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runheadtime ) ){
522     trkpar1 = false;
523 mocchiut 1.4 Int_t glpar = q4->Query_GL_PARAM(runinfo->RUNHEADER_TIME,"field",dbc);
524     if ( glpar < 0 ){
525     code = glpar;
526     goto closeandexit;
527     };
528 mocchiut 1.1 tttrkpar1 = q4->TO_TIME;
529     // ----------------------------
530     // Read the magnetic field
531     // ----------------------------
532     if ( verbose ) printf(" Reading magnetic field maps at %s\n",(q4->PATH+q4->NAME).Data());
533     trk->LoadField(q4->PATH+q4->NAME);
534     if ( verbose ) printf("\n");
535     };
536     //
537     // run over all the events of the run
538     //
539     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
540     //
541     for ( re = evfrom; re <= evto; re++){
542     //
543     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
544     //
545     l0registry->GetEntry(re);
546     //
547     // absolute time of this event
548     //
549     atime = l0reg->absTime;
550     //
551     // physics events is at entry number ei where
552     //
553     ei = l0reg->event;
554     //
555     //
556     //
557     if ( ei > caloevents-1 ){
558     if ( verbose ) printf(" CALORIMETER - ERROR: no physics events with entry = %i in Level0 file\n",i);
559     l0File->Close();
560     code = -112;
561     goto closeandexit;
562     };
563     //
564     if ( atime > runtrailtime || atime < runheadtime ) {
565     if ( verbose ) printf(" CALORIMETER - WARNING: event at time outside the run time window, skipping it\n");
566     goto jumpev;
567     };
568     //
569     // retrieve tracker informations
570     //
571     if ( !reprocall ){
572     itr = nobefrun + (re - evfrom);
573     } else {
574     itr = runinfo->GetFirstEntry() + (re - evfrom);
575     };
576     if ( itr > nevtrkl2 ){
577     if ( verbose ) printf(" CALORIMETER - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
578     l0File->Close();
579     code = -113;
580     goto closeandexit;
581     };
582     tracker->GetEntry(itr);
583     //
584     procev++;
585     //
586     // start processing
587     //
588 mocchiut 1.6 ca->Clear();
589     // ca = new CaloLevel2();
590 mocchiut 1.1 //
591     // determine who generate the trigger for this event (TOF, S4/PULSER, CALO)
592     //
593     l0trig->GetEntry(ei);
594     S3 = 0;
595     S2 = 0;
596     S12 = 0;
597     S11 = 0;
598     S3 = trig->patterntrig[2];
599     S2 = trig->patterntrig[3];
600     S12 = trig->patterntrig[4];
601     S11 = trig->patterntrig[5];
602     if ( trig->patterntrig[0] ) tmptrigty = 2.;
603     if ( S3 || S2 || S12 || S11 ) tmptrigty = 0.;
604     if ( trig->patterntrig[1] & (1<<0) || (!trig->patterntrig[0] && !S3 && !S2 && !S12 && !S11) ) tmptrigty = 1.;
605     event->clevel2->trigty = tmptrigty;
606     // event->clevel2->trigty = 2.;
607     //
608     // check if the calibration we are using is still good, if not load another calibration
609     //
610     sgnl = 0;
611     sgnl = event->ChkCalib(dbc,atime);
612     if ( sgnl < 0 ){
613     code = sgnl;
614     goto closeandexit;
615     };
616     if ( sgnl == 100 ){
617     code = sgnl;
618     if ( verbose ) printf(" CALORIMETER - WARNING: data not associated to any calibration interval\n");
619     badevent++;
620     sgnl = 0;
621     };
622     //
623     // do we have at least one track from the tracker?
624     //
625     event->clevel1->good2 = 1;
626 mocchiut 1.5 // if ( trk->GetNTracks() > 0 ) event->clevel1->good2 = 1;
627     if ( trk->ntrk() > 0 ) event->clevel1->good2 = 1;
628 mocchiut 1.1 //
629     // Calibrate calorimeter event "ei" and store output in the two structures that will be passed to fortran routine
630     //
631     event->Calibrate(ei);
632     //
633     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract topological variables.
634     //
635     //
636     // Calculate variables common to all tracks (qtot, nstrip, etc.)
637     //
638     event->GetCommonVar();
639     //
640     // Fill common variables
641     //
642     event->FillCommonVar(ca);
643     //
644     // Calculate variables related to tracks only if we have at least one track (from selftrigger and/or tracker)
645     //
646     ntrkentry = 0;
647     //
648     filled = false;
649     //
650     if ( event->clevel1->good2 == 1 || event->clevel2->trigty > 1. ){
651     //
652     if ( event->clevel1->good2 == 1 ){
653     //
654     // We have at least one track
655     //
656     //
657     // Run over tracks
658     //
659     for(Int_t nt=0; nt < trk->ntrk(); nt++){
660     //
661     event->clevel1->good2 = 1;
662     //
663     TrkTrack *ptt = trk->GetStoredTrack(nt);
664     //
665     event->clevel1->trkchi2 = 0;
666     //
667     // Copy the alpha vector in the input structure
668     //
669     for (Int_t e = 0; e < 5 ; e++){
670     event->clevel1->al_p[e][0] = ptt->al[e];
671     };
672     //
673     // Get tracker related variables for this track
674     //
675     event->GetTrkVar();
676     //
677     // Save tracker track sequence number
678     //
679    
680     event->trkseqno = nt;
681     //
682     // Copy values in the class ca from the structure clevel2
683     //
684     event->FillTrkVar(ca,ntrkentry);
685     ntrkentry++;
686     filled = true;
687     //
688     }; // loop on all the tracks
689     };
690     if ( event->clevel2->trigty >= 2. ){
691     if ( verbose ) printf(" Selftrigger event at entry %i \n",itr);
692     //
693     // Disable "track mode" in the fortran routine
694     //
695     event->clevel1->good2 = 0;
696     //
697     // We have a selftrigger event to analyze.
698     //
699     for (Int_t e = 0; e < 5 ; e++){
700     event->clevel1->al_p[e][0] = 0.;
701     event->clevel1->al_p[e][1] = 0.;
702     };
703     event->clevel1->trkchi2 = 0;
704     //
705     event->GetTrkVar();
706     //
707     // if we had no problem (clevel2->good = 0, NOTICE zero, not one in selftrigger mode!), fill and go on
708     //
709     if ( event->clevel1->good2 == 0 ) {
710     //
711     // In selftrigger mode the trkentry variable is set to -1
712     //
713     event->trkseqno = -1;
714     //
715     // Copy values in the class ca from the structure clevel2
716     //
717     event->FillTrkVar(ca,ntrkentry);
718     ntrkentry++;
719     filled = true;
720     //
721     } else {
722     if ( verbose ) printf(" Selftrigger: problems with event at entry %i \n",itr);
723     };
724     };
725     };
726     //
727     if ( !filled ) badevent++;
728     //
729     // Clear structures used to communicate with fortran
730     //
731     event->ClearStructs();
732     //
733     // Fill the rootple
734     //
735     calo->Fill();
736     //
737 mocchiut 1.6 // delete ca;
738 mocchiut 1.1 //
739     jumpev:
740     debug = false;
741     //
742     };
743     //
744     if ( verbose ) printf("\n SUMMARY:\n");
745     if ( verbose ) printf(" Total number of events: %i \n",totevent);
746     if ( verbose ) printf(" Events with at least one track: %i \n",totevent-badevent);
747     if ( verbose ) printf(" Events without tracks: %i \n",badevent);
748     //
749     if ( badevent == totevent ){
750     if ( verbose ) printf("\n CALORIMETER - WARNING no tracks or good events in run %llu \n",idRun);
751     code = 101;
752     };
753     //
754     ei = 0;
755     //
756     // Clear variables before processing another run (needed to have always the same result when reprocessing data with the same software).
757     //
758     event->RunClose();
759     if ( l0File ) l0File->Close();
760     //
761     }; // process all the runs
762     //
763     if ( verbose ) printf("\n Finished processing data \n");
764     //
765     closeandexit:
766     //
767     if ( !reprocall && reproc && code >= 0 ){
768     if ( totfileentries > noaftrun ){
769     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
770     if ( verbose ) printf(" Copying %lli events in the file which are after the end of the run %llu \n",(totfileentries-noaftrun),run);
771     if ( verbose ) printf(" Start copying at event number %u end copying at event number %lli \n",noaftrun,totfileentries);
772     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
773     //
774     // Get entry from old tree
775     //
776     caloclone->GetEntry(j);
777     //
778     // copy caclone to ca
779     //
780 mocchiut 1.6 ca->Clear();
781     // ca = new CaloLevel2();
782 mocchiut 1.1 memcpy(&ca,&caclone,sizeof(caclone));
783     //
784     // Fill entry in the new tree
785     //
786     calo->Fill();
787     //
788     };
789     if ( verbose ) printf(" Finished successful copying!\n");
790     };
791     };
792     //
793     // Case of no errors: close files, delete old tree(s), write and close level2 file
794     //
795     if ( l0File ) l0File->Close();
796     if ( tempfile ) tempfile->Close();
797     gSystem->Unlink(tempname.str().c_str());
798     if ( tracker ) tracker->Delete();
799     //
800     if ( code < 0 ) printf("\n CALORIMETER - ERROR: an error occurred, try to save anyway...\n");
801     if ( verbose ) printf("\n Writing and closing rootple\n");
802     if ( runinfo ) runinfo->Close();
803     if ( calo ) calo->SetName("Calorimeter");
804     if ( file ){
805     file->cd();
806     file->Write();
807     };
808     if ( calo ) calo->Delete();
809     //
810     gSystem->Unlink(calofolder.str().c_str());
811     //
812 mocchiut 1.7 if ( ca ) delete ca;
813     if ( caclone ) delete caclone;
814     if ( trk ) delete trk;
815     if ( q4 ) delete q4;
816     if ( glroot ) delete glroot;
817     if ( runinfo ) delete runinfo;
818     //
819 mocchiut 1.1 // the end
820     //
821     if ( verbose ) printf("\n Exiting...\n");
822     if ( code < 0 ) throw code;
823     return(code);
824     }
825    
826    
827    

  ViewVC Help
Powered by ViewVC 1.1.23