/[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.38 - (hide annotations) (download)
Mon Nov 23 09:50:49 2009 UTC (15 years, 1 month ago) by mocchiut
Branch: MAIN
Changes since 1.37: +10 -17 lines
Cleanup of both C++ and F77 routines

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     //
218 mocchiut 1.1 // Let's start!
219     //
220     //
221     // 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
222     // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file
223     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
224     //
225 mocchiut 1.6 if ( run == 0 ) reproc = true;
226 mocchiut 1.1 //
227     //
228     // Output file is "outputfile"
229     //
230     if ( !file->IsOpen() ){
231     if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n");
232     throw -301;
233     };
234     //
235     // Does it contain the Tracker tree?
236     //
237     tracker = (TTree*)file->Get("Tracker");
238     if ( !tracker ) {
239     if ( verbose ) printf(" TOF - ERROR: no tracker tree\n");
240     code = -302;
241     goto closeandexit;
242     };
243     //
244     // get tracker level2 data pointer
245     //
246     tracker->SetBranchAddress("TrkLevel2",&trk);
247     nevtrkl2 = tracker->GetEntries();
248     //
249     // Retrieve GL_RUN variables from the level2 file
250     //
251     tofversion = ToFInfo(false); // we should decide how to handle versioning system
252     //
253     // create an interface to RunInfo called "runinfo"
254     //
255     // ItoRunInfo= interface with RunInfo and GL_RUN
256     runinfo = new ItoRunInfo(file);
257     //
258     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
259     //
260     sgnl = 0;
261     sgnl = runinfo->Update(run, "TOF",tofversion);
262     if ( sgnl ){
263     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
264     code = sgnl;
265     goto closeandexit;
266     } else {
267     sgnl = 0;
268     };
269     //
270     // number of events in the file BEFORE the first event of our run
271     //
272     nobefrun = runinfo->GetFirstEntry();
273     //
274     // total number of events in the file
275     //
276     totfileentries = runinfo->GetFileEntries();
277     //
278     // first file entry AFTER the last event of our run
279     //
280     noaftrun = runinfo->GetLastEntry() + 1;
281     //
282     // number of run to be processed
283     //
284     numbofrun = runinfo->GetNoRun();
285 mocchiut 1.36 totnorun = runinfo->GetRunEntries();
286 mocchiut 1.1 //
287     // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run
288     //
289     toftclone = (TTree*)file->Get("ToF");
290     //
291     if ( !toftclone ){
292     //
293     // tree does not exist, we are not reprocessing
294     //
295     reproc = false;
296 mocchiut 1.6 if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n");
297     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");
298 mocchiut 1.1
299     } else {
300     //
301     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
302     //
303 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
304 mocchiut 1.1 reproc = true;
305     //
306     // update versioning information
307     //
308     if ( verbose ) printf("\n Preparing the pre-processing...\n");
309     //
310 mocchiut 1.21 if ( run == 0 || totnorun == 1 ){
311 mocchiut 1.1 //
312     // we are reprocessing all the file
313     // 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
314     //
315     reprocall = true;
316     //
317     if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n");
318     //
319     } else {
320     //
321     // 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
322     //
323     reprocall = false;
324     //
325 mocchiut 1.6 if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run);
326 mocchiut 1.1 //
327     // copying old tree to a new file
328     //
329 mocchiut 1.25 gSystem->MakeDirectory(toffolder.str().c_str());
330     myfold = true;
331 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
332     temptof = toftclone->CloneTree(-1,"fast");
333     temptof->SetName("ToF-old");
334     tempfile->Write();
335     tempfile->Close();
336     }
337     //
338     // Delete the old tree from old file and memory
339     //
340     toftclone->Delete("all");
341     //
342     if ( verbose ) printf(" ...done!\n");
343     //
344     };
345     //
346     // create ToF detector tree toft
347     //
348     file->cd();
349     toft = new TTree("ToF-new","PAMELA Level2 ToF data");
350 mocchiut 1.15 toft->SetAutoSave(900000000000000LL);
351     tof->Set();//ELENA **TEMPORANEO?**
352 mocchiut 1.1 toft->Branch("ToFLevel2","ToFLevel2",&tof);
353     //
354     if ( reproc && !reprocall ){
355     //
356     // open new file and retrieve all tree informations
357     //
358     tempfile = new TFile(tempname.str().c_str(),"READ");
359     toftclone = (TTree*)tempfile->Get("ToF-old");
360 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
361 mocchiut 1.1 toftclone->SetBranchAddress("ToFLevel2",&tofclone);
362     //
363     if ( nobefrun > 0 ){
364     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
365 mocchiut 1.6 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
366 mocchiut 1.1 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
367     for (UInt_t j = 0; j < nobefrun; j++){
368     //
369     toftclone->GetEntry(j);
370     //
371     // copy tofclone to tof
372     //
373 mocchiut 1.3 tof->Clear();
374 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
375     //
376     // Fill entry in the new tree
377     //
378     toft->Fill();
379     //
380     };
381     if ( verbose ) printf(" Finished successful copying!\n");
382     };
383     };
384     //
385     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
386     //
387     runlist = runinfo->GetRunList();
388     //
389     // Loop over the run to be processed
390     //
391     for (UInt_t irun=0; irun < numbofrun; irun++){
392     //
393     // retrieve the first run ID to be processed using the RunInfo list
394     //
395     idRun = runlist->At(irun);
396     if ( verbose ) printf("\n\n\n ####################################################################### \n");
397 mocchiut 1.6 if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun);
398 mocchiut 1.1 if ( verbose ) printf(" ####################################################################### \n\n\n");
399     //
400 mocchiut 1.6 runinfo->ID_ROOT_L0 = 0;
401 mocchiut 1.1 //
402     // store in the runinfo class the GL_RUN variables for our run
403     //
404     sgnl = 0;
405     sgnl = runinfo->GetRunInfo(idRun);
406     if ( sgnl ){
407     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
408     code = sgnl;
409     goto closeandexit;
410     } else {
411     sgnl = 0;
412     };
413     //
414 mocchiut 1.6 // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
415 mocchiut 1.1 //
416 mocchiut 1.6 if ( runinfo->ID_ROOT_L0 == 0 ){
417     if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
418 mocchiut 1.1 code = -5;
419     goto closeandexit;
420     };
421     //
422 mocchiut 1.6 // prepare the timesync for the db
423     //
424 mocchiut 1.27 TString host = glt->CGetHost();
425     TString user = glt->CGetUser();
426     TString psw = glt->CGetPsw();
427     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
428     if ( !dbc->IsConnected() ) throw -314;
429 mocchiut 1.28 stringstream myquery;
430     myquery.str("");
431     myquery << "SET time_zone='+0:00'";
432     dbc->Query(myquery.str().c_str());
433 mocchiut 1.6 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
434     //
435 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
436     //
437 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
438 mocchiut 1.6 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
439 mocchiut 1.1 //
440     ftmpname.str("");
441     ftmpname << glroot->PATH.Data() << "/";
442     ftmpname << glroot->NAME.Data();
443     fname = ftmpname.str().c_str();
444     //
445     // print out informations
446     //
447 mocchiut 1.6 totevent = runinfo->NEVENTS;
448 mocchiut 1.1 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
449 mocchiut 1.6 if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
450     if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
451     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);
452 mocchiut 1.1 //
453 mocchiut 1.31 // if ( !totevent ) goto closeandexit;
454 mocchiut 1.30 //
455 mocchiut 1.1 // Open Level0 file
456     //
457     l0File = new TFile(fname.Data());
458     if ( !l0File ) {
459     if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n");
460     code = -6;
461     goto closeandexit;
462     };
463     l0tr = (TTree*)l0File->Get("Physics");
464     if ( !l0tr ) {
465     if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n");
466     l0File->Close();
467     code = -7;
468     goto closeandexit;
469     };
470     l0head = l0tr->GetBranch("Header");
471     if ( !l0head ) {
472     if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n");
473     l0File->Close();
474     code = -8;
475     goto closeandexit;
476     };
477     l0trig = l0tr->GetBranch("Trigger");
478     if ( !l0trig ) {
479     if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n");
480     l0File->Close();
481     code = -300;
482     goto closeandexit;
483     };
484     l0tof = l0tr->GetBranch("Tof");
485     if ( !l0tof ) {
486     if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n");
487     l0File->Close();
488     code = -303;
489     goto closeandexit;
490     };
491     //
492     l0tr->SetBranchAddress("Trigger", &trig);
493     l0tr->SetBranchAddress("Tof", &tofEvent);
494 mocchiut 1.6 l0tr->SetBranchAddress("Header", &eh);
495 mocchiut 1.1 //
496 mocchiut 1.6 nevents = l0tof->GetEntries();
497 mocchiut 1.1 //
498 mocchiut 1.31 if ( nevents < 1 && totevent ) {
499 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n");
500     l0File->Close();
501     code = -11;
502     goto closeandexit;
503     };
504     //
505 mocchiut 1.31 if ( runinfo->EV_TO > nevents-1 && totevent ) {
506 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n");
507     l0File->Close();
508     code = -12;
509     goto closeandexit;
510     };
511     //
512     // Check if we have to load parameter files (or calibration associated to runs and not to events)
513     //
514     // for example let's assume that we could have different magnetic field maps for different runs:
515     //
516     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){
517     trkpar1 = false;
518     // read from DB infos about Magnetic filed maps
519 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
520 mocchiut 1.6 glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table
521 mocchiut 1.1 tttrkpar1 = glparam->TO_TIME;
522     // ----------------------------
523     // Read the magnetic field
524     // ----------------------------
525     if ( verbose ) printf(" Reading magnetic field maps: \n");
526     trk->LoadField(glparam->PATH+glparam->NAME);
527     if ( verbose ) printf("\n");
528     };
529 mocchiut 1.6 //
530 mocchiut 1.22 // variable to save information about the tof calibration used
531     //
532     Bool_t defcal = true;
533     //
534 mocchiut 1.1 if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
535     tofpar1 = false;
536     //
537 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
538 mocchiut 1.6 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
539 mocchiut 1.1 if ( error<0 ) {
540     code = error;
541     goto closeandexit;
542     };
543     //
544 mocchiut 1.9 if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
545     //
546 mocchiut 1.24 if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
547 mocchiut 1.22 //
548 mocchiut 1.1 tttofpar1 = glparam->TO_TIME;
549 mocchiut 1.9 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
550     rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
551 mocchiut 1.20 //
552 mocchiut 1.1 };
553     //
554 carbone 1.37 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table
555     if ( error<0 ) {
556     code = error;
557     goto closeandexit;
558     };
559     //
560     if ( verbose ) printf(" Reading ToF attenuation parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
561     tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data());
562    
563     //
564     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table
565     if ( error<0 ) {
566     code = error;
567     goto closeandexit;
568     };
569     //
570     if ( verbose ) printf(" Reading ToF desaturation on position parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
571     tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data());
572    
573     //
574     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table
575     if ( error<0 ) {
576     code = error;
577     goto closeandexit;
578     };
579     //
580     if ( verbose ) printf(" Reading ToF BetheBloch parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
581     tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data());
582    
583     //
584     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table
585     if ( error<0 ) {
586     code = error;
587     goto closeandexit;
588     };
589     //
590     if ( verbose ) printf(" Reading ToF Bethe-Bloch parameter file for beta gt1: %s \n",(glparam->PATH+glparam->NAME).Data());
591     tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data());
592    
593     //
594     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table
595     if ( error<0 ) {
596     code = error;
597     goto closeandexit;
598     };
599     //
600     if ( verbose ) printf(" Reading ToF desaturation on beta parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
601     tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data());
602    
603    
604     tofdedx->CheckConnectors(runinfo->RUNHEADER_TIME,glparam,dbc);
605    
606     //
607 mocchiut 1.32 // WM reading parameter file for dE/dx II order corrections
608     //
609     memset(dedx_corr_m,0,100*48*sizeof(Float_t));
610     memset(dedx_corr,0,48*sizeof(Float_t));
611     memset(mtime,0,100*sizeof(Double_t));
612     //
613     // Query the DB to get the file
614     //
615 carbone 1.37 error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,203,dbc); // parameters stored in DB in GL_PRAM table
616 mocchiut 1.32 if ( error<0 ) {
617     code = error;
618     goto closeandexit;
619     };
620     //
621     if ( verbose ) printf(" Reading ToF dE/dx II order correction parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
622     //
623     ical=0; // counter set to zero if first-time reading
624     //-----------------------------------------------------------
625     // Here I read the dEdx_korr parameters
626     //-----------------------------------------------------------
627     jj=0;
628     ifstream fin((glparam->PATH+glparam->NAME).Data());
629 mocchiut 1.33 UInt_t window = 200000;
630     Bool_t first = true;
631     Bool_t last = true;
632     Float_t sdedx_corr_m[48];
633     memset(sdedx_corr_m,0,48*sizeof(Float_t));
634     Double_t stm = 0;
635 mocchiut 1.32 while ( !fin.eof() ){
636 mocchiut 1.33 stm = tm;
637 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
638 mocchiut 1.32 fin>>t1>>tm>>t2;
639     if ( verbose ) cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl;
640 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
641     if ( first ){
642     mtime[jj]=stm;
643     jj++;
644     if ( jj >= 100 ){
645     code = -318;
646     goto closeandexit;
647     };
648     };
649 mocchiut 1.32 mtime[jj]=tm;
650     };
651     for (ii=0; ii<48;ii++){
652     fin>>wj>>xmean1>>xwidth1;
653 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
654 mocchiut 1.35 if ( first ){
655 mocchiut 1.33 dedx_corr_m[jj-1][ii]=sdedx_corr_m[ii];
656     };
657 mocchiut 1.32 dedx_corr_m[jj][ii]=xmean1;
658     };
659 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
660 mocchiut 1.32 };
661 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last)){
662     if ( first ) first = false;
663     if ( tm > (runinfo->RUNTRAILER_TIME+window) ) last = false;
664 mocchiut 1.32 jj++;
665     };
666     if ( jj >= 100 ){
667     code = -318;
668     goto closeandexit;
669     };
670     };
671     //
672 mocchiut 1.35 fin.close();
673     // this is a possible bug...
674     // Bool_t ff = false;
675     // while ( runinfo->RUNHEADER_TIME > mtime[ical] && ical < 100 ) {
676     // ical = ical+1;
677     // ff = true;
678     // };
679     while ( (mtime[ical] > runinfo->RUNHEADER_TIME || runinfo->RUNHEADER_TIME > mtime[ical+1] ) && ical < 99 ) {
680 mocchiut 1.32 ical = ical+1;
681 mocchiut 1.35 // ff = true;
682 mocchiut 1.32 };
683 mocchiut 1.35 // if ( ff ) ical = ical-1;
684 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;
685     if ( ical < 0 || ical >= 98 ){
686     code = -315;
687     goto closeandexit;
688     };
689     //
690 mocchiut 1.1 // run over all the events of the run
691     //
692     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
693     //
694 mocchiut 1.26 if ( dbc ){
695     dbc->Close();
696 mocchiut 1.27 delete dbc;
697 mocchiut 1.26 };
698     //
699 mocchiut 1.7 jumped = 0;
700 mocchiut 1.6 //
701     for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
702 mocchiut 1.1 //
703     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
704     //
705 mocchiut 1.6 l0head->GetEntry(re);
706 mocchiut 1.1 //
707     // absolute time of this event
708     //
709 mocchiut 1.6 ph = eh->GetPscuHeader();
710     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
711 mocchiut 1.4 //
712     tof->Clear();
713     Int_t pmt_id = 0;
714     ToFPMT *t_pmt = new ToFPMT();
715 mocchiut 1.15 if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA
716 mocchiut 1.4 TClonesArray &tpmt = *tof->PMT;
717     ToFTrkVar *t_tof = new ToFTrkVar();
718 mocchiut 1.15 if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
719 mocchiut 1.4 TClonesArray &t = *tof->ToFTrk;
720     //
721 mocchiut 1.1 // paranoid check
722     //
723 mocchiut 1.32 if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) {
724 mocchiut 1.1 if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n");
725 mocchiut 1.7 jumped++;
726 mocchiut 1.1 goto jumpev;
727     };
728     //
729     // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr"
730     //
731     if ( !reprocall ){
732 mocchiut 1.7 itr = nobefrun + (re - runinfo->EV_FROM -jumped);
733 mocchiut 1.1 } else {
734 mocchiut 1.7 itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped);
735 mocchiut 1.1 };
736     if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number
737     if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
738     l0File->Close();
739     code = -313;
740     goto closeandexit;
741     };
742 mocchiut 1.8 //
743     trk->Clear();
744     //
745 mocchiut 1.1 tracker->GetEntry(itr);
746     ///
747 mocchiut 1.2 //
748 mocchiut 1.6 l0tof->GetEntry(re);
749     l0trig->GetEntry(re);
750 mocchiut 1.1 ///
751     //
752     procev++;
753     //
754     // start processing
755     //
756 mocchiut 1.32 // dE/dx II order correction: check time limits and interpolate time correction
757     //==================================================================
758     //== if time is outside time limits:
759     //==================================================================
760     if ( atime<mtime[ical] || atime>mtime[ical+1] ){
761     if ( verbose ) cout<<"Checking Time Limits!"<<endl;
762     ical=0;
763 mocchiut 1.35 //Bool_t fg = false;
764     while ( ( mtime[ical] > atime || atime > mtime[ical+1]) && ical < 99 ){
765 mocchiut 1.32 ical = ical+1;
766 mocchiut 1.35 //fg = true;
767 mocchiut 1.32 }
768 mocchiut 1.35 // if ( fg ) ical = ical-1;
769 mocchiut 1.32 if ( ical < 0 || ical >= 98 ){
770     code = -317;
771     goto closeandexit;
772     };
773     if ( verbose ) cout<<"abs time "<<atime<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl;
774     };
775     //==================================================================
776     //== interpolate betwen time limits
777     //==================================================================
778     thelp1 = mtime[ical];
779     thelp2 = mtime[ical+1];
780     for (ii=0; ii<48;ii++) {
781     yhelp1 = dedx_corr_m[ical][ii];
782 mocchiut 1.38 if ( yhelp1 < 0.1 ) yhelp1 = 6.;
783 mocchiut 1.32 yhelp2 = dedx_corr_m[ical+1][ii];
784 mocchiut 1.38 if ( yhelp2 < 0.1 ) yhelp2 = 6.;
785 mocchiut 1.32 slope = (yhelp2-yhelp1)/(thelp2-thelp1);
786     inter = yhelp1 - slope*thelp1;
787     dedx_corr[ii] = slope*atime + inter;
788 mocchiut 1.34 if ( fabs(dedx_corr[ii]) <= 1e-15 ){
789     if ( verbose ) printf("ii %i slope %f atime %u inter %f dedx_corr %f \n",ii,slope,atime,inter,dedx_corr[ii]);
790     if ( verbose ) printf("ical %i yhelp2 %f yhelp1 %f thelp2 %f thelp1 %f \n",ical,yhelp2,yhelp1,thelp2,thelp1);
791 mocchiut 1.32 code = -316;
792     goto closeandexit;
793     };
794     };
795     //================================================================
796     //================================================================
797 mocchiut 1.1 //
798     // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
799 mocchiut 1.32 //
800 mocchiut 1.1 for (Int_t gg=0; gg<4;gg++){
801     for (Int_t hh=0; hh<12;hh++){
802     tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
803     tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh];
804     };
805     };
806 mocchiut 1.32 //
807 mocchiut 1.38 tofdedx->Init(tofEvent);
808     //
809 mocchiut 1.1 for (Int_t hh=0; hh<5;hh++){
810     tofinput_.patterntrig[hh]=trig->patterntrig[hh];
811     };
812     //
813     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
814     //
815 mocchiut 1.4 npmtentry = 0;
816     //
817     ntrkentry = 0;
818 mocchiut 1.1 //
819     // Calculate tracks informations from ToF alone
820     //
821     tofl2com();
822     //
823 mocchiut 1.4 memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
824     //
825     t_tof->trkseqno = -1;
826     //
827 mocchiut 1.1 // and now we must copy from the output structure to the level2 class:
828     //
829 mocchiut 1.4 t_tof->npmttdc = 0;
830     //
831 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
832     for (Int_t kk=0; kk<4;kk++){
833 mocchiut 1.4 if ( tofoutput_.tofmask[hh][kk] != 0 ){
834     pmt_id = tof->GetPMTid(kk,hh);
835     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
836 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
837 mocchiut 1.4 t_tof->npmttdc++;
838     };
839     };
840     };
841     for (Int_t kk=0; kk<13;kk++){
842     t_tof->beta[kk] = tofoutput_.betatof_a[kk];
843 mocchiut 1.1 }
844 mocchiut 1.4 //
845 carbone 1.37
846     //
847     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
848     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
849     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
850     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
851     //
852     {
853     Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]};
854     Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.};
855    
856 mocchiut 1.38 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
857 carbone 1.37 }
858 mocchiut 1.4 t_tof->npmtadc = 0;
859 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
860     for (Int_t kk=0; kk<4;kk++){
861 mocchiut 1.4 pmt_id = tof->GetPMTid(kk,hh);
862 carbone 1.37 if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. ){
863     t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
864 mocchiut 1.4 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
865 carbone 1.37 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
866 mocchiut 1.4 t_tof->npmtadc++;
867     };
868     };
869     };
870 mocchiut 1.20
871     /*
872     cout<<"ToFCore tofl2com"<<endl;
873     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
874     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
875     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;
876     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;
877     */
878    
879    
880 mocchiut 1.4 new(t[ntrkentry]) ToFTrkVar(*t_tof);
881     ntrkentry++;
882     t_tof->Clear();
883     //
884 mocchiut 1.1 //
885     //
886 mocchiut 1.4 t_pmt->Clear();
887 mocchiut 1.1 //
888 mocchiut 1.4 for (Int_t hh=0; hh<12;hh++){
889     for (Int_t kk=0; kk<4;kk++){
890 mocchiut 1.29 // new WM
891     if ( tofoutput_.tdc_c[hh][kk] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofEvent->tdc[kk][hh] < 4095 ){
892 mocchiut 1.4 //
893     t_pmt->pmt_id = tof->GetPMTid(kk,hh);
894     t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
895 mocchiut 1.28 t_pmt->adc = (Float_t)tofEvent->adc[kk][hh];
896     t_pmt->tdc = (Float_t)tofEvent->tdc[kk][hh];
897 mocchiut 1.29 //
898 mocchiut 1.4 new(tpmt[npmtentry]) ToFPMT(*t_pmt);
899     npmtentry++;
900     t_pmt->Clear();
901     };
902     };
903     };
904 mocchiut 1.1 //
905 mocchiut 1.38 if ( debug ) printf(" ATIME %u re %u \n",atime,(UInt_t)re);
906 mocchiut 1.4 // Calculate track-related variables
907 mocchiut 1.1 //
908 mocchiut 1.2 if ( trk->ntrk() > 0 ){
909 mocchiut 1.1 //
910     // We have at least one track
911     //
912     //
913     // Run over tracks
914     //
915     for(Int_t nt=0; nt < trk->ntrk(); nt++){
916     //
917     TrkTrack *ptt = trk->GetStoredTrack(nt);
918     //
919     // Copy the alpha vector in the input structure
920     //
921     for (Int_t e = 0; e < 5 ; e++){
922     tofinput_.al_pp[e] = ptt->al[e];
923     };
924     //
925     // Get tracker related variables for this track
926     //
927     toftrk();
928     //
929     // Copy values in the class from the structure (we need to use a temporary class to store variables).
930     //
931 mocchiut 1.4 t_tof->npmttdc = 0;
932     for (Int_t hh=0; hh<12;hh++){
933     for (Int_t kk=0; kk<4;kk++){
934     if ( tofoutput_.tofmask[hh][kk] != 0 ){
935     pmt_id = tof->GetPMTid(kk,hh);
936     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
937 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
938 mocchiut 1.4 t_tof->npmttdc++;
939     };
940     };
941     };
942 mocchiut 1.1 for (Int_t kk=0; kk<13;kk++){
943 mocchiut 1.4 t_tof->beta[kk] = tofoutput_.beta_a[kk];
944     };
945 carbone 1.37 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
946     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
947     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
948     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
949 mocchiut 1.4 //
950 mocchiut 1.38 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
951 mocchiut 1.4 t_tof->npmtadc = 0;
952 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
953     for (Int_t kk=0; kk<4;kk++){
954 carbone 1.37 pmt_id = tof->GetPMTid(kk,hh);
955 mocchiut 1.38 if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. ){
956 carbone 1.37 t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
957 mocchiut 1.38 if ( debug ) printf(" nt %i npmtadc %i dedx %f dedx corr %f\n",nt,t_tof->npmtadc,(tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),dedx_corr[pmt_id]);
958 mocchiut 1.4 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
959 carbone 1.37 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
960 mocchiut 1.4 t_tof->npmtadc++;
961     };
962 carbone 1.37
963 mocchiut 1.4 };
964     };
965     //
966 mocchiut 1.20
967     /*
968     cout<<"ToFCore toftrk"<<endl;
969     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
970     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
971     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;
972     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;
973     */
974    
975 mocchiut 1.1 //
976     // Store the tracker track number in order to be sure to have shyncronized data during analysis
977     //
978     t_tof->trkseqno = nt;
979     //
980     // create a new object for this event with track-related variables
981     //
982     new(t[ntrkentry]) ToFTrkVar(*t_tof);
983     ntrkentry++;
984 mocchiut 1.4 t_tof->Clear();
985 mocchiut 1.1 //
986     }; // loop on all the tracks
987     };
988     //
989 mocchiut 1.9 tof->unpackError = tofEvent->unpackError;
990 mocchiut 1.22 if ( defcal ){
991     tof->default_calib = 1;
992     } else {
993     tof->default_calib = 0;
994     };
995 mocchiut 1.9 //
996 mocchiut 1.1 // Fill the rootple
997     //
998     toft->Fill();
999     //
1000     //
1001 mocchiut 1.4 //
1002     delete t_tof;
1003     //
1004     //
1005     //
1006 mocchiut 1.1 jumpev:
1007 mocchiut 1.38 if ( !debug ) debug = false;
1008 mocchiut 1.1 //
1009     };
1010 mocchiut 1.6 //
1011     // Here you may want to clear some variables before processing another run
1012     //
1013     delete dbtime;
1014 mocchiut 1.1 }; // process all the runs
1015     //
1016     if ( verbose ) printf("\n Finished processing data \n");
1017     //
1018     closeandexit:
1019     //
1020     // 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.
1021     //
1022     if ( !reprocall && reproc && code >= 0 ){
1023     if ( totfileentries > noaftrun ){
1024     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
1025     if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1026     if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1027     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1028     //
1029     // Get entry from old tree
1030     //
1031     toftclone->GetEntry(j);
1032     //
1033     // copy tofclone to tof
1034     //
1035 mocchiut 1.3 tof->Clear();
1036 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
1037     //
1038     // Fill entry in the new tree
1039     //
1040     toft->Fill();
1041     };
1042     if ( verbose ) printf(" Finished successful copying!\n");
1043     };
1044     };
1045     //
1046     // Close files, delete old tree(s), write and close level2 file
1047     //
1048     if ( l0File ) l0File->Close();
1049     if ( tempfile ) tempfile->Close();
1050 mocchiut 1.25 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1051 mocchiut 1.1 if ( tracker ) tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file!
1052     //
1053     if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
1054     if ( verbose ) printf("\n Writing and closing rootple\n");
1055     if ( runinfo ) runinfo->Close();
1056     if ( toft ) toft->SetName("ToF");
1057     if ( file ){
1058     file->cd();
1059     file->Write("ToF");
1060     };
1061     //
1062 mocchiut 1.25 if ( myfold ) gSystem->Unlink(toffolder.str().c_str());
1063 mocchiut 1.1 //
1064     // the end
1065     //
1066     if ( verbose ) printf("\n Exiting...\n");
1067     if(toft)toft->Delete();
1068 mocchiut 1.5 //
1069     if ( tof ) delete tof;
1070     if ( tofclone ) delete tofclone;
1071 carbone 1.37 if ( tofdedx ) delete tofdedx;
1072 mocchiut 1.5 if ( glroot ) delete glroot;
1073     if ( runinfo ) delete runinfo;
1074     //
1075 mocchiut 1.1 if ( code < 0 ) throw code;
1076     return(code);
1077     }

  ViewVC Help
Powered by ViewVC 1.1.23