/[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.43 - (hide annotations) (download)
Fri Jan 29 17:13:35 2010 UTC (14 years, 10 months ago) by mocchiut
Branch: MAIN
Changes since 1.42: +5 -5 lines
ToF dE/dx II order correction changed back to He

1 mocchiut 1.1 //
2     // C/C++ headers
3     //
4     #include <fstream>
5     #include <string.h>
6 mocchiut 1.32 #include <iomanip>
7 mocchiut 1.1 //
8     // ROOT headers
9     //
10     #include <TTree.h>
11     #include <TClassEdit.h>
12     #include <TObject.h>
13     #include <TList.h>
14 mocchiut 1.6 #include <TArrayI.h>
15 mocchiut 1.1 #include <TSystem.h>
16     #include <TSystemDirectory.h>
17     #include <TString.h>
18     #include <TFile.h>
19     #include <TClass.h>
20     #include <TCanvas.h>
21     #include <TH1.h>
22     #include <TH1F.h>
23     #include <TH2D.h>
24     #include <TLatex.h>
25     #include <TPad.h>
26     #include <TSQLServer.h>
27     #include <TSQLRow.h>
28     #include <TSQLResult.h>
29     #include <TClonesArray.h>
30     //
31 mocchiut 1.16 // RunInfo header
32     //
33     #include <RunInfo.h>
34     //
35 mocchiut 1.1 // YODA headers
36     //
37     #include <PamelaRun.h>
38     #include <physics/trigger/TriggerEvent.h>
39     #include <physics/tof/TofEvent.h>
40     //
41     // This program headers
42     //
43     #include <ToFCore.h>
44     #include <ToFLevel2.h>
45     #include <ToFVerl2.h>
46     //
47     //
48     // Declaration of the core fortran routines
49     //
50     #define tofl2com tofl2com_
51     extern "C" int tofl2com();
52     #define toftrk toftrk_
53     extern "C" int toftrk();
54     #define rdtofcal rdtofcal_
55 mocchiut 1.9 extern "C" int rdtofcal(char [], int *);
56 mocchiut 1.1
57     //
58     // Tracker classes headers and definitions
59     //
60     #include <TrkLevel2.h>
61     //
62     using namespace std;
63     //
64     //
65     // CORE ROUTINE
66     //
67     //
68 mocchiut 1.27 int ToFCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t ToFargc, char *ToFargv[]){
69 mocchiut 1.1 //
70     //
71     // Set these to true to have a very verbose output.
72     //
73     Bool_t verbose = false;
74     Bool_t debug = false;
75     //
76 mocchiut 1.19 TString processFolder = Form("ToFFolder_%u",run);
77 mocchiut 1.1 if ( ToFargc > 0 ){
78     Int_t i = 0;
79     while ( i < ToFargc ){
80     if ( !strcmp(ToFargv[i],"-processFolder") ) {
81     if ( ToFargc < i+1 ){
82     throw -3;
83     };
84     processFolder = (TString)ToFargv[i+1];
85     i++;
86     };
87 mocchiut 1.20 if ( !strcmp(ToFargv[i],"-v") || !strcmp(ToFargv[i],"--verbose") ) {
88 mocchiut 1.1 verbose = true;
89 mocchiut 1.20 };
90 mocchiut 1.1 if ( !strcmp(ToFargv[i],"-g") || !strcmp(ToFargv[i],"--debug") ) {
91 mocchiut 1.18 verbose = true;
92 mocchiut 1.1 debug = true;
93     };
94     i++;
95     };
96     };
97     //
98     //
99     // Output directory is the working directoy.
100     //
101     const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
102     //
103     // Variables for level2
104     //
105     TTree *tracker = 0;
106     TTree *toft = 0;
107 mocchiut 1.6 UInt_t nevents = 0;
108 mocchiut 1.15 Long64_t maxsize = 10000000000LL;
109     TTree::SetMaxTreeSize(maxsize);
110 mocchiut 1.1 //
111     // variables needed to reprocess data
112     //
113     TString tofversion;
114     ItoRunInfo *runinfo = 0;
115 mocchiut 1.6 TArrayI *runlist = 0;
116 mocchiut 1.1 TTree *toftclone = 0;
117     Bool_t reproc = false;
118     Bool_t reprocall = false;
119     UInt_t nobefrun = 0;
120     UInt_t noaftrun = 0;
121     UInt_t numbofrun = 0;
122     stringstream ftmpname;
123     TString fname;
124 mocchiut 1.6 UInt_t totfileentries = 0;
125     UInt_t idRun = 0;
126 mocchiut 1.1 //
127     // variables needed to handle error signals
128     //
129     Int_t code = 0;
130     Int_t sgnl;
131     //
132     // tof level2 classes
133     //
134     ToFLevel2 *tof = new ToFLevel2();
135     ToFLevel2 *tofclone = new ToFLevel2();
136 carbone 1.37 ToFdEdx *tofdedx = new ToFdEdx();
137 mocchiut 1.1 //
138     // tracker level2 variables
139     //
140     TrkLevel2 *trk = new TrkLevel2();
141 mocchiut 1.6 Int_t nevtrkl2 = 0;
142 mocchiut 1.1 //
143     // define variables for opening and reading level0 file
144     //
145     TFile *l0File = 0;
146     TTree *l0tr = 0;
147     TBranch *l0head = 0;
148     TBranch *l0trig = 0;
149     TBranch *l0tof = 0;
150 mocchiut 1.6 pamela::EventHeader *eh = 0;
151     pamela::PscuHeader *ph = 0;
152 mocchiut 1.1 pamela::trigger::TriggerEvent *trig = 0;
153     pamela::tof::TofEvent *tofEvent = 0;
154     //
155     // Define other basic variables
156     //
157     UInt_t procev = 0;
158     stringstream file2;
159     stringstream file3;
160     stringstream qy;
161     Int_t itr = -1;
162     Int_t totevent = 0;
163 mocchiut 1.6 UInt_t atime = 0;
164     UInt_t re = 0;
165 mocchiut 1.7 UInt_t jumped = 0;
166 mocchiut 1.1 //
167     // Working filename
168     //
169     TString outputfile;
170     stringstream name;
171     name.str("");
172     name << outdir << "/";
173     //
174     // temporary file and folder
175     //
176     TFile *tempfile = 0;
177     TTree *temptof = 0;
178     stringstream tempname;
179     stringstream toffolder;
180 mocchiut 1.25 Bool_t myfold = false;
181 mocchiut 1.1 tempname.str("");
182     tempname << outdir;
183     tempname << "/" << processFolder.Data();
184     toffolder.str("");
185     toffolder << tempname.str().c_str();
186     tempname << "/toftree_run";
187     tempname << run << ".root";
188 mocchiut 1.36 UInt_t totnorun = 0;
189 mocchiut 1.1 //
190     // variables needed to load magnetic field maps
191     //
192     Int_t ntrkentry = 0;
193 mocchiut 1.4 Int_t npmtentry = 0;
194 mocchiut 1.6 UInt_t tttrkpar1 = 0;
195 mocchiut 1.1 Bool_t trkpar1 = true;
196 mocchiut 1.6 UInt_t tttofpar1 = 0;
197 mocchiut 1.1 Bool_t tofpar1 = true;
198     //
199     // DB classes
200     //
201     GL_ROOT *glroot = new GL_ROOT();
202     GL_PARAM *glparam = new GL_PARAM();
203 mocchiut 1.6 GL_TIMESYNC *dbtime = 0;
204 mocchiut 1.1 //
205     // declaring external output and input structures
206     //
207     extern struct ToFInput tofinput_;
208     extern struct ToFOutput tofoutput_;
209     //
210 mocchiut 1.32 // WM variables perform dE/dx II order corrections
211     //
212     Float_t dedx_corr_m[100][48],dedx_corr[48];
213     Double_t mtime[100],t1,t2,tm;
214     Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2;
215     Float_t xmean1,xwidth1;
216     Int_t ical,ii,wj,jj;
217 mocchiut 1.40 Float_t xleft=0;
218     Float_t xright=0;
219     Float_t yleft=0;
220     Float_t yright=0;
221 mocchiut 1.32 //
222 mocchiut 1.1 // Let's start!
223     //
224     //
225     // 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
226     // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file
227     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
228     //
229 mocchiut 1.6 if ( run == 0 ) reproc = true;
230 mocchiut 1.1 //
231     //
232     // Output file is "outputfile"
233     //
234     if ( !file->IsOpen() ){
235     if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n");
236     throw -301;
237     };
238     //
239     // Does it contain the Tracker tree?
240     //
241     tracker = (TTree*)file->Get("Tracker");
242     if ( !tracker ) {
243     if ( verbose ) printf(" TOF - ERROR: no tracker tree\n");
244     code = -302;
245     goto closeandexit;
246     };
247     //
248     // get tracker level2 data pointer
249     //
250     tracker->SetBranchAddress("TrkLevel2",&trk);
251     nevtrkl2 = tracker->GetEntries();
252     //
253     // Retrieve GL_RUN variables from the level2 file
254     //
255     tofversion = ToFInfo(false); // we should decide how to handle versioning system
256     //
257     // create an interface to RunInfo called "runinfo"
258     //
259     // ItoRunInfo= interface with RunInfo and GL_RUN
260     runinfo = new ItoRunInfo(file);
261     //
262     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
263     //
264     sgnl = 0;
265     sgnl = runinfo->Update(run, "TOF",tofversion);
266     if ( sgnl ){
267     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
268     code = sgnl;
269     goto closeandexit;
270     } else {
271     sgnl = 0;
272     };
273     //
274     // number of events in the file BEFORE the first event of our run
275     //
276     nobefrun = runinfo->GetFirstEntry();
277     //
278     // total number of events in the file
279     //
280     totfileentries = runinfo->GetFileEntries();
281     //
282     // first file entry AFTER the last event of our run
283     //
284     noaftrun = runinfo->GetLastEntry() + 1;
285     //
286     // number of run to be processed
287     //
288     numbofrun = runinfo->GetNoRun();
289 mocchiut 1.36 totnorun = runinfo->GetRunEntries();
290 mocchiut 1.1 //
291     // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run
292     //
293     toftclone = (TTree*)file->Get("ToF");
294     //
295     if ( !toftclone ){
296     //
297     // tree does not exist, we are not reprocessing
298     //
299     reproc = false;
300 mocchiut 1.6 if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n");
301     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");
302 mocchiut 1.1
303     } else {
304     //
305     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
306     //
307 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
308 mocchiut 1.1 reproc = true;
309     //
310     // update versioning information
311     //
312     if ( verbose ) printf("\n Preparing the pre-processing...\n");
313     //
314 mocchiut 1.21 if ( run == 0 || totnorun == 1 ){
315 mocchiut 1.1 //
316     // we are reprocessing all the file
317     // 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
318     //
319     reprocall = true;
320     //
321     if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n");
322     //
323     } else {
324     //
325     // 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
326     //
327     reprocall = false;
328     //
329 mocchiut 1.6 if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run);
330 mocchiut 1.1 //
331     // copying old tree to a new file
332     //
333 mocchiut 1.25 gSystem->MakeDirectory(toffolder.str().c_str());
334     myfold = true;
335 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
336     temptof = toftclone->CloneTree(-1,"fast");
337     temptof->SetName("ToF-old");
338     tempfile->Write();
339     tempfile->Close();
340     }
341     //
342     // Delete the old tree from old file and memory
343     //
344     toftclone->Delete("all");
345     //
346     if ( verbose ) printf(" ...done!\n");
347     //
348     };
349     //
350     // create ToF detector tree toft
351     //
352     file->cd();
353     toft = new TTree("ToF-new","PAMELA Level2 ToF data");
354 mocchiut 1.15 toft->SetAutoSave(900000000000000LL);
355     tof->Set();//ELENA **TEMPORANEO?**
356 mocchiut 1.1 toft->Branch("ToFLevel2","ToFLevel2",&tof);
357     //
358     if ( reproc && !reprocall ){
359     //
360     // open new file and retrieve all tree informations
361     //
362     tempfile = new TFile(tempname.str().c_str(),"READ");
363     toftclone = (TTree*)tempfile->Get("ToF-old");
364 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
365 mocchiut 1.1 toftclone->SetBranchAddress("ToFLevel2",&tofclone);
366     //
367     if ( nobefrun > 0 ){
368     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
369 mocchiut 1.6 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
370 mocchiut 1.1 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
371     for (UInt_t j = 0; j < nobefrun; j++){
372     //
373 mocchiut 1.42 if ( toftclone->GetEntry(j) <= 0 ) throw -36;
374 mocchiut 1.1 //
375     // copy tofclone to tof
376     //
377 mocchiut 1.3 tof->Clear();
378 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
379     //
380     // Fill entry in the new tree
381     //
382     toft->Fill();
383     //
384     };
385     if ( verbose ) printf(" Finished successful copying!\n");
386     };
387     };
388     //
389     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
390     //
391     runlist = runinfo->GetRunList();
392     //
393     // Loop over the run to be processed
394     //
395     for (UInt_t irun=0; irun < numbofrun; irun++){
396     //
397     // retrieve the first run ID to be processed using the RunInfo list
398     //
399     idRun = runlist->At(irun);
400     if ( verbose ) printf("\n\n\n ####################################################################### \n");
401 mocchiut 1.6 if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun);
402 mocchiut 1.1 if ( verbose ) printf(" ####################################################################### \n\n\n");
403     //
404 mocchiut 1.6 runinfo->ID_ROOT_L0 = 0;
405 mocchiut 1.1 //
406     // store in the runinfo class the GL_RUN variables for our run
407     //
408     sgnl = 0;
409     sgnl = runinfo->GetRunInfo(idRun);
410     if ( sgnl ){
411     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
412     code = sgnl;
413     goto closeandexit;
414     } else {
415     sgnl = 0;
416     };
417     //
418 mocchiut 1.6 // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
419 mocchiut 1.1 //
420 mocchiut 1.6 if ( runinfo->ID_ROOT_L0 == 0 ){
421     if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
422 mocchiut 1.1 code = -5;
423     goto closeandexit;
424     };
425     //
426 mocchiut 1.6 // prepare the timesync for the db
427     //
428 mocchiut 1.27 TString host = glt->CGetHost();
429     TString user = glt->CGetUser();
430     TString psw = glt->CGetPsw();
431     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
432     if ( !dbc->IsConnected() ) throw -314;
433 mocchiut 1.28 stringstream myquery;
434     myquery.str("");
435     myquery << "SET time_zone='+0:00'";
436     dbc->Query(myquery.str().c_str());
437 mocchiut 1.6 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
438     //
439 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
440     //
441 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
442 mocchiut 1.6 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
443 mocchiut 1.1 //
444     ftmpname.str("");
445     ftmpname << glroot->PATH.Data() << "/";
446     ftmpname << glroot->NAME.Data();
447     fname = ftmpname.str().c_str();
448     //
449     // print out informations
450     //
451 mocchiut 1.6 totevent = runinfo->NEVENTS;
452 mocchiut 1.1 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
453 mocchiut 1.6 if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
454     if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
455     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);
456 mocchiut 1.1 //
457 mocchiut 1.31 // if ( !totevent ) goto closeandexit;
458 mocchiut 1.30 //
459 mocchiut 1.1 // Open Level0 file
460     //
461     l0File = new TFile(fname.Data());
462     if ( !l0File ) {
463     if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n");
464     code = -6;
465     goto closeandexit;
466     };
467     l0tr = (TTree*)l0File->Get("Physics");
468     if ( !l0tr ) {
469     if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n");
470     l0File->Close();
471     code = -7;
472     goto closeandexit;
473     };
474     l0head = l0tr->GetBranch("Header");
475     if ( !l0head ) {
476     if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n");
477     l0File->Close();
478     code = -8;
479     goto closeandexit;
480     };
481     l0trig = l0tr->GetBranch("Trigger");
482     if ( !l0trig ) {
483     if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n");
484     l0File->Close();
485     code = -300;
486     goto closeandexit;
487     };
488     l0tof = l0tr->GetBranch("Tof");
489     if ( !l0tof ) {
490     if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n");
491     l0File->Close();
492     code = -303;
493     goto closeandexit;
494     };
495     //
496     l0tr->SetBranchAddress("Trigger", &trig);
497     l0tr->SetBranchAddress("Tof", &tofEvent);
498 mocchiut 1.6 l0tr->SetBranchAddress("Header", &eh);
499 mocchiut 1.1 //
500 mocchiut 1.6 nevents = l0tof->GetEntries();
501 mocchiut 1.1 //
502 mocchiut 1.31 if ( nevents < 1 && totevent ) {
503 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n");
504     l0File->Close();
505     code = -11;
506     goto closeandexit;
507     };
508     //
509 mocchiut 1.31 if ( runinfo->EV_TO > nevents-1 && totevent ) {
510 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n");
511     l0File->Close();
512     code = -12;
513     goto closeandexit;
514     };
515     //
516     // Check if we have to load parameter files (or calibration associated to runs and not to events)
517     //
518     // for example let's assume that we could have different magnetic field maps for different runs:
519     //
520     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){
521     trkpar1 = false;
522     // read from DB infos about Magnetic filed maps
523 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
524 mocchiut 1.6 glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table
525 mocchiut 1.1 tttrkpar1 = glparam->TO_TIME;
526     // ----------------------------
527     // Read the magnetic field
528     // ----------------------------
529     if ( verbose ) printf(" Reading magnetic field maps: \n");
530     trk->LoadField(glparam->PATH+glparam->NAME);
531     if ( verbose ) printf("\n");
532     };
533 mocchiut 1.6 //
534 mocchiut 1.22 // variable to save information about the tof calibration used
535     //
536     Bool_t defcal = true;
537     //
538 mocchiut 1.1 if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
539     tofpar1 = false;
540     //
541 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
542 mocchiut 1.6 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
543 mocchiut 1.1 if ( error<0 ) {
544     code = error;
545     goto closeandexit;
546     };
547     //
548 mocchiut 1.9 if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
549     //
550 mocchiut 1.24 if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
551 mocchiut 1.22 //
552 mocchiut 1.1 tttofpar1 = glparam->TO_TIME;
553 mocchiut 1.9 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
554     rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
555 mocchiut 1.20 //
556 mocchiut 1.1 };
557     //
558 carbone 1.37 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table
559     if ( error<0 ) {
560     code = error;
561     goto closeandexit;
562     };
563     //
564     if ( verbose ) printf(" Reading ToF attenuation parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
565     tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data());
566    
567     //
568     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table
569     if ( error<0 ) {
570     code = error;
571     goto closeandexit;
572     };
573     //
574     if ( verbose ) printf(" Reading ToF desaturation on position parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
575     tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data());
576    
577     //
578     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table
579     if ( error<0 ) {
580     code = error;
581     goto closeandexit;
582     };
583     //
584     if ( verbose ) printf(" Reading ToF BetheBloch parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
585     tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data());
586    
587     //
588     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table
589     if ( error<0 ) {
590     code = error;
591     goto closeandexit;
592     };
593     //
594     if ( verbose ) printf(" Reading ToF Bethe-Bloch parameter file for beta gt1: %s \n",(glparam->PATH+glparam->NAME).Data());
595     tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data());
596    
597     //
598     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table
599     if ( error<0 ) {
600     code = error;
601     goto closeandexit;
602     };
603     //
604     if ( verbose ) printf(" Reading ToF desaturation on beta parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
605     tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data());
606    
607    
608     tofdedx->CheckConnectors(runinfo->RUNHEADER_TIME,glparam,dbc);
609    
610     //
611 mocchiut 1.32 // WM reading parameter file for dE/dx II order corrections
612     //
613     memset(dedx_corr_m,0,100*48*sizeof(Float_t));
614     memset(dedx_corr,0,48*sizeof(Float_t));
615     memset(mtime,0,100*sizeof(Double_t));
616     //
617     // Query the DB to get the file
618     //
619 carbone 1.37 error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,203,dbc); // parameters stored in DB in GL_PRAM table
620 mocchiut 1.32 if ( error<0 ) {
621     code = error;
622     goto closeandexit;
623     };
624     //
625     if ( verbose ) printf(" Reading ToF dE/dx II order correction parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
626     //
627     ical=0; // counter set to zero if first-time reading
628     //-----------------------------------------------------------
629     // Here I read the dEdx_korr parameters
630     //-----------------------------------------------------------
631     jj=0;
632     ifstream fin((glparam->PATH+glparam->NAME).Data());
633 mocchiut 1.33 UInt_t window = 200000;
634     Bool_t first = true;
635     Bool_t last = true;
636     Float_t sdedx_corr_m[48];
637     memset(sdedx_corr_m,0,48*sizeof(Float_t));
638     Double_t stm = 0;
639 mocchiut 1.32 while ( !fin.eof() ){
640 mocchiut 1.33 stm = tm;
641 mocchiut 1.35 // if ( jj > 0 ) memcpy(sdedx_corr_m,dedx_corr_m[jj-1],48*sizeof(Float_t)); // BUG sdedx should be the previous in time not the previous saved [absurd dE/dx for 8th reduction March and > March 2008 data - fixed on 2009/02/04
642 mocchiut 1.32 fin>>t1>>tm>>t2;
643     if ( verbose ) cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl;
644 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
645     if ( first ){
646     mtime[jj]=stm;
647     jj++;
648     if ( jj >= 100 ){
649     code = -318;
650     goto closeandexit;
651     };
652     };
653 mocchiut 1.32 mtime[jj]=tm;
654     };
655     for (ii=0; ii<48;ii++){
656     fin>>wj>>xmean1>>xwidth1;
657 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
658 mocchiut 1.35 if ( first ){
659 mocchiut 1.33 dedx_corr_m[jj-1][ii]=sdedx_corr_m[ii];
660     };
661 mocchiut 1.32 dedx_corr_m[jj][ii]=xmean1;
662     };
663 mocchiut 1.35 sdedx_corr_m[ii]=xmean1; // BUG sdedx should be the previous in time not the previous saved [absurd dE/dx for 8th reduction March and > March 2008 data - fixed on 2009/02/04
664 mocchiut 1.32 };
665 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last)){
666     if ( first ) first = false;
667     if ( tm > (runinfo->RUNTRAILER_TIME+window) ) last = false;
668 mocchiut 1.32 jj++;
669     };
670     if ( jj >= 100 ){
671     code = -318;
672     goto closeandexit;
673     };
674     };
675     //
676 mocchiut 1.35 fin.close();
677     // this is a possible bug...
678     // Bool_t ff = false;
679     // while ( runinfo->RUNHEADER_TIME > mtime[ical] && ical < 100 ) {
680     // ical = ical+1;
681     // ff = true;
682     // };
683     while ( (mtime[ical] > runinfo->RUNHEADER_TIME || runinfo->RUNHEADER_TIME > mtime[ical+1] ) && ical < 99 ) {
684 mocchiut 1.32 ical = ical+1;
685 mocchiut 1.35 // ff = true;
686 mocchiut 1.32 };
687 mocchiut 1.35 // if ( ff ) ical = ical-1;
688 mocchiut 1.32 if ( verbose ) cout<<"rh time "<<runinfo->RUNHEADER_TIME<<" rt time "<<runinfo->RUNTRAILER_TIME<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<< " jj " << jj<< endl;
689     if ( ical < 0 || ical >= 98 ){
690     code = -315;
691     goto closeandexit;
692     };
693     //
694 mocchiut 1.1 // run over all the events of the run
695     //
696     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
697     //
698 mocchiut 1.26 if ( dbc ){
699     dbc->Close();
700 mocchiut 1.27 delete dbc;
701 mocchiut 1.26 };
702     //
703 mocchiut 1.7 jumped = 0;
704 mocchiut 1.6 //
705     for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
706 mocchiut 1.1 //
707     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
708     //
709 mocchiut 1.42 if ( l0head->GetEntry(re) <= 0 ) throw -36;
710 mocchiut 1.1 //
711     // absolute time of this event
712     //
713 mocchiut 1.6 ph = eh->GetPscuHeader();
714     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
715 mocchiut 1.4 //
716     tof->Clear();
717     Int_t pmt_id = 0;
718     ToFPMT *t_pmt = new ToFPMT();
719 mocchiut 1.15 if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA
720 mocchiut 1.4 TClonesArray &tpmt = *tof->PMT;
721     ToFTrkVar *t_tof = new ToFTrkVar();
722 mocchiut 1.15 if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
723 mocchiut 1.4 TClonesArray &t = *tof->ToFTrk;
724     //
725 mocchiut 1.1 // paranoid check
726     //
727 mocchiut 1.32 if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) {
728 mocchiut 1.1 if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n");
729 mocchiut 1.7 jumped++;
730 mocchiut 1.1 goto jumpev;
731     };
732     //
733     // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr"
734     //
735     if ( !reprocall ){
736 mocchiut 1.7 itr = nobefrun + (re - runinfo->EV_FROM -jumped);
737 mocchiut 1.1 } else {
738 mocchiut 1.7 itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped);
739 mocchiut 1.1 };
740     if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number
741     if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
742     l0File->Close();
743     code = -313;
744     goto closeandexit;
745     };
746 mocchiut 1.8 //
747     trk->Clear();
748     //
749 mocchiut 1.42 if ( tracker->GetEntry(itr) <= 0 ) throw -36;
750 mocchiut 1.1 ///
751 mocchiut 1.2 //
752 mocchiut 1.42 if ( l0tof->GetEntry(re) <= 0 ) throw -36;
753     if ( l0trig->GetEntry(re) <= 0 ) throw -36;
754 mocchiut 1.1 ///
755     //
756     procev++;
757     //
758     // start processing
759     //
760 mocchiut 1.32 // dE/dx II order correction: check time limits and interpolate time correction
761     //==================================================================
762     //== if time is outside time limits:
763     //==================================================================
764     if ( atime<mtime[ical] || atime>mtime[ical+1] ){
765     if ( verbose ) cout<<"Checking Time Limits!"<<endl;
766     ical=0;
767 mocchiut 1.35 //Bool_t fg = false;
768     while ( ( mtime[ical] > atime || atime > mtime[ical+1]) && ical < 99 ){
769 mocchiut 1.32 ical = ical+1;
770 mocchiut 1.35 //fg = true;
771 mocchiut 1.32 }
772 mocchiut 1.35 // if ( fg ) ical = ical-1;
773 mocchiut 1.32 if ( ical < 0 || ical >= 98 ){
774     code = -317;
775     goto closeandexit;
776     };
777     if ( verbose ) cout<<"abs time "<<atime<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl;
778     };
779     //==================================================================
780     //== interpolate betwen time limits
781     //==================================================================
782     thelp1 = mtime[ical];
783     thelp2 = mtime[ical+1];
784     for (ii=0; ii<48;ii++) {
785 mocchiut 1.39 yhelp1 = fabs(dedx_corr_m[ical][ii]);
786 mocchiut 1.43 if ( yhelp1 < 0.1 ) yhelp1 = 4.;
787 mocchiut 1.39 yhelp2 = fabs(dedx_corr_m[ical+1][ii]);
788 mocchiut 1.43 if ( yhelp2 < 0.1 ) yhelp2 = 4.;
789 mocchiut 1.32 slope = (yhelp2-yhelp1)/(thelp2-thelp1);
790     inter = yhelp1 - slope*thelp1;
791     dedx_corr[ii] = slope*atime + inter;
792 mocchiut 1.34 if ( fabs(dedx_corr[ii]) <= 1e-15 ){
793     if ( verbose ) printf("ii %i slope %f atime %u inter %f dedx_corr %f \n",ii,slope,atime,inter,dedx_corr[ii]);
794     if ( verbose ) printf("ical %i yhelp2 %f yhelp1 %f thelp2 %f thelp1 %f \n",ical,yhelp2,yhelp1,thelp2,thelp1);
795 mocchiut 1.32 code = -316;
796     goto closeandexit;
797     };
798     };
799     //================================================================
800     //================================================================
801 mocchiut 1.1 //
802     // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
803 mocchiut 1.32 //
804 mocchiut 1.1 for (Int_t gg=0; gg<4;gg++){
805     for (Int_t hh=0; hh<12;hh++){
806     tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
807     tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh];
808     };
809     };
810 mocchiut 1.32 //
811 mocchiut 1.38 tofdedx->Init(tofEvent);
812     //
813 mocchiut 1.1 for (Int_t hh=0; hh<5;hh++){
814     tofinput_.patterntrig[hh]=trig->patterntrig[hh];
815     };
816     //
817     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
818     //
819 mocchiut 1.4 npmtentry = 0;
820     //
821     ntrkentry = 0;
822 mocchiut 1.1 //
823     // Calculate tracks informations from ToF alone
824     //
825     tofl2com();
826     //
827 mocchiut 1.4 memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
828     //
829     t_tof->trkseqno = -1;
830     //
831 mocchiut 1.1 // and now we must copy from the output structure to the level2 class:
832     //
833 mocchiut 1.4 t_tof->npmttdc = 0;
834     //
835 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
836     for (Int_t kk=0; kk<4;kk++){
837 mocchiut 1.4 if ( tofoutput_.tofmask[hh][kk] != 0 ){
838     pmt_id = tof->GetPMTid(kk,hh);
839     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
840 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
841 mocchiut 1.4 t_tof->npmttdc++;
842     };
843     };
844     };
845     for (Int_t kk=0; kk<13;kk++){
846     t_tof->beta[kk] = tofoutput_.betatof_a[kk];
847 mocchiut 1.1 }
848 mocchiut 1.4 //
849 carbone 1.37
850     //
851     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
852     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
853     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
854     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
855     //
856     {
857    
858 mocchiut 1.40 Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
859     Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
860    
861     if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
862     xtof_temp[1]=t_tof->xtofpos[0];
863     ytof_temp[0]=t_tof->ytofpos[0];
864     }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
865     ytof_temp[0]=t_tof->ytofpos[0];
866     tof->GetPaddleGeometry(0,(Int_t)log2(tof->tof_j_flag[0]),xleft, xright, yleft, yright);
867 mocchiut 1.41 xtof_temp[1]=xleft+2.55;
868 mocchiut 1.40 }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
869     xtof_temp[1]=t_tof->xtofpos[0];
870     tof->GetPaddleGeometry(1,(Int_t)log2(tof->tof_j_flag[1]),xleft, xright, yleft, yright);
871 mocchiut 1.41 ytof_temp[0]=yleft+2.75;
872 mocchiut 1.40 }
873    
874     if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
875     xtof_temp[2]=t_tof->xtofpos[1];
876     ytof_temp[3]=t_tof->ytofpos[1];
877     }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
878     ytof_temp[3]=t_tof->ytofpos[1];
879     tof->GetPaddleGeometry(3,(Int_t)log2(tof->tof_j_flag[3]),xleft, xright, yleft, yright);
880 mocchiut 1.41 xtof_temp[2]=xleft+4.5;
881 mocchiut 1.40 }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
882     xtof_temp[2]=t_tof->xtofpos[1];
883     tof->GetPaddleGeometry(2,(Int_t)log2(tof->tof_j_flag[2]),xleft, xright, yleft, yright);
884 mocchiut 1.41 ytof_temp[3]=yleft+3.75;
885 mocchiut 1.40 }
886    
887     if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
888     xtof_temp[5]=t_tof->xtofpos[2];
889     ytof_temp[4]=t_tof->ytofpos[2];
890     }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
891     ytof_temp[4]=t_tof->ytofpos[2];
892     tof->GetPaddleGeometry(4,(Int_t)log2(tof->tof_j_flag[4]),xleft, xright, yleft, yright);
893 mocchiut 1.41 xtof_temp[5]=xleft+3;
894 mocchiut 1.40 }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
895     xtof_temp[5]=t_tof->xtofpos[2];
896     tof->GetPaddleGeometry(5,(Int_t)log2(tof->tof_j_flag[5]),xleft, xright, yleft, yright);
897 mocchiut 1.41 ytof_temp[4]=yleft+2.5;
898 mocchiut 1.40 }
899     // Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]};
900     // Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.};
901     tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
902     t_tof->npmtadc = 0;
903     for (Int_t hh=0; hh<12;hh++){
904     for (Int_t kk=0; kk<4;kk++){
905 mocchiut 1.4 pmt_id = tof->GetPMTid(kk,hh);
906 mocchiut 1.40 Int_t Iplane=-1;
907     Int_t Ipaddle=-1;
908     // Int_t IpaddleT=-1;
909     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
910     tof->GetPaddleGeometry(Iplane,Ipaddle,xleft,xright,yleft,yright);
911     if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. &&((xtof_temp[Iplane]>=xleft&&xtof_temp[Iplane]<=xright) || (ytof_temp[Iplane]>=yleft&&ytof_temp[Iplane]<=yright)) ){ //attenzione:qui va inserito un controllo sulla traccia tof o sulle variabili di posizione !!!!
912 mocchiut 1.43 t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc);
913 mocchiut 1.40 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
914     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
915     t_tof->npmtadc++;
916     };
917 mocchiut 1.4 };
918     };
919     };
920 mocchiut 1.40
921 mocchiut 1.20 /*
922     cout<<"ToFCore tofl2com"<<endl;
923     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
924     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
925     cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl;
926     cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl;
927     */
928    
929    
930 mocchiut 1.4 new(t[ntrkentry]) ToFTrkVar(*t_tof);
931     ntrkentry++;
932     t_tof->Clear();
933     //
934 mocchiut 1.1 //
935     //
936 mocchiut 1.4 t_pmt->Clear();
937 mocchiut 1.1 //
938 mocchiut 1.4 for (Int_t hh=0; hh<12;hh++){
939     for (Int_t kk=0; kk<4;kk++){
940 mocchiut 1.29 // new WM
941     if ( tofoutput_.tdc_c[hh][kk] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofEvent->tdc[kk][hh] < 4095 ){
942 mocchiut 1.4 //
943     t_pmt->pmt_id = tof->GetPMTid(kk,hh);
944     t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
945 mocchiut 1.28 t_pmt->adc = (Float_t)tofEvent->adc[kk][hh];
946     t_pmt->tdc = (Float_t)tofEvent->tdc[kk][hh];
947 mocchiut 1.29 //
948 mocchiut 1.4 new(tpmt[npmtentry]) ToFPMT(*t_pmt);
949     npmtentry++;
950     t_pmt->Clear();
951     };
952     };
953     };
954 mocchiut 1.1 //
955 mocchiut 1.38 if ( debug ) printf(" ATIME %u re %u \n",atime,(UInt_t)re);
956 mocchiut 1.4 // Calculate track-related variables
957 mocchiut 1.1 //
958 mocchiut 1.2 if ( trk->ntrk() > 0 ){
959 mocchiut 1.1 //
960     // We have at least one track
961     //
962     //
963     // Run over tracks
964     //
965     for(Int_t nt=0; nt < trk->ntrk(); nt++){
966     //
967     TrkTrack *ptt = trk->GetStoredTrack(nt);
968     //
969     // Copy the alpha vector in the input structure
970     //
971     for (Int_t e = 0; e < 5 ; e++){
972     tofinput_.al_pp[e] = ptt->al[e];
973     };
974     //
975     // Get tracker related variables for this track
976     //
977     toftrk();
978     //
979     // Copy values in the class from the structure (we need to use a temporary class to store variables).
980     //
981 mocchiut 1.4 t_tof->npmttdc = 0;
982     for (Int_t hh=0; hh<12;hh++){
983     for (Int_t kk=0; kk<4;kk++){
984     if ( tofoutput_.tofmask[hh][kk] != 0 ){
985     pmt_id = tof->GetPMTid(kk,hh);
986     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
987 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
988 mocchiut 1.4 t_tof->npmttdc++;
989     };
990     };
991     };
992 mocchiut 1.1 for (Int_t kk=0; kk<13;kk++){
993 mocchiut 1.4 t_tof->beta[kk] = tofoutput_.beta_a[kk];
994     };
995 carbone 1.37 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
996     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
997     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
998     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
999 mocchiut 1.4 //
1000 mocchiut 1.38 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
1001 mocchiut 1.4 t_tof->npmtadc = 0;
1002 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
1003     for (Int_t kk=0; kk<4;kk++){
1004 carbone 1.37 pmt_id = tof->GetPMTid(kk,hh);
1005 mocchiut 1.40 Int_t Iplane=-1;
1006     Int_t Ipaddle=-1;
1007     Int_t IpaddleT=-1;
1008     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1009     IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane);
1010     if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && Ipaddle==IpaddleT ){
1011 mocchiut 1.43 t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),t_tof->npmtadc);
1012     if ( debug ) printf(" nt %i npmtadc %i dedx %f dedx corr %f\n",nt,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*4./dedx_corr[pmt_id]),dedx_corr[pmt_id]);
1013 mocchiut 1.4 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1014 carbone 1.37 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1015 mocchiut 1.4 t_tof->npmtadc++;
1016     };
1017 carbone 1.37
1018 mocchiut 1.4 };
1019     };
1020     //
1021 mocchiut 1.20
1022     /*
1023     cout<<"ToFCore toftrk"<<endl;
1024     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
1025     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
1026     cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl;
1027     cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl;
1028     */
1029    
1030 mocchiut 1.1 //
1031     // Store the tracker track number in order to be sure to have shyncronized data during analysis
1032     //
1033     t_tof->trkseqno = nt;
1034     //
1035     // create a new object for this event with track-related variables
1036     //
1037     new(t[ntrkentry]) ToFTrkVar(*t_tof);
1038     ntrkentry++;
1039 mocchiut 1.4 t_tof->Clear();
1040 mocchiut 1.1 //
1041     }; // loop on all the tracks
1042     };
1043     //
1044 mocchiut 1.9 tof->unpackError = tofEvent->unpackError;
1045 mocchiut 1.22 if ( defcal ){
1046     tof->default_calib = 1;
1047     } else {
1048     tof->default_calib = 0;
1049     };
1050 mocchiut 1.9 //
1051 mocchiut 1.1 // Fill the rootple
1052     //
1053     toft->Fill();
1054     //
1055     //
1056 mocchiut 1.4 //
1057     delete t_tof;
1058     //
1059     //
1060     //
1061 mocchiut 1.1 jumpev:
1062 mocchiut 1.38 if ( !debug ) debug = false;
1063 mocchiut 1.1 //
1064     };
1065 mocchiut 1.6 //
1066     // Here you may want to clear some variables before processing another run
1067     //
1068     delete dbtime;
1069 mocchiut 1.1 }; // process all the runs
1070     //
1071     if ( verbose ) printf("\n Finished processing data \n");
1072     //
1073     closeandexit:
1074     //
1075     // 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.
1076     //
1077     if ( !reprocall && reproc && code >= 0 ){
1078     if ( totfileentries > noaftrun ){
1079     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
1080     if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1081     if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1082     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1083     //
1084     // Get entry from old tree
1085     //
1086 mocchiut 1.42 if ( toftclone->GetEntry(j) <= 0 ) throw -36;
1087 mocchiut 1.1 //
1088     // copy tofclone to tof
1089     //
1090 mocchiut 1.3 tof->Clear();
1091 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
1092     //
1093     // Fill entry in the new tree
1094     //
1095     toft->Fill();
1096     };
1097     if ( verbose ) printf(" Finished successful copying!\n");
1098     };
1099     };
1100     //
1101     // Close files, delete old tree(s), write and close level2 file
1102     //
1103     if ( l0File ) l0File->Close();
1104     if ( tempfile ) tempfile->Close();
1105 mocchiut 1.25 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1106 mocchiut 1.1 if ( tracker ) tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file!
1107     //
1108     if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
1109     if ( verbose ) printf("\n Writing and closing rootple\n");
1110     if ( runinfo ) runinfo->Close();
1111     if ( toft ) toft->SetName("ToF");
1112     if ( file ){
1113     file->cd();
1114     file->Write("ToF");
1115     };
1116     //
1117 mocchiut 1.25 if ( myfold ) gSystem->Unlink(toffolder.str().c_str());
1118 mocchiut 1.1 //
1119     // the end
1120     //
1121     if ( verbose ) printf("\n Exiting...\n");
1122     if(toft)toft->Delete();
1123 mocchiut 1.5 //
1124     if ( tof ) delete tof;
1125     if ( tofclone ) delete tofclone;
1126 carbone 1.37 if ( tofdedx ) delete tofdedx;
1127 mocchiut 1.5 if ( glroot ) delete glroot;
1128     if ( runinfo ) delete runinfo;
1129     //
1130 mocchiut 1.1 if ( code < 0 ) throw code;
1131     return(code);
1132     }

  ViewVC Help
Powered by ViewVC 1.1.23