| 1 | #include <PamLevel2.h> | 
| 2 |  | 
| 3 |  | 
| 4 |  | 
| 5 | ///////////////////////////////////////////////////////////////////////////// | 
| 6 | ///////////////////////////////////////////////////////////////////////////// | 
| 7 | ///////////////////////////////////////////////////////////////////////////// | 
| 8 | ///////////////////////////////////////////////////////////////////////////// | 
| 9 |  | 
| 10 | void GPamela::Clear(){ | 
| 11 | Irun   = 0; | 
| 12 | Ievnt  = 0; | 
| 13 | Ipa    = 0; | 
| 14 | X0     = 0.; | 
| 15 | Y0     = 0.; | 
| 16 | Z0     = 0.; | 
| 17 | Theta  = 0.; | 
| 18 | Phi    = 0.; | 
| 19 | P0     = 0.; | 
| 20 | Nthtof  = 0; | 
| 21 | Nthcat  = 0; | 
| 22 | Nthcas  = 0; | 
| 23 | Nthspe  = 0; | 
| 24 | Nstrpx  = 0; | 
| 25 | Nstrpy  = 0; | 
| 26 | Nthcali = 0; | 
| 27 | Nthcal  = 0; | 
| 28 | Nthnd   = 0; | 
| 29 | Nthcard = 0; | 
| 30 | } | 
| 31 |  | 
| 32 | void GPamela::Delete(){ | 
| 33 |  | 
| 34 | Clear(); | 
| 35 |  | 
| 36 | delete []    Ipltof; | 
| 37 | delete []    Ipaddle; | 
| 38 | delete []    Ipartof; | 
| 39 | delete []    Xintof; | 
| 40 | delete []    Yintof; | 
| 41 | delete []    Zintof; | 
| 42 | delete []    Xouttof; | 
| 43 | delete []    Youttof; | 
| 44 | delete []    Zouttof; | 
| 45 | delete []    Ereltof; | 
| 46 | delete []    Timetof; | 
| 47 | delete []    Pathtof; | 
| 48 | delete []    P0tof; | 
| 49 | delete []    Iparcat; | 
| 50 | delete []    Icat; | 
| 51 | delete []    Xincat; | 
| 52 | delete []    Yincat; | 
| 53 | delete []    Zincat; | 
| 54 | delete []    Xoutcat; | 
| 55 | delete []    Youtcat; | 
| 56 | delete []    Zoutcat; | 
| 57 | delete []    Erelcat; | 
| 58 | delete []    Timecat; | 
| 59 | delete []    Pathcat; | 
| 60 | delete []    P0cat; | 
| 61 | delete []    Iparcas; | 
| 62 | delete []    Icas; | 
| 63 | delete []    Xincas; | 
| 64 | delete []    Yincas; | 
| 65 | delete []    Zincas; | 
| 66 | delete []    Xoutcas; | 
| 67 | delete []    Youtcas; | 
| 68 | delete []    Zoutcas; | 
| 69 | delete []    Erelcas; | 
| 70 | delete []    Timecas; | 
| 71 | delete []    Pathcas; | 
| 72 | delete []    P0cas; | 
| 73 | delete []    Iparspe; | 
| 74 | delete []    Itrpb; | 
| 75 | delete []    Itrsl; | 
| 76 | delete []    Itspa; | 
| 77 | delete []    Xinspe; | 
| 78 | delete []    Yinspe; | 
| 79 | delete []    Zinspe; | 
| 80 | delete []    Xoutspe; | 
| 81 | delete []    Youtspe; | 
| 82 | delete []    Zoutspe; | 
| 83 | delete []    Xavspe; | 
| 84 | delete []    Yavspe; | 
| 85 | delete []    Zavspe; | 
| 86 | delete []    Erelspe; | 
| 87 | delete []    Pathspe; | 
| 88 | delete []    P0spe; | 
| 89 | delete []    Nxmult; | 
| 90 | delete []    Nymult; | 
| 91 | delete []    Npstripx; | 
| 92 | delete []    Ntstripx; | 
| 93 | delete []    Istripx; | 
| 94 | delete []    Qstripx; | 
| 95 | delete []    Xstripx; | 
| 96 | delete []    Npstripy; | 
| 97 | delete []    Ntstripy; | 
| 98 | delete []    Istripy; | 
| 99 | delete []    Qstripy; | 
| 100 | delete []    Ystripy; | 
| 101 | delete []    Icaplane; | 
| 102 | delete []    Icastrip; | 
| 103 | delete []    Icamod; | 
| 104 | delete []    Enestrip; | 
| 105 | delete []    Icapl; | 
| 106 | delete []    Icasi; | 
| 107 | delete []    Icast; | 
| 108 | delete []    Xincal; | 
| 109 | delete []    Yincal; | 
| 110 | delete []    Zincal; | 
| 111 | delete []    Erelcal; | 
| 112 | delete []    Itubend; | 
| 113 | delete []    Iparnd; | 
| 114 | delete []    Xinnd; | 
| 115 | delete []    Yinnd; | 
| 116 | delete []    Zinnd; | 
| 117 | delete []    Xoutnd; | 
| 118 | delete []    Youtnd; | 
| 119 | delete []    Zoutnd; | 
| 120 | delete []    Erelnd; | 
| 121 | delete []    Timend; | 
| 122 | delete []    Pathnd; | 
| 123 | delete []    P0nd; | 
| 124 | delete []    Iparcard; | 
| 125 | delete []    Icard; | 
| 126 | delete []    Xincard; | 
| 127 | delete []    Yincard; | 
| 128 | delete []    Zincard; | 
| 129 | delete []    Xoutcard; | 
| 130 | delete []    Youtcard; | 
| 131 | delete []    Zoutcard; | 
| 132 | delete []    Erelcard; | 
| 133 | delete []    Timecard; | 
| 134 | delete []    Pathcard; | 
| 135 | delete []    P0card; | 
| 136 |  | 
| 137 |  | 
| 138 | }; | 
| 139 |  | 
| 140 |  | 
| 141 |  | 
| 142 | void GPamela::SetBranchAddress( TChain* fhBookTree ){ | 
| 143 |  | 
| 144 | //    cout << "fhBookTree "<<fhBookTree << endl; | 
| 145 | // prepare tree | 
| 146 | fhBookTree->SetBranchAddress("Irun",&Irun); | 
| 147 | fhBookTree->SetBranchAddress("Ievnt",&Ievnt); | 
| 148 | fhBookTree->SetBranchAddress("Ipa",&Ipa); | 
| 149 | fhBookTree->SetBranchAddress("X0",&X0); | 
| 150 | fhBookTree->SetBranchAddress("Y0",&Y0); | 
| 151 | fhBookTree->SetBranchAddress("Z0",&Z0); | 
| 152 | fhBookTree->SetBranchAddress("Theta",&Theta); | 
| 153 | fhBookTree->SetBranchAddress("Phi",&Phi); | 
| 154 | fhBookTree->SetBranchAddress("P0",&P0); | 
| 155 | fhBookTree->SetBranchAddress("Nthtof",&Nthtof); | 
| 156 | fhBookTree->SetBranchAddress("Ipltof",Ipltof); | 
| 157 | fhBookTree->SetBranchAddress("Ipaddle",Ipaddle); | 
| 158 | fhBookTree->SetBranchAddress("Ipartof",Ipartof); | 
| 159 | fhBookTree->SetBranchAddress("Xintof",Xintof); | 
| 160 | fhBookTree->SetBranchAddress("Yintof",Yintof); | 
| 161 | fhBookTree->SetBranchAddress("Zintof",Zintof); | 
| 162 | fhBookTree->SetBranchAddress("Xouttof",Xouttof); | 
| 163 | fhBookTree->SetBranchAddress("Youttof",Youttof); | 
| 164 | fhBookTree->SetBranchAddress("Zouttof",Zouttof); | 
| 165 | fhBookTree->SetBranchAddress("Ereltof",Ereltof); | 
| 166 | fhBookTree->SetBranchAddress("Timetof",Timetof); | 
| 167 | fhBookTree->SetBranchAddress("Pathtof",Pathtof); | 
| 168 | fhBookTree->SetBranchAddress("P0tof",P0tof); | 
| 169 | fhBookTree->SetBranchAddress("Nthcat",&Nthcat); | 
| 170 | fhBookTree->SetBranchAddress("Iparcat",Iparcat); | 
| 171 | fhBookTree->SetBranchAddress("Icat",Icat); | 
| 172 | fhBookTree->SetBranchAddress("Xincat",Xincat); | 
| 173 | fhBookTree->SetBranchAddress("Yincat",Yincat); | 
| 174 | fhBookTree->SetBranchAddress("Zincat",Zincat); | 
| 175 | fhBookTree->SetBranchAddress("Xoutcat",Xoutcat); | 
| 176 | fhBookTree->SetBranchAddress("Youtcat",Youtcat); | 
| 177 | fhBookTree->SetBranchAddress("Zoutcat",Zoutcat); | 
| 178 | fhBookTree->SetBranchAddress("Erelcat",Erelcat); | 
| 179 | fhBookTree->SetBranchAddress("Timecat",Timecat); | 
| 180 | fhBookTree->SetBranchAddress("Pathcat",Pathcat); | 
| 181 | fhBookTree->SetBranchAddress("P0cat",P0cat); | 
| 182 | fhBookTree->SetBranchAddress("Nthcas",&Nthcas); | 
| 183 | fhBookTree->SetBranchAddress("Iparcas",Iparcas); | 
| 184 | fhBookTree->SetBranchAddress("Icas",Icas); | 
| 185 | fhBookTree->SetBranchAddress("Xincas",Xincas); | 
| 186 | fhBookTree->SetBranchAddress("Yincas",Yincas); | 
| 187 | fhBookTree->SetBranchAddress("Zincas",Zincas); | 
| 188 | fhBookTree->SetBranchAddress("Xoutcas",Xoutcas); | 
| 189 | fhBookTree->SetBranchAddress("Youtcas",Youtcas); | 
| 190 | fhBookTree->SetBranchAddress("Zoutcas",Zoutcas); | 
| 191 | fhBookTree->SetBranchAddress("Erelcas",Erelcas); | 
| 192 | fhBookTree->SetBranchAddress("Timecas",Timecas); | 
| 193 | fhBookTree->SetBranchAddress("Pathcas",Pathcas); | 
| 194 | fhBookTree->SetBranchAddress("P0cas",P0cas); | 
| 195 | fhBookTree->SetBranchAddress("Nthspe",&Nthspe); | 
| 196 | fhBookTree->SetBranchAddress("Iparspe",Iparspe); | 
| 197 | fhBookTree->SetBranchAddress("Itrpb",Itrpb); | 
| 198 | fhBookTree->SetBranchAddress("Itrsl",Itrsl); | 
| 199 | fhBookTree->SetBranchAddress("Itspa",Itspa); | 
| 200 | fhBookTree->SetBranchAddress("Xinspe",Xinspe); | 
| 201 | fhBookTree->SetBranchAddress("Yinspe",Yinspe); | 
| 202 | fhBookTree->SetBranchAddress("Zinspe",Zinspe); | 
| 203 | fhBookTree->SetBranchAddress("Xoutspe",Xoutspe); | 
| 204 | fhBookTree->SetBranchAddress("Youtspe",Youtspe); | 
| 205 | fhBookTree->SetBranchAddress("Zoutspe",Zoutspe); | 
| 206 | fhBookTree->SetBranchAddress("Xavspe",Xavspe); | 
| 207 | fhBookTree->SetBranchAddress("Yavspe",Yavspe); | 
| 208 | fhBookTree->SetBranchAddress("Zavspe",Zavspe); | 
| 209 | fhBookTree->SetBranchAddress("Erelspe",Erelspe); | 
| 210 | fhBookTree->SetBranchAddress("Pathspe",Pathspe); | 
| 211 | fhBookTree->SetBranchAddress("P0spe",P0spe); | 
| 212 | fhBookTree->SetBranchAddress("Nxmult",Nxmult); | 
| 213 | fhBookTree->SetBranchAddress("Nymult",Nymult); | 
| 214 | fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx); | 
| 215 | fhBookTree->SetBranchAddress("Npstripx",Npstripx); | 
| 216 | fhBookTree->SetBranchAddress("Ntstripx",Ntstripx); | 
| 217 | fhBookTree->SetBranchAddress("Istripx",Istripx); | 
| 218 | fhBookTree->SetBranchAddress("Qstripx",Qstripx); | 
| 219 | fhBookTree->SetBranchAddress("Xstripx",Xstripx); | 
| 220 | fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy); | 
| 221 | fhBookTree->SetBranchAddress("Npstripy",Npstripy); | 
| 222 | fhBookTree->SetBranchAddress("Ntstripy",Ntstripy); | 
| 223 | fhBookTree->SetBranchAddress("Istripy",Istripy); | 
| 224 | fhBookTree->SetBranchAddress("Qstripy",Qstripy); | 
| 225 | fhBookTree->SetBranchAddress("Ystripy",Ystripy); | 
| 226 | fhBookTree->SetBranchAddress("Nthcali",&Nthcali); | 
| 227 | fhBookTree->SetBranchAddress("Icaplane",Icaplane); | 
| 228 | fhBookTree->SetBranchAddress("Icastrip",Icastrip); | 
| 229 | fhBookTree->SetBranchAddress("Icamod",Icamod); | 
| 230 | fhBookTree->SetBranchAddress("Enestrip",Enestrip); | 
| 231 | fhBookTree->SetBranchAddress("Nthcal",&Nthcal); | 
| 232 | fhBookTree->SetBranchAddress("Icapl",Icapl); | 
| 233 | fhBookTree->SetBranchAddress("Icasi",Icasi); | 
| 234 | fhBookTree->SetBranchAddress("Icast",Icast); | 
| 235 | fhBookTree->SetBranchAddress("Xincal",Xincal); | 
| 236 | fhBookTree->SetBranchAddress("Yincal",Yincal); | 
| 237 | fhBookTree->SetBranchAddress("Zincal",Zincal); | 
| 238 | fhBookTree->SetBranchAddress("Erelcal",Erelcal); | 
| 239 | fhBookTree->SetBranchAddress("Nthnd",&Nthnd); | 
| 240 | fhBookTree->SetBranchAddress("Itubend",Itubend); | 
| 241 | fhBookTree->SetBranchAddress("Iparnd",Iparnd); | 
| 242 | fhBookTree->SetBranchAddress("Xinnd",Xinnd); | 
| 243 | fhBookTree->SetBranchAddress("Yinnd",Yinnd); | 
| 244 | fhBookTree->SetBranchAddress("Zinnd",Zinnd); | 
| 245 | fhBookTree->SetBranchAddress("Xoutnd",Xoutnd); | 
| 246 | fhBookTree->SetBranchAddress("Youtnd",Youtnd); | 
| 247 | fhBookTree->SetBranchAddress("Zoutnd",Zoutnd); | 
| 248 | fhBookTree->SetBranchAddress("Erelnd",Erelnd); | 
| 249 | fhBookTree->SetBranchAddress("Timend",Timend); | 
| 250 | fhBookTree->SetBranchAddress("Pathnd",Pathnd); | 
| 251 | fhBookTree->SetBranchAddress("P0nd",P0nd); | 
| 252 | fhBookTree->SetBranchAddress("Nthcard",&Nthcard); | 
| 253 | fhBookTree->SetBranchAddress("Iparcard",Iparcard); | 
| 254 | fhBookTree->SetBranchAddress("Icard",Icard); | 
| 255 | fhBookTree->SetBranchAddress("Xincard",Xincard); | 
| 256 | fhBookTree->SetBranchAddress("Yincard",Yincard); | 
| 257 | fhBookTree->SetBranchAddress("Zincard",Zincard); | 
| 258 | fhBookTree->SetBranchAddress("Xoutcard",Xoutcard); | 
| 259 | fhBookTree->SetBranchAddress("Youtcard",Youtcard); | 
| 260 | fhBookTree->SetBranchAddress("Zoutcard",Zoutcard); | 
| 261 | fhBookTree->SetBranchAddress("Erelcard",Erelcard); | 
| 262 | fhBookTree->SetBranchAddress("Timecard",Timecard); | 
| 263 | fhBookTree->SetBranchAddress("Pathcard",Pathcard); | 
| 264 | fhBookTree->SetBranchAddress("P0card",P0card); | 
| 265 |  | 
| 266 | //    fhBookTree->SetBranchStatus("*",0); | 
| 267 |  | 
| 268 | } | 
| 269 |  | 
| 270 | ClassImp(GPamela); | 
| 271 |  | 
| 272 | ///////////////////////////////////////////////////////////////////////////// | 
| 273 | ///////////////////////////////////////////////////////////////////////////// | 
| 274 | ///////////////////////////////////////////////////////////////////////////// | 
| 275 | ///////////////////////////////////////////////////////////////////////////// | 
| 276 | //-------------------------------------- | 
| 277 | // | 
| 278 | // | 
| 279 | //-------------------------------------- | 
| 280 | /** | 
| 281 | * Default constructor | 
| 282 | */ | 
| 283 | PamTrack::PamTrack(){ | 
| 284 | trk_track  = 0; | 
| 285 | calo_track = 0; | 
| 286 | tof_track  = 0; | 
| 287 | candeleteobj = 0; | 
| 288 | pscore = 0; | 
| 289 | iscore = 0; | 
| 290 | }; | 
| 291 | //-------------------------------------- | 
| 292 | // | 
| 293 | // | 
| 294 | //-------------------------------------- | 
| 295 | /** | 
| 296 | * Constructor | 
| 297 | */ | 
| 298 | PamTrack::PamTrack(TrkTrack* t, CaloTrkVar* c, ToFTrkVar* o){ | 
| 299 |  | 
| 300 | trk_track  = 0; | 
| 301 | calo_track = 0; | 
| 302 | tof_track  = 0; | 
| 303 | //     if(t)trk_track  = new TrkTrack(*t); | 
| 304 | //     if(c)calo_track = new CaloTrkVar(*c); | 
| 305 | //     if(o)tof_track  = new ToFTrkVar(*o); | 
| 306 | if(t)trk_track  = t; | 
| 307 | if(c)calo_track = c; | 
| 308 | if(o)tof_track  = o; | 
| 309 | candeleteobj = 0; | 
| 310 |  | 
| 311 | }; | 
| 312 | PamTrack::PamTrack(const PamTrack& track){ | 
| 313 |  | 
| 314 | TrkTrack   *t = track.trk_track; | 
| 315 | CaloTrkVar *c = track.calo_track; | 
| 316 | ToFTrkVar  *o = track.tof_track; | 
| 317 |  | 
| 318 | trk_track  = 0; | 
| 319 | calo_track = 0; | 
| 320 | tof_track  = 0; | 
| 321 | if(t)trk_track  = new TrkTrack(*t); | 
| 322 | if(c)calo_track = new CaloTrkVar(*c); | 
| 323 | if(o)tof_track  = new ToFTrkVar(*o); | 
| 324 | candeleteobj = 1; | 
| 325 |  | 
| 326 | } | 
| 327 | void PamTrack::Clear(){ | 
| 328 |  | 
| 329 | //    cout << "PamTrack::Clear() "<<candeleteobj<<endl; | 
| 330 | if(candeleteobj){ | 
| 331 | if(trk_track)  trk_track->TrkTrack::Clear(); | 
| 332 | if(calo_track) calo_track->CaloTrkVar::Clear();//??? | 
| 333 | if(tof_track)  tof_track->ToFTrkVar::Clear();//??? | 
| 334 | }else{ | 
| 335 | trk_track  = 0; | 
| 336 | calo_track = 0; | 
| 337 | tof_track  = 0; | 
| 338 | } | 
| 339 | pscore = 0; | 
| 340 | iscore = 0; | 
| 341 |  | 
| 342 | } | 
| 343 | void PamTrack::Delete(){ | 
| 344 | //    cout << "PamTrack::Delete() "<<candeleteobj<<endl; | 
| 345 | if(candeleteobj){ | 
| 346 | if(trk_track)  { | 
| 347 | trk_track->TrkTrack::Clear(); | 
| 348 | delete trk_track; | 
| 349 | } | 
| 350 | if(calo_track){ | 
| 351 | calo_track->CaloTrkVar::Clear();//??? | 
| 352 | delete calo_track; | 
| 353 | } | 
| 354 | if(tof_track){ | 
| 355 | tof_track->ToFTrkVar::Clear();//??? | 
| 356 | delete tof_track; | 
| 357 | } | 
| 358 | }else{ | 
| 359 | Clear(); | 
| 360 | } | 
| 361 | } | 
| 362 | //-------------------------------------- | 
| 363 | // | 
| 364 | // | 
| 365 | //-------------------------------------- | 
| 366 | /** | 
| 367 | * Default Constructor | 
| 368 | */ | 
| 369 | PamLevel2::PamLevel2(){ | 
| 370 | Initialize(); | 
| 371 | }; | 
| 372 |  | 
| 373 | /** | 
| 374 | * Constructor | 
| 375 | * @param ddir Name of directory where level2 files are stored. | 
| 376 | * @param list Name of an ascii file containing the list of file names | 
| 377 | * @param detlist Options to chose what to load. | 
| 378 | * Possible options are: | 
| 379 | *       +AUTO --> load all trees/branches in the input files | 
| 380 | *       +(-)ALL --> inlcude(exclude) all trees/branches | 
| 381 | *       +(-)TRK1+(-)TRK2+(-)CAL1+(-)CAL2+(-)TOF+(-)TRG+(-)ND+(-)S4+(-)ORB+(-)AC --> inlcude(exclude) trees and branches | 
| 382 | *       +(-)TRK0 --> include(exclude) tracker level0 tree | 
| 383 | *       +(-)GP --> include exclude GPAMELA output tree | 
| 384 | * If no options are specified, the default is assumed. Default is: | 
| 385 | * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB | 
| 386 | */ | 
| 387 | PamLevel2::PamLevel2(TString ddir,TString list,TString detlist){ | 
| 388 | Initialize(); | 
| 389 | GetPamTree(GetListOfLevel2Files(ddir,list),detlist); | 
| 390 | GetRunTree(GetListOfLevel2Files(ddir,list)); | 
| 391 | }; | 
| 392 |  | 
| 393 | /** | 
| 394 | * Constructor | 
| 395 | * @param ddir Name of directory where level2 files are stored. | 
| 396 | * @param list Name of an ascii file containing the list of file names | 
| 397 | * Default trees/branches are loaded. Default is: | 
| 398 | * +TRK2+CAL2+CAL1+TOF+TRG+ND+AC+S4+ORB | 
| 399 | */ | 
| 400 | PamLevel2::PamLevel2(TString ddir,TString list){ | 
| 401 | Initialize(); | 
| 402 | GetPamTree(GetListOfLevel2Files(ddir,list),""); | 
| 403 | GetRunTree(GetListOfLevel2Files(ddir,list)); | 
| 404 | }; | 
| 405 |  | 
| 406 |  | 
| 407 | void PamLevel2::Initialize(){ | 
| 408 |  | 
| 409 | h0_obj    = 0; | 
| 410 | trk0_obj  = 0; | 
| 411 | calo0_obj  = 0; | 
| 412 |  | 
| 413 | trk2_obj  = 0; | 
| 414 | trk1_obj  = 0; | 
| 415 | trkh_obj  = 0; | 
| 416 | calo1_obj = 0; | 
| 417 | calo2_obj = 0; | 
| 418 | tof_obj   = 0; | 
| 419 | trig_obj  = 0; | 
| 420 | s4_obj    = 0; | 
| 421 | nd_obj    = 0; | 
| 422 | ac_obj    = 0; | 
| 423 | orb_obj   = 0; | 
| 424 | gp_obj    = 0; | 
| 425 |  | 
| 426 | run_obj   = 0;//new GL_RUN(); | 
| 427 | soft_obj   = 0;// Emiliano | 
| 428 | irun = -1LL; | 
| 429 | runfirstentry = 0LL; | 
| 430 | runlastentry = 0LL; | 
| 431 |  | 
| 432 | l0_file = NULL; | 
| 433 | l0_tree = NULL; | 
| 434 | iroot   = -1; | 
| 435 | dbc     = 0; | 
| 436 |  | 
| 437 | prevshift = 0; | 
| 438 | maxshift = 10; //EMILIANO | 
| 439 |  | 
| 440 | run_tree = NULL; | 
| 441 | run_tree_clone = NULL; | 
| 442 | sel_tree = NULL; | 
| 443 | sel_tree_clone = NULL; | 
| 444 |  | 
| 445 | irunentry = -1LL; | 
| 446 | pam_tree = NULL; | 
| 447 | for(Int_t i=0; i<NCLONES; i++ )pam_tree_clone[i]=NULL; | 
| 448 |  | 
| 449 | totdltime[0] = 0LL; | 
| 450 | totdltime[1] = 0LL; | 
| 451 |  | 
| 452 | host = "mysql://localhost/pamelaprod"; | 
| 453 | user = "anonymous"; | 
| 454 | psw = ""; | 
| 455 | const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); | 
| 456 | const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); | 
| 457 | const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); | 
| 458 | if ( !pamdbhost ) pamdbhost = ""; | 
| 459 | if ( !pamdbuser ) pamdbuser = ""; | 
| 460 | if ( !pamdbpsw ) pamdbpsw = ""; | 
| 461 | if ( strcmp(pamdbhost,"") ) host = pamdbhost; | 
| 462 | if ( strcmp(pamdbuser,"") ) user = pamdbuser; | 
| 463 | if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; | 
| 464 |  | 
| 465 |  | 
| 466 |  | 
| 467 | //    sorted_tracks = 0;//new TRefArray(); | 
| 468 |  | 
| 469 | CAL0 = false; | 
| 470 | CAL1 = true; | 
| 471 | CAL2 = true; | 
| 472 | TRK2 = true; | 
| 473 | TRK1 = false; | 
| 474 | TRK0 = false; | 
| 475 | TRKh = false; | 
| 476 | TRG  = true; | 
| 477 | TOF  = true; | 
| 478 | TOF0 = false; | 
| 479 | S4   = true; | 
| 480 | ND   = true; | 
| 481 | AC   = true; | 
| 482 | ORB  = true; | 
| 483 | GP   = false; | 
| 484 |  | 
| 485 | RUN  = true; | 
| 486 |  | 
| 487 | SELLI = -1; | 
| 488 |  | 
| 489 | ISGP = false; | 
| 490 |  | 
| 491 | tsorted=0; | 
| 492 | timage=0; | 
| 493 |  | 
| 494 | howtosort = "+CAL+TOF"; | 
| 495 | //howtosort = "+TOF"; | 
| 496 | sortthr = 100.; | 
| 497 |  | 
| 498 | }; | 
| 499 | /** | 
| 500 | * Delete the event (act as Dtor) | 
| 501 | */ | 
| 502 | void PamLevel2::Delete(){ | 
| 503 |  | 
| 504 | if(run_obj)delete run_obj; | 
| 505 | if(soft_obj)delete soft_obj; //Emiliano | 
| 506 |  | 
| 507 | //    cout << "void PamLevel2::Clear()"<<endl; | 
| 508 | if(h0_obj)   delete h0_obj; | 
| 509 | if(trk0_obj) delete trk0_obj; | 
| 510 | if(calo0_obj) delete calo0_obj; | 
| 511 | if(trk1_obj) delete trk1_obj; | 
| 512 | if(trk2_obj) delete trk2_obj; | 
| 513 | if(trkh_obj) delete trkh_obj; | 
| 514 | if(calo1_obj)delete calo1_obj; | 
| 515 | if(calo2_obj)delete calo2_obj; | 
| 516 | if(tof_obj)  delete tof_obj; | 
| 517 | if(trig_obj) delete trig_obj; | 
| 518 | if(s4_obj)   delete s4_obj; | 
| 519 | if(nd_obj)   delete nd_obj; | 
| 520 | if(ac_obj)   delete ac_obj; | 
| 521 | if(orb_obj)  delete orb_obj; | 
| 522 | if(gp_obj)   delete gp_obj; | 
| 523 |  | 
| 524 | if(tsorted){ | 
| 525 | tsorted->Delete(); | 
| 526 | delete tsorted; | 
| 527 | } | 
| 528 | if(timage){ | 
| 529 | timage->Delete(); | 
| 530 | delete timage; | 
| 531 | } | 
| 532 |  | 
| 533 | if(dbc){ | 
| 534 | dbc->Close(); | 
| 535 | delete dbc; | 
| 536 | } | 
| 537 |  | 
| 538 | if(l0_file)l0_file->Close(); | 
| 539 | //    if(pam_tree)pam_tree->Delete();; | 
| 540 |  | 
| 541 | if ( pam_tree ){ | 
| 542 | // | 
| 543 | // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault... | 
| 544 | // | 
| 545 | TList *temp = pam_tree->GetListOfFriends(); | 
| 546 | TList *contents  = new TList; // create chain friend list | 
| 547 | contents->SetOwner(); | 
| 548 | TIter next(temp); | 
| 549 | TChain *questo = 0; | 
| 550 | while ( (questo = (TChain*) next()) ){ | 
| 551 | TString name =  questo->GetName(); | 
| 552 | contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list | 
| 553 | }; | 
| 554 | // | 
| 555 | // deleting the main chain | 
| 556 | // | 
| 557 | pam_tree->Delete(); | 
| 558 | // | 
| 559 | // deleting the friends... | 
| 560 | // | 
| 561 | TIter next2(contents); | 
| 562 | TChain *questa = 0; | 
| 563 | while ( questa = (TChain*)next2() ){ | 
| 564 | TString name =  questa->GetName(); | 
| 565 | questa->Delete(); | 
| 566 | questa=NULL; | 
| 567 | }; | 
| 568 | // | 
| 569 | }; | 
| 570 | pam_tree = NULL; | 
| 571 |  | 
| 572 | if(run_tree)run_tree->Delete();; | 
| 573 | if(sel_tree)sel_tree->Delete();; | 
| 574 | for(Int_t i=0; i<NCLONES; i++ )if(pam_tree_clone[i])pam_tree_clone[i]->Delete();; | 
| 575 | if(run_tree_clone)run_tree_clone->Delete();; | 
| 576 | if(sel_tree_clone)sel_tree_clone->Delete();; | 
| 577 |  | 
| 578 |  | 
| 579 | }; | 
| 580 |  | 
| 581 | /** | 
| 582 | * Clear the event (NB! does not deallocate objects) | 
| 583 | */ | 
| 584 | void PamLevel2::Clear(){ | 
| 585 |  | 
| 586 | //    cout << "void PamLevel2::Clear()"<<endl; | 
| 587 |  | 
| 588 | // | 
| 589 | // This method is called once for every entry but RunInfo and SoftInfo do not change until the next run so we cannot clear them here unless we don't | 
| 590 | // want to load them for each event even if they are the same... | 
| 591 | // | 
| 592 | //    if(run_obj)delete run_obj; | 
| 593 | //    if(run_obj) run_obj->Clear();  // Emiliano: Do not deallocate run_obj here, it will give segmentation fault! call clear instead | 
| 594 | //    if(soft_obj) soft_obj->Clear(); | 
| 595 |  | 
| 596 | if(h0_obj)   h0_obj->Clear(); | 
| 597 | //    if(trk0_obj) trk0_obj->Clear(); | 
| 598 | if(trk1_obj) trk1_obj->Clear(); | 
| 599 | if(trk2_obj) trk2_obj->Clear(); | 
| 600 | if(trkh_obj) trkh_obj->Clear(); | 
| 601 | if(calo0_obj) calo0_obj->Clear(); | 
| 602 | if(calo1_obj)calo1_obj->Clear(); | 
| 603 | if(calo2_obj)calo2_obj->Clear(); | 
| 604 | if(tof_obj)  tof_obj->Clear(); | 
| 605 | if(trig_obj) trig_obj->Clear(); | 
| 606 | if(s4_obj)   s4_obj->Clear(); | 
| 607 | if(nd_obj)   nd_obj->Clear(); | 
| 608 | if(ac_obj)   ac_obj->Clear(); | 
| 609 | if(orb_obj)  orb_obj->Clear(); | 
| 610 | if(gp_obj)   gp_obj->Clear(); | 
| 611 |  | 
| 612 | //    if(sorted_tracks)sorted_tracks->Clear(); | 
| 613 | //    sorted_tracks.Clear(); | 
| 614 |  | 
| 615 | if(tsorted){ | 
| 616 | tsorted->Delete(); | 
| 617 | } | 
| 618 | if(timage){ | 
| 619 | timage->Delete(); | 
| 620 | } | 
| 621 | }; | 
| 622 |  | 
| 623 | void PamLevel2::Reset(){ | 
| 624 | // | 
| 625 | // First of all clear everything | 
| 626 | // | 
| 627 | Clear(); | 
| 628 | // | 
| 629 | // close and reset chains and pointers | 
| 630 | // | 
| 631 | if ( pam_tree ){ | 
| 632 | // | 
| 633 | // we have first to find which chains we have to delete, then delete the main chain and only after delete the friend chains. Any other order causes a segfault... | 
| 634 | // | 
| 635 | TList *temp = pam_tree->GetListOfFriends(); | 
| 636 | TList *contents  = new TList; // create chain friend list | 
| 637 | contents->SetOwner(); | 
| 638 | TIter next(temp); | 
| 639 | TChain *questo = 0; | 
| 640 | while ( (questo = (TChain*) next()) ){ | 
| 641 | TString name =  questo->GetName(); | 
| 642 | contents->Add((TChain*)gROOT->FindObject(name.Data()));// add object to the list | 
| 643 | }; | 
| 644 | // | 
| 645 | // deleting the main chain | 
| 646 | // | 
| 647 | pam_tree->Delete(); | 
| 648 | // | 
| 649 | // deleting the friends... | 
| 650 | // | 
| 651 | TIter next2(contents); | 
| 652 | TChain *questa = 0; | 
| 653 | while ( questa = (TChain*)next2() ){ | 
| 654 | TString name =  questa->GetName(); | 
| 655 | questa->Delete(); | 
| 656 | questa=NULL; | 
| 657 | }; | 
| 658 | // | 
| 659 | }; | 
| 660 | pam_tree = NULL; | 
| 661 | // | 
| 662 | if(run_tree)run_tree->Delete();; | 
| 663 | run_tree = NULL; | 
| 664 | if(sel_tree)sel_tree->Delete();; | 
| 665 | sel_tree = NULL; | 
| 666 | // | 
| 667 | // Close file | 
| 668 | // | 
| 669 | if(l0_file)l0_file->Close("R"); | 
| 670 | l0_file = NULL; | 
| 671 | // | 
| 672 | h0_obj    = 0; | 
| 673 | trk0_obj  = 0; | 
| 674 | calo0_obj  = 0; | 
| 675 | // | 
| 676 | trk2_obj  = 0; | 
| 677 | trk1_obj  = 0; | 
| 678 | trkh_obj  = 0; | 
| 679 | calo1_obj = 0; | 
| 680 | calo2_obj = 0; | 
| 681 | tof_obj   = 0; | 
| 682 | trig_obj  = 0; | 
| 683 | s4_obj    = 0; | 
| 684 | nd_obj    = 0; | 
| 685 | ac_obj    = 0; | 
| 686 | orb_obj   = 0; | 
| 687 | gp_obj    = 0; | 
| 688 | // | 
| 689 | // Reset run pointers | 
| 690 | // | 
| 691 | run_obj   = 0;//new GL_RUN(); | 
| 692 | soft_obj   = 0;// Emiliano | 
| 693 | irun = -1; | 
| 694 | runfirstentry = 0ULL; | 
| 695 | runlastentry = 0ULL; | 
| 696 | // | 
| 697 | totdltime[0] = 0LL; | 
| 698 | totdltime[1] = 0LL; | 
| 699 | // | 
| 700 | }; | 
| 701 |  | 
| 702 | Bool_t PamLevel2::IsGood(){ | 
| 703 | Bool_t goodev=true; | 
| 704 | //  if(trk2_obj && trk2_obj->UnpackError() != 0 ) goodev = false; | 
| 705 | if(calo2_obj && calo2_obj->good != 1) goodev = false; | 
| 706 | if(tof_obj && tof_obj->unpackError != 0) goodev = false; | 
| 707 | if(trig_obj && trig_obj->unpackError != 0) goodev = false; | 
| 708 | if(s4_obj && s4_obj->unpackError != 0) goodev = false; | 
| 709 | if(nd_obj && nd_obj->unpackError != 0) goodev = false; | 
| 710 | if(ac_obj && ac_obj->unpackError != 255) goodev = false; | 
| 711 | //  if(orb_obj) | 
| 712 | return goodev; | 
| 713 | }; | 
| 714 |  | 
| 715 | //-------------------------------------- | 
| 716 | // | 
| 717 | // | 
| 718 | //-------------------------------------- | 
| 719 | void *PamLevel2::GetPointerTo(const char* c ){ | 
| 720 |  | 
| 721 | TString objname = c; | 
| 722 |  | 
| 723 | if(!objname.CompareTo("TrkLevel1"))  { | 
| 724 | if(!trk1_obj){ | 
| 725 | trk1_obj  = new TrkLevel1(); | 
| 726 | trk1_obj->Set(); | 
| 727 | } | 
| 728 | return &trk1_obj; | 
| 729 | }; | 
| 730 | if(!objname.CompareTo("TrkLevel2"))  { | 
| 731 | if(!trk2_obj){ | 
| 732 | trk2_obj  = new TrkLevel2(); | 
| 733 | trk2_obj->Set(); | 
| 734 | } | 
| 735 | return &trk2_obj; | 
| 736 | }; | 
| 737 | if(!objname.CompareTo("TrkHough"))   { | 
| 738 | if(!trkh_obj)  trkh_obj  = new TrkHough(); | 
| 739 | return &trkh_obj; | 
| 740 | }; | 
| 741 | if(!objname.CompareTo("CaloLevel1")) { | 
| 742 | if(!calo1_obj) calo1_obj = new CaloLevel1(); | 
| 743 | return &calo1_obj; | 
| 744 | }; | 
| 745 | if(!objname.CompareTo("CaloLevel2")) { | 
| 746 | if(!calo2_obj){ | 
| 747 | calo2_obj = new CaloLevel2(); | 
| 748 | calo2_obj->Set(); | 
| 749 | }; | 
| 750 | return &calo2_obj; | 
| 751 | }; | 
| 752 | if(!objname.CompareTo("ToFLevel2"))  { | 
| 753 | if(!tof_obj){ | 
| 754 | tof_obj   = new ToFLevel2(); | 
| 755 | tof_obj->Set(); | 
| 756 | } | 
| 757 | return &tof_obj; | 
| 758 | }; | 
| 759 | if(!objname.CompareTo("TrigLevel2")) { | 
| 760 | if(!trig_obj)  trig_obj  = new TrigLevel2(); | 
| 761 | return &trig_obj; | 
| 762 | }; | 
| 763 | if(!objname.CompareTo("S4Level2"))   { | 
| 764 | if(!s4_obj)    s4_obj    = new S4Level2(); | 
| 765 | return &s4_obj; | 
| 766 | }; | 
| 767 | if(!objname.CompareTo("NDLevel2"))   { | 
| 768 | if(!nd_obj)    nd_obj    = new NDLevel2(); | 
| 769 | return &nd_obj; | 
| 770 | }; | 
| 771 | if(!objname.CompareTo("AcLevel2"))   { | 
| 772 | if(!ac_obj)    ac_obj    = new AcLevel2(); | 
| 773 | return &ac_obj; | 
| 774 | }; | 
| 775 | if(!objname.CompareTo("OrbitalInfo")){ | 
| 776 | if(!orb_obj)   orb_obj   = new OrbitalInfo(); | 
| 777 | return &orb_obj; | 
| 778 | }; | 
| 779 | if(!objname.CompareTo("GPamela")){ | 
| 780 | if(!gp_obj)   gp_obj   = new GPamela(); | 
| 781 | return &gp_obj; | 
| 782 | }; | 
| 783 |  | 
| 784 | if(!objname.CompareTo("RunInfo"))return &run_obj; | 
| 785 |  | 
| 786 | if(!objname.CompareTo("SoftInfo"))return &soft_obj; // Emiliano | 
| 787 |  | 
| 788 | return NULL; | 
| 789 | }; | 
| 790 | //-------------------------------------- | 
| 791 | // | 
| 792 | // | 
| 793 | //-------------------------------------- | 
| 794 | /** | 
| 795 | * Retrieves the calorimeter track matching the seqno-th tracker stored track. | 
| 796 | * (If seqno = -1 retrieves the self-trigger calorimeter track) | 
| 797 | */ | 
| 798 | CaloTrkVar *PamLevel2::GetCaloStoredTrack(int seqno){ | 
| 799 |  | 
| 800 | if( !calo2_obj )return 0; | 
| 801 |  | 
| 802 | if( calo2_obj->CaloLevel2::ntrk()==0 ){ | 
| 803 | cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no Calorimeter tracks are stored"<<endl; | 
| 804 | return NULL; | 
| 805 | }; | 
| 806 |  | 
| 807 | CaloTrkVar *c = 0; | 
| 808 | Int_t it_calo=0; | 
| 809 |  | 
| 810 | do{ | 
| 811 | c = calo2_obj->CaloLevel2::GetCaloTrkVar(it_calo); | 
| 812 | it_calo++; | 
| 813 | } while( c && seqno != c->trkseqno && it_calo < calo2_obj->CaloLevel2::ntrk()); | 
| 814 |  | 
| 815 | if(!c || seqno != c->trkseqno){ | 
| 816 | c = 0; | 
| 817 | if(seqno!=-1)cout << "PamLevel2::GetCaloStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match Calorimeter stored tracks"<<endl; | 
| 818 | }; | 
| 819 | return c; | 
| 820 |  | 
| 821 | }; | 
| 822 | //-------------------------------------- | 
| 823 | // | 
| 824 | // | 
| 825 | //-------------------------------------- | 
| 826 | /** | 
| 827 | * Retrieves the ToF track matching the seqno-th tracker stored track. | 
| 828 | * (If seqno = -1 retrieves the tracker-independent tof track) | 
| 829 | */ | 
| 830 | ToFTrkVar *PamLevel2::GetToFStoredTrack(int seqno){ | 
| 831 |  | 
| 832 | if( !tof_obj )return 0; | 
| 833 |  | 
| 834 | if( tof_obj->ToFLevel2::ntrk()==0 ){ | 
| 835 | cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" but no ToF tracks are stored"<<endl; | 
| 836 | return NULL; | 
| 837 | }; | 
| 838 |  | 
| 839 | ToFTrkVar *c = 0; | 
| 840 | Int_t it_tof=0; | 
| 841 |  | 
| 842 | do{ | 
| 843 | c = tof_obj->ToFLevel2::GetToFTrkVar(it_tof); | 
| 844 | it_tof++; | 
| 845 | } while( c && seqno != c->trkseqno && it_tof < tof_obj->ToFLevel2::ntrk()); | 
| 846 |  | 
| 847 | if(!c || seqno != c->trkseqno){ | 
| 848 | c = 0; | 
| 849 | if(seqno!=-1)cout << "PamLevel2::GetToFStoredTrack(int) : requested tracker SeqNo "<< seqno <<" does not match ToF stored tracks"<<endl; | 
| 850 | }; | 
| 851 | return c; | 
| 852 |  | 
| 853 | }; | 
| 854 |  | 
| 855 | //-------------------------------------- | 
| 856 | // | 
| 857 | // | 
| 858 | //-------------------------------------- | 
| 859 | /** | 
| 860 | * Give the pamela track associated to a tracker track, retrieving related calorimeter and tof track information. | 
| 861 | */ | 
| 862 | PamTrack* PamLevel2::GetPamTrackAlong(TrkTrack* t){ | 
| 863 |  | 
| 864 | cout <<"PamLevel2::GetPamTrackAlong(TrkTrack* t) **obsolete** "<<endl; | 
| 865 | cout <<"(if you use it, remember to delete the PamTrack object)"<<endl; | 
| 866 |  | 
| 867 | CaloTrkVar *c = 0; | 
| 868 | ToFTrkVar  *o = 0; | 
| 869 |  | 
| 870 | if(CAL2) c = GetCaloStoredTrack(t->GetSeqNo()); | 
| 871 | if(TOF) o = GetToFStoredTrack(t->GetSeqNo()); | 
| 872 |  | 
| 873 | //    if(t && c && o)track = new PamTrack(t,c,o); | 
| 874 | PamTrack *track = new PamTrack(t,c,o); | 
| 875 |  | 
| 876 | return track; | 
| 877 |  | 
| 878 | }; | 
| 879 | //-------------------------------------- | 
| 880 | // | 
| 881 | // | 
| 882 | //-------------------------------------- | 
| 883 | /** | 
| 884 | * Retrieves the it-th stored track. | 
| 885 | * It override TrkLevel2::GetTrack(int it). | 
| 886 | * @param itrk Track number, ranging from 0 to GetNTracks(). | 
| 887 | */ | 
| 888 |  | 
| 889 | PamTrack* PamLevel2::GetStoredTrack(Int_t itrk){ | 
| 890 |  | 
| 891 | cout <<"PamLevel2::GetStoredTrack(Int_t itrk) **to-be-updated** "<<endl; | 
| 892 | cout <<"for the moment, better use separately the methods: TrkLevel2::GetStoredTrack(seqno) CaloLevel2::GetCaloTrkVar(Int_t notrack) ToFLevel2::GetToFTrkVar(Int_t notrack)"<<endl; | 
| 893 | cout <<"(if you use it, remember to delete the PamTrack object)"<<endl; | 
| 894 | PamTrack *track = 0; | 
| 895 |  | 
| 896 | if( itrk >=0 && itrk < trk2_obj->TrkLevel2::ntrk() ){ | 
| 897 |  | 
| 898 | TrkTrack *t = trk2_obj->TrkLevel2::GetStoredTrack(itrk); | 
| 899 | track = GetPamTrackAlong(t); | 
| 900 |  | 
| 901 |  | 
| 902 |  | 
| 903 | }else{ | 
| 904 | cout << "PamLevel2::GetStoredTrack(int) : tracker track SeqNo "<< itrk <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl; | 
| 905 | }; | 
| 906 |  | 
| 907 | return track; | 
| 908 |  | 
| 909 | } | 
| 910 | //-------------------------------------- | 
| 911 | // | 
| 912 |  | 
| 913 | /** | 
| 914 | * Sort physical (tracker) tracks. Left here as backward compatibility method. | 
| 915 | **/ | 
| 916 | void PamLevel2::SortTracks(TString how){ | 
| 917 | printf(" WARNING! obsolete, use SortTracks() and SetSortingMethod(TString) instead! \n Setting sorting method to %s \n",how.Data()); | 
| 918 | howtosort = how; | 
| 919 | SortTracks(); | 
| 920 | }; | 
| 921 |  | 
| 922 | // | 
| 923 | //-------------------------------------- | 
| 924 | /** | 
| 925 | * Sort physical (tracker) tracks. | 
| 926 | * @param how String to set the sorting cryterium (es: "CAL" or "TRK+CAL+TOF" ecc...). | 
| 927 | * Sorting cryteria: | 
| 928 | * TRK: lower chi**2 | 
| 929 | * CAL: lower Y spatial residual on the first calorimeter plane | 
| 930 | * TOF: bigger numebr of hit PMTs along the track, on S12 S21 S32 (where paddles are along the Y axis). | 
| 931 | * S1: (ask Emiliano) | 
| 932 | * S2: (ask Emiliano) | 
| 933 | * S3: (ask Emiliano) | 
| 934 | * GP: more GP hits | 
| 935 | * The default sorting cryterium is "TOF+CAL". | 
| 936 | * | 
| 937 | * The total number of physical tracks is always given by GetNTracks() and the it-th physical track can be retrieved by means of the methods GetTrack(int it) and GetTrack(int it, TString how). | 
| 938 | */ | 
| 939 | void PamLevel2::SortTracks(){ | 
| 940 | TString how = howtosort; | 
| 941 |  | 
| 942 | //  cout <<" PamLevel2::SortTracks(TString how) "<<endl; | 
| 943 | if( !trk2_obj ){ | 
| 944 | cout << "void PamLevel2::SortTracks():  TrkLevel2 not loaded !!!"; | 
| 945 | return; | 
| 946 | }; | 
| 947 | //Save current Object count | 
| 948 | Int_t ObjectNumber = TProcessID::GetObjectCount(); | 
| 949 |  | 
| 950 | // create TCloneArrays to store tracks and its images | 
| 951 | if(!tsorted)tsorted = new TClonesArray("PamTrack",trk2_obj->GetNTracks()); | 
| 952 | tsorted->Delete(); | 
| 953 | TClonesArray &ttsorted = *tsorted; | 
| 954 |  | 
| 955 | if(!timage)timage = new TClonesArray("PamTrack",trk2_obj->GetNTracks()); | 
| 956 | timage->Delete(); | 
| 957 | TClonesArray &ttimage = *timage; | 
| 958 |  | 
| 959 |  | 
| 960 |  | 
| 961 | //-------------------------------------------------- | 
| 962 | // retrieve sorting method | 
| 963 | //-------------------------------------------------- | 
| 964 | Bool_t use_TRK = how.Contains("TRK", TString::kIgnoreCase); | 
| 965 | Bool_t use_CAL = how.Contains("CAL", TString::kIgnoreCase); | 
| 966 | Bool_t use_TOF = how.Contains("TOF", TString::kIgnoreCase); | 
| 967 | Bool_t use_S1 = how.Contains("S1", TString::kIgnoreCase); | 
| 968 | Bool_t use_S2 = how.Contains("S2", TString::kIgnoreCase); | 
| 969 | Bool_t use_S3 = how.Contains("S3", TString::kIgnoreCase); | 
| 970 | Bool_t use_GP = how.Contains("GP", TString::kIgnoreCase); | 
| 971 |  | 
| 972 | if ( use_TOF ){ | 
| 973 | use_S1 = true; | 
| 974 | use_S2 = true; | 
| 975 | use_S3 = true; | 
| 976 | }; | 
| 977 | if( !CAL2 &&  use_CAL) use_CAL = false; | 
| 978 | if( !TOF ){ | 
| 979 | use_TOF = false; | 
| 980 | use_S1  = false; | 
| 981 | use_S2  = false; | 
| 982 | use_S3  = false; | 
| 983 | } | 
| 984 | if( !GP ){ | 
| 985 | use_GP  = false; | 
| 986 | } | 
| 987 |  | 
| 988 | if( !TRK2 ){ | 
| 989 | cout << "SortTracks() : without tracker does not work!!! (not yet)" << endl; | 
| 990 | return; | 
| 991 | }; | 
| 992 |  | 
| 993 | //   cout << "use_CAL "<<use_CAL<<" use_TOF "<<use_TOF<<" use_TRK "<<use_TRK <<endl; | 
| 994 |  | 
| 995 |  | 
| 996 | //-------------------------------------------------- | 
| 997 | // loop over "physical" tracks sorted by the tracker | 
| 998 | //-------------------------------------------------- | 
| 999 | for(Int_t i=0; i < trk2_obj->TrkLevel2::GetNTracks(); i++){ | 
| 1000 |  | 
| 1001 | TrkTrack   *ts = 0; | 
| 1002 | CaloTrkVar *cs = 0; | 
| 1003 | ToFTrkVar  *os = 0; | 
| 1004 |  | 
| 1005 | // get tracker tracks | 
| 1006 | TrkTrack   *tp = trk2_obj->TrkLevel2::GetTrack(i); //tracker | 
| 1007 | CaloTrkVar *cp = GetCaloStoredTrack(tp->GetSeqNo()); | 
| 1008 | ToFTrkVar  *op = GetToFStoredTrack(tp->GetSeqNo()); | 
| 1009 |  | 
| 1010 | TrkTrack   *ti = 0; //tracker (image) | 
| 1011 | CaloTrkVar *ci = 0; | 
| 1012 | ToFTrkVar  *oi = 0; | 
| 1013 | //      cout << "trk track n. "<<i << " "<<hex<< tp <<dec<< endl; | 
| 1014 | // if track has an image, check image selection | 
| 1015 |  | 
| 1016 | Int_t tp_score = 0;  //main track sorted by the tracker | 
| 1017 | Int_t ti_score = 0;  //image track | 
| 1018 | Int_t totp_score = 0;  //main track sorted by the tracker | 
| 1019 | Int_t toti_score = 0;  //image track | 
| 1020 |  | 
| 1021 | if(tp->HasImage()){ | 
| 1022 |  | 
| 1023 | ti = trk2_obj->TrkLevel2::GetTrackImage(i);              //tracker (image) | 
| 1024 | ci = GetCaloStoredTrack(ti->GetSeqNo()); | 
| 1025 | oi = GetToFStoredTrack(ti->GetSeqNo()); | 
| 1026 |  | 
| 1027 | //      cout << "its image "<<i << " "<<hex<< ti <<dec<< endl; | 
| 1028 |  | 
| 1029 | //assign starting scores | 
| 1030 | tp_score = 0;  //main track sorted by the tracker | 
| 1031 | ti_score = 0;  //image track | 
| 1032 |  | 
| 1033 | // ----------------------------------------------------------------------------------------- | 
| 1034 | // ***************************************************************************************** | 
| 1035 | // ----------------------------------------------------------------------------------------- | 
| 1036 | // calorimeter check | 
| 1037 | // ----------------------------------------------------------------------------------------- | 
| 1038 | if( use_CAL && !calo2_obj ){ | 
| 1039 | cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but CaloLevel2 not loaded !!!"; | 
| 1040 | return; | 
| 1041 | }; | 
| 1042 | if( use_CAL && !cp &&  ci ){ | 
| 1043 | ti_score++; | 
| 1044 | toti_score++; | 
| 1045 | }; | 
| 1046 | if( use_CAL &&  cp && !ci ){ | 
| 1047 | tp_score++; | 
| 1048 | totp_score++; | 
| 1049 | }; | 
| 1050 | if( | 
| 1051 | use_CAL            && | 
| 1052 | cp && ci && | 
| 1053 | true){ | 
| 1054 |  | 
| 1055 |  | 
| 1056 | if( | 
| 1057 | cp->npresh > ci->npresh && | 
| 1058 | true){ | 
| 1059 | tp_score++; | 
| 1060 | totp_score++; | 
| 1061 | }; | 
| 1062 | if( | 
| 1063 | cp->npresh < ci->npresh && | 
| 1064 | true){ | 
| 1065 | ti_score++; | 
| 1066 | toti_score++; | 
| 1067 | }; | 
| 1068 |  | 
| 1069 | //      cout << "CALO "<<tp_score<<ti_score<<endl; | 
| 1070 |  | 
| 1071 | }; | 
| 1072 | // ----------------------------------------------------------------------------------------- | 
| 1073 | // ***************************************************************************************** | 
| 1074 | // ----------------------------------------------------------------------------------------- | 
| 1075 | // TOF check | 
| 1076 | // ----------------------------------------------------------------------------------------- | 
| 1077 | // check the number of hit pmts along the track | 
| 1078 | // on S12 S21 and S32, where paddles are parallel to Y axis | 
| 1079 | if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !tof_obj ){ | 
| 1080 | cout << "void PamLevel2::SortTracks(): howtosort= "<<how<<" but ToFLevel2 not loaded !!!"; | 
| 1081 | return; | 
| 1082 | }; | 
| 1083 | // | 
| 1084 | if( (use_TOF || use_S1 || use_S2 || use_S3 ) && !op && oi ){ | 
| 1085 | ti_score++; | 
| 1086 | toti_score++; | 
| 1087 | }; | 
| 1088 | if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && !oi ){ | 
| 1089 | tp_score++; | 
| 1090 | totp_score++; | 
| 1091 | }; | 
| 1092 | if( (use_TOF || use_S1 || use_S2 || use_S3 ) && op && oi ){ | 
| 1093 | // | 
| 1094 | Float_t sen = 0.; | 
| 1095 | for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1096 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1097 | if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (op->dedx).At(ih); | 
| 1098 | }; | 
| 1099 | for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1100 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1101 | if ( pl == 2 || pl == 3 || pl == 4 || pl == 5 ) sen += (oi->dedx).At(ih); | 
| 1102 | }; | 
| 1103 | // | 
| 1104 | if (  sen >= sortthr && false){ // temporary disabled NUCLEI special algorithm since the new one should work for every particle (to be checked!) | 
| 1105 | //printf(" IS A NUCLEUS! en = %f \n",sen); | 
| 1106 | // | 
| 1107 | // is a nucleus use a different algorithm | 
| 1108 | // | 
| 1109 | Int_t nz = 6; Float_t zin[6];                                          // << define TOF z-coordinates | 
| 1110 | for(Int_t ip=0; ip<nz; ip++) | 
| 1111 | zin[ip] = tof_obj->ToFLevel2::GetZTOF(tof_obj->ToFLevel2::GetToFPlaneID(ip));     // << read ToF plane z-coordinates | 
| 1112 | Trajectory *tr = new Trajectory(nz,zin); | 
| 1113 | // | 
| 1114 | Int_t nphit_p =0; | 
| 1115 | Int_t nphit_i =0; | 
| 1116 | Float_t enhit_p = 0.; | 
| 1117 | Float_t enhit_i = 0.; | 
| 1118 | // | 
| 1119 | for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1120 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1121 | if(pl == 1 || pl == 2 || pl == 5){ | 
| 1122 | nphit_p++; | 
| 1123 | enhit_p += (op->dedx).At(ih); | 
| 1124 | }; | 
| 1125 | }; | 
| 1126 | // | 
| 1127 | tp->DoTrack2(tr); | 
| 1128 | // | 
| 1129 | if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){ | 
| 1130 | for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1131 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1132 | if(pl == 0){ | 
| 1133 | nphit_p++; | 
| 1134 | enhit_p += (op->dedx).At(ih); | 
| 1135 | }; | 
| 1136 | }; | 
| 1137 | }; | 
| 1138 | if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){ | 
| 1139 | for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1140 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1141 | if(pl == 3){ | 
| 1142 | nphit_p++; | 
| 1143 | enhit_p += (op->dedx).At(ih); | 
| 1144 | }; | 
| 1145 | }; | 
| 1146 | }; | 
| 1147 | if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){ | 
| 1148 | for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1149 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1150 | if(pl == 4){ | 
| 1151 | nphit_p++; | 
| 1152 | enhit_p += (op->dedx).At(ih); | 
| 1153 | }; | 
| 1154 | }; | 
| 1155 | }; | 
| 1156 |  | 
| 1157 | for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1158 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1159 | if(pl == 1 || pl == 2 || pl == 5){ | 
| 1160 | nphit_i++; | 
| 1161 | enhit_i += (op->dedx).At(ih); | 
| 1162 | }; | 
| 1163 | }; | 
| 1164 | // | 
| 1165 | ti->DoTrack2(tr); | 
| 1166 | // | 
| 1167 | if ( fabs(tr->y[0]-oi->ytofpos[0]) < 2. ){ | 
| 1168 | for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1169 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1170 | if(pl == 0){ | 
| 1171 | nphit_i++; | 
| 1172 | enhit_i += (op->dedx).At(ih); | 
| 1173 | }; | 
| 1174 | }; | 
| 1175 | }; | 
| 1176 | if ( fabs(tr->y[3]-oi->ytofpos[1]) < 2. ){ | 
| 1177 | for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1178 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1179 | if(pl == 3){ | 
| 1180 | nphit_i++; | 
| 1181 | enhit_i += (op->dedx).At(ih); | 
| 1182 | }; | 
| 1183 | }; | 
| 1184 | }; | 
| 1185 | if ( fabs(tr->y[4]-oi->ytofpos[2]) < 2. ){ | 
| 1186 | for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1187 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1188 | if(pl == 4){ | 
| 1189 | nphit_i++; | 
| 1190 | enhit_i += (op->dedx).At(ih); | 
| 1191 | }; | 
| 1192 | }; | 
| 1193 | }; | 
| 1194 |  | 
| 1195 |  | 
| 1196 | if( | 
| 1197 | (use_TOF || use_S1 || use_S2 || use_S3)            && | 
| 1198 | (nphit_p+nphit_i) !=0 && | 
| 1199 | true){ | 
| 1200 |  | 
| 1201 | //          printf(" seqno %i nphit_p %i nphit_i %i enhit_p %f enhit_i %f \n",trk2_obj->TrkLevel2::GetSeqNo(i),nphit_p,nphit_i,enhit_p,enhit_i); | 
| 1202 | //          printf(" score p %i score i %i \n",tp_score,ti_score); | 
| 1203 | //                if( enhit_p > enhit_i ) tp_score++; | 
| 1204 | //                if( nphit_p >= nphit_i && enhit_p > enhit_i ) tp_score++; | 
| 1205 | if ( nphit_p > nphit_i ) tp_score++; | 
| 1206 | if ( nphit_p < nphit_i ) ti_score++; | 
| 1207 | if ( nphit_p == nphit_i ){ | 
| 1208 | if ( enhit_p > enhit_i ) tp_score++; | 
| 1209 | else ti_score++; | 
| 1210 | }; | 
| 1211 | //          printf(" dopo score p %i score i %i \n",tp_score,ti_score); | 
| 1212 | }; | 
| 1213 | delete tr; | 
| 1214 | // | 
| 1215 | } else { | 
| 1216 | // ------------- | 
| 1217 | // NOT a NUCLEUS | 
| 1218 | // ------------- | 
| 1219 | //printf(" NOT a NUCLEUS! en = %f \n",sen); | 
| 1220 |  | 
| 1221 | Int_t nphit_p =0; | 
| 1222 | Int_t nphit_i =0; | 
| 1223 |  | 
| 1224 |  | 
| 1225 | /*                          cout << "track: npmtadc "<< op->npmtadc << endl; | 
| 1226 | cout << "track: npmttdc "<< op->npmttdc << endl; | 
| 1227 | cout << "image: npmtadc "<< oi->npmtadc << endl; | 
| 1228 | cout << "image: npmttdc "<< oi->npmttdc << endl;*/ | 
| 1229 |  | 
| 1230 | //        for (Int_t ih=0; ih < op->npmtadc; ih++){ | 
| 1231 | //          Int_t pl = tof_obj->GetPlaneIndex( (op->pmtadc).At(ih) ); | 
| 1232 | //          if(pl == 1 || pl == 2 || pl == 5)nphit_p++; | 
| 1233 | //        }; | 
| 1234 |  | 
| 1235 | //        for (Int_t ih=0; ih < oi->npmtadc; ih++){ | 
| 1236 | //          Int_t pl = tof_obj->GetPlaneIndex( (oi->pmtadc).At(ih) ); | 
| 1237 | //          if(pl == 1 || pl == 2 || pl == 5)nphit_i++; | 
| 1238 | //        }; | 
| 1239 | // --- modified to count tdc signals (more efficient?) | 
| 1240 | // --- and to implement check on tdcflag | 
| 1241 | for (Int_t ih=0; ih < op->npmttdc; ih++){ | 
| 1242 | Int_t pl = tof_obj->GetPlaneIndex( (op->pmttdc).At(ih) ); | 
| 1243 | //          if( (op->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_p++; | 
| 1244 | if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ | 
| 1245 | if( (op->tdcflag).At(ih)==0 )nphit_p++; | 
| 1246 | }; | 
| 1247 | }; | 
| 1248 |  | 
| 1249 | for (Int_t ih=0; ih < oi->npmttdc; ih++){ | 
| 1250 | Int_t pl = tof_obj->GetPlaneIndex( (oi->pmttdc).At(ih) ); | 
| 1251 | //          if( (oi->tdcflag).At(ih)==0 && (pl == 1 || pl == 2 || pl == 5) )nphit_i++; | 
| 1252 | if ( (use_S1 && ( pl == 0 || pl == 1 )) || (use_S2 && ( pl == 2 || pl == 3 )) || (use_S3 && ( pl == 4 || pl == 5 )) ){ | 
| 1253 | if( (oi->tdcflag).At(ih)==0 )nphit_i++; | 
| 1254 | }; | 
| 1255 | }; | 
| 1256 |  | 
| 1257 | if( | 
| 1258 | (nphit_p+nphit_i) !=0 && | 
| 1259 | true){ | 
| 1260 |  | 
| 1261 | if ( nphit_p != nphit_i ){ | 
| 1262 | totp_score += nphit_p; | 
| 1263 | toti_score += nphit_i; | 
| 1264 | tp_score+=nphit_p; | 
| 1265 | ti_score+=nphit_i; | 
| 1266 | }; | 
| 1267 | //          if     ( nphit_p > nphit_i) tp_score+=nphit_p; | 
| 1268 | //          else if( nphit_p < nphit_i) ti_score+=nphit_i; | 
| 1269 | //          else ;//niente | 
| 1270 | }; | 
| 1271 | }; | 
| 1272 | //      cout << "TOF "<<tp_score<<ti_score<<endl; | 
| 1273 | }; | 
| 1274 |  | 
| 1275 |  | 
| 1276 | //      if(tp_score == ti_score) use_TRK = true; | 
| 1277 |  | 
| 1278 |  | 
| 1279 | // ----------------------------------------------------------------------------------------- | 
| 1280 | // ***************************************************************************************** | 
| 1281 | // ----------------------------------------------------------------------------------------- | 
| 1282 | // tracker check | 
| 1283 | // ----------------------------------------------------------------------------------------- | 
| 1284 | // chi**2 difference is not always large enough to distinguish among | 
| 1285 | // the real track and its image. | 
| 1286 | // Tracker check will be applied always when calorimeter and tof information is ambiguous. | 
| 1287 | // *** MODIFIED ON AUGUST 2007 *** | 
| 1288 | if(use_TRK){ | 
| 1289 | //      if(      tp->chi2 > 0 && tp->chi2 < ti->chi2 ) tp_score++ ; | 
| 1290 | //      else if( ti->chi2 > 0 && ti->chi2 < tp->chi2 ) ti_score++ ; | 
| 1291 |  | 
| 1292 | // CHECK 1 : number of points along X | 
| 1293 | if ( tp->GetNX() >= ti->GetNX() ){ | 
| 1294 | tp_score++ ; | 
| 1295 | totp_score++ ; | 
| 1296 | }; | 
| 1297 | if ( tp->GetNX() <= ti->GetNX() ){ | 
| 1298 | ti_score++ ; | 
| 1299 | toti_score++ ; | 
| 1300 | }; | 
| 1301 | // CHECK 2 : number of points along Y | 
| 1302 | if ( tp->GetNY() >= ti->GetNY() ){ | 
| 1303 | tp_score++ ; | 
| 1304 | totp_score++ ; | 
| 1305 | }; | 
| 1306 | if ( tp->GetNY() <= ti->GetNY() ){ | 
| 1307 | ti_score++ ; | 
| 1308 | toti_score++ ; | 
| 1309 | }; | 
| 1310 |  | 
| 1311 | //      cout << "TRK "<<tp_score<<ti_score<<endl; | 
| 1312 | }; | 
| 1313 |  | 
| 1314 |  | 
| 1315 | // ----------------------------------------------------------------------------------------- | 
| 1316 | // ***************************************************************************************** | 
| 1317 | // ----------------------------------------------------------------------------------------- | 
| 1318 | // GPamela check | 
| 1319 | // ----------------------------------------------------------------------------------------- | 
| 1320 |  | 
| 1321 | //--------------------------------------------------- | 
| 1322 | // count the number of GP hits | 
| 1323 | //--------------------------------------------------- | 
| 1324 | if(use_GP){ | 
| 1325 | int ngphits_p=0; | 
| 1326 | int ngphits_i=0; | 
| 1327 | float toll = 0.02; //200 micron | 
| 1328 | for(int ih=0; ih<GetGPamela()->Nthspe; ih++){ | 
| 1329 | int ip = (Int_t) GetGPamela()->Itrpb[ih] - 1; | 
| 1330 | if( | 
| 1331 | tp && | 
| 1332 | tp->YGood(ip) && | 
| 1333 | fabs(tp->ym[ip]- GetGPamela()->Yavspe[ih])<toll && | 
| 1334 | true) ngphits_p++; | 
| 1335 | if( ti && | 
| 1336 | ti->YGood(ip) && | 
| 1337 | fabs(ti->ym[ip]- GetGPamela()->Yavspe[ih])<toll && | 
| 1338 | true) ngphits_i++; | 
| 1339 | } | 
| 1340 | if( | 
| 1341 | ngphits_p > ngphits_i && | 
| 1342 | true){ | 
| 1343 | tp_score++ ; | 
| 1344 | totp_score++ ; | 
| 1345 | } | 
| 1346 | if( | 
| 1347 | ngphits_p < ngphits_i && | 
| 1348 | true){ | 
| 1349 | ti_score++ ; | 
| 1350 | toti_score++ ; | 
| 1351 | } | 
| 1352 | } | 
| 1353 |  | 
| 1354 |  | 
| 1355 | // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1356 | // the winner is.... | 
| 1357 | // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1358 | if      (tp_score > ti_score) { | 
| 1359 |  | 
| 1360 |  | 
| 1361 | }else if (tp_score < ti_score) { | 
| 1362 |  | 
| 1363 |  | 
| 1364 | ts = ti;//its image!! | 
| 1365 | cs = ci; | 
| 1366 | os = oi; | 
| 1367 | Int_t totis = toti_score; | 
| 1368 |  | 
| 1369 | ti = tp;//its image!! | 
| 1370 | ci = cp; | 
| 1371 | oi = op; | 
| 1372 |  | 
| 1373 | tp = ts;//its image!! | 
| 1374 | cp = cs; | 
| 1375 | op = os; | 
| 1376 |  | 
| 1377 | toti_score = totp_score; | 
| 1378 | totp_score = totis; | 
| 1379 |  | 
| 1380 |  | 
| 1381 | }else { | 
| 1382 |  | 
| 1383 | //      cout << "Warning - track image ambiguity not solved" << endl; | 
| 1384 |  | 
| 1385 | }; | 
| 1386 |  | 
| 1387 | }else{ | 
| 1388 | totp_score = 1; | 
| 1389 | toti_score = 0; | 
| 1390 |  | 
| 1391 | //      ts = tp; | 
| 1392 | //      cs = cp; | 
| 1393 | //      os = op; | 
| 1394 | }; | 
| 1395 |  | 
| 1396 | //      cout <<" SortTracks() "<<i<<" -- "<<ts<<endl; | 
| 1397 | //      sorted_tracks->Add(ts);//save the track in the sorted array | 
| 1398 | //      sorted_tracks.Add(ts);//save the track in the sorted array | 
| 1399 | //      sorted_tracks.Add(tp);//save the track in the sorted array | 
| 1400 | //      cout << "SortTracks:: sorted_tracks->Add(it) "<<i<<" "<<ts<<endl; | 
| 1401 | //      cout<<"o "<<tp<<endl; | 
| 1402 | //      cout<<"o "<<cp<<endl; | 
| 1403 | //      cout<<"o "<<op<<endl; | 
| 1404 |  | 
| 1405 | new(ttsorted[i]) PamTrack(tp,cp,op); | 
| 1406 | new(ttimage[i])  PamTrack(ti,ci,oi); | 
| 1407 |  | 
| 1408 | ((PamTrack*)(ttsorted[i]))->SetPScore(totp_score); | 
| 1409 | ((PamTrack*)(ttsorted[i]))->SetIScore(toti_score); | 
| 1410 | ((PamTrack*)(ttimage[i]))->SetPScore(totp_score); | 
| 1411 | ((PamTrack*)(ttimage[i]))->SetIScore(toti_score); | 
| 1412 | }; | 
| 1413 |  | 
| 1414 | if( tsorted->GetEntries() != trk2_obj->GetNTracks() ){ | 
| 1415 | cout << "void PamLevel2::SortTracks(): tsorted->GetEntries() "<<tsorted->GetEntries()<<" != trk2_obj->GetNTracks() = "<<trk2_obj->GetNTracks() <<endl; | 
| 1416 | tsorted->Delete(); tsorted=0; | 
| 1417 | timage->Delete(); timage=0; | 
| 1418 | } | 
| 1419 |  | 
| 1420 | //Restore Object count | 
| 1421 | //To save space in the table keeping track of all referenced objects | 
| 1422 | //We reset the object count to what it was at the beginning of the event. | 
| 1423 | TProcessID::SetObjectCount(ObjectNumber); | 
| 1424 |  | 
| 1425 | }; | 
| 1426 | //-------------------------------------- | 
| 1427 | // | 
| 1428 | // | 
| 1429 | //-------------------------------------- | 
| 1430 | /** | 
| 1431 | * This method overrides TrkLevel2::GetTracks(), where sorting is done by decreasing number of fit points and increasing chi^2. | 
| 1432 | * PamLevel2::GetTracks() keeps the same track order given by TrkLevel2::GetTracks(), but checks image selection by using calorimeter and ToF tracking information. | 
| 1433 | */ | 
| 1434 | // TRefArray *PamLevel2::GetTracks(){ | 
| 1435 |  | 
| 1436 | // //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1437 | //     SortTracks("+CAL+TOF"); | 
| 1438 | // //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1439 |  | 
| 1440 | // //   return  sorted_tracks; | 
| 1441 | //     return &sorted_tracks; | 
| 1442 |  | 
| 1443 | //  }; | 
| 1444 | TClonesArray *PamLevel2::GetTracks(){ | 
| 1445 |  | 
| 1446 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1447 | SortTracks(); | 
| 1448 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1449 |  | 
| 1450 | return tsorted; | 
| 1451 |  | 
| 1452 | }; | 
| 1453 | //-------------------------------------- | 
| 1454 | // | 
| 1455 | // | 
| 1456 | //-------------------------------------- | 
| 1457 | /** | 
| 1458 | * Retrieves the it-th Pamela "physical" track. | 
| 1459 | * It override TrkLevel2::GetTrack(int it). | 
| 1460 | * @param it Track number, ranging from 0 to GetNTracks(). | 
| 1461 | */ | 
| 1462 | PamTrack *PamLevel2::GetTrack(int it){ | 
| 1463 |  | 
| 1464 | //    if(!trk2_obj) return 0; | 
| 1465 |  | 
| 1466 | // //  *-*-*-*+-*-*-*-*-*-*-*-*-* | 
| 1467 | //     SortTracks("+CAL+TOF"); | 
| 1468 | // //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1469 | // //    if(!sorted_tracks)return 0; | 
| 1470 | //     if(sorted_tracks.IsEmpty())return 0; | 
| 1471 |  | 
| 1472 | //     PamTrack *track = 0; | 
| 1473 |  | 
| 1474 | //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() && it<sorted_tracks.GetEntriesFast() ){ | 
| 1475 | //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it); | 
| 1476 | //      track = GetPamTrackAlong(t); | 
| 1477 | //     }else{ | 
| 1478 | //      cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl; | 
| 1479 | //     }; | 
| 1480 |  | 
| 1481 | //     return track; | 
| 1482 |  | 
| 1483 | //    cout << "PamLevel2::GetTrack(int it) "<<endl; | 
| 1484 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1485 | SortTracks(); | 
| 1486 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1487 | if(!tsorted)return 0; | 
| 1488 | if(!tsorted->GetEntries())return 0; | 
| 1489 |  | 
| 1490 | PamTrack *track = 0; | 
| 1491 |  | 
| 1492 | if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks()){ | 
| 1493 | //      TrkTrack   *t = (TrkTrack*)sorted_tracks.At(it); | 
| 1494 | //      track = GetPamTrackAlong(t); | 
| 1495 | TClonesArray &t = *(tsorted); | 
| 1496 | track = (PamTrack*)t[it]; | 
| 1497 |  | 
| 1498 | }else{ | 
| 1499 | cout << "PamLevel2::GetTrack(int) : tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl; | 
| 1500 | }; | 
| 1501 |  | 
| 1502 | return track; | 
| 1503 |  | 
| 1504 | }; | 
| 1505 |  | 
| 1506 | //-------------------------------------- | 
| 1507 | // | 
| 1508 | // | 
| 1509 | //-------------------------------------- | 
| 1510 | /** | 
| 1511 | * Retrieves (if present) the image of the it-th Pamela "physical" track, sorted by the method PamLevel2::SortTracks(). | 
| 1512 | * @param it Track number, ranging from 0 to GetNTracks(). | 
| 1513 | */ | 
| 1514 | PamTrack *PamLevel2::GetTrackImage(int it){ | 
| 1515 |  | 
| 1516 | //     if(!trk2_obj) return 0; | 
| 1517 |  | 
| 1518 | // //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1519 | //     SortTracks("+CAL+TOF"); | 
| 1520 | // //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1521 | // //    if(!sorted_tracks)return 0; | 
| 1522 | //     if(sorted_tracks.IsEmpty())return 0; | 
| 1523 |  | 
| 1524 | //     PamTrack *image = 0; | 
| 1525 |  | 
| 1526 | //     if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){ | 
| 1527 | //      TrkTrack *temp = (TrkTrack*)sorted_tracks.At(it); | 
| 1528 | //      if( temp->HasImage() ){ | 
| 1529 | //          TrkTrack   *t = trk2_obj->TrkLevel2::GetStoredTrack(temp->GetImageSeqNo()); | 
| 1530 | //          image = GetPamTrackAlong(t); | 
| 1531 | //      }else{ | 
| 1532 | //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl; | 
| 1533 | //      }; | 
| 1534 | //     }else{ | 
| 1535 | //      cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl; | 
| 1536 | //     }; | 
| 1537 |  | 
| 1538 | //     return image; | 
| 1539 |  | 
| 1540 |  | 
| 1541 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1542 | SortTracks(); | 
| 1543 | //  *-*-*-*-*-*-*-*-*-*-*-*-* | 
| 1544 | if(!timage)return 0; | 
| 1545 | if(!timage->GetEntries())return 0; | 
| 1546 |  | 
| 1547 | PamTrack *image = 0; | 
| 1548 |  | 
| 1549 | if( it >=0 && it < trk2_obj->TrkLevel2::GetNTracks() ){ | 
| 1550 | TClonesArray &t = *(tsorted); | 
| 1551 | PamTrack *temp = (PamTrack*)t[it]; | 
| 1552 | if( temp->GetTrkTrack()->HasImage() ){ | 
| 1553 | TClonesArray &t = *(timage); | 
| 1554 | image = (PamTrack*)t[it]; | 
| 1555 | }else{ | 
| 1556 | //          cout <<"PamLevel2::GetTrackImage(int) : Track SeqNo "<<it<<" does not have image"<<endl; | 
| 1557 | }; | 
| 1558 | }else{ | 
| 1559 | cout << "PamLevel2::GetTrackImage(int) : Tracker track SeqNo "<< it <<" does not exist (GetNTracks() = "<<trk2_obj->TrkLevel2::GetNTracks()<<")"<<endl; | 
| 1560 | }; | 
| 1561 |  | 
| 1562 | return image; | 
| 1563 | } | 
| 1564 |  | 
| 1565 | //-------------------------------------- | 
| 1566 | // | 
| 1567 | // | 
| 1568 | //-------------------------------------- | 
| 1569 | /** | 
| 1570 | * Get the Pamela detector trees in a single file and make them friends. | 
| 1571 | * @param f TFile pointer | 
| 1572 | * @param detlist String to select trees to be included | 
| 1573 | * @return Pointer to a TTree | 
| 1574 | */ | 
| 1575 | TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ){ | 
| 1576 |  | 
| 1577 | if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) { | 
| 1578 | cout << "+AUTO"<<endl; | 
| 1579 | GetWhichTrees(f); | 
| 1580 | }; | 
| 1581 | SetWhichTrees(detlist); | 
| 1582 |  | 
| 1583 | if ( pam_tree ){ | 
| 1584 | printf("WARNING: TTree *PamLevel2::GetPamTree(TFile *fl, TString detlist) -- pam_tree already exists!\n "); | 
| 1585 | return pam_tree; | 
| 1586 | }; | 
| 1587 | // | 
| 1588 |  | 
| 1589 | cout << "TTree *PamLevel2::GetPamTree(TFile *f, TString detlist ) -- obsolte "<<endl; | 
| 1590 |  | 
| 1591 | //    SetWhichTrees(detlist); | 
| 1592 |  | 
| 1593 | TTree *Trout =0; | 
| 1594 |  | 
| 1595 | TString fname = f->GetName(); | 
| 1596 | if(!CheckLevel2File(fname))return NULL; | 
| 1597 |  | 
| 1598 | //    UInt_t *found=0; | 
| 1599 |  | 
| 1600 | cout<< "GetPamTree(TFile*,TString): detector list --> "; | 
| 1601 | if(TRK1)cout<<"TRK1 "; | 
| 1602 | if(TRK2)cout<<"TRK2 "; | 
| 1603 | if(TRKh)cout<<"TRKH "; | 
| 1604 | if(CAL1)cout<<"CAL1 "; | 
| 1605 | if(CAL2)cout<<"CAL2 "; | 
| 1606 | if(TOF)cout<<"TOF "; | 
| 1607 | if(TRG)cout<<"TRG "; | 
| 1608 | if(AC)cout<<"AC "; | 
| 1609 | if(ND)cout<<"ND "; | 
| 1610 | if(S4)cout<<"S4 "; | 
| 1611 | if(ORB)cout<<"ORB "; | 
| 1612 | if(GP)cout<<"GP "; | 
| 1613 | cout << endl; | 
| 1614 | if(SELLI)cout<<">>> Found selection-list <<<"<<endl; | 
| 1615 |  | 
| 1616 | f->cd(); | 
| 1617 |  | 
| 1618 | // Tracker | 
| 1619 | TTree *T = (TTree*)f->Get("Tracker"); | 
| 1620 | if(T && (TRK2||TRK1||TRKh)) { | 
| 1621 | if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); | 
| 1622 | //      else    T->SetBranchStatus("TrkLevel2",0,found); | 
| 1623 | if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl; | 
| 1624 | if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); | 
| 1625 | //      else    T->SetBranchStatus("TrkLevel1",0,found); | 
| 1626 | if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl; | 
| 1627 | if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); | 
| 1628 | //      else    T->SetBranchStatus("TrkHough",0,found); | 
| 1629 | if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl; | 
| 1630 | if(!Trout)Trout=T; | 
| 1631 | else Trout->AddFriend(T); | 
| 1632 | }else{ | 
| 1633 | cout << "Tracker      : missing tree"<<endl; | 
| 1634 | }; | 
| 1635 | // Calorimeter | 
| 1636 | TTree *C = (TTree*)f->Get("Calorimeter"); | 
| 1637 | if(C && (CAL2||CAL1)) { | 
| 1638 | if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); | 
| 1639 | //      else    C->SetBranchStatus("CaloLevel2",0,found); | 
| 1640 | if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl; | 
| 1641 | if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); | 
| 1642 | //      else    C->SetBranchStatus("CaloLevel1",0,found); | 
| 1643 | if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl; | 
| 1644 | if(!Trout)Trout=C; | 
| 1645 | else Trout->AddFriend(C); | 
| 1646 | }else{ | 
| 1647 | cout << "Calorimeter  : missing tree"<<endl; | 
| 1648 | }; | 
| 1649 |  | 
| 1650 | // ToF | 
| 1651 | TTree *O = (TTree*)f->Get("ToF"); | 
| 1652 | if(O && TOF) { | 
| 1653 | O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); | 
| 1654 | cout << "ToF          : set branch address ToFLevel2"<<endl; | 
| 1655 | if(!Trout)Trout=O; | 
| 1656 | else Trout->AddFriend(O); | 
| 1657 | }else{ | 
| 1658 | cout << "ToF         : missing tree"<<endl; | 
| 1659 | }; | 
| 1660 | // Trigger | 
| 1661 | TTree *R = (TTree*)f->Get("Trigger"); | 
| 1662 | if(R && TRG) { | 
| 1663 | R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); | 
| 1664 | cout << "Trigger      : set branch address TrigLevel2"<<endl; | 
| 1665 | if(!Trout)Trout=R; | 
| 1666 | else Trout->AddFriend(R); | 
| 1667 | }else{ | 
| 1668 | cout << "Trigger      : missing tree"<<endl; | 
| 1669 | }; | 
| 1670 | // S4 | 
| 1671 | TTree *S = (TTree*)f->Get("S4"); | 
| 1672 | if(S && S4) { | 
| 1673 | S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); | 
| 1674 | cout << "S4           : set branch address S4Level2"<<endl; | 
| 1675 | if(!Trout)Trout=S; | 
| 1676 | else Trout->AddFriend(S); | 
| 1677 | }else{ | 
| 1678 | cout << "S4           : missing tree"<<endl; | 
| 1679 | }; | 
| 1680 | // Neutron Detector | 
| 1681 | TTree *N = (TTree*)f->Get("NeutronD"); | 
| 1682 | if(N && ND) { | 
| 1683 | N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); | 
| 1684 | cout << "NeutronD     : set branch address NDLevel2"<<endl; | 
| 1685 | if(!Trout)Trout=N; | 
| 1686 | else Trout->AddFriend(N); | 
| 1687 | }else{ | 
| 1688 | cout << "NeutronD     : missing tree"<<endl; | 
| 1689 | }; | 
| 1690 | // Anticounters | 
| 1691 | TTree *A = (TTree*)f->Get("Anticounter"); | 
| 1692 | if(A && AC) { | 
| 1693 | A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); | 
| 1694 | cout << "Anticounter  : set branch address AcLevel2"<<endl; | 
| 1695 | if(!Trout)Trout=A; | 
| 1696 | else Trout->AddFriend(A); | 
| 1697 | }else{ | 
| 1698 | cout << "Anticounter  : missing tree"<<endl; | 
| 1699 | }; | 
| 1700 | // Orbital Info | 
| 1701 | TTree *B = (TTree*)f->Get("OrbitalInfo"); | 
| 1702 | if(B && ORB) { | 
| 1703 | B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); | 
| 1704 | cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl; | 
| 1705 | if(!Trout)Trout=B; | 
| 1706 | else Trout->AddFriend(B); | 
| 1707 | }else{ | 
| 1708 | cout << "OrbitalInfo  : missing tree"<<endl; | 
| 1709 | }; | 
| 1710 |  | 
| 1711 | // GPamela | 
| 1712 | TTree *G = (TTree*)f->Get("h20"); | 
| 1713 | if(G && GP) { | 
| 1714 | if(!gp_obj)gp_obj=new GPamela(); | 
| 1715 | //      ------------------------------------ | 
| 1716 | //      ATTENZIONE!!! | 
| 1717 | //      non so per quale arcano motivo, | 
| 1718 | //      per l'albero di gpamela il branch address lo devo settare | 
| 1719 | //      DOPO aver fatto friend | 
| 1720 | //      FGRRRVZZZZUTSALKJMSLKJ!!! | 
| 1721 | //      ------------------------------------ | 
| 1722 | //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri | 
| 1723 | //      cout << "h20          : set branch address GPamela "<<endl; | 
| 1724 | if(!Trout)Trout=G; | 
| 1725 | else Trout->AddFriend(G); | 
| 1726 | }else{ | 
| 1727 | //      cout << "h20          : missing tree"<<endl; | 
| 1728 | }; | 
| 1729 |  | 
| 1730 |  | 
| 1731 | TTree *L = (TTree*)f->Get("SelectionList"); | 
| 1732 | if(L && SELLI==1) { | 
| 1733 | //      L->SetBranchAddress("RunEntry",&irun); | 
| 1734 | //      cout << "SelectionList: set branch address RunEntry"<<endl; | 
| 1735 | //      L->SetBranchAddress("EventEntry",&irunentry); | 
| 1736 | //      cout << "SelectionList: set branch address EventEntry"<<endl; | 
| 1737 | //      if(!Trout)Trout=O; | 
| 1738 | //      else Trout->AddFriend("SelectionList"); | 
| 1739 | cout << " TTree *PamLevel2::GetPamTree(TFile, TString) >>> SelectionList not implemented!!!!"<<endl; | 
| 1740 | sel_tree = 0; | 
| 1741 | }else{ | 
| 1742 | cout << "SelectionList  : missing tree"<<endl; | 
| 1743 | }; | 
| 1744 |  | 
| 1745 | cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl; | 
| 1746 |  | 
| 1747 | //      ------------------------------------ | 
| 1748 | //      ATTENZIONE!!! | 
| 1749 | //      non so per quale arcano motivo, | 
| 1750 | //      per l'albero di gpamela il branch address lo devo settare | 
| 1751 | //      DOPO aver fatto friend | 
| 1752 | //      FGRRRVZZZZUTSALKJMSLKJ!!! | 
| 1753 | //      ------------------------------------ | 
| 1754 | if(G && GP) { | 
| 1755 | gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri | 
| 1756 | cout << "h20          : set branch address GPamela "<<endl; | 
| 1757 | }else{ | 
| 1758 | cout << "h20          : missing tree"<<endl; | 
| 1759 | }; | 
| 1760 |  | 
| 1761 | pam_tree = (TChain*)Trout; | 
| 1762 |  | 
| 1763 | return Trout; | 
| 1764 |  | 
| 1765 | } | 
| 1766 | //-------------------------------------- | 
| 1767 | // | 
| 1768 | // | 
| 1769 | //-------------------------------------- | 
| 1770 | /** | 
| 1771 | * Get list of Level2 files. | 
| 1772 | * @param ddir Level2 data directory. | 
| 1773 | * @param flisttxt Name of txt file containing file list. | 
| 1774 | * @return Pointer to a TList of TSystemFiles | 
| 1775 | * If no input file list is given , all the Level2 files inside the directory are processed. | 
| 1776 | */ | 
| 1777 | TList*  PamLevel2::GetListOfLevel2Files(TString ddir, TString flisttxt = ""){ | 
| 1778 |  | 
| 1779 | TString wdir = gSystem->WorkingDirectory(); | 
| 1780 |  | 
| 1781 | //    if(ddir=="")ddir = wdir; | 
| 1782 | //      TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); | 
| 1783 | if ( ddir != ""){ | 
| 1784 | cout << "Level2 data directory : "<<  ddir << endl; | 
| 1785 | } else { | 
| 1786 | cout << "Level2 data directory not given as input: trying to evaluate from list or taking working directory " << endl; | 
| 1787 | }; | 
| 1788 | TList *contents  = new TList; // create output list | 
| 1789 | contents->SetOwner(); | 
| 1790 |  | 
| 1791 | //    char *fullpath; | 
| 1792 | //    const char *fullpath; | 
| 1793 |  | 
| 1794 | // if no input file list is given: | 
| 1795 | if ( flisttxt != "" ){ | 
| 1796 |  | 
| 1797 | //      if( !gSystem->IsFileInIncludePath(flisttxt,&fullpath) ){ | 
| 1798 | //      if( !(fullpath = gSystem->FindFile("./",flisttxt)) ){ | 
| 1799 | //          cout <<"File "<<flisttxt<<" not found"<<endl; | 
| 1800 | //          return 0; | 
| 1801 | //      } | 
| 1802 | //      flisttxt = fullpath; | 
| 1803 | if ( !flisttxt.EndsWith(".root") ){ | 
| 1804 |  | 
| 1805 | flisttxt = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); | 
| 1806 |  | 
| 1807 | if( !gSystem->ChangeDirectory(ddir) ){ | 
| 1808 | cout << "Cannot change directory : "<<ddir<<endl; | 
| 1809 | return 0; | 
| 1810 | } | 
| 1811 |  | 
| 1812 | cout <<"Input file list : " << flisttxt <<endl; | 
| 1813 | ifstream in; | 
| 1814 | in.open(flisttxt, ios::in); //open input file list | 
| 1815 | if(!in.good()){ | 
| 1816 | cout <<" ERROR opening the file "<<endl; | 
| 1817 | gSystem->ChangeDirectory(wdir); // back to the working directory | 
| 1818 | return 0; | 
| 1819 | } | 
| 1820 | int line=0; | 
| 1821 | while (1) { | 
| 1822 | TString file; | 
| 1823 | in >> file; | 
| 1824 | if (!in.good()) break; | 
| 1825 | line++; | 
| 1826 | //          cout <<"(1) " << file << endl; | 
| 1827 | if(file.IsNull()){ | 
| 1828 | cout << "-- list interrupted at line "<<line <<endl; | 
| 1829 | break; | 
| 1830 | } | 
| 1831 | if(file.Contains("#"))file = file(0,file.First("#")); | 
| 1832 | //          cout <<"(2) " << file << endl; | 
| 1833 | //          if( gSystem->IsFileInIncludePath(file,&fullpath) ){ | 
| 1834 | //          if( (fullpath = gSystem->FindFile(ddir,file)) ){ | 
| 1835 | if( file.EndsWith(".root") ){ | 
| 1836 | TString filedir; | 
| 1837 | if (ddir != ""){ | 
| 1838 | filedir = ddir; // take the input dir | 
| 1839 | } else { | 
| 1840 | gSystem->ChangeDirectory(wdir); // back to the working directory | 
| 1841 | filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir | 
| 1842 | }; | 
| 1843 | char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir),gSystem->BaseName(file)); | 
| 1844 | contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list | 
| 1845 | delete fullpath; | 
| 1846 | } | 
| 1847 | //          }else{ | 
| 1848 | //              if(file.Data()!="")cout << "File: "<<file<<" ---> missing "<< endl; | 
| 1849 | //          }; | 
| 1850 | }; | 
| 1851 | in.close(); | 
| 1852 | } else { | 
| 1853 | if(flisttxt.Contains("#"))flisttxt = flisttxt(0,flisttxt.First("#")); | 
| 1854 | char *fullpath = gSystem->ConcatFileName(gSystem->DirName(flisttxt),gSystem->BaseName(flisttxt)); | 
| 1855 | contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath)));// add file to the list | 
| 1856 | delete fullpath; | 
| 1857 | }; | 
| 1858 | }else{ | 
| 1859 |  | 
| 1860 | cout << "No input file list given."<<endl; | 
| 1861 | cout << "Check for existing root files."<<endl; | 
| 1862 | //              cout << "Warking directory: "<< gSystem->WorkingDirectory()<< endl; | 
| 1863 | if ( ddir == "" ){ | 
| 1864 | ddir = wdir; | 
| 1865 | cout << "Level2 data directory : "<<  ddir << endl; | 
| 1866 | }; | 
| 1867 |  | 
| 1868 | TSystemDirectory *datadir = new TSystemDirectory(gSystem->BaseName(ddir),ddir); | 
| 1869 | TList *temp = datadir->GetListOfFiles(); | 
| 1870 | //              temp->Print(); | 
| 1871 | //              cout << "*************************************" << endl; | 
| 1872 |  | 
| 1873 | TIter next(temp); | 
| 1874 | TSystemFile *questo = 0; | 
| 1875 |  | 
| 1876 |  | 
| 1877 | while ( (questo = (TSystemFile*) next()) ) { | 
| 1878 | TString name =  questo-> GetName(); | 
| 1879 | if( name.EndsWith(".root") ){ | 
| 1880 | //              const char *fullpath = gSystem->FindFile(ddir,name); | 
| 1881 | //              char *fullpath; | 
| 1882 | //              gSystem->IsFileInIncludePath(name,&fullpath); | 
| 1883 | char *fullpath = gSystem->ConcatFileName(gSystem->DirName(ddir),gSystem->BaseName(name)); | 
| 1884 | contents->Add(new TSystemFile(fullpath,gSystem->DirName(fullpath))); | 
| 1885 | delete fullpath; | 
| 1886 | }; | 
| 1887 | } | 
| 1888 | delete temp; | 
| 1889 | delete datadir; | 
| 1890 |  | 
| 1891 | }; | 
| 1892 | gSystem->ChangeDirectory(wdir); // back to the working directory | 
| 1893 | //      cout << endl << "Selected files:" << endl; | 
| 1894 | //      contents->Print(); | 
| 1895 | cout << contents->GetEntries()<<" files \n"; | 
| 1896 | //      cout << endl; | 
| 1897 | //      cout << "Working directory: "<< gSystem->WorkingDirectory()<< endl; | 
| 1898 | return contents; | 
| 1899 | }; | 
| 1900 | //-------------------------------------- | 
| 1901 | // | 
| 1902 | // | 
| 1903 | //-------------------------------------- | 
| 1904 | /** | 
| 1905 | * Get the Pamela detector chains from a list of files and make them friends. | 
| 1906 | * @param fl Pointer to a TList of TSystemFiles | 
| 1907 | * @param detlist String to select trees to be included | 
| 1908 | * @return Pointer to a TChain | 
| 1909 | */ | 
| 1910 | TChain *PamLevel2::GetPamTree(TList *fl, TString detlist ){ | 
| 1911 | // | 
| 1912 | // | 
| 1913 | // | 
| 1914 | if ( pam_tree ){ | 
| 1915 | printf("WARNING: TChain *PamLevel2::GetPamTree(TList *fl, TString detlist) -- pam_tree already exists!\n "); | 
| 1916 | return pam_tree; | 
| 1917 | }; | 
| 1918 | // | 
| 1919 |  | 
| 1920 | TChain *Trout =0; | 
| 1921 |  | 
| 1922 |  | 
| 1923 | if( detlist.Contains("+AUTO", TString::kIgnoreCase) ) { | 
| 1924 | if( fl->GetEntries()>0 ){ | 
| 1925 | cout << "+AUTO"<<endl; | 
| 1926 | TFile *fprimo = new TFile( fl->At(0)->GetName() ); | 
| 1927 | GetWhichTrees(fprimo); | 
| 1928 | fprimo->Delete(); | 
| 1929 | } | 
| 1930 | }; | 
| 1931 | SetWhichTrees(detlist); | 
| 1932 |  | 
| 1933 |  | 
| 1934 |  | 
| 1935 | //    if( !detlist.IsNull() )SetWhichTrees(detlist); | 
| 1936 | // | 
| 1937 | TChain *T = 0; | 
| 1938 | TChain *C = 0; | 
| 1939 | TChain *O = 0; | 
| 1940 | TChain *R = 0; | 
| 1941 | TChain *S = 0; | 
| 1942 | TChain *N = 0; | 
| 1943 | TChain *A = 0; | 
| 1944 | TChain *B = 0; | 
| 1945 | TChain *G = 0; | 
| 1946 |  | 
| 1947 | TChain *L = 0; | 
| 1948 |  | 
| 1949 | if(TRK2||TRK1||TRKh) T = new TChain("Tracker"); | 
| 1950 | if(CAL2||CAL1)       C = new TChain("Calorimeter"); | 
| 1951 | if(TOF)              O = new TChain("ToF"); | 
| 1952 | if(TRG)              R = new TChain("Trigger"); | 
| 1953 | if(S4)               S = new TChain("S4"); | 
| 1954 | if(ND)               N = new TChain("NeutronD"); | 
| 1955 | if(AC)               A = new TChain("Anticounter"); | 
| 1956 | if(ORB)              B = new TChain("OrbitalInfo"); | 
| 1957 | if(GP)               G = new TChain("h20"); | 
| 1958 | L = new TChain("SelectionList"); | 
| 1959 |  | 
| 1960 | // loop over files and create chains | 
| 1961 | TIter next(fl); | 
| 1962 | TSystemFile *questo = 0; | 
| 1963 | while ( (questo = (TSystemFile*) next()) ) { | 
| 1964 | TString name =  questo->GetName(); | 
| 1965 | cout << "File: "<< name << endl; | 
| 1966 | if( CheckLevel2File(name) ){ | 
| 1967 | if(TRK2||TRK1||TRKh) T->Add(name); | 
| 1968 | if(CAL1||CAL2)       C->Add(name); | 
| 1969 | if(TOF)              O->Add(name); | 
| 1970 | if(TRG)              R->Add(name); | 
| 1971 | if(S4)               S->Add(name); | 
| 1972 | if(ND)               N->Add(name); | 
| 1973 | if(AC)               A->Add(name); | 
| 1974 | if(ORB)              B->Add(name); | 
| 1975 | if(GP)               G->Add(name); | 
| 1976 | if(SELLI==1)         L->Add(name); | 
| 1977 | }; | 
| 1978 | }; | 
| 1979 |  | 
| 1980 | cout << "done chain \n"; | 
| 1981 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 1982 |  | 
| 1983 | //    UInt_t *found=0; | 
| 1984 | // Tracker | 
| 1985 | if(T && (TRK2||TRK1||TRKh)) { | 
| 1986 | //      if(TRK2)T->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); | 
| 1987 | //      if(TRK2)cout << "Tracker      : set branch address TrkLevel2"<<endl; | 
| 1988 | //      if(TRK1)T->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); | 
| 1989 | //      if(TRK1)cout << "Tracker      : set branch address TrkLevel1"<<endl; | 
| 1990 | //      if(TRKh)T->SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); | 
| 1991 | //      if(TRKh)cout << "Tracker      : set branch address TrkHough"<<endl; | 
| 1992 | if(!Trout)Trout=T; | 
| 1993 | else Trout->AddFriend("Tracker"); | 
| 1994 | }else{ | 
| 1995 | //        cout << "Tracker      : missing tree"<<endl; | 
| 1996 | }; | 
| 1997 | // Calorimeter | 
| 1998 | if(C && (CAL2||CAL1)) { | 
| 1999 | //        if(CAL2)C->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); | 
| 2000 | //        if(CAL2)cout << "Calorimeter  : set branch address CaloLevel2"<<endl; | 
| 2001 | //        if(CAL1)C->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); | 
| 2002 | //        if(CAL1)cout << "Calorimeter  : set branch address CaloLevel1"<<endl; | 
| 2003 | if(!Trout)Trout=C; | 
| 2004 | else Trout->AddFriend("Calorimeter"); | 
| 2005 | }else{ | 
| 2006 | //        cout << "Calorimeter  : missing tree"<<endl; | 
| 2007 | }; | 
| 2008 | // ToF | 
| 2009 | if(O && TOF) { | 
| 2010 | //        O->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); | 
| 2011 | //        cout << "ToF          : set branch address ToFLevel2"<<endl; | 
| 2012 | if(!Trout)Trout=O; | 
| 2013 | else Trout->AddFriend("ToF"); | 
| 2014 | }else{ | 
| 2015 | //        cout << "ToF         : missing tree"<<endl; | 
| 2016 | }; | 
| 2017 | // Trigger | 
| 2018 | if(R && TRG) { | 
| 2019 | //        R->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); | 
| 2020 | //        cout << "Trigger      : set branch address TrigLevel2"<<endl; | 
| 2021 | if(!Trout)Trout=O; | 
| 2022 | else Trout->AddFriend("Trigger"); | 
| 2023 | }else{ | 
| 2024 | //        cout << "Trigger      : missing tree"<<endl; | 
| 2025 | }; | 
| 2026 | // S4 | 
| 2027 | if(S && S4) { | 
| 2028 | //        S->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); | 
| 2029 | //        cout << "S4           : set branch address S4Level2"<<endl; | 
| 2030 | if(!Trout)Trout=O; | 
| 2031 | else Trout->AddFriend("S4"); | 
| 2032 | }else{ | 
| 2033 | //        cout << "S4           : missing tree"<<endl; | 
| 2034 | }; | 
| 2035 | // Neutron Detector | 
| 2036 | if(N && ND) { | 
| 2037 | //        N->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); | 
| 2038 | //        cout << "NeutronD     : set branch address NDLevel2"<<endl; | 
| 2039 | if(!Trout)Trout=O; | 
| 2040 | else Trout->AddFriend("NeutronD"); | 
| 2041 | }else{ | 
| 2042 | //        cout << "NeutronD     : missing tree"<<endl; | 
| 2043 | }; | 
| 2044 | // Anticounters | 
| 2045 | if(A && AC) { | 
| 2046 | //        A->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); | 
| 2047 | //        cout << "Anticounter  : set branch address AcLevel2"<<endl; | 
| 2048 | if(!Trout)Trout=O; | 
| 2049 | else Trout->AddFriend("Anticounter"); | 
| 2050 | }else{ | 
| 2051 | //        cout << "Anticounter  : missing tree"<<endl; | 
| 2052 | }; | 
| 2053 | // Orbital Info | 
| 2054 | if(B && ORB) { | 
| 2055 | //      B->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); | 
| 2056 | //      cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl; | 
| 2057 | if(!Trout)Trout=O; | 
| 2058 | else Trout->AddFriend("OrbitalInfo"); | 
| 2059 | }else{ | 
| 2060 | //      cout << "OrbitalInfo  : missing tree"<<endl; | 
| 2061 | }; | 
| 2062 | // GPamela | 
| 2063 | if(G && GP) { | 
| 2064 | if(!gp_obj)gp_obj = new GPamela(); | 
| 2065 | //      ------------------------------------ | 
| 2066 | //      ATTENZIONE!!! | 
| 2067 | //      non so per quale arcano motivo, | 
| 2068 | //      per l'albero di gpamela il branch address lo devo settare | 
| 2069 | //      DOPO aver fatto friend | 
| 2070 | //      FGRRRVZZZZUTSALKJMSLKJ!!! | 
| 2071 | //      ------------------------------------ | 
| 2072 | //      gp_obj->SetBranchAddress(G); //ho dovuto fare in maniera diversa dagli altri | 
| 2073 | //      cout << "h20          : set branch address GPamela "<<endl; | 
| 2074 | if(!Trout)Trout=G; | 
| 2075 | else Trout->AddFriend("h20"); | 
| 2076 | }else{ | 
| 2077 | //      cout << "h20          : missing tree"<<endl; | 
| 2078 | }; | 
| 2079 |  | 
| 2080 | //  ===================================== | 
| 2081 | //  SET BRANCH-ADDRESS AFTER CHAIN+FRIEND | 
| 2082 | //  ===================================== | 
| 2083 | SetBranchAddress(Trout); | 
| 2084 |  | 
| 2085 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 2086 |  | 
| 2087 | // Selection List | 
| 2088 | if(L && SELLI==1) { | 
| 2089 | cout<<">>> Found selection-list <<<"<<endl; | 
| 2090 | //      L->SetBranchAddress("RunEntry",&irun); | 
| 2091 | L->SetBranchAddress("RunEntry",&irun); | 
| 2092 | cout << "SelectionList: set branch address RunEntry"<<endl; | 
| 2093 | L->SetBranchAddress("EventEntry",&irunentry); | 
| 2094 | cout << "SelectionList: set branch address EventEntry"<<endl; | 
| 2095 | sel_tree = L; | 
| 2096 | //      if(!Trout)Trout=O; | 
| 2097 | //      else Trout->AddFriend("SelectionList"); | 
| 2098 | cout << "----------------------------------------------------" <<endl; | 
| 2099 | }else{ | 
| 2100 | //      cout << "SelectionList  : missing tree"<<endl; | 
| 2101 | if(L)L->Delete(); | 
| 2102 | }; | 
| 2103 |  | 
| 2104 | //    cout<<endl<<" Number of entries: "<<Trout->GetEntries()<<endl<<endl; | 
| 2105 |  | 
| 2106 | //      ------------------------------------ | 
| 2107 | //      ATTENZIONE!!! | 
| 2108 | //      non so per quale arcano motivo, | 
| 2109 | //      per l'albero di gpamela il branch address lo devo settare | 
| 2110 | //      DOPO aver fatto friend | 
| 2111 | //      FGRRRVZZZZUTSALKJMSLKJ!!! | 
| 2112 | //      ------------------------------------ | 
| 2113 | //     cout << G << " --- "<<GP <<endl; | 
| 2114 | //     if(G && GP) { | 
| 2115 | //      gp_obj->SetBranchAddress(Trout); //ho dovuto fare in maniera diversa dagli altri | 
| 2116 | //      cout << "h20          : set branch address GPamela "<<endl; | 
| 2117 | //     }else{ | 
| 2118 | //      cout << "h20          : missing tree"<<endl; | 
| 2119 | //     }; | 
| 2120 |  | 
| 2121 |  | 
| 2122 | pam_tree = Trout; | 
| 2123 |  | 
| 2124 | return Trout; | 
| 2125 | } | 
| 2126 |  | 
| 2127 |  | 
| 2128 |  | 
| 2129 | //-------------------------------------- | 
| 2130 | // | 
| 2131 | // | 
| 2132 | //-------------------------------------- | 
| 2133 | /** | 
| 2134 | * Set branch addresses for Pamela friend trees | 
| 2135 | */ | 
| 2136 | void PamLevel2::SetBranchAddress(TTree *t){ | 
| 2137 |  | 
| 2138 | TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2"); | 
| 2139 | TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1"); | 
| 2140 | TRKh    = TRKh & t->GetBranchStatus("TrkHough"); | 
| 2141 | CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2"); | 
| 2142 | CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1"); | 
| 2143 | TOF    = TOF & t->GetBranchStatus("ToFLevel2"); | 
| 2144 | TRG    = TRG & t->GetBranchStatus("TrigLevel2"); | 
| 2145 | S4     = S4  & t->GetBranchStatus("S4Level2"); | 
| 2146 | ND     = ND  & t->GetBranchStatus("NDLevel2"); | 
| 2147 | AC     = AC  & t->GetBranchStatus("AcLevel2"); | 
| 2148 | ORB    = ORB & t->GetBranchStatus("OrbitalInfo"); | 
| 2149 | GP     = GP  & t->GetBranchStatus("h20"); | 
| 2150 |  | 
| 2151 |  | 
| 2152 | // Tracker | 
| 2153 | if(TRK1) { | 
| 2154 | t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel2")); | 
| 2155 | cout << "Tracker      : set branch address TrkLevel1"<<endl; | 
| 2156 | }; | 
| 2157 | if(TRK2) { | 
| 2158 | t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel1")); | 
| 2159 | cout << "Tracker      : set branch address TrkLevel2"<<endl; | 
| 2160 | }; | 
| 2161 | if(TRKh) { | 
| 2162 | t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); | 
| 2163 | cout << "Tracker      : set branch address TrkHough"<<endl; | 
| 2164 | }; | 
| 2165 |  | 
| 2166 | // Calorimeter | 
| 2167 | if(CAL1) { | 
| 2168 | t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); | 
| 2169 | cout << "Calorimeter  : set branch address CaloLevel1"<<endl; | 
| 2170 | }; | 
| 2171 | if(CAL2) { | 
| 2172 | t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); | 
| 2173 | cout << "Calorimeter  : set branch address CaloLevel2"<<endl; | 
| 2174 | }; | 
| 2175 |  | 
| 2176 | // ToF | 
| 2177 | if(TOF) { | 
| 2178 | t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); | 
| 2179 | cout << "ToF          : set branch address ToFLevel2"<<endl; | 
| 2180 | }; | 
| 2181 | // Trigger | 
| 2182 | if(TRG) { | 
| 2183 | t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); | 
| 2184 | cout << "Trigger      : set branch address TrigLevel2"<<endl; | 
| 2185 | }; | 
| 2186 | // S4 | 
| 2187 | if(S4) { | 
| 2188 | t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); | 
| 2189 | cout << "S4           : set branch address S4Level2"<<endl; | 
| 2190 | }; | 
| 2191 | // Neutron Detector | 
| 2192 | if(ND) { | 
| 2193 | t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); | 
| 2194 | cout << "NeutronD     : set branch address NDLevel2"<<endl; | 
| 2195 | }; | 
| 2196 | // Anticounters | 
| 2197 | if(AC) { | 
| 2198 | t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); | 
| 2199 | cout << "Anticounter  : set branch address AcLevel2"<<endl; | 
| 2200 | }; | 
| 2201 | // OrbitalInfo | 
| 2202 | if(ORB) { | 
| 2203 | t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); | 
| 2204 | cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl; | 
| 2205 | }; | 
| 2206 | // GPamela | 
| 2207 | if(GP) { | 
| 2208 | //      GetPointerTo("GPamela"); | 
| 2209 | if(!gp_obj)gp_obj = new GPamela(); | 
| 2210 | gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri | 
| 2211 | cout << "h20          : set branch address GPamela "<<endl; | 
| 2212 | }; | 
| 2213 | // SelectionList | 
| 2214 | if(SELLI==1) { | 
| 2215 | //      t->SetBranchAddress("RunEntry", &irun); | 
| 2216 | t->SetBranchAddress("RunEntry", &irun); | 
| 2217 | cout << "SelectionList: set branch address RunEntry"<<endl; | 
| 2218 | t->SetBranchAddress("EventEntry", &irunentry); | 
| 2219 | cout << "SelectionList: set branch address EventEntry"<<endl; | 
| 2220 | }; | 
| 2221 |  | 
| 2222 | } | 
| 2223 | /** | 
| 2224 | * Set branch addresses for Pamela friend trees | 
| 2225 | */ | 
| 2226 | void PamLevel2::SetBranchAddress(TChain *t){ | 
| 2227 |  | 
| 2228 | //     TRK2    = TRK2 & t->GetBranchStatus("TrkLevel2"); | 
| 2229 | //     TRK1    = TRK1 & t->GetBranchStatus("TrkLevel1"); | 
| 2230 | //     TRKh    = TRKh & t->GetBranchStatus("TrkHough"); | 
| 2231 | //     CAL1    = CAL1 & t->GetBranchStatus("CaloLevel1"); | 
| 2232 | //     CAL2    = CAL2 & t->GetBranchStatus("CaloLevel2"); | 
| 2233 | //     TOF    = TOF & t->GetBranchStatus("ToFLevel2"); | 
| 2234 | //     TRG    = TRG & t->GetBranchStatus("TrigLevel2"); | 
| 2235 | //     S4     = S4  & t->GetBranchStatus("S4Level2"); | 
| 2236 | //     ND     = ND  & t->GetBranchStatus("NDLevel2"); | 
| 2237 | //     AC     = AC  & t->GetBranchStatus("AcLevel2"); | 
| 2238 | //     ORB    = ORB & t->GetBranchStatus("OrbitalInfo"); | 
| 2239 | //    GP     = GP & t->GetBranchStatus("h20"); | 
| 2240 |  | 
| 2241 | // Tracker | 
| 2242 | if(TRK2) { | 
| 2243 | t->SetBranchAddress("TrkLevel2", GetPointerTo("TrkLevel2")); | 
| 2244 | cout << "Tracker      : set branch address TrkLevel2"<<endl; | 
| 2245 | }; | 
| 2246 | if(TRK1) { | 
| 2247 | t->SetBranchAddress("TrkLevel1", GetPointerTo("TrkLevel1")); | 
| 2248 | cout << "Tracker      : set branch address TrkLevel1"<<endl; | 
| 2249 | }; | 
| 2250 | if(TRKh) { | 
| 2251 | t->SetBranchAddress("TrkHough", GetPointerTo("TrkHough")); | 
| 2252 | cout << "Tracker      : set branch address TrkHough"<<endl; | 
| 2253 | }; | 
| 2254 |  | 
| 2255 | // Calorimeter | 
| 2256 | if(CAL2) { | 
| 2257 | t->SetBranchAddress("CaloLevel2", GetPointerTo("CaloLevel2")); | 
| 2258 | cout << "Calorimeter  : set branch address CaloLevel2"<<endl; | 
| 2259 | }; | 
| 2260 | if(CAL1) { | 
| 2261 | t->SetBranchAddress("CaloLevel1", GetPointerTo("CaloLevel1")); | 
| 2262 | cout << "Calorimeter  : set branch address CaloLevel1"<<endl; | 
| 2263 | }; | 
| 2264 |  | 
| 2265 | // ToF | 
| 2266 | if(TOF) { | 
| 2267 | t->SetBranchAddress("ToFLevel2", GetPointerTo("ToFLevel2")); | 
| 2268 | cout << "ToF          : set branch address ToFLevel2"<<endl; | 
| 2269 | }; | 
| 2270 | // Trigger | 
| 2271 | if(TRG) { | 
| 2272 | t->SetBranchAddress("TrigLevel2", GetPointerTo("TrigLevel2")); | 
| 2273 | cout << "Trigger      : set branch address TrigLevel2"<<endl; | 
| 2274 | }; | 
| 2275 | // S4 | 
| 2276 | if(S4) { | 
| 2277 | t->SetBranchAddress("S4Level2", GetPointerTo("S4Level2")); | 
| 2278 | cout << "S4           : set branch address S4Level2"<<endl; | 
| 2279 | }; | 
| 2280 | // Neutron Detector | 
| 2281 | if(ND) { | 
| 2282 | t->SetBranchAddress("NDLevel2", GetPointerTo("NDLevel2")); | 
| 2283 | cout << "NeutronD     : set branch address NDLevel2"<<endl; | 
| 2284 | }; | 
| 2285 | // Anticounters | 
| 2286 | if(AC) { | 
| 2287 | t->SetBranchAddress("AcLevel2", GetPointerTo("AcLevel2")); | 
| 2288 | cout << "Anticounter  : set branch address AcLevel2"<<endl; | 
| 2289 | }; | 
| 2290 | // OrbitalInfo | 
| 2291 | if(ORB) { | 
| 2292 | t->SetBranchAddress("OrbitalInfo", GetPointerTo("OrbitalInfo")); | 
| 2293 | cout << "OrbitalInfo  : set branch address OrbitalInfo"<<endl; | 
| 2294 | }; | 
| 2295 | // GPamela | 
| 2296 | //    cout <<"GP "<<GP<<endl; | 
| 2297 | if(GP) { | 
| 2298 | //      GetPointerTo("GPamela"); | 
| 2299 | if(!gp_obj)gp_obj = new GPamela(); | 
| 2300 | gp_obj->SetBranchAddress(t); //ho dovuto fare in maniera diversa dagli altri | 
| 2301 | cout << "h20          : set branch address GPamela "<<endl; | 
| 2302 | }; | 
| 2303 | // SelectionList | 
| 2304 | if(SELLI==1) { | 
| 2305 | //      t->SetBranchAddress("RunEntry", &irun); | 
| 2306 | t->SetBranchAddress("RunEntry", &irun); | 
| 2307 | cout << "SelectionList: set branch address RunEntry"<<endl; | 
| 2308 | t->SetBranchAddress("EventEntry", &irunentry); | 
| 2309 | cout << "SelectionList: set branch address EventEntry"<<endl; | 
| 2310 | }; | 
| 2311 |  | 
| 2312 | } | 
| 2313 |  | 
| 2314 |  | 
| 2315 | //-------------------------------------- | 
| 2316 | // | 
| 2317 | // | 
| 2318 | //-------------------------------------- | 
| 2319 | /** | 
| 2320 | * Get the Run tree chain from a list of files. | 
| 2321 | * @param fl Pointer to a TList of TSystemFiles | 
| 2322 | * @return Pointer to a TChain | 
| 2323 | */ | 
| 2324 | TChain *PamLevel2::GetRunTree(TList *fl){ | 
| 2325 | // | 
| 2326 | // | 
| 2327 | // | 
| 2328 | if ( run_tree ){ | 
| 2329 | printf("WARNING: TChain *PamLevel2::GetRunTree(TList *fl) -- run_tree already exists!\n "); | 
| 2330 | return run_tree; | 
| 2331 | }; | 
| 2332 | // | 
| 2333 | TChain *R = new TChain("Run"); | 
| 2334 |  | 
| 2335 | // loop over files and create chains | 
| 2336 | TIter next(fl); | 
| 2337 | TSystemFile *questo = 0; | 
| 2338 | while ( (questo = (TSystemFile*) next()) ) { | 
| 2339 | TString name =  questo->GetName(); | 
| 2340 | //              cout << "File: "<< name << endl; | 
| 2341 | if( CheckLevel2File(name) ){ | 
| 2342 | R->Add(name); | 
| 2343 | }; | 
| 2344 | } | 
| 2345 |  | 
| 2346 | if(R->GetNtrees()){ | 
| 2347 |  | 
| 2348 | R->SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); | 
| 2349 | cout << "Run         : set branch address RunInfo"<<endl; | 
| 2350 | R->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano | 
| 2351 | cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano | 
| 2352 | }else{ | 
| 2353 | delete R; | 
| 2354 | R=0; | 
| 2355 | } | 
| 2356 |  | 
| 2357 | run_tree = R; | 
| 2358 |  | 
| 2359 | return R; | 
| 2360 |  | 
| 2361 | } | 
| 2362 | //-------------------------------------- | 
| 2363 | // | 
| 2364 | // | 
| 2365 | //-------------------------------------- | 
| 2366 | /** | 
| 2367 | * Get the Run tree  from a file. | 
| 2368 | * @param f Pointer to a TFile | 
| 2369 | * @return Pointer to a TTree | 
| 2370 | */ | 
| 2371 | TTree *PamLevel2::GetRunTree(TFile *f){ | 
| 2372 | if ( run_tree ){ | 
| 2373 | printf("WARNING: TTree *PamLevel2::GetRunTree(TFile *f) -- run_tree already exists!\n "); | 
| 2374 | return run_tree; | 
| 2375 | }; | 
| 2376 |  | 
| 2377 |  | 
| 2378 | cout << "TTree *PamLevel2::GetRunTree(TFile *f) -- obsolte "<<endl; | 
| 2379 |  | 
| 2380 | TTree *T = (TTree*)f->Get("Run"); | 
| 2381 |  | 
| 2382 | if(T){ | 
| 2383 | T->SetBranchAddress("RunInfo", GetPointerTo("RunInfo")); | 
| 2384 | cout << "Run         : set branch address RunInfo"<<endl; | 
| 2385 | T->SetBranchAddress("SoftInfo", GetPointerTo("SoftInfo")); // Emiliano | 
| 2386 | cout << "Software    : set branch address SoftInfo"<<endl; // Emiliano | 
| 2387 | } | 
| 2388 |  | 
| 2389 | run_tree = (TChain*)T; | 
| 2390 |  | 
| 2391 | return T; | 
| 2392 |  | 
| 2393 | } | 
| 2394 | /** | 
| 2395 | * Update the runinfo informations (to be used to have Run infos event by event basis) | 
| 2396 | * @param run Pointer to the chain/tree which contains run infos | 
| 2397 | * @return true if a new run has been read, false if it is still the same run | 
| 2398 | */ | 
| 2399 | Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev){ | 
| 2400 | // | 
| 2401 | // check if we have already called once GetEntry, if not call it | 
| 2402 | // | 
| 2403 | cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... "<<endl; | 
| 2404 | if(!run){ | 
| 2405 | cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree "<<endl; | 
| 2406 | return(false); | 
| 2407 | } | 
| 2408 | if ( run->GetEntries() <= 0 ) return(false); | 
| 2409 | // | 
| 2410 |  | 
| 2411 | //  Int_t oldrun = irun; | 
| 2412 | Long64_t oldrun = irun; | 
| 2413 |  | 
| 2414 | // -------------------------------------- | 
| 2415 | // if it is a full file (not preselected) | 
| 2416 | // -------------------------------------- | 
| 2417 | if(SELLI==0){ | 
| 2418 |  | 
| 2419 | // | 
| 2420 | // the absolute time is necessary to relate the event with the run | 
| 2421 | // | 
| 2422 | if( !GetOrbitalInfo() && !ISGP){ | 
| 2423 | cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
| 2424 | return(false); | 
| 2425 | } | 
| 2426 |  | 
| 2427 | ULong64_t abstime = 0; | 
| 2428 | if( GetOrbitalInfo() )abstime=GetOrbitalInfo()->absTime; | 
| 2429 |  | 
| 2430 |  | 
| 2431 | // | 
| 2432 | // the first time the routine is called, set run search from the beginning | 
| 2433 | // | 
| 2434 | if ( irun < 0LL ){ | 
| 2435 | irun = 0LL; | 
| 2436 | run->GetEntry(irun); | 
| 2437 | runfirstentry = 0LL; | 
| 2438 | runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); | 
| 2439 | if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; | 
| 2440 |  | 
| 2441 | if( ISGP && run->GetEntries()!=1 ){ | 
| 2442 | cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run->GetEntries() << endl; | 
| 2443 | cout << "** WARNING ** run will not be updated"<<endl; | 
| 2444 | } | 
| 2445 |  | 
| 2446 | }; | 
| 2447 | // | 
| 2448 | if(ISGP)abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO | 
| 2449 | // | 
| 2450 | if ( irun == run->GetEntries()-1LL && | 
| 2451 | !(abstime >= GetRunInfo()->RUNHEADER_TIME && | 
| 2452 | abstime <= GetRunInfo()->RUNTRAILER_TIME) | 
| 2453 | ){ | 
| 2454 | irun = -1LL; | 
| 2455 | runfirstentry = 0LL; | 
| 2456 | runlastentry = -1LL; | 
| 2457 | }; | 
| 2458 | // modificato il controllo sull'aggiornamento del run, per evitare problemi | 
| 2459 | // dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!) | 
| 2460 | // | 
| 2461 | bool fromfirst = true; | 
| 2462 | // | 
| 2463 | while ( !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries()-1LL ){ | 
| 2464 | //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ | 
| 2465 | irun++; | 
| 2466 | run->GetEntry(irun); | 
| 2467 | runfirstentry = runlastentry; | 
| 2468 | if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runfirstentry += 1LL; | 
| 2469 | runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); | 
| 2470 | //        cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 2471 | //        cout << "runfirstentry "<<runfirstentry<<endl; | 
| 2472 | //    printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); | 
| 2473 | //    printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME); | 
| 2474 | //    printf(" IDRUN %u \n",GetRunInfo()->ID); | 
| 2475 | // | 
| 2476 | //        prevshift = 0; | 
| 2477 | // | 
| 2478 | if ( irun == (Long64_t)(run->GetEntries()-1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)){ | 
| 2479 | printf(" resetting irun  (it should NOT happen!!!)\n"); | 
| 2480 | fromfirst = false; | 
| 2481 | irun = 0; | 
| 2482 | run->GetEntry(irun); | 
| 2483 | runfirstentry = 0ULL; | 
| 2484 | runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); | 
| 2485 | if ( (Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL ) runlastentry -= 1LL; | 
| 2486 | }; | 
| 2487 | // | 
| 2488 | }; | 
| 2489 | // | 
| 2490 | if ( | 
| 2491 | !(abstime >= GetRunInfo()->RUNHEADER_TIME && | 
| 2492 | abstime <= GetRunInfo()->RUNTRAILER_TIME) | 
| 2493 | ) { | 
| 2494 | printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n",abstime); | 
| 2495 | return false; | 
| 2496 | } | 
| 2497 | // | 
| 2498 | if ( irun == oldrun || irun >= run->GetEntries() ) return(false); | 
| 2499 | // | 
| 2500 | //  printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry); | 
| 2501 | // | 
| 2502 | prevshift = 0; | 
| 2503 | cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 2504 | //      cout << "runfirstentry "<<runfirstentry<<endl; | 
| 2505 | return(true); | 
| 2506 | }; | 
| 2507 | // ---------------------------------------------------- | 
| 2508 | // if it is a preselected file (there is SelectionList) | 
| 2509 | // NBNB - the event tree MUST be read first | 
| 2510 | // ---------------------------------------------------- | 
| 2511 | if(SELLI==1){ | 
| 2512 | sel_tree->GetEntry(iev); | 
| 2513 | //      cout << irun << " "<< irunentry << endl; | 
| 2514 | if(irun != oldrun){ | 
| 2515 | run->GetEntry(irun); | 
| 2516 | cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 2517 | prevshift = 0; | 
| 2518 | return true; | 
| 2519 | } | 
| 2520 | return false; | 
| 2521 | } | 
| 2522 |  | 
| 2523 | return false; | 
| 2524 | // | 
| 2525 | }; | 
| 2526 |  | 
| 2527 | Bool_t PamLevel2::UpdateRunInfo(Long64_t iev){ | 
| 2528 |  | 
| 2529 | if(!run_tree){ | 
| 2530 | cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded"<<endl; | 
| 2531 | return false; | 
| 2532 | } | 
| 2533 | if ( run_tree->GetEntries() <= 0 ) { | 
| 2534 | cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty"<<endl; | 
| 2535 | return(false); | 
| 2536 | } | 
| 2537 |  | 
| 2538 | Int_t oldrun = irun; // store current run index | 
| 2539 |  | 
| 2540 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
| 2541 | // if it is a full file (not preselected) | 
| 2542 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
| 2543 | if(SELLI==0){ | 
| 2544 |  | 
| 2545 | // --------------------------------------------------------------- | 
| 2546 | // increment dead and live-time counters | 
| 2547 | // --------------------------------------------------------------- | 
| 2548 | if( GetTrigLevel2() ){ | 
| 2549 | totdltime[0]+=GetTrigLevel2()->dltime[0]; | 
| 2550 | totdltime[1]+=GetTrigLevel2()->dltime[1]; | 
| 2551 | } | 
| 2552 | totdltime[2]++; | 
| 2553 |  | 
| 2554 | //      cout << setw(10)<<totdltime[0]<<setw(10)<<totdltime[1]<<setw(10)<<totdltime[2]<<endl; | 
| 2555 |  | 
| 2556 | // --------------------------------------------------------------- | 
| 2557 | // retrieve OBT and absolute time of the event | 
| 2558 | // --------------------------------------------------------------- | 
| 2559 | ULong64_t abstime = 0; | 
| 2560 | ULong64_t obt     = 0; | 
| 2561 | if( GetOrbitalInfo() ){ | 
| 2562 | abstime = GetOrbitalInfo()->absTime; | 
| 2563 | obt     = GetOrbitalInfo()->OBT; | 
| 2564 | } | 
| 2565 | // --------------------------------------------------------------- | 
| 2566 | // the absolute time is necessary to relate the event with the run | 
| 2567 | // --------------------------------------------------------------- | 
| 2568 | if( !GetOrbitalInfo() && !ISGP ){ | 
| 2569 | cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- missing OrbitalInfo "<<endl; | 
| 2570 | return(false); | 
| 2571 | } | 
| 2572 |  | 
| 2573 | // ----------------------------------------------------------------------- | 
| 2574 | // the first time the routine is called, set run search from the beginning | 
| 2575 | // ----------------------------------------------------------------------- | 
| 2576 | if ( irun < 0 ){ | 
| 2577 | irun = 0LL; | 
| 2578 | irunentry = 0; | 
| 2579 | prevshift = 0; | 
| 2580 | run_tree->GetEntry(irun); | 
| 2581 |  | 
| 2582 | if( ISGP && run_tree->GetEntries()!=1 ){ | 
| 2583 | cout << "** WARNING ** simulated files are assumed to have 1 single run, not "<< run_tree->GetEntries() << endl; | 
| 2584 | cout << "** WARNING ** run will not be updated"<<endl; | 
| 2585 | } | 
| 2586 | }; | 
| 2587 |  | 
| 2588 | // ----------------------------------------------------------------------- | 
| 2589 | // if it is simulation, assign abstime by hand (temporaneo!!!) | 
| 2590 | // ----------------------------------------------------------------------- | 
| 2591 | if(ISGP){ | 
| 2592 | abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO | 
| 2593 | obt     = GetRunInfo()->RUNHEADER_OBT; // BARBATRUCCO | 
| 2594 | } | 
| 2595 | // | 
| 2596 | bool fromfirst = true; // first loop over runs | 
| 2597 |  | 
| 2598 | //      Bool_t hasfrag = false; | 
| 2599 | //      if( GetRunInfo()->ID_RUN_FRAG!=0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID)hasfrag=true; | 
| 2600 | //      ULong64_t fragid = GetRunInfo()->ID_RUN_FRAG; | 
| 2601 |  | 
| 2602 | // ------------------------------------------------------ | 
| 2603 | // loop over runs to find the one that contains the event | 
| 2604 | // ------------------------------------------------------ | 
| 2605 | while ( | 
| 2606 | ( | 
| 2607 | ( | 
| 2608 | !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s) | 
| 2609 | abstime <= GetRunInfo()->RUNTRAILER_TIME) && | 
| 2610 | !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms) | 
| 2611 | obt <= GetRunInfo()->RUNTRAILER_OBT) | 
| 2612 | ) | 
| 2613 | || GetRunInfo()->NEVENTS==0 | 
| 2614 | //              || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento | 
| 2615 | || !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) | 
| 2616 | ) | 
| 2617 | && irun < run_tree->GetEntries() ){ | 
| 2618 |  | 
| 2619 | // - - - - - - - - - - - - - | 
| 2620 | // irunentry = position of current entry, relative to the run | 
| 2621 | // prevshift = shift needed to synchronize l0 and l2 data (nested events) | 
| 2622 | // - - - - - - - - - - - - - | 
| 2623 |  | 
| 2624 | // ----------------------------------------- | 
| 2625 | // store dead and live-time of previous run | 
| 2626 | // ----------------------------------------- | 
| 2627 | if(fromfirst){ | 
| 2628 | if(oldrun==irun){ | 
| 2629 | /// decrement counters | 
| 2630 | if( GetTrigLevel2()){ | 
| 2631 | totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time | 
| 2632 | totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time | 
| 2633 | } | 
| 2634 | totdltime[2]--;                              //event counter | 
| 2635 | cout << endl; | 
| 2636 | cout << "n.events     : "<<totdltime[2]<<endl; | 
| 2637 | cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl; | 
| 2638 | cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl; | 
| 2639 | }else{ | 
| 2640 | totdltime[0]=0;//live-time | 
| 2641 | totdltime[1]=0;//dead-time | 
| 2642 | totdltime[2]=0;                             //event counter | 
| 2643 | cout << " *** JUMP RUN *** irun "<<irun<<endl; | 
| 2644 | } | 
| 2645 | /// add an entry | 
| 2646 | if(run_tree_clone) | 
| 2647 | if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) | 
| 2648 | run_tree_clone->GetBranch("DeadLiveTime")->Fill(); | 
| 2649 | /// reset counters | 
| 2650 | if( GetTrigLevel2() ){ | 
| 2651 | totdltime[0]=GetTrigLevel2()->dltime[0];//live-time | 
| 2652 | totdltime[1]=0;                         //dead-time | 
| 2653 | } | 
| 2654 | totdltime[2]=1;                             //event counter | 
| 2655 | } | 
| 2656 |  | 
| 2657 |  | 
| 2658 | irun++; | 
| 2659 | // ------------------------------------ | 
| 2660 | // if the end of run tree is reached... | 
| 2661 | // ------------------------------------ | 
| 2662 | if( irun == run_tree->GetEntries() ){ | 
| 2663 | if(!fromfirst){ | 
| 2664 | // ----------------------------------------------------- | 
| 2665 | // if it happened already once and the run was not found | 
| 2666 | // ---> exit with error | 
| 2667 | // ----------------------------------------------------- | 
| 2668 | cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #"<<iev<<" does not belong to any run (should not happen)" <<endl; | 
| 2669 | return false; | 
| 2670 | } | 
| 2671 | // ----------------------------------------- | 
| 2672 | // ...otherwise repeat search from beginning | 
| 2673 | // ----------------------------------------- | 
| 2674 | cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " <<endl; | 
| 2675 | fromfirst = false; | 
| 2676 | irun = 0LL; | 
| 2677 | runfirstentry = 0LL; | 
| 2678 | } | 
| 2679 | // ------------------------------------------------------------------- | 
| 2680 | // save the index of the first entry of the run, relative to pam_tree, | 
| 2681 | // and read a new run | 
| 2682 | // ------------------------------------------------------------------- | 
| 2683 | if(irun>0)runfirstentry += (GetRunInfo()->NEVENTS)-prevshift; | 
| 2684 | irunentry = 0; | 
| 2685 | prevshift = 0; | 
| 2686 | run_tree->GetEntry(irun); | 
| 2687 | if(GetRunInfo()->RUNHEADER_OBT>GetRunInfo()->RUNTRAILER_OBT ){ | 
| 2688 | cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun "<<irun<<"  has RUNHEADER_OBT>=RUNTRAILER_OBT " <<endl; | 
| 2689 | cout << "                                                            (NB!! in this case some events are assigned to a wrong run)"<<endl; | 
| 2690 | } | 
| 2691 | //          if(hasfrag &&  fragid != GetRunInfo()->ID){ | 
| 2692 | //              cout << "... where is the next fragment ??"<<endl; | 
| 2693 | //          } | 
| 2694 | }; | 
| 2695 |  | 
| 2696 |  | 
| 2697 | // -------------------------------------- | 
| 2698 | // if there was no need to update the run | 
| 2699 | // ---> exit with FALSE | 
| 2700 | // -------------------------------------- | 
| 2701 | if ( irun == oldrun ) return(false); | 
| 2702 |  | 
| 2703 | // -------------------------------------- | 
| 2704 | // ... otherwise | 
| 2705 | // -------------------------------------- | 
| 2706 |  | 
| 2707 |  | 
| 2708 |  | 
| 2709 | //      // ----------------------------------------- | 
| 2710 | //      // store dead and live-time of previous run | 
| 2711 | //      // ----------------------------------------- | 
| 2712 | //      // -------------------------------------------------------------- | 
| 2713 | //      // if the run is empty, fill the dead-live time branch with zeros | 
| 2714 | //      // -------------------------------------------------------------- | 
| 2715 | //      /// if some runs have been jumped, fill with zeros | 
| 2716 | //      if(irun-oldrun>1){ | 
| 2717 | //          ULong64_t  temp[3]; | 
| 2718 | //          temp[0]=totdltime[0]; | 
| 2719 | //          temp[1]=totdltime[1]; | 
| 2720 | //          temp[2]=totdltime[2]; | 
| 2721 | //          for(int i=oldrun+1; i<irun; irun++){ | 
| 2722 | //              totdltime[0]=0; | 
| 2723 | //              totdltime[1]=0; | 
| 2724 | //              totdltime[2]=0; | 
| 2725 | //              cout << " ** JUMPED RUN **"<<endl; | 
| 2726 | //              if(run_tree_clone) | 
| 2727 | //                  if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) | 
| 2728 | //                      run_tree_clone->GetBranch("DeadLiveTime")->Fill(); | 
| 2729 | //          } | 
| 2730 | //          totdltime[0]=temp[0]; | 
| 2731 | //          totdltime[1]=temp[1]; | 
| 2732 | //          totdltime[2]=temp[2]; | 
| 2733 | //      } | 
| 2734 | //      /// decrement counters | 
| 2735 | //      if( GetTrigLevel2() ){ | 
| 2736 | //          totdltime[0]-=GetTrigLevel2()->dltime[0];//live-time | 
| 2737 | //          totdltime[1]-=GetTrigLevel2()->dltime[1];//dead-time | 
| 2738 | //      } | 
| 2739 | //      totdltime[2]--;                              //event counter | 
| 2740 | //      /// add an entry | 
| 2741 | //      if(irun>0 ){ | 
| 2742 | //          cout << endl; | 
| 2743 | //          cout << "n.events     : "<<totdltime[2]<<endl; | 
| 2744 | //          cout << "RUN LIVE-TIME: "<<totdltime[0]*0.16<<" ms"<<endl; | 
| 2745 | //          cout << "RUN DEAD-TIME: "<<totdltime[1]*0.01<<" ms"<<endl; | 
| 2746 | //          if(run_tree_clone) | 
| 2747 | //              if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) | 
| 2748 | //                  run_tree_clone->GetBranch("DeadLiveTime")->Fill(); | 
| 2749 | //      } | 
| 2750 | //      /// reset counters | 
| 2751 | //      if( GetTrigLevel2() ){ | 
| 2752 | //          totdltime[0]=GetTrigLevel2()->dltime[0];//live-time | 
| 2753 | //          totdltime[1]=0;                         //dead-time | 
| 2754 | //      } | 
| 2755 | //      totdltime[2]=1;                             //event counter | 
| 2756 |  | 
| 2757 |  | 
| 2758 | // -------------------------------------- | 
| 2759 | // ---> exit with TRUE | 
| 2760 | // -------------------------------------- | 
| 2761 | cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 2762 | // ---------------------------------------------------- | 
| 2763 | // then check if the run has a fragment | 
| 2764 | // in this case we have to switch to the next fragment | 
| 2765 | // when the end of the first fragment is reached | 
| 2766 | // ---------------------------------------------------- | 
| 2767 | if( | 
| 2768 | GetRunInfo()->ID_RUN_FRAG != 0 && | 
| 2769 | //          GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID && | 
| 2770 | true ){ | 
| 2771 | cout << "* fragment *"<<endl; | 
| 2772 | } | 
| 2773 |  | 
| 2774 | return(true); | 
| 2775 | }; | 
| 2776 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
| 2777 | // if it is a preselected file (there is SelectionList) | 
| 2778 | // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | 
| 2779 | if(SELLI==1){ | 
| 2780 | sel_tree->GetEntry(iev); | 
| 2781 | if(irun != oldrun){ | 
| 2782 | run_tree->GetEntry(irun); | 
| 2783 | cout << endl << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; | 
| 2784 | prevshift = 0; | 
| 2785 | return true; | 
| 2786 | } | 
| 2787 | return false; | 
| 2788 | } | 
| 2789 |  | 
| 2790 | return false; | 
| 2791 | // | 
| 2792 | }; | 
| 2793 | /** | 
| 2794 | * Update the runinfo informations (to be used to have Run infos event by event basis) | 
| 2795 | * @param run Pointer to the chain/tree which contains run infos | 
| 2796 | * @return true if a new run has been read, false if it is still the same run | 
| 2797 | */ | 
| 2798 | Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev){ | 
| 2799 | return(UpdateRunInfo((TChain*)run,iev)); | 
| 2800 | }; | 
| 2801 |  | 
| 2802 | //-------------------------------------- | 
| 2803 | // | 
| 2804 | // | 
| 2805 | //-------------------------------------- | 
| 2806 | /** | 
| 2807 | * Set which trees shoul be analysed | 
| 2808 | * @param detlist TString containing the sequence of trees required | 
| 2809 | */ | 
| 2810 | void PamLevel2::SetWhichTrees(TString detlist){ | 
| 2811 |  | 
| 2812 | //    if(detlist.IsNull() || detlist.Contains("+ALL", TString::kIgnoreCase)){ | 
| 2813 | if( detlist.Contains("+ALL", TString::kIgnoreCase)){ | 
| 2814 |  | 
| 2815 | cout << " ======================================================== "<<endl; | 
| 2816 | cout << "                       (( WARNING ))                      "<< endl; | 
| 2817 | cout << " The meaning of the option +ALL has changed!!             "<<endl; | 
| 2818 | cout << " Now it includes really all (level0+level1+level2+gpamela)"<<endl; | 
| 2819 | cout << " and the file is discarded if it does not contain all     "<<endl; | 
| 2820 | cout << " trees or level0 files are not available!!                "<<endl; | 
| 2821 | cout << " ======================================================== "<<endl; | 
| 2822 |  | 
| 2823 | CAL0 = true; | 
| 2824 | CAL1 = true; | 
| 2825 | CAL2 = true; | 
| 2826 | TRK2 = true; | 
| 2827 | TRK1 = true; | 
| 2828 | TRKh = true; | 
| 2829 | TRK0 = true; | 
| 2830 | TRG = true; | 
| 2831 | TOF = true; | 
| 2832 | TOF0 = true; | 
| 2833 | S4  = true; | 
| 2834 | ND  = true; | 
| 2835 | AC  = true; | 
| 2836 | ORB = true; | 
| 2837 | GP  = true; | 
| 2838 | }else if( detlist.Contains("-ALL", TString::kIgnoreCase) ){ | 
| 2839 | CAL0 = false; | 
| 2840 | CAL1 = false; | 
| 2841 | CAL2 = false; | 
| 2842 | TRK2 = false; | 
| 2843 | TRK1 = false; | 
| 2844 | TRKh = false; | 
| 2845 | TRK0 = false; | 
| 2846 | TRG = false; | 
| 2847 | TOF = false; | 
| 2848 | TOF0 = false; | 
| 2849 | S4  = false; | 
| 2850 | ND  = false; | 
| 2851 | AC  = false; | 
| 2852 | ORB = false; | 
| 2853 | GP  = false; | 
| 2854 | }; | 
| 2855 |  | 
| 2856 | //  ------------------------------------------------------------------------- | 
| 2857 | if( detlist.Contains("CAL1", TString::kIgnoreCase) ){ | 
| 2858 | if ( detlist.Contains("-CAL1", TString::kIgnoreCase) )CAL1=false; | 
| 2859 | if ( detlist.Contains("+CAL1", TString::kIgnoreCase) )CAL1=true; | 
| 2860 | }; | 
| 2861 |  | 
| 2862 | if( detlist.Contains("CAL0", TString::kIgnoreCase) ){ | 
| 2863 | if ( detlist.Contains("-CAL0", TString::kIgnoreCase) )CAL0=false; | 
| 2864 | if ( detlist.Contains("+CAL0", TString::kIgnoreCase) )CAL0=true; | 
| 2865 | }; | 
| 2866 |  | 
| 2867 | if( detlist.Contains("CAL2", TString::kIgnoreCase)){ | 
| 2868 | if ( detlist.Contains("-CAL2", TString::kIgnoreCase) )CAL2=false; | 
| 2869 | if ( detlist.Contains("+CAL2", TString::kIgnoreCase) )CAL2=true; | 
| 2870 | }; | 
| 2871 |  | 
| 2872 | if( detlist.Contains("+CAL", TString::kIgnoreCase) && !CAL1 && !CAL2 )CAL2=true; | 
| 2873 | if( detlist.Contains("-CAL", TString::kIgnoreCase) && CAL1 && CAL2 ){ | 
| 2874 | CAL2=false; | 
| 2875 | CAL1=false; | 
| 2876 | } | 
| 2877 | //  ------------------------------------------------------------------------- | 
| 2878 | if( detlist.Contains("TRK0", TString::kIgnoreCase) ){ | 
| 2879 | if ( detlist.Contains("-TRK0", TString::kIgnoreCase) )TRK0=false; | 
| 2880 | if ( detlist.Contains("+TRK0", TString::kIgnoreCase) )TRK0=true; | 
| 2881 | }; | 
| 2882 |  | 
| 2883 | if( detlist.Contains("TRK1", TString::kIgnoreCase) ){ | 
| 2884 | if ( detlist.Contains("-TRK1", TString::kIgnoreCase) )TRK1=false; | 
| 2885 | if ( detlist.Contains("+TRK1", TString::kIgnoreCase) )TRK1=true; | 
| 2886 | }; | 
| 2887 |  | 
| 2888 | if( detlist.Contains("TRK2", TString::kIgnoreCase)){ | 
| 2889 | if ( detlist.Contains("-TRK2", TString::kIgnoreCase) )TRK2=false; | 
| 2890 | if ( detlist.Contains("+TRK2", TString::kIgnoreCase) )TRK2=true; | 
| 2891 | }; | 
| 2892 |  | 
| 2893 | if( detlist.Contains("TRKh", TString::kIgnoreCase)){ | 
| 2894 | if ( detlist.Contains("-TRKh", TString::kIgnoreCase) )TRKh=false; | 
| 2895 | if ( detlist.Contains("+TRKh", TString::kIgnoreCase) )TRKh=true; | 
| 2896 | }; | 
| 2897 |  | 
| 2898 | if( detlist.Contains("+TRK", TString::kIgnoreCase) && !TRK1 && !TRK2 && !TRKh )TRK2=true; | 
| 2899 | if( detlist.Contains("-TRK", TString::kIgnoreCase) && TRK1 && TRK2 && TRKh){ | 
| 2900 | TRK2=false; | 
| 2901 | TRK1=false; | 
| 2902 | TRKh=false; | 
| 2903 | } | 
| 2904 | //  ------------------------------------------------------------------------- | 
| 2905 |  | 
| 2906 | if( detlist.Contains("-TRG", TString::kIgnoreCase) )TRG = false; | 
| 2907 | else if( detlist.Contains("+TRG", TString::kIgnoreCase) )TRG = true; | 
| 2908 |  | 
| 2909 | if( detlist.Contains("-TOF", TString::kIgnoreCase) )TOF = false; | 
| 2910 | else if( detlist.Contains("+TOF", TString::kIgnoreCase) )TOF = true; | 
| 2911 |  | 
| 2912 | if( detlist.Contains("-TOF0", TString::kIgnoreCase) )TOF0 = false; | 
| 2913 | else if( detlist.Contains("+TOF0", TString::kIgnoreCase) )TOF0 = true; | 
| 2914 |  | 
| 2915 | if( detlist.Contains("-S4",  TString::kIgnoreCase) )S4  = false; | 
| 2916 | else if( detlist.Contains("+S4",  TString::kIgnoreCase) )S4  = true; | 
| 2917 |  | 
| 2918 | if( detlist.Contains("-ND",  TString::kIgnoreCase) )ND  = false; | 
| 2919 | else if( detlist.Contains("+ND",  TString::kIgnoreCase) )ND  = true; | 
| 2920 |  | 
| 2921 | if( detlist.Contains("-AC",  TString::kIgnoreCase) )AC  = false; | 
| 2922 | else if( detlist.Contains("+AC",  TString::kIgnoreCase) )AC  = true; | 
| 2923 |  | 
| 2924 | if( detlist.Contains("-ORB", TString::kIgnoreCase) )ORB = false; | 
| 2925 | else if( detlist.Contains("+ORB", TString::kIgnoreCase) )ORB = true; | 
| 2926 |  | 
| 2927 | if( detlist.Contains("-GP", TString::kIgnoreCase) )GP = false; | 
| 2928 | else if( detlist.Contains("+GP", TString::kIgnoreCase) )GP = true; | 
| 2929 |  | 
| 2930 | cout<< "Set detector list from input --> "; | 
| 2931 | if(TRK0)cout<<"TRK0 "; | 
| 2932 | if(TRK1)cout<<"TRK1 "; | 
| 2933 | if(TRK2)cout<<"TRK2 "; | 
| 2934 | if(TRKh)cout<<"TRKH "; | 
| 2935 | if(CAL0)cout<<"CAL0 "; | 
| 2936 | if(CAL1)cout<<"CAL1 "; | 
| 2937 | if(CAL2)cout<<"CAL2 "; | 
| 2938 | if(TOF)cout<<"TOF "; | 
| 2939 | if(TRG)cout<<"TRG "; | 
| 2940 | if(AC)cout<<"AC "; | 
| 2941 | if(ND)cout<<"ND "; | 
| 2942 | if(S4)cout<<"S4 "; | 
| 2943 | if(ORB)cout<<"ORB "; | 
| 2944 | if(GP)cout<<"GP "; | 
| 2945 | cout << endl; | 
| 2946 | //     cout<< "Set detector list --> "; | 
| 2947 | //     if(TRK1)cout<<"TRK1 "; | 
| 2948 | //     if(TRK2)cout<<"TRK2 "; | 
| 2949 | //     if(TRKh)cout<<"TRKH "; | 
| 2950 | //     if(CAL1)cout<<"CAL1 "; | 
| 2951 | //     if(CAL2)cout<<"CAL2 "; | 
| 2952 | //     if(TOF0)cout<<"TOF0 "; | 
| 2953 | //     if(TOF)cout<<"TOF "; | 
| 2954 | //     if(TRG)cout<<"TRG "; | 
| 2955 | //     if(AC)cout<<"AC "; | 
| 2956 | //     if(ND)cout<<"ND "; | 
| 2957 | //     if(S4)cout<<"S4 "; | 
| 2958 | //     if(ORB)cout<<"ORB "; | 
| 2959 | //     cout << endl; | 
| 2960 |  | 
| 2961 | }; | 
| 2962 |  | 
| 2963 |  | 
| 2964 | /** | 
| 2965 | * Set tree/branch detector flags from the content of a tree | 
| 2966 | */ | 
| 2967 | void  PamLevel2::GetWhichTrees(TFile* f){ | 
| 2968 |  | 
| 2969 |  | 
| 2970 |  | 
| 2971 | //    cout << "void  PamLevel2::GetWhichTrees(TFile* f) --- WARNING!! --- ...potrebbe non funzionare "<<endl; | 
| 2972 | // ----------- | 
| 2973 | // reset flags | 
| 2974 | // ----------- | 
| 2975 | CAL1   = false; | 
| 2976 | CAL2   = false; | 
| 2977 | TRK2   = false; | 
| 2978 | TRK1   = false; | 
| 2979 | TRKh   = false; | 
| 2980 | TRG    = false; | 
| 2981 | TOF    = false; | 
| 2982 | S4     = false; | 
| 2983 | ND     = false; | 
| 2984 | AC     = false; | 
| 2985 | ORB    = false; | 
| 2986 | GP     = false; | 
| 2987 |  | 
| 2988 | RUN    = false; | 
| 2989 |  | 
| 2990 | cout << "Checking file: "<<f->GetName()<<endl; | 
| 2991 | if( !f || f->IsZombie() ){ | 
| 2992 | cout << "File: "<< f->GetName() <<" Non valid root file"<< endl; | 
| 2993 | return; | 
| 2994 | } | 
| 2995 |  | 
| 2996 | TList *lk = f->GetListOfKeys(); | 
| 2997 | TIter next(lk); | 
| 2998 | TKey *key =0; | 
| 2999 |  | 
| 3000 | Int_t nev = 0; | 
| 3001 |  | 
| 3002 | while( (key = (TKey*)next()) ){ | 
| 3003 |  | 
| 3004 | if( !strcmp(key->GetName(),"Run"        ) )RUN = true; | 
| 3005 |  | 
| 3006 | //========================================================= | 
| 3007 | if( !strcmp(key->GetName(),"Trigger"    ) ){ | 
| 3008 | TRG = true; | 
| 3009 | Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries(); | 
| 3010 | if( nev && nevt!=nev){ | 
| 3011 | cout << "File: "<< f->GetName() <<" Trigger tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3012 | TRG = false; | 
| 3013 | }else nev=nevt; | 
| 3014 | } | 
| 3015 | //========================================================= | 
| 3016 | if( !strcmp(key->GetName(),"ToF"        ) ){ | 
| 3017 | TOF = true; | 
| 3018 | Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries(); | 
| 3019 | if( nev && nevt!=nev){ | 
| 3020 | cout << "File: "<< f->GetName() <<"     ToF tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3021 | TOF = false; | 
| 3022 | }else nev=nevt; | 
| 3023 | } | 
| 3024 | //========================================================= | 
| 3025 | if( !strcmp(key->GetName(),"S4"         ) ){ | 
| 3026 | S4 = true; | 
| 3027 | Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries(); | 
| 3028 | if( nev && nevt!=nev){ | 
| 3029 | cout << "File: "<< f->GetName() <<"      S4 tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3030 | S4 = false; | 
| 3031 | }else nev=nevt; | 
| 3032 | } | 
| 3033 | //========================================================= | 
| 3034 |  | 
| 3035 | if( !strcmp(key->GetName(),"NeutronD"   ) ){ | 
| 3036 | ND = true; | 
| 3037 | Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries(); | 
| 3038 | if( nev && nevt!=nev){ | 
| 3039 | cout << "File: "<< f->GetName() <<"NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3040 | ND =false; | 
| 3041 | }else nev=nevt; | 
| 3042 | } | 
| 3043 | //========================================================= | 
| 3044 | if( !strcmp(key->GetName(),"Anticounter") ){ | 
| 3045 | AC = true; | 
| 3046 | Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries(); | 
| 3047 | if( nev && nevt!=nev){ | 
| 3048 | cout << "File: "<< f->GetName() <<" Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3049 | AC =false; | 
| 3050 | }else nev=nevt; | 
| 3051 | } | 
| 3052 | //========================================================= | 
| 3053 | if( !strcmp(key->GetName(),"OrbitalInfo") ){ | 
| 3054 | ORB = true; | 
| 3055 | Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries(); | 
| 3056 | if( nev && nevt!=nev){ | 
| 3057 | cout << "File: "<< f->GetName() <<" OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3058 | ORB = false; | 
| 3059 | }else nev=nevt; | 
| 3060 | } | 
| 3061 | //========================================================= | 
| 3062 | if( !strcmp(key->GetName(),"Tracker"    ) ){ | 
| 3063 | TTree *T = (TTree*)f->Get("Tracker"); | 
| 3064 | for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ | 
| 3065 | TString name = T->GetListOfBranches()->At(i)->GetName(); | 
| 3066 | if( !name.CompareTo("TrkLevel1") )TRK1=true; | 
| 3067 | if( !name.CompareTo("TrkLevel2") )TRK2=true; | 
| 3068 | if( !name.CompareTo("TrkHough") )TRKh=true; | 
| 3069 | }; | 
| 3070 | Int_t nevt = T->GetEntries(); | 
| 3071 | if( nev && nevt!=nev){ | 
| 3072 | cout << "File: "<< f->GetName() <<" Tracker tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3073 | TRK1 = false; | 
| 3074 | TRK2 = false; | 
| 3075 | TRKh = false; | 
| 3076 | }else nev=nevt; | 
| 3077 | //          T->Delete(); | 
| 3078 | }; | 
| 3079 | //========================================================= | 
| 3080 | if( !strcmp(key->GetName(),"Calorimeter"    ) ){ | 
| 3081 | TTree *T = (TTree*)f->Get("Calorimeter"); | 
| 3082 | for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ | 
| 3083 | TString name = T->GetListOfBranches()->At(i)->GetName(); | 
| 3084 | if( !name.CompareTo("CaloLevel1") )CAL1=true; | 
| 3085 | if( !name.CompareTo("CaloLevel2") )CAL2=true; | 
| 3086 | }; | 
| 3087 | Int_t nevt = T->GetEntries(); | 
| 3088 | if( nev && nevt!=nev){ | 
| 3089 | cout << "File: "<< f->GetName() <<"  Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3090 | CAL1 = false; | 
| 3091 | CAL2 = false; | 
| 3092 | }else nev=nevt; | 
| 3093 | //          T->Delete(); | 
| 3094 | }; | 
| 3095 | //========================================================= | 
| 3096 | if( !strcmp(key->GetName(),"h20") ){ | 
| 3097 | GP = true; | 
| 3098 | Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries(); | 
| 3099 | if( nev && nevt!=nev){ | 
| 3100 | cout << "File: "<< f->GetName() <<" h20 tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3101 | GP = false; | 
| 3102 | }else nev=nevt; | 
| 3103 | } | 
| 3104 |  | 
| 3105 | }; | 
| 3106 |  | 
| 3107 | //    delete lk; | 
| 3108 |  | 
| 3109 | cout<< "Get detector list from input file --> "; | 
| 3110 | if(TRK1)cout<<"TRK1 "; | 
| 3111 | if(TRK2)cout<<"TRK2 "; | 
| 3112 | if(TRKh)cout<<"TRKH "; | 
| 3113 | if(CAL1)cout<<"CAL1 "; | 
| 3114 | if(CAL2)cout<<"CAL2 "; | 
| 3115 | if(TOF)cout<<"TOF "; | 
| 3116 | if(TRG)cout<<"TRG "; | 
| 3117 | if(AC)cout<<"AC "; | 
| 3118 | if(ND)cout<<"ND "; | 
| 3119 | if(S4)cout<<"S4 "; | 
| 3120 | if(ORB)cout<<"ORB "; | 
| 3121 | if(GP)cout<<"GP "; | 
| 3122 | cout << endl; | 
| 3123 |  | 
| 3124 | return ; | 
| 3125 |  | 
| 3126 | }; | 
| 3127 |  | 
| 3128 |  | 
| 3129 | //-------------------------------------- | 
| 3130 | // | 
| 3131 | // | 
| 3132 | //-------------------------------------- | 
| 3133 | /** | 
| 3134 | * Check if a file contains selected Pamela Level2 trees. | 
| 3135 | * @param name File name | 
| 3136 | * @return true if the file is ok. | 
| 3137 | */ | 
| 3138 | Bool_t  PamLevel2::CheckLevel2File(TString name){ | 
| 3139 |  | 
| 3140 | Bool_t CAL1__ok   = false; | 
| 3141 | Bool_t CAL2__ok   = false; | 
| 3142 | Bool_t TRK2__ok   = false; | 
| 3143 | Bool_t TRK1__ok   = false; | 
| 3144 | Bool_t TRKh__ok   = false; | 
| 3145 | Bool_t TRG__ok    = false; | 
| 3146 | Bool_t TOF__ok    = false; | 
| 3147 | Bool_t S4__ok     = false; | 
| 3148 | Bool_t ND__ok     = false; | 
| 3149 | Bool_t AC__ok     = false; | 
| 3150 | Bool_t ORB__ok    = false; | 
| 3151 | Bool_t GP__ok     = false; | 
| 3152 |  | 
| 3153 | Bool_t RUN__ok    = false; | 
| 3154 |  | 
| 3155 | Bool_t SELLI__ok  = false; | 
| 3156 |  | 
| 3157 | cout << "Checking file: "<<name<<endl; | 
| 3158 | TFile *f = new TFile(name.Data()); | 
| 3159 | if( !f || f->IsZombie() ){ | 
| 3160 | cout << "File: "<< f->GetName() <<" discarded ---- Non valid root file"<< endl; return false; | 
| 3161 | } | 
| 3162 | //    cout << "Get list of keys: "<<f<<endl; | 
| 3163 | TList *lk = f->GetListOfKeys(); | 
| 3164 | //    lk->Print(); | 
| 3165 | TIter next(lk); | 
| 3166 | TKey *key =0; | 
| 3167 |  | 
| 3168 | Int_t nev = 0; | 
| 3169 |  | 
| 3170 | while( (key = (TKey*)next()) ){ | 
| 3171 |  | 
| 3172 | //      cout << key->GetName() << endl; | 
| 3173 | //      cout << key->GetName() << ""<<key->GetClassName()<<endl; | 
| 3174 | //              cout << " Get tree: " << f->Get(key->GetName())<<endl; | 
| 3175 | //      nev_previous = nev; | 
| 3176 | //      cout << " n.entries  "<< nev <<endl; | 
| 3177 | //      if( key->GetClassName()=="TTree" && nev_previous && nev != nev_previous ){ | 
| 3178 | //          nev = ((TTree*)f->Get(key->GetName()))->GetEntries(); | 
| 3179 | //          cout << "File: "<< f->GetName() <<" discarded ---- "<< key->GetName() << " tree: n.entries does not match "<<nev<<" "<<nev_previous<< endl; | 
| 3180 | //          return false; | 
| 3181 | //      }; | 
| 3182 |  | 
| 3183 | //========================================================= | 
| 3184 | // check if the file | 
| 3185 |  | 
| 3186 |  | 
| 3187 | if( !strcmp(key->GetName(),"Run"        ) )RUN__ok = true; | 
| 3188 |  | 
| 3189 | //========================================================= | 
| 3190 | if( !strcmp(key->GetName(),"SelectionList"    ) ){ | 
| 3191 | SELLI__ok = true; | 
| 3192 | if(SELLI==1){ | 
| 3193 | Int_t nevt = ((TTree*)f->Get("SelectionList"))->GetEntries(); | 
| 3194 | if( nev && nevt!=nev){ | 
| 3195 | cout << "File: "<< f->GetName() <<" discarded ---- SelectionList tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3196 | return false; | 
| 3197 | } | 
| 3198 | nev=nevt; | 
| 3199 | } | 
| 3200 | } | 
| 3201 |  | 
| 3202 | //========================================================= | 
| 3203 | if( !strcmp(key->GetName(),"Trigger"    ) ){ | 
| 3204 | TRG__ok = true; | 
| 3205 | if(TRG){ | 
| 3206 | Int_t nevt = ((TTree*)f->Get("Trigger"))->GetEntries(); | 
| 3207 | if( nev && nevt!=nev){ | 
| 3208 | cout << "File: "<< f->GetName() <<" discarded ---- Trigger tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3209 | return false; | 
| 3210 | } | 
| 3211 | nev=nevt; | 
| 3212 | } | 
| 3213 | } | 
| 3214 | //========================================================= | 
| 3215 | if( !strcmp(key->GetName(),"ToF"        ) ){ | 
| 3216 | TOF__ok = true; | 
| 3217 | if(TOF){ | 
| 3218 | Int_t nevt = ((TTree*)f->Get("ToF"))->GetEntries(); | 
| 3219 | if( nev && nevt!=nev){ | 
| 3220 | cout << "File: "<< f->GetName() <<" discarded ---- ToF tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3221 | return false; | 
| 3222 | } | 
| 3223 | nev=nevt; | 
| 3224 | } | 
| 3225 | } | 
| 3226 | //========================================================= | 
| 3227 | if( !strcmp(key->GetName(),"S4"         ) ){ | 
| 3228 | S4__ok = true; | 
| 3229 | if(S4){ | 
| 3230 | Int_t nevt = ((TTree*)f->Get("S4"))->GetEntries(); | 
| 3231 | if( nev && nevt!=nev){ | 
| 3232 | cout << "File: "<< f->GetName() <<" discarded ---- S4 tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3233 | return false; | 
| 3234 | } | 
| 3235 | nev=nevt; | 
| 3236 | } | 
| 3237 | } | 
| 3238 | //========================================================= | 
| 3239 |  | 
| 3240 | if( !strcmp(key->GetName(),"NeutronD"   ) ){ | 
| 3241 | ND__ok = true; | 
| 3242 | if(ND){ | 
| 3243 | Int_t nevt = ((TTree*)f->Get("NeutronD"))->GetEntries(); | 
| 3244 | if( nev && nevt!=nev){ | 
| 3245 | cout << "File: "<< f->GetName() <<" discarded ---- NeutronD tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3246 | return false; | 
| 3247 | } | 
| 3248 | nev=nevt; | 
| 3249 | } | 
| 3250 | } | 
| 3251 | //========================================================= | 
| 3252 | if( !strcmp(key->GetName(),"Anticounter") ){ | 
| 3253 | AC__ok = true; | 
| 3254 | if(AC){ | 
| 3255 | Int_t nevt = ((TTree*)f->Get("Anticounter"))->GetEntries(); | 
| 3256 | if( nev && nevt!=nev){ | 
| 3257 | cout << "File: "<< f->GetName() <<" discarded ---- Anticounter tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3258 | return false; | 
| 3259 | } | 
| 3260 | nev=nevt; | 
| 3261 | } | 
| 3262 | } | 
| 3263 | //========================================================= | 
| 3264 | if( !strcmp(key->GetName(),"OrbitalInfo") ){ | 
| 3265 | ORB__ok = true; | 
| 3266 | if(ORB){ | 
| 3267 | Int_t nevt = ((TTree*)f->Get("OrbitalInfo"))->GetEntries(); | 
| 3268 | if( nev && nevt!=nev){ | 
| 3269 | cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3270 | return false; | 
| 3271 | } | 
| 3272 | nev=nevt; | 
| 3273 | } | 
| 3274 | } | 
| 3275 | //========================================================= | 
| 3276 | if( !strcmp(key->GetName(),"Tracker"    ) ){ | 
| 3277 | TTree *T = (TTree*)f->Get("Tracker"); | 
| 3278 | if(TRK1||TRK2||TRKh){ | 
| 3279 | Int_t nevt = T->GetEntries(); | 
| 3280 | if( nev && nevt!=nev){ | 
| 3281 | cout << "File: "<< f->GetName() <<" discarded ---- Tracker tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3282 | return false; | 
| 3283 | } | 
| 3284 | nev=nevt; | 
| 3285 | } | 
| 3286 | for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ | 
| 3287 | TString name = T->GetListOfBranches()->At(i)->GetName(); | 
| 3288 | if( !name.CompareTo("TrkLevel1") )TRK1__ok=true; | 
| 3289 | if( !name.CompareTo("TrkLevel2") )TRK2__ok=true; | 
| 3290 | if( !name.CompareTo("TrkHough") )TRKh__ok=true; | 
| 3291 | }; | 
| 3292 | T->Delete(); | 
| 3293 | }; | 
| 3294 | //========================================================= | 
| 3295 | if( !strcmp(key->GetName(),"Calorimeter"    ) ){ | 
| 3296 | TTree *T = (TTree*)f->Get("Calorimeter"); | 
| 3297 | if(CAL1||CAL2){ | 
| 3298 | Int_t nevt = T->GetEntries(); | 
| 3299 | if( nev && nevt!=nev){ | 
| 3300 | cout << "File: "<< f->GetName() <<" discarded ---- Calorimeter tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3301 | return false; | 
| 3302 | } | 
| 3303 | nev=nevt; | 
| 3304 | } | 
| 3305 | for(Int_t i=0; i<T->GetListOfBranches()->GetEntries(); i++){ | 
| 3306 | TString name = T->GetListOfBranches()->At(i)->GetName(); | 
| 3307 | if( !name.CompareTo("CaloLevel1") )CAL1__ok=true; | 
| 3308 | if( !name.CompareTo("CaloLevel2") )CAL2__ok=true; | 
| 3309 | }; | 
| 3310 | T->Delete(); | 
| 3311 | }; | 
| 3312 | //========================================================= | 
| 3313 | if( !strcmp(key->GetName(),"h20") ){ | 
| 3314 | ISGP = true; | 
| 3315 | GP__ok = true; | 
| 3316 | if(GP){ | 
| 3317 | Int_t nevt = ((TTree*)f->Get("h20"))->GetEntries(); | 
| 3318 | if( nev && nevt!=nev){ | 
| 3319 | cout << "File: "<< f->GetName() <<" discarded ---- OrbitalInfo tree has "<<nevt<<" events instead of "<<nev<< endl; | 
| 3320 | return false; | 
| 3321 | } | 
| 3322 | nev=nevt; | 
| 3323 | } | 
| 3324 | } | 
| 3325 |  | 
| 3326 | }; | 
| 3327 |  | 
| 3328 | if( SELLI==-1 )SELLI = (Int_t)SELLI__ok; | 
| 3329 | if( SELLI==0 && SELLI__ok ){ | 
| 3330 | cout << "File: "<< f->GetName() <<" discarded ---- found SelectionList (it is not a full-event file)" << endl; | 
| 3331 | return false; | 
| 3332 | } | 
| 3333 | if( SELLI==1 && !SELLI__ok ){ | 
| 3334 | cout << "File: "<< f->GetName() <<" discarded ---- SelectionList missing" << endl; | 
| 3335 | return false; | 
| 3336 | } | 
| 3337 |  | 
| 3338 | //    cout << "SELLI "<<SELLI<<endl; | 
| 3339 |  | 
| 3340 | //     cout<< "CheckLevel2File(TString): detector list --> "; | 
| 3341 | //     if(TRK1__ok)cout<<"TRK1 "; | 
| 3342 | //     if(TRK2__ok)cout<<"TRK2 "; | 
| 3343 | //     if(TRKh__ok)cout<<"TRKH "; | 
| 3344 | //     if(CAL1__ok)cout<<"CAL1 "; | 
| 3345 | //     if(CAL2__ok)cout<<"CAL2 "; | 
| 3346 | //     if(TOF__ok)cout<<"TOF "; | 
| 3347 | //     if(TRG__ok)cout<<"TRG "; | 
| 3348 | //     if(AC__ok)cout<<"AC "; | 
| 3349 | //     if(ND__ok)cout<<"ND "; | 
| 3350 | //     if(S4__ok)cout<<"S4 "; | 
| 3351 | //     if(ORB__ok)cout<<"ORB "; | 
| 3352 | //     cout << endl; | 
| 3353 |  | 
| 3354 |  | 
| 3355 | if(TRK2 && TRK1__ok)TRK1=1; | 
| 3356 | // ---------------------------------------------------------------------------- | 
| 3357 | // NOTA | 
| 3358 | // se c'e` il level1, lo devo necessarimente leggere. | 
| 3359 | // infatti (non ho capito perche`) i cluster vengono letti e allocati in memoria | 
| 3360 | // comunque, ma non vengono disallocati da PamLevel2::Clear() | 
| 3361 | // ---------------------------------------------------------------------------- | 
| 3362 |  | 
| 3363 |  | 
| 3364 | if(!RUN__ok) { | 
| 3365 | cout << "File: "<< f->GetName() <<" *WARNING* ---- Missing RunInfo tree"<< endl; | 
| 3366 | //      return false; | 
| 3367 | }; | 
| 3368 |  | 
| 3369 | if(CAL1 && !CAL1__ok){ | 
| 3370 | cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel1 branch"<< endl; | 
| 3371 | return false; | 
| 3372 | }; | 
| 3373 | if(CAL2 && !CAL2__ok){ | 
| 3374 | cout << "File: "<< f->GetName() <<" discarded ---- Missing CaloLevel2 branch"<< endl; | 
| 3375 | return false; | 
| 3376 | }; | 
| 3377 | if(TRK2 && !TRK2__ok){ | 
| 3378 | cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel2 branch"<< endl; | 
| 3379 | return false; | 
| 3380 | }; | 
| 3381 | if(TRK1 && !TRK1__ok){ | 
| 3382 | cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkLevel1 branch"<< endl; | 
| 3383 | return false; | 
| 3384 | }; | 
| 3385 | if(TRKh && !TRKh__ok){ | 
| 3386 | cout << "File: "<< f->GetName() <<" discarded ---- Missing TrkHough branch"<< endl; | 
| 3387 | return false; | 
| 3388 | }; | 
| 3389 | if(ORB && !ORB__ok){ | 
| 3390 | cout << "File: "<< f->GetName() <<" discarded ---- Missing ORB tree"<< endl; | 
| 3391 | return false; | 
| 3392 | }; | 
| 3393 | if(AC && !AC__ok){ | 
| 3394 | cout << "File: "<< f->GetName() <<" discarded ---- Missing AC tree"<< endl; | 
| 3395 | return false; | 
| 3396 | }; | 
| 3397 | if(S4 && !S4__ok){ | 
| 3398 | cout << "File: "<< f->GetName() <<" discarded ---- Missing S4 tree"<< endl; | 
| 3399 | return false; | 
| 3400 | }; | 
| 3401 | if(TOF && !TOF__ok){ | 
| 3402 | cout << "File: "<< f->GetName() <<" discarded ---- Missing ToF tree"<< endl; | 
| 3403 | return false; | 
| 3404 | }; | 
| 3405 |  | 
| 3406 | if(ND && !ND__ok){ | 
| 3407 | cout << "File: "<< f->GetName() <<" discarded ---- Missing ND tree"<< endl; | 
| 3408 | return false; | 
| 3409 | }; | 
| 3410 | if(TRG && !TRG__ok){ | 
| 3411 | cout << "File: "<< f->GetName() <<" discarded ---- Missing Trigger tree"<< endl; | 
| 3412 | return false; | 
| 3413 | }; | 
| 3414 | if(GP && !GP__ok){ | 
| 3415 | cout << "File: "<< f->GetName() <<" discarded ---- Missing h20 tree"<< endl; | 
| 3416 | return false; | 
| 3417 | }; | 
| 3418 |  | 
| 3419 |  | 
| 3420 | //    lk->Delete(); | 
| 3421 | //    delete lk; | 
| 3422 | f->Close(); | 
| 3423 |  | 
| 3424 | //     cout<< "CheckLevel2File(TString): detector list --> "; | 
| 3425 | //     if(TRK1)cout<<"TRK1 "; | 
| 3426 | //     if(TRK2)cout<<"TRK2 "; | 
| 3427 | //     if(TRKh)cout<<"TRKH "; | 
| 3428 | //     if(CAL1)cout<<"CAL1 "; | 
| 3429 | //     if(CAL2)cout<<"CAL2 "; | 
| 3430 | //     if(TOF)cout<<"TOF "; | 
| 3431 | //     if(TRG)cout<<"TRG "; | 
| 3432 | //     if(AC)cout<<"AC "; | 
| 3433 | //     if(ND)cout<<"ND "; | 
| 3434 | //     if(S4)cout<<"S4 "; | 
| 3435 | //     if(ORB)cout<<"ORB "; | 
| 3436 | //     if(GP)cout<<"GP "; | 
| 3437 | //     cout << endl; | 
| 3438 |  | 
| 3439 | return true; | 
| 3440 |  | 
| 3441 | }; | 
| 3442 |  | 
| 3443 |  | 
| 3444 | /** | 
| 3445 | * Create clone-trees | 
| 3446 | */ | 
| 3447 | void PamLevel2::CreateCloneTrees0( TChain *fChain, TFile *ofile ){ | 
| 3448 |  | 
| 3449 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3450 | cout << "Create clones of PAMELA trees "<<endl; | 
| 3451 |  | 
| 3452 | Int_t i=0; | 
| 3453 | pam_tree_clone[i] = fChain->GetTree()->CloneTree(0); | 
| 3454 | TString name =  pam_tree_clone[i]->GetName(); | 
| 3455 | name.Append("_clone"); | 
| 3456 | //    pam_tree_clone[i]->SetName(name.Data()); | 
| 3457 | cout << pam_tree_clone[i]->GetName() <<endl; | 
| 3458 | i++; | 
| 3459 |  | 
| 3460 | TList *li = fChain->GetListOfFriends(); | 
| 3461 | TIter next(li); | 
| 3462 | TFriendElement* T_friend=0; | 
| 3463 | ofile->cd(); | 
| 3464 | while( (T_friend = (TFriendElement*)next()) ){ | 
| 3465 | //      cout<<T_friend->IsA()->GetName()<<" "<<T_friend->GetName()<<hex << T_friend->GetTree() << dec<<endl; | 
| 3466 | //      cout<<T_friend->GetTree()->GetName()<< endl; | 
| 3467 | pam_tree_clone[i] = T_friend->GetTree()->CloneTree(0); | 
| 3468 | pam_tree_clone[i]->SetAutoSave(1000000); | 
| 3469 | name =  pam_tree_clone[i]->GetName(); | 
| 3470 | name.Append("_clone"); | 
| 3471 | //      pam_tree_clone[i]->SetName(name.Data()); | 
| 3472 | cout << pam_tree_clone[i]->GetName() << endl; | 
| 3473 | i++; | 
| 3474 | } | 
| 3475 |  | 
| 3476 | delete li; | 
| 3477 |  | 
| 3478 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3479 |  | 
| 3480 | } | 
| 3481 |  | 
| 3482 | /** | 
| 3483 | * Create clone-trees | 
| 3484 | */ | 
| 3485 | void PamLevel2::CreateCloneTrees(TFile *ofile){ | 
| 3486 |  | 
| 3487 |  | 
| 3488 | //  if the pointer is null, create a default file | 
| 3489 |  | 
| 3490 | if(!ofile){ | 
| 3491 | cout << "void PamLevel2::CreateCloneTrees(TFile*) -- WARNING -- Creating file: clone-tree.root "<<endl; | 
| 3492 | ofile = new TFile("clone-tree.root","recreate"); | 
| 3493 | } | 
| 3494 |  | 
| 3495 | ofile->cd(); | 
| 3496 |  | 
| 3497 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3498 | cout << "Create new PAMELA trees "<<endl; | 
| 3499 |  | 
| 3500 |  | 
| 3501 | run_tree_clone = new TTree("Run","PAMELA Level2 data from the GL_RUN table "); | 
| 3502 | run_tree_clone->Branch("RunInfo","GL_RUN",GetPointerTo("RunInfo")); | 
| 3503 | cout << "Run          : branch RunInfo"<<endl; | 
| 3504 | run_tree_clone->Branch("SoftInfo","SoftInfo",GetPointerTo("SoftInfo")); | 
| 3505 | cout << "Run          : branch SoftInfo"<<endl; | 
| 3506 | // ------------------ | 
| 3507 | // replicate run tree | 
| 3508 | // ------------------ | 
| 3509 | cout << "----------------------------------------------------"<<endl; | 
| 3510 | cout << "irun\t | RUN\t NEVENTS\t absolute time"<<endl; | 
| 3511 | for (Int_t i=0; i<run_tree->GetEntries(); i++){ | 
| 3512 | run_tree->GetEntry(i); | 
| 3513 | cout << i<< "\t | "<<GetRunInfo()->ID<<"\t "<<GetRunInfo()->NEVENTS<< "\t "<<GetRunInfo()->RUNHEADER_TIME<<" <---> "<<GetRunInfo()->RUNTRAILER_TIME<<endl; | 
| 3514 | run_tree_clone->Fill(); | 
| 3515 | } | 
| 3516 | cout << "----------------------------------------------------"<<endl; | 
| 3517 |  | 
| 3518 | // ------------------------------------ | 
| 3519 | // add branch with dead and live times | 
| 3520 | // ------------------------------------ | 
| 3521 | run_tree_clone->Branch("DeadLiveTime",totdltime,"dltime[3]/l"); | 
| 3522 | cout << "Run          : branch DeadLiveTime"<<endl; | 
| 3523 |  | 
| 3524 |  | 
| 3525 | sel_tree_clone = new TTree("SelectionList","List of selected events "); | 
| 3526 | //    sel_tree_clone->Branch("RunEntry",&irun,"runentry/L"); | 
| 3527 | sel_tree_clone->Branch("RunEntry",&irun,"runentry/L"); | 
| 3528 | sel_tree_clone->Branch("EventEntry",&irunentry,"eventry/L"); | 
| 3529 |  | 
| 3530 |  | 
| 3531 | Int_t i=0; | 
| 3532 | if(TRK1||TRK2||TRKh){ | 
| 3533 | pam_tree_clone[i] = new TTree("Tracker","PAMELA tracker level2 data "); | 
| 3534 | if(TRK1) { | 
| 3535 | pam_tree_clone[i]->Branch("TrkLevel1","TrkLevel1", GetPointerTo("TrkLevel1")); | 
| 3536 | pam_tree_clone[i]->BranchRef(); | 
| 3537 | cout << "Tracker      : branch TrkLevel1"<<endl; | 
| 3538 | //          cout << "CreateCloneTrees " << GetTrkLevel1()<<endl; | 
| 3539 | }; | 
| 3540 | if(TRK2) { | 
| 3541 | pam_tree_clone[i]->Branch("TrkLevel2", "TrkLevel2",GetPointerTo("TrkLevel2")); | 
| 3542 | cout << "Tracker      : branch TrkLevel2"<<endl; | 
| 3543 | }; | 
| 3544 | if(TRKh) { | 
| 3545 | pam_tree_clone[i]->Branch("TrkHough","TrkHough", GetPointerTo("TrkHough")); | 
| 3546 | cout << "Tracker      : branch TrkHough"<<endl; | 
| 3547 | }; | 
| 3548 | i++; | 
| 3549 | } | 
| 3550 |  | 
| 3551 | // Calorimeter | 
| 3552 | if(CAL1||CAL2){ | 
| 3553 | pam_tree_clone[i] = new TTree("Calorimeter","PAMELA calorimeter level2 data "); | 
| 3554 | if(CAL1) { | 
| 3555 | pam_tree_clone[i]->Branch("CaloLevel1", "CaloLevel1", GetPointerTo("CaloLevel1")); | 
| 3556 | cout << "Calorimeter  : branch CaloLevel1"<<endl; | 
| 3557 | }; | 
| 3558 | if(CAL2) { | 
| 3559 | pam_tree_clone[i]->Branch("CaloLevel2","CaloLevel2", GetPointerTo("CaloLevel2")); | 
| 3560 | cout << "Calorimeter  : branch CaloLevel2"<<endl; | 
| 3561 | }; | 
| 3562 | i++; | 
| 3563 | } | 
| 3564 |  | 
| 3565 | // ToF | 
| 3566 | if(TOF) { | 
| 3567 | pam_tree_clone[i] = new TTree("ToF","PAMELA ToF level2 data "); | 
| 3568 | pam_tree_clone[i]->Branch("ToFLevel2","ToFLevel2", GetPointerTo("ToFLevel2")); | 
| 3569 | cout << "ToF          : branch ToFLevel2"<<endl; | 
| 3570 | i++; | 
| 3571 | }; | 
| 3572 | // Trigger | 
| 3573 | if(TRG) { | 
| 3574 | pam_tree_clone[i] = new TTree("Trigger","PAMELA trigger level2 data "); | 
| 3575 | pam_tree_clone[i]->Branch("TrigLevel2","TrigLevel2", GetPointerTo("TrigLevel2")); | 
| 3576 | cout << "Trigger      : branch TrigLevel2"<<endl; | 
| 3577 | i++; | 
| 3578 | }; | 
| 3579 | // S4 | 
| 3580 | if(S4) { | 
| 3581 | pam_tree_clone[i] = new TTree("S4","PAMELA S4 level2 data "); | 
| 3582 | pam_tree_clone[i]->Branch("S4Level2","S4Level2", GetPointerTo("S4Level2")); | 
| 3583 | cout << "S4           : branch S4Level2"<<endl; | 
| 3584 | i++; | 
| 3585 | }; | 
| 3586 | // Neutron Detector | 
| 3587 | if(ND) { | 
| 3588 | pam_tree_clone[i] = new TTree("NeutronD","PAMELA neutron detector level2 data "); | 
| 3589 | pam_tree_clone[i]->Branch("NDLevel2","NDLevel2", GetPointerTo("NDLevel2")); | 
| 3590 | cout << "NeutronD     : branch NDLevel2"<<endl; | 
| 3591 | i++; | 
| 3592 | }; | 
| 3593 | // Anticounters | 
| 3594 | if(AC) { | 
| 3595 | pam_tree_clone[i] = new TTree("Anticounter","PAMELA anticounter detector level2 data "); | 
| 3596 | pam_tree_clone[i]->Branch("AcLevel2","AcLevel2", GetPointerTo("AcLevel2")); | 
| 3597 | cout << "Anticounter  : branch AcLevel2"<<endl; | 
| 3598 | i++; | 
| 3599 | }; | 
| 3600 | // OrbitalInfo | 
| 3601 | if(ORB) { | 
| 3602 | pam_tree_clone[i] = new TTree("OrbitalInfo","PAMELA oribital info  "); | 
| 3603 | pam_tree_clone[i]->Branch("OrbitalInfo","OrbitalInfo", GetPointerTo("OrbitalInfo")); | 
| 3604 | cout << "OrbitalInfo  : branch OrbitalInfo"<<endl; | 
| 3605 | i++; | 
| 3606 | }; | 
| 3607 | // GPamela | 
| 3608 | if(GP) { | 
| 3609 | pam_tree_clone[i] = new TTree("h20","PAMELA oribital info  "); | 
| 3610 | pam_tree_clone[i]->Branch("GPamela","GPamela", GetPointerTo("GPamela"),32000,1);//split | 
| 3611 | cout << "OrbitalInfo  : branch OrbitalInfo"<<endl; | 
| 3612 | i++; | 
| 3613 | }; | 
| 3614 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3615 |  | 
| 3616 | } | 
| 3617 |  | 
| 3618 |  | 
| 3619 | /** | 
| 3620 | * Fill tree (created with CreateCloneTrees) | 
| 3621 | * | 
| 3622 | */ | 
| 3623 | //void PamLevel2::FillNewPamTree(TTree *T){ | 
| 3624 | void PamLevel2::FillCloneTrees(){ | 
| 3625 |  | 
| 3626 | //    cout << "PamLevel2::FillCloneTrees()" << irunentry << endl; | 
| 3627 |  | 
| 3628 | for(Int_t i=0; i<NCLONES; i++){ | 
| 3629 | if(pam_tree_clone[i])pam_tree_clone[i]->Fill(); | 
| 3630 | } | 
| 3631 | if(sel_tree_clone)sel_tree_clone->Fill(); | 
| 3632 |  | 
| 3633 | } | 
| 3634 |  | 
| 3635 |  | 
| 3636 | TTree* PamLevel2::GetCloneTree(TString name){ | 
| 3637 |  | 
| 3638 | for(Int_t i=0; i<NCLONES; i++){ | 
| 3639 | if(pam_tree_clone[i]){ | 
| 3640 | TString na = pam_tree_clone[i]->GetName(); | 
| 3641 | if(!name.CompareTo(na))return pam_tree_clone[i]; | 
| 3642 | }; | 
| 3643 | } | 
| 3644 | if(run_tree_clone){ | 
| 3645 | TString na = run_tree_clone->GetName(); | 
| 3646 | if(!name.CompareTo(na))return run_tree_clone; | 
| 3647 | } | 
| 3648 | if(sel_tree_clone){ | 
| 3649 | TString na = sel_tree_clone->GetName(); | 
| 3650 | if(!name.CompareTo(na))return sel_tree_clone; | 
| 3651 | } | 
| 3652 | return NULL; | 
| 3653 |  | 
| 3654 | } | 
| 3655 | void PamLevel2::WriteCloneTrees(){ | 
| 3656 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3657 | cout << "Write clones of PAMELA trees "<<endl; | 
| 3658 | cout << run_tree_clone->GetName()<<endl; | 
| 3659 | if(run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) | 
| 3660 | run_tree_clone->GetBranch("DeadLiveTime")->Fill(); | 
| 3661 | run_tree_clone->Write(); | 
| 3662 | cout << sel_tree_clone->GetName()<<endl; | 
| 3663 | sel_tree_clone->Write(); | 
| 3664 | for(Int_t i=0; i<NCLONES; i++){ | 
| 3665 | if(pam_tree_clone[i]){ | 
| 3666 | cout << pam_tree_clone[i]->GetName()<<endl; | 
| 3667 | pam_tree_clone[i]->Write(); | 
| 3668 | }; | 
| 3669 | } | 
| 3670 | cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" <<endl; | 
| 3671 |  | 
| 3672 | } | 
| 3673 |  | 
| 3674 | /** | 
| 3675 | * Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry. | 
| 3676 | */ | 
| 3677 | //Int_t PamLevel2::GetEntry(Int_t iee){ | 
| 3678 | Int_t PamLevel2::GetEntry(Long64_t iee){ | 
| 3679 |  | 
| 3680 | //     cout << "-------------------------------------"<<endl; | 
| 3681 | //     cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl; | 
| 3682 |  | 
| 3683 | if(!pam_tree){ | 
| 3684 | cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded"<<endl; | 
| 3685 | return 0; | 
| 3686 | } | 
| 3687 |  | 
| 3688 |  | 
| 3689 | // | 
| 3690 | // This is a sort of bug: if you don't have the run tree you don't want to exit here you want to have loaded the event anyway... | 
| 3691 | // | 
| 3692 | //    if(!run_tree ){ | 
| 3693 | //  cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loeaded"<<endl; | 
| 3694 | //  return 0; | 
| 3695 | //    } | 
| 3696 |  | 
| 3697 | Long64_t ii=0; | 
| 3698 | //------------------------------- | 
| 3699 | ii = iee; | 
| 3700 | if( !pam_tree->GetEntry(ii) ){ | 
| 3701 | cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree"<<endl; | 
| 3702 | return 0; | 
| 3703 | } | 
| 3704 |  | 
| 3705 | //    cout << " gp_obj->P0 "<<gp_obj->P0<<endl; | 
| 3706 | // | 
| 3707 | // ... that's way I put it here. Notice that nothing change in the code (is backward compatible) since in any case you return with 0. | 
| 3708 | // in theory one would like to return 1 if run is not loaded but now I don't have the will to add that 2 lines of code and it is not | 
| 3709 | // a problem if you don't check the return code of getentry. | 
| 3710 | // | 
| 3711 | if(!run_tree ){ | 
| 3712 | if ( TRK0 || CAL0 || TOF0 || RUN ) { //forse cosi` va bene per tornare 1? | 
| 3713 | cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- run tree not loaded"<<endl; | 
| 3714 | return 0; | 
| 3715 | }  else { | 
| 3716 | return 1; //cosi` se non c'e` run esce qua... | 
| 3717 | } | 
| 3718 | } | 
| 3719 |  | 
| 3720 | //------------------------------- | 
| 3721 | ii = iee; | 
| 3722 | //    Bool_t UPDATED = UpdateRunInfo(run_tree,ii); | 
| 3723 | //    Bool_t UPDATED = UpdateRunInfo(ii); | 
| 3724 | UpdateRunInfo(ii); | 
| 3725 | if(SELLI==0)irunentry = iee-runfirstentry; | 
| 3726 | //    if(UPDATED && run_tree_clone)run_tree_clone->Fill(); | 
| 3727 |  | 
| 3728 | //    cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl; | 
| 3729 |  | 
| 3730 | //     cout << "irunentry     "<<irunentry << endl; | 
| 3731 | //     cout << "runfirstentry "<<runfirstentry << endl; | 
| 3732 | //     cout << "nevents       "<<GetRunInfo()->NEVENTS<< endl; | 
| 3733 |  | 
| 3734 | //     if( TRK0 || CAL0 || TOF0 ){ | 
| 3735 | //      if( !GetYodaEntry( ) ){ | 
| 3736 | //          cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl; | 
| 3737 | //          return 0; | 
| 3738 | //      } | 
| 3739 | //     } | 
| 3740 |  | 
| 3741 |  | 
| 3742 | return 1; | 
| 3743 |  | 
| 3744 | } | 
| 3745 |  | 
| 3746 | TrkLevel0    *PamLevel2::GetTrkLevel0(){ | 
| 3747 | if( !TRK0 )return NULL; | 
| 3748 | if( !GetYodaEntry( ) ){ | 
| 3749 | cout << " Int_t PamLevel2::GetTrkLevel0() -- ERROR -- error reading level0 tree"<<endl; | 
| 3750 | return 0; | 
| 3751 | } | 
| 3752 | return trk0_obj; | 
| 3753 | }; | 
| 3754 | CaloLevel0    *PamLevel2::GetCaloLevel0(){ | 
| 3755 | if( !CAL0 )return NULL; | 
| 3756 | if( !GetYodaEntry( ) ){ | 
| 3757 | cout << " Int_t PamLevel2::GetCaloLevel0() -- ERROR -- error reading level0 tree"<<endl; | 
| 3758 | return 0; | 
| 3759 | } | 
| 3760 | return calo0_obj; | 
| 3761 | }; | 
| 3762 |  | 
| 3763 |  | 
| 3764 | /** | 
| 3765 | * Method to retrieve the level0 tree (YODA tree) that contains the current event. | 
| 3766 | * Given the run ID (...), if needed it query the DB and load the proper file. | 
| 3767 | * @return Pointer to the tree | 
| 3768 | */ | 
| 3769 |  | 
| 3770 |  | 
| 3771 | TTree* PamLevel2::GetYodaTree( ){ | 
| 3772 |  | 
| 3773 | //    cout << "TTree* PamLevel2::GetYodaTree( )"<<endl; | 
| 3774 | //=================================== | 
| 3775 | // check if iroot has changed | 
| 3776 | //=================================== | 
| 3777 | if( irun<0 ){ | 
| 3778 | cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = "<<irun<<endl; | 
| 3779 | //      cout << "In order to use this method you have to first load the RunInfo tree "<<endl; | 
| 3780 | return NULL; | 
| 3781 | } | 
| 3782 | Int_t irootnew = run_obj->ID_ROOT_L0; | 
| 3783 | //      cout << "iroot    "<<iroot<<endl; | 
| 3784 | //      cout << "irootnew "<<irootnew<<endl; | 
| 3785 |  | 
| 3786 | //=================================== | 
| 3787 | // load the level0 file | 
| 3788 | // (if not already loaded) | 
| 3789 | //=================================== | 
| 3790 | if( iroot != irootnew || !l0_tree){ | 
| 3791 | iroot = irootnew; | 
| 3792 | //=================================== | 
| 3793 | // open the DB connection | 
| 3794 | // (if not already opened) | 
| 3795 | //=================================== | 
| 3796 | if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection(); | 
| 3797 | GL_ROOT glroot = GL_ROOT(); | 
| 3798 | if( glroot.Query_GL_ROOT(iroot,dbc) ){ | 
| 3799 | cout << "TTree* PamLevel2::GetYodaTree( ) -- ERROR -- level0 file iroot = "<<iroot<< " does not exists"<<endl; | 
| 3800 | return NULL; | 
| 3801 | }; | 
| 3802 | TString filename = glroot.PATH + glroot.NAME; | 
| 3803 | if(l0_file){ | 
| 3804 | l0_file->Close(); | 
| 3805 | l0_file->Delete(); | 
| 3806 | } | 
| 3807 | cout << "Opening LEVEL0 file: "<< filename << endl; | 
| 3808 | FileStat_t t; | 
| 3809 | if( gSystem->GetPathInfo(filename.Data(),t) ){ | 
| 3810 | cout << " PamLevel2::GetYodaTree() -- ERROR opening file "<<endl; | 
| 3811 | return NULL; | 
| 3812 | } | 
| 3813 | l0_file = new TFile(filename); | 
| 3814 | if( !l0_file )return NULL; | 
| 3815 | l0_tree = (TTree*)l0_file->Get("Physics"); | 
| 3816 | if(!h0_obj)h0_obj = new EventHeader(); | 
| 3817 | l0_tree->SetBranchAddress("Header" ,&h0_obj); | 
| 3818 | prevshift = 0; | 
| 3819 | //--------------------------------------------------- | 
| 3820 | // TRACKER: | 
| 3821 | if(TRK0){ | 
| 3822 | if(!trk0_obj){ | 
| 3823 | trk0_obj = new TrkLevel0(); | 
| 3824 | trk0_obj->Set(); | 
| 3825 | }; | 
| 3826 | l0_tree->SetBranchAddress("Tracker" ,trk0_obj->GetPointerToTrackerEvent()); | 
| 3827 | } | 
| 3828 | //-------------------------------------------------- | 
| 3829 | // CALORIMETER: | 
| 3830 | if(CAL0){ | 
| 3831 | if(!calo0_obj){ | 
| 3832 | calo0_obj = new CaloLevel0(); | 
| 3833 | calo0_obj->Set(); | 
| 3834 | }; | 
| 3835 | l0_tree->SetBranchAddress("Calorimeter" ,calo0_obj->GetPointerToCalorimeterEvent()); | 
| 3836 | //      cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl; | 
| 3837 | } | 
| 3838 | //--------------------------------------------------- | 
| 3839 | // TOF: | 
| 3840 | if(TOF0){ | 
| 3841 | cout << "PamLevel2::GetYodaTree() --- level0 TOF not implemented "<<endl; | 
| 3842 | } | 
| 3843 |  | 
| 3844 | dbc->Close(); // EMILIANO, do not leave open connections, open only when needed | 
| 3845 |  | 
| 3846 |  | 
| 3847 | }; | 
| 3848 |  | 
| 3849 | //     if(!dbc || (dbc && !dbc->IsConnected())){ | 
| 3850 | //      cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl; | 
| 3851 | //     } | 
| 3852 |  | 
| 3853 | if ( TRK0 ){ | 
| 3854 | TrkParams::Load(6); | 
| 3855 | if( !TrkParams::IsLoaded(6) ){ | 
| 3856 | cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl; | 
| 3857 | }; | 
| 3858 | if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection(); | 
| 3859 | TrkParams::SetCalib(run_obj,dbc); | 
| 3860 | TrkParams::LoadCalib( ); | 
| 3861 | if( !TrkParams::CalibIsLoaded() ){ | 
| 3862 | cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- Calibration not loaded"<<endl; | 
| 3863 | }; | 
| 3864 | dbc->Close(); // EMILIANO, do not leave open connections, open only when needed | 
| 3865 | } | 
| 3866 |  | 
| 3867 |  | 
| 3868 | //    cout << l0_tree << endl; | 
| 3869 | return l0_tree; | 
| 3870 |  | 
| 3871 | } | 
| 3872 |  | 
| 3873 | /** | 
| 3874 | * Method to retrieve the level0 tree (YODA tree) that contains the current event. | 
| 3875 | */ | 
| 3876 | Int_t PamLevel2::GetYodaEntry(){ | 
| 3877 |  | 
| 3878 | //    cout << "Int_t PamLevel2::GetYodaEntry()"<<endl; | 
| 3879 | if(!GetYodaTree())return 0; | 
| 3880 |  | 
| 3881 | // patch | 
| 3882 | if( irunentry < 0){ | 
| 3883 | //      cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; | 
| 3884 | irunentry=0LL; | 
| 3885 | } | 
| 3886 | //  --------------------------------- | 
| 3887 | //  if file is NOT a preselected file | 
| 3888 | //  --------------------------------- | 
| 3889 | Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); | 
| 3890 | //     cout << " irunentry "<<irunentry<<endl; | 
| 3891 | //     cout << " EV_FROM "<<run_obj->EV_FROM<<endl; | 
| 3892 | //     cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl; | 
| 3893 |  | 
| 3894 | //     cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; | 
| 3895 | //     cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; | 
| 3896 | //     cout << " time "<< abstime << endl; | 
| 3897 | //     cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl; | 
| 3898 |  | 
| 3899 | ULong64_t obt     = 0; | 
| 3900 | ULong64_t pktn    = 0; | 
| 3901 | if( GetOrbitalInfo() ){ | 
| 3902 | obt     = GetOrbitalInfo()->OBT; | 
| 3903 | pktn    = GetOrbitalInfo()->pkt_num; | 
| 3904 | } | 
| 3905 |  | 
| 3906 | if( !GetOrbitalInfo() && !ISGP){ | 
| 3907 | cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo "<<endl; | 
| 3908 | return 0; | 
| 3909 | } | 
| 3910 | if( obt==0 && pktn==0 && !ISGP ){ | 
| 3911 | cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? "<<endl; | 
| 3912 | return 0; | 
| 3913 | } | 
| 3914 |  | 
| 3915 | // --------------------------------------------------------------------- | 
| 3916 | // ATTENTION!!! | 
| 3917 | // If data are not pre-processed with cleaner, the level0 tree may contain | 
| 3918 | // spurious nested physics packets. | 
| 3919 | // The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries | 
| 3920 | // while level2 tree DOES NOT!! | 
| 3921 | // This means that "quellagiusta" in these cases is not correct. | 
| 3922 | // In order to retrieve the correct level0 event, I implemented a check | 
| 3923 | // of the OBT and pkt-number. In case of mismatch, the level0 entry number | 
| 3924 | // is shift forward until when the packets match. | 
| 3925 | // --------------------------------------------------------------------- | 
| 3926 | Int_t answer = 0; | 
| 3927 | Int_t shift =0; | 
| 3928 | //    printf(" siamo qui %i %i \n",shift,prevshift); | 
| 3929 | //    Int_t maxshift = 50; // EMILIANO | 
| 3930 | do{ | 
| 3931 | if(shift>0){ | 
| 3932 | cout << " PKTNUM  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
| 3933 | cout << "         RUN: ID "<< GetRunInfo()->ID << " ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<" ID_RUN_FRAG "<<GetRunInfo()->ID_RUN_FRAG << " EV_FROM "<<GetRunInfo()->EV_FROM  <<endl; | 
| 3934 | cout << "         L2 <--> L0 mismatch ( irun "<<irun<<" irunentry "<<irunentry<<" shift "<<shift<<" prevshift "<<prevshift<<" )"<<endl; | 
| 3935 | } | 
| 3936 | answer = l0_tree->GetEntry(quellagiusta+(Long64_t)shift+(Long64_t)prevshift); | 
| 3937 | shift++; | 
| 3938 | if( !GetEventHeader() ){ | 
| 3939 | cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader "<<endl; | 
| 3940 | return 0; | 
| 3941 | } | 
| 3942 |  | 
| 3943 | if(ISGP){ | 
| 3944 | obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO | 
| 3945 | pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO | 
| 3946 | } | 
| 3947 |  | 
| 3948 | //      cout << "PKTNUM "<<shift<<" ==  L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; | 
| 3949 | //      cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl; | 
| 3950 | //      if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl; | 
| 3951 | //      cout << " obt "<< obt << endl; | 
| 3952 | //      cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; | 
| 3953 | //      cout << " pktn "<< pktn << endl; | 
| 3954 | //      cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; | 
| 3955 | //      printf(" IDRUN %u \n",GetRunInfo()->ID); | 
| 3956 | // | 
| 3957 | if ( prevshift != 0 && (quellagiusta+(Long64_t)shift) == GetYodaTree()->GetEntries() ){ | 
| 3958 | prevshift = 0; | 
| 3959 | shift = -1; | 
| 3960 | }; | 
| 3961 |  | 
| 3962 | }while( ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || | 
| 3963 | pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())       ) | 
| 3964 | && (quellagiusta+(Long64_t)shift) < GetYodaTree()->GetEntries() && shift < maxshift); | 
| 3965 |  | 
| 3966 | if ( (quellagiusta+(Long64_t)shift+(Long64_t)prevshift) > GetYodaTree()->GetEntries() || shift == maxshift ) { | 
| 3967 | cout << " Big trouble here, no such event in Level0 data! " <<endl; | 
| 3968 | return 0; | 
| 3969 | } | 
| 3970 | //    cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl; | 
| 3971 | //    return GetYodaTree()->GetEntry(quellagiusta); | 
| 3972 | if ( shift > 1 ) prevshift += (shift-1); | 
| 3973 |  | 
| 3974 | return answer; | 
| 3975 |  | 
| 3976 | } | 
| 3977 | /** | 
| 3978 | * \Brief Set DB connection | 
| 3979 | */ | 
| 3980 | Bool_t PamLevel2::SetDBConnection(){ | 
| 3981 |  | 
| 3982 | cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; | 
| 3983 | cout<<"Connecting to DB"<<endl; | 
| 3984 | cout<<"HOST "<<host<<endl; | 
| 3985 | cout<<"USER "<<user<<endl; | 
| 3986 | cout<<"PSW  "<<psw<<endl; | 
| 3987 | dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); | 
| 3988 | if( !dbc )return false; | 
| 3989 | if( !dbc->IsConnected() )return false; | 
| 3990 | stringstream myquery;  // EMILIANO | 
| 3991 | myquery.str("");  // EMILIANO | 
| 3992 | myquery << "SET time_zone='+0:00'";  // EMILIANO | 
| 3993 | dbc->Query(myquery.str().c_str());  // EMILIANO | 
| 3994 | cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl; | 
| 3995 | return true; | 
| 3996 |  | 
| 3997 | } | 
| 3998 |  | 
| 3999 | /** | 
| 4000 | * \Brief Add a friend to the pamela chain. | 
| 4001 | * @param cname name of the chain to be added | 
| 4002 | */ | 
| 4003 |  | 
| 4004 | TChain* PamLevel2::AddFriend(TString cname){ | 
| 4005 |  | 
| 4006 | if(!GetPamTree()){ | 
| 4007 | cout << " TChain* PamLevel2::AddFriend(TString cname) --- a pamela tree must be created first"<<endl; | 
| 4008 | return NULL; | 
| 4009 | } | 
| 4010 |  | 
| 4011 |  | 
| 4012 | TChain *c = new TChain( cname.Data() ); | 
| 4013 |  | 
| 4014 | TIter next( GetPamTree()->GetListOfFiles() ); | 
| 4015 | Int_t nf = 0; | 
| 4016 | TChainElement* element = 0; | 
| 4017 | while ((element = (TChainElement*) next())) { | 
| 4018 | c->Add(element->GetTitle()); | 
| 4019 | nf++; | 
| 4020 | } | 
| 4021 |  | 
| 4022 | GetPamTree()->AddFriend(cname.Data()); | 
| 4023 |  | 
| 4024 | cout << "external chain created and added to pamela friends :"<<cname<<endl; | 
| 4025 | cout << "n.files "<<nf<<endl; | 
| 4026 |  | 
| 4027 |  | 
| 4028 | return c; | 
| 4029 |  | 
| 4030 | } | 
| 4031 |  | 
| 4032 |  |