/[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.37 - (hide annotations) (download)
Fri Nov 20 11:05:21 2009 UTC (15 years ago) by carbone
Branch: MAIN
Changes since 1.36: +94 -18 lines
ToF dEdx calibration changed

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     yhelp2 = dedx_corr_m[ical+1][ii];
783     slope = (yhelp2-yhelp1)/(thelp2-thelp1);
784     inter = yhelp1 - slope*thelp1;
785     dedx_corr[ii] = slope*atime + inter;
786 mocchiut 1.34 if ( fabs(dedx_corr[ii]) <= 1e-15 ){
787     if ( verbose ) printf("ii %i slope %f atime %u inter %f dedx_corr %f \n",ii,slope,atime,inter,dedx_corr[ii]);
788     if ( verbose ) printf("ical %i yhelp2 %f yhelp1 %f thelp2 %f thelp1 %f \n",ical,yhelp2,yhelp1,thelp2,thelp1);
789 mocchiut 1.32 code = -316;
790     goto closeandexit;
791     };
792     };
793     //================================================================
794     //================================================================
795 mocchiut 1.1 //
796     // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
797 mocchiut 1.32 //
798 mocchiut 1.1 for (Int_t gg=0; gg<4;gg++){
799     for (Int_t hh=0; hh<12;hh++){
800     tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh];
801     tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh];
802     };
803     };
804 mocchiut 1.32 //
805 mocchiut 1.1 for (Int_t hh=0; hh<5;hh++){
806     tofinput_.patterntrig[hh]=trig->patterntrig[hh];
807     };
808     //
809 carbone 1.37
810    
811    
812    
813    
814    
815    
816    
817    
818    
819    
820    
821 mocchiut 1.1 // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
822     //
823 mocchiut 1.4 npmtentry = 0;
824     //
825     ntrkentry = 0;
826 mocchiut 1.1 //
827     // Calculate tracks informations from ToF alone
828     //
829     tofl2com();
830     //
831 mocchiut 1.4 memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
832     //
833     t_tof->trkseqno = -1;
834     //
835 mocchiut 1.1 // and now we must copy from the output structure to the level2 class:
836     //
837 mocchiut 1.4 t_tof->npmttdc = 0;
838     //
839 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
840     for (Int_t kk=0; kk<4;kk++){
841 mocchiut 1.4 if ( tofoutput_.tofmask[hh][kk] != 0 ){
842     pmt_id = tof->GetPMTid(kk,hh);
843     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
844 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
845 mocchiut 1.4 t_tof->npmttdc++;
846     };
847     };
848     };
849     for (Int_t kk=0; kk<13;kk++){
850     t_tof->beta[kk] = tofoutput_.betatof_a[kk];
851 mocchiut 1.1 }
852 mocchiut 1.4 //
853 carbone 1.37
854     //
855     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
856     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
857     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
858     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
859     //
860     {
861     Float_t xtof_temp[6]={0.,t_tof->xtofpos[0],t_tof->xtofpos[1],0.,0.,t_tof->xtofpos[2]};
862     Float_t ytof_temp[6]={t_tof->ytofpos[0],0.,0.,t_tof->ytofpos[1],t_tof->ytofpos[2],0.};
863    
864     tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp, tofEvent);
865     }
866 mocchiut 1.4 t_tof->npmtadc = 0;
867 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
868     for (Int_t kk=0; kk<4;kk++){
869 mocchiut 1.4 pmt_id = tof->GetPMTid(kk,hh);
870 carbone 1.37 if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. ){
871     t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
872 mocchiut 1.4 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
873 carbone 1.37 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
874 mocchiut 1.4 t_tof->npmtadc++;
875     };
876     };
877     };
878 mocchiut 1.20
879     /*
880     cout<<"ToFCore tofl2com"<<endl;
881     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
882     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
883     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;
884     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;
885     */
886    
887    
888 mocchiut 1.4 new(t[ntrkentry]) ToFTrkVar(*t_tof);
889     ntrkentry++;
890     t_tof->Clear();
891     //
892 mocchiut 1.1 //
893     //
894 mocchiut 1.4 t_pmt->Clear();
895 mocchiut 1.1 //
896 mocchiut 1.4 for (Int_t hh=0; hh<12;hh++){
897     for (Int_t kk=0; kk<4;kk++){
898 mocchiut 1.29 // new WM
899     if ( tofoutput_.tdc_c[hh][kk] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofEvent->tdc[kk][hh] < 4095 ){
900 mocchiut 1.4 //
901     t_pmt->pmt_id = tof->GetPMTid(kk,hh);
902     t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk];
903 mocchiut 1.28 t_pmt->adc = (Float_t)tofEvent->adc[kk][hh];
904     t_pmt->tdc = (Float_t)tofEvent->tdc[kk][hh];
905 mocchiut 1.29 //
906 mocchiut 1.4 new(tpmt[npmtentry]) ToFPMT(*t_pmt);
907     npmtentry++;
908     t_pmt->Clear();
909     };
910     };
911     };
912 mocchiut 1.1 //
913 mocchiut 1.29
914 mocchiut 1.4 // Calculate track-related variables
915 mocchiut 1.1 //
916 mocchiut 1.2 if ( trk->ntrk() > 0 ){
917 mocchiut 1.1 //
918     // We have at least one track
919     //
920     //
921     // Run over tracks
922     //
923     for(Int_t nt=0; nt < trk->ntrk(); nt++){
924     //
925     TrkTrack *ptt = trk->GetStoredTrack(nt);
926     //
927     // Copy the alpha vector in the input structure
928     //
929     for (Int_t e = 0; e < 5 ; e++){
930     tofinput_.al_pp[e] = ptt->al[e];
931     };
932     //
933     // Get tracker related variables for this track
934     //
935     toftrk();
936     //
937     // Copy values in the class from the structure (we need to use a temporary class to store variables).
938     //
939 mocchiut 1.4 t_tof->npmttdc = 0;
940     for (Int_t hh=0; hh<12;hh++){
941     for (Int_t kk=0; kk<4;kk++){
942     if ( tofoutput_.tofmask[hh][kk] != 0 ){
943     pmt_id = tof->GetPMTid(kk,hh);
944     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
945 mocchiut 1.14 t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
946 mocchiut 1.4 t_tof->npmttdc++;
947     };
948     };
949     };
950 mocchiut 1.1 for (Int_t kk=0; kk<13;kk++){
951 mocchiut 1.4 t_tof->beta[kk] = tofoutput_.beta_a[kk];
952     };
953 carbone 1.37 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
954     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
955     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
956     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
957 mocchiut 1.4 //
958 carbone 1.37 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof, tofEvent);
959 mocchiut 1.4 t_tof->npmtadc = 0;
960 mocchiut 1.1 for (Int_t hh=0; hh<12;hh++){
961     for (Int_t kk=0; kk<4;kk++){
962 carbone 1.37 pmt_id = tof->GetPMTid(kk,hh);
963     if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. ){
964     t_tof->dedx.AddAt((tofdedx->GetdEdx_pmt(pmt_id)*36./pow(dedx_corr[pmt_id],2)),t_tof->npmtadc);
965 mocchiut 1.4 t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
966 carbone 1.37 t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
967 mocchiut 1.4 t_tof->npmtadc++;
968     };
969 carbone 1.37
970 mocchiut 1.4 };
971     };
972     //
973 mocchiut 1.20
974     /*
975     cout<<"ToFCore toftrk"<<endl;
976     cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl;
977     cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl;
978     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;
979     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;
980     */
981    
982 mocchiut 1.1 //
983     // Store the tracker track number in order to be sure to have shyncronized data during analysis
984     //
985     t_tof->trkseqno = nt;
986     //
987     // create a new object for this event with track-related variables
988     //
989     new(t[ntrkentry]) ToFTrkVar(*t_tof);
990     ntrkentry++;
991 mocchiut 1.4 t_tof->Clear();
992 mocchiut 1.1 //
993     }; // loop on all the tracks
994     };
995     //
996 mocchiut 1.9 tof->unpackError = tofEvent->unpackError;
997 mocchiut 1.22 if ( defcal ){
998     tof->default_calib = 1;
999     } else {
1000     tof->default_calib = 0;
1001     };
1002 mocchiut 1.9 //
1003 mocchiut 1.1 // Fill the rootple
1004     //
1005     toft->Fill();
1006     //
1007     //
1008 mocchiut 1.4 //
1009     delete t_tof;
1010     //
1011     //
1012     //
1013 mocchiut 1.1 jumpev:
1014     debug = false;
1015     //
1016     };
1017 mocchiut 1.6 //
1018     // Here you may want to clear some variables before processing another run
1019     //
1020     delete dbtime;
1021 mocchiut 1.1 }; // process all the runs
1022     //
1023     if ( verbose ) printf("\n Finished processing data \n");
1024     //
1025     closeandexit:
1026     //
1027     // 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.
1028     //
1029     if ( !reprocall && reproc && code >= 0 ){
1030     if ( totfileentries > noaftrun ){
1031     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
1032     if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1033     if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1034     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1035     //
1036     // Get entry from old tree
1037     //
1038     toftclone->GetEntry(j);
1039     //
1040     // copy tofclone to tof
1041     //
1042 mocchiut 1.3 tof->Clear();
1043 mocchiut 1.1 memcpy(&tof,&tofclone,sizeof(tofclone));
1044     //
1045     // Fill entry in the new tree
1046     //
1047     toft->Fill();
1048     };
1049     if ( verbose ) printf(" Finished successful copying!\n");
1050     };
1051     };
1052     //
1053     // Close files, delete old tree(s), write and close level2 file
1054     //
1055     if ( l0File ) l0File->Close();
1056     if ( tempfile ) tempfile->Close();
1057 mocchiut 1.25 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1058 mocchiut 1.1 if ( tracker ) tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file!
1059     //
1060     if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
1061     if ( verbose ) printf("\n Writing and closing rootple\n");
1062     if ( runinfo ) runinfo->Close();
1063     if ( toft ) toft->SetName("ToF");
1064     if ( file ){
1065     file->cd();
1066     file->Write("ToF");
1067     };
1068     //
1069 mocchiut 1.25 if ( myfold ) gSystem->Unlink(toffolder.str().c_str());
1070 mocchiut 1.1 //
1071     // the end
1072     //
1073     if ( verbose ) printf("\n Exiting...\n");
1074     if(toft)toft->Delete();
1075 mocchiut 1.5 //
1076     if ( tof ) delete tof;
1077     if ( tofclone ) delete tofclone;
1078 carbone 1.37 if ( tofdedx ) delete tofdedx;
1079 mocchiut 1.5 if ( glroot ) delete glroot;
1080     if ( runinfo ) delete runinfo;
1081     //
1082 mocchiut 1.1 if ( code < 0 ) throw code;
1083     return(code);
1084     }

  ViewVC Help
Powered by ViewVC 1.1.23