/[PAMELA software]/DarthVader/ToFLevel2/src/ToFCore.cpp
ViewVC logotype

Annotation of /DarthVader/ToFLevel2/src/ToFCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Tue Jan 23 15:36:48 2007 UTC (17 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v3r00
Changes since 1.15: +4 -4 lines
Compiling bug under fedora4 fixed, Syntax error inc/TrkLevelX bug fixed

1 mocchiut 1.1 //
2     // C/C++ headers
3     //
4     #include <fstream>
5     #include <string.h>
6     //
7     // ROOT headers
8     //
9     #include <TTree.h>
10     #include <TClassEdit.h>
11     #include <TObject.h>
12     #include <TList.h>
13 mocchiut 1.6 #include <TArrayI.h>
14 mocchiut 1.1 #include <TSystem.h>
15     #include <TSystemDirectory.h>
16     #include <TString.h>
17     #include <TFile.h>
18     #include <TClass.h>
19     #include <TCanvas.h>
20     #include <TH1.h>
21     #include <TH1F.h>
22     #include <TH2D.h>
23     #include <TLatex.h>
24     #include <TPad.h>
25     #include <TSQLServer.h>
26     #include <TSQLRow.h>
27     #include <TSQLResult.h>
28     #include <TClonesArray.h>
29     //
30 mocchiut 1.16 // RunInfo header
31     //
32     #include <RunInfo.h>
33     //
34 mocchiut 1.1 // YODA headers
35     //
36     #include <PamelaRun.h>
37     #include <physics/trigger/TriggerEvent.h>
38     #include <physics/tof/TofEvent.h>
39     //
40     // This program headers
41     //
42     #include <ToFCore.h>
43     #include <ToFLevel2.h>
44     #include <ToFVerl2.h>
45     //
46     //
47     // Declaration of the core fortran routines
48     //
49     #define tofl2com tofl2com_
50     extern "C" int tofl2com();
51     #define toftrk toftrk_
52     extern "C" int toftrk();
53     #define rdtofcal rdtofcal_
54 mocchiut 1.9 extern "C" int rdtofcal(char [], int *);
55 mocchiut 1.1
56     //
57     // Tracker classes headers and definitions
58     //
59     #include <TrkLevel2.h>
60     //
61     using namespace std;
62     //
63     //
64     // CORE ROUTINE
65     //
66     //
67 mocchiut 1.6 int ToFCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t ToFargc, char *ToFargv[]){
68 mocchiut 1.1 //
69     //
70     // Set these to true to have a very verbose output.
71     //
72     Bool_t verbose = false;
73     Bool_t debug = false;
74     //
75     TString processFolder = "ToFFolder";
76     if ( ToFargc > 0 ){
77     Int_t i = 0;
78     while ( i < ToFargc ){
79     if ( !strcmp(ToFargv[i],"-processFolder") ) {
80     if ( ToFargc < i+1 ){
81     throw -3;
82     };
83     processFolder = (TString)ToFargv[i+1];
84     i++;
85     };
86     if ( !strcmp(ToFargv[i],"-v") || !strcmp(ToFargv[i],"--verbose") ) {
87     verbose = true;
88     };
89     if ( !strcmp(ToFargv[i],"-g") || !strcmp(ToFargv[i],"--debug") ) {
90     debug = true;
91     };
92     i++;
93     };
94     };
95     //
96     //
97     // Output directory is the working directoy.
98     //
99     const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
100     //
101     // Variables for level2
102     //
103     TTree *tracker = 0;
104     TTree *toft = 0;
105 mocchiut 1.6 UInt_t nevents = 0;
106 mocchiut 1.15 Long64_t maxsize = 10000000000LL;
107     TTree::SetMaxTreeSize(maxsize);
108 mocchiut 1.1 //
109     // variables needed to reprocess data
110     //
111     TString tofversion;
112     ItoRunInfo *runinfo = 0;
113 mocchiut 1.6 TArrayI *runlist = 0;
114 mocchiut 1.1 TTree *toftclone = 0;
115     Bool_t reproc = false;
116     Bool_t reprocall = false;
117     UInt_t nobefrun = 0;
118     UInt_t noaftrun = 0;
119     UInt_t numbofrun = 0;
120     stringstream ftmpname;
121     TString fname;
122 mocchiut 1.6 UInt_t totfileentries = 0;
123     UInt_t idRun = 0;
124 mocchiut 1.1 //
125     // variables needed to handle error signals
126     //
127     Int_t code = 0;
128     Int_t sgnl;
129     //
130     // tof level2 classes
131     //
132     ToFLevel2 *tof = new ToFLevel2();
133     ToFLevel2 *tofclone = new ToFLevel2();
134     //
135     // tracker level2 variables
136     //
137     TrkLevel2 *trk = new TrkLevel2();
138 mocchiut 1.6 Int_t nevtrkl2 = 0;
139 mocchiut 1.1 //
140     // define variables for opening and reading level0 file
141     //
142     TFile *l0File = 0;
143     TTree *l0tr = 0;
144     TBranch *l0head = 0;
145     TBranch *l0trig = 0;
146     TBranch *l0tof = 0;
147 mocchiut 1.6 pamela::EventHeader *eh = 0;
148     pamela::PscuHeader *ph = 0;
149 mocchiut 1.1 pamela::trigger::TriggerEvent *trig = 0;
150     pamela::tof::TofEvent *tofEvent = 0;
151     //
152     // Define other basic variables
153     //
154     UInt_t procev = 0;
155     stringstream file2;
156     stringstream file3;
157     stringstream qy;
158     Int_t itr = -1;
159     Int_t totevent = 0;
160 mocchiut 1.6 UInt_t atime = 0;
161     UInt_t re = 0;
162 mocchiut 1.7 UInt_t jumped = 0;
163 mocchiut 1.1 //
164     // Working filename
165     //
166     TString outputfile;
167     stringstream name;
168     name.str("");
169     name << outdir << "/";
170     //
171     // temporary file and folder
172     //
173     TFile *tempfile = 0;
174     TTree *temptof = 0;
175     stringstream tempname;
176     stringstream toffolder;
177     tempname.str("");
178     tempname << outdir;
179     tempname << "/" << processFolder.Data();
180     toffolder.str("");
181     toffolder << tempname.str().c_str();
182     gSystem->MakeDirectory(toffolder.str().c_str());
183     tempname << "/toftree_run";
184     tempname << run << ".root";
185     //
186     // variables needed to load magnetic field maps
187     //
188     Int_t ntrkentry = 0;
189 mocchiut 1.4 Int_t npmtentry = 0;
190 mocchiut 1.6 UInt_t tttrkpar1 = 0;
191 mocchiut 1.1 Bool_t trkpar1 = true;
192 mocchiut 1.6 UInt_t tttofpar1 = 0;
193 mocchiut 1.1 Bool_t tofpar1 = true;
194     //
195     // DB classes
196     //
197     GL_ROOT *glroot = new GL_ROOT();
198     GL_PARAM *glparam = new GL_PARAM();
199 mocchiut 1.6 GL_TIMESYNC *dbtime = 0;
200 mocchiut 1.1 //
201     // declaring external output and input structures
202     //
203     extern struct ToFInput tofinput_;
204     extern struct ToFOutput tofoutput_;
205     //
206     // Let's start!
207     //
208     //
209     // As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed
210     // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file
211     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
212     //
213 mocchiut 1.6 if ( run == 0 ) reproc = true;
214 mocchiut 1.1 //
215     //
216     // Output file is "outputfile"
217     //
218     if ( !file->IsOpen() ){
219     if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n");
220     throw -301;
221     };
222     //
223     // Does it contain the Tracker tree?
224     //
225     tracker = (TTree*)file->Get("Tracker");
226     if ( !tracker ) {
227     if ( verbose ) printf(" TOF - ERROR: no tracker tree\n");
228     code = -302;
229     goto closeandexit;
230     };
231     //
232     // get tracker level2 data pointer
233     //
234     tracker->SetBranchAddress("TrkLevel2",&trk);
235     nevtrkl2 = tracker->GetEntries();
236     //
237     // Retrieve GL_RUN variables from the level2 file
238     //
239     tofversion = ToFInfo(false); // we should decide how to handle versioning system
240     //
241     // create an interface to RunInfo called "runinfo"
242     //
243     // ItoRunInfo= interface with RunInfo and GL_RUN
244     runinfo = new ItoRunInfo(file);
245     //
246     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
247     //
248     sgnl = 0;
249     sgnl = runinfo->Update(run, "TOF",tofversion);
250     if ( sgnl ){
251     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
252     code = sgnl;
253     goto closeandexit;
254     } else {
255     sgnl = 0;
256     };
257     //
258     // number of events in the file BEFORE the first event of our run
259     //
260     nobefrun = runinfo->GetFirstEntry();
261     //
262     // total number of events in the file
263     //
264     totfileentries = runinfo->GetFileEntries();
265     //
266     // first file entry AFTER the last event of our run
267     //
268     noaftrun = runinfo->GetLastEntry() + 1;
269     //
270     // number of run to be processed
271     //
272     numbofrun = runinfo->GetNoRun();
273     //
274     // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run
275     //
276     toftclone = (TTree*)file->Get("ToF");
277     //
278     if ( !toftclone ){
279     //
280     // tree does not exist, we are not reprocessing
281     //
282     reproc = false;
283 mocchiut 1.6 if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n");
284     if ( runinfo->IsReprocessing() && run != 0 && verbose ) printf(" ToF - WARNING: it seems you are not reprocessing data but ToF\n versioning information already exists in RunInfo.\n");
285 mocchiut 1.1
286     } else {
287     //
288     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
289     //
290 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
291 mocchiut 1.1 reproc = true;
292     //
293     // update versioning information
294     //
295     if ( verbose ) printf("\n Preparing the pre-processing...\n");
296     //
297 mocchiut 1.6 if ( run == 0 ){
298 mocchiut 1.1 //
299     // we are reprocessing all the file
300     // if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately
301     //
302     reprocall = true;
303     //
304     if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n");
305     //
306     } else {
307     //
308     // we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run
309     //
310     reprocall = false;
311     //
312 mocchiut 1.6 if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run);
313 mocchiut 1.1 //
314     // copying old tree to a new file
315     //
316     tempfile = new TFile(tempname.str().c_str(),"RECREATE");
317     temptof = toftclone->CloneTree(-1,"fast");
318     temptof->SetName("ToF-old");
319     tempfile->Write();
320     tempfile->Close();
321     }
322     //
323     // Delete the old tree from old file and memory
324     //
325     toftclone->Delete("all");
326     //
327     if ( verbose ) printf(" ...done!\n");
328     //
329     };
330     //
331     // create ToF detector tree toft
332     //
333     file->cd();
334     toft = new TTree("ToF-new","PAMELA Level2 ToF data");
335 mocchiut 1.15 toft->SetAutoSave(900000000000000LL);
336     tof->Set();//ELENA **TEMPORANEO?**
337 mocchiut 1.1 toft->Branch("ToFLevel2","ToFLevel2",&tof);
338     //
339     if ( reproc && !reprocall ){
340     //
341     // open new file and retrieve all tree informations
342     //
343     tempfile = new TFile(tempname.str().c_str(),"READ");
344     toftclone = (TTree*)tempfile->Get("ToF-old");
345 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
346 mocchiut 1.1 toftclone->SetBranchAddress("ToFLevel2",&tofclone);
347     //
348     if ( nobefrun > 0 ){
349     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
350 mocchiut 1.6 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
351 mocchiut 1.1 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
352     for (UInt_t j = 0; j < nobefrun; j++){
353     //
354     toftclone->GetEntry(j);
355     //
356     // copy tofclone to tof
357     //
358 mocchiut 1.3 tof->Clear();
359 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
360     //
361     // Fill entry in the new tree
362     //
363     toft->Fill();
364     //
365     };
366     if ( verbose ) printf(" Finished successful copying!\n");
367     };
368     };
369     //
370     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
371     //
372     runlist = runinfo->GetRunList();
373     //
374     // Loop over the run to be processed
375     //
376     for (UInt_t irun=0; irun < numbofrun; irun++){
377     //
378     // retrieve the first run ID to be processed using the RunInfo list
379     //
380     idRun = runlist->At(irun);
381     if ( verbose ) printf("\n\n\n ####################################################################### \n");
382 mocchiut 1.6 if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun);
383 mocchiut 1.1 if ( verbose ) printf(" ####################################################################### \n\n\n");
384     //
385 mocchiut 1.6 runinfo->ID_ROOT_L0 = 0;
386 mocchiut 1.1 //
387     // store in the runinfo class the GL_RUN variables for our run
388     //
389     sgnl = 0;
390     sgnl = runinfo->GetRunInfo(idRun);
391     if ( sgnl ){
392     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
393     code = sgnl;
394     goto closeandexit;
395     } else {
396     sgnl = 0;
397     };
398     //
399 mocchiut 1.6 // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
400 mocchiut 1.1 //
401 mocchiut 1.6 if ( runinfo->ID_ROOT_L0 == 0 ){
402     if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
403 mocchiut 1.1 code = -5;
404     goto closeandexit;
405     };
406     //
407 mocchiut 1.6 // prepare the timesync for the db
408     //
409 mocchiut 1.10 if ( !dbc->IsConnected() ) throw -314;
410 mocchiut 1.6 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
411     //
412 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
413     //
414 mocchiut 1.10 if ( !dbc->IsConnected() ) throw -314;
415 mocchiut 1.6 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
416 mocchiut 1.1 //
417     ftmpname.str("");
418     ftmpname << glroot->PATH.Data() << "/";
419     ftmpname << glroot->NAME.Data();
420     fname = ftmpname.str().c_str();
421     //
422     // print out informations
423     //
424 mocchiut 1.6 totevent = runinfo->NEVENTS;
425 mocchiut 1.1 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
426 mocchiut 1.6 if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
427     if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
428     if ( verbose ) printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent);
429 mocchiut 1.1 //
430     // Open Level0 file
431     //
432     l0File = new TFile(fname.Data());
433     if ( !l0File ) {
434     if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n");
435     code = -6;
436     goto closeandexit;
437     };
438     l0tr = (TTree*)l0File->Get("Physics");
439     if ( !l0tr ) {
440     if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n");
441     l0File->Close();
442     code = -7;
443     goto closeandexit;
444     };
445     l0head = l0tr->GetBranch("Header");
446     if ( !l0head ) {
447     if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n");
448     l0File->Close();
449     code = -8;
450     goto closeandexit;
451     };
452     l0trig = l0tr->GetBranch("Trigger");
453     if ( !l0trig ) {
454     if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n");
455     l0File->Close();
456     code = -300;
457     goto closeandexit;
458     };
459     l0tof = l0tr->GetBranch("Tof");
460     if ( !l0tof ) {
461     if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n");
462     l0File->Close();
463     code = -303;
464     goto closeandexit;
465     };
466     //
467     l0tr->SetBranchAddress("Trigger", &trig);
468     l0tr->SetBranchAddress("Tof", &tofEvent);
469 mocchiut 1.6 l0tr->SetBranchAddress("Header", &eh);
470 mocchiut 1.1 //
471 mocchiut 1.6 nevents = l0tof->GetEntries();
472 mocchiut 1.1 //
473     if ( nevents < 1 ) {
474     if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n");
475     l0File->Close();
476     code = -11;
477     goto closeandexit;
478     };
479     //
480 mocchiut 1.6 if ( runinfo->EV_TO > nevents-1 ) {
481 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n");
482     l0File->Close();
483     code = -12;
484     goto closeandexit;
485     };
486     //
487     // Check if we have to load parameter files (or calibration associated to runs and not to events)
488     //
489     // for example let's assume that we could have different magnetic field maps for different runs:
490     //
491     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){
492     trkpar1 = false;
493     // read from DB infos about Magnetic filed maps
494 mocchiut 1.10 if ( !dbc->IsConnected() ) throw -314;
495 mocchiut 1.6 glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table
496 mocchiut 1.1 tttrkpar1 = glparam->TO_TIME;
497     // ----------------------------
498     // Read the magnetic field
499     // ----------------------------
500     if ( verbose ) printf(" Reading magnetic field maps: \n");
501     trk->LoadField(glparam->PATH+glparam->NAME);
502     if ( verbose ) printf("\n");
503     };
504 mocchiut 1.6 //
505 mocchiut 1.1 if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
506     tofpar1 = false;
507     //
508 mocchiut 1.10 if ( !dbc->IsConnected() ) throw -314;
509 mocchiut 1.6 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
510 mocchiut 1.1 if ( error<0 ) {
511     code = error;
512     goto closeandexit;
513     };
514     //
515 mocchiut 1.9 if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
516     //
517 mocchiut 1.1 tttofpar1 = glparam->TO_TIME;
518 mocchiut 1.9 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
519     rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
520 mocchiut 1.1 };
521     //
522     // run over all the events of the run
523     //
524     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
525     //
526 mocchiut 1.7 jumped = 0;
527 mocchiut 1.6 //
528     for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
529 mocchiut 1.1 //
530     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
531     //
532 mocchiut 1.6 l0head->GetEntry(re);
533 mocchiut 1.1 //
534     // absolute time of this event
535     //
536 mocchiut 1.6 ph = eh->GetPscuHeader();
537     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
538 mocchiut 1.4 //
539     tof->Clear();
540     Int_t pmt_id = 0;
541     ToFPMT *t_pmt = new ToFPMT();
542 mocchiut 1.15 if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA
543 mocchiut 1.4 TClonesArray &tpmt = *tof->PMT;
544     ToFTrkVar *t_tof = new ToFTrkVar();
545 mocchiut 1.15 if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
546 mocchiut 1.4 TClonesArray &t = *tof->ToFTrk;
547     //
548 mocchiut 1.1 // paranoid check
549     //
550     if ( atime > runinfo->RUNTRAILER_TIME || atime < runinfo->RUNHEADER_TIME ) {
551     if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n");
552 mocchiut 1.7 jumped++;
553 mocchiut 1.1 goto jumpev;
554     };
555     //
556     // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr"
557     //
558     if ( !reprocall ){
559 mocchiut 1.7 itr = nobefrun + (re - runinfo->EV_FROM -jumped);
560 mocchiut 1.1 } else {
561 mocchiut 1.7 itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped);
562 mocchiut 1.1 };
563     if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number
564     if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
565     l0File->Close();
566     code = -313;
567     goto closeandexit;
568     };
569 mocchiut 1.8 //
570     trk->Clear();
571     //
572 mocchiut 1.1 tracker->GetEntry(itr);
573     ///
574 mocchiut 1.2 //
575 mocchiut 1.6 l0tof->GetEntry(re);
576     l0trig->GetEntry(re);
577 mocchiut 1.1 ///
578     //
579     procev++;
580     //
581     // start processing
582     //
583     //
584     // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
585    
586     for (Int_t gg=0; gg<4;gg++){
587     for (Int_t hh=0; hh<12;hh++){
588     tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
589     tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh];
590     };
591     };
592    
593     for (Int_t hh=0; hh<5;hh++){
594     tofinput_.patterntrig[hh]=trig->patterntrig[hh];
595     };
596     //
597     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
598     //
599 mocchiut 1.4 npmtentry = 0;
600     //
601     ntrkentry = 0;
602 mocchiut 1.1 //
603     // Calculate tracks informations from ToF alone
604     //
605     tofl2com();
606     //
607 mocchiut 1.4 memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
608     //
609     t_tof->trkseqno = -1;
610     //
611 mocchiut 1.1 // and now we must copy from the output structure to the level2 class:
612     //
613 mocchiut 1.4 t_tof->npmttdc = 0;
614     //
615 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
616     for (Int_t kk=0; kk<4;kk++){
617 mocchiut 1.4 if ( tofoutput_.tofmask[hh][kk] != 0 ){
618     pmt_id = tof->GetPMTid(kk,hh);
619     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
620 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
621 mocchiut 1.4 t_tof->npmttdc++;
622     };
623     };
624     };
625     for (Int_t kk=0; kk<13;kk++){
626     t_tof->beta[kk] = tofoutput_.betatof_a[kk];
627 mocchiut 1.1 }
628 mocchiut 1.4 //
629     t_tof->npmtadc = 0;
630 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
631     for (Int_t kk=0; kk<4;kk++){
632 mocchiut 1.4 if ( tofoutput_.adctof_c[hh][kk] < 1000 ){
633     t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc);
634     pmt_id = tof->GetPMTid(kk,hh);
635     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
636 mocchiut 1.14 t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
637 mocchiut 1.4 t_tof->npmtadc++;
638     };
639     };
640     };
641     //
642     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
643     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
644     //
645     new(t[ntrkentry]) ToFTrkVar(*t_tof);
646     ntrkentry++;
647     t_tof->Clear();
648     //
649 mocchiut 1.1 //
650     //
651 mocchiut 1.4 t_pmt->Clear();
652 mocchiut 1.1 //
653 mocchiut 1.4 for (Int_t hh=0; hh<12;hh++){
654     for (Int_t kk=0; kk<4;kk++){
655     if ( tofoutput_.tdc_c[hh][kk] < 4095 || tofEvent->adc[kk][hh] < 4095 ){
656     //
657     t_pmt->pmt_id = tof->GetPMTid(kk,hh);
658     t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
659     t_pmt->adc = tofEvent->adc[kk][hh];
660     //
661     new(tpmt[npmtentry]) ToFPMT(*t_pmt);
662     npmtentry++;
663     t_pmt->Clear();
664     };
665     };
666     };
667 mocchiut 1.1 //
668 mocchiut 1.4 // Calculate track-related variables
669 mocchiut 1.1 //
670 mocchiut 1.2 if ( trk->ntrk() > 0 ){
671 mocchiut 1.1 //
672     // We have at least one track
673     //
674     //
675     // Run over tracks
676     //
677     for(Int_t nt=0; nt < trk->ntrk(); nt++){
678     //
679     TrkTrack *ptt = trk->GetStoredTrack(nt);
680     //
681     // Copy the alpha vector in the input structure
682     //
683     for (Int_t e = 0; e < 5 ; e++){
684     tofinput_.al_pp[e] = ptt->al[e];
685     };
686     //
687     // Get tracker related variables for this track
688     //
689     toftrk();
690     //
691     // Copy values in the class from the structure (we need to use a temporary class to store variables).
692     //
693 mocchiut 1.4 t_tof->npmttdc = 0;
694     for (Int_t hh=0; hh<12;hh++){
695     for (Int_t kk=0; kk<4;kk++){
696     if ( tofoutput_.tofmask[hh][kk] != 0 ){
697     pmt_id = tof->GetPMTid(kk,hh);
698     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
699 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
700 mocchiut 1.4 t_tof->npmttdc++;
701     };
702     };
703     };
704 mocchiut 1.1 for (Int_t kk=0; kk<13;kk++){
705 mocchiut 1.4 t_tof->beta[kk] = tofoutput_.beta_a[kk];
706     };
707     //
708     t_tof->npmtadc = 0;
709 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
710     for (Int_t kk=0; kk<4;kk++){
711 mocchiut 1.4 if ( tofoutput_.adc_c[hh][kk] < 1000 ){
712     t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc);
713     pmt_id = tof->GetPMTid(kk,hh);
714     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
715 mocchiut 1.14 t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07
716 mocchiut 1.4 t_tof->npmtadc++;
717     };
718     };
719     };
720     //
721     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
722     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
723 mocchiut 1.1 //
724     // Store the tracker track number in order to be sure to have shyncronized data during analysis
725     //
726     t_tof->trkseqno = nt;
727     //
728     // create a new object for this event with track-related variables
729     //
730     new(t[ntrkentry]) ToFTrkVar(*t_tof);
731     ntrkentry++;
732 mocchiut 1.4 t_tof->Clear();
733 mocchiut 1.1 //
734     }; // loop on all the tracks
735     };
736     //
737 mocchiut 1.9 tof->unpackError = tofEvent->unpackError;
738     //
739 mocchiut 1.1 // Fill the rootple
740     //
741     toft->Fill();
742     //
743     //
744 mocchiut 1.4 //
745     delete t_tof;
746     //
747     //
748     //
749 mocchiut 1.1 jumpev:
750     debug = false;
751     //
752     };
753 mocchiut 1.6 //
754     // Here you may want to clear some variables before processing another run
755     //
756     delete dbtime;
757 mocchiut 1.1 }; // process all the runs
758     //
759     if ( verbose ) printf("\n Finished processing data \n");
760     //
761     closeandexit:
762     //
763     // we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree.
764     //
765     if ( !reprocall && reproc && code >= 0 ){
766     if ( totfileentries > noaftrun ){
767     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
768     if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
769     if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
770     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
771     //
772     // Get entry from old tree
773     //
774     toftclone->GetEntry(j);
775     //
776     // copy tofclone to tof
777     //
778 mocchiut 1.3 tof->Clear();
779 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
780     //
781     // Fill entry in the new tree
782     //
783     toft->Fill();
784     };
785     if ( verbose ) printf(" Finished successful copying!\n");
786     };
787     };
788     //
789     // Close files, delete old tree(s), write and close level2 file
790     //
791     if ( l0File ) l0File->Close();
792     if ( tempfile ) tempfile->Close();
793     gSystem->Unlink(tempname.str().c_str());
794     if ( tracker ) tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file!
795     //
796     if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
797     if ( verbose ) printf("\n Writing and closing rootple\n");
798     if ( runinfo ) runinfo->Close();
799     if ( toft ) toft->SetName("ToF");
800     if ( file ){
801     file->cd();
802     file->Write("ToF");
803     };
804     //
805     gSystem->Unlink(toffolder.str().c_str());
806     //
807     // the end
808     //
809     if ( verbose ) printf("\n Exiting...\n");
810     if(toft)toft->Delete();
811 mocchiut 1.5 //
812     if ( tof ) delete tof;
813     if ( tofclone ) delete tofclone;
814     if ( glroot ) delete glroot;
815     if ( runinfo ) delete runinfo;
816     //
817 mocchiut 1.1 if ( code < 0 ) throw code;
818     return(code);
819     }

  ViewVC Help
Powered by ViewVC 1.1.23