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

  ViewVC Help
Powered by ViewVC 1.1.23