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