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