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