/[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.48 - (hide annotations) (download)
Mon Jun 23 08:34:18 2014 UTC (10 years, 8 months ago) by pam-ts
Branch: MAIN
Changes since 1.47: +60 -36 lines
extended tracking-algorythm flag added
C

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

  ViewVC Help
Powered by ViewVC 1.1.23