Made more robust
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.cxx
CommitLineData
ffa6d63b 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
803d1ab0 16/* $Id$ */
ffa6d63b 17
18//_________________________________________________________________________
19// A singleton. This class should be used in the analysis stage to get
20// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
21// instead of directly reading them from galice.root file. This container
88cb7938 22// ensures, that one reads Digits, made of these particular digits, RecPoints,
ffa6d63b 23// made of these particular RecPoints, TrackSegments and RecParticles.
24// This becomes non trivial if there are several identical branches, produced with
d75bea67 25// different set of parameters.
ffa6d63b 26//
27// An example of how to use (see also class AliEMCALAnalyser):
28// AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
d75bea67 29// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30// AliEMCALRecParticle * part = gime->RecParticle(1) ;
ffa6d63b 31// ................
88cb7938 32// gime->Event(event) ; // reads new event from galice.root
ffa6d63b 33//
d75bea67 34//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35//*-- Completely redesigned by Dmitri Peressounko March 2001
36//
37//*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
88cb7938 38//*-- systematic usage of TFolders without changing the interface
ffa6d63b 39//////////////////////////////////////////////////////////////////////////////
40
ffa6d63b 41// --- ROOT system ---
173558f2 42
88cb7938 43#include "TSystem.h"
ffa6d63b 44#include "TROOT.h"
1ce25ac8 45
ffa6d63b 46
47// --- Standard library ---
173558f2 48
ffa6d63b 49// --- AliRoot header files ---
1ce25ac8 50
ffa6d63b 51#include "AliEMCALGetter.h"
d64c959b 52#include "AliEMCAL.h"
88cb7938 53#include "AliRunLoader.h"
54#include "AliStack.h"
7fba1747 55#include "AliHeader.h"
88cb7938 56#include "AliEMCALLoader.h"
5d12ce38 57#include "AliMC.h"
ffa6d63b 58
59ClassImp(AliEMCALGetter)
88cb7938 60
61AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ;
62AliEMCALLoader * AliEMCALGetter::fgEmcalLoader = 0;
63Int_t AliEMCALGetter::fgDebug = 0;
173558f2 64
88cb7938 65// TFile * AliEMCALGetter::fgFile = 0 ;
ffa6d63b 66
67//____________________________________________________________________________
88cb7938 68AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* version, Option_t * openingOption)
ffa6d63b 69{
88cb7938 70 // ctor only called by Instance()
ffa6d63b 71
88cb7938 72 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
73 if (!rl) {
74 rl = AliRunLoader::Open(headerFile, version, openingOption);
75 if (!rl) {
76 Fatal("AliEMCALGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
77 return ;
78 }
79 if (rl->GetAliRun() == 0x0) {
80 rl->LoadgAlice();
81 gAlice = rl->GetAliRun(); // should be removed
ba298680 82 }
ffa6d63b 83 }
88cb7938 84 fgEmcalLoader = dynamic_cast<AliEMCALLoader*>(rl->GetLoader("EMCALLoader"));
85 if ( !fgEmcalLoader )
86 Error("AliEMCALGetter", "Could not find EMCALLoader") ;
87 else
88 fgEmcalLoader->SetTitle(version);
89
90
91 // initialize data members
92 SetDebug(0) ;
93 //fBTE = 0 ;
94 fPrimaries = 0 ;
95 fLoadingStatus = "" ;
ffa6d63b 96}
05a92d59 97
ffa6d63b 98//____________________________________________________________________________
ba298680 99AliEMCALGetter::~AliEMCALGetter()
100{
88cb7938 101 // dtor
102 delete fgEmcalLoader ;
103 fgEmcalLoader = 0 ;
104 //delete fBTE ;
105 // fBTE = 0 ;
106 fPrimaries->Delete() ;
107 delete fPrimaries ;
0ef40383 108 fgObjGetter = 0;
109}
110
111//____________________________________________________________________________
112void AliEMCALGetter::Reset()
113{
114 // resets things in case the getter is called consecutively with different files
115 // the EMCAL Loader is already deleted by the Run Loader
116
117 if (fPrimaries) {
118 fPrimaries->Delete() ;
119 delete fPrimaries ;
120 }
121 fgEmcalLoader = 0;
122 fgObjGetter = 0;
65549808 123}
124
125//____________________________________________________________________________
88cb7938 126AliEMCALClusterizer * AliEMCALGetter::Clusterizer()
127{
1ce25ac8 128 // return pointer to Clusterizer Tree
88cb7938 129 AliEMCALClusterizer * rv ;
130 rv = dynamic_cast<AliEMCALClusterizer *>(EmcalLoader()->Reconstructioner()) ;
131 if (!rv) {
132 Event(0, "R") ;
133 rv = dynamic_cast<AliEMCALClusterizer*>(EmcalLoader()->Reconstructioner()) ;
0c87da39 134 }
88cb7938 135 return rv ;
0c87da39 136}
05a92d59 137
ffa6d63b 138
139//____________________________________________________________________________
1ce25ac8 140TClonesArray * AliEMCALGetter::Digits() const
ffa6d63b 141{
88cb7938 142 // asks the Loader to return the Digits container
173558f2 143
88cb7938 144 TClonesArray * rv = 0 ;
145 rv = EmcalLoader()->Digits() ;
173558f2 146
88cb7938 147 if( !rv ) {
148 EmcalLoader()->MakeDigitsArray() ;
149 rv = EmcalLoader()->Digits() ;
05a92d59 150 }
88cb7938 151 return rv ;
05a92d59 152}
6c58180f 153
05a92d59 154//____________________________________________________________________________
88cb7938 155AliEMCALDigitizer * AliEMCALGetter::Digitizer()
156{
1ce25ac8 157 // return pointer to Digitizer Tree
88cb7938 158 AliEMCALDigitizer * rv ;
159 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
160 if (!rv) {
161 Event(0, "D") ;
162 rv = dynamic_cast<AliEMCALDigitizer *>(EmcalLoader()->Digitizer()) ;
48f12df6 163 }
88cb7938 164 return rv ;
05a92d59 165}
166
ffa6d63b 167//____________________________________________________________________________
1ce25ac8 168TObjArray * AliEMCALGetter::ECARecPoints() const
05a92d59 169{
88cb7938 170 // asks the Loader to return the EMC RecPoints container
171
172 TObjArray * rv = 0 ;
173
174 rv = EmcalLoader()->ECARecPoints() ;
175 if (!rv) {
176 EmcalLoader()->MakeRecPointsArray() ;
177 rv = EmcalLoader()->ECARecPoints() ;
178 }
179 return rv ;
05a92d59 180}
181
182//____________________________________________________________________________
1ce25ac8 183TClonesArray * AliEMCALGetter::TrackSegments() const
ffa6d63b 184{
88cb7938 185 // asks the Loader to return the TrackSegments container
ffa6d63b 186
88cb7938 187 TClonesArray * rv = 0 ;
188
189 rv = EmcalLoader()->TrackSegments() ;
190 if (!rv) {
191 EmcalLoader()->MakeTrackSegmentsArray() ;
192 rv = EmcalLoader()->TrackSegments() ;
193 }
ffa6d63b 194 return rv ;
88cb7938 195}
9bd3caba 196
197//____________________________________________________________________________
88cb7938 198AliEMCALTrackSegmentMaker * AliEMCALGetter::TrackSegmentMaker()
199{
1ce25ac8 200 // return pointer to TrackSegmentMaker Tree
88cb7938 201 AliEMCALTrackSegmentMaker * rv ;
202 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
203 if (!rv) {
204 Event(0, "T") ;
205 rv = dynamic_cast<AliEMCALTrackSegmentMaker *>(EmcalLoader()->TrackSegmentMaker()) ;
9bd3caba 206 }
88cb7938 207 return rv ;
9bd3caba 208}
209
210//____________________________________________________________________________
1ce25ac8 211TClonesArray * AliEMCALGetter::RecParticles() const
88cb7938 212{
213 // asks the Loader to return the TrackSegments container
173558f2 214
88cb7938 215 TClonesArray * rv = 0 ;
216
217 rv = EmcalLoader()->RecParticles() ;
218 if (!rv) {
219 EmcalLoader()->MakeRecParticlesArray() ;
220 rv = EmcalLoader()->RecParticles() ;
ffa6d63b 221 }
88cb7938 222 return rv ;
ffa6d63b 223}
ffa6d63b 224//____________________________________________________________________________
09884213 225void AliEMCALGetter::Event(Int_t event, const char* opt)
88cb7938 226{
227 // Reads the content of all Tree's S, D and R
173558f2 228
88cb7938 229 if ( event >= MaxEvent() ) {
230 Error("Event", "%d not found in TreeE !", event) ;
231 return ;
ffa6d63b 232 }
173558f2 233
88cb7938 234 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
88cb7938 235 // checks if we are dealing with test-beam data
236// TBranch * btb = rl->TreeE()->GetBranch("AliEMCALBeamTestEvent") ;
237// if(btb){
238// if(!fBTE)
239// fBTE = new AliEMCALBeamTestEvent() ;
240// btb->SetAddress(&fBTE) ;
241// btb->GetEntry(event) ;
242// }
243// else{
244// if(fBTE){
245// delete fBTE ;
246// fBTE = 0 ;
247// }
248// }
ffa6d63b 249
88cb7938 250 // Loads the type of object(s) requested
251
252 rl->GetEvent(event) ;
173558f2 253
88cb7938 254 if( strstr(opt,"X") || (strcmp(opt,"")==0) )
255 ReadPrimaries() ;
173558f2 256
88cb7938 257 if(strstr(opt,"H") )
258 ReadTreeH();
ffa6d63b 259
88cb7938 260 if(strstr(opt,"S") )
261 ReadTreeS() ;
173558f2 262
88cb7938 263 if( strstr(opt,"D") )
264 ReadTreeD() ;
173558f2 265
88cb7938 266 if( strstr(opt,"R") )
267 ReadTreeR() ;
ffa6d63b 268
88cb7938 269 if( strstr(opt,"T") )
270 ReadTreeT() ;
173558f2 271
88cb7938 272 if( strstr(opt,"P") )
273 ReadTreeP() ;
88cb7938 274
ffa6d63b 275}
276
ffa6d63b 277
278//____________________________________________________________________________
88cb7938 279Int_t AliEMCALGetter::EventNumber() const
280 {
281 // return the current event number
282 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
283 return static_cast<Int_t>(rl->GetEventNumber()) ;
ffa6d63b 284}
285
286//____________________________________________________________________________
1ce25ac8 287 TClonesArray * AliEMCALGetter::Hits() const
88cb7938 288{
289 // asks the loader to return the Hits container
290
291 TClonesArray * rv = 0 ;
292
293 rv = EmcalLoader()->Hits() ;
294 if ( !rv ) {
295 EmcalLoader()->LoadHits("read");
296 rv = EmcalLoader()->Hits() ;
ffa6d63b 297 }
88cb7938 298 return rv ;
ffa6d63b 299}
300
301//____________________________________________________________________________
88cb7938 302AliEMCALGetter * AliEMCALGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
303{
304 // Creates and returns the pointer of the unique instance
305 // Must be called only when the environment has changed
306
88cb7938 307 if(!fgObjGetter){ // first time the getter is called
308 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
309 }
310 else { // the getter has been called previously
311 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
312 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
313 // check if the file is already open
314 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
315
316 if ( !galiceFile )
317 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
318
319 else { // the file is already open check the version name
320 TString currentVersionName = rl->GetEventFolder()->GetName() ;
321 TString newVersionName(version) ;
322 if (currentVersionName == newVersionName)
323 if(fgDebug)
324 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
325 else {
326 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
327 }
328 }
d75bea67 329 }
7fba1747 330 else {
331 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
1c221c70 332 if ( strstr(version, AliConfig::fgkDefaultEventFolderName) ) // false in case of merging
333 delete rl ;
88cb7938 334 fgObjGetter = new AliEMCALGetter(alirunFileName, version, openingOption) ;
7fba1747 335 }
ffa6d63b 336 }
88cb7938 337 if (!fgObjGetter)
9e5dd82c 338 ::Error("AliEMCALGetter::Instance", "Failed to create the EMCAL Getter object") ;
88cb7938 339 else
340 if (fgDebug)
341 Print() ;
342
343 return fgObjGetter ;
ffa6d63b 344}
345
346//____________________________________________________________________________
88cb7938 347AliEMCALGetter * AliEMCALGetter::Instance()
348{
349 // Returns the pointer of the unique instance already defined
350
9e5dd82c 351 if(!fgObjGetter && fgDebug)
352 ::Warning("AliEMCALGetter::Instance", "Getter not initialized") ;
173558f2 353
88cb7938 354 return fgObjGetter ;
355
ffa6d63b 356}
357
358//____________________________________________________________________________
88cb7938 359Int_t AliEMCALGetter::MaxEvent() const
360{
361 // returns the number of events in the run (from TE)
173558f2 362
88cb7938 363 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
364 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
365}
ffa6d63b 366
367//____________________________________________________________________________
88cb7938 368TParticle * AliEMCALGetter::Primary(Int_t index) const
369{
370 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
371 return rl->Stack()->Particle(index) ;
ffa6d63b 372}
373
ffa6d63b 374//____________________________________________________________________________
88cb7938 375AliEMCAL * AliEMCALGetter:: EMCAL() const
376{
377 // returns the EMCAL object
378 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(EmcalLoader()->GetModulesFolder()->FindObject("EMCAL")) ;
379 if (!emcal)
380 if (fgDebug)
381 Warning("EMCAL", "EMCAL module not found in module folders: %s", EmcalLoader()->GetModulesFolder()->GetName() ) ;
382 return emcal ;
383}
173558f2 384
ffa6d63b 385
173558f2 386
ffa6d63b 387//____________________________________________________________________________
88cb7938 388AliEMCALPID * AliEMCALGetter::PID()
9859bfc0 389{
1ce25ac8 390 // return pointer to PID Tree
88cb7938 391 AliEMCALPID * rv ;
392 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
393 if (!rv) {
394 Event(0, "P") ;
395 rv = dynamic_cast<AliEMCALPID *>(EmcalLoader()->PIDTask()) ;
d75bea67 396 }
88cb7938 397 return rv ;
d75bea67 398}
399
400//____________________________________________________________________________
88cb7938 401AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() const
402{
403 // Returns EMCAL geometry
173558f2 404
88cb7938 405 AliEMCALGeometry * rv = 0 ;
406 if (EMCAL() )
407 rv = EMCAL()->GetGeometry() ;
408 return rv ;
d75bea67 409}
410
411//____________________________________________________________________________
88cb7938 412TClonesArray * AliEMCALGetter::Primaries()
413{
414 // creates the Primaries container if needed
415 if ( !fPrimaries ) {
416 if (fgDebug)
b7de6a56 417 Info("Primaries", "Creating a new TClonesArray for primaries") ;
88cb7938 418 fPrimaries = new TClonesArray("TParticle", 1000) ;
d75bea67 419 }
88cb7938 420 return fPrimaries ;
d75bea67 421}
422
423//____________________________________________________________________________
88cb7938 424void AliEMCALGetter::Print()
425{
426 // Print usefull information about the getter
427
428 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgEmcalLoader->GetTitle());
b7de6a56 429 ::Info("Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
d75bea67 430}
431
05a92d59 432//____________________________________________________________________________
88cb7938 433void AliEMCALGetter::ReadPrimaries()
434{
435 // Read Primaries from Kinematics.root
516fff8e 436
88cb7938 437 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
516fff8e 438
88cb7938 439 // gets kine tree from the root file (Kinematics.root)
440 if ( ! rl->TreeK() ) // load treeK the first time
441 rl->LoadKinematics() ;
516fff8e 442
7fba1747 443 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 444 if (fgDebug)
b7de6a56 445 Info("ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
516fff8e 446
88cb7938 447 // first time creates the container
448 if ( Primaries() )
449 fPrimaries->Clear() ;
516fff8e 450
88cb7938 451 Int_t index = 0 ;
452 for (index = 0 ; index < fNPrimaries; index++) {
453 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
516fff8e 454 }
88cb7938 455}
516fff8e 456
516fff8e 457//____________________________________________________________________________
88cb7938 458Int_t AliEMCALGetter::ReadTreeD()
459{
460 // Read the Digits
516fff8e 461
516fff8e 462
88cb7938 463 // gets TreeD from the root file (EMCAL.SDigits.root)
464 if ( !IsLoaded("D") ) {
465 EmcalLoader()->LoadDigits("UPDATE") ;
466 EmcalLoader()->LoadDigitizer("UPDATE") ;
467 SetLoaded("D") ;
516fff8e 468 }
88cb7938 469 return Digits()->GetEntries() ;
470}
516fff8e 471
472//____________________________________________________________________________
88cb7938 473Int_t AliEMCALGetter::ReadTreeH()
474{
475 // Read the Hits
476
477 // gets TreeH from the root file (EMCAL.Hit.root)
478 if ( !IsLoaded("H") ) {
bf49006a 479 EmcalLoader()->LoadHits("READ") ;
88cb7938 480 SetLoaded("H") ;
481 }
482 return Hits()->GetEntries() ;
483}
516fff8e 484
485//____________________________________________________________________________
88cb7938 486Int_t AliEMCALGetter::ReadTreeR()
487{
488 // Read the RecPoints
516fff8e 489
516fff8e 490
88cb7938 491 // gets TreeR from the root file (EMCAL.RecPoints.root)
492 if ( !IsLoaded("R") ) {
493 EmcalLoader()->LoadRecPoints("UPDATE") ;
494 EmcalLoader()->LoadClusterizer("UPDATE") ;
495 SetLoaded("R") ;
516fff8e 496 }
516fff8e 497
88cb7938 498 return ECARecPoints()->GetEntries() ;
516fff8e 499}
500
501//____________________________________________________________________________
88cb7938 502Int_t AliEMCALGetter::ReadTreeT()
503{
504 // Read the TrackSegments
eddd30d1 505
eddd30d1 506
88cb7938 507 // gets TreeT from the root file (EMCAL.TrackSegments.root)
508 if ( !IsLoaded("T") ) {
509 EmcalLoader()->LoadTracks("UPDATE") ;
510 EmcalLoader()->LoadTrackSegmentMaker("UPDATE") ;
511 SetLoaded("T") ;
eddd30d1 512 }
eddd30d1 513
88cb7938 514 return TrackSegments()->GetEntries() ;
515}
eddd30d1 516//____________________________________________________________________________
88cb7938 517Int_t AliEMCALGetter::ReadTreeP()
518{
519 // Read the TrackSegments
eddd30d1 520
eddd30d1 521
88cb7938 522 // gets TreeT from the root file (EMCAL.TrackSegments.root)
523 if ( !IsLoaded("P") ) {
524 EmcalLoader()->LoadRecParticles("UPDATE") ;
525 EmcalLoader()->LoadPID("UPDATE") ;
526 SetLoaded("P") ;
eddd30d1 527 }
eddd30d1 528
88cb7938 529 return RecParticles()->GetEntries() ;
530}
eddd30d1 531//____________________________________________________________________________
88cb7938 532Int_t AliEMCALGetter::ReadTreeS()
05a92d59 533{
88cb7938 534 // Read the SDigits
535
47dfe516 536
88cb7938 537 // gets TreeS from the root file (EMCAL.SDigits.root)
1c221c70 538 if ( !IsLoaded("S") ) {
bf49006a 539 EmcalLoader()->LoadSDigits("READ") ;
540 EmcalLoader()->LoadSDigitizer("READ") ;
88cb7938 541 SetLoaded("S") ;
47dfe516 542 }
173558f2 543
88cb7938 544 return SDigits()->GetEntries() ;
05a92d59 545}
546
547//____________________________________________________________________________
1ce25ac8 548TClonesArray * AliEMCALGetter::SDigits() const
05a92d59 549{
88cb7938 550 // asks the Loader to return the Digits container
173558f2 551
88cb7938 552 TClonesArray * rv = 0 ;
553
554 rv = EmcalLoader()->SDigits() ;
555 if (!rv) {
556 EmcalLoader()->MakeSDigitsArray() ;
557 rv = EmcalLoader()->SDigits() ;
05a92d59 558 }
88cb7938 559 return rv ;
05a92d59 560}
561
562//____________________________________________________________________________
88cb7938 563AliEMCALSDigitizer * AliEMCALGetter::SDigitizer()
564{
b7de6a56 565 // Return pointer to SDigitizer task
88cb7938 566 AliEMCALSDigitizer * rv ;
567 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
568 if (!rv) {
569 Event(0, "S") ;
570 rv = dynamic_cast<AliEMCALSDigitizer *>(EmcalLoader()->SDigitizer()) ;
05a92d59 571 }
88cb7938 572 return rv ;
ffa6d63b 573}
574
575//____________________________________________________________________________
09884213 576TParticle * AliEMCALGetter::Secondary(const TParticle* p, Int_t index) const
ffa6d63b 577{
05a92d59 578 // Return first (index=1) or second (index=2) secondary particle of primary particle p
579
580 if(index <= 0)
581 return 0 ;
582 if(index > 2)
583 return 0 ;
584
585 if(p) {
88cb7938 586 Int_t daughterIndex = p->GetDaughter(index-1) ;
587 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
5d12ce38 588 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
05a92d59 589 }
590 else
591 return 0 ;
592}
9bd3caba 593
05a92d59 594//____________________________________________________________________________
09884213 595void AliEMCALGetter::Track(Int_t itrack)
ffa6d63b 596{
597 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
88cb7938 598
599 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
173558f2 600
88cb7938 601 if( !TreeH() ) // load treeH the first time
602 rl->LoadHits() ;
173558f2 603
88cb7938 604 // first time create the container
605 TClonesArray * hits = Hits() ;
606 if ( hits )
607 hits->Clear() ;
05a92d59 608
88cb7938 609 TBranch * emcalbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("EMCAL")) ;
610 emcalbranch->SetAddress(&hits) ;
611 emcalbranch->GetEntry(itrack) ;
ffa6d63b 612}
9bd3caba 613
9bd3caba 614//____________________________________________________________________________
88cb7938 615TTree * AliEMCALGetter::TreeD() const
9bd3caba 616{
1ce25ac8 617 // return pointer to Digits Tree
88cb7938 618 TTree * rv = 0 ;
619 rv = EmcalLoader()->TreeD() ;
620 if ( !rv ) {
621 EmcalLoader()->MakeTree("D");
622 rv = EmcalLoader()->TreeD() ;
9859bfc0 623 }
516fff8e 624
88cb7938 625 return rv ;
d75bea67 626}
f07cab21 627
d75bea67 628//____________________________________________________________________________
88cb7938 629TTree * AliEMCALGetter::TreeH() const
ffa6d63b 630{
1ce25ac8 631 // return pointer to Hits Tree
88cb7938 632 TTree * rv = 0 ;
633 rv = EmcalLoader()->TreeH() ;
634 if ( !rv ) {
635 EmcalLoader()->MakeTree("H");
636 rv = EmcalLoader()->TreeH() ;
ffa6d63b 637 }
88cb7938 638
639 return rv ;
ffa6d63b 640}
641
642//____________________________________________________________________________
88cb7938 643TTree * AliEMCALGetter::TreeR() const
ffa6d63b 644{
1ce25ac8 645 // return pointer to RecPoints Tree
646
88cb7938 647 TTree * rv = 0 ;
648 rv = EmcalLoader()->TreeR() ;
649 if ( !rv ) {
650 EmcalLoader()->MakeTree("R");
651 rv = EmcalLoader()->TreeR() ;
652 }
653
654 return rv ;
ffa6d63b 655}
173558f2 656
ffa6d63b 657//____________________________________________________________________________
88cb7938 658TTree * AliEMCALGetter::TreeT() const
1ce25ac8 659{
660 // return pointer to TrackSegments Tree
88cb7938 661 TTree * rv = 0 ;
662 rv = EmcalLoader()->TreeT() ;
663 if ( !rv ) {
664 EmcalLoader()->MakeTree("T");
665 rv = EmcalLoader()->TreeT() ;
666 }
516fff8e 667
88cb7938 668 return rv ;
ffa6d63b 669}
65549808 670//____________________________________________________________________________
88cb7938 671TTree * AliEMCALGetter::TreeP() const
65549808 672{
1ce25ac8 673 // return pointer to RecParticles Tree
88cb7938 674 TTree * rv = 0 ;
675 rv = EmcalLoader()->TreeP() ;
676 if ( !rv ) {
677 EmcalLoader()->MakeTree("P");
678 rv = EmcalLoader()->TreeP() ;
05a92d59 679 }
88cb7938 680
681 return rv ;
65549808 682}
173558f2 683
65549808 684//____________________________________________________________________________
88cb7938 685TTree * AliEMCALGetter::TreeS() const
65549808 686{
1ce25ac8 687 // return pointer to SDigits Tree
88cb7938 688 TTree * rv = 0 ;
689 rv = EmcalLoader()->TreeS() ;
690 if ( !rv ) {
691 EmcalLoader()->MakeTree("S");
692 rv = EmcalLoader()->TreeS() ;
693 }
694
695 return rv ;
65549808 696}
697
698//____________________________________________________________________________
88cb7938 699Bool_t AliEMCALGetter::VersionExists(TString & opt) const
65549808 700{
88cb7938 701 // checks if the version with the present name already exists in the same directory
173558f2 702
88cb7938 703 Bool_t rv = kFALSE ;
704
705 AliRunLoader * rl = AliRunLoader::GetRunLoader(EmcalLoader()->GetTitle());
706 TString version( rl->GetEventFolder()->GetName() ) ;
173558f2 707
88cb7938 708 opt.ToLower() ;
709
710 if ( opt == "sdigits") {
711 // add the version name to the root file name
712 TString fileName( EmcalLoader()->GetSDigitsFileName() ) ;
713 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
714 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
715 if ( !(gSystem->AccessPathName(fileName)) ) {
716 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
717 rv = kTRUE ;
05a92d59 718 }
88cb7938 719 EmcalLoader()->SetSDigitsFileName(fileName) ;
05a92d59 720 }
173558f2 721
88cb7938 722 if ( opt == "digits") {
723 // add the version name to the root file name
724 TString fileName( EmcalLoader()->GetDigitsFileName() ) ;
725 if (version != AliConfig::fgkDefaultEventFolderName) // only if not the default folder name
726 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
727 if ( !(gSystem->AccessPathName(fileName)) ) {
728 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
729 rv = kTRUE ;
05a92d59 730 }
731 }
732
88cb7938 733 return rv ;
173558f2 734
05a92d59 735}
173558f2 736
05a92d59 737//____________________________________________________________________________
88cb7938 738UShort_t AliEMCALGetter::EventPattern(void) const
05a92d59 739{
88cb7938 740 // Return the pattern (trigger bit register) of the beam-test event
741// if(fBTE)
742// return fBTE->GetPattern() ;
743// else
744 return 0 ;
05a92d59 745}
746//____________________________________________________________________________
88cb7938 747Float_t AliEMCALGetter::BeamEnergy(void) const
748{
749 // Return the beam energy of the beam-test event
750// if(fBTE)
751// return fBTE->GetBeamEnergy() ;
752// else
753 return 0 ;
9859bfc0 754}