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