/[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.6 - (hide annotations) (download)
Wed Sep 6 08:05:11 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.5: +53 -68 lines
small update, still not compiling

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

  ViewVC Help
Powered by ViewVC 1.1.23