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