/[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.1.1.1 - (hide annotations) (download) (vendor branch)
Fri May 19 13:15:49 2006 UTC (18 years, 6 months ago) by mocchiut
Branch: DarthVader
CVS Tags: v0r01, start
Changes since 1.1: +0 -0 lines
Imported sources

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

  ViewVC Help
Powered by ViewVC 1.1.23