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 |
|
|
|
28 |
mocchiut |
1.1 |
// ......................................................... |
29 |
|
|
// other general header files |
30 |
|
|
// ......................................................... |
31 |
|
|
#include <fstream> |
32 |
|
|
#include <iostream> |
33 |
|
|
// ......................................................... |
34 |
|
|
// files in the inc directory |
35 |
|
|
// ......................................................... |
36 |
|
|
#include <RunInfo.h> |
37 |
|
|
#include <GLTables.h> |
38 |
|
|
#include <TrkVerl2.h> |
39 |
|
|
#include <TrkProcess.h> |
40 |
pam-fi |
1.2 |
//#include <TrkStruct.h> |
41 |
mocchiut |
1.1 |
#include <TrkLevel2.h> |
42 |
pam-fi |
1.6 |
#include <TrkLevel1.h> |
43 |
mocchiut |
1.1 |
#include <TrkLevel0.h> |
44 |
pam-fi |
1.15 |
#include <TrkHough.h> |
45 |
mocchiut |
1.1 |
// ......................................................... |
46 |
|
|
// YODA header files |
47 |
|
|
// ......................................................... |
48 |
|
|
#include <PamelaRun.h> |
49 |
pam-fi |
1.7 |
//#include <RegistryEvent.h> |
50 |
mocchiut |
1.1 |
#include <physics/tracker/TrackerEvent.h> |
51 |
|
|
#include <CalibTrk1Event.h> |
52 |
|
|
#include <CalibTrk2Event.h> |
53 |
mocchiut |
1.42 |
// |
54 |
mocchiut |
1.43 |
// Calorimeter level1 class header and definitions |
55 |
mocchiut |
1.42 |
// |
56 |
|
|
#include <CaloLevel1.h> //EM |
57 |
mocchiut |
1.43 |
// |
58 |
|
|
// ToF level2 class header and definitions |
59 |
|
|
// |
60 |
|
|
#include <ToFLevel2.h> //EM |
61 |
pam-fi |
1.2 |
|
62 |
mocchiut |
1.1 |
// ......................................................... |
63 |
|
|
// namespaces |
64 |
|
|
// ......................................................... |
65 |
|
|
using namespace std; |
66 |
|
|
using namespace pamela; |
67 |
|
|
// ================================================================================ |
68 |
|
|
// |
69 |
|
|
// |
70 |
|
|
// ================================================================================ |
71 |
|
|
/** |
72 |
|
|
* \brief Tracker data reduction routine. |
73 |
|
|
* |
74 |
|
|
* It performs data reduction LEVEL0->LEVEL1->LEVEL2, producing LEVEL1 and or LEVEL2 output, in ROOT or HBOOK format. |
75 |
|
|
* Input parameters: |
76 |
|
|
* @param run id of the run to be processed (if run=0 a whole file is reprocessed) |
77 |
|
|
* @param dbc pointer to BD server |
78 |
|
|
* @param file1 output LEVEL1 file name (null if no LEVEL1 output is required) |
79 |
|
|
* @param file2 output LEVEL2 file name (null if no LEVEL2 output is required) |
80 |
|
|
* @param standalone (flag to run the program in standalone mode, that is without reading RunInfo) |
81 |
|
|
*/ |
82 |
|
|
//short int TrkCore(Int_t run, TSQLServer *dbc, TString file1, TString file2, Bool_t standalone) |
83 |
mocchiut |
1.31 |
//int TrkCore(UInt_t run, TFile *f2, TSQLServer *dbc, int ncustom, char*vcustom[]) // EMILIANO |
84 |
|
|
int TrkCore(UInt_t run, TFile *f2, GL_TABLES *glt, int ncustom, char*vcustom[]) // EMILIANO |
85 |
mocchiut |
1.1 |
{ |
86 |
|
|
// --------------------------- |
87 |
|
|
// Define some basic variables |
88 |
|
|
// --------------------------- |
89 |
|
|
|
90 |
pizzolot |
1.36 |
TString filename = ""; |
91 |
pam-fi |
1.7 |
Long64_t nentries = 0LL; |
92 |
pam-fi |
1.2 |
|
93 |
mocchiut |
1.1 |
// LEVEL0 input |
94 |
|
|
TFile *f0 = 0; |
95 |
|
|
TTree *physicsTree = 0; |
96 |
|
|
TBranch *b_trk = 0; |
97 |
|
|
TBranch *b_header = 0; |
98 |
|
|
EventHeader *header = 0; |
99 |
|
|
PscuHeader *pscu = 0; |
100 |
pam-fi |
1.22 |
TrkLevel0 *l0_event = new TrkLevel0(); |
101 |
mocchiut |
1.1 |
// RunInfo |
102 |
|
|
ItoRunInfo *runinfo = 0; |
103 |
pam-fi |
1.7 |
TArrayI *runlist = 0; |
104 |
|
|
UInt_t from_run; |
105 |
|
|
UInt_t to_run; |
106 |
mocchiut |
1.1 |
Bool_t reprocessing = false; |
107 |
|
|
//LEVEL2 output - ROOT |
108 |
|
|
TTree *t_level2 = 0; |
109 |
|
|
TTree *t_clone = 0; |
110 |
|
|
TrkLevel2 *l2_event = new TrkLevel2(); |
111 |
|
|
TrkLevel2 *l2_clone = new TrkLevel2(); |
112 |
pam-fi |
1.13 |
//LEVEL1 output - ROOT |
113 |
|
|
TrkLevel1 *l1_event = new TrkLevel1(); |
114 |
pam-fi |
1.15 |
TrkHough *lh_event = new TrkHough(); |
115 |
mocchiut |
1.42 |
|
116 |
mocchiut |
1.43 |
/* |
117 |
mocchiut |
1.42 |
// EM: how to use CaloLevel1 data inside tracker core routine, example: |
118 |
|
|
TTree *T = (TTree*)f2->Get("Calorimeter"); |
119 |
|
|
if ( T ){ |
120 |
|
|
CaloStrip *cs = new CaloStrip(false); |
121 |
|
|
CaloLevel1 *cl1 = new CaloLevel1(); |
122 |
|
|
T->SetBranchAddress("CaloLevel1",&cl1); |
123 |
|
|
// |
124 |
|
|
for (Int_t i=0; i < T->GetEntries(); i++){ |
125 |
|
|
T->GetEntry(i); |
126 |
|
|
Bool_t OK = false; |
127 |
|
|
Int_t k = 0; |
128 |
|
|
Int_t view = 0; |
129 |
|
|
Int_t plane = 0; |
130 |
|
|
Int_t strip = 0; |
131 |
|
|
Float_t mip = 0.; |
132 |
|
|
Float_t ene[2][22][96]; |
133 |
|
|
memset (ene,0,sizeof(Float_t)*2*22*96); |
134 |
|
|
// |
135 |
|
|
while ( k < cl1->istrip ){ |
136 |
|
|
mip = cl1->DecodeEstrip(k,view,plane,strip); |
137 |
|
|
// if ( view==0 && plane==18 ) mip = 0.; // 9thRED - set to zero signals from plane 18X |
138 |
|
|
// |
139 |
|
|
ene[view][plane][strip] = mip; |
140 |
|
|
k++; |
141 |
|
|
}; |
142 |
|
|
// check 5 |
143 |
|
|
Float_t totX = 0.; |
144 |
|
|
Float_t totY = 0.; |
145 |
|
|
Float_t posX = 0.; |
146 |
|
|
Float_t posY = 0.; |
147 |
|
|
Int_t minYstrip = 100; |
148 |
|
|
Int_t maxYstrip = -1; |
149 |
|
|
// calculate baricenter strip on first x and y planes |
150 |
|
|
for (Int_t j = 0; j<2; j++){ |
151 |
|
|
for (Int_t i = 0; i<96; i++){ |
152 |
|
|
totX += ene[0][j][i]; |
153 |
|
|
totY += ene[1][j][i]; |
154 |
|
|
if ( j==0 && ene[1][0][i]>0. && i > maxYstrip ) maxYstrip = i; |
155 |
|
|
if ( j==0 && ene[1][0][i]>0. && i < minYstrip ) minYstrip = i; |
156 |
|
|
posX += (float)i*ene[0][j][i]; |
157 |
|
|
posY += (float)i*ene[1][j][i]; |
158 |
|
|
} |
159 |
|
|
} |
160 |
|
|
// |
161 |
|
|
// printf(" totX %f totY %f maxYstrip %i minYstrip %i \n",totX,totY,maxYstrip,minYstrip); |
162 |
|
|
Int_t bariX = 0; |
163 |
|
|
Int_t bariY = 0; |
164 |
|
|
if ( totX>0. && totY > 0.){ |
165 |
|
|
// printf(" totX %f totY %f \n",totX,totY); |
166 |
|
|
posX /= totX; |
167 |
|
|
posY /= totY; |
168 |
|
|
bariX = (int)(posX); |
169 |
|
|
bariY = (int)(posY); |
170 |
|
|
Int_t minX = bariX - 10; |
171 |
|
|
Int_t maxX = bariX + 10; |
172 |
|
|
Int_t minY = bariY - 10; |
173 |
|
|
Int_t maxY = bariY + 10; |
174 |
|
|
if ( minX < 0 ) minX = 0; |
175 |
|
|
if ( minY < 0 ) minY = 0; |
176 |
|
|
if ( maxX > 95 ) maxX = 95; |
177 |
|
|
if ( maxY > 95 ) maxY = 95; |
178 |
|
|
totX = 0.; |
179 |
|
|
totY = 0.; |
180 |
|
|
Float_t parX = 0.; |
181 |
|
|
Float_t parY = 0.; |
182 |
|
|
|
183 |
|
|
for (Int_t j = 0; j<3; j++){ |
184 |
|
|
for (Int_t i = 0; i<96; i++){ |
185 |
|
|
totX += ene[0][j][i]; |
186 |
|
|
|
187 |
|
|
|
188 |
|
|
totY += ene[1][j][i]; |
189 |
|
|
if ( i>=minX && i<=maxX){ |
190 |
|
|
parX += ene[0][j][i]; |
191 |
|
|
} |
192 |
|
|
if ( i>=minY && i<=maxY){ |
193 |
|
|
parY += ene[1][j][i]; |
194 |
|
|
} |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
// 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); |
198 |
|
|
|
199 |
|
|
if ( parX/totX > 0.65 && parY/totY > 0.75 ) OK = true; // less strict cut on the X due to possible bremsstrhalung double showers |
200 |
|
|
// if ( OK ) printf(" CHECK5 PASSED\n"); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
// check 1 |
204 |
|
|
if ( totY > 0. && abs(maxYstrip-minYstrip)<10 ){ |
205 |
|
|
posY /= totY; |
206 |
|
|
bariY = (int)(posY); |
207 |
|
|
Float_t ntotX = 0.; |
208 |
|
|
Float_t ntotY = 0.; |
209 |
|
|
for (Int_t j = 0; j<2; j++){ |
210 |
|
|
for (Int_t i = 0; i<96; i++){ |
211 |
|
|
ntotX += ene[0][j][i]; |
212 |
|
|
if ( j > 0 ) ntotY += ene[1][j][i]; |
213 |
|
|
} |
214 |
|
|
} |
215 |
|
|
if ( ntotX < 0.3 && ntotY < 0.3 ){ |
216 |
|
|
OK = true; |
217 |
|
|
// printf(" CHECK1 PASSED\n"); |
218 |
|
|
} |
219 |
|
|
} |
220 |
|
|
|
221 |
|
|
if ( OK ){ |
222 |
|
|
printf("%i: event is good! \n",i); |
223 |
|
|
cs->Set(1,0,bariY); |
224 |
|
|
printf(" Y0 hit strip coordinates: X %f Y %f Z %f \n",cs->GetX(),cs->GetY(),cs->GetZ()); |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
T->Delete(); |
228 |
|
|
} |
229 |
|
|
// end EM |
230 |
mocchiut |
1.43 |
// EM: how to use ToF data inside tracker core routine, example: |
231 |
|
|
T = (TTree*)f2->Get("ToF"); |
232 |
|
|
if ( T ){ |
233 |
|
|
ToFLevel2 *tl2 = new ToFLevel2(); |
234 |
|
|
T->SetBranchAddress("ToFLevel2",&tl2); |
235 |
|
|
// |
236 |
|
|
for (Int_t i=0; i < T->GetEntries(); i++){ |
237 |
|
|
T->GetEntry(i); |
238 |
|
|
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)); |
239 |
|
|
} |
240 |
|
|
T->Delete(); |
241 |
|
|
} |
242 |
|
|
// END EM |
243 |
|
|
*/ |
244 |
mocchiut |
1.42 |
|
245 |
mocchiut |
1.1 |
// ----------------------- |
246 |
|
|
// ----------------------- |
247 |
|
|
// Handle input parameters |
248 |
|
|
// (data) |
249 |
|
|
// |
250 |
|
|
// - open/create output files, determining the environment root/hbook from the estension |
251 |
|
|
// - create the level1/level2 tree+branch/nt-uple |
252 |
|
|
// ----------------------- |
253 |
|
|
// ----------------------- |
254 |
|
|
TrkProcess *p = new TrkProcess(run,f2); |
255 |
pam-fi |
1.26 |
if( p->HandleCustomPar(ncustom,vcustom) )return(p->ostatus);; |
256 |
pam-fi |
1.25 |
if( TrkParams::VerboseMode() )p->Dump(); |
257 |
mocchiut |
1.1 |
|
258 |
|
|
// =================================== |
259 |
|
|
// Open/Create level2 output file |
260 |
|
|
// =================================== |
261 |
|
|
if(p->get2){ |
262 |
pam-fi |
1.13 |
//------------------------------------------- |
263 |
|
|
// read RunInfo |
264 |
|
|
//------------------------------------------- |
265 |
|
|
if(!(p->standalone)){ |
266 |
|
|
// Open "RunInfo" tree and get list of run |
267 |
|
|
runinfo = new ItoRunInfo(f2); |
268 |
|
|
char *trkversion = TrkInfo(false); |
269 |
|
|
int runinfo_error = runinfo->Update(run,"TRK",trkversion); |
270 |
|
|
if( runinfo_error ) throw runinfo_error; |
271 |
|
|
runlist = runinfo->GetRunList(); |
272 |
|
|
reprocessing = runinfo->IsReprocessing();//???? |
273 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode()){ |
274 |
pam-fi |
1.13 |
cout << "#events "<< runinfo->GetFileEntries() << endl;// #events in the file |
275 |
|
|
cout << "#runs "<< runinfo->GetRunEntries() << endl;// #runs in the file |
276 |
|
|
cout << "1-st run "<< runlist->At(0) << endl; |
277 |
|
|
cout << "last run "<< runlist->At(runinfo->GetRunEntries()-1) << endl; |
278 |
|
|
cout << "1-st event "<< runinfo->GetFirstEntry() << endl;// first event of our run |
279 |
|
|
cout << "last event+1 "<< runinfo->GetLastEntry() << endl;// first event AFTER the last event of our run |
280 |
|
|
cout << "reprocessing "<< runinfo->IsReprocessing() << endl << endl; |
281 |
|
|
}; |
282 |
|
|
}; |
283 |
|
|
//------------------------------------------- |
284 |
|
|
// |
285 |
|
|
//------------------------------------------- |
286 |
|
|
// Take (if present) the old Tracker tree |
287 |
|
|
t_clone = (TTree*)f2->Get("Tracker"); |
288 |
|
|
if( t_clone != NULL ) t_clone->SetBranchAddress("TrkLevel2",&l2_clone); |
289 |
|
|
// Create NEW Tracker tree |
290 |
|
|
t_level2 = new TTree("Tracker","PAMELA tracker level2 data "); |
291 |
pam-fi |
1.21 |
l2_event->Set(); // ****NBNBNBN***** |
292 |
pam-fi |
1.13 |
t_level2->Branch("TrkLevel2","TrkLevel2",&l2_event); |
293 |
|
|
if(p->get1){ |
294 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode())cout << endl << "Requested LEVEL1 output" << endl; |
295 |
pam-fi |
1.21 |
l1_event->Set(); // ****NBNBNBN***** |
296 |
pam-fi |
1.13 |
t_level2->Branch("TrkLevel1","TrkLevel1",&l1_event); |
297 |
pam-fi |
1.16 |
} |
298 |
|
|
if(p->geth){ |
299 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode())cout << endl << "Requested Hough-Transform output" << endl; |
300 |
pam-fi |
1.16 |
t_level2->Branch("TrkHough","TrkHough",&lh_event); |
301 |
pam-fi |
1.7 |
}; |
302 |
pam-fi |
1.13 |
}; |
303 |
mocchiut |
1.1 |
|
304 |
|
|
|
305 |
|
|
// ------------------------------------------- |
306 |
|
|
// define runs to be processed/reprocessed |
307 |
|
|
// ------------------------------------------- |
308 |
|
|
if(run == 0){ |
309 |
pam-fi |
1.13 |
// reprocessing ALL runs |
310 |
|
|
if(p->standalone)throw -298; // reprocessing not implemented |
311 |
|
|
from_run = runlist->At(0); |
312 |
|
|
to_run = runlist->At(runinfo->GetRunEntries()-1); |
313 |
mocchiut |
1.1 |
}else{ |
314 |
|
|
// processing/reprocessing ONE single run |
315 |
pam-fi |
1.13 |
from_run = run; |
316 |
|
|
to_run = run; |
317 |
mocchiut |
1.1 |
}; |
318 |
|
|
|
319 |
|
|
// |
320 |
|
|
// init event counter |
321 |
|
|
// |
322 |
|
|
Int_t ev_count =0; |
323 |
|
|
// |
324 |
|
|
// create query-results objects |
325 |
|
|
// |
326 |
pam-fi |
1.7 |
GL_RUN q1 = GL_RUN(); |
327 |
mocchiut |
1.1 |
GL_TRK_CALIB q2 = GL_TRK_CALIB(); |
328 |
|
|
GL_ROOT q3 = GL_ROOT(); |
329 |
|
|
GL_PARAM q4 = GL_PARAM(); |
330 |
|
|
|
331 |
|
|
// ------------------------------------------------------------ |
332 |
|
|
// if reprocessing one run, copy all the events BEFORE the run |
333 |
|
|
// ------------------------------------------------------------ |
334 |
|
|
if( !(p->standalone) ){ |
335 |
pam-fi |
1.13 |
for(UInt_t i=0; i<runinfo->GetFirstEntry(); i++){ |
336 |
mocchiut |
1.37 |
if ( t_clone->GetEntry(i) <= 0 ) throw -36;// EM |
337 |
pam-fi |
1.13 |
*l2_event = *l2_clone; |
338 |
|
|
t_level2->Fill(); |
339 |
|
|
l2_event->Clear(); |
340 |
|
|
// COPY COPY COPY |
341 |
|
|
}; |
342 |
mocchiut |
1.1 |
}; |
343 |
|
|
// ------------------------------------------------------------ |
344 |
|
|
// ------------------------------------------------------------ |
345 |
pam-fi |
1.25 |
// START LOOP OVER RUNS TO PROCESS/REPROCESS |
346 |
mocchiut |
1.1 |
// ------------------------------------------------------------ |
347 |
|
|
// ------------------------------------------------------------ |
348 |
pam-fi |
1.7 |
for(UInt_t idRun = from_run; idRun <= to_run; idRun++){ |
349 |
mocchiut |
1.1 |
|
350 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode()) cout << endl<<" ========================= Run: "<< idRun << endl; |
351 |
pam-fi |
1.7 |
UInt_t runheadtime = 0; |
352 |
|
|
UInt_t runtrailtime = 0; |
353 |
pam-fi |
1.32 |
UInt_t runheadobt = 0; |
354 |
|
|
UInt_t runtrailobt = 0; |
355 |
mocchiut |
1.41 |
UInt_t abstime = 0; |
356 |
mocchiut |
1.1 |
UInt_t evfrom = 0; |
357 |
|
|
UInt_t evto = 0; |
358 |
pam-fi |
1.7 |
UInt_t nevents = 0; |
359 |
|
|
Int_t id_root_l0 =-1; |
360 |
mocchiut |
1.1 |
Int_t trk_calib_used = 0; |
361 |
pam-fi |
1.7 |
|
362 |
mocchiut |
1.31 |
TString host = glt->CGetHost(); // EMILIANO |
363 |
|
|
TString user = glt->CGetUser(); // EMILIANO |
364 |
|
|
TString psw = glt->CGetPsw(); // EMILIANO |
365 |
|
|
// TString host = "mysql://localhost/pamelaprod"; |
366 |
|
|
// TString user = "anonymous"; |
367 |
|
|
// TString psw = ""; |
368 |
|
|
// const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
369 |
|
|
// const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
370 |
|
|
// const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
371 |
|
|
// if ( !pamdbhost ) pamdbhost = ""; |
372 |
|
|
// if ( !pamdbuser ) pamdbuser = ""; |
373 |
|
|
// if ( !pamdbpsw ) pamdbpsw = ""; |
374 |
|
|
// if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
375 |
|
|
// if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
376 |
|
|
// if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
377 |
mocchiut |
1.29 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
378 |
mocchiut |
1.31 |
stringstream myquery; // EMILIANO |
379 |
|
|
myquery.str(""); // EMILIANO |
380 |
|
|
myquery << "SET time_zone='+0:00'"; // EMILIANO |
381 |
mocchiut |
1.39 |
delete dbc->Query(myquery.str().c_str()); // EMILIANO |
382 |
mocchiut |
1.1 |
if(p->standalone){ |
383 |
|
|
// ============================== |
384 |
|
|
// first query: retrieve run info |
385 |
|
|
// ============================== |
386 |
pam-fi |
1.7 |
if (q1.Query_GL_RUN(idRun,dbc) )throw -50; |
387 |
|
|
id_root_l0 = q1.ID_ROOT_L0; |
388 |
mocchiut |
1.1 |
runheadtime = q1.RUNHEADER_TIME; |
389 |
|
|
runtrailtime = q1.RUNTRAILER_TIME; |
390 |
pam-fi |
1.32 |
runheadobt = q1.RUNHEADER_OBT; |
391 |
|
|
runtrailobt = q1.RUNTRAILER_OBT; |
392 |
pam-fi |
1.7 |
evfrom = q1.EV_FROM; |
393 |
|
|
evto = q1.EV_TO; |
394 |
pam-fi |
1.13 |
nevents = q1.NEVENTS; |
395 |
|
|
trk_calib_used = q1.TRK_CALIB_USED; |
396 |
mocchiut |
1.1 |
}else{ |
397 |
|
|
// ============================== |
398 |
|
|
// get run info from RunInfo tree |
399 |
|
|
// ============================== |
400 |
pam-fi |
1.3 |
int runinfo_error = runinfo->GetRunInfo(idRun); |
401 |
pam-fi |
1.7 |
if( runinfo_error ) throw runinfo_error; |
402 |
|
|
id_root_l0 = runinfo->ID_ROOT_L0; |
403 |
mocchiut |
1.1 |
runheadtime = runinfo->RUNHEADER_TIME; |
404 |
|
|
runtrailtime = runinfo->RUNTRAILER_TIME; |
405 |
pam-fi |
1.32 |
runheadobt = runinfo->RUNHEADER_OBT; |
406 |
|
|
runtrailobt = runinfo->RUNTRAILER_OBT; |
407 |
pam-fi |
1.7 |
evfrom = runinfo->EV_FROM; |
408 |
|
|
evto = runinfo->EV_TO; |
409 |
pam-fi |
1.13 |
nevents = runinfo->NEVENTS; |
410 |
|
|
trk_calib_used = runinfo->TRK_CALIB_USED; |
411 |
pam-fi |
1.24 |
|
412 |
mocchiut |
1.1 |
}; |
413 |
pam-fi |
1.24 |
|
414 |
mocchiut |
1.1 |
// |
415 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode()){ |
416 |
pam-fi |
1.7 |
cout << "ROOT file ID "<< id_root_l0 << endl; |
417 |
mocchiut |
1.1 |
cout << "RunHeader time "<< runheadtime << endl; |
418 |
|
|
cout << "RunTrailer time "<< runtrailtime << endl; |
419 |
pam-fi |
1.7 |
cout << " from event "<< evfrom << endl; |
420 |
|
|
cout << " to event "<< evto << endl; |
421 |
pam-fi |
1.24 |
cout << " num. events "<< nevents << endl; |
422 |
|
|
cout << "trk-calibration used "<< trk_calib_used << endl; |
423 |
mocchiut |
1.1 |
}; |
424 |
|
|
// ======================================================== |
425 |
|
|
// second query: search the LEVEL0 file that contains idRun |
426 |
|
|
// ======================================================== |
427 |
|
|
TString lastfilename = filename; |
428 |
pam-fi |
1.7 |
if( q3.Query_GL_ROOT(id_root_l0,dbc) )throw -51; |
429 |
mocchiut |
1.1 |
filename = q3.PATH + q3.NAME; |
430 |
|
|
// ======================================================== |
431 |
|
|
// Open the input LEVEL0 data file |
432 |
|
|
// ======================================================== |
433 |
|
|
if(filename.CompareTo(lastfilename)){ |
434 |
|
|
if(!lastfilename.IsNull())f0->Close(); |
435 |
|
|
//if( debug ) cout << "Opening LEVEL0 file: "<< filename << endl; |
436 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode()) cout << "Opening LEVEL0 file: "<< filename << endl; |
437 |
pam-fi |
1.2 |
FileStat_t t; |
438 |
|
|
if( gSystem->GetPathInfo(filename.Data(),t) )throw -6; |
439 |
mocchiut |
1.39 |
if ( f0 ) f0->Close(); |
440 |
mocchiut |
1.1 |
f0 = new TFile(filename); |
441 |
|
|
if ( !f0 ) throw -6; |
442 |
|
|
physicsTree = (TTree*)f0->Get("Physics"); if(!physicsTree) throw -7; |
443 |
|
|
b_header = physicsTree ->GetBranch("Header"); if(!b_header ) throw -8; |
444 |
|
|
b_trk = physicsTree ->GetBranch("Tracker"); if(!b_trk ) throw -203; |
445 |
pam-fi |
1.22 |
l0_event->Set(); |
446 |
|
|
physicsTree->SetBranchAddress("Tracker" ,l0_event->GetPointerToTrackerEvent()); |
447 |
mocchiut |
1.1 |
physicsTree->SetBranchAddress("Header",&header); |
448 |
|
|
|
449 |
pam-fi |
1.7 |
nentries = physicsTree->GetEntries(); |
450 |
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 |
451 |
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 |
452 |
|
|
// 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 |
453 |
|
|
// the condition ( nentries < (evto+1) ) is satisfied and DV exit with error even if the error is only in the DB. |
454 |
pam-fi |
1.7 |
|
455 |
mocchiut |
1.1 |
}; |
456 |
|
|
|
457 |
pam-fi |
1.7 |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(id_root_l0,"ID",dbc); |
458 |
|
|
|
459 |
pam-fi |
1.24 |
|
460 |
|
|
// ============================================================= |
461 |
|
|
// retrieve information about parameters to process LEVEL2 |
462 |
|
|
// ============================================================= |
463 |
|
|
|
464 |
mocchiut |
1.41 |
TrkParams::Set(runinfo->GetGL_RUN(),dbc); |
465 |
|
|
for(int i=0; i<p->npar; i++){ |
466 |
|
|
if(TrkParams::VerboseMode())cout<<" ((( force parameters from input path )))"<<endl; |
467 |
|
|
TrkParams::Set(p->parpath[i],p->partype[i]); |
468 |
|
|
} |
469 |
pam-fi |
1.25 |
|
470 |
mocchiut |
1.41 |
TrkParams::Load(); |
471 |
|
|
if( !TrkParams::IsLoaded() )throw -52; |
472 |
pam-fi |
1.24 |
|
473 |
|
|
// ============================================================= |
474 |
|
|
// retrieve calibration file needed to reduce data |
475 |
|
|
// ============================================================= |
476 |
|
|
|
477 |
|
|
TrkParams::SetCalib(runinfo->GetGL_RUN(),dbc); |
478 |
|
|
TrkParams::LoadCalib( ); |
479 |
|
|
if( !TrkParams::CalibIsLoaded() )throw -53; |
480 |
|
|
|
481 |
pam-fi |
1.11 |
TBenchmark *reduction = new TBenchmark(); |
482 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode())reduction->Start("reduction"); |
483 |
pam-fi |
1.11 |
Int_t ntrk=0; |
484 |
mocchiut |
1.1 |
// ==================================================== |
485 |
|
|
// start looping on events cointained in the data file |
486 |
|
|
// ==================================================== |
487 |
mocchiut |
1.41 |
if ( TrkParams::GetSimuFlag() ){ |
488 |
|
|
abstime = runheadtime; |
489 |
|
|
} else { |
490 |
|
|
if(dbc){ |
491 |
|
|
dbc->Close(); |
492 |
|
|
delete dbc; |
493 |
|
|
} |
494 |
|
|
} |
495 |
|
|
|
496 |
pam-fi |
1.32 |
for (UInt_t re = evfrom+min(p->nskip,nevents); re < evfrom+nevents; re++){ |
497 |
mocchiut |
1.1 |
|
498 |
|
|
ev_count++; |
499 |
pam-fi |
1.32 |
|
500 |
|
|
|
501 |
pam-fi |
1.25 |
// if ( TrkParams::DebugMode() && re%100 == 0 && re > 0 ) cout << "."; |
502 |
mocchiut |
1.1 |
|
503 |
mocchiut |
1.37 |
if ( b_trk->GetEntry(re) <= 0 ) throw -36;//EM |
504 |
|
|
if ( b_header->GetEntry(re) <= 0 ) throw -36;//EM |
505 |
pam-fi |
1.13 |
pscu = header->GetPscuHeader(); |
506 |
mocchiut |
1.41 |
|
507 |
|
|
// ============================================================= |
508 |
|
|
// The following 6 lines have been moved here by VALERIO. |
509 |
|
|
if(TrkParams::GetSimuFlag()){ |
510 |
|
|
abstime = runheadtime + (int) floor(0.03*(re-evfrom)); //If simulated data we need to assign a fake abstime. 30ms between each event. |
511 |
|
|
if(TrkParams::VerboseMode())cout << "Event: " << re-evfrom << " - Attempting to retrieve Mask Info for abstime=" << abstime << endl; |
512 |
|
|
if(!TrkParams::Set(runinfo->GetGL_RUN(),dbc,6,abstime))throw -52; // Setting to load mask (VALERIO) |
513 |
|
|
TrkParams::Load(6); |
514 |
|
|
if( !TrkParams::IsLoaded() )throw -52; |
515 |
|
|
if(TrkParams::VerboseMode())cout << "Mask Info for abstime=" << abstime << " retrieved" << endl; |
516 |
|
|
} |
517 |
|
|
|
518 |
pam-fi |
1.25 |
if( TrkParams::DebugMode() )cout << ">>> "<<ev_count-1<<" @ OBT "<<pscu->GetOrbitalTime()<<endl; |
519 |
pam-fi |
1.23 |
|
520 |
mocchiut |
1.35 |
if ( dbtime->DBabsTime(pscu->GetOrbitalTime()) > (runtrailtime+1) || dbtime->DBabsTime(pscu->GetOrbitalTime()) < (runheadtime-1)) { |
521 |
pam-fi |
1.7 |
|
522 |
pam-fi |
1.25 |
if (TrkParams::VerboseMode()){ |
523 |
pam-fi |
1.14 |
printf(" TrkCore - WARNING: event outside the run time window, skipping it\n"); |
524 |
pam-fi |
1.32 |
cout << " OBT "<<pscu->GetOrbitalTime()<<" RUN "<<runheadobt<<"-"<<runtrailobt<<" ABS-time "<<dbtime->DBabsTime(pscu->GetOrbitalTime())<<" RUN "<<runheadtime<<"-"<<runtrailtime<<endl; |
525 |
pam-fi |
1.14 |
}; |
526 |
pam-fi |
1.13 |
}else{ |
527 |
pam-fi |
1.25 |
if ( TrkParams::DebugMode() ) |
528 |
pam-fi |
1.23 |
printf("\n-------------------------------\nevent %d\n",re-evfrom); |
529 |
pam-fi |
1.16 |
|
530 |
pam-fi |
1.13 |
p->ProcessEvent(l0_event); |
531 |
pam-fi |
1.7 |
|
532 |
pam-fi |
1.13 |
// ---------------- |
533 |
|
|
// LEVEL1 output |
534 |
|
|
// ---------------- |
535 |
|
|
if(p->get1){ |
536 |
|
|
if(p->ifroot1){ // root |
537 |
|
|
l1_event->Clear(); |
538 |
pam-fi |
1.22 |
// l1_event->SetFromLevel1Struct(&level1event_,p->full1); |
539 |
|
|
l1_event->SetFromLevel1Struct(p->full1); |
540 |
pam-fi |
1.13 |
// t_level1->Fill(); |
541 |
pam-fi |
1.23 |
}else{ // hbook |
542 |
pam-fi |
1.13 |
throw -299; |
543 |
|
|
}; |
544 |
|
|
}; |
545 |
|
|
// ---------------- |
546 |
|
|
// HOUGH output |
547 |
|
|
// ---------------- |
548 |
|
|
if(p->geth){ |
549 |
|
|
if(p->ifrooth){ // root |
550 |
pam-fi |
1.23 |
lh_event->Delete(); |
551 |
|
|
lh_event->SetFromHoughStruct(&houghevent_); |
552 |
pam-fi |
1.13 |
}else{ // hbook |
553 |
|
|
throw -299; |
554 |
|
|
}; |
555 |
|
|
}; |
556 |
|
|
// ---------------- |
557 |
|
|
// LEVEL2 output |
558 |
|
|
// ---------------- |
559 |
|
|
if(p->get2){ |
560 |
pam-fi |
1.23 |
l2_event->Clear(); |
561 |
|
|
if(p->get1){ |
562 |
|
|
l2_event->SetFromLevel2Struct(&level2event_,l1_event);//set references to level1 |
563 |
|
|
}else{ |
564 |
|
|
l2_event->SetFromLevel2Struct(&level2event_); |
565 |
|
|
} |
566 |
pam-fi |
1.10 |
// l2_event->Dump(); |
567 |
pam-fi |
1.23 |
t_level2->Fill(); |
568 |
|
|
if( l2_event->ntrk()>0 )ntrk++; |
569 |
pam-fi |
1.27 |
if(TrkParams::VerboseMode())l2_event->Dump(); |
570 |
mocchiut |
1.1 |
}; |
571 |
pam-fi |
1.13 |
}; |
572 |
mocchiut |
1.1 |
}; // end loop on events |
573 |
pam-fi |
1.25 |
if(TrkParams::VerboseMode()){ |
574 |
pam-fi |
1.13 |
cout << " >>> processed "<< ev_count <<" events"<< endl; |
575 |
|
|
if(ev_count)cout << ntrk << " events with at least one track ("<<(Int_t)(100*ntrk/ev_count)<<"%)\n"; |
576 |
|
|
reduction->Show("reduction"); |
577 |
pam-fi |
1.11 |
} |
578 |
|
|
delete reduction; |
579 |
pam-fi |
1.7 |
|
580 |
|
|
delete dbtime; |
581 |
|
|
|
582 |
pam-fi |
1.13 |
}; // end loop on runs |
583 |
|
|
|
584 |
|
|
|
585 |
mocchiut |
1.1 |
// ------------------------------------------------------------ |
586 |
|
|
// if reprocessing one run, copy all the events AFTER the run |
587 |
|
|
// ------------------------------------------------------------ |
588 |
|
|
if( !(p->standalone) ){ |
589 |
|
|
for(UInt_t i=runinfo->GetLastEntry()+1; i<runinfo->GetFileEntries(); i++){ |
590 |
mocchiut |
1.37 |
if ( t_clone->GetEntry(i) <= 0 ) throw -36;//EM |
591 |
mocchiut |
1.1 |
*l2_event = *l2_clone; |
592 |
|
|
t_level2->Fill(); |
593 |
|
|
l2_event->Clear(); |
594 |
|
|
// COPY COPY COPY |
595 |
|
|
}; |
596 |
|
|
}; |
597 |
|
|
// --------------- |
598 |
|
|
// close the files |
599 |
|
|
// --------------- |
600 |
|
|
if(p->get2){ |
601 |
mocchiut |
1.40 |
if( t_clone )t_clone->Delete("all");//delete old tree from file |
602 |
pam-fi |
1.13 |
if( !(p->standalone) )runinfo->Close(); |
603 |
mocchiut |
1.40 |
// t_level2->Write("Tracker", TObject::kOverwrite); |
604 |
|
|
f2->Write("Tracker", TObject::kOverwrite); |
605 |
|
|
if( t_level2 )t_level2->Delete(); //delete new tree from memory |
606 |
pam-fi |
1.13 |
|
607 |
|
|
}; |
608 |
pam-fi |
1.6 |
|
609 |
pam-fi |
1.24 |
if(f0) if(f0->IsOpen()) f0->Close(); |
610 |
|
|
// if( f0_c->IsOpen() )f0_c->Close(); |
611 |
pam-fi |
1.13 |
|
612 |
|
|
// lh_event->Delete(); |
613 |
|
|
l1_event->Delete(); |
614 |
|
|
l2_event->Delete(); |
615 |
|
|
l2_clone->Delete(); |
616 |
pam-fi |
1.2 |
|
617 |
|
|
return(p->ostatus); |
618 |
mocchiut |
1.1 |
} |
619 |
|
|
|