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

  ViewVC Help
Powered by ViewVC 1.1.23