/[PAMELA software]/DarthVader/TrackerLevel2/src/TrkCore.cpp
ViewVC logotype

Annotation of /DarthVader/TrackerLevel2/src/TrkCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (hide annotations) (download)
Fri Jun 6 11:24:02 2014 UTC (10 years, 6 months ago) by mocchiut
Branch: MAIN
Changes since 1.46: +1 -1 lines
New version, STDOUT under _debug flag, GetDeflection and GetdEdx added to ExtTrack, compilation warnings fixed

1 mocchiut 1.1 /**
2     * \file TrkCore.cpp
3     * \author Elena Vannuccini
4     */
5     // .........................................................
6     // ROOT header files
7     // .........................................................
8     #include <TTree.h>
9     #include <TClassEdit.h>
10     #include <TObject.h>
11     #include <TList.h>
12     #include <TSystem.h>
13     #include <TSystemDirectory.h>
14     #include <TString.h>
15     #include <TFile.h>
16     #include <TClass.h>
17     #include <TCanvas.h>
18     #include <TH1.h>
19     #include <TH1F.h>
20     #include <TH2D.h>
21     #include <TLatex.h>
22     #include <TPad.h>
23     #include <TSQLServer.h>
24     #include <TSQLRow.h>
25     #include <TSQLResult.h>
26 pam-fi 1.11 #include <TBenchmark.h>
27 pam-ts 1.46 #include <TStopwatch.h>
28 pam-fi 1.11
29 mocchiut 1.1 // .........................................................
30     // other general header files
31     // .........................................................
32     #include <fstream>
33     #include <iostream>
34     // .........................................................
35     // files in the inc directory
36     // .........................................................
37     #include <RunInfo.h>
38     #include <GLTables.h>
39     #include <TrkVerl2.h>
40     #include <TrkProcess.h>
41 pam-fi 1.2 //#include <TrkStruct.h>
42 mocchiut 1.1 #include <TrkLevel2.h>
43 pam-fi 1.6 #include <TrkLevel1.h>
44 mocchiut 1.1 #include <TrkLevel0.h>
45 pam-fi 1.15 #include <TrkHough.h>
46 mocchiut 1.1 // .........................................................
47     // YODA header files
48     // .........................................................
49     #include <PamelaRun.h>
50 pam-fi 1.7 //#include <RegistryEvent.h>
51 mocchiut 1.1 #include <physics/tracker/TrackerEvent.h>
52     #include <CalibTrk1Event.h>
53     #include <CalibTrk2Event.h>
54 mocchiut 1.42 //
55 mocchiut 1.43 // Calorimeter level1 class header and definitions
56 mocchiut 1.42 //
57     #include <CaloLevel1.h> //EM
58 mocchiut 1.43 //
59     // ToF level2 class header and definitions
60     //
61     #include <ToFLevel2.h> //EM
62 pam-fi 1.45 //
63     // Extended tracking
64     //
65     #include <ExtTrkingAlg.h> //EV
66 pam-fi 1.2
67 mocchiut 1.1 // .........................................................
68     // namespaces
69     // .........................................................
70     using namespace std;
71     using namespace pamela;
72     // ================================================================================
73     //
74     //
75     // ================================================================================
76     /**
77     * \brief Tracker data reduction routine.
78     *
79     * It performs data reduction LEVEL0->LEVEL1->LEVEL2, producing LEVEL1 and or LEVEL2 output, in ROOT or HBOOK format.
80     * Input parameters:
81     * @param run id of the run to be processed (if run=0 a whole file is reprocessed)
82     * @param dbc pointer to BD server
83     * @param file1 output LEVEL1 file name (null if no LEVEL1 output is required)
84     * @param file2 output LEVEL2 file name (null if no LEVEL2 output is required)
85     * @param standalone (flag to run the program in standalone mode, that is without reading RunInfo)
86     */
87     //short int TrkCore(Int_t run, TSQLServer *dbc, TString file1, TString file2, Bool_t standalone)
88 mocchiut 1.31 //int TrkCore(UInt_t run, TFile *f2, TSQLServer *dbc, int ncustom, char*vcustom[]) // EMILIANO
89     int TrkCore(UInt_t run, TFile *f2, GL_TABLES *glt, int ncustom, char*vcustom[]) // EMILIANO
90 mocchiut 1.1 {
91     // ---------------------------
92     // Define some basic variables
93     // ---------------------------
94    
95 pizzolot 1.36 TString filename = "";
96 pam-fi 1.7 Long64_t nentries = 0LL;
97 pam-fi 1.2
98 mocchiut 1.1 // LEVEL0 input
99     TFile *f0 = 0;
100     TTree *physicsTree = 0;
101     TBranch *b_trk = 0;
102     TBranch *b_header = 0;
103     EventHeader *header = 0;
104     PscuHeader *pscu = 0;
105 pam-fi 1.22 TrkLevel0 *l0_event = new TrkLevel0();
106 mocchiut 1.1 // RunInfo
107     ItoRunInfo *runinfo = 0;
108 pam-fi 1.7 TArrayI *runlist = 0;
109     UInt_t from_run;
110     UInt_t to_run;
111 mocchiut 1.44 // Bool_t reprocessing = false; // EM GCC 4.7
112 mocchiut 1.1 //LEVEL2 output - ROOT
113     TTree *t_level2 = 0;
114     TTree *t_clone = 0;
115     TrkLevel2 *l2_event = new TrkLevel2();
116     TrkLevel2 *l2_clone = new TrkLevel2();
117 pam-ts 1.46 TrkLevel2 *l2_event_nuclei = new TrkLevel2();
118 mocchiut 1.47 // EM TrkLevel2 *l2_clone_nuclei = new TrkLevel2();
119 pam-fi 1.13 //LEVEL1 output - ROOT
120 pam-ts 1.46 TrkLevel1 *l1_event = new TrkLevel1();
121     TrkLevel1 *l1_event_nuclei = new TrkLevel1();
122 pam-fi 1.15 TrkHough *lh_event = new TrkHough();
123 mocchiut 1.42
124 pam-fi 1.45 //Extended tracking:
125     TTree *t_cal = NULL;
126     TTree *t_tof = NULL;
127     ExtTrkingAlg *trkAlg = NULL;
128 pam-ts 1.46 ExtTrkingAlg *trkAlg_nuclei = NULL;
129 pam-fi 1.45 TClonesArray *trk_array = NULL;
130 pam-ts 1.46 TClonesArray *trk_array_nuclei = NULL;
131    
132 pam-fi 1.45 CaloLevel1 *cl1 = NULL;
133     ToFLevel2 *tl2 = NULL;
134 pam-ts 1.46
135     typedef struct {
136    
137     Int_t nTrk;
138     Int_t nTrkNuc;
139     Int_t nTrkExt;
140     Int_t nTrkExtNuc;
141    
142     Int_t nCl;
143     Int_t nClCut;
144    
145     Float_t tTrk;
146     Float_t tTrkExt;
147     Float_t tTrkNuc;
148    
149     } TrkWatch;
150     TrkWatch trkWatch;
151     TTree *tWatch = NULL;
152    
153    
154    
155    
156 mocchiut 1.43 /*
157 mocchiut 1.42 // EM: how to use CaloLevel1 data inside tracker core routine, example:
158     TTree *T = (TTree*)f2->Get("Calorimeter");
159     if ( T ){
160     CaloStrip *cs = new CaloStrip(false);
161     CaloLevel1 *cl1 = new CaloLevel1();
162     T->SetBranchAddress("CaloLevel1",&cl1);
163     //
164     for (Int_t i=0; i < T->GetEntries(); i++){
165     T->GetEntry(i);
166     Bool_t OK = false;
167     Int_t k = 0;
168     Int_t view = 0;
169     Int_t plane = 0;
170     Int_t strip = 0;
171     Float_t mip = 0.;
172     Float_t ene[2][22][96];
173     memset (ene,0,sizeof(Float_t)*2*22*96);
174     //
175     while ( k < cl1->istrip ){
176     mip = cl1->DecodeEstrip(k,view,plane,strip);
177     // if ( view==0 && plane==18 ) mip = 0.; // 9thRED - set to zero signals from plane 18X
178     //
179     ene[view][plane][strip] = mip;
180     k++;
181     };
182     // check 5
183     Float_t totX = 0.;
184     Float_t totY = 0.;
185     Float_t posX = 0.;
186     Float_t posY = 0.;
187     Int_t minYstrip = 100;
188     Int_t maxYstrip = -1;
189     // calculate baricenter strip on first x and y planes
190     for (Int_t j = 0; j<2; j++){
191     for (Int_t i = 0; i<96; i++){
192     totX += ene[0][j][i];
193     totY += ene[1][j][i];
194     if ( j==0 && ene[1][0][i]>0. && i > maxYstrip ) maxYstrip = i;
195     if ( j==0 && ene[1][0][i]>0. && i < minYstrip ) minYstrip = i;
196     posX += (float)i*ene[0][j][i];
197     posY += (float)i*ene[1][j][i];
198     }
199     }
200     //
201     // printf(" totX %f totY %f maxYstrip %i minYstrip %i \n",totX,totY,maxYstrip,minYstrip);
202     Int_t bariX = 0;
203     Int_t bariY = 0;
204     if ( totX>0. && totY > 0.){
205     // printf(" totX %f totY %f \n",totX,totY);
206     posX /= totX;
207     posY /= totY;
208     bariX = (int)(posX);
209     bariY = (int)(posY);
210     Int_t minX = bariX - 10;
211     Int_t maxX = bariX + 10;
212     Int_t minY = bariY - 10;
213     Int_t maxY = bariY + 10;
214     if ( minX < 0 ) minX = 0;
215     if ( minY < 0 ) minY = 0;
216     if ( maxX > 95 ) maxX = 95;
217     if ( maxY > 95 ) maxY = 95;
218     totX = 0.;
219     totY = 0.;
220     Float_t parX = 0.;
221     Float_t parY = 0.;
222    
223     for (Int_t j = 0; j<3; j++){
224     for (Int_t i = 0; i<96; i++){
225     totX += ene[0][j][i];
226    
227    
228     totY += ene[1][j][i];
229     if ( i>=minX && i<=maxX){
230     parX += ene[0][j][i];
231     }
232     if ( i>=minY && i<=maxY){
233     parY += ene[1][j][i];
234     }
235     }
236     }
237     // printf(" bariX %i bariY %i minX %i maxX %i minY %i maxY %i fractionX %f fractionY %f \n",bariX,bariY,minX,maxX,minY,maxY,parX/totX,parY/totY);
238    
239     if ( parX/totX > 0.65 && parY/totY > 0.75 ) OK = true; // less strict cut on the X due to possible bremsstrhalung double showers
240     // if ( OK ) printf(" CHECK5 PASSED\n");
241     }
242    
243     // check 1
244     if ( totY > 0. && abs(maxYstrip-minYstrip)<10 ){
245     posY /= totY;
246     bariY = (int)(posY);
247     Float_t ntotX = 0.;
248     Float_t ntotY = 0.;
249     for (Int_t j = 0; j<2; j++){
250     for (Int_t i = 0; i<96; i++){
251     ntotX += ene[0][j][i];
252     if ( j > 0 ) ntotY += ene[1][j][i];
253     }
254     }
255     if ( ntotX < 0.3 && ntotY < 0.3 ){
256     OK = true;
257     // printf(" CHECK1 PASSED\n");
258     }
259     }
260    
261     if ( OK ){
262     printf("%i: event is good! \n",i);
263     cs->Set(1,0,bariY);
264     printf(" Y0 hit strip coordinates: X %f Y %f Z %f \n",cs->GetX(),cs->GetY(),cs->GetZ());
265     }
266     }
267     T->Delete();
268     }
269     // end EM
270 mocchiut 1.43 // EM: how to use ToF data inside tracker core routine, example:
271     T = (TTree*)f2->Get("ToF");
272     if ( T ){
273     ToFLevel2 *tl2 = new ToFLevel2();
274     T->SetBranchAddress("ToFLevel2",&tl2);
275     //
276     for (Int_t i=0; i < T->GetEntries(); i++){
277     T->GetEntry(i);
278     printf("%i GetPaddleIdOfTrack(-2.4,5.6,2) %i HitPaddle(2,0) %i \n",i,tl2->GetPaddleIdOfTrack(-24.,5.6,2),tl2->HitPaddle(2,0));
279     }
280     T->Delete();
281     }
282     // END EM
283     */
284 mocchiut 1.42
285 mocchiut 1.1 // -----------------------
286     // -----------------------
287     // Handle input parameters
288     // (data)
289     //
290     // - open/create output files, determining the environment root/hbook from the estension
291     // - create the level1/level2 tree+branch/nt-uple
292     // -----------------------
293     // -----------------------
294     TrkProcess *p = new TrkProcess(run,f2);
295 pam-fi 1.26 if( p->HandleCustomPar(ncustom,vcustom) )return(p->ostatus);;
296 pam-fi 1.25 if( TrkParams::VerboseMode() )p->Dump();
297 pam-ts 1.46 // p->Dump();
298 mocchiut 1.1
299     // ===================================
300     // Open/Create level2 output file
301     // ===================================
302     if(p->get2){
303 pam-fi 1.13 //-------------------------------------------
304     // read RunInfo
305     //-------------------------------------------
306     if(!(p->standalone)){
307     // Open "RunInfo" tree and get list of run
308     runinfo = new ItoRunInfo(f2);
309     char *trkversion = TrkInfo(false);
310     int runinfo_error = runinfo->Update(run,"TRK",trkversion);
311     if( runinfo_error ) throw runinfo_error;
312     runlist = runinfo->GetRunList();
313 mocchiut 1.44 // reprocessing = runinfo->IsReprocessing();//????
314 pam-fi 1.25 if(TrkParams::VerboseMode()){
315 pam-fi 1.13 cout << "#events "<< runinfo->GetFileEntries() << endl;// #events in the file
316     cout << "#runs "<< runinfo->GetRunEntries() << endl;// #runs in the file
317     cout << "1-st run "<< runlist->At(0) << endl;
318     cout << "last run "<< runlist->At(runinfo->GetRunEntries()-1) << endl;
319     cout << "1-st event "<< runinfo->GetFirstEntry() << endl;// first event of our run
320     cout << "last event+1 "<< runinfo->GetLastEntry() << endl;// first event AFTER the last event of our run
321 mocchiut 1.44 // cout << "reprocessing "<< runinfo->IsReprocessing() << endl << endl;
322 pam-fi 1.13 };
323     };
324     //-------------------------------------------
325     //
326 pam-ts 1.46 //-------------------------------------------
327 pam-fi 1.13 // Take (if present) the old Tracker tree
328     t_clone = (TTree*)f2->Get("Tracker");
329     if( t_clone != NULL ) t_clone->SetBranchAddress("TrkLevel2",&l2_clone);
330 pam-ts 1.46
331 pam-fi 1.13 // Create NEW Tracker tree
332     t_level2 = new TTree("Tracker","PAMELA tracker level2 data ");
333 pam-fi 1.21 l2_event->Set(); // ****NBNBNBN*****
334 pam-fi 1.13 t_level2->Branch("TrkLevel2","TrkLevel2",&l2_event);
335 pam-ts 1.46
336 pam-fi 1.13 if(p->get1){
337 pam-fi 1.25 if(TrkParams::VerboseMode())cout << endl << "Requested LEVEL1 output" << endl;
338 pam-fi 1.21 l1_event->Set(); // ****NBNBNBN*****
339 pam-fi 1.13 t_level2->Branch("TrkLevel1","TrkLevel1",&l1_event);
340 pam-fi 1.16 }
341     if(p->geth){
342 pam-fi 1.25 if(TrkParams::VerboseMode())cout << endl << "Requested Hough-Transform output" << endl;
343 pam-fi 1.16 t_level2->Branch("TrkHough","TrkHough",&lh_event);
344 pam-fi 1.7 };
345 pam-ts 1.46 if(p->getn){
346     if(TrkParams::VerboseMode())cout << endl << "Requested nuclei-algorythm output" << endl;
347     if(!l2_event_nuclei)l2_event_nuclei = new TrkLevel2();
348     l2_event_nuclei->Set(); // ****NBNBNBN*****
349     t_level2->Branch("TrackNuclei",l2_event_nuclei->GetPointerToTrackArray());
350    
351     }
352     // =========================================================
353     // extended tracking algorythm output
354     // =========================================================
355     if(p->gete){
356     trkAlg = new ExtTrkingAlg(p->extAlgID);// create the algorythm
357     trk_array = trkAlg->GetTrackArray(); // get the track array
358     if(!trk_array)throw -206;
359     t_level2->Branch("RecoveredTrack",trkAlg->GetPointerToTrackArray());// put it in a branch
360     if(p->getn){
361     if(TrkParams::VerboseMode())cout << endl << "Requested nuclei-algorythm output" << endl;
362     trkAlg_nuclei = new ExtTrkingAlg(p->extAlgID);// create the algorythm for nuclei
363     trk_array_nuclei = trkAlg_nuclei->GetTrackArray();// get the track array
364     if(!trk_array_nuclei)throw -206;
365     t_level2->Branch("RecoveredTrackNuclei",trkAlg_nuclei->GetPointerToTrackArray()); // put it in a branch
366     }
367     //
368     // calorimeter and tof tree
369     //
370     t_cal = (TTree*)f2->Get("Calorimeter");
371     if(!t_cal)throw -206;
372     cl1 = new CaloLevel1();
373     t_cal->SetBranchAddress("CaloLevel1",&cl1);
374    
375    
376     t_tof = (TTree*)f2->Get("ToF");
377     if(!t_tof)throw -206;
378     tl2 = new ToFLevel2();
379     t_tof->SetBranchAddress("ToFLevel2",&tl2);
380    
381     }
382     if(p->watch){
383    
384     // f2->cd();
385     tWatch = new TTree("TrkWatch"," Tracking timing info");
386    
387     tWatch->Branch("nCl",&trkWatch.nCl,"nCl/I");
388     tWatch->Branch("nClCut",&trkWatch.nClCut,"nClCut/I");
389    
390     tWatch->Branch("nTrk",&trkWatch.nTrk,"nTrk/I");
391     tWatch->Branch("nTrkExt",&trkWatch.nTrkExt,"nTrkExt/I");
392     tWatch->Branch("nTrkNuc",&trkWatch.nTrkNuc,"nTrkNuc/I");
393     tWatch->Branch("nTrkExtNuc",&trkWatch.nTrkExtNuc,"nTrkExtExt/I");
394    
395     tWatch->Branch("tTrk",&trkWatch.tTrk,"tTrk/F");
396     tWatch->Branch("tTrkExt",&trkWatch.tTrkExt,"tTrkExt/F");
397     tWatch->Branch("tTrkNuc",&trkWatch.tTrkNuc,"tTrkNuc/F");
398    
399    
400     }
401    
402    
403    
404    
405 pam-fi 1.13 };
406 pam-fi 1.45
407 pam-ts 1.46
408 pam-fi 1.45
409 mocchiut 1.1
410     // -------------------------------------------
411     // define runs to be processed/reprocessed
412     // -------------------------------------------
413     if(run == 0){
414 pam-fi 1.13 // reprocessing ALL runs
415     if(p->standalone)throw -298; // reprocessing not implemented
416     from_run = runlist->At(0);
417     to_run = runlist->At(runinfo->GetRunEntries()-1);
418 mocchiut 1.1 }else{
419     // processing/reprocessing ONE single run
420 pam-fi 1.13 from_run = run;
421     to_run = run;
422 mocchiut 1.1 };
423    
424     //
425     // init event counter
426     //
427     Int_t ev_count =0;
428     //
429     // create query-results objects
430     //
431 pam-fi 1.7 GL_RUN q1 = GL_RUN();
432 mocchiut 1.1 GL_TRK_CALIB q2 = GL_TRK_CALIB();
433     GL_ROOT q3 = GL_ROOT();
434     GL_PARAM q4 = GL_PARAM();
435    
436     // ------------------------------------------------------------
437     // if reprocessing one run, copy all the events BEFORE the run
438     // ------------------------------------------------------------
439     if( !(p->standalone) ){
440 pam-fi 1.13 for(UInt_t i=0; i<runinfo->GetFirstEntry(); i++){
441 mocchiut 1.37 if ( t_clone->GetEntry(i) <= 0 ) throw -36;// EM
442 pam-ts 1.46 // COPY COPY COPY
443 pam-fi 1.13 *l2_event = *l2_clone;
444     t_level2->Fill();
445     l2_event->Clear();
446     };
447 mocchiut 1.1 };
448     // ------------------------------------------------------------
449     // ------------------------------------------------------------
450 pam-fi 1.25 // START LOOP OVER RUNS TO PROCESS/REPROCESS
451 mocchiut 1.1 // ------------------------------------------------------------
452     // ------------------------------------------------------------
453 pam-fi 1.7 for(UInt_t idRun = from_run; idRun <= to_run; idRun++){
454 mocchiut 1.1
455 pam-fi 1.25 if(TrkParams::VerboseMode()) cout << endl<<" ========================= Run: "<< idRun << endl;
456 pam-fi 1.7 UInt_t runheadtime = 0;
457     UInt_t runtrailtime = 0;
458 pam-fi 1.32 UInt_t runheadobt = 0;
459     UInt_t runtrailobt = 0;
460 mocchiut 1.41 UInt_t abstime = 0;
461 mocchiut 1.1 UInt_t evfrom = 0;
462     UInt_t evto = 0;
463 pam-fi 1.7 UInt_t nevents = 0;
464     Int_t id_root_l0 =-1;
465 mocchiut 1.1 Int_t trk_calib_used = 0;
466 pam-fi 1.7
467 mocchiut 1.31 TString host = glt->CGetHost(); // EMILIANO
468     TString user = glt->CGetUser(); // EMILIANO
469     TString psw = glt->CGetPsw(); // EMILIANO
470     // TString host = "mysql://localhost/pamelaprod";
471     // TString user = "anonymous";
472     // TString psw = "";
473     // const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
474     // const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
475     // const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
476     // if ( !pamdbhost ) pamdbhost = "";
477     // if ( !pamdbuser ) pamdbuser = "";
478     // if ( !pamdbpsw ) pamdbpsw = "";
479     // if ( strcmp(pamdbhost,"") ) host = pamdbhost;
480     // if ( strcmp(pamdbuser,"") ) user = pamdbuser;
481     // if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
482 mocchiut 1.29 TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
483 mocchiut 1.31 stringstream myquery; // EMILIANO
484     myquery.str(""); // EMILIANO
485     myquery << "SET time_zone='+0:00'"; // EMILIANO
486 mocchiut 1.39 delete dbc->Query(myquery.str().c_str()); // EMILIANO
487 mocchiut 1.1 if(p->standalone){
488     // ==============================
489     // first query: retrieve run info
490     // ==============================
491 pam-fi 1.7 if (q1.Query_GL_RUN(idRun,dbc) )throw -50;
492     id_root_l0 = q1.ID_ROOT_L0;
493 mocchiut 1.1 runheadtime = q1.RUNHEADER_TIME;
494     runtrailtime = q1.RUNTRAILER_TIME;
495 pam-fi 1.32 runheadobt = q1.RUNHEADER_OBT;
496     runtrailobt = q1.RUNTRAILER_OBT;
497 pam-fi 1.7 evfrom = q1.EV_FROM;
498     evto = q1.EV_TO;
499 pam-fi 1.13 nevents = q1.NEVENTS;
500     trk_calib_used = q1.TRK_CALIB_USED;
501 mocchiut 1.1 }else{
502     // ==============================
503     // get run info from RunInfo tree
504     // ==============================
505 pam-fi 1.3 int runinfo_error = runinfo->GetRunInfo(idRun);
506 pam-fi 1.7 if( runinfo_error ) throw runinfo_error;
507     id_root_l0 = runinfo->ID_ROOT_L0;
508 mocchiut 1.1 runheadtime = runinfo->RUNHEADER_TIME;
509     runtrailtime = runinfo->RUNTRAILER_TIME;
510 pam-fi 1.32 runheadobt = runinfo->RUNHEADER_OBT;
511     runtrailobt = runinfo->RUNTRAILER_OBT;
512 pam-fi 1.7 evfrom = runinfo->EV_FROM;
513     evto = runinfo->EV_TO;
514 pam-fi 1.13 nevents = runinfo->NEVENTS;
515     trk_calib_used = runinfo->TRK_CALIB_USED;
516 pam-fi 1.24
517 mocchiut 1.1 };
518 pam-fi 1.24
519 mocchiut 1.1 //
520 pam-fi 1.25 if(TrkParams::VerboseMode()){
521 pam-fi 1.7 cout << "ROOT file ID "<< id_root_l0 << endl;
522 mocchiut 1.1 cout << "RunHeader time "<< runheadtime << endl;
523     cout << "RunTrailer time "<< runtrailtime << endl;
524 pam-fi 1.7 cout << " from event "<< evfrom << endl;
525     cout << " to event "<< evto << endl;
526 pam-fi 1.24 cout << " num. events "<< nevents << endl;
527     cout << "trk-calibration used "<< trk_calib_used << endl;
528 mocchiut 1.1 };
529     // ========================================================
530     // second query: search the LEVEL0 file that contains idRun
531     // ========================================================
532     TString lastfilename = filename;
533 pam-fi 1.7 if( q3.Query_GL_ROOT(id_root_l0,dbc) )throw -51;
534 mocchiut 1.1 filename = q3.PATH + q3.NAME;
535     // ========================================================
536     // Open the input LEVEL0 data file
537     // ========================================================
538     if(filename.CompareTo(lastfilename)){
539     if(!lastfilename.IsNull())f0->Close();
540     //if( debug ) cout << "Opening LEVEL0 file: "<< filename << endl;
541 pam-fi 1.25 if(TrkParams::VerboseMode()) cout << "Opening LEVEL0 file: "<< filename << endl;
542 pam-fi 1.2 FileStat_t t;
543     if( gSystem->GetPathInfo(filename.Data(),t) )throw -6;
544 mocchiut 1.39 if ( f0 ) f0->Close();
545 mocchiut 1.1 f0 = new TFile(filename);
546     if ( !f0 ) throw -6;
547     physicsTree = (TTree*)f0->Get("Physics"); if(!physicsTree) throw -7;
548     b_header = physicsTree ->GetBranch("Header"); if(!b_header ) throw -8;
549     b_trk = physicsTree ->GetBranch("Tracker"); if(!b_trk ) throw -203;
550 pam-fi 1.22 l0_event->Set();
551     physicsTree->SetBranchAddress("Tracker" ,l0_event->GetPointerToTrackerEvent());
552 mocchiut 1.1 physicsTree->SetBranchAddress("Header",&header);
553    
554 pam-fi 1.7 nentries = physicsTree->GetEntries();
555 mocchiut 1.34 if ( nentries < 1 && nevents ) throw -11; // EMILIANO: go on if the file is empty, why not? in principle we should not have any event to process but if the case the next line will take care of exiting; exit only if the file is empty but nevents is not zero
556 mocchiut 1.33 if ( nentries < (evto+1) && nevents > 0 ) throw -12; // EMILIANO: if NEVENTS = 0 and the file is empty everything is ok but due to a mistake in the
557     // variable EV_TO type (UInt_t instead of Int_t) that we don't want to change to avoid changing a lot of code, evto becomes inf hence
558     // the condition ( nentries < (evto+1) ) is satisfied and DV exit with error even if the error is only in the DB.
559 pam-fi 1.7
560 mocchiut 1.1 };
561    
562 pam-fi 1.7 GL_TIMESYNC *dbtime = new GL_TIMESYNC(id_root_l0,"ID",dbc);
563    
564 pam-fi 1.24
565     // =============================================================
566     // retrieve information about parameters to process LEVEL2
567     // =============================================================
568    
569 mocchiut 1.41 TrkParams::Set(runinfo->GetGL_RUN(),dbc);
570     for(int i=0; i<p->npar; i++){
571     if(TrkParams::VerboseMode())cout<<" ((( force parameters from input path )))"<<endl;
572     TrkParams::Set(p->parpath[i],p->partype[i]);
573     }
574 pam-fi 1.25
575 mocchiut 1.41 TrkParams::Load();
576     if( !TrkParams::IsLoaded() )throw -52;
577 pam-fi 1.24
578     // =============================================================
579     // retrieve calibration file needed to reduce data
580     // =============================================================
581    
582     TrkParams::SetCalib(runinfo->GetGL_RUN(),dbc);
583     TrkParams::LoadCalib( );
584     if( !TrkParams::CalibIsLoaded() )throw -53;
585    
586 pam-fi 1.11 TBenchmark *reduction = new TBenchmark();
587 pam-fi 1.25 if(TrkParams::VerboseMode())reduction->Start("reduction");
588 pam-fi 1.11 Int_t ntrk=0;
589 mocchiut 1.1 // ====================================================
590     // start looping on events cointained in the data file
591     // ====================================================
592 mocchiut 1.41 if ( TrkParams::GetSimuFlag() ){
593     abstime = runheadtime;
594     } else {
595     if(dbc){
596     dbc->Close();
597     delete dbc;
598     }
599     }
600    
601 pam-fi 1.32 for (UInt_t re = evfrom+min(p->nskip,nevents); re < evfrom+nevents; re++){
602 mocchiut 1.1
603     ev_count++;
604 pam-fi 1.32
605 pam-fi 1.45 //
606     // NBNB check if events are aligned!!!!!!!!!!!
607     //
608    
609    
610     if(p->gete){
611     int iev = 0;
612     int jumped = 0;
613     iev = runinfo->GetFirstEntry() + (re - evfrom -jumped);
614     if ( t_cal->GetEntry(iev) <= 0 ) throw -36;//EV
615     if ( t_tof->GetEntry(iev) <= 0 ) throw -36;//EV
616     }
617    
618 pam-fi 1.25 // if ( TrkParams::DebugMode() && re%100 == 0 && re > 0 ) cout << ".";
619 mocchiut 1.1
620 mocchiut 1.37 if ( b_trk->GetEntry(re) <= 0 ) throw -36;//EM
621     if ( b_header->GetEntry(re) <= 0 ) throw -36;//EM
622 pam-fi 1.13 pscu = header->GetPscuHeader();
623 mocchiut 1.41
624     // =============================================================
625     // The following 6 lines have been moved here by VALERIO.
626     if(TrkParams::GetSimuFlag()){
627     abstime = runheadtime + (int) floor(0.03*(re-evfrom)); //If simulated data we need to assign a fake abstime. 30ms between each event.
628     if(TrkParams::VerboseMode())cout << "Event: " << re-evfrom << " - Attempting to retrieve Mask Info for abstime=" << abstime << endl;
629     if(!TrkParams::Set(runinfo->GetGL_RUN(),dbc,6,abstime))throw -52; // Setting to load mask (VALERIO)
630     TrkParams::Load(6);
631     if( !TrkParams::IsLoaded() )throw -52;
632     if(TrkParams::VerboseMode())cout << "Mask Info for abstime=" << abstime << " retrieved" << endl;
633     }
634    
635 pam-fi 1.25 if( TrkParams::DebugMode() )cout << ">>> "<<ev_count-1<<" @ OBT "<<pscu->GetOrbitalTime()<<endl;
636 pam-fi 1.23
637 mocchiut 1.35 if ( dbtime->DBabsTime(pscu->GetOrbitalTime()) > (runtrailtime+1) || dbtime->DBabsTime(pscu->GetOrbitalTime()) < (runheadtime-1)) {
638 pam-fi 1.7
639 pam-fi 1.25 if (TrkParams::VerboseMode()){
640 pam-fi 1.14 printf(" TrkCore - WARNING: event outside the run time window, skipping it\n");
641 pam-fi 1.32 cout << " OBT "<<pscu->GetOrbitalTime()<<" RUN "<<runheadobt<<"-"<<runtrailobt<<" ABS-time "<<dbtime->DBabsTime(pscu->GetOrbitalTime())<<" RUN "<<runheadtime<<"-"<<runtrailtime<<endl;
642 pam-fi 1.14 };
643 pam-fi 1.13 }else{
644 pam-fi 1.25 if ( TrkParams::DebugMode() )
645 pam-fi 1.23 printf("\n-------------------------------\nevent %d\n",re-evfrom);
646 pam-fi 1.16
647 pam-ts 1.46 //=============================================
648     // EVENT PROCESSING
649     //=============================================
650     TStopwatch w;
651     // cout << " START --------------------------------------------------------------------------"<<endl;
652     w.Start();
653    
654     // ------------------
655     // default tracking
656     // ------------------
657     p->ProcessEvent(l0_event);//call f77 routine
658    
659     w.Stop();
660     // cout << " STOP default "<<w.CpuTime()<<" s"<<endl;
661     trkWatch.tTrk = (float) w.CpuTime();
662 pam-fi 1.7
663 pam-fi 1.13 // ----------------
664     // HOUGH output
665     // ----------------
666     if(p->geth){
667     if(p->ifrooth){ // root
668 pam-fi 1.23 lh_event->Delete();
669     lh_event->SetFromHoughStruct(&houghevent_);
670 pam-fi 1.13 }else{ // hbook
671     throw -299;
672     };
673     };
674 pam-ts 1.46
675     // // ----------------
676     // // LEVEL2 output
677     // // ----------------
678     l2_event->Clear();
679     if(p->get1){
680     l2_event->SetFromLevel2Struct(&level2event_,l1_event);//set references to level1
681     }else{
682     l2_event->SetFromLevel2Struct(&level2event_);
683     }
684    
685     if( l2_event->ntrk()>0 )ntrk++;
686     if(TrkParams::VerboseMode())l2_event->Dump();
687    
688     w.Start();
689    
690 pam-fi 1.45 // ------------------
691     // extended-tracking
692     // ------------------
693     if(p->gete){
694 pam-ts 1.46
695    
696     l1_event->Clear();
697     l1_event->SetFromLevel1Struct(true);
698    
699     trkAlg->Clear();
700    
701     //----------------------------
702     // check conditions
703     //----------------------------
704     if(
705     l2_event->ntrk()==0 &&
706     l1_event->nclstr()<24 &&
707     true){
708    
709    
710     trkAlg->SetDebug(false);
711     trkAlg->SetTrkLevel2(l2_event);
712     trkAlg->SetTrkLevel1(l1_event);
713     trkAlg->SetCaloLevel1(cl1);
714     trkAlg->SetToFLevel2(tl2);
715     // trkAlg->Dump();
716     trkAlg->ProcessEvent();
717    
718     }
719     }
720    
721     w.Stop();
722     // cout << " STOP extended "<<w.CpuTime()<<" s"<<endl;
723     trkWatch.tTrkExt = (float) w.CpuTime();
724    
725    
726     w.Start();
727     if(p->getn){
728    
729     l1_event_nuclei->Set(l1_event,5.,0.2);//apply a cut
730     l1_event_nuclei->GetLevel1Struct();//from cleaned l1 object, to f77 common
731     l1_event_nuclei->ProcessEvent(); // default routine
732     l2_event_nuclei->SetFromLevel2Struct(); // from f77 common to l2 object
733    
734     trkAlg_nuclei->Clear();
735    
736     if(p->gete){
737    
738     if(
739     l2_event_nuclei->ntrk()==0 &&
740     l1_event_nuclei->nclstr()<24 &&
741     true){
742    
743     trkAlg_nuclei->SetDebug(false);
744     trkAlg_nuclei->SetTrkLevel2( l2_event_nuclei );
745     trkAlg_nuclei->SetTrkLevel1( l1_event_nuclei );//cleaned level1
746     trkAlg_nuclei->SetCaloLevel1( cl1 );
747     trkAlg_nuclei->SetToFLevel2( tl2 );
748     trkAlg_nuclei->ProcessEvent();
749     }
750     }
751     }
752    
753     w.Stop();
754     // cout << " STOP nuclei "<<w.CpuTime()<<" s"<<endl;
755     trkWatch.tTrkNuc = (float) w.CpuTime();
756 pam-fi 1.45
757 pam-ts 1.46 // ----------------
758     // LEVEL1 output
759     // ----------------
760    
761     if(p->get1 ){
762     l1_event->Clear();
763     l1_event->SetFromLevel1Struct(p->full1);//get l1 object from f77 common
764     }
765 pam-fi 1.45
766 pam-ts 1.46 trkWatch.nCl = l1_event->nclstr();
767     trkWatch.nClCut = l1_event_nuclei->nclstr();
768 pam-fi 1.45
769 pam-ts 1.46 trkWatch.nTrk = l2_event->GetNTracks();
770     trkWatch.nTrkNuc = l2_event_nuclei->GetNTracks();
771 pam-fi 1.45
772 pam-ts 1.46 trkWatch.nTrkExt = ( trkAlg ? trkAlg->GetTrackArray()->GetEntries() : 0);
773     trkWatch.nTrkExtNuc = ( trkAlg_nuclei ? trkAlg_nuclei->GetTrackArray()->GetEntries() : 0);
774    
775    
776     /////////////////////
777     // ==== FILL ===== //
778     /////////////////////
779     // cout << " FILL "<<endl;
780     t_level2->Fill();
781    
782     if(tWatch)tWatch->Fill();
783 pam-fi 1.45
784 pam-fi 1.13 };
785 mocchiut 1.1 }; // end loop on events
786 pam-fi 1.25 if(TrkParams::VerboseMode()){
787 pam-fi 1.13 cout << " >>> processed "<< ev_count <<" events"<< endl;
788     if(ev_count)cout << ntrk << " events with at least one track ("<<(Int_t)(100*ntrk/ev_count)<<"%)\n";
789     reduction->Show("reduction");
790 pam-fi 1.11 }
791     delete reduction;
792 pam-fi 1.7
793     delete dbtime;
794    
795 pam-fi 1.13 }; // end loop on runs
796    
797    
798 mocchiut 1.1 // ------------------------------------------------------------
799     // if reprocessing one run, copy all the events AFTER the run
800     // ------------------------------------------------------------
801     if( !(p->standalone) ){
802     for(UInt_t i=runinfo->GetLastEntry()+1; i<runinfo->GetFileEntries(); i++){
803 mocchiut 1.37 if ( t_clone->GetEntry(i) <= 0 ) throw -36;//EM
804 mocchiut 1.1 *l2_event = *l2_clone;
805 pam-ts 1.46 // COPY COPY COPY
806 mocchiut 1.1 t_level2->Fill();
807     l2_event->Clear();
808     };
809     };
810     // ---------------
811     // close the files
812     // ---------------
813     if(p->get2){
814 pam-ts 1.46 f2->cd();
815     // if(tWatch){
816     // if(tWatch)f2->Write("TrkWatch",TObject::kOverwrite);
817     // }
818     // f2->Write("Tracker", TObject::kOverwrite);
819     if( t_level2 )t_level2->Write();
820     if( t_level2 )t_level2->Delete(); //delete new tree from memory
821    
822 mocchiut 1.40 if( t_clone )t_clone->Delete("all");//delete old tree from file
823 pam-fi 1.13 if( !(p->standalone) )runinfo->Close();
824 pam-ts 1.46 if(tWatch)tWatch->Write();
825 pam-fi 1.13
826     };
827 pam-ts 1.46
828 pam-fi 1.45
829 pam-fi 1.24 if(f0) if(f0->IsOpen()) f0->Close();
830 pam-ts 1.46
831 pam-fi 1.13 l1_event->Delete();
832     l2_event->Delete();
833     l2_clone->Delete();
834 pam-fi 1.2
835 pam-fi 1.45
836 pam-fi 1.2 return(p->ostatus);
837 mocchiut 1.1 }
838    

  ViewVC Help
Powered by ViewVC 1.1.23