Changes needed to run simulation and reconstrruction in the same AliRoot session
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
CommitLineData
4ae78bb1 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$ */
4ae78bb1 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
22// ensures, that one reads Digits, made of these particular digits, RecPoints,
23// made of these particular RecPoints, TrackSegments and RecParticles.
24// This becomes non trivial if there are several identical branches, produced with
25// different set of parameters.
26//
27// An example of how to use (see also class AliPHOSAnalyser):
28// AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
29// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
30// AliPHOSRecParticle * part = gime->RecParticle(1) ;
31// ................
2a657981 32// gime->Event(event) ; // reads new event from galice.root
4ae78bb1 33//
2a657981 34//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35//*-- Completely redesigned by Dmitri Peressounko March 2001
4ae78bb1 36//
37//*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
38//*-- systematic usage of TFolders without changing the interface
39//////////////////////////////////////////////////////////////////////////////
40
4ae78bb1 41// --- ROOT system ---
88cb7938 42
d7b234dd 43#include <TFile.h>
44#include <TROOT.h>
45#include <TSystem.h>
46#include <TParticle.h>
a43c51c3 47#include <TF1.h>
e4d04cf1 48#include <TGraph.h>
ff808dc7 49//#include <TCanvas.h>
351dd634 50//#include <TFrame.h>
4ae78bb1 51
52// --- Standard library ---
4ae78bb1 53
54// --- AliRoot header files ---
024a7e64 55#include "AliESD.h"
56#include "AliHeader.h"
57#include "AliMC.h"
e957fea8 58#include "AliPHOS.h"
024a7e64 59#include "AliPHOSBeamTestEvent.h"
60#include "AliPHOSGetter.h"
61#include "AliPHOSLoader.h"
88cb7938 62#include "AliRunLoader.h"
63#include "AliStack.h"
a43c51c3 64#include "AliPHOSRawStream.h"
65#include "AliRawReaderFile.h"
e4d04cf1 66#include "AliLog.h"
88cb7938 67
4ae78bb1 68ClassImp(AliPHOSGetter)
69
88cb7938 70AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
71AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
72Int_t AliPHOSGetter::fgDebug = 0;
73
74// TFile * AliPHOSGetter::fgFile = 0 ;
4ae78bb1 75
76//____________________________________________________________________________
88cb7938 77AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
4ae78bb1 78{
88cb7938 79 // ctor only called by Instance()
4ae78bb1 80
88cb7938 81 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
82 if (!rl) {
83 rl = AliRunLoader::Open(headerFile, version, openingOption);
84 if (!rl) {
85 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
86 return ;
87 }
88 if (rl->GetAliRun() == 0x0) {
89 rl->LoadgAlice();
90 gAlice = rl->GetAliRun(); // should be removed
91 }
fbf811ec 92 }
88cb7938 93 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
94 if ( !fgPhosLoader )
95 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
96 else
97 fgPhosLoader->SetTitle(version);
98
88cb7938 99 // initialize data members
100 SetDebug(0) ;
101 fBTE = 0 ;
102 fPrimaries = 0 ;
103 fLoadingStatus = "" ;
d2713783 104
105 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
106 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
95635748 107 fESDFile = 0 ;
677c8a30 108 fESD = 0 ;
109 fESDTree = 0 ;
66f895c8 110 fRawDigits = kFALSE ;
88cb7938 111}
9bd3caba 112
88cb7938 113//____________________________________________________________________________
114AliPHOSGetter::~AliPHOSGetter()
115{
116 // dtor
66f895c8 117 if(fgPhosLoader){
118 delete fgPhosLoader ;
119 fgPhosLoader = 0 ;
120 }
121 if(fBTE){
122 delete fBTE ;
123 fBTE = 0 ;
124 }
125 if(fPrimaries){
126 fPrimaries->Delete() ;
127 delete fPrimaries ;
128 }
677c8a30 129 if (fESD)
130 delete fESD ;
131 if (fESDTree)
66f895c8 132 delete fESDTree ;
133
7c193632 134 fgObjGetter = 0;
0ef40383 135}
136
137//____________________________________________________________________________
138void AliPHOSGetter::Reset()
139{
140 // resets things in case the getter is called consecutively with different files
141 // the PHOS Loader is already deleted by the Run Loader
142
143 if (fPrimaries) {
144 fPrimaries->Delete() ;
145 delete fPrimaries ;
146 }
147 fgPhosLoader = 0;
148 fgObjGetter = 0;
88cb7938 149}
fbf811ec 150
88cb7938 151//____________________________________________________________________________
152AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
153{
e957fea8 154 // Returns pointer to the Clusterizer task
88cb7938 155 AliPHOSClusterizer * rv ;
156 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
157 if (!rv) {
158 Event(0, "R") ;
159 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
160 }
161 return rv ;
162}
4ae78bb1 163
88cb7938 164//____________________________________________________________________________
165TObjArray * AliPHOSGetter::CpvRecPoints()
166{
167 // asks the Loader to return the CPV RecPoints container
4ae78bb1 168
88cb7938 169 TObjArray * rv = 0 ;
170
171 rv = PhosLoader()->CpvRecPoints() ;
172 if (!rv) {
173 PhosLoader()->MakeRecPointsArray() ;
174 rv = PhosLoader()->CpvRecPoints() ;
175 }
176 return rv ;
177}
dca3a7c4 178
88cb7938 179//____________________________________________________________________________
180TClonesArray * AliPHOSGetter::Digits()
181{
182 // asks the Loader to return the Digits container
7bb289a7 183
88cb7938 184 TClonesArray * rv = 0 ;
185 rv = PhosLoader()->Digits() ;
7bb289a7 186
88cb7938 187 if( !rv ) {
188 PhosLoader()->MakeDigitsArray() ;
189 rv = PhosLoader()->Digits() ;
4ae78bb1 190 }
88cb7938 191 return rv ;
192}
4b808d52 193
88cb7938 194//____________________________________________________________________________
195AliPHOSDigitizer * AliPHOSGetter::Digitizer()
196{
e957fea8 197 // Returns pointer to the Digitizer task
88cb7938 198 AliPHOSDigitizer * rv ;
199 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
200 if (!rv) {
201 Event(0, "D") ;
202 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
203 }
204 return rv ;
4ae78bb1 205}
fbf811ec 206
88cb7938 207
4ae78bb1 208//____________________________________________________________________________
88cb7938 209TObjArray * AliPHOSGetter::EmcRecPoints()
0bc3b8ed 210{
88cb7938 211 // asks the Loader to return the EMC RecPoints container
d489fb96 212
88cb7938 213 TObjArray * rv = 0 ;
65549808 214
88cb7938 215 rv = PhosLoader()->EmcRecPoints() ;
216 if (!rv) {
217 PhosLoader()->MakeRecPointsArray() ;
218 rv = PhosLoader()->EmcRecPoints() ;
89165262 219 }
88cb7938 220 return rv ;
81bb1a45 221}
7a9d98f9 222
65549808 223//____________________________________________________________________________
88cb7938 224TClonesArray * AliPHOSGetter::TrackSegments()
65549808 225{
88cb7938 226 // asks the Loader to return the TrackSegments container
227
228 TClonesArray * rv = 0 ;
229
230 rv = PhosLoader()->TrackSegments() ;
231 if (!rv) {
232 PhosLoader()->MakeTrackSegmentsArray() ;
233 rv = PhosLoader()->TrackSegments() ;
234 }
235 return rv ;
65549808 236}
4ae78bb1 237
0c87da39 238//____________________________________________________________________________
e957fea8 239AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
88cb7938 240{
e957fea8 241 // Returns pointer to the TrackSegmentMaker task
88cb7938 242 AliPHOSTrackSegmentMaker * rv ;
243 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
244 if (!rv) {
245 Event(0, "T") ;
246 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
0c87da39 247 }
88cb7938 248 return rv ;
0c87da39 249}
250
4ae78bb1 251//____________________________________________________________________________
88cb7938 252TClonesArray * AliPHOSGetter::RecParticles()
4ae78bb1 253{
88cb7938 254 // asks the Loader to return the TrackSegments container
255
256 TClonesArray * rv = 0 ;
4ae78bb1 257
88cb7938 258 rv = PhosLoader()->RecParticles() ;
259 if (!rv) {
260 PhosLoader()->MakeRecParticlesArray() ;
261 rv = PhosLoader()->RecParticles() ;
b134c32f 262 }
88cb7938 263 return rv ;
4ae78bb1 264}
4ae78bb1 265//____________________________________________________________________________
fc7e2f43 266void AliPHOSGetter::Event(Int_t event, const char* opt)
4ae78bb1 267{
88cb7938 268 // Reads the content of all Tree's S, D and R
548f0134 269
66f895c8 270// if ( event >= MaxEvent() ) {
271// Error("Event", "%d not found in TreeE !", event) ;
272// return ;
273// }
4ae78bb1 274
88cb7938 275 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
df25f7dd 276
66f895c8 277// // checks if we are dealing with test-beam data
278// TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
279// if(btb){
280// if(!fBTE)
281// fBTE = new AliPHOSBeamTestEvent() ;
282// btb->SetAddress(&fBTE) ;
283// btb->GetEntry(event) ;
284// }
285// else{
286// if(fBTE){
287// delete fBTE ;
288// fBTE = 0 ;
289// }
290// }
88cb7938 291
292 // Loads the type of object(s) requested
b134c32f 293
88cb7938 294 rl->GetEvent(event) ;
295
66f895c8 296 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
88cb7938 297 ReadPrimaries() ;
66f895c8 298 }
299
300 if(strstr(opt,"H") ){
88cb7938 301 ReadTreeH();
66f895c8 302 }
303
304 if(strstr(opt,"S") ){
88cb7938 305 ReadTreeS() ;
66f895c8 306 }
307
308 if(strstr(opt,"D") ){
88cb7938 309 ReadTreeD() ;
66f895c8 310 }
311
312 if(strstr(opt,"R") ){
88cb7938 313 ReadTreeR() ;
66f895c8 314 }
88cb7938 315
66f895c8 316 if( strstr(opt,"T") ){
88cb7938 317 ReadTreeT() ;
66f895c8 318 }
88cb7938 319
66f895c8 320 if( strstr(opt,"P") ){
88cb7938 321 ReadTreeP() ;
66f895c8 322 }
677c8a30 323
66f895c8 324 if( strstr(opt,"E") ){
677c8a30 325 ReadTreeE(event) ;
66f895c8 326 }
a43c51c3 327
66f895c8 328if( strstr(opt,"W") ){
a43c51c3 329 ReadRaw(event) ;
66f895c8 330 }
95635748 331
88cb7938 332}
333
334
335//____________________________________________________________________________
336Int_t AliPHOSGetter::EventNumber() const
337 {
338 // return the current event number
339 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
340 return static_cast<Int_t>(rl->GetEventNumber()) ;
fbf811ec 341}
d489fb96 342
fbf811ec 343//____________________________________________________________________________
88cb7938 344 TClonesArray * AliPHOSGetter::Hits()
fbf811ec 345{
88cb7938 346 // asks the loader to return the Hits container
347
348 TClonesArray * rv = 0 ;
349
350 rv = PhosLoader()->Hits() ;
351 if ( !rv ) {
352 PhosLoader()->LoadHits("read");
353 rv = PhosLoader()->Hits() ;
fbf811ec 354 }
88cb7938 355 return rv ;
356}
fbf811ec 357
88cb7938 358//____________________________________________________________________________
359AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
360{
361 // Creates and returns the pointer of the unique instance
362 // Must be called only when the environment has changed
d489fb96 363
88cb7938 364 if(!fgObjGetter){ // first time the getter is called
365 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
fbf811ec 366 }
88cb7938 367 else { // the getter has been called previously
368 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
369 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
370 // check if the file is already open
371 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
372
373 if ( !galiceFile )
374 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
375
376 else { // the file is already open check the version name
377 TString currentVersionName = rl->GetEventFolder()->GetName() ;
378 TString newVersionName(version) ;
379 if (currentVersionName == newVersionName)
380 if(fgDebug)
381 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
382 else {
383 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
384 }
385 }
386 }
7fba1747 387 else {
388 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
e191bb57 389 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
1c221c70 390 delete rl ;
88cb7938 391 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
7fba1747 392 }
48f12df6 393 }
88cb7938 394 if (!fgObjGetter)
95635748 395 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
88cb7938 396 else
397 if (fgDebug)
398 Print() ;
4ae78bb1 399
88cb7938 400 return fgObjGetter ;
4ae78bb1 401}
402
6ad0e528 403//____________________________________________________________________________
88cb7938 404AliPHOSGetter * AliPHOSGetter::Instance()
6ad0e528 405{
88cb7938 406 // Returns the pointer of the unique instance already defined
fbf811ec 407
95635748 408 if(!fgObjGetter && fgDebug)
409 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
6ad0e528 410
88cb7938 411 return fgObjGetter ;
412
6ad0e528 413}
414
415//____________________________________________________________________________
88cb7938 416Int_t AliPHOSGetter::MaxEvent() const
6ad0e528 417{
88cb7938 418 // returns the number of events in the run (from TE)
0bc3b8ed 419
88cb7938 420 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
421 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
6ad0e528 422}
423
424//____________________________________________________________________________
88cb7938 425TParticle * AliPHOSGetter::Primary(Int_t index) const
6ad0e528 426{
88cb7938 427 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
428 return rl->Stack()->Particle(index) ;
429}
6ad0e528 430
4ae78bb1 431//____________________________________________________________________________
88cb7938 432AliPHOS * AliPHOSGetter:: PHOS() const
4ae78bb1 433{
434 // returns the PHOS object
5c4bcd63 435 AliPHOSLoader * loader = 0;
436 static AliPHOSLoader * oldloader = 0;
437 static AliPHOS * phos = 0;
438
439 loader = PhosLoader();
440
441 if ( loader != oldloader) {
442 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
443 oldloader = loader;
444 }
7a9d98f9 445 if (!phos)
88cb7938 446 if (fgDebug)
447 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
7a9d98f9 448 return phos ;
4ae78bb1 449}
450
88cb7938 451
452
453//____________________________________________________________________________
e957fea8 454AliPHOSPID * AliPHOSGetter::PID()
88cb7938 455{
e957fea8 456 // Returns pointer to the PID task
88cb7938 457 AliPHOSPID * rv ;
458 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
459 if (!rv) {
460 Event(0, "P") ;
461 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
462 }
463 return rv ;
464}
465
4ae78bb1 466//____________________________________________________________________________
88cb7938 467AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
4ae78bb1 468{
0bc3b8ed 469 // Returns PHOS geometry
470
7a9d98f9 471 AliPHOSGeometry * rv = 0 ;
472 if (PHOS() )
473 rv = PHOS()->GetGeometry() ;
474 return rv ;
475}
4ae78bb1 476
cb34a1fa 477//____________________________________________________________________________
88cb7938 478TClonesArray * AliPHOSGetter::Primaries()
479{
480 // creates the Primaries container if needed
481 if ( !fPrimaries ) {
482 if (fgDebug)
483 Info("Primaries", "Creating a new TClonesArray for primaries") ;
484 fPrimaries = new TClonesArray("TParticle", 1000) ;
485 }
486 return fPrimaries ;
487}
488
489//____________________________________________________________________________
490void AliPHOSGetter::Print()
491{
492 // Print usefull information about the getter
493
494 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
495 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
496}
cb34a1fa 497
88cb7938 498//____________________________________________________________________________
499void AliPHOSGetter::ReadPrimaries()
500{
501 // Read Primaries from Kinematics.root
cb34a1fa 502
88cb7938 503 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
cb34a1fa 504
88cb7938 505 // gets kine tree from the root file (Kinematics.root)
7fba1747 506 if ( ! rl->TreeK() ) { // load treeK the first time
88cb7938 507 rl->LoadKinematics() ;
7fba1747 508 }
88cb7938 509
7fba1747 510 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 511 if (fgDebug)
512 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
cb34a1fa 513
cb34a1fa 514
88cb7938 515 // first time creates the container
516 if ( Primaries() )
517 fPrimaries->Clear() ;
cb34a1fa 518
88cb7938 519 Int_t index = 0 ;
520 for (index = 0 ; index < fNPrimaries; index++) {
521 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
cb34a1fa 522 }
cb34a1fa 523}
524
95635748 525//____________________________________________________________________________
d2713783 526Bool_t AliPHOSGetter::OpenESDFile()
95635748 527{
d2713783 528 //Open the ESD file
95635748 529 Bool_t rv = kTRUE ;
d2713783 530 if (!fESDFile) {
531 fESDFile = TFile::Open(fESDFileName) ;
532 if (!fESDFile )
533 return kFALSE ;
534 }
95635748 535 else if (fESDFile->IsOpen()) {
536 fESDFile->Close() ;
537 fESDFile = TFile::Open(fESDFileName) ;
538 }
539 if (!fESDFile->IsOpen())
540 rv = kFALSE ;
541 return rv ;
542}
543
a43c51c3 544//____________________________________________________________________________
545Int_t AliPHOSGetter::ReadRaw(Int_t event)
546{
547 // reads the raw format data, converts it into digits format and store digits in Digits()
548 // container.
549
550 AliRawReaderFile rawReader(event) ;
551 AliPHOSRawStream in(&rawReader);
a43c51c3 552
553 TClonesArray * digits = Digits() ;
554 digits->Clear() ;
555 Int_t idigit = 0 ;
ff808dc7 556
a43c51c3 557 while ( in.Next() ) { // PHOS entries loop
66f895c8 558
559 Int_t amp = in.GetSignal() ;
560 Double_t time = in.GetTime() ;
561 Int_t relId[4], id ;
e4d04cf1 562
66f895c8 563 relId[0] = in.GetModule() ;
564 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
565 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
566 }
567 relId[1] = 0 ;
568 relId[2] = in.GetRow() ;
569 relId[3] = in.GetColumn() ;
570 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
571
572 if (amp > 0 && id >=0 ) {
573 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
574 idigit++ ;
575 }
576
a43c51c3 577 } // PHOS entries loop
66f895c8 578
ff808dc7 579 digits->Sort() ;
a43c51c3 580
e4d04cf1 581 return digits->GetEntriesFast() ;
a43c51c3 582}
b0bba0af 583//____________________________________________________________________________
88cb7938 584Int_t AliPHOSGetter::ReadTreeD()
585{
586 // Read the Digits
b0bba0af 587
41c29fde 588 PhosLoader()->CleanDigits() ;
ff808dc7 589 PhosLoader()->LoadDigits("UPDATE") ;
590 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 591 return Digits()->GetEntries() ;
592}
7a9d98f9 593
b0bba0af 594//____________________________________________________________________________
88cb7938 595Int_t AliPHOSGetter::ReadTreeH()
596{
597 // Read the Hits
41c29fde 598 PhosLoader()->CleanHits() ;
88cb7938 599 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 600 //if ( !IsLoaded("H") ) {
88cb7938 601 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 602 // SetLoaded("H") ;
603 //}
88cb7938 604 return Hits()->GetEntries() ;
605}
4ae78bb1 606
88cb7938 607//____________________________________________________________________________
608Int_t AliPHOSGetter::ReadTreeR()
609{
610 // Read the RecPoints
b0bba0af 611
41c29fde 612 PhosLoader()->CleanRecPoints() ;
88cb7938 613 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 614 //if ( !IsLoaded("R") ) {
88cb7938 615 PhosLoader()->LoadRecPoints("UPDATE") ;
616 PhosLoader()->LoadClusterizer("UPDATE") ;
41c29fde 617 // SetLoaded("R") ;
618 //}
f1611b7c 619
88cb7938 620 return EmcRecPoints()->GetEntries() ;
b0bba0af 621}
7a9d98f9 622
b0bba0af 623//____________________________________________________________________________
88cb7938 624Int_t AliPHOSGetter::ReadTreeT()
625{
626 // Read the TrackSegments
7a9d98f9 627
41c29fde 628 PhosLoader()->CleanTracks() ;
88cb7938 629 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 630 //if ( !IsLoaded("T") ) {
88cb7938 631 PhosLoader()->LoadTracks("UPDATE") ;
632 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 633 // SetLoaded("T") ;
634 //}
fbf811ec 635
88cb7938 636 return TrackSegments()->GetEntries() ;
637}
b0bba0af 638//____________________________________________________________________________
88cb7938 639Int_t AliPHOSGetter::ReadTreeP()
640{
41c29fde 641 // Read the RecParticles
88cb7938 642
41c29fde 643 PhosLoader()->CleanRecParticles() ;
644
88cb7938 645 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 646 // if ( !IsLoaded("P") ) {
88cb7938 647 PhosLoader()->LoadRecParticles("UPDATE") ;
648 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 649 // SetLoaded("P") ;
650 //}
7a9d98f9 651
88cb7938 652 return RecParticles()->GetEntries() ;
653}
654//____________________________________________________________________________
655Int_t AliPHOSGetter::ReadTreeS()
656{
657 // Read the SDigits
658
41c29fde 659 PhosLoader()->CleanSDigits() ;
88cb7938 660 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 661 //if ( !IsLoaded("S") ) {
7b4c1168 662 PhosLoader()->LoadSDigits("READ") ;
663 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 664 // SetLoaded("S") ;
665 //}
b0bba0af 666
88cb7938 667 return SDigits()->GetEntries() ;
668}
f1611b7c 669
677c8a30 670//____________________________________________________________________________
671Int_t AliPHOSGetter::ReadTreeE(Int_t event)
672{
673 // Read the ESD
674
675 // gets esdTree from the root file (AliESDs.root)
676 if (!fESDFile)
677 if ( !OpenESDFile() )
678 return -1 ;
679
680 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
681 fESD = new AliESD;
682 if (!fESDTree) {
683
684 Error("ReadTreeE", "no ESD tree found");
685 return -1;
686 }
687 fESDTree->SetBranchAddress("ESD", &fESD);
688 fESDTree->GetEvent(event);
689
690 return event ;
691}
692
88cb7938 693//____________________________________________________________________________
694TClonesArray * AliPHOSGetter::SDigits()
695{
696 // asks the Loader to return the Digits container
b0bba0af 697
88cb7938 698 TClonesArray * rv = 0 ;
699
700 rv = PhosLoader()->SDigits() ;
701 if (!rv) {
702 PhosLoader()->MakeSDigitsArray() ;
703 rv = PhosLoader()->SDigits() ;
704 }
705 return rv ;
b0bba0af 706}
707
708//____________________________________________________________________________
e957fea8 709AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 710{
e957fea8 711 // Returns pointer to the SDigitizer task
88cb7938 712 AliPHOSSDigitizer * rv ;
713 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
714 if (!rv) {
715 Event(0, "S") ;
716 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
b0bba0af 717 }
88cb7938 718 return rv ;
b0bba0af 719}
7a9d98f9 720
b0bba0af 721//____________________________________________________________________________
fc7e2f43 722TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
88cb7938 723{
724 // Return first (index=1) or second (index=2) secondary particle of primary particle p
725
726 if(index <= 0)
727 return 0 ;
728 if(index > 2)
729 return 0 ;
b0bba0af 730
88cb7938 731 if(p) {
732 Int_t daughterIndex = p->GetDaughter(index-1) ;
733 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 734 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
88cb7938 735 }
736 else
737 return 0 ;
738}
4ae78bb1 739
88cb7938 740//____________________________________________________________________________
fc7e2f43 741void AliPHOSGetter::Track(Int_t itrack)
88cb7938 742{
743 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
744
745 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
b0bba0af 746
88cb7938 747 if( !TreeH() ) // load treeH the first time
748 rl->LoadHits() ;
b0bba0af 749
88cb7938 750 // first time create the container
751 TClonesArray * hits = Hits() ;
752 if ( hits )
753 hits->Clear() ;
b0bba0af 754
88cb7938 755 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
756 phosbranch->SetAddress(&hits) ;
757 phosbranch->GetEntry(itrack) ;
b0bba0af 758}
759
b0bba0af 760//____________________________________________________________________________
88cb7938 761TTree * AliPHOSGetter::TreeD() const
762{
e957fea8 763 // Returns pointer to the Digits Tree
88cb7938 764 TTree * rv = 0 ;
765 rv = PhosLoader()->TreeD() ;
766 if ( !rv ) {
767 PhosLoader()->MakeTree("D");
768 rv = PhosLoader()->TreeD() ;
b0bba0af 769 }
b0bba0af 770
88cb7938 771 return rv ;
b0bba0af 772}
548f0134 773
b0bba0af 774//____________________________________________________________________________
88cb7938 775TTree * AliPHOSGetter::TreeH() const
776{
e957fea8 777 // Returns pointer to the Hits Tree
88cb7938 778 TTree * rv = 0 ;
779 rv = PhosLoader()->TreeH() ;
780 if ( !rv ) {
781 PhosLoader()->MakeTree("H");
782 rv = PhosLoader()->TreeH() ;
783 }
784
785 return rv ;
b0bba0af 786}
7a9d98f9 787
b0bba0af 788//____________________________________________________________________________
88cb7938 789TTree * AliPHOSGetter::TreeR() const
0bc3b8ed 790{
e957fea8 791 // Returns pointer to the RecPoints Tree
88cb7938 792 TTree * rv = 0 ;
793 rv = PhosLoader()->TreeR() ;
794 if ( !rv ) {
795 PhosLoader()->MakeTree("R");
796 rv = PhosLoader()->TreeR() ;
797 }
b0bba0af 798
88cb7938 799 return rv ;
b0bba0af 800}
801
b0bba0af 802//____________________________________________________________________________
88cb7938 803TTree * AliPHOSGetter::TreeT() const
0bc3b8ed 804{
e957fea8 805 // Returns pointer to the TrackSegments Tree
88cb7938 806 TTree * rv = 0 ;
807 rv = PhosLoader()->TreeT() ;
808 if ( !rv ) {
809 PhosLoader()->MakeTree("T");
810 rv = PhosLoader()->TreeT() ;
811 }
b0bba0af 812
88cb7938 813 return rv ;
b0bba0af 814}
b0bba0af 815//____________________________________________________________________________
88cb7938 816TTree * AliPHOSGetter::TreeP() const
0bc3b8ed 817{
e957fea8 818 // Returns pointer to the RecParticles Tree
88cb7938 819 TTree * rv = 0 ;
820 rv = PhosLoader()->TreeP() ;
821 if ( !rv ) {
822 PhosLoader()->MakeTree("P");
823 rv = PhosLoader()->TreeP() ;
824 }
4ae78bb1 825
88cb7938 826 return rv ;
b0bba0af 827}
828
829//____________________________________________________________________________
88cb7938 830TTree * AliPHOSGetter::TreeS() const
e957fea8 831{
832 // Returns pointer to the SDigits Tree
88cb7938 833 TTree * rv = 0 ;
834 rv = PhosLoader()->TreeS() ;
835 if ( !rv ) {
836 PhosLoader()->MakeTree("S");
837 rv = PhosLoader()->TreeS() ;
b0bba0af 838 }
b0bba0af 839
88cb7938 840 return rv ;
b0bba0af 841}
7a9d98f9 842
b0bba0af 843//____________________________________________________________________________
88cb7938 844Bool_t AliPHOSGetter::VersionExists(TString & opt) const
845{
846 // checks if the version with the present name already exists in the same directory
7a9d98f9 847
88cb7938 848 Bool_t rv = kFALSE ;
849
850 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
851 TString version( rl->GetEventFolder()->GetName() ) ;
7a9d98f9 852
88cb7938 853 opt.ToLower() ;
b0bba0af 854
88cb7938 855 if ( opt == "sdigits") {
856 // add the version name to the root file name
857 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 858 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 859 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
860 if ( !(gSystem->AccessPathName(fileName)) ) {
861 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
862 rv = kTRUE ;
4ae78bb1 863 }
88cb7938 864 PhosLoader()->SetSDigitsFileName(fileName) ;
b0bba0af 865 }
7a9d98f9 866
88cb7938 867 if ( opt == "digits") {
868 // add the version name to the root file name
869 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 870 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 871 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
872 if ( !(gSystem->AccessPathName(fileName)) ) {
873 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
874 rv = kTRUE ;
7a9d98f9 875 }
b0bba0af 876 }
7a9d98f9 877
88cb7938 878 return rv ;
7a9d98f9 879
b0bba0af 880}
88cb7938 881
7bb289a7 882//____________________________________________________________________________
88cb7938 883UShort_t AliPHOSGetter::EventPattern(void) const
0bc3b8ed 884{
885 // Return the pattern (trigger bit register) of the beam-test event
7bb289a7 886 if(fBTE)
887 return fBTE->GetPattern() ;
888 else
889 return 0 ;
890}
891//____________________________________________________________________________
88cb7938 892Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 893{
894 // Return the beam energy of the beam-test event
7bb289a7 895 if(fBTE)
896 return fBTE->GetBeamEnergy() ;
897 else
898 return 0 ;
899}