/[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.55 - (hide annotations) (download)
Thu Aug 28 08:06:50 2014 UTC (10 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.54: +11 -7 lines
Calo and ToF reprocessing bug fixed

1 mocchiut 1.49 // // C/C++ headers //
2 mocchiut 1.1 #include <fstream>
3     #include <string.h>
4 mocchiut 1.32 #include <iomanip>
5 mocchiut 1.1 //
6     // ROOT headers
7     //
8     #include <TTree.h>
9     #include <TClassEdit.h>
10     #include <TObject.h>
11     #include <TList.h>
12 mocchiut 1.6 #include <TArrayI.h>
13 mocchiut 1.1 #include <TSystem.h>
14     #include <TSystemDirectory.h>
15     #include <TString.h>
16     #include <TFile.h>
17     #include <TClass.h>
18     #include <TCanvas.h>
19     #include <TH1.h>
20     #include <TH1F.h>
21     #include <TH2D.h>
22     #include <TLatex.h>
23     #include <TPad.h>
24     #include <TSQLServer.h>
25     #include <TSQLRow.h>
26     #include <TSQLResult.h>
27     #include <TClonesArray.h>
28     //
29 mocchiut 1.16 // RunInfo header
30     //
31     #include <RunInfo.h>
32     //
33 mocchiut 1.1 // YODA headers
34     //
35     #include <PamelaRun.h>
36 mocchiut 1.48 //#include <physics/trigger/TriggerEvent.h>
37 mocchiut 1.1 #include <physics/tof/TofEvent.h>
38     //
39     // This program headers
40     //
41     #include <ToFCore.h>
42     #include <ToFLevel2.h>
43     #include <ToFVerl2.h>
44     //
45     //
46     // Declaration of the core fortran routines
47     //
48     #define tofl2com tofl2com_
49     extern "C" int tofl2com();
50     #define toftrk toftrk_
51     extern "C" int toftrk();
52     #define rdtofcal rdtofcal_
53 mocchiut 1.46 //extern "C" int rdtofcal(char [], int *);
54     extern "C" int rdtofcal(const char *, int *);
55 mocchiut 1.1
56     //
57     // Tracker classes headers and definitions
58     //
59     #include <TrkLevel2.h>
60 mocchiut 1.52 #include <ExtTrack.h> // new tracking code
61 mocchiut 1.1 //
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.51 Bool_t l1only = false;
77     //
78     Bool_t deltree = false;
79     //
80     //
81 mocchiut 1.19 TString processFolder = Form("ToFFolder_%u",run);
82 mocchiut 1.1 if ( ToFargc > 0 ){
83     Int_t i = 0;
84     while ( i < ToFargc ){
85     if ( !strcmp(ToFargv[i],"-processFolder") ) {
86     if ( ToFargc < i+1 ){
87     throw -3;
88     };
89     processFolder = (TString)ToFargv[i+1];
90     i++;
91     };
92 mocchiut 1.20 if ( !strcmp(ToFargv[i],"-v") || !strcmp(ToFargv[i],"--verbose") ) {
93 mocchiut 1.1 verbose = true;
94 mocchiut 1.20 };
95 mocchiut 1.1 if ( !strcmp(ToFargv[i],"-g") || !strcmp(ToFargv[i],"--debug") ) {
96 mocchiut 1.18 verbose = true;
97 mocchiut 1.1 debug = true;
98     };
99 mocchiut 1.51 if ( !strcmp(ToFargv[i],"--level1-only") ) {
100     l1only = true;
101     }
102     if ( !strcmp(ToFargv[i],"--delete-tree") ) {
103     deltree = true;
104     }
105 mocchiut 1.1 i++;
106     };
107     };
108     //
109     //
110     // Output directory is the working directoy.
111     //
112     const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath()));
113     //
114     // Variables for level2
115     //
116     TTree *tracker = 0;
117 mocchiut 1.48 TTree *trigger = 0;
118 mocchiut 1.1 TTree *toft = 0;
119 mocchiut 1.6 UInt_t nevents = 0;
120 mocchiut 1.15 Long64_t maxsize = 10000000000LL;
121     TTree::SetMaxTreeSize(maxsize);
122 mocchiut 1.1 //
123     // variables needed to reprocess data
124     //
125     TString tofversion;
126     ItoRunInfo *runinfo = 0;
127 mocchiut 1.6 TArrayI *runlist = 0;
128 mocchiut 1.1 TTree *toftclone = 0;
129     Bool_t reproc = false;
130     Bool_t reprocall = false;
131     UInt_t nobefrun = 0;
132     UInt_t noaftrun = 0;
133     UInt_t numbofrun = 0;
134     stringstream ftmpname;
135     TString fname;
136 mocchiut 1.6 UInt_t totfileentries = 0;
137     UInt_t idRun = 0;
138 mocchiut 1.1 //
139     // variables needed to handle error signals
140     //
141     Int_t code = 0;
142     Int_t sgnl;
143     //
144     // tof level2 classes
145     //
146     ToFLevel2 *tof = new ToFLevel2();
147     ToFLevel2 *tofclone = new ToFLevel2();
148 carbone 1.37 ToFdEdx *tofdedx = new ToFdEdx();
149 mocchiut 1.1 //
150     // tracker level2 variables
151     //
152     TrkLevel2 *trk = new TrkLevel2();
153 mocchiut 1.6 Int_t nevtrkl2 = 0;
154 mocchiut 1.1 //
155 mocchiut 1.48 // trigger level2 variables
156     //
157     TrigLevel2 *trg = new TrigLevel2();
158     Int_t nevtrgl2 = 0;
159     //
160 mocchiut 1.1 // define variables for opening and reading level0 file
161     //
162     TFile *l0File = 0;
163     TTree *l0tr = 0;
164     TBranch *l0head = 0;
165 mocchiut 1.48 // TBranch *l0trig = 0;
166 mocchiut 1.1 TBranch *l0tof = 0;
167 mocchiut 1.6 pamela::EventHeader *eh = 0;
168     pamela::PscuHeader *ph = 0;
169 mocchiut 1.48 // pamela::trigger::TriggerEvent *trig = 0;
170 mocchiut 1.1 pamela::tof::TofEvent *tofEvent = 0;
171     //
172     // Define other basic variables
173     //
174     UInt_t procev = 0;
175     stringstream file2;
176     stringstream file3;
177     stringstream qy;
178     Int_t itr = -1;
179     Int_t totevent = 0;
180 mocchiut 1.6 UInt_t atime = 0;
181     UInt_t re = 0;
182 mocchiut 1.7 UInt_t jumped = 0;
183 mocchiut 1.1 //
184     // Working filename
185     //
186     TString outputfile;
187     stringstream name;
188     name.str("");
189     name << outdir << "/";
190     //
191     // temporary file and folder
192     //
193     TFile *tempfile = 0;
194     TTree *temptof = 0;
195     stringstream tempname;
196     stringstream toffolder;
197 mocchiut 1.25 Bool_t myfold = false;
198 mocchiut 1.1 tempname.str("");
199     tempname << outdir;
200     tempname << "/" << processFolder.Data();
201     toffolder.str("");
202     toffolder << tempname.str().c_str();
203     tempname << "/toftree_run";
204     tempname << run << ".root";
205 mocchiut 1.36 UInt_t totnorun = 0;
206 mocchiut 1.1 //
207     // variables needed to load magnetic field maps
208     //
209     Int_t ntrkentry = 0;
210 mocchiut 1.4 Int_t npmtentry = 0;
211 mocchiut 1.6 UInt_t tttrkpar1 = 0;
212 mocchiut 1.1 Bool_t trkpar1 = true;
213 mocchiut 1.6 UInt_t tttofpar1 = 0;
214 mocchiut 1.1 Bool_t tofpar1 = true;
215     //
216     // DB classes
217     //
218     GL_ROOT *glroot = new GL_ROOT();
219     GL_PARAM *glparam = new GL_PARAM();
220 mocchiut 1.6 GL_TIMESYNC *dbtime = 0;
221 mocchiut 1.1 //
222     // declaring external output and input structures
223     //
224     extern struct ToFInput tofinput_;
225     extern struct ToFOutput tofoutput_;
226     //
227 mocchiut 1.32 // WM variables perform dE/dx II order corrections
228     //
229 mocchiut 1.48 //Float_t dedx_corr_m[100][48],dedx_corr[48];
230 mocchiut 1.32 Double_t mtime[100],t1,t2,tm;
231 mocchiut 1.48 //Float_t yhelp1,yhelp2,slope,inter,thelp1,thelp2;
232    
233     //RC variables for new dEdx II order correction (10th reduction)
234     Float_t Heyhelp1,Heyhelp2,Heslope,Heinter,thelp1,thelp2;
235     Float_t pyhelp1,pyhelp2,pslope,pinter;
236     Float_t dedx_Hepeak[48],dedx_ppeak[48];
237     Float_t dedx_Hepeak_m[100][48],dedx_ppeak_m[100][48];
238     Float_t inter_dedx[48],slope_dedx[48];
239    
240 mocchiut 1.32 Float_t xmean1,xwidth1;
241     Int_t ical,ii,wj,jj;
242 mocchiut 1.40 Float_t xleft=0;
243     Float_t xright=0;
244     Float_t yleft=0;
245     Float_t yright=0;
246 mocchiut 1.48
247     Int_t warning = 0;
248     int a=0, b=0;
249    
250 mocchiut 1.32 //
251 mocchiut 1.1 // Let's start!
252     //
253     //
254     // 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
255     // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file
256     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
257     //
258 mocchiut 1.6 if ( run == 0 ) reproc = true;
259 mocchiut 1.1 //
260     //
261     // Output file is "outputfile"
262     //
263     if ( !file->IsOpen() ){
264     if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n");
265     throw -301;
266 mocchiut 1.55 }
267    
268     if ( debug ) file->ls();
269 mocchiut 1.51
270 mocchiut 1.1 //
271 mocchiut 1.51 // Delete tree if requested
272 mocchiut 1.1 //
273 mocchiut 1.51 if ( deltree ){
274     TTree *T = (TTree*)file->Get("ToF");
275     if ( T ){
276     if ( verbose ) printf(" ToF - REMOVING ToF TTree \n");
277     T->Delete("all");
278     }
279     }
280    
281 mocchiut 1.1 //
282 mocchiut 1.51 // Does it contain the Tracker tree?
283 mocchiut 1.1 //
284 mocchiut 1.52 //
285     TClonesArray *tcNucleiTrk = NULL;
286     TClonesArray *tcExtNucleiTrk = NULL;
287     TClonesArray *tcExtTrk = NULL;
288     TClonesArray *ttofNucleiTrk = NULL;
289     TClonesArray *ttofExtNucleiTrk = NULL;
290     TClonesArray *ttofExtTrk = NULL;
291     Bool_t hasNucleiTrk = false;
292     Bool_t hasExtNucleiTrk = false;
293     Bool_t hasExtTrk = false;
294 mocchiut 1.51 if ( !l1only ){
295     tracker = (TTree*)file->Get("Tracker");
296     if ( !tracker ) {
297     if ( verbose ) printf(" TOF - ERROR: no tracker tree\n");
298     code = -302;
299     goto closeandexit;
300     }
301     //
302     // get tracker level2 data pointer
303     //
304 mocchiut 1.54 // tracker->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big
305 mocchiut 1.51 tracker->SetBranchAddress("TrkLevel2",&trk);
306     nevtrkl2 = tracker->GetEntries();
307 mocchiut 1.52 //
308     // Look for extended tracking algorithm
309     //
310     if ( verbose ) printf("Look for extended and nuclei tracking algorithms\n");
311     // Nuclei tracking algorithm
312     Int_t checkAlgo = 0;
313     tcNucleiTrk = new TClonesArray("TrkTrack");
314     checkAlgo = tracker->SetBranchAddress("TrackNuclei",&tcNucleiTrk);
315     if ( !checkAlgo ){
316     if ( verbose ) printf(" Nuclei tracking algorithm branch found! :D \n");
317     hasNucleiTrk = true;
318     } else {
319     if ( verbose ) printf(" Nuclei tracking algorithm branch not found :( !\n");
320     printf(" ok, this is not a problem (it depends on tracker settings) \n");
321     delete tcNucleiTrk;
322     }
323     // Nuclei tracking algorithm using calorimeter points
324     tcExtNucleiTrk = new TClonesArray("ExtTrack");
325     checkAlgo = tracker->SetBranchAddress("RecoveredTrackNuclei",&tcExtNucleiTrk);
326     if ( !checkAlgo ){
327     if ( verbose ) printf(" Recovered nuclei tracking algorithm branch found! :D \n");
328     hasExtNucleiTrk = true;
329     } else {
330     if ( verbose ) printf(" Recovered nuclei tracking algorithm branch not found :( !\n");
331     printf(" ok, this is not a problem (it depends on tracker settings) \n");
332     delete tcExtNucleiTrk;
333     }
334     // Tracking algorithm using calorimeter points
335     tcExtTrk = new TClonesArray("ExtTrack");
336     checkAlgo = tracker->SetBranchAddress("RecoveredTrack",&tcExtTrk);
337     if ( !checkAlgo ){
338     if ( verbose ) printf(" Recovered track algorithm branch found! :D \n");
339     hasExtTrk = true;
340     } else {
341     if ( verbose ) printf(" Recovered track algorithm branch not found :( !\n");
342     printf(" ok, this is not a problem (it depends on tracker settings) \n");
343     delete tcExtTrk;
344     }
345 mocchiut 1.51 }
346 mocchiut 1.48 //
347     // Does it contain the Trigger tree?
348     //
349     trigger = (TTree*)file->Get("Trigger");
350     if ( !trigger ) {
351     if ( verbose ) printf(" TOF - ERROR: no trigger tree\n");
352     code = -302;
353     goto closeandexit;
354     };
355     //
356     // get trigger level2 data pointer
357     //
358 mocchiut 1.54 // trigger->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big
359 mocchiut 1.48 trigger->SetBranchAddress("TrigLevel2",&trg);
360     nevtrgl2 = trigger->GetEntries();
361    
362 mocchiut 1.1 //
363     // Retrieve GL_RUN variables from the level2 file
364     //
365     tofversion = ToFInfo(false); // we should decide how to handle versioning system
366     //
367     // create an interface to RunInfo called "runinfo"
368     //
369     // ItoRunInfo= interface with RunInfo and GL_RUN
370     runinfo = new ItoRunInfo(file);
371     //
372     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
373     //
374     sgnl = 0;
375     sgnl = runinfo->Update(run, "TOF",tofversion);
376     if ( sgnl ){
377     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
378     code = sgnl;
379     goto closeandexit;
380     } else {
381     sgnl = 0;
382     };
383     //
384     // number of events in the file BEFORE the first event of our run
385     //
386     nobefrun = runinfo->GetFirstEntry();
387     //
388     // total number of events in the file
389     //
390     totfileentries = runinfo->GetFileEntries();
391     //
392     // first file entry AFTER the last event of our run
393     //
394     noaftrun = runinfo->GetLastEntry() + 1;
395     //
396     // number of run to be processed
397     //
398     numbofrun = runinfo->GetNoRun();
399 mocchiut 1.36 totnorun = runinfo->GetRunEntries();
400 mocchiut 1.1 //
401     // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run
402     //
403     toftclone = (TTree*)file->Get("ToF");
404     //
405     if ( !toftclone ){
406     //
407     // tree does not exist, we are not reprocessing
408     //
409     reproc = false;
410 mocchiut 1.6 if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n");
411     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");
412 mocchiut 1.1
413     } else {
414     //
415     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
416     //
417 mocchiut 1.54 // toftclone->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big
418 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
419 mocchiut 1.1 reproc = true;
420     //
421     // update versioning information
422     //
423     if ( verbose ) printf("\n Preparing the pre-processing...\n");
424     //
425 mocchiut 1.21 if ( run == 0 || totnorun == 1 ){
426 mocchiut 1.1 //
427     // we are reprocessing all the file
428     // 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
429     //
430     reprocall = true;
431     //
432     if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n");
433     //
434     } else {
435     //
436     // 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
437     //
438     reprocall = false;
439     //
440 mocchiut 1.6 if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run);
441 mocchiut 1.1 //
442     // copying old tree to a new file
443     //
444 mocchiut 1.25 gSystem->MakeDirectory(toffolder.str().c_str());
445     myfold = true;
446 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
447     temptof = toftclone->CloneTree(-1,"fast");
448     temptof->SetName("ToF-old");
449     tempfile->Write();
450     tempfile->Close();
451     }
452     //
453     // Delete the old tree from old file and memory
454     //
455     toftclone->Delete("all");
456     //
457     if ( verbose ) printf(" ...done!\n");
458     //
459     };
460     //
461     // create ToF detector tree toft
462     //
463     file->cd();
464     toft = new TTree("ToF-new","PAMELA Level2 ToF data");
465 mocchiut 1.54 // toft->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big
466 mocchiut 1.15 toft->SetAutoSave(900000000000000LL);
467     tof->Set();//ELENA **TEMPORANEO?**
468 mocchiut 1.1 toft->Branch("ToFLevel2","ToFLevel2",&tof);
469     //
470 mocchiut 1.52 // create new branches for new tracking algorithms
471     //
472     if ( hasNucleiTrk ){
473     ttofNucleiTrk = new TClonesArray("ToFTrkVar",1);
474     toft->Branch("TrackNuclei",&ttofNucleiTrk);
475     }
476     if ( hasExtNucleiTrk ){
477     ttofExtNucleiTrk = new TClonesArray("ToFTrkVar",1);
478     toft->Branch("RecoveredTrackNuclei",&ttofExtNucleiTrk);
479     }
480     if ( hasExtTrk ){
481     ttofExtTrk = new TClonesArray("ToFTrkVar",1);
482     toft->Branch("RecoveredTrack",&ttofExtTrk);
483     }
484    
485     //
486 mocchiut 1.1 if ( reproc && !reprocall ){
487     //
488     // open new file and retrieve all tree informations
489     //
490     tempfile = new TFile(tempname.str().c_str(),"READ");
491     toftclone = (TTree*)tempfile->Get("ToF-old");
492 mocchiut 1.54 // toftclone->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big
493 mocchiut 1.15 toftclone->SetAutoSave(900000000000000LL);
494 mocchiut 1.55 toftclone->SetBranchAddress("ToFLevel2",&tofclone); // EM reprocessing bug fixed
495 mocchiut 1.1 //
496     if ( nobefrun > 0 ){
497     if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n");
498 mocchiut 1.6 if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
499 mocchiut 1.1 if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
500     for (UInt_t j = 0; j < nobefrun; j++){
501     //
502 mocchiut 1.42 if ( toftclone->GetEntry(j) <= 0 ) throw -36;
503 mocchiut 1.1 //
504     // copy tofclone to tof
505     //
506 mocchiut 1.3 tof->Clear();
507 mocchiut 1.55 // if ( !l1only ) memcpy(&tof,&tofclone,sizeof(tofclone));
508     memcpy(&tof,&tofclone,sizeof(tofclone));
509 mocchiut 1.1 //
510     // Fill entry in the new tree
511     //
512 mocchiut 1.55 toft->Fill();
513 mocchiut 1.1 //
514     };
515     if ( verbose ) printf(" Finished successful copying!\n");
516     };
517     };
518     //
519     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
520     //
521     runlist = runinfo->GetRunList();
522     //
523     // Loop over the run to be processed
524     //
525     for (UInt_t irun=0; irun < numbofrun; irun++){
526     //
527     // retrieve the first run ID to be processed using the RunInfo list
528     //
529     idRun = runlist->At(irun);
530     if ( verbose ) printf("\n\n\n ####################################################################### \n");
531 mocchiut 1.6 if ( verbose ) printf(" PROCESSING RUN NUMBER %u \n",idRun);
532 mocchiut 1.1 if ( verbose ) printf(" ####################################################################### \n\n\n");
533     //
534 mocchiut 1.6 runinfo->ID_ROOT_L0 = 0;
535 mocchiut 1.1 //
536     // store in the runinfo class the GL_RUN variables for our run
537     //
538     sgnl = 0;
539     sgnl = runinfo->GetRunInfo(idRun);
540     if ( sgnl ){
541     if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n");
542     code = sgnl;
543     goto closeandexit;
544     } else {
545     sgnl = 0;
546     };
547     //
548 mocchiut 1.6 // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0
549 mocchiut 1.1 //
550 mocchiut 1.6 if ( runinfo->ID_ROOT_L0 == 0 ){
551     if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
552 mocchiut 1.1 code = -5;
553     goto closeandexit;
554     };
555     //
556 mocchiut 1.6 // prepare the timesync for the db
557     //
558 mocchiut 1.27 TString host = glt->CGetHost();
559     TString user = glt->CGetUser();
560     TString psw = glt->CGetPsw();
561     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
562     if ( !dbc->IsConnected() ) throw -314;
563 mocchiut 1.28 stringstream myquery;
564     myquery.str("");
565     myquery << "SET time_zone='+0:00'";
566 mocchiut 1.50 delete dbc->Query(myquery.str().c_str());
567 mocchiut 1.6 dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
568     //
569 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
570     //
571 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
572 mocchiut 1.6 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
573 mocchiut 1.1 //
574     ftmpname.str("");
575     ftmpname << glroot->PATH.Data() << "/";
576     ftmpname << glroot->NAME.Data();
577     fname = ftmpname.str().c_str();
578     //
579     // print out informations
580     //
581 mocchiut 1.6 totevent = runinfo->NEVENTS;
582 mocchiut 1.1 if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data());
583 mocchiut 1.6 if ( verbose ) printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
584     if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
585     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);
586 mocchiut 1.1 //
587 mocchiut 1.31 // if ( !totevent ) goto closeandexit;
588 mocchiut 1.30 //
589 mocchiut 1.1 // Open Level0 file
590     //
591 mocchiut 1.50 if ( l0File ) l0File->Close();
592 mocchiut 1.1 l0File = new TFile(fname.Data());
593     if ( !l0File ) {
594     if ( verbose ) printf(" TOF - ERROR: problems opening Level0 file\n");
595     code = -6;
596     goto closeandexit;
597     };
598     l0tr = (TTree*)l0File->Get("Physics");
599     if ( !l0tr ) {
600     if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n");
601     l0File->Close();
602     code = -7;
603     goto closeandexit;
604     };
605     l0head = l0tr->GetBranch("Header");
606     if ( !l0head ) {
607     if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n");
608     l0File->Close();
609     code = -8;
610     goto closeandexit;
611     };
612 mocchiut 1.51 // l0trig = l0tr->GetBranch("Trigger");
613     // if ( !l0trig ) {
614     // if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n");
615     // l0File->Close();
616     // code = -300;
617     // goto closeandexit;
618     // };
619 mocchiut 1.1 l0tof = l0tr->GetBranch("Tof");
620     if ( !l0tof ) {
621     if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n");
622     l0File->Close();
623     code = -303;
624     goto closeandexit;
625     };
626     //
627 mocchiut 1.48 // l0tr->SetBranchAddress("Trigger", &trig);
628 mocchiut 1.1 l0tr->SetBranchAddress("Tof", &tofEvent);
629 mocchiut 1.6 l0tr->SetBranchAddress("Header", &eh);
630 mocchiut 1.1 //
631 mocchiut 1.6 nevents = l0tof->GetEntries();
632 mocchiut 1.1 //
633 mocchiut 1.31 if ( nevents < 1 && totevent ) {
634 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n");
635     l0File->Close();
636     code = -11;
637     goto closeandexit;
638     };
639     //
640 mocchiut 1.31 if ( runinfo->EV_TO > nevents-1 && totevent ) {
641 mocchiut 1.1 if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n");
642     l0File->Close();
643     code = -12;
644     goto closeandexit;
645     };
646     //
647     // Check if we have to load parameter files (or calibration associated to runs and not to events)
648     //
649     // for example let's assume that we could have different magnetic field maps for different runs:
650     //
651 mocchiut 1.51 if ( !l1only ){
652     if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){
653     trkpar1 = false;
654     // read from DB infos about Magnetic filed maps
655     // if ( !dbc->IsConnected() ) throw -314;
656     glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table
657     tttrkpar1 = glparam->TO_TIME;
658     // ----------------------------
659     // Read the magnetic field
660     // ----------------------------
661     if ( verbose ) printf(" Reading magnetic field maps: \n");
662     trk->LoadField(glparam->PATH+glparam->NAME);
663     if ( verbose ) printf("\n");
664     }
665     }
666 mocchiut 1.6 //
667 mocchiut 1.22 // variable to save information about the tof calibration used
668     //
669     Bool_t defcal = true;
670     //
671 mocchiut 1.1 if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){
672     tofpar1 = false;
673     //
674 mocchiut 1.26 // if ( !dbc->IsConnected() ) throw -314;
675 mocchiut 1.6 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table
676 mocchiut 1.1 if ( error<0 ) {
677     code = error;
678     goto closeandexit;
679     };
680     //
681 mocchiut 1.9 if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
682     //
683 mocchiut 1.24 if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false;
684 mocchiut 1.22 //
685 mocchiut 1.1 tttofpar1 = glparam->TO_TIME;
686 mocchiut 1.9 Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length();
687 mocchiut 1.46 // rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
688     rdtofcal((const char *)(glparam->PATH+glparam->NAME).Data(),&nlen);
689 mocchiut 1.20 //
690 mocchiut 1.1 };
691     //
692 carbone 1.37 Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,204,dbc); // parameters stored in DB in GL_PRAM table
693     if ( error<0 ) {
694     code = error;
695     goto closeandexit;
696     };
697     //
698     if ( verbose ) printf(" Reading ToF attenuation parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
699     tofdedx->ReadParAtt((glparam->PATH+glparam->NAME).Data());
700    
701     //
702     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,205,dbc); // parameters stored in DB in GL_PRAM table
703     if ( error<0 ) {
704     code = error;
705     goto closeandexit;
706     };
707     //
708     if ( verbose ) printf(" Reading ToF desaturation on position parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
709     tofdedx->ReadParPos((glparam->PATH+glparam->NAME).Data());
710    
711     //
712     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,206,dbc); // parameters stored in DB in GL_PRAM table
713     if ( error<0 ) {
714     code = error;
715     goto closeandexit;
716     };
717     //
718     if ( verbose ) printf(" Reading ToF BetheBloch parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
719     tofdedx->ReadParBBneg((glparam->PATH+glparam->NAME).Data());
720    
721     //
722     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,207,dbc); // parameters stored in DB in GL_PRAM table
723     if ( error<0 ) {
724     code = error;
725     goto closeandexit;
726     };
727     //
728     if ( verbose ) printf(" Reading ToF Bethe-Bloch parameter file for beta gt1: %s \n",(glparam->PATH+glparam->NAME).Data());
729     tofdedx->ReadParBBpos((glparam->PATH+glparam->NAME).Data());
730    
731     //
732     error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,208,dbc); // parameters stored in DB in GL_PRAM table
733     if ( error<0 ) {
734     code = error;
735     goto closeandexit;
736     };
737     //
738     if ( verbose ) printf(" Reading ToF desaturation on beta parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
739     tofdedx->ReadParDesatBB((glparam->PATH+glparam->NAME).Data());
740    
741    
742     tofdedx->CheckConnectors(runinfo->RUNHEADER_TIME,glparam,dbc);
743    
744     //
745 mocchiut 1.32 // WM reading parameter file for dE/dx II order corrections
746     //
747 mocchiut 1.48 //memset(dedx_corr_m,0,100*48*sizeof(Float_t));
748     //memset(dedx_corr,0,48*sizeof(Float_t));
749     //memset(mtime,0,100*sizeof(Double_t));
750    
751     //
752     // RC reading parameter file for new dE/dx II order correction (10th red)
753     //
754     memset(dedx_Hepeak_m,0,100*48*sizeof(Float_t));
755     memset(dedx_ppeak_m,0,100*48*sizeof(Float_t));
756     memset(dedx_Hepeak,0,48*sizeof(Float_t));
757     memset(dedx_ppeak,0,48*sizeof(Float_t));
758 mocchiut 1.32 memset(mtime,0,100*sizeof(Double_t));
759 mocchiut 1.48
760 mocchiut 1.32 //
761     // Query the DB to get the file
762     //
763 carbone 1.37 error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,203,dbc); // parameters stored in DB in GL_PRAM table
764 mocchiut 1.32 if ( error<0 ) {
765     code = error;
766     goto closeandexit;
767     };
768     //
769     if ( verbose ) printf(" Reading ToF dE/dx II order correction parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
770     //
771     ical=0; // counter set to zero if first-time reading
772     //-----------------------------------------------------------
773     // Here I read the dEdx_korr parameters
774     //-----------------------------------------------------------
775     jj=0;
776     ifstream fin((glparam->PATH+glparam->NAME).Data());
777 mocchiut 1.33 UInt_t window = 200000;
778     Bool_t first = true;
779     Bool_t last = true;
780 mocchiut 1.48 //Float_t sdedx_corr_m[48];
781     //memset(sdedx_corr_m,0,48*sizeof(Float_t));
782    
783     Float_t sdedx_Hepeak_m[48];
784     memset(sdedx_Hepeak_m,0,48*sizeof(Float_t));
785     Float_t sdedx_ppeak_m[48];
786     memset(sdedx_ppeak_m,0,48*sizeof(Float_t));
787    
788 mocchiut 1.33 Double_t stm = 0;
789 mocchiut 1.32 while ( !fin.eof() ){
790 mocchiut 1.33 stm = tm;
791 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
792 mocchiut 1.32 fin>>t1>>tm>>t2;
793 mocchiut 1.55 if ( debug ) cout << setiosflags(ios::fixed) << setw(10) << setprecision(3) << tm << endl;
794 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
795     if ( first ){
796     mtime[jj]=stm;
797     jj++;
798     if ( jj >= 100 ){
799     code = -318;
800     goto closeandexit;
801     };
802     };
803 mocchiut 1.32 mtime[jj]=tm;
804     };
805     for (ii=0; ii<48;ii++){
806     fin>>wj>>xmean1>>xwidth1;
807 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last) ){
808 mocchiut 1.35 if ( first ){
809 mocchiut 1.48 //dedx_corr_m[jj-1][ii]=sdedx_corr_m[ii];
810    
811     dedx_Hepeak_m[jj-1][ii]=sdedx_Hepeak_m[ii];
812     dedx_ppeak_m[jj-1][ii]=sdedx_ppeak_m[ii];
813 mocchiut 1.33 };
814 mocchiut 1.48 //dedx_corr_m[jj][ii]=xmean1;
815    
816     dedx_Hepeak_m[jj][ii]=xmean1;
817     dedx_ppeak_m[jj][ii]=xwidth1;
818 mocchiut 1.32 };
819 mocchiut 1.48 //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
820     sdedx_Hepeak_m[ii]=xmean1;
821     sdedx_ppeak_m[ii]=xwidth1;
822    
823 mocchiut 1.32 };
824 mocchiut 1.33 if ( (tm >= (runinfo->RUNHEADER_TIME-window) && tm <= (runinfo->RUNTRAILER_TIME+window)) || (tm > (runinfo->RUNTRAILER_TIME+window) && last)){
825     if ( first ) first = false;
826     if ( tm > (runinfo->RUNTRAILER_TIME+window) ) last = false;
827 mocchiut 1.32 jj++;
828     };
829     if ( jj >= 100 ){
830     code = -318;
831     goto closeandexit;
832     };
833     };
834     //
835 mocchiut 1.35 fin.close();
836     // this is a possible bug...
837     // Bool_t ff = false;
838     // while ( runinfo->RUNHEADER_TIME > mtime[ical] && ical < 100 ) {
839     // ical = ical+1;
840     // ff = true;
841     // };
842     while ( (mtime[ical] > runinfo->RUNHEADER_TIME || runinfo->RUNHEADER_TIME > mtime[ical+1] ) && ical < 99 ) {
843 mocchiut 1.32 ical = ical+1;
844 mocchiut 1.35 // ff = true;
845 mocchiut 1.32 };
846 mocchiut 1.35 // if ( ff ) ical = ical-1;
847 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;
848     if ( ical < 0 || ical >= 98 ){
849     code = -315;
850     goto closeandexit;
851     };
852     //
853 mocchiut 1.1 // run over all the events of the run
854     //
855     if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n");
856     //
857 mocchiut 1.26 if ( dbc ){
858     dbc->Close();
859 mocchiut 1.27 delete dbc;
860 pam-fi 1.47 dbc = 0;
861 mocchiut 1.26 };
862     //
863 mocchiut 1.7 jumped = 0;
864 mocchiut 1.6 //
865     for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
866 mocchiut 1.51 // for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+100); re++){ // QUIIIIIII
867 mocchiut 1.1 //
868     if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
869     //
870 mocchiut 1.42 if ( l0head->GetEntry(re) <= 0 ) throw -36;
871 mocchiut 1.1 //
872     // absolute time of this event
873     //
874 mocchiut 1.6 ph = eh->GetPscuHeader();
875     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
876 mocchiut 1.4 //
877     tof->Clear();
878     Int_t pmt_id = 0;
879     ToFPMT *t_pmt = new ToFPMT();
880 mocchiut 1.15 if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA
881 mocchiut 1.4 TClonesArray &tpmt = *tof->PMT;
882     ToFTrkVar *t_tof = new ToFTrkVar();
883 mocchiut 1.15 if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA
884 mocchiut 1.4 TClonesArray &t = *tof->ToFTrk;
885     //
886 mocchiut 1.1 // paranoid check
887     //
888 mocchiut 1.32 if ( atime > (runinfo->RUNTRAILER_TIME+1) || atime < (runinfo->RUNHEADER_TIME-1) ) {
889 mocchiut 1.1 if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n");
890 mocchiut 1.7 jumped++;
891 mocchiut 1.1 goto jumpev;
892     };
893     //
894     // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr"
895     //
896     if ( !reprocall ){
897 mocchiut 1.7 itr = nobefrun + (re - runinfo->EV_FROM -jumped);
898 mocchiut 1.1 } else {
899 mocchiut 1.7 itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped);
900 mocchiut 1.1 };
901 mocchiut 1.51 if ( !l1only ){
902     if ( itr > nevtrkl2 ){ // nevtrkl2 tracker entry number
903     if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr);
904     l0File->Close();
905     code = -313;
906     goto closeandexit;
907     }
908     }
909 mocchiut 1.48 if ( itr > nevtrgl2 ){ // nevtrgl2 trigger entry number
910     if ( verbose ) printf(" TOF - ERROR: no trigger events with entry = %i in Level2 file\n",itr);
911     l0File->Close();
912     code = -319;
913     goto closeandexit;
914 mocchiut 1.51 }
915 mocchiut 1.8 //
916 mocchiut 1.52 if ( !l1only ){
917     trk->Clear();
918     //
919     // Clones array must be cleared before going on
920     //
921     if ( hasNucleiTrk ){
922     tcNucleiTrk->Delete();
923     ttofNucleiTrk->Delete();
924     }
925     if ( hasExtNucleiTrk ){
926     tcExtNucleiTrk->Delete();
927     ttofExtNucleiTrk->Delete();
928     }
929     if ( hasExtTrk ){
930     tcExtTrk->Delete();
931     ttofExtTrk->Delete();
932     }
933     }
934 mocchiut 1.48 trg->Clear();
935 mocchiut 1.8 //
936 mocchiut 1.51 if ( !l1only && tracker->GetEntry(itr) <= 0 ) throw -36;
937 mocchiut 1.48 if ( trigger->GetEntry(itr) <= 0 ) throw -36;
938 mocchiut 1.1 ///
939 mocchiut 1.51 //
940     if ( l0tof->GetEntry(re) <= 0 ) throw -36;
941     // if ( l0trig->GetEntry(re) <= 0 ) throw -36;
942     ///
943     //
944     procev++;
945     //
946     // start processing
947     //
948     // dE/dx II order correction: check time limits and interpolate time correction
949     //==================================================================
950     //== if time is outside time limits:
951     //==================================================================
952     if ( atime<mtime[ical] || atime>mtime[ical+1] ){
953     if ( verbose ) cout<<"Checking Time Limits!"<<endl;
954     ical=0;
955     while ( ( mtime[ical] > atime || atime > mtime[ical+1]) && ical < 99 ){
956     ical = ical+1;
957     }
958 mocchiut 1.52 //
959 mocchiut 1.51 if ( ical < 0 || ical >= 98 ){
960     code = -317;
961     goto closeandexit;
962     };
963     if ( verbose ) cout<<"abs time "<<atime<<" limit low "<<mtime[ical]<<" limit up "<<mtime[ical+1]<<" ical "<<ical<<endl;
964     };
965     //==================================================================
966     //== interpolate betwen time limits
967     //==================================================================
968     thelp1 = mtime[ical];
969     thelp2 = mtime[ical+1];
970     for (ii=0; ii<48;ii++) {
971    
972     Heyhelp1 = fabs(dedx_Hepeak_m[ical][ii]);
973     if ( Heyhelp1 < 0.1 ) Heyhelp1 = 4.;
974     Heyhelp2 = fabs(dedx_Hepeak_m[ical+1][ii]);
975     if ( Heyhelp2 < 0.1 ) Heyhelp2 = 4.;
976     Heslope = (Heyhelp2-Heyhelp1)/(thelp2-thelp1);
977     Heinter = Heyhelp1 - Heslope*thelp1;
978     dedx_Hepeak[ii] = Heslope*atime + Heinter;
979    
980     pyhelp1 = fabs(dedx_ppeak_m[ical][ii]);
981     if ( pyhelp1 < 0.1 ) pyhelp1 = 1.;
982     pyhelp2 = fabs(dedx_ppeak_m[ical+1][ii]);
983     if ( pyhelp2 < 0.1 ) pyhelp2 = 1.;
984     pslope = (pyhelp2-pyhelp1)/(thelp2-thelp1);
985     pinter = pyhelp1 - pslope*thelp1;
986     dedx_ppeak[ii] = pslope*atime + pinter;
987    
988     if(dedx_Hepeak[ii]>dedx_ppeak[ii])slope_dedx[ii]=3./(dedx_Hepeak[ii]-dedx_ppeak[ii]);
989     else slope_dedx[ii]=4.;
990     if(dedx_Hepeak[ii]>dedx_ppeak[ii])inter_dedx[ii]=1.-(slope_dedx[ii]*dedx_ppeak[ii]);
991     else inter_dedx[ii]=0.;
992 mocchiut 1.52
993 mocchiut 1.51 if ( fabs(dedx_ppeak[ii]) <= 1e-15 ){
994     if ( verbose ) printf("ii %i pslope %f atime %u pinter %f dedx_ppeak %f \n",ii,pslope,atime,pinter,dedx_ppeak[ii]);
995     if ( verbose ) printf("ical %i pyhelp2 %f pyhelp1 %f thelp2 %f thelp1 %f \n",ical,pyhelp2,pyhelp1,thelp2,thelp1);
996     code = -316;
997     goto closeandexit;
998 mocchiut 1.52 }
999     }
1000 mocchiut 1.51 //================================================================
1001     //================================================================
1002 mocchiut 1.52
1003 mocchiut 1.51 //
1004     // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure
1005     //
1006     for (Int_t gg=0; gg<4;gg++){
1007     for (Int_t hh=0; hh<12;hh++){
1008     tofinput_.tdc[hh][gg] = (0xFFF & tofEvent->tdc[gg][hh]); // exclude warning bits
1009     tofinput_.adc[hh][gg] = (0xFFF & tofEvent->adc[gg][hh]); // exclude warning bits
1010 mocchiut 1.52 }
1011     }
1012 mocchiut 1.51 //
1013     tofdedx->Init(tofEvent);
1014     warning = 0;
1015     //
1016     for (Int_t hh=0; hh<5;hh++){
1017     tofinput_.patterntrig[hh]=trg->patterntrig[hh];
1018     }
1019     //
1020     // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related variables.
1021     //
1022     npmtentry = 0;
1023     //
1024     ntrkentry = 0;
1025     //
1026     // Calculate tracks informations from ToF alone
1027     //
1028     tofl2com();
1029     //
1030     memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t));
1031     //
1032     if ( !l1only ){
1033     //
1034     t_tof->trkseqno = -1;
1035     //
1036     // and now we must copy from the output structure to the level2 class:
1037     //
1038     t_tof->npmttdc = 0;
1039     //
1040     for (Int_t hh=0; hh<12;hh++){
1041     for (Int_t kk=0; kk<4;kk++){
1042     if ( tofoutput_.tofmask[hh][kk] != 0 ){
1043     pmt_id = tof->GetPMTid(kk,hh);
1044     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1045     t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1046     t_tof->npmttdc++;
1047     };
1048     };
1049     };
1050     for (Int_t kk=0; kk<13;kk++){
1051     t_tof->beta[kk] = tofoutput_.betatof_a[kk];
1052     }
1053     //
1054 mocchiut 1.29 //
1055 mocchiut 1.51 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1056     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1057     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1058     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1059     //
1060     {
1061     Float_t xtof_temp[6]={100.,100.,100.,100.,100.,100.};
1062     Float_t ytof_temp[6]={100.,100.,100.,100.,100.,100.};
1063 mocchiut 1.20
1064 mocchiut 1.51 if(t_tof->xtofpos[0]<100. && t_tof->ytofpos[0]<100.){
1065     xtof_temp[1]=t_tof->xtofpos[0];
1066     ytof_temp[0]=t_tof->ytofpos[0];
1067     }else if(t_tof->xtofpos[0]>=100. && t_tof->ytofpos[0]<100.){
1068     ytof_temp[0]=t_tof->ytofpos[0];
1069     tof->GetPaddleGeometry(0,(Int_t)log2(tof->tof_j_flag[0]),xleft, xright, yleft, yright);
1070     xtof_temp[1]=xleft+2.55;
1071     }else if(t_tof->ytofpos[0]>=100. && t_tof->xtofpos[0]<100.){
1072     xtof_temp[1]=t_tof->xtofpos[0];
1073     tof->GetPaddleGeometry(1,(Int_t)log2(tof->tof_j_flag[1]),xleft, xright, yleft, yright);
1074     ytof_temp[0]=yleft+2.75;
1075     }
1076    
1077     if(t_tof->xtofpos[1]<100. && t_tof->ytofpos[1]<100.){
1078     xtof_temp[2]=t_tof->xtofpos[1];
1079     ytof_temp[3]=t_tof->ytofpos[1];
1080     }else if(t_tof->xtofpos[1]>=100. && t_tof->ytofpos[1]<100.){
1081     ytof_temp[3]=t_tof->ytofpos[1];
1082     tof->GetPaddleGeometry(3,(Int_t)log2(tof->tof_j_flag[3]),xleft, xright, yleft, yright);
1083     xtof_temp[2]=xleft+4.5;
1084     }else if(t_tof->ytofpos[1]>=100. && t_tof->xtofpos[1]<100.){
1085     xtof_temp[2]=t_tof->xtofpos[1];
1086     tof->GetPaddleGeometry(2,(Int_t)log2(tof->tof_j_flag[2]),xleft, xright, yleft, yright);
1087     ytof_temp[3]=yleft+3.75;
1088     }
1089    
1090     if(t_tof->xtofpos[2]<100. && t_tof->ytofpos[2]<100.){
1091     xtof_temp[5]=t_tof->xtofpos[2];
1092     ytof_temp[4]=t_tof->ytofpos[2];
1093     }else if(t_tof->xtofpos[2]>=100. && t_tof->ytofpos[2]<100.){
1094     ytof_temp[4]=t_tof->ytofpos[2];
1095     tof->GetPaddleGeometry(4,(Int_t)log2(tof->tof_j_flag[4]),xleft, xright, yleft, yright);
1096     xtof_temp[5]=xleft+3;
1097     }else if(t_tof->ytofpos[2]>=100. && t_tof->xtofpos[2]<100.){
1098     xtof_temp[5]=t_tof->xtofpos[2];
1099     tof->GetPaddleGeometry(5,(Int_t)log2(tof->tof_j_flag[5]),xleft, xright, yleft, yright);
1100     ytof_temp[4]=yleft+2.5;
1101     }
1102 mocchiut 1.52 //
1103 mocchiut 1.51 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)xtof_temp,(Float_t *)ytof_temp);
1104     t_tof->npmtadc = 0;
1105     for (Int_t hh=0; hh<12;hh++){
1106     for (Int_t kk=0; kk<4;kk++){
1107     pmt_id = tof->GetPMTid(kk,hh);
1108     Int_t Iplane=-1;
1109     Int_t Ipaddle=-1;
1110     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1111     tof->GetPaddleGeometry(Iplane,Ipaddle,xleft,xright,yleft,yright);
1112     if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) {
1113     if ( tofdedx->GetdEdx_pmt(pmt_id)>-1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. &&((xtof_temp[Iplane]>=xleft&&xtof_temp[Iplane]<=xright) || (ytof_temp[Iplane]>=yleft&&ytof_temp[Iplane]<=yright)) ){
1114    
1115     t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction
1116    
1117     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1118     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1119     t_tof->npmtadc++;
1120     }
1121     }
1122     }
1123     }
1124     }
1125     new(t[ntrkentry]) ToFTrkVar(*t_tof);
1126     ntrkentry++;
1127     t_tof->Clear();
1128     t_pmt->Clear();
1129     //
1130     for (Int_t gg=0; gg<4;gg++){
1131     for (Int_t hh=0; hh<12;hh++){
1132     // new WM
1133     if ( tofoutput_.tdc_c[hh][gg] < 4095 || (0xFFF & tofEvent->adc[gg][hh]) < 4095 || (0xFFF & tofEvent->tdc[gg][hh]) < 4095 ){
1134     t_pmt->pmt_id = tof->GetPMTid(gg,hh);
1135     t_pmt->tdc_tw = tofoutput_.tdc_c[hh][gg];
1136     t_pmt->adc = (Float_t)(0xFFF & tofEvent->adc[gg][hh]);
1137     t_pmt->tdc = (Float_t)(0xFFF & tofEvent->tdc[gg][hh]);
1138     t_pmt->l0flag_adc = (Float_t)(tofEvent->adc[gg][hh]>>12);
1139     t_pmt->l0flag_tdc = (Float_t)(tofEvent->tdc[gg][hh]>>12);
1140     if ( t_pmt->l0flag_adc || t_pmt->l0flag_tdc ) warning |= 1 << 0;
1141     //
1142     new(tpmt[npmtentry]) ToFPMT(*t_pmt);
1143     npmtentry++;
1144     t_pmt->Clear();
1145 mocchiut 1.52 }
1146     }
1147     }
1148 mocchiut 1.51 //
1149     if ( debug ) printf(" ATIME %u re %u \n",atime,(UInt_t)re);
1150 mocchiut 1.52 //
1151 mocchiut 1.51 // Calculate track-related variables
1152     //
1153 mocchiut 1.52
1154     //
1155     // Run over tracks - standard algorithm
1156     //
1157     for(Int_t nt=0; nt < trk->ntrk(); nt++){
1158     //
1159     TrkTrack *ptt = trk->GetStoredTrack(nt);
1160     //
1161     // Copy the alpha vector in the input structure
1162     //
1163     for (Int_t e = 0; e < 5 ; e++){
1164     tofinput_.al_pp[e] = ptt->al[e];
1165     }
1166     // new input for 9th reduction: tracker dEdx
1167     tofinput_.trkmip = ptt->GetDEDX();
1168     //
1169     // Get tracker related variables for this track
1170     //
1171     toftrk();
1172 mocchiut 1.51 //
1173 mocchiut 1.52 // Copy values in the class from the structure (we need to use a temporary class to store variables).
1174 mocchiut 1.51 //
1175 mocchiut 1.52 t_tof->npmttdc = 0;
1176     for (Int_t hh=0; hh<12;hh++){
1177     for (Int_t kk=0; kk<4;kk++){
1178     if ( tofoutput_.tofmask[hh][kk] != 0 ){
1179     pmt_id = tof->GetPMTid(kk,hh);
1180     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1181     t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1182     t_tof->npmttdc++;
1183     }
1184     }
1185     }
1186     for (Int_t kk=0; kk<13;kk++){
1187     t_tof->beta[kk] = tofoutput_.beta_a[kk];
1188     }
1189     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1190     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1191     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1192     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1193     //
1194     tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
1195     t_tof->npmtadc = 0;
1196     for (Int_t hh=0; hh<12;hh++){
1197     for (Int_t kk=0; kk<4;kk++){
1198     pmt_id = tof->GetPMTid(kk,hh);
1199     Int_t Iplane=-1;
1200     Int_t Ipaddle=-1;
1201     Int_t IpaddleT=-1;
1202     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1203     IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0);
1204     if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,pmt_id,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1205     if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) {
1206     if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. && Ipaddle==IpaddleT ){
1207     t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction
1208     if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1209     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1210     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1211     t_tof->npmtadc++;
1212     }
1213     }
1214     }
1215     }
1216     //
1217     // Store the tracker track number in order to be sure to have shyncronized data during analysis
1218 mocchiut 1.51 //
1219 mocchiut 1.52 t_tof->trkseqno = nt;
1220 mocchiut 1.51 //
1221 mocchiut 1.52 // create a new object for this event with track-related variables
1222     //
1223     new(t[ntrkentry]) ToFTrkVar(*t_tof);
1224     ntrkentry++;
1225     t_tof->Clear();
1226     //
1227     } // loop on all the tracks
1228     //
1229     // Code for extended tracking algorithm:
1230     //
1231     //
1232     // Run over tracks - nuclei algorithm
1233     //
1234     if ( hasNucleiTrk ){
1235     Int_t ttentry = 0;
1236     for(Int_t nt=0; nt < tcNucleiTrk->GetEntries(); nt++){
1237 mocchiut 1.51 //
1238 mocchiut 1.52 TrkTrack *ptt = (TrkTrack*)(tcNucleiTrk->At(nt));
1239 mocchiut 1.51 //
1240     // Copy the alpha vector in the input structure
1241     //
1242     for (Int_t e = 0; e < 5 ; e++){
1243     tofinput_.al_pp[e] = ptt->al[e];
1244 mocchiut 1.52 }
1245     // new input for 9th reduction: tracker dEdx
1246     tofinput_.trkmip = ptt->GetDEDX();
1247     //
1248     // Get tracker related variables for this track
1249     //
1250     toftrk();
1251     //
1252     // Copy values in the class from the structure (we need to use a temporary class to store variables).
1253     //
1254     t_tof->npmttdc = 0;
1255     for (Int_t hh=0; hh<12;hh++){
1256     for (Int_t kk=0; kk<4;kk++){
1257     if ( tofoutput_.tofmask[hh][kk] != 0 ){
1258     pmt_id = tof->GetPMTid(kk,hh);
1259     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1260     t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1261     t_tof->npmttdc++;
1262     }
1263     }
1264     }
1265     for (Int_t kk=0; kk<13;kk++){
1266     t_tof->beta[kk] = tofoutput_.beta_a[kk];
1267     }
1268     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1269     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1270     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1271     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1272     //
1273     tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
1274     t_tof->npmtadc = 0;
1275     for (Int_t hh=0; hh<12;hh++){
1276     for (Int_t kk=0; kk<4;kk++){
1277     pmt_id = tof->GetPMTid(kk,hh);
1278     Int_t Iplane=-1;
1279     Int_t Ipaddle=-1;
1280     Int_t IpaddleT=-1;
1281     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1282     IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0);
1283     if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,pmt_id,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1284     if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) {
1285     if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. && Ipaddle==IpaddleT ){
1286     t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction
1287     if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1288     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1289     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1290     t_tof->npmtadc++;
1291     }
1292     }
1293     }
1294     }
1295     //
1296     // Store the tracker track number in order to be sure to have shyncronized data during analysis
1297     //
1298     t_tof->trkseqno = nt;
1299     //
1300     // create a new object for this event with track-related variables
1301     //
1302     TClonesArray &tt1 = *ttofNucleiTrk;
1303     new(tt1[ttentry]) ToFTrkVar(*t_tof);
1304     ttentry++;
1305     t_tof->Clear();
1306     //
1307     } // loop on all the tracks, nuclei algorithm
1308     }
1309     //
1310     // Run over tracks - extended nuclei algorithm
1311     //
1312     if ( hasExtNucleiTrk ){
1313     Int_t ttentry = 0;
1314     for(Int_t nt=0; nt < tcExtNucleiTrk->GetEntries(); nt++){
1315     //
1316     ExtTrack *ptt = (ExtTrack*)(tcExtNucleiTrk->At(nt));
1317     //
1318     // Copy the alpha vector in the input structure
1319     //
1320     for (Int_t e = 0; e < 5 ; e++){
1321     tofinput_.al_pp[e] = ptt->al[e];
1322     }
1323 mocchiut 1.51 // new input for 9th reduction: tracker dEdx
1324     tofinput_.trkmip = ptt->GetDEDX();
1325     //
1326     // Get tracker related variables for this track
1327     //
1328     toftrk();
1329     //
1330     // Copy values in the class from the structure (we need to use a temporary class to store variables).
1331     //
1332     t_tof->npmttdc = 0;
1333     for (Int_t hh=0; hh<12;hh++){
1334     for (Int_t kk=0; kk<4;kk++){
1335     if ( tofoutput_.tofmask[hh][kk] != 0 ){
1336     pmt_id = tof->GetPMTid(kk,hh);
1337     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1338     t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1339     t_tof->npmttdc++;
1340 mocchiut 1.52 }
1341     }
1342     }
1343 mocchiut 1.51 for (Int_t kk=0; kk<13;kk++){
1344     t_tof->beta[kk] = tofoutput_.beta_a[kk];
1345 mocchiut 1.52 }
1346 mocchiut 1.51 memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1347     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1348     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1349     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1350     //
1351     tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
1352     t_tof->npmtadc = 0;
1353     for (Int_t hh=0; hh<12;hh++){
1354     for (Int_t kk=0; kk<4;kk++){
1355     pmt_id = tof->GetPMTid(kk,hh);
1356     Int_t Iplane=-1;
1357     Int_t Ipaddle=-1;
1358     Int_t IpaddleT=-1;
1359     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1360     IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0);
1361     if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,pmt_id,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1362     if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) {
1363     if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. && Ipaddle==IpaddleT ){
1364     t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction
1365     if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1366     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1367     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1368     t_tof->npmtadc++;
1369 mocchiut 1.52 }
1370     }
1371     }
1372     }
1373     //
1374     // Store the tracker track number in order to be sure to have shyncronized data during analysis
1375     //
1376     t_tof->trkseqno = nt;
1377     //
1378     // create a new object for this event with track-related variables
1379     //
1380     TClonesArray &tt2 = *ttofExtNucleiTrk;
1381     new(tt2[ttentry]) ToFTrkVar(*t_tof);
1382     ttentry++;
1383     t_tof->Clear();
1384     //
1385     } // loop on all the tracks, extended nuclei algorithm
1386     }
1387     //
1388     // Run over tracks - extended algorithm
1389     //
1390     if ( hasExtTrk ){
1391     Int_t ttentry = 0;
1392     for(Int_t nt=0; nt < tcExtTrk->GetEntries(); nt++){
1393     //
1394     ExtTrack *ptt = (ExtTrack*)(tcExtTrk->At(nt));
1395     //
1396     // Copy the alpha vector in the input structure
1397     //
1398     for (Int_t e = 0; e < 5 ; e++){
1399     tofinput_.al_pp[e] = ptt->al[e];
1400     }
1401     // new input for 9th reduction: tracker dEdx
1402     tofinput_.trkmip = ptt->GetDEDX();
1403     //
1404     // Get tracker related variables for this track
1405     //
1406     toftrk();
1407     //
1408     // Copy values in the class from the structure (we need to use a temporary class to store variables).
1409     //
1410     t_tof->npmttdc = 0;
1411     for (Int_t hh=0; hh<12;hh++){
1412     for (Int_t kk=0; kk<4;kk++){
1413     if ( tofoutput_.tofmask[hh][kk] != 0 ){
1414     pmt_id = tof->GetPMTid(kk,hh);
1415     t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc);
1416     t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07
1417     t_tof->npmttdc++;
1418     }
1419     }
1420     }
1421     for (Int_t kk=0; kk<13;kk++){
1422     t_tof->beta[kk] = tofoutput_.beta_a[kk];
1423     }
1424     memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos));
1425     memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos));
1426     memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof));
1427     memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof));
1428 mocchiut 1.51 //
1429 mocchiut 1.52 tofdedx->Process(atime,t_tof->beta[12], (Float_t *)t_tof->xtr_tof,(Float_t *)t_tof->ytr_tof);
1430     t_tof->npmtadc = 0;
1431     for (Int_t hh=0; hh<12;hh++){
1432     for (Int_t kk=0; kk<4;kk++){
1433     pmt_id = tof->GetPMTid(kk,hh);
1434     Int_t Iplane=-1;
1435     Int_t Ipaddle=-1;
1436     Int_t IpaddleT=-1;
1437     tof->GetPMTPaddle(pmt_id, Iplane, Ipaddle);
1438     IpaddleT=tof->GetPaddleIdOfTrack(t_tof->xtr_tof[Iplane],t_tof->ytr_tof[Iplane], Iplane,0.0);
1439     if ( debug ) printf(" 1nt %i pmt_id %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,pmt_id,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1440     if (tofEvent->tdc[kk][hh] < 4095 || tofEvent->adc[kk][hh] < 4095 || tofinput_.tdc[hh][kk] < 4095 || tofinput_.adc[hh][kk] < 4095 ) {
1441     if ( tofdedx->GetdEdx_pmt(pmt_id) > -1. && (inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)) > 0. && Ipaddle==IpaddleT ){
1442     t_tof->dedx.AddAt((inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),t_tof->npmtadc);// RC new dE/dx II order correction
1443     if ( debug ) printf(" 2nt %i npmtadc %i dedx %f dedx slope %f dedx inter %f\n",nt,t_tof->npmtadc,(inter_dedx[pmt_id]+slope_dedx[pmt_id]*tofdedx->GetdEdx_pmt(pmt_id)),inter_dedx[pmt_id],slope_dedx[pmt_id]);
1444     t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc);
1445     t_tof->adcflag.AddAt(0,t_tof->npmtadc); // gf: Jan 09/07
1446     t_tof->npmtadc++;
1447     }
1448     }
1449     }
1450     }
1451 mocchiut 1.51 //
1452     // Store the tracker track number in order to be sure to have shyncronized data during analysis
1453     //
1454     t_tof->trkseqno = nt;
1455     //
1456     // create a new object for this event with track-related variables
1457     //
1458 mocchiut 1.52 TClonesArray &tt3 = *ttofExtTrk;
1459     new(tt3[ttentry]) ToFTrkVar(*t_tof);
1460     ttentry++;
1461 mocchiut 1.51 t_tof->Clear();
1462     //
1463 mocchiut 1.52 } // loop on all the tracks, extended algorithm
1464 mocchiut 1.51 }
1465 mocchiut 1.52
1466 mocchiut 1.51 } // if !l1only
1467     //
1468     tof->unpackError = tofEvent->unpackError;
1469    
1470     a = 0;
1471     b = 0;
1472     if ( !tof->checkPMTpatternPMThit(trg, a, b) ) warning |= 1 << 1;
1473     if ( !tof->checkPMTpmttrig(trg) ) warning |= 1 << 2;
1474     if ( !trg->checkPMTpatterntrig() ) warning |= 1 << 3;
1475     tof->unpackWarning = warning;
1476    
1477     if ( defcal ){
1478     tof->default_calib = 1;
1479     } else {
1480     tof->default_calib = 0;
1481     }
1482     //
1483     // Fill the rootple
1484     //
1485     toft->Fill();
1486     //
1487     //
1488     //
1489     delete t_tof;
1490     //
1491     //
1492     //
1493 mocchiut 1.1 jumpev:
1494 mocchiut 1.51 if ( !debug ) debug = false;
1495     //
1496     }
1497 mocchiut 1.6 //
1498     // Here you may want to clear some variables before processing another run
1499     //
1500     delete dbtime;
1501 mocchiut 1.51 } // process all the runs
1502 mocchiut 1.1 //
1503     if ( verbose ) printf("\n Finished processing data \n");
1504     //
1505     closeandexit:
1506     //
1507     // 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.
1508     //
1509     if ( !reprocall && reproc && code >= 0 ){
1510     if ( totfileentries > noaftrun ){
1511     if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n");
1512     if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1513     if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1514     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1515     //
1516     // Get entry from old tree
1517     //
1518 mocchiut 1.42 if ( toftclone->GetEntry(j) <= 0 ) throw -36;
1519 mocchiut 1.1 //
1520     // copy tofclone to tof
1521     //
1522 mocchiut 1.3 tof->Clear();
1523 mocchiut 1.55 memcpy(&tof,&tofclone,sizeof(tofclone));// EM reprocessing bug fixed
1524 mocchiut 1.1 //
1525     // Fill entry in the new tree
1526     //
1527 mocchiut 1.55 toft->Fill();// EM reprocessing bug fixed
1528 mocchiut 1.1 };
1529     if ( verbose ) printf(" Finished successful copying!\n");
1530     };
1531     };
1532     //
1533     // Close files, delete old tree(s), write and close level2 file
1534     //
1535     if ( l0File ) l0File->Close();
1536     if ( tempfile ) tempfile->Close();
1537 mocchiut 1.25 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1538 mocchiut 1.1 //
1539     if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n");
1540     if ( verbose ) printf("\n Writing and closing rootple\n");
1541     if ( toft ) toft->SetName("ToF");
1542     if ( file ){
1543     file->cd();
1544 mocchiut 1.51 if ( toft ) toft->Write(0, TObject::kOverwrite); // 10RED bug fixed
1545 mocchiut 1.1 };
1546     //
1547 mocchiut 1.25 if ( myfold ) gSystem->Unlink(toffolder.str().c_str());
1548 mocchiut 1.1 //
1549     // the end
1550     //
1551 mocchiut 1.52 if ( tcNucleiTrk ){
1552     tcNucleiTrk->Delete();
1553     delete tcNucleiTrk;
1554     tcNucleiTrk = NULL;
1555     }
1556     if ( tcExtNucleiTrk ){
1557     tcExtNucleiTrk->Delete();
1558     delete tcExtNucleiTrk;
1559     tcExtNucleiTrk = NULL;
1560     }
1561     if ( tcExtTrk ){
1562     tcExtTrk->Delete();
1563     delete tcExtTrk;
1564     tcExtTrk = NULL;
1565     }
1566     //
1567 mocchiut 1.1 if ( verbose ) printf("\n Exiting...\n");
1568 mocchiut 1.5 //
1569 carbone 1.37 if ( tofdedx ) delete tofdedx;
1570 mocchiut 1.5 if ( glroot ) delete glroot;
1571 mocchiut 1.49 if ( glparam ) delete glparam;
1572     if ( runinfo ) runinfo->Close();
1573 mocchiut 1.5 if ( runinfo ) delete runinfo;
1574     //
1575 mocchiut 1.1 if ( code < 0 ) throw code;
1576 mocchiut 1.55 if ( debug ) file->ls();
1577 mocchiut 1.1 return(code);
1578     }

  ViewVC Help
Powered by ViewVC 1.1.23