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