| 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 |
#include <TBenchmark.h> |
| 27 |
#include <TStopwatch.h> |
| 28 |
|
| 29 |
// ......................................................... |
| 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 |
//#include <TrkStruct.h> |
| 42 |
#include <TrkLevel2.h> |
| 43 |
#include <TrkLevel1.h> |
| 44 |
#include <TrkLevel0.h> |
| 45 |
#include <TrkHough.h> |
| 46 |
// ......................................................... |
| 47 |
// YODA header files |
| 48 |
// ......................................................... |
| 49 |
#include <PamelaRun.h> |
| 50 |
//#include <RegistryEvent.h> |
| 51 |
#include <physics/tracker/TrackerEvent.h> |
| 52 |
#include <CalibTrk1Event.h> |
| 53 |
#include <CalibTrk2Event.h> |
| 54 |
// |
| 55 |
// Calorimeter level1 class header and definitions |
| 56 |
// |
| 57 |
#include <CaloLevel1.h> //EM |
| 58 |
// |
| 59 |
// ToF level2 class header and definitions |
| 60 |
// |
| 61 |
#include <ToFLevel2.h> //EM |
| 62 |
// |
| 63 |
// Extended tracking |
| 64 |
// |
| 65 |
#include <ExtTrkingAlg.h> //EV |
| 66 |
|
| 67 |
// ......................................................... |
| 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 |
//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 |
{ |
| 91 |
// --------------------------- |
| 92 |
// Define some basic variables |
| 93 |
// --------------------------- |
| 94 |
|
| 95 |
TString filename = ""; |
| 96 |
Long64_t nentries = 0LL; |
| 97 |
|
| 98 |
// 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 |
TrkLevel0 *l0_event = new TrkLevel0(); |
| 106 |
// RunInfo |
| 107 |
ItoRunInfo *runinfo = 0; |
| 108 |
TArrayI *runlist = 0; |
| 109 |
UInt_t from_run; |
| 110 |
UInt_t to_run; |
| 111 |
// Bool_t reprocessing = false; // EM GCC 4.7 |
| 112 |
//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 |
|
| 118 |
TrkLevel2 *l2_event_nuclei = NULL; // EM bug new TrkLevel2(); |
| 119 |
// EM TrkLevel2 *l2_clone_nuclei = new TrkLevel2(); |
| 120 |
//LEVEL1 output - ROOT |
| 121 |
TrkLevel1 *l1_event = new TrkLevel1(); |
| 122 |
TrkLevel1 *l1_event_nuclei = NULL; // EM, bug new TrkLevel1(); |
| 123 |
TrkHough *lh_event = new TrkHough(); |
| 124 |
|
| 125 |
//Extended tracking: |
| 126 |
TTree *t_cal = NULL; |
| 127 |
TTree *t_tof = NULL; |
| 128 |
ExtTrkingAlg *trkAlg = NULL; |
| 129 |
ExtTrkingAlg *trkAlg_nuclei = NULL; |
| 130 |
TClonesArray *trk_array = NULL; |
| 131 |
TClonesArray *trk_array_nuclei = NULL; |
| 132 |
|
| 133 |
CaloLevel1 *cl1 = NULL; |
| 134 |
ToFLevel2 *tl2 = NULL; |
| 135 |
|
| 136 |
typedef struct { |
| 137 |
|
| 138 |
Int_t nTrk; |
| 139 |
Int_t nTrkNuc; |
| 140 |
Int_t nTrkExt; |
| 141 |
Int_t nTrkExtNuc; |
| 142 |
|
| 143 |
Int_t nCl; |
| 144 |
Int_t nClCut; |
| 145 |
|
| 146 |
Float_t tTrk; |
| 147 |
Float_t tTrkExt; |
| 148 |
Float_t tTrkNuc; |
| 149 |
|
| 150 |
|
| 151 |
void Dump(){ |
| 152 |
cout <<" nTrk"<<setw(5)<<nTrk ; |
| 153 |
cout <<" nTrkNuc"<<setw(5)<<nTrkNuc ; |
| 154 |
cout <<" nTrkExt"<<setw(5)<< nTrkExt; |
| 155 |
cout <<" nTrkExtNuc"<<setw(5)<<nTrkExtNuc ; |
| 156 |
cout <<" nCl"<<setw(5)<<nCl ; |
| 157 |
cout <<" nClCut"<<setw(5)<<nClCut ; |
| 158 |
cout <<" tTrk"<<setw(15)<<tTrk ; |
| 159 |
cout <<" tTrkExt"<<setw(15)<<tTrkExt; |
| 160 |
cout <<" tTrkNuc"<<setw(15)<<tTrkNuc ; |
| 161 |
cout << endl; |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
} TrkWatch; |
| 166 |
TrkWatch trkWatch; |
| 167 |
TTree *tWatch = NULL; |
| 168 |
|
| 169 |
Int_t extAlgFlag=0; |
| 170 |
|
| 171 |
// ----------------------- |
| 172 |
// ----------------------- |
| 173 |
// Handle input parameters |
| 174 |
// (data) |
| 175 |
// |
| 176 |
// - open/create output files, determining the environment root/hbook from the estension |
| 177 |
// - create the level1/level2 tree+branch/nt-uple |
| 178 |
// ----------------------- |
| 179 |
// ----------------------- |
| 180 |
TrkProcess *p = new TrkProcess(run,f2); |
| 181 |
if( p->HandleCustomPar(ncustom,vcustom) )return(p->ostatus);; |
| 182 |
if( TrkParams::VerboseMode() )p->Dump(); |
| 183 |
// p->Dump(); |
| 184 |
|
| 185 |
// =================================== |
| 186 |
// Open/Create level2 output file |
| 187 |
// =================================== |
| 188 |
if(p->get2){ |
| 189 |
//------------------------------------------- |
| 190 |
// read RunInfo |
| 191 |
//------------------------------------------- |
| 192 |
if(!(p->standalone)){ |
| 193 |
// Open "RunInfo" tree and get list of run |
| 194 |
runinfo = new ItoRunInfo(f2); |
| 195 |
char *trkversion = TrkInfo(false); |
| 196 |
int runinfo_error = runinfo->Update(run,"TRK",trkversion); // EMQUI |
| 197 |
if( runinfo_error ) throw runinfo_error; |
| 198 |
runlist = runinfo->GetRunList(); |
| 199 |
// reprocessing = runinfo->IsReprocessing();//???? |
| 200 |
if(TrkParams::VerboseMode()){ |
| 201 |
cout << "#events "<< runinfo->GetFileEntries() << endl;// #events in the file |
| 202 |
cout << "#runs "<< runinfo->GetRunEntries() << endl;// #runs in the file |
| 203 |
cout << "1-st run "<< runlist->At(0) << endl; |
| 204 |
cout << "last run "<< runlist->At(runinfo->GetRunEntries()-1) << endl; |
| 205 |
cout << "1-st event "<< runinfo->GetFirstEntry() << endl;// first event of our run |
| 206 |
cout << "last event+1 "<< runinfo->GetLastEntry() << endl;// first event AFTER the last event of our run |
| 207 |
// cout << "reprocessing "<< runinfo->IsReprocessing() << endl << endl; |
| 208 |
}; |
| 209 |
}; |
| 210 |
//------------------------------------------- |
| 211 |
// |
| 212 |
//------------------------------------------- |
| 213 |
// Take (if present) the old Tracker tree |
| 214 |
t_clone = (TTree*)f2->Get("Tracker"); |
| 215 |
if( t_clone != NULL ){ |
| 216 |
t_clone->SetBranchAddress("TrkLevel2",&l2_clone); |
| 217 |
// t_clone->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 218 |
t_clone->SetAutoSave(900000000000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 219 |
} |
| 220 |
|
| 221 |
// Create NEW Tracker tree |
| 222 |
t_level2 = new TTree("Tracker-new","PAMELA tracker level2 data "); |
| 223 |
// t_level2->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 224 |
t_level2->SetAutoSave(900000000000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 225 |
l2_event->Set(); // ****NBNBNBN***** |
| 226 |
t_level2->Branch("TrkLevel2","TrkLevel2",&l2_event); |
| 227 |
|
| 228 |
if(p->get1){ |
| 229 |
if(TrkParams::VerboseMode())cout << endl << "Requested LEVEL1 output" << endl; |
| 230 |
l1_event->Set(); // ****NBNBNBN***** |
| 231 |
t_level2->Branch("TrkLevel1","TrkLevel1",&l1_event); |
| 232 |
} |
| 233 |
if(p->geth){ |
| 234 |
if(TrkParams::VerboseMode())cout << endl << "Requested Hough-Transform output" << endl; |
| 235 |
t_level2->Branch("TrkHough","TrkHough",&lh_event); |
| 236 |
}; |
| 237 |
if(p->getn){ |
| 238 |
if(TrkParams::VerboseMode())cout << endl << "Requested nuclei-algorythm output" << endl; |
| 239 |
if(!l2_event_nuclei)l2_event_nuclei = new TrkLevel2(); |
| 240 |
if(!l1_event_nuclei)l1_event_nuclei = new TrkLevel1(); // EM bug |
| 241 |
l2_event_nuclei->Set(); // ****NBNBNBN***** |
| 242 |
t_level2->Branch("TrackNuclei",l2_event_nuclei->GetPointerToTrackArray()); |
| 243 |
|
| 244 |
} |
| 245 |
// ========================================================= |
| 246 |
// extended tracking algorythm output |
| 247 |
// ========================================================= |
| 248 |
if(p->gete){ |
| 249 |
|
| 250 |
if(TrkParams::VerboseMode()) cout <<"Creating extended tracking algorythm "<<p->extAlgID<<endl; |
| 251 |
trkAlg = new ExtTrkingAlg(p->extAlgID);// create the algorythm |
| 252 |
trk_array = trkAlg->GetTrackArray(); // get the track array |
| 253 |
if(!trk_array)throw -206; |
| 254 |
t_level2->Branch("RecoveredTrack",trkAlg->GetPointerToTrackArray());// put it in a branch |
| 255 |
if(p->getn){ |
| 256 |
if(TrkParams::VerboseMode())cout << endl << "Requested extended nuclei-algorythm output" << endl; |
| 257 |
trkAlg_nuclei = new ExtTrkingAlg(p->extAlgID);// create the algorythm for nuclei |
| 258 |
trk_array_nuclei = trkAlg_nuclei->GetTrackArray();// get the track array |
| 259 |
if(!trk_array_nuclei)throw -206; |
| 260 |
t_level2->Branch("RecoveredTrackNuclei",trkAlg_nuclei->GetPointerToTrackArray()); // put it in a branch |
| 261 |
} |
| 262 |
t_level2->Branch("extAlgFlag",&extAlgFlag,"extAlgFlag/I"); |
| 263 |
// ------------------------ |
| 264 |
// calorimeter and tof tree |
| 265 |
// ------------------------ |
| 266 |
t_cal = (TTree*)f2->Get("Calorimeter"); |
| 267 |
if(!t_cal)throw -206; |
| 268 |
cl1 = new CaloLevel1(); |
| 269 |
t_cal->SetBranchAddress("CaloLevel1",&cl1); |
| 270 |
t_cal->SetAutoSave(900000000000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 271 |
// t_cal->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 272 |
|
| 273 |
|
| 274 |
t_tof = (TTree*)f2->Get("ToF"); |
| 275 |
if(!t_tof)throw -206; |
| 276 |
tl2 = new ToFLevel2(); |
| 277 |
t_tof->SetBranchAddress("ToFLevel2",&tl2); |
| 278 |
t_tof->SetAutoSave(900000000000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 279 |
// t_tof->SetMaxVirtualSize(2500000000LL); // EM residual Tracker-new tree in level2 files when NEVENTS is big |
| 280 |
|
| 281 |
} |
| 282 |
if(p->watch){ |
| 283 |
|
| 284 |
// f2->cd(); |
| 285 |
tWatch = new TTree("TrkWatch"," Tracking timing info"); |
| 286 |
|
| 287 |
tWatch->Branch("nCl",&trkWatch.nCl,"nCl/I"); |
| 288 |
tWatch->Branch("nClCut",&trkWatch.nClCut,"nClCut/I"); |
| 289 |
|
| 290 |
tWatch->Branch("nTrk",&trkWatch.nTrk,"nTrk/I"); |
| 291 |
tWatch->Branch("nTrkExt",&trkWatch.nTrkExt,"nTrkExt/I"); |
| 292 |
tWatch->Branch("nTrkNuc",&trkWatch.nTrkNuc,"nTrkNuc/I"); |
| 293 |
tWatch->Branch("nTrkExtNuc",&trkWatch.nTrkExtNuc,"nTrkExtExt/I"); |
| 294 |
|
| 295 |
tWatch->Branch("tTrk",&trkWatch.tTrk,"tTrk/F"); |
| 296 |
tWatch->Branch("tTrkExt",&trkWatch.tTrkExt,"tTrkExt/F"); |
| 297 |
tWatch->Branch("tTrkNuc",&trkWatch.tTrkNuc,"tTrkNuc/F"); |
| 298 |
|
| 299 |
|
| 300 |
} |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
}; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
// ------------------------------------------- |
| 311 |
// define runs to be processed/reprocessed |
| 312 |
// ------------------------------------------- |
| 313 |
if(run == 0){ |
| 314 |
// reprocessing ALL runs |
| 315 |
if(p->standalone)throw -298; // reprocessing not implemented |
| 316 |
from_run = runlist->At(0); |
| 317 |
to_run = runlist->At(runinfo->GetRunEntries()-1); |
| 318 |
}else{ |
| 319 |
// processing/reprocessing ONE single run |
| 320 |
from_run = run; |
| 321 |
to_run = run; |
| 322 |
}; |
| 323 |
|
| 324 |
// |
| 325 |
// init event counter |
| 326 |
// |
| 327 |
Int_t ev_count =0; |
| 328 |
Int_t pr_count =0; |
| 329 |
// |
| 330 |
// create query-results objects |
| 331 |
// |
| 332 |
GL_RUN q1 = GL_RUN(); |
| 333 |
GL_TRK_CALIB q2 = GL_TRK_CALIB(); |
| 334 |
GL_ROOT q3 = GL_ROOT(); |
| 335 |
GL_PARAM q4 = GL_PARAM(); |
| 336 |
|
| 337 |
// ------------------------------------------------------------ |
| 338 |
// if reprocessing one run, copy all the events BEFORE the run |
| 339 |
// ------------------------------------------------------------ |
| 340 |
if( !(p->standalone) ){ |
| 341 |
if(TrkParams::VerboseMode()) cout << " Reprocessing one run: "<<run<< endl; |
| 342 |
for(UInt_t i=0; i<runinfo->GetFirstEntry(); i++){ |
| 343 |
if ( t_clone->GetEntry(i) <= 0 ) throw -36;// EM |
| 344 |
// COPY COPY COPY |
| 345 |
*l2_event = *l2_clone; |
| 346 |
t_level2->Fill(); |
| 347 |
l2_event->Clear(); |
| 348 |
}; |
| 349 |
}; |
| 350 |
// ------------------------------------------------------------ |
| 351 |
// ------------------------------------------------------------ |
| 352 |
// START LOOP OVER RUNS TO PROCESS/REPROCESS |
| 353 |
// ------------------------------------------------------------ |
| 354 |
// ------------------------------------------------------------ |
| 355 |
for(UInt_t idRun = from_run; idRun <= to_run; idRun++){ |
| 356 |
|
| 357 |
if(TrkParams::VerboseMode()) cout << endl<<" ========================= Run: "<< idRun << endl; |
| 358 |
UInt_t runheadtime = 0; |
| 359 |
UInt_t runtrailtime = 0; |
| 360 |
UInt_t runheadobt = 0; |
| 361 |
UInt_t runtrailobt = 0; |
| 362 |
UInt_t abstime = 0; |
| 363 |
UInt_t evfrom = 0; |
| 364 |
UInt_t evto = 0; |
| 365 |
UInt_t nevents = 0; |
| 366 |
Int_t id_root_l0 =-1; |
| 367 |
Int_t trk_calib_used = 0; |
| 368 |
|
| 369 |
TString host = glt->CGetHost(); // EMILIANO |
| 370 |
TString user = glt->CGetUser(); // EMILIANO |
| 371 |
TString psw = glt->CGetPsw(); // EMILIANO |
| 372 |
// TString host = "mysql://localhost/pamelaprod"; |
| 373 |
// TString user = "anonymous"; |
| 374 |
// TString psw = ""; |
| 375 |
// const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
| 376 |
// const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
| 377 |
// const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
| 378 |
// if ( !pamdbhost ) pamdbhost = ""; |
| 379 |
// if ( !pamdbuser ) pamdbuser = ""; |
| 380 |
// if ( !pamdbpsw ) pamdbpsw = ""; |
| 381 |
// if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
| 382 |
// if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
| 383 |
// if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
| 384 |
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 385 |
stringstream myquery; // EMILIANO |
| 386 |
myquery.str(""); // EMILIANO |
| 387 |
myquery << "SET time_zone='+0:00';"; // EMILIANO |
| 388 |
delete dbc->Query(myquery.str().c_str()); // EMILIANO |
| 389 |
delete dbc->Query("SET sql_mode = 'NO_UNSIGNED_SUBTRACTION';");// EM |
| 390 |
if(p->standalone){ |
| 391 |
// ============================== |
| 392 |
// first query: retrieve run info |
| 393 |
// ============================== |
| 394 |
if (q1.Query_GL_RUN(idRun,dbc) )throw -50; |
| 395 |
id_root_l0 = q1.ID_ROOT_L0; |
| 396 |
runheadtime = q1.RUNHEADER_TIME; |
| 397 |
runtrailtime = q1.RUNTRAILER_TIME; |
| 398 |
runheadobt = q1.RUNHEADER_OBT; |
| 399 |
runtrailobt = q1.RUNTRAILER_OBT; |
| 400 |
evfrom = q1.EV_FROM; |
| 401 |
evto = q1.EV_TO; |
| 402 |
nevents = q1.NEVENTS; |
| 403 |
trk_calib_used = q1.TRK_CALIB_USED; |
| 404 |
}else{ |
| 405 |
// ============================== |
| 406 |
// get run info from RunInfo tree |
| 407 |
// ============================== |
| 408 |
int runinfo_error = runinfo->GetRunInfo(idRun); |
| 409 |
if( runinfo_error ) throw runinfo_error; |
| 410 |
id_root_l0 = runinfo->ID_ROOT_L0; |
| 411 |
runheadtime = runinfo->RUNHEADER_TIME; |
| 412 |
runtrailtime = runinfo->RUNTRAILER_TIME; |
| 413 |
runheadobt = runinfo->RUNHEADER_OBT; |
| 414 |
runtrailobt = runinfo->RUNTRAILER_OBT; |
| 415 |
evfrom = runinfo->EV_FROM; |
| 416 |
evto = runinfo->EV_TO; |
| 417 |
nevents = runinfo->NEVENTS; |
| 418 |
trk_calib_used = runinfo->TRK_CALIB_USED; |
| 419 |
|
| 420 |
}; |
| 421 |
|
| 422 |
// |
| 423 |
if(TrkParams::VerboseMode()){ |
| 424 |
cout << "ROOT file ID "<< id_root_l0 << endl; |
| 425 |
cout << "RunHeader time "<< runheadtime << endl; |
| 426 |
cout << "RunTrailer time "<< runtrailtime << endl; |
| 427 |
cout << " from event "<< evfrom << endl; |
| 428 |
cout << " to event "<< evto << endl; |
| 429 |
cout << " num. events "<< nevents << endl; |
| 430 |
cout << "trk-calibration used "<< trk_calib_used << endl; |
| 431 |
}; |
| 432 |
// ======================================================== |
| 433 |
// second query: search the LEVEL0 file that contains idRun |
| 434 |
// ======================================================== |
| 435 |
TString lastfilename = filename; |
| 436 |
if( q3.Query_GL_ROOT(id_root_l0,dbc) )throw -51; |
| 437 |
filename = q3.PATH + q3.NAME; |
| 438 |
// ======================================================== |
| 439 |
// Open the input LEVEL0 data file |
| 440 |
// ======================================================== |
| 441 |
if(filename.CompareTo(lastfilename)){ |
| 442 |
if(!lastfilename.IsNull())f0->Close(); |
| 443 |
//if( debug ) cout << "Opening LEVEL0 file: "<< filename << endl; |
| 444 |
if(TrkParams::VerboseMode()) cout << "Opening LEVEL0 file: "<< filename << endl; |
| 445 |
FileStat_t t; |
| 446 |
if( gSystem->GetPathInfo(filename.Data(),t) )throw -6; |
| 447 |
if ( f0 ) f0->Close(); |
| 448 |
f0 = new TFile(filename); |
| 449 |
if ( !f0 ) throw -6; |
| 450 |
physicsTree = (TTree*)f0->Get("Physics"); if(!physicsTree) throw -7; |
| 451 |
b_header = physicsTree ->GetBranch("Header"); if(!b_header ) throw -8; |
| 452 |
b_trk = physicsTree ->GetBranch("Tracker"); if(!b_trk ) throw -203; |
| 453 |
l0_event->Set(); |
| 454 |
physicsTree->SetBranchAddress("Tracker" ,l0_event->GetPointerToTrackerEvent()); |
| 455 |
physicsTree->SetBranchAddress("Header",&header); |
| 456 |
|
| 457 |
nentries = physicsTree->GetEntries(); |
| 458 |
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 |
| 459 |
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 |
| 460 |
// 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 |
| 461 |
// the condition ( nentries < (evto+1) ) is satisfied and DV exit with error even if the error is only in the DB. |
| 462 |
|
| 463 |
}; |
| 464 |
|
| 465 |
GL_TIMESYNC *dbtime = new GL_TIMESYNC(id_root_l0,"ID",dbc); |
| 466 |
|
| 467 |
|
| 468 |
// ============================================================= |
| 469 |
// retrieve information about parameters to process LEVEL2 |
| 470 |
// ============================================================= |
| 471 |
|
| 472 |
TrkParams::Set(runinfo->GetGL_RUN(),dbc); |
| 473 |
for(int i=0; i<p->npar; i++){ |
| 474 |
if(TrkParams::VerboseMode())cout<<" ((( force parameters from input path )))"<<endl; |
| 475 |
TrkParams::Set(p->parpath[i],p->partype[i]); |
| 476 |
} |
| 477 |
|
| 478 |
TrkParams::Load(); |
| 479 |
if( !TrkParams::IsLoaded() )throw -52; |
| 480 |
|
| 481 |
// ============================================================= |
| 482 |
// retrieve calibration file needed to reduce data |
| 483 |
// ============================================================= |
| 484 |
|
| 485 |
TrkParams::SetCalib(runinfo->GetGL_RUN(),dbc); |
| 486 |
TrkParams::LoadCalib( ); |
| 487 |
if( !TrkParams::CalibIsLoaded() )throw -53; |
| 488 |
|
| 489 |
TBenchmark *reduction = new TBenchmark(); |
| 490 |
if(TrkParams::VerboseMode())reduction->Start("reduction"); |
| 491 |
Int_t ntrk=0; |
| 492 |
// ==================================================== |
| 493 |
// start looping on events cointained in the data file |
| 494 |
// ==================================================== |
| 495 |
if ( TrkParams::GetSimuFlag() ){ |
| 496 |
abstime = runheadtime; |
| 497 |
} else { |
| 498 |
if(dbc){ |
| 499 |
dbc->Close(); |
| 500 |
delete dbc; |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
ev_count =0; // EM, ev_count must be cleared before processing a run (to be consistent when/if reprocessing) |
| 505 |
pr_count =0; |
| 506 |
|
| 507 |
for (UInt_t re = evfrom+min(p->nskip,nevents); re < evfrom+nevents; re++){ |
| 508 |
|
| 509 |
ev_count++; |
| 510 |
|
| 511 |
// |
| 512 |
// NBNB check if events are aligned!!!!!!!!!!! |
| 513 |
// |
| 514 |
|
| 515 |
/* if(p->gete){ 10RED BUG: unsync with calo and tof... |
| 516 |
int iev = 0; |
| 517 |
int jumped = 0; |
| 518 |
iev = runinfo->GetFirstEntry() + (re - evfrom -jumped); |
| 519 |
if ( t_cal->GetEntry(iev) <= 0 ) throw -36;//EV |
| 520 |
if ( t_tof->GetEntry(iev) <= 0 ) throw -36;//EV |
| 521 |
} // EMI AAAAGGH COSI` NO! |
| 522 |
*/ |
| 523 |
// if ( TrkParams::DebugMode() && re%100 == 0 && re > 0 ) cout << "."; |
| 524 |
|
| 525 |
if ( b_trk->GetEntry(re) <= 0 ) throw -36;//EM |
| 526 |
if ( b_header->GetEntry(re) <= 0 ) throw -36;//EM |
| 527 |
pscu = header->GetPscuHeader(); |
| 528 |
|
| 529 |
// ============================================================= |
| 530 |
// The following 6 lines have been moved here by VALERIO. |
| 531 |
if(TrkParams::GetSimuFlag()){ |
| 532 |
abstime = runheadtime + (int) floor(0.03*(re-evfrom)); //If simulated data we need to assign a fake abstime. 30ms between each event. |
| 533 |
if(TrkParams::VerboseMode())cout << "Event: " << re-evfrom << " - Attempting to retrieve Mask Info for abstime=" << abstime << endl; |
| 534 |
if(!TrkParams::Set(runinfo->GetGL_RUN(),dbc,6,abstime))throw -52; // Setting to load mask (VALERIO) |
| 535 |
TrkParams::Load(6); |
| 536 |
if( !TrkParams::IsLoaded() )throw -52; |
| 537 |
if(TrkParams::VerboseMode())cout << "Mask Info for abstime=" << abstime << " retrieved" << endl; |
| 538 |
} |
| 539 |
|
| 540 |
if( TrkParams::DebugMode() )cout << ">>> "<<ev_count-1<<" @ OBT "<<pscu->GetOrbitalTime()<<endl; |
| 541 |
|
| 542 |
if ( dbtime->DBabsTime(pscu->GetOrbitalTime()) > (runtrailtime+1) || dbtime->DBabsTime(pscu->GetOrbitalTime()) < (runheadtime-1)) { |
| 543 |
|
| 544 |
if (TrkParams::VerboseMode()){ |
| 545 |
printf(" TrkCore - WARNING: event outside the run time window, skipping it\n"); |
| 546 |
cout << " OBT "<<pscu->GetOrbitalTime()<<" RUN "<<runheadobt<<"-"<<runtrailobt<<" ABS-time "<<dbtime->DBabsTime(pscu->GetOrbitalTime())<<" RUN "<<runheadtime<<"-"<<runtrailtime<<endl; |
| 547 |
}; |
| 548 |
}else{ |
| 549 |
if ( TrkParams::DebugMode() ) |
| 550 |
printf("\n-------------------------------\nevent %d\n",re-evfrom); |
| 551 |
|
| 552 |
if(p->gete){ // must stay here to avoid losing sync with calo and tof in case of skipped events outside time window |
| 553 |
int iev = 0; |
| 554 |
iev = runinfo->GetFirstEntry() + pr_count; |
| 555 |
if ( t_cal->GetEntry(iev) <= 0 ){ |
| 556 |
if (TrkParams::VerboseMode()) printf(" %i %i %i %i \n",iev,runinfo->GetFirstEntry(), pr_count ,evfrom); |
| 557 |
if ( TrkParams::VerboseMode() ) printf("\n missing calorimeter entry! \n"); |
| 558 |
throw -36;//EV |
| 559 |
} |
| 560 |
if ( t_tof->GetEntry(iev) <= 0 ){ |
| 561 |
if (TrkParams::VerboseMode()) printf(" %i %i %i %i \n",iev,runinfo->GetFirstEntry(), pr_count ,evfrom); |
| 562 |
if ( TrkParams::VerboseMode() ) printf("\n missing tof entry! \n"); |
| 563 |
throw -36;//EV |
| 564 |
} |
| 565 |
} |
| 566 |
pr_count++; |
| 567 |
//============================================= |
| 568 |
// EVENT PROCESSING |
| 569 |
//============================================= |
| 570 |
TStopwatch w; |
| 571 |
// cout << " -------------------------------------------------------------------------"<<endl; |
| 572 |
|
| 573 |
// ---------------------------------------------- |
| 574 |
// default tracking |
| 575 |
// ---------------------------------------------- |
| 576 |
if(tWatch)w.Start(); |
| 577 |
|
| 578 |
p->ProcessEvent(l0_event);//call f77 routine |
| 579 |
|
| 580 |
if(tWatch)w.Stop(); |
| 581 |
if(tWatch)trkWatch.tTrk = (float) w.CpuTime(); |
| 582 |
// if(tWatch)cout << " t."<<trkWatch.tTrk<<endl; |
| 583 |
|
| 584 |
|
| 585 |
// // ---------------- |
| 586 |
// // LEVEL1 output |
| 587 |
// // ---------------- |
| 588 |
l1_event->Clear(); |
| 589 |
l1_event->SetFromLevel1Struct(); |
| 590 |
|
| 591 |
// ---------------- |
| 592 |
// HOUGH output |
| 593 |
// ---------------- |
| 594 |
if(p->geth){ |
| 595 |
if(p->ifrooth){ // root |
| 596 |
lh_event->Delete(); |
| 597 |
lh_event->SetFromHoughStruct(&houghevent_); |
| 598 |
}else{ // hbook |
| 599 |
throw -299; |
| 600 |
}; |
| 601 |
}; |
| 602 |
|
| 603 |
// // ---------------- |
| 604 |
// // LEVEL2 output |
| 605 |
// // ---------------- |
| 606 |
l2_event->Clear(); |
| 607 |
if(p->get1){ |
| 608 |
l2_event->SetFromLevel2Struct(&level2event_,l1_event);//set references to level1 |
| 609 |
}else{ |
| 610 |
l2_event->SetFromLevel2Struct(&level2event_); |
| 611 |
} |
| 612 |
|
| 613 |
if( l2_event->ntrk()>0 )ntrk++; |
| 614 |
if(TrkParams::VerboseMode())l2_event->Dump(); |
| 615 |
|
| 616 |
|
| 617 |
//---------------------------------------------- |
| 618 |
// verify conditions to apply extended algorythm |
| 619 |
//---------------------------------------------- |
| 620 |
bool APPLY_EXTENDED = false; |
| 621 |
extAlgFlag = 0; // EM: this is the standard situation, extAlgFlag must be set to zero here. It does not garantuee you have an extended track, it just states |
| 622 |
// that if there were no standard tracks the extended algorithm is used. If not cleared and if there is at least one standard track |
| 623 |
// extAlgFlag retains the previous value that could be DIFFERENT from zero if the previous event was a check event... |
| 624 |
if( |
| 625 |
p->gete && //input flag set |
| 626 |
true){ |
| 627 |
|
| 628 |
// regular condition for extended processing |
| 629 |
if(l2_event->ntrk()==0){ |
| 630 |
APPLY_EXTENDED = true; |
| 631 |
extAlgFlag = 1; // EM: meaning of extAlgFlag changed: 0 if not used, 1 if used, 2 if used for cross-check, 3 used for cross-check and no std tracks |
| 632 |
} |
| 633 |
// extended algorythm applied for cross-check |
| 634 |
if(p->gete_ncheck>0 && ev_count%p->gete_ncheck==0){ |
| 635 |
APPLY_EXTENDED = true; |
| 636 |
extAlgFlag = 2; // EM read above |
| 637 |
if(l2_event->ntrk()==0) extAlgFlag = 3; // EM make it easier to recognize events with no standard tracks AND forced extended algorithm // EM read above |
| 638 |
} |
| 639 |
|
| 640 |
} |
| 641 |
|
| 642 |
// cout << re<<" ev_count "<<ev_count<<" apply extended "<<APPLY_EXTENDED<<" flag "<<extAlgFlag<<endl; |
| 643 |
|
| 644 |
if(tWatch)w.Start(); |
| 645 |
|
| 646 |
// ------------------ |
| 647 |
// extended-tracking |
| 648 |
// ------------------ |
| 649 |
trkAlg->Clear(); |
| 650 |
if(APPLY_EXTENDED){ |
| 651 |
|
| 652 |
// //---------------------------- |
| 653 |
// // check conditions |
| 654 |
// //---------------------------- |
| 655 |
// if( |
| 656 |
// l2_event->ntrk()==0 && |
| 657 |
// l1_event->nclstr()<24 && |
| 658 |
// true){ |
| 659 |
|
| 660 |
trkAlg->SetDebug(false); |
| 661 |
trkAlg->SetTrkLevel2(l2_event); |
| 662 |
trkAlg->SetTrkLevel1(l1_event); |
| 663 |
trkAlg->SetCaloLevel1(cl1); |
| 664 |
trkAlg->SetToFLevel2(tl2); |
| 665 |
// trkAlg->Dump(); |
| 666 |
trkAlg->ProcessEvent(); |
| 667 |
|
| 668 |
// } |
| 669 |
} |
| 670 |
|
| 671 |
if(tWatch)w.Stop(); |
| 672 |
if(tWatch)trkWatch.tTrkExt = (float) w.CpuTime(); |
| 673 |
// if(tWatch)cout << " t."<<trkWatch.tTrkExt<<endl; |
| 674 |
|
| 675 |
|
| 676 |
if(p->getn){ |
| 677 |
|
| 678 |
if(tWatch)w.Start(); |
| 679 |
|
| 680 |
l1_event_nuclei->Clear(); |
| 681 |
l1_event_nuclei->Set(l1_event,5.,0.2);//apply a cut |
| 682 |
l1_event_nuclei->GetLevel1Struct();//from cleaned l1 object, to f77 common |
| 683 |
l1_event_nuclei->ProcessEvent(); // default routine |
| 684 |
l2_event_nuclei->Clear(); |
| 685 |
l2_event_nuclei->SetFromLevel2Struct(); // from f77 common to l2 object |
| 686 |
|
| 687 |
|
| 688 |
trkAlg_nuclei->Clear(); |
| 689 |
|
| 690 |
if(APPLY_EXTENDED){ |
| 691 |
|
| 692 |
trkAlg_nuclei->SetDebug(false); |
| 693 |
trkAlg_nuclei->SetTrkLevel2( l2_event_nuclei ); |
| 694 |
trkAlg_nuclei->SetTrkLevel1( l1_event_nuclei );//cleaned level1 |
| 695 |
trkAlg_nuclei->SetCaloLevel1( cl1 ); |
| 696 |
trkAlg_nuclei->SetToFLevel2( tl2 ); |
| 697 |
trkAlg_nuclei->ProcessEvent(); |
| 698 |
} |
| 699 |
|
| 700 |
if(tWatch)w.Stop(); |
| 701 |
if(tWatch)trkWatch.tTrkNuc = (float) w.CpuTime(); |
| 702 |
// if(tWatch)cout << " t."<<trkWatch.tTrkNuc<<endl; |
| 703 |
|
| 704 |
} |
| 705 |
|
| 706 |
|
| 707 |
// if( l1_event->nclstr() > 15 && trkAlg->GetTrackArray()->GetEntries()>0){ |
| 708 |
|
| 709 |
// if(l1_event)cout<<" std n.cl "<<l1_event->nclstr(); |
| 710 |
// if(l2_event)cout<<" n.tr "<<l2_event->GetNTracks() ; |
| 711 |
// if(trkAlg)cout<<" ext "<<trkAlg->GetTrackArray()->GetEntries(); |
| 712 |
// cout<<endl; |
| 713 |
|
| 714 |
// trkAlg->SetDebug(true); |
| 715 |
// trkAlg->CheckEvent(); |
| 716 |
// trkAlg->SetDebug(false); |
| 717 |
|
| 718 |
|
| 719 |
// } |
| 720 |
|
| 721 |
// if( l1_event_nuclei->nclstr() <3 && trkAlg_nuclei->GetTrackArray()->GetEntries()>0){ |
| 722 |
// if(l1_event_nuclei)cout<<" nuc n.cl "<<l1_event_nuclei->nclstr(); |
| 723 |
// if(l2_event_nuclei)cout<<" n.tr "<<l2_event_nuclei->GetNTracks() ; |
| 724 |
// if(trkAlg_nuclei)cout<<" ext "<<trkAlg_nuclei->GetTrackArray()->GetEntries(); |
| 725 |
// cout<<endl; |
| 726 |
// trkAlg_nuclei->SetDebug(true); |
| 727 |
// trkAlg_nuclei->CheckEvent(); |
| 728 |
// trkAlg_nuclei->SetDebug(false); |
| 729 |
// } |
| 730 |
|
| 731 |
///////////////////// |
| 732 |
// ==== FILL ===== // |
| 733 |
///////////////////// |
| 734 |
t_level2->Fill(); |
| 735 |
|
| 736 |
if(tWatch){ |
| 737 |
|
| 738 |
trkWatch.nCl = (l1_event ? l1_event->nclstr() :0); |
| 739 |
trkWatch.nClCut = (l1_event_nuclei ? l1_event_nuclei->nclstr() :0); |
| 740 |
|
| 741 |
|
| 742 |
trkWatch.nTrk = (l2_event ? l2_event->GetNTracks() :0); |
| 743 |
trkWatch.nTrkNuc = (l2_event_nuclei ? l2_event_nuclei->GetNTracks() :0); |
| 744 |
|
| 745 |
trkWatch.nTrkExt = ( trkAlg ? trkAlg->GetTrackArray()->GetEntries() : 0); |
| 746 |
trkWatch.nTrkExtNuc = ( trkAlg_nuclei ? trkAlg_nuclei->GetTrackArray()->GetEntries() : 0); |
| 747 |
|
| 748 |
if(TrkParams::VerboseMode())trkWatch.Dump(); |
| 749 |
|
| 750 |
|
| 751 |
tWatch->Fill(); |
| 752 |
} |
| 753 |
|
| 754 |
}; |
| 755 |
}; // end loop on events |
| 756 |
if(TrkParams::VerboseMode()){ |
| 757 |
cout << " >>> processed "<< ev_count <<" events"<< endl; |
| 758 |
if(ev_count)cout << ntrk << " events with at least one track ("<<(Int_t)(100*ntrk/ev_count)<<"%)\n"; |
| 759 |
reduction->Show("reduction"); |
| 760 |
} |
| 761 |
delete reduction; |
| 762 |
|
| 763 |
delete dbtime; |
| 764 |
|
| 765 |
}; // end loop on runs |
| 766 |
|
| 767 |
|
| 768 |
// ------------------------------------------------------------ |
| 769 |
// if reprocessing one run, copy all the events AFTER the run |
| 770 |
// ------------------------------------------------------------ |
| 771 |
if( !(p->standalone) ){ |
| 772 |
if(TrkParams::VerboseMode()) cout << " Reprocessing one run: "<<run<< " copy all events AFTER the run"<< endl; |
| 773 |
for(UInt_t i=runinfo->GetLastEntry()+1; i<runinfo->GetFileEntries(); i++){ |
| 774 |
if ( t_clone->GetEntry(i) <= 0 ) throw -36;//EM |
| 775 |
*l2_event = *l2_clone; |
| 776 |
// COPY COPY COPY |
| 777 |
t_level2->Fill(); |
| 778 |
l2_event->Clear(); |
| 779 |
}; |
| 780 |
}; |
| 781 |
// --------------- |
| 782 |
// close the files |
| 783 |
// --------------- |
| 784 |
if(p->get2){ |
| 785 |
if(TrkParams::VerboseMode()) cout << " Writing and closing the files, t_level2 "<< t_level2<< endl; |
| 786 |
f2->cd(); |
| 787 |
// if(tWatch){ |
| 788 |
// if(tWatch)f2->Write("TrkWatch",TObject::kOverwrite); |
| 789 |
// } |
| 790 |
// f2->Write("Tracker", TObject::kOverwrite); |
| 791 |
// if( t_level2 )t_level2->Write(); |
| 792 |
|
| 793 |
if( t_clone )t_clone->Delete("all");//delete old tree from file |
| 794 |
|
| 795 |
if( t_level2 )t_level2->SetName("Tracker"); |
| 796 |
if( t_level2 )t_level2->Write("Tracker",TObject::kOverwrite); |
| 797 |
if( t_level2 )t_level2->Delete(); //delete new tree from memory |
| 798 |
|
| 799 |
if( !(p->standalone) )runinfo->Close(); |
| 800 |
if(tWatch)tWatch->Write(); |
| 801 |
|
| 802 |
}; |
| 803 |
|
| 804 |
|
| 805 |
if(f0) if(f0->IsOpen()) f0->Close(); |
| 806 |
|
| 807 |
l1_event->Delete(); |
| 808 |
l2_event->Delete(); |
| 809 |
l2_clone->Delete(); |
| 810 |
|
| 811 |
|
| 812 |
return(p->ostatus); |
| 813 |
} |
| 814 |
|