/[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.56 - (hide annotations) (download)
Thu Aug 28 13:43:46 2014 UTC (10 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.55: +3 -6 lines
More processing/reprocessing bugs fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23