| 1 | mocchiut | 1.1 | // | 
| 2 |  |  | // C/C++ headers | 
| 3 |  |  | // | 
| 4 |  |  | #include <fstream> | 
| 5 |  |  | #include <string.h> | 
| 6 |  |  | // | 
| 7 |  |  | // ROOT headers | 
| 8 |  |  | // | 
| 9 |  |  | #include <TTree.h> | 
| 10 |  |  | #include <TClassEdit.h> | 
| 11 |  |  | #include <TObject.h> | 
| 12 |  |  | #include <TList.h> | 
| 13 | mocchiut | 1.6 | #include <TArrayI.h> | 
| 14 | mocchiut | 1.1 | #include <TSystem.h> | 
| 15 |  |  | #include <TSystemDirectory.h> | 
| 16 |  |  | #include <TString.h> | 
| 17 |  |  | #include <TFile.h> | 
| 18 |  |  | #include <TClass.h> | 
| 19 |  |  | #include <TCanvas.h> | 
| 20 |  |  | #include <TH1.h> | 
| 21 |  |  | #include <TH1F.h> | 
| 22 |  |  | #include <TH2D.h> | 
| 23 |  |  | #include <TLatex.h> | 
| 24 |  |  | #include <TPad.h> | 
| 25 |  |  | #include <TSQLServer.h> | 
| 26 |  |  | #include <TSQLRow.h> | 
| 27 |  |  | #include <TSQLResult.h> | 
| 28 |  |  | #include <TClonesArray.h> | 
| 29 |  |  | // | 
| 30 | mocchiut | 1.16 | // RunInfo header | 
| 31 |  |  | // | 
| 32 |  |  | #include <RunInfo.h> | 
| 33 |  |  | // | 
| 34 | mocchiut | 1.1 | // YODA headers | 
| 35 |  |  | // | 
| 36 |  |  | #include <PamelaRun.h> | 
| 37 |  |  | #include <physics/trigger/TriggerEvent.h> | 
| 38 |  |  | #include <physics/tof/TofEvent.h> | 
| 39 |  |  | // | 
| 40 |  |  | // This program headers | 
| 41 |  |  | // | 
| 42 |  |  | #include <ToFCore.h> | 
| 43 |  |  | #include <ToFLevel2.h> | 
| 44 |  |  | #include <ToFVerl2.h> | 
| 45 |  |  | // | 
| 46 |  |  | // | 
| 47 |  |  | // Declaration of the core fortran routines | 
| 48 |  |  | // | 
| 49 |  |  | #define tofl2com tofl2com_ | 
| 50 |  |  | extern "C" int tofl2com(); | 
| 51 |  |  | #define toftrk toftrk_ | 
| 52 |  |  | extern "C" int toftrk(); | 
| 53 |  |  | #define rdtofcal rdtofcal_ | 
| 54 | mocchiut | 1.9 | extern "C" int rdtofcal(char [], int *); | 
| 55 | mocchiut | 1.1 |  | 
| 56 |  |  | // | 
| 57 |  |  | // Tracker classes headers and definitions | 
| 58 |  |  | // | 
| 59 |  |  | #include <TrkLevel2.h> | 
| 60 |  |  | // | 
| 61 |  |  | using namespace std; | 
| 62 |  |  | // | 
| 63 |  |  | // | 
| 64 |  |  | // CORE ROUTINE | 
| 65 |  |  | // | 
| 66 |  |  | // | 
| 67 | mocchiut | 1.6 | int ToFCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t ToFargc, char *ToFargv[]){ | 
| 68 | mocchiut | 1.1 | // | 
| 69 |  |  | // | 
| 70 |  |  | // Set these to true to have a very verbose output. | 
| 71 |  |  | // | 
| 72 |  |  | Bool_t verbose = false; | 
| 73 |  |  | Bool_t debug = false; | 
| 74 |  |  | // | 
| 75 | mocchiut | 1.19 | TString processFolder = Form("ToFFolder_%u",run); | 
| 76 | mocchiut | 1.1 | if ( ToFargc > 0 ){ | 
| 77 |  |  | Int_t i = 0; | 
| 78 |  |  | while ( i < ToFargc ){ | 
| 79 |  |  | if ( !strcmp(ToFargv[i],"-processFolder") ) { | 
| 80 |  |  | if ( ToFargc < i+1 ){ | 
| 81 |  |  | throw -3; | 
| 82 |  |  | }; | 
| 83 |  |  | processFolder = (TString)ToFargv[i+1]; | 
| 84 |  |  | i++; | 
| 85 |  |  | }; | 
| 86 | mocchiut | 1.20 | if ( !strcmp(ToFargv[i],"-v") ||  !strcmp(ToFargv[i],"--verbose") ) { | 
| 87 | mocchiut | 1.1 | verbose = true; | 
| 88 | mocchiut | 1.20 | }; | 
| 89 | mocchiut | 1.1 | if ( !strcmp(ToFargv[i],"-g") ||  !strcmp(ToFargv[i],"--debug") ) { | 
| 90 | mocchiut | 1.18 | verbose = true; | 
| 91 | mocchiut | 1.1 | debug = true; | 
| 92 |  |  | }; | 
| 93 |  |  | i++; | 
| 94 |  |  | }; | 
| 95 |  |  | }; | 
| 96 |  |  | // | 
| 97 |  |  | // | 
| 98 |  |  | // Output directory is the working directoy. | 
| 99 |  |  | // | 
| 100 |  |  | const char* outdir = gSystem->DirName(gSystem->DirName(file->GetPath())); | 
| 101 |  |  | // | 
| 102 |  |  | // Variables for level2 | 
| 103 |  |  | // | 
| 104 |  |  | TTree *tracker = 0; | 
| 105 |  |  | TTree *toft = 0; | 
| 106 | mocchiut | 1.6 | UInt_t nevents = 0; | 
| 107 | mocchiut | 1.15 | Long64_t maxsize = 10000000000LL; | 
| 108 |  |  | TTree::SetMaxTreeSize(maxsize); | 
| 109 | mocchiut | 1.1 | // | 
| 110 |  |  | // variables needed to reprocess data | 
| 111 |  |  | // | 
| 112 |  |  | TString tofversion; | 
| 113 |  |  | ItoRunInfo *runinfo = 0; | 
| 114 | mocchiut | 1.6 | TArrayI *runlist = 0; | 
| 115 | mocchiut | 1.1 | TTree *toftclone = 0; | 
| 116 |  |  | Bool_t reproc = false; | 
| 117 |  |  | Bool_t reprocall = false; | 
| 118 |  |  | UInt_t nobefrun = 0; | 
| 119 |  |  | UInt_t noaftrun = 0; | 
| 120 |  |  | UInt_t numbofrun = 0; | 
| 121 |  |  | stringstream ftmpname; | 
| 122 |  |  | TString fname; | 
| 123 | mocchiut | 1.6 | UInt_t totfileentries = 0; | 
| 124 |  |  | UInt_t idRun = 0; | 
| 125 | mocchiut | 1.1 | // | 
| 126 |  |  | // variables needed to handle error signals | 
| 127 |  |  | // | 
| 128 |  |  | Int_t code = 0; | 
| 129 |  |  | Int_t sgnl; | 
| 130 |  |  | // | 
| 131 |  |  | // tof level2 classes | 
| 132 |  |  | // | 
| 133 |  |  | ToFLevel2 *tof = new ToFLevel2(); | 
| 134 |  |  | ToFLevel2 *tofclone = new ToFLevel2(); | 
| 135 |  |  | // | 
| 136 |  |  | // tracker level2 variables | 
| 137 |  |  | // | 
| 138 |  |  | TrkLevel2 *trk = new TrkLevel2(); | 
| 139 | mocchiut | 1.6 | Int_t nevtrkl2 = 0; | 
| 140 | mocchiut | 1.1 | // | 
| 141 |  |  | // define variables for opening and reading level0 file | 
| 142 |  |  | // | 
| 143 |  |  | TFile *l0File = 0; | 
| 144 |  |  | TTree *l0tr = 0; | 
| 145 |  |  | TBranch *l0head = 0; | 
| 146 |  |  | TBranch *l0trig = 0; | 
| 147 |  |  | TBranch *l0tof = 0; | 
| 148 | mocchiut | 1.6 | pamela::EventHeader *eh = 0; | 
| 149 |  |  | pamela::PscuHeader *ph = 0; | 
| 150 | mocchiut | 1.1 | pamela::trigger::TriggerEvent *trig = 0; | 
| 151 |  |  | pamela::tof::TofEvent *tofEvent = 0; | 
| 152 |  |  | // | 
| 153 |  |  | // Define other basic variables | 
| 154 |  |  | // | 
| 155 |  |  | UInt_t procev = 0; | 
| 156 |  |  | stringstream file2; | 
| 157 |  |  | stringstream file3; | 
| 158 |  |  | stringstream qy; | 
| 159 |  |  | Int_t itr = -1; | 
| 160 |  |  | Int_t totevent = 0; | 
| 161 | mocchiut | 1.6 | UInt_t atime = 0; | 
| 162 |  |  | UInt_t re = 0; | 
| 163 | mocchiut | 1.7 | UInt_t jumped = 0; | 
| 164 | mocchiut | 1.1 | // | 
| 165 |  |  | // Working filename | 
| 166 |  |  | // | 
| 167 |  |  | TString outputfile; | 
| 168 |  |  | stringstream name; | 
| 169 |  |  | name.str(""); | 
| 170 |  |  | name << outdir << "/"; | 
| 171 |  |  | // | 
| 172 |  |  | // temporary file and folder | 
| 173 |  |  | // | 
| 174 |  |  | TFile *tempfile = 0; | 
| 175 |  |  | TTree *temptof = 0; | 
| 176 |  |  | stringstream tempname; | 
| 177 |  |  | stringstream toffolder; | 
| 178 | mocchiut | 1.25 | Bool_t myfold = false; | 
| 179 | mocchiut | 1.1 | tempname.str(""); | 
| 180 |  |  | tempname << outdir; | 
| 181 |  |  | tempname << "/" << processFolder.Data(); | 
| 182 |  |  | toffolder.str(""); | 
| 183 |  |  | toffolder << tempname.str().c_str(); | 
| 184 |  |  | tempname << "/toftree_run"; | 
| 185 |  |  | tempname << run << ".root"; | 
| 186 |  |  | // | 
| 187 |  |  | // variables needed to load magnetic field maps | 
| 188 |  |  | // | 
| 189 |  |  | Int_t ntrkentry = 0; | 
| 190 | mocchiut | 1.4 | Int_t npmtentry = 0; | 
| 191 | mocchiut | 1.6 | UInt_t tttrkpar1 = 0; | 
| 192 | mocchiut | 1.1 | Bool_t trkpar1 = true; | 
| 193 | mocchiut | 1.6 | UInt_t tttofpar1 = 0; | 
| 194 | mocchiut | 1.1 | Bool_t tofpar1 = true; | 
| 195 |  |  | // | 
| 196 |  |  | // DB classes | 
| 197 |  |  | // | 
| 198 |  |  | GL_ROOT *glroot = new GL_ROOT(); | 
| 199 |  |  | GL_PARAM *glparam = new GL_PARAM(); | 
| 200 | mocchiut | 1.6 | GL_TIMESYNC *dbtime = 0; | 
| 201 | mocchiut | 1.1 | // | 
| 202 |  |  | // declaring external output and input structures | 
| 203 |  |  | // | 
| 204 |  |  | extern struct ToFInput  tofinput_; | 
| 205 |  |  | extern struct ToFOutput tofoutput_; | 
| 206 |  |  | // | 
| 207 |  |  | // Let's start! | 
| 208 |  |  | // | 
| 209 |  |  | // | 
| 210 |  |  | // As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed | 
| 211 |  |  | // if run != 0 we must process only that run but first we have to check if the tree ToF already exist in the file | 
| 212 |  |  | // if it exists we are reprocessing data and we must delete that entries, if not we must create it. | 
| 213 |  |  | // | 
| 214 | mocchiut | 1.6 | if ( run == 0 )  reproc = true; | 
| 215 | mocchiut | 1.1 | // | 
| 216 |  |  | // | 
| 217 |  |  | // Output file is "outputfile" | 
| 218 |  |  | // | 
| 219 |  |  | if ( !file->IsOpen() ){ | 
| 220 |  |  | if ( verbose ) printf(" ToF - ERROR: cannot open file for writing\n"); | 
| 221 |  |  | throw -301; | 
| 222 |  |  | }; | 
| 223 |  |  | // | 
| 224 |  |  | // Does it contain the Tracker tree? | 
| 225 |  |  | // | 
| 226 |  |  | tracker = (TTree*)file->Get("Tracker"); | 
| 227 |  |  | if ( !tracker ) { | 
| 228 |  |  | if ( verbose ) printf(" TOF - ERROR: no tracker tree\n"); | 
| 229 |  |  | code = -302; | 
| 230 |  |  | goto closeandexit; | 
| 231 |  |  | }; | 
| 232 |  |  | // | 
| 233 |  |  | // get tracker level2 data pointer | 
| 234 |  |  | // | 
| 235 |  |  | tracker->SetBranchAddress("TrkLevel2",&trk); | 
| 236 |  |  | nevtrkl2 = tracker->GetEntries(); | 
| 237 |  |  | // | 
| 238 |  |  | // Retrieve GL_RUN variables from the level2 file | 
| 239 |  |  | // | 
| 240 |  |  | tofversion = ToFInfo(false); // we should decide how to handle versioning system | 
| 241 |  |  | // | 
| 242 |  |  | // create an interface to RunInfo called "runinfo" | 
| 243 |  |  | // | 
| 244 |  |  | // ItoRunInfo= interface with RunInfo and GL_RUN | 
| 245 |  |  | runinfo = new ItoRunInfo(file); | 
| 246 |  |  | // | 
| 247 |  |  | // open "Run" tree in level2 file, if not existing return an error (sngl != 0) | 
| 248 |  |  | // | 
| 249 |  |  | sgnl = 0; | 
| 250 |  |  | sgnl = runinfo->Update(run, "TOF",tofversion); | 
| 251 |  |  | if ( sgnl ){ | 
| 252 |  |  | if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n"); | 
| 253 |  |  | code = sgnl; | 
| 254 |  |  | goto closeandexit; | 
| 255 |  |  | } else { | 
| 256 |  |  | sgnl = 0; | 
| 257 |  |  | }; | 
| 258 |  |  | // | 
| 259 |  |  | // number of events in the file BEFORE the first event of our run | 
| 260 |  |  | // | 
| 261 |  |  | nobefrun = runinfo->GetFirstEntry(); | 
| 262 |  |  | // | 
| 263 |  |  | // total number of events in the file | 
| 264 |  |  | // | 
| 265 |  |  | totfileentries = runinfo->GetFileEntries(); | 
| 266 |  |  | // | 
| 267 |  |  | // first file entry AFTER the last event of our run | 
| 268 |  |  | // | 
| 269 |  |  | noaftrun = runinfo->GetLastEntry() + 1; | 
| 270 |  |  | // | 
| 271 |  |  | // number of run to be processed | 
| 272 |  |  | // | 
| 273 |  |  | numbofrun = runinfo->GetNoRun(); | 
| 274 | mocchiut | 1.21 | UInt_t totnorun = runinfo->GetRunEntries(); | 
| 275 | mocchiut | 1.1 | // | 
| 276 |  |  | // Try to access the ToF tree in the file, if it exists we are reprocessing data if not we are processing a new run | 
| 277 |  |  | // | 
| 278 |  |  | toftclone = (TTree*)file->Get("ToF"); | 
| 279 |  |  | // | 
| 280 |  |  | if ( !toftclone ){ | 
| 281 |  |  | // | 
| 282 |  |  | // tree does not exist, we are not reprocessing | 
| 283 |  |  | // | 
| 284 |  |  | reproc = false; | 
| 285 | mocchiut | 1.6 | if ( run == 0 && verbose ) printf(" ToF - WARNING: you are reprocessing data but ToF tree does not exist!\n"); | 
| 286 |  |  | if ( runinfo->IsReprocessing() && run != 0 && verbose ) printf(" ToF - WARNING: it seems you are not reprocessing data but ToF\n versioning information already exists in RunInfo.\n"); | 
| 287 | mocchiut | 1.1 |  | 
| 288 |  |  | } else { | 
| 289 |  |  | // | 
| 290 |  |  | // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? | 
| 291 |  |  | // | 
| 292 | mocchiut | 1.15 | toftclone->SetAutoSave(900000000000000LL); | 
| 293 | mocchiut | 1.1 | reproc = true; | 
| 294 |  |  | // | 
| 295 |  |  | // update versioning information | 
| 296 |  |  | // | 
| 297 |  |  | if ( verbose ) printf("\n Preparing the pre-processing...\n"); | 
| 298 |  |  | // | 
| 299 | mocchiut | 1.21 | if ( run == 0 || totnorun == 1 ){ | 
| 300 | mocchiut | 1.1 | // | 
| 301 |  |  | // we are reprocessing all the file | 
| 302 |  |  | // if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately | 
| 303 |  |  | // | 
| 304 |  |  | reprocall = true; | 
| 305 |  |  | // | 
| 306 |  |  | if ( verbose ) printf("\n ToF - WARNING: Reprocessing all runs\n"); | 
| 307 |  |  | // | 
| 308 |  |  | } else { | 
| 309 |  |  | // | 
| 310 |  |  | // we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run | 
| 311 |  |  | // | 
| 312 |  |  | reprocall = false; | 
| 313 |  |  | // | 
| 314 | mocchiut | 1.6 | if ( verbose ) printf("\n ToF - WARNING: Reprocessing run number %u \n",run); | 
| 315 | mocchiut | 1.1 | // | 
| 316 |  |  | // copying old tree to a new file | 
| 317 |  |  | // | 
| 318 | mocchiut | 1.25 | gSystem->MakeDirectory(toffolder.str().c_str()); | 
| 319 |  |  | myfold = true; | 
| 320 | mocchiut | 1.1 | tempfile = new TFile(tempname.str().c_str(),"RECREATE"); | 
| 321 |  |  | temptof = toftclone->CloneTree(-1,"fast"); | 
| 322 |  |  | temptof->SetName("ToF-old"); | 
| 323 |  |  | tempfile->Write(); | 
| 324 |  |  | tempfile->Close(); | 
| 325 |  |  | } | 
| 326 |  |  | // | 
| 327 |  |  | // Delete the old tree from old file and memory | 
| 328 |  |  | // | 
| 329 |  |  | toftclone->Delete("all"); | 
| 330 |  |  | // | 
| 331 |  |  | if ( verbose ) printf(" ...done!\n"); | 
| 332 |  |  | // | 
| 333 |  |  | }; | 
| 334 |  |  | // | 
| 335 |  |  | // create ToF detector tree toft | 
| 336 |  |  | // | 
| 337 |  |  | file->cd(); | 
| 338 |  |  | toft = new TTree("ToF-new","PAMELA Level2 ToF data"); | 
| 339 | mocchiut | 1.15 | toft->SetAutoSave(900000000000000LL); | 
| 340 |  |  | tof->Set();//ELENA **TEMPORANEO?** | 
| 341 | mocchiut | 1.1 | toft->Branch("ToFLevel2","ToFLevel2",&tof); | 
| 342 |  |  | // | 
| 343 |  |  | if ( reproc && !reprocall ){ | 
| 344 |  |  | // | 
| 345 |  |  | //  open new file and retrieve all tree informations | 
| 346 |  |  | // | 
| 347 |  |  | tempfile = new TFile(tempname.str().c_str(),"READ"); | 
| 348 |  |  | toftclone = (TTree*)tempfile->Get("ToF-old"); | 
| 349 | mocchiut | 1.15 | toftclone->SetAutoSave(900000000000000LL); | 
| 350 | mocchiut | 1.1 | toftclone->SetBranchAddress("ToFLevel2",&tofclone); | 
| 351 |  |  | // | 
| 352 |  |  | if ( nobefrun > 0 ){ | 
| 353 |  |  | if ( verbose ) printf("\n Pre-processing: copying events from the old tree before the processed run\n"); | 
| 354 | mocchiut | 1.6 | if ( verbose ) printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); | 
| 355 | mocchiut | 1.1 | if ( verbose ) printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); | 
| 356 |  |  | for (UInt_t j = 0; j < nobefrun; j++){ | 
| 357 |  |  | // | 
| 358 |  |  | toftclone->GetEntry(j); | 
| 359 |  |  | // | 
| 360 |  |  | // copy tofclone to tof | 
| 361 |  |  | // | 
| 362 | mocchiut | 1.3 | tof->Clear(); | 
| 363 | mocchiut | 1.1 | memcpy(&tof,&tofclone,sizeof(tofclone)); | 
| 364 |  |  | // | 
| 365 |  |  | // Fill entry in the new tree | 
| 366 |  |  | // | 
| 367 |  |  | toft->Fill(); | 
| 368 |  |  | // | 
| 369 |  |  | }; | 
| 370 |  |  | if ( verbose ) printf(" Finished successful copying!\n"); | 
| 371 |  |  | }; | 
| 372 |  |  | }; | 
| 373 |  |  | // | 
| 374 |  |  | // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only. | 
| 375 |  |  | // | 
| 376 |  |  | runlist = runinfo->GetRunList(); | 
| 377 |  |  | // | 
| 378 |  |  | // Loop over the run to be processed | 
| 379 |  |  | // | 
| 380 |  |  | for (UInt_t irun=0; irun < numbofrun; irun++){ | 
| 381 |  |  | // | 
| 382 |  |  | // retrieve the first run ID to be processed using the RunInfo list | 
| 383 |  |  | // | 
| 384 |  |  | idRun = runlist->At(irun); | 
| 385 |  |  | if ( verbose ) printf("\n\n\n ####################################################################### \n"); | 
| 386 | mocchiut | 1.6 | if ( verbose ) printf("                    PROCESSING RUN NUMBER %u \n",idRun); | 
| 387 | mocchiut | 1.1 | if ( verbose ) printf(" ####################################################################### \n\n\n"); | 
| 388 |  |  | // | 
| 389 | mocchiut | 1.6 | runinfo->ID_ROOT_L0 = 0; | 
| 390 | mocchiut | 1.1 | // | 
| 391 |  |  | // store in the runinfo class the GL_RUN variables for our run | 
| 392 |  |  | // | 
| 393 |  |  | sgnl = 0; | 
| 394 |  |  | sgnl = runinfo->GetRunInfo(idRun); | 
| 395 |  |  | if ( sgnl ){ | 
| 396 |  |  | if ( verbose ) printf(" TOF - ERROR: RunInfo exited with non-zero status\n"); | 
| 397 |  |  | code = sgnl; | 
| 398 |  |  | goto closeandexit; | 
| 399 |  |  | } else { | 
| 400 |  |  | sgnl = 0; | 
| 401 |  |  | }; | 
| 402 |  |  | // | 
| 403 | mocchiut | 1.6 | // now you can access that variables using the RunInfo class this way runinfo->ID_ROOT_L0 | 
| 404 | mocchiut | 1.1 | // | 
| 405 | mocchiut | 1.6 | if ( runinfo->ID_ROOT_L0 == 0 ){ | 
| 406 |  |  | if ( verbose ) printf("\n TOF - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); | 
| 407 | mocchiut | 1.1 | code = -5; | 
| 408 |  |  | goto closeandexit; | 
| 409 |  |  | }; | 
| 410 |  |  | // | 
| 411 | mocchiut | 1.6 | // prepare the timesync for the db | 
| 412 |  |  | // | 
| 413 | mocchiut | 1.10 | if ( !dbc->IsConnected() ) throw -314; | 
| 414 | mocchiut | 1.6 | dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); | 
| 415 |  |  | // | 
| 416 | mocchiut | 1.1 | // Search in the DB the path and name of the LEVEL0 file to be processed. | 
| 417 |  |  | // | 
| 418 | mocchiut | 1.10 | if ( !dbc->IsConnected() ) throw -314; | 
| 419 | mocchiut | 1.6 | glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); | 
| 420 | mocchiut | 1.1 | // | 
| 421 |  |  | ftmpname.str(""); | 
| 422 |  |  | ftmpname << glroot->PATH.Data() << "/"; | 
| 423 |  |  | ftmpname << glroot->NAME.Data(); | 
| 424 |  |  | fname = ftmpname.str().c_str(); | 
| 425 |  |  | // | 
| 426 |  |  | // print out informations | 
| 427 |  |  | // | 
| 428 | mocchiut | 1.6 | totevent = runinfo->NEVENTS; | 
| 429 | mocchiut | 1.1 | if ( verbose ) printf("\n LEVEL0 data file: %s \n",fname.Data()); | 
| 430 | mocchiut | 1.6 | if ( verbose ) printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME); | 
| 431 |  |  | if ( verbose ) printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); | 
| 432 |  |  | if ( verbose ) printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent); | 
| 433 | mocchiut | 1.1 | // | 
| 434 |  |  | // Open Level0 file | 
| 435 |  |  | // | 
| 436 |  |  | l0File = new TFile(fname.Data()); | 
| 437 |  |  | if ( !l0File ) { | 
| 438 |  |  | if ( verbose ) printf(" TOF - ERROR: problems opening  Level0 file\n"); | 
| 439 |  |  | code = -6; | 
| 440 |  |  | goto closeandexit; | 
| 441 |  |  | }; | 
| 442 |  |  | l0tr = (TTree*)l0File->Get("Physics"); | 
| 443 |  |  | if ( !l0tr ) { | 
| 444 |  |  | if ( verbose ) printf(" TOF - ERROR: no Physics tree in Level0 file\n"); | 
| 445 |  |  | l0File->Close(); | 
| 446 |  |  | code = -7; | 
| 447 |  |  | goto closeandexit; | 
| 448 |  |  | }; | 
| 449 |  |  | l0head = l0tr->GetBranch("Header"); | 
| 450 |  |  | if ( !l0head ) { | 
| 451 |  |  | if ( verbose ) printf(" TOF - ERROR: no Header branch in Level0 tree\n"); | 
| 452 |  |  | l0File->Close(); | 
| 453 |  |  | code = -8; | 
| 454 |  |  | goto closeandexit; | 
| 455 |  |  | }; | 
| 456 |  |  | l0trig = l0tr->GetBranch("Trigger"); | 
| 457 |  |  | if ( !l0trig ) { | 
| 458 |  |  | if ( verbose ) printf(" TOF - ERROR: no Trigger branch in Level0 tree\n"); | 
| 459 |  |  | l0File->Close(); | 
| 460 |  |  | code = -300; | 
| 461 |  |  | goto closeandexit; | 
| 462 |  |  | }; | 
| 463 |  |  | l0tof = l0tr->GetBranch("Tof"); | 
| 464 |  |  | if ( !l0tof ) { | 
| 465 |  |  | if ( verbose ) printf(" TOF - ERROR: no ToF branch in Level0 tree\n"); | 
| 466 |  |  | l0File->Close(); | 
| 467 |  |  | code = -303; | 
| 468 |  |  | goto closeandexit; | 
| 469 |  |  | }; | 
| 470 |  |  | // | 
| 471 |  |  | l0tr->SetBranchAddress("Trigger", &trig); | 
| 472 |  |  | l0tr->SetBranchAddress("Tof", &tofEvent); | 
| 473 | mocchiut | 1.6 | l0tr->SetBranchAddress("Header", &eh); | 
| 474 | mocchiut | 1.1 | // | 
| 475 | mocchiut | 1.6 | nevents = l0tof->GetEntries(); | 
| 476 | mocchiut | 1.1 | // | 
| 477 |  |  | if ( nevents < 1 ) { | 
| 478 |  |  | if ( verbose ) printf(" TOF - ERROR: Level0 file is empty\n\n"); | 
| 479 |  |  | l0File->Close(); | 
| 480 |  |  | code = -11; | 
| 481 |  |  | goto closeandexit; | 
| 482 |  |  | }; | 
| 483 |  |  | // | 
| 484 | mocchiut | 1.6 | if ( runinfo->EV_TO > nevents-1 ) { | 
| 485 | mocchiut | 1.1 | if ( verbose ) printf(" TOF - ERROR: too few entries in the registry tree\n"); | 
| 486 |  |  | l0File->Close(); | 
| 487 |  |  | code = -12; | 
| 488 |  |  | goto closeandexit; | 
| 489 |  |  | }; | 
| 490 |  |  | // | 
| 491 |  |  | // Check if we have to load parameter files (or calibration associated to runs and not to events) | 
| 492 |  |  | // | 
| 493 |  |  | // for example let's assume that we could have different magnetic field maps for different runs: | 
| 494 |  |  | // | 
| 495 |  |  | if ( trkpar1 || ( tttrkpar1 != 0 && tttrkpar1 < runinfo->RUNHEADER_TIME ) ){ | 
| 496 |  |  | trkpar1 = false; | 
| 497 |  |  | // read from DB infos about Magnetic filed maps | 
| 498 | mocchiut | 1.10 | if ( !dbc->IsConnected() ) throw -314; | 
| 499 | mocchiut | 1.6 | glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,1,dbc); // parameters stored in DB in GL_PRAM table | 
| 500 | mocchiut | 1.1 | tttrkpar1 = glparam->TO_TIME; | 
| 501 |  |  | // ---------------------------- | 
| 502 |  |  | // Read the magnetic field | 
| 503 |  |  | // ---------------------------- | 
| 504 |  |  | if ( verbose ) printf(" Reading magnetic field maps: \n"); | 
| 505 |  |  | trk->LoadField(glparam->PATH+glparam->NAME); | 
| 506 |  |  | if ( verbose ) printf("\n"); | 
| 507 |  |  | }; | 
| 508 | mocchiut | 1.6 | // | 
| 509 | mocchiut | 1.22 | // variable to save information about the tof calibration used | 
| 510 |  |  | // | 
| 511 |  |  | Bool_t defcal = true; | 
| 512 |  |  | // | 
| 513 | mocchiut | 1.1 | if ( tofpar1 || ( tttofpar1 != 0 && tttofpar1 < runinfo->RUNHEADER_TIME ) ){ | 
| 514 |  |  | tofpar1 = false; | 
| 515 |  |  | // | 
| 516 | mocchiut | 1.10 | if ( !dbc->IsConnected() ) throw -314; | 
| 517 | mocchiut | 1.6 | Int_t error=glparam->Query_GL_PARAM(runinfo->RUNHEADER_TIME,201,dbc); // parameters stored in DB in GL_PRAM table | 
| 518 | mocchiut | 1.1 | if ( error<0 ) { | 
| 519 |  |  | code = error; | 
| 520 |  |  | goto closeandexit; | 
| 521 |  |  | }; | 
| 522 |  |  | // | 
| 523 | mocchiut | 1.9 | if ( verbose ) printf(" Reading ToF parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); | 
| 524 |  |  | // | 
| 525 | mocchiut | 1.24 | if ( (UInt_t)glparam->TO_TIME != (UInt_t)4294967295UL ) defcal = false; | 
| 526 | mocchiut | 1.22 | // | 
| 527 | mocchiut | 1.1 | tttofpar1 = glparam->TO_TIME; | 
| 528 | mocchiut | 1.9 | Int_t nlen = (Int_t)(glparam->PATH+glparam->NAME).Length(); | 
| 529 |  |  | rdtofcal((char *)(glparam->PATH+glparam->NAME).Data(),&nlen); | 
| 530 | mocchiut | 1.20 | // | 
| 531 | mocchiut | 1.1 | }; | 
| 532 |  |  | // | 
| 533 |  |  | // run over all the events of the run | 
| 534 |  |  | // | 
| 535 |  |  | if ( verbose ) printf("\n Ready to start! \n\n Processed events: \n\n"); | 
| 536 |  |  | // | 
| 537 | mocchiut | 1.7 | jumped = 0; | 
| 538 | mocchiut | 1.6 | // | 
| 539 |  |  | for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ | 
| 540 | mocchiut | 1.1 | // | 
| 541 |  |  | if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); | 
| 542 |  |  | // | 
| 543 | mocchiut | 1.6 | l0head->GetEntry(re); | 
| 544 | mocchiut | 1.1 | // | 
| 545 |  |  | // absolute time of this event | 
| 546 |  |  | // | 
| 547 | mocchiut | 1.6 | ph = eh->GetPscuHeader(); | 
| 548 |  |  | atime = dbtime->DBabsTime(ph->GetOrbitalTime()); | 
| 549 | mocchiut | 1.4 | // | 
| 550 |  |  | tof->Clear(); | 
| 551 |  |  | Int_t pmt_id = 0; | 
| 552 |  |  | ToFPMT *t_pmt = new ToFPMT(); | 
| 553 | mocchiut | 1.15 | if(!(tof->PMT))tof->PMT = new TClonesArray("ToFPMT",12); //ELENA | 
| 554 | mocchiut | 1.4 | TClonesArray &tpmt = *tof->PMT; | 
| 555 |  |  | ToFTrkVar *t_tof = new ToFTrkVar(); | 
| 556 | mocchiut | 1.15 | if(!(tof->ToFTrk))tof->ToFTrk = new TClonesArray("ToFTrkVar",2); //ELENA | 
| 557 | mocchiut | 1.4 | TClonesArray &t = *tof->ToFTrk; | 
| 558 |  |  | // | 
| 559 | mocchiut | 1.1 | // paranoid check | 
| 560 |  |  | // | 
| 561 |  |  | if ( atime > runinfo->RUNTRAILER_TIME || atime < runinfo->RUNHEADER_TIME  ) { | 
| 562 |  |  | if ( verbose ) printf(" TOF - WARNING: event at time outside the run time window, skipping it\n"); | 
| 563 | mocchiut | 1.7 | jumped++; | 
| 564 | mocchiut | 1.1 | goto jumpev; | 
| 565 |  |  | }; | 
| 566 |  |  | // | 
| 567 |  |  | // retrieve tracker informations, the LEVEL2 entry which correspond to our event will be "itr" | 
| 568 |  |  | // | 
| 569 |  |  | if ( !reprocall ){ | 
| 570 | mocchiut | 1.7 | itr = nobefrun + (re - runinfo->EV_FROM -jumped); | 
| 571 | mocchiut | 1.1 | } else { | 
| 572 | mocchiut | 1.7 | itr = runinfo->GetFirstEntry() + (re - runinfo->EV_FROM -jumped); | 
| 573 | mocchiut | 1.1 | }; | 
| 574 |  |  | if ( itr > nevtrkl2 ){  // nevtrkl2 tracker entry number | 
| 575 |  |  | if ( verbose ) printf(" TOF - ERROR: no tracker events with entry = %i in Level2 file\n",itr); | 
| 576 |  |  | l0File->Close(); | 
| 577 |  |  | code = -313; | 
| 578 |  |  | goto closeandexit; | 
| 579 |  |  | }; | 
| 580 | mocchiut | 1.8 | // | 
| 581 |  |  | trk->Clear(); | 
| 582 |  |  | // | 
| 583 | mocchiut | 1.1 | tracker->GetEntry(itr); | 
| 584 |  |  | /// | 
| 585 | mocchiut | 1.2 | // | 
| 586 | mocchiut | 1.6 | l0tof->GetEntry(re); | 
| 587 |  |  | l0trig->GetEntry(re); | 
| 588 | mocchiut | 1.1 | /// | 
| 589 |  |  | // | 
| 590 |  |  | procev++; | 
| 591 |  |  | // | 
| 592 |  |  | // start processing | 
| 593 |  |  | // | 
| 594 |  |  | // | 
| 595 |  |  | // Here we will use some procedure to calibrate our data and put some kind of informations in the cinput structure | 
| 596 |  |  |  | 
| 597 |  |  | for (Int_t gg=0; gg<4;gg++){ | 
| 598 |  |  | for (Int_t hh=0; hh<12;hh++){ | 
| 599 |  |  | tofinput_.tdc[hh][gg]=tofEvent->tdc[gg][hh]; | 
| 600 |  |  | tofinput_.adc[hh][gg]=tofEvent->adc[gg][hh]; | 
| 601 |  |  | }; | 
| 602 |  |  | }; | 
| 603 |  |  |  | 
| 604 |  |  | for (Int_t hh=0; hh<5;hh++){ | 
| 605 |  |  | tofinput_.patterntrig[hh]=trig->patterntrig[hh]; | 
| 606 |  |  | }; | 
| 607 |  |  | // | 
| 608 |  |  | // Here we have calibrated data, ready to be passed to the FORTRAN routine which will extract common and track-related  variables. | 
| 609 |  |  | // | 
| 610 | mocchiut | 1.4 | npmtentry = 0; | 
| 611 |  |  | // | 
| 612 |  |  | ntrkentry = 0; | 
| 613 | mocchiut | 1.1 | // | 
| 614 |  |  | // Calculate tracks informations from ToF alone | 
| 615 |  |  | // | 
| 616 |  |  | tofl2com(); | 
| 617 |  |  | // | 
| 618 | mocchiut | 1.4 | memcpy(tof->tof_j_flag,tofoutput_.tof_j_flag,6*sizeof(Int_t)); | 
| 619 |  |  | // | 
| 620 |  |  | t_tof->trkseqno = -1; | 
| 621 |  |  | // | 
| 622 | mocchiut | 1.1 | // and now we must copy from the output structure to the level2 class: | 
| 623 |  |  | // | 
| 624 | mocchiut | 1.4 | t_tof->npmttdc = 0; | 
| 625 |  |  | // | 
| 626 | mocchiut | 1.1 | for (Int_t hh=0; hh<12;hh++){ | 
| 627 |  |  | for (Int_t kk=0; kk<4;kk++){ | 
| 628 | mocchiut | 1.4 | if ( tofoutput_.tofmask[hh][kk] != 0 ){ | 
| 629 |  |  | pmt_id = tof->GetPMTid(kk,hh); | 
| 630 |  |  | t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); | 
| 631 | mocchiut | 1.14 | t_tof->tdcflag.AddAt(tofoutput_.tdcflagtof[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 | 
| 632 | mocchiut | 1.4 | t_tof->npmttdc++; | 
| 633 |  |  | }; | 
| 634 |  |  | }; | 
| 635 |  |  | }; | 
| 636 |  |  | for (Int_t kk=0; kk<13;kk++){ | 
| 637 |  |  | t_tof->beta[kk] = tofoutput_.betatof_a[kk]; | 
| 638 | mocchiut | 1.1 | } | 
| 639 | mocchiut | 1.4 | // | 
| 640 |  |  | t_tof->npmtadc = 0; | 
| 641 | mocchiut | 1.1 | for (Int_t hh=0; hh<12;hh++){ | 
| 642 |  |  | for (Int_t kk=0; kk<4;kk++){ | 
| 643 | mocchiut | 1.4 | if ( tofoutput_.adctof_c[hh][kk] < 1000 ){ | 
| 644 |  |  | t_tof->dedx.AddAt(tofoutput_.adctof_c[hh][kk],t_tof->npmtadc); | 
| 645 |  |  | pmt_id = tof->GetPMTid(kk,hh); | 
| 646 |  |  | t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); | 
| 647 | mocchiut | 1.14 | t_tof->adcflag.AddAt(tofoutput_.adcflagtof[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 | 
| 648 | mocchiut | 1.4 | t_tof->npmtadc++; | 
| 649 |  |  | }; | 
| 650 |  |  | }; | 
| 651 |  |  | }; | 
| 652 |  |  | // | 
| 653 |  |  | memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); | 
| 654 |  |  | memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); | 
| 655 | mocchiut | 1.20 | memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); | 
| 656 |  |  | memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); | 
| 657 | mocchiut | 1.4 | // | 
| 658 | mocchiut | 1.20 |  | 
| 659 |  |  | /* | 
| 660 |  |  | cout<<"ToFCore  tofl2com"<<endl; | 
| 661 |  |  | cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl; | 
| 662 |  |  | cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl; | 
| 663 |  |  | cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl; | 
| 664 |  |  | cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl; | 
| 665 |  |  | */ | 
| 666 |  |  |  | 
| 667 |  |  |  | 
| 668 | mocchiut | 1.4 | new(t[ntrkentry]) ToFTrkVar(*t_tof); | 
| 669 |  |  | ntrkentry++; | 
| 670 |  |  | t_tof->Clear(); | 
| 671 |  |  | // | 
| 672 | mocchiut | 1.1 | // | 
| 673 |  |  | // | 
| 674 | mocchiut | 1.4 | t_pmt->Clear(); | 
| 675 | mocchiut | 1.1 | // | 
| 676 | mocchiut | 1.4 | for (Int_t hh=0; hh<12;hh++){ | 
| 677 |  |  | for (Int_t kk=0; kk<4;kk++){ | 
| 678 |  |  | if ( tofoutput_.tdc_c[hh][kk] < 4095 || tofEvent->adc[kk][hh] < 4095 ){ | 
| 679 |  |  | // | 
| 680 |  |  | t_pmt->pmt_id = tof->GetPMTid(kk,hh); | 
| 681 |  |  | t_pmt->tdc_tw = tofoutput_.tdc_c[hh][kk]; | 
| 682 |  |  | t_pmt->adc = tofEvent->adc[kk][hh]; | 
| 683 | mocchiut | 1.22 | t_pmt->tdc = tofEvent->tdc[kk][hh]; | 
| 684 | mocchiut | 1.4 | // | 
| 685 |  |  | new(tpmt[npmtentry]) ToFPMT(*t_pmt); | 
| 686 |  |  | npmtentry++; | 
| 687 |  |  | t_pmt->Clear(); | 
| 688 |  |  | }; | 
| 689 |  |  | }; | 
| 690 |  |  | }; | 
| 691 | mocchiut | 1.1 | // | 
| 692 | mocchiut | 1.4 | // Calculate track-related variables | 
| 693 | mocchiut | 1.1 | // | 
| 694 | mocchiut | 1.2 | if ( trk->ntrk() > 0 ){ | 
| 695 | mocchiut | 1.1 | // | 
| 696 |  |  | // We have at least one track | 
| 697 |  |  | // | 
| 698 |  |  | // | 
| 699 |  |  | // Run over tracks | 
| 700 |  |  | // | 
| 701 |  |  | for(Int_t nt=0; nt < trk->ntrk(); nt++){ | 
| 702 |  |  | // | 
| 703 |  |  | TrkTrack *ptt = trk->GetStoredTrack(nt); | 
| 704 |  |  | // | 
| 705 |  |  | // Copy the alpha vector in the input structure | 
| 706 |  |  | // | 
| 707 |  |  | for (Int_t e = 0; e < 5 ; e++){ | 
| 708 |  |  | tofinput_.al_pp[e] = ptt->al[e]; | 
| 709 |  |  | }; | 
| 710 |  |  | // | 
| 711 |  |  | // Get tracker related variables for this track | 
| 712 |  |  | // | 
| 713 |  |  | toftrk(); | 
| 714 |  |  | // | 
| 715 |  |  | // Copy values in the class from the structure (we need to use a temporary class to store variables). | 
| 716 |  |  | // | 
| 717 | mocchiut | 1.4 | t_tof->npmttdc = 0; | 
| 718 |  |  | for (Int_t hh=0; hh<12;hh++){ | 
| 719 |  |  | for (Int_t kk=0; kk<4;kk++){ | 
| 720 |  |  | if ( tofoutput_.tofmask[hh][kk] != 0 ){ | 
| 721 |  |  | pmt_id = tof->GetPMTid(kk,hh); | 
| 722 |  |  | t_tof->pmttdc.AddAt(pmt_id,t_tof->npmttdc); | 
| 723 | mocchiut | 1.14 | t_tof->tdcflag.AddAt(tofoutput_.tdcflag[hh][kk],t_tof->npmttdc); // gf: Jan 09/07 | 
| 724 | mocchiut | 1.4 | t_tof->npmttdc++; | 
| 725 |  |  | }; | 
| 726 |  |  | }; | 
| 727 |  |  | }; | 
| 728 | mocchiut | 1.1 | for (Int_t kk=0; kk<13;kk++){ | 
| 729 | mocchiut | 1.4 | t_tof->beta[kk] = tofoutput_.beta_a[kk]; | 
| 730 |  |  | }; | 
| 731 |  |  | // | 
| 732 |  |  | t_tof->npmtadc = 0; | 
| 733 | mocchiut | 1.1 | for (Int_t hh=0; hh<12;hh++){ | 
| 734 |  |  | for (Int_t kk=0; kk<4;kk++){ | 
| 735 | mocchiut | 1.4 | if ( tofoutput_.adc_c[hh][kk] < 1000 ){ | 
| 736 |  |  | t_tof->dedx.AddAt(tofoutput_.adc_c[hh][kk],t_tof->npmtadc); | 
| 737 |  |  | pmt_id = tof->GetPMTid(kk,hh); | 
| 738 |  |  | t_tof->pmtadc.AddAt(pmt_id,t_tof->npmtadc); | 
| 739 | mocchiut | 1.14 | t_tof->adcflag.AddAt(tofoutput_.adcflag[hh][kk],t_tof->npmtadc); // gf: Jan 09/07 | 
| 740 | mocchiut | 1.4 | t_tof->npmtadc++; | 
| 741 |  |  | }; | 
| 742 |  |  | }; | 
| 743 |  |  | }; | 
| 744 |  |  | // | 
| 745 |  |  | memcpy(t_tof->xtofpos,tofoutput_.xtofpos,sizeof(t_tof->xtofpos)); | 
| 746 |  |  | memcpy(t_tof->ytofpos,tofoutput_.ytofpos,sizeof(t_tof->ytofpos)); | 
| 747 | mocchiut | 1.20 | memcpy(t_tof->xtr_tof,tofoutput_.xtr_tof,sizeof(t_tof->xtr_tof)); | 
| 748 |  |  | memcpy(t_tof->ytr_tof,tofoutput_.ytr_tof,sizeof(t_tof->ytr_tof)); | 
| 749 |  |  |  | 
| 750 |  |  | /* | 
| 751 |  |  | cout<<"ToFCore  toftrk"<<endl; | 
| 752 |  |  | cout<<tofoutput_.xtofpos[0]<<" "<<tofoutput_.xtofpos[1]<<" "<<tofoutput_.xtofpos[2]<<endl; | 
| 753 |  |  | cout<<tofoutput_.ytofpos[0]<<" "<<tofoutput_.ytofpos[1]<<" "<<tofoutput_.ytofpos[2]<<endl; | 
| 754 |  |  | cout<<tofoutput_.xtr_tof[0]<<" "<<tofoutput_.xtr_tof[1]<<" "<<tofoutput_.xtr_tof[2]<<" "<<tofoutput_.xtr_tof[3]<<" "<<tofoutput_.xtr_tof[4]<<" "<<tofoutput_.xtr_tof[5]<<endl; | 
| 755 |  |  | cout<<tofoutput_.ytr_tof[0]<<" "<<tofoutput_.ytr_tof[1]<<" "<<tofoutput_.ytr_tof[2]<<" "<<tofoutput_.ytr_tof[3]<<" "<<tofoutput_.ytr_tof[4]<<" "<<tofoutput_.ytr_tof[5]<<endl; | 
| 756 |  |  | */ | 
| 757 |  |  |  | 
| 758 | mocchiut | 1.1 | // | 
| 759 |  |  | // Store the tracker track number in order to be sure to have shyncronized data during analysis | 
| 760 |  |  | // | 
| 761 |  |  | t_tof->trkseqno = nt; | 
| 762 |  |  | // | 
| 763 |  |  | // create a new object for this event with track-related variables | 
| 764 |  |  | // | 
| 765 |  |  | new(t[ntrkentry]) ToFTrkVar(*t_tof); | 
| 766 |  |  | ntrkentry++; | 
| 767 | mocchiut | 1.4 | t_tof->Clear(); | 
| 768 | mocchiut | 1.1 | // | 
| 769 |  |  | }; // loop on all the tracks | 
| 770 |  |  | }; | 
| 771 |  |  | // | 
| 772 | mocchiut | 1.9 | tof->unpackError = tofEvent->unpackError; | 
| 773 | mocchiut | 1.22 | if ( defcal ){ | 
| 774 |  |  | tof->default_calib = 1; | 
| 775 |  |  | } else { | 
| 776 |  |  | tof->default_calib = 0; | 
| 777 |  |  | }; | 
| 778 | mocchiut | 1.9 | // | 
| 779 | mocchiut | 1.1 | // Fill the rootple | 
| 780 |  |  | // | 
| 781 |  |  | toft->Fill(); | 
| 782 |  |  | // | 
| 783 |  |  | // | 
| 784 | mocchiut | 1.4 | // | 
| 785 |  |  | delete t_tof; | 
| 786 |  |  | // | 
| 787 |  |  | // | 
| 788 |  |  | // | 
| 789 | mocchiut | 1.1 | jumpev: | 
| 790 |  |  | debug = false; | 
| 791 |  |  | // | 
| 792 |  |  | }; | 
| 793 | mocchiut | 1.6 | // | 
| 794 |  |  | // Here you may want to clear some variables before processing another run | 
| 795 |  |  | // | 
| 796 |  |  | delete dbtime; | 
| 797 | mocchiut | 1.1 | }; // process all the runs | 
| 798 |  |  | // | 
| 799 |  |  | if ( verbose ) printf("\n Finished processing data \n"); | 
| 800 |  |  | // | 
| 801 |  |  | closeandexit: | 
| 802 |  |  | // | 
| 803 |  |  | // we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree. | 
| 804 |  |  | // | 
| 805 |  |  | if ( !reprocall && reproc && code >= 0 ){ | 
| 806 |  |  | if ( totfileentries > noaftrun ){ | 
| 807 |  |  | if ( verbose ) printf("\n Post-processing: copying events from the old tree after the processed run\n"); | 
| 808 |  |  | if ( verbose ) printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); | 
| 809 |  |  | if ( verbose ) printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); | 
| 810 |  |  | for (UInt_t j = noaftrun; j < totfileentries; j++ ){ | 
| 811 |  |  | // | 
| 812 |  |  | // Get entry from old tree | 
| 813 |  |  | // | 
| 814 |  |  | toftclone->GetEntry(j); | 
| 815 |  |  | // | 
| 816 |  |  | // copy tofclone to tof | 
| 817 |  |  | // | 
| 818 | mocchiut | 1.3 | tof->Clear(); | 
| 819 | mocchiut | 1.1 | memcpy(&tof,&tofclone,sizeof(tofclone)); | 
| 820 |  |  | // | 
| 821 |  |  | // Fill entry in the new tree | 
| 822 |  |  | // | 
| 823 |  |  | toft->Fill(); | 
| 824 |  |  | }; | 
| 825 |  |  | if ( verbose ) printf(" Finished successful copying!\n"); | 
| 826 |  |  | }; | 
| 827 |  |  | }; | 
| 828 |  |  | // | 
| 829 |  |  | // Close files, delete old tree(s), write and close level2 file | 
| 830 |  |  | // | 
| 831 |  |  | if ( l0File ) l0File->Close(); | 
| 832 |  |  | if ( tempfile ) tempfile->Close(); | 
| 833 | mocchiut | 1.25 | if ( myfold ) gSystem->Unlink(tempname.str().c_str()); | 
| 834 | mocchiut | 1.1 | if ( tracker )  tracker->Delete(); // delete tracker tree from memory only to avoid writing a copy to file! | 
| 835 |  |  | // | 
| 836 |  |  | if ( code < 0 && verbose ) printf("\n TOF - ERROR: an error occurred, try to save anyway...\n"); | 
| 837 |  |  | if ( verbose ) printf("\n Writing and closing rootple\n"); | 
| 838 |  |  | if ( runinfo ) runinfo->Close(); | 
| 839 |  |  | if ( toft ) toft->SetName("ToF"); | 
| 840 |  |  | if ( file ){ | 
| 841 |  |  | file->cd(); | 
| 842 |  |  | file->Write("ToF"); | 
| 843 |  |  | }; | 
| 844 |  |  | // | 
| 845 | mocchiut | 1.25 | if ( myfold ) gSystem->Unlink(toffolder.str().c_str()); | 
| 846 | mocchiut | 1.1 | // | 
| 847 |  |  | // the end | 
| 848 |  |  | // | 
| 849 |  |  | if ( verbose ) printf("\n Exiting...\n"); | 
| 850 |  |  | if(toft)toft->Delete(); | 
| 851 | mocchiut | 1.5 | // | 
| 852 |  |  | if ( tof ) delete tof; | 
| 853 |  |  | if ( tofclone ) delete tofclone; | 
| 854 |  |  | if ( glroot ) delete glroot; | 
| 855 |  |  | if ( runinfo ) delete runinfo; | 
| 856 |  |  | // | 
| 857 | mocchiut | 1.1 | if ( code < 0 ) throw code; | 
| 858 |  |  | return(code); | 
| 859 |  |  | } |