]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGetter.cxx
Incrementing ClassDefs (Y.Schutz)
[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) ;
3cf4f75f 326 }
327
328}
329
330
331//____________________________________________________________________________
332void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt)
333{
334 // Reads the raw event from rawReader
a43c51c3 335
3cf4f75f 336 if( strstr(opt,"W") ){
337 ReadRaw(rawReader) ;
66f895c8 338 }
95635748 339
88cb7938 340}
341
342
343//____________________________________________________________________________
344Int_t AliPHOSGetter::EventNumber() const
345 {
346 // return the current event number
347 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
348 return static_cast<Int_t>(rl->GetEventNumber()) ;
fbf811ec 349}
d489fb96 350
fbf811ec 351//____________________________________________________________________________
88cb7938 352 TClonesArray * AliPHOSGetter::Hits()
fbf811ec 353{
88cb7938 354 // asks the loader to return the Hits container
355
356 TClonesArray * rv = 0 ;
357
358 rv = PhosLoader()->Hits() ;
359 if ( !rv ) {
360 PhosLoader()->LoadHits("read");
361 rv = PhosLoader()->Hits() ;
fbf811ec 362 }
88cb7938 363 return rv ;
364}
fbf811ec 365
88cb7938 366//____________________________________________________________________________
367AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
368{
369 // Creates and returns the pointer of the unique instance
370 // Must be called only when the environment has changed
d489fb96 371
88cb7938 372 if(!fgObjGetter){ // first time the getter is called
373 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
fbf811ec 374 }
88cb7938 375 else { // the getter has been called previously
376 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
377 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
378 // check if the file is already open
379 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
380
381 if ( !galiceFile )
382 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
383
384 else { // the file is already open check the version name
385 TString currentVersionName = rl->GetEventFolder()->GetName() ;
386 TString newVersionName(version) ;
387 if (currentVersionName == newVersionName)
388 if(fgDebug)
389 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
390 else {
391 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
392 }
393 }
394 }
7fba1747 395 else {
396 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
e191bb57 397 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
1c221c70 398 delete rl ;
88cb7938 399 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
7fba1747 400 }
48f12df6 401 }
88cb7938 402 if (!fgObjGetter)
95635748 403 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
88cb7938 404 else
405 if (fgDebug)
406 Print() ;
4ae78bb1 407
88cb7938 408 return fgObjGetter ;
4ae78bb1 409}
410
6ad0e528 411//____________________________________________________________________________
88cb7938 412AliPHOSGetter * AliPHOSGetter::Instance()
6ad0e528 413{
88cb7938 414 // Returns the pointer of the unique instance already defined
fbf811ec 415
95635748 416 if(!fgObjGetter && fgDebug)
417 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
6ad0e528 418
88cb7938 419 return fgObjGetter ;
420
6ad0e528 421}
422
423//____________________________________________________________________________
88cb7938 424Int_t AliPHOSGetter::MaxEvent() const
6ad0e528 425{
88cb7938 426 // returns the number of events in the run (from TE)
0bc3b8ed 427
88cb7938 428 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
429 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
6ad0e528 430}
431
432//____________________________________________________________________________
88cb7938 433TParticle * AliPHOSGetter::Primary(Int_t index) const
6ad0e528 434{
88cb7938 435 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
436 return rl->Stack()->Particle(index) ;
437}
6ad0e528 438
4ae78bb1 439//____________________________________________________________________________
88cb7938 440AliPHOS * AliPHOSGetter:: PHOS() const
4ae78bb1 441{
442 // returns the PHOS object
5c4bcd63 443 AliPHOSLoader * loader = 0;
444 static AliPHOSLoader * oldloader = 0;
445 static AliPHOS * phos = 0;
446
447 loader = PhosLoader();
448
449 if ( loader != oldloader) {
450 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
451 oldloader = loader;
452 }
7a9d98f9 453 if (!phos)
88cb7938 454 if (fgDebug)
455 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
7a9d98f9 456 return phos ;
4ae78bb1 457}
458
88cb7938 459
460
461//____________________________________________________________________________
e957fea8 462AliPHOSPID * AliPHOSGetter::PID()
88cb7938 463{
e957fea8 464 // Returns pointer to the PID task
88cb7938 465 AliPHOSPID * rv ;
466 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
467 if (!rv) {
468 Event(0, "P") ;
469 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
470 }
471 return rv ;
472}
473
4ae78bb1 474//____________________________________________________________________________
88cb7938 475AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
4ae78bb1 476{
0bc3b8ed 477 // Returns PHOS geometry
478
7a9d98f9 479 AliPHOSGeometry * rv = 0 ;
480 if (PHOS() )
481 rv = PHOS()->GetGeometry() ;
482 return rv ;
483}
4ae78bb1 484
cb34a1fa 485//____________________________________________________________________________
88cb7938 486TClonesArray * AliPHOSGetter::Primaries()
487{
488 // creates the Primaries container if needed
489 if ( !fPrimaries ) {
490 if (fgDebug)
491 Info("Primaries", "Creating a new TClonesArray for primaries") ;
492 fPrimaries = new TClonesArray("TParticle", 1000) ;
493 }
494 return fPrimaries ;
495}
496
497//____________________________________________________________________________
498void AliPHOSGetter::Print()
499{
500 // Print usefull information about the getter
501
502 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
503 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
504}
cb34a1fa 505
88cb7938 506//____________________________________________________________________________
507void AliPHOSGetter::ReadPrimaries()
508{
509 // Read Primaries from Kinematics.root
cb34a1fa 510
88cb7938 511 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
cb34a1fa 512
88cb7938 513 // gets kine tree from the root file (Kinematics.root)
7fba1747 514 if ( ! rl->TreeK() ) { // load treeK the first time
88cb7938 515 rl->LoadKinematics() ;
7fba1747 516 }
88cb7938 517
7fba1747 518 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 519 if (fgDebug)
520 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
cb34a1fa 521
cb34a1fa 522
88cb7938 523 // first time creates the container
524 if ( Primaries() )
525 fPrimaries->Clear() ;
cb34a1fa 526
88cb7938 527 Int_t index = 0 ;
528 for (index = 0 ; index < fNPrimaries; index++) {
529 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
cb34a1fa 530 }
cb34a1fa 531}
532
95635748 533//____________________________________________________________________________
d2713783 534Bool_t AliPHOSGetter::OpenESDFile()
95635748 535{
d2713783 536 //Open the ESD file
95635748 537 Bool_t rv = kTRUE ;
d2713783 538 if (!fESDFile) {
539 fESDFile = TFile::Open(fESDFileName) ;
540 if (!fESDFile )
541 return kFALSE ;
542 }
95635748 543 else if (fESDFile->IsOpen()) {
544 fESDFile->Close() ;
545 fESDFile = TFile::Open(fESDFileName) ;
546 }
547 if (!fESDFile->IsOpen())
548 rv = kFALSE ;
549 return rv ;
550}
551
a43c51c3 552//____________________________________________________________________________
3cf4f75f 553Int_t AliPHOSGetter::ReadRaw(AliRawReader *rawReader)
a43c51c3 554{
555 // reads the raw format data, converts it into digits format and store digits in Digits()
556 // container.
557
3cf4f75f 558 AliPHOSRawStream in(rawReader);
a43c51c3 559
560 TClonesArray * digits = Digits() ;
561 digits->Clear() ;
562 Int_t idigit = 0 ;
ff808dc7 563
a43c51c3 564 while ( in.Next() ) { // PHOS entries loop
66f895c8 565
566 Int_t amp = in.GetSignal() ;
567 Double_t time = in.GetTime() ;
568 Int_t relId[4], id ;
e4d04cf1 569
66f895c8 570 relId[0] = in.GetModule() ;
571 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
572 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
573 }
574 relId[1] = 0 ;
575 relId[2] = in.GetRow() ;
576 relId[3] = in.GetColumn() ;
577 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
578
579 if (amp > 0 && id >=0 ) {
580 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
581 idigit++ ;
582 }
583
a43c51c3 584 } // PHOS entries loop
66f895c8 585
ff808dc7 586 digits->Sort() ;
a43c51c3 587
e4d04cf1 588 return digits->GetEntriesFast() ;
a43c51c3 589}
b0bba0af 590//____________________________________________________________________________
88cb7938 591Int_t AliPHOSGetter::ReadTreeD()
592{
593 // Read the Digits
b0bba0af 594
41c29fde 595 PhosLoader()->CleanDigits() ;
ff808dc7 596 PhosLoader()->LoadDigits("UPDATE") ;
597 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 598 return Digits()->GetEntries() ;
599}
7a9d98f9 600
b0bba0af 601//____________________________________________________________________________
88cb7938 602Int_t AliPHOSGetter::ReadTreeH()
603{
604 // Read the Hits
41c29fde 605 PhosLoader()->CleanHits() ;
88cb7938 606 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 607 //if ( !IsLoaded("H") ) {
88cb7938 608 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 609 // SetLoaded("H") ;
610 //}
88cb7938 611 return Hits()->GetEntries() ;
612}
4ae78bb1 613
88cb7938 614//____________________________________________________________________________
615Int_t AliPHOSGetter::ReadTreeR()
616{
617 // Read the RecPoints
b0bba0af 618
41c29fde 619 PhosLoader()->CleanRecPoints() ;
88cb7938 620 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 621 //if ( !IsLoaded("R") ) {
88cb7938 622 PhosLoader()->LoadRecPoints("UPDATE") ;
623 PhosLoader()->LoadClusterizer("UPDATE") ;
41c29fde 624 // SetLoaded("R") ;
625 //}
f1611b7c 626
88cb7938 627 return EmcRecPoints()->GetEntries() ;
b0bba0af 628}
7a9d98f9 629
b0bba0af 630//____________________________________________________________________________
88cb7938 631Int_t AliPHOSGetter::ReadTreeT()
632{
633 // Read the TrackSegments
7a9d98f9 634
41c29fde 635 PhosLoader()->CleanTracks() ;
88cb7938 636 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 637 //if ( !IsLoaded("T") ) {
88cb7938 638 PhosLoader()->LoadTracks("UPDATE") ;
639 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 640 // SetLoaded("T") ;
641 //}
fbf811ec 642
88cb7938 643 return TrackSegments()->GetEntries() ;
644}
b0bba0af 645//____________________________________________________________________________
88cb7938 646Int_t AliPHOSGetter::ReadTreeP()
647{
41c29fde 648 // Read the RecParticles
88cb7938 649
41c29fde 650 PhosLoader()->CleanRecParticles() ;
651
88cb7938 652 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 653 // if ( !IsLoaded("P") ) {
88cb7938 654 PhosLoader()->LoadRecParticles("UPDATE") ;
655 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 656 // SetLoaded("P") ;
657 //}
7a9d98f9 658
88cb7938 659 return RecParticles()->GetEntries() ;
660}
661//____________________________________________________________________________
662Int_t AliPHOSGetter::ReadTreeS()
663{
664 // Read the SDigits
665
41c29fde 666 PhosLoader()->CleanSDigits() ;
88cb7938 667 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 668 //if ( !IsLoaded("S") ) {
7b4c1168 669 PhosLoader()->LoadSDigits("READ") ;
670 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 671 // SetLoaded("S") ;
672 //}
b0bba0af 673
88cb7938 674 return SDigits()->GetEntries() ;
675}
f1611b7c 676
677c8a30 677//____________________________________________________________________________
678Int_t AliPHOSGetter::ReadTreeE(Int_t event)
679{
680 // Read the ESD
681
682 // gets esdTree from the root file (AliESDs.root)
683 if (!fESDFile)
684 if ( !OpenESDFile() )
685 return -1 ;
686
687 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
688 fESD = new AliESD;
689 if (!fESDTree) {
690
691 Error("ReadTreeE", "no ESD tree found");
692 return -1;
693 }
694 fESDTree->SetBranchAddress("ESD", &fESD);
695 fESDTree->GetEvent(event);
696
697 return event ;
698}
699
88cb7938 700//____________________________________________________________________________
701TClonesArray * AliPHOSGetter::SDigits()
702{
703 // asks the Loader to return the Digits container
b0bba0af 704
88cb7938 705 TClonesArray * rv = 0 ;
706
707 rv = PhosLoader()->SDigits() ;
708 if (!rv) {
709 PhosLoader()->MakeSDigitsArray() ;
710 rv = PhosLoader()->SDigits() ;
711 }
712 return rv ;
b0bba0af 713}
714
715//____________________________________________________________________________
e957fea8 716AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 717{
e957fea8 718 // Returns pointer to the SDigitizer task
88cb7938 719 AliPHOSSDigitizer * rv ;
720 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
721 if (!rv) {
722 Event(0, "S") ;
723 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
b0bba0af 724 }
88cb7938 725 return rv ;
b0bba0af 726}
7a9d98f9 727
b0bba0af 728//____________________________________________________________________________
fc7e2f43 729TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
88cb7938 730{
731 // Return first (index=1) or second (index=2) secondary particle of primary particle p
732
733 if(index <= 0)
734 return 0 ;
735 if(index > 2)
736 return 0 ;
b0bba0af 737
88cb7938 738 if(p) {
739 Int_t daughterIndex = p->GetDaughter(index-1) ;
740 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 741 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
88cb7938 742 }
743 else
744 return 0 ;
745}
4ae78bb1 746
88cb7938 747//____________________________________________________________________________
fc7e2f43 748void AliPHOSGetter::Track(Int_t itrack)
88cb7938 749{
750 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
751
752 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
b0bba0af 753
88cb7938 754 if( !TreeH() ) // load treeH the first time
755 rl->LoadHits() ;
b0bba0af 756
88cb7938 757 // first time create the container
758 TClonesArray * hits = Hits() ;
759 if ( hits )
760 hits->Clear() ;
b0bba0af 761
88cb7938 762 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
763 phosbranch->SetAddress(&hits) ;
764 phosbranch->GetEntry(itrack) ;
b0bba0af 765}
766
b0bba0af 767//____________________________________________________________________________
88cb7938 768TTree * AliPHOSGetter::TreeD() const
769{
e957fea8 770 // Returns pointer to the Digits Tree
88cb7938 771 TTree * rv = 0 ;
772 rv = PhosLoader()->TreeD() ;
773 if ( !rv ) {
774 PhosLoader()->MakeTree("D");
775 rv = PhosLoader()->TreeD() ;
b0bba0af 776 }
b0bba0af 777
88cb7938 778 return rv ;
b0bba0af 779}
548f0134 780
b0bba0af 781//____________________________________________________________________________
88cb7938 782TTree * AliPHOSGetter::TreeH() const
783{
e957fea8 784 // Returns pointer to the Hits Tree
88cb7938 785 TTree * rv = 0 ;
786 rv = PhosLoader()->TreeH() ;
787 if ( !rv ) {
788 PhosLoader()->MakeTree("H");
789 rv = PhosLoader()->TreeH() ;
790 }
791
792 return rv ;
b0bba0af 793}
7a9d98f9 794
b0bba0af 795//____________________________________________________________________________
88cb7938 796TTree * AliPHOSGetter::TreeR() const
0bc3b8ed 797{
e957fea8 798 // Returns pointer to the RecPoints Tree
88cb7938 799 TTree * rv = 0 ;
800 rv = PhosLoader()->TreeR() ;
801 if ( !rv ) {
802 PhosLoader()->MakeTree("R");
803 rv = PhosLoader()->TreeR() ;
804 }
b0bba0af 805
88cb7938 806 return rv ;
b0bba0af 807}
808
b0bba0af 809//____________________________________________________________________________
88cb7938 810TTree * AliPHOSGetter::TreeT() const
0bc3b8ed 811{
e957fea8 812 // Returns pointer to the TrackSegments Tree
88cb7938 813 TTree * rv = 0 ;
814 rv = PhosLoader()->TreeT() ;
815 if ( !rv ) {
816 PhosLoader()->MakeTree("T");
817 rv = PhosLoader()->TreeT() ;
818 }
b0bba0af 819
88cb7938 820 return rv ;
b0bba0af 821}
b0bba0af 822//____________________________________________________________________________
88cb7938 823TTree * AliPHOSGetter::TreeP() const
0bc3b8ed 824{
e957fea8 825 // Returns pointer to the RecParticles Tree
88cb7938 826 TTree * rv = 0 ;
827 rv = PhosLoader()->TreeP() ;
828 if ( !rv ) {
829 PhosLoader()->MakeTree("P");
830 rv = PhosLoader()->TreeP() ;
831 }
4ae78bb1 832
88cb7938 833 return rv ;
b0bba0af 834}
835
836//____________________________________________________________________________
88cb7938 837TTree * AliPHOSGetter::TreeS() const
e957fea8 838{
839 // Returns pointer to the SDigits Tree
88cb7938 840 TTree * rv = 0 ;
841 rv = PhosLoader()->TreeS() ;
842 if ( !rv ) {
843 PhosLoader()->MakeTree("S");
844 rv = PhosLoader()->TreeS() ;
b0bba0af 845 }
b0bba0af 846
88cb7938 847 return rv ;
b0bba0af 848}
7a9d98f9 849
b0bba0af 850//____________________________________________________________________________
88cb7938 851Bool_t AliPHOSGetter::VersionExists(TString & opt) const
852{
853 // checks if the version with the present name already exists in the same directory
7a9d98f9 854
88cb7938 855 Bool_t rv = kFALSE ;
856
857 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
858 TString version( rl->GetEventFolder()->GetName() ) ;
7a9d98f9 859
88cb7938 860 opt.ToLower() ;
b0bba0af 861
88cb7938 862 if ( opt == "sdigits") {
863 // add the version name to the root file name
864 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 865 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 866 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
867 if ( !(gSystem->AccessPathName(fileName)) ) {
868 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
869 rv = kTRUE ;
4ae78bb1 870 }
88cb7938 871 PhosLoader()->SetSDigitsFileName(fileName) ;
b0bba0af 872 }
7a9d98f9 873
88cb7938 874 if ( opt == "digits") {
875 // add the version name to the root file name
876 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 877 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 878 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
879 if ( !(gSystem->AccessPathName(fileName)) ) {
880 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
881 rv = kTRUE ;
7a9d98f9 882 }
b0bba0af 883 }
7a9d98f9 884
88cb7938 885 return rv ;
7a9d98f9 886
b0bba0af 887}
88cb7938 888
7bb289a7 889//____________________________________________________________________________
88cb7938 890UShort_t AliPHOSGetter::EventPattern(void) const
0bc3b8ed 891{
892 // Return the pattern (trigger bit register) of the beam-test event
7bb289a7 893 if(fBTE)
894 return fBTE->GetPattern() ;
895 else
896 return 0 ;
897}
898//____________________________________________________________________________
88cb7938 899Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 900{
901 // Return the beam energy of the beam-test event
7bb289a7 902 if(fBTE)
903 return fBTE->GetBeamEnergy() ;
904 else
905 return 0 ;
906}