Loaders removed from the reconstruction code (C.Cheshkov)
[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>
2bb77d5e 49#include <TCanvas.h>
50#include <TStyle.h>
351dd634 51//#include <TFrame.h>
4ae78bb1 52
53// --- Standard library ---
4ae78bb1 54
55// --- AliRoot header files ---
024a7e64 56#include "AliESD.h"
57#include "AliHeader.h"
58#include "AliMC.h"
e957fea8 59#include "AliPHOS.h"
024a7e64 60#include "AliPHOSBeamTestEvent.h"
61#include "AliPHOSGetter.h"
62#include "AliPHOSLoader.h"
431a9211 63#include "AliPHOSPulseGenerator.h"
88cb7938 64#include "AliRunLoader.h"
65#include "AliStack.h"
a29c28b6 66#include "AliPHOSRawDecoder.h"
a43c51c3 67#include "AliRawReaderFile.h"
e4d04cf1 68#include "AliLog.h"
7ca0684e 69#include "AliCDBLocal.h"
70#include "AliCDBStorage.h"
9e1ceb13 71#include "AliCDBManager.h"
4fc0021f 72#include "AliPHOSRawDigiProducer.h"
88cb7938 73
4ae78bb1 74ClassImp(AliPHOSGetter)
75
2bb77d5e 76AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
77AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
78AliPHOSCalibData* AliPHOSGetter::fgCalibData = 0;
88cb7938 79Int_t AliPHOSGetter::fgDebug = 0;
80
81// TFile * AliPHOSGetter::fgFile = 0 ;
4ae78bb1 82
3663622c 83AliPHOSGetter::AliPHOSGetter() :
84 fBTE(0),
85 fLoadingStatus(),
86 fNPrimaries(0),
87 fPrimaries(0),
88 fESDFile(0),
89 fESDFileName(),
90 fESD(0),
91 fESDTree(0),
92 fRawDigits(kFALSE),
93 fcdb(0)
94{
95 // ctor: this is a singleton, the ctor should never be called but cint needs it as public
96 Fatal("ctor", "AliPHOSGetter is a singleton default ctor not callable") ;
97}
98
99
4ae78bb1 100//____________________________________________________________________________
3663622c 101AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption) :
102 fBTE(0),
103 fLoadingStatus(),
104 fNPrimaries(0),
105 fPrimaries(0),
106 fESDFile(0),
107 fESDFileName(),
108 fESD(0),
109 fESDTree(0),
110 fRawDigits(kFALSE),
111 fcdb(0)
4ae78bb1 112{
88cb7938 113 // ctor only called by Instance()
dca3a7c4 114
88cb7938 115 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
116 if (!rl) {
117 rl = AliRunLoader::Open(headerFile, version, openingOption);
118 if (!rl) {
119 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
120 return ;
121 }
122 if (rl->GetAliRun() == 0x0) {
123 rl->LoadgAlice();
124 gAlice = rl->GetAliRun(); // should be removed
12a7cec1 125 rl->LoadHeader();
7bb289a7 126 }
93aeb834 127 }
88cb7938 128 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
129 if ( !fgPhosLoader )
130 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
131 else
132 fgPhosLoader->SetTitle(version);
85290134 133
88cb7938 134 // initialize data members
135 SetDebug(0) ;
136 fBTE = 0 ;
137 fPrimaries = 0 ;
138 fLoadingStatus = "" ;
d2713783 139
140 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
141 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
95635748 142 fESDFile = 0 ;
677c8a30 143 fESD = 0 ;
144 fESDTree = 0 ;
66f895c8 145 fRawDigits = kFALSE ;
7ca0684e 146
4ae78bb1 147}
fbf811ec 148
3663622c 149AliPHOSGetter::AliPHOSGetter(const AliPHOSGetter & obj) :
150 TObject(obj),
151 fBTE(0),
152 fLoadingStatus(),
153 fNPrimaries(0),
154 fPrimaries(0),
155 fESDFile(0),
156 fESDFileName(),
157 fESD(0),
158 fESDTree(0),
159 fRawDigits(kFALSE),
160 fcdb(0)
161{
162 // cpy ctor requested by Coding Convention
163 Fatal("cpy ctor", "not implemented") ;
164}
165
166//____________________________________________________________________________
167AliPHOSGetter::AliPHOSGetter(Int_t /*i*/) :
168 fBTE(0),
169 fLoadingStatus(),
170 fNPrimaries(0),
171 fPrimaries(0),
172 fESDFile(0),
173 fESDFileName(),
174 fESD(0),
175 fESDTree(0),
176 fRawDigits(kFALSE),
177 fcdb(0)
178{
179 // special constructor for onflight
180}
181
182
4ae78bb1 183//____________________________________________________________________________
0bc3b8ed 184AliPHOSGetter::~AliPHOSGetter()
185{
186 // dtor
66f895c8 187 if(fgPhosLoader){
188 delete fgPhosLoader ;
189 fgPhosLoader = 0 ;
190 }
191 if(fBTE){
192 delete fBTE ;
193 fBTE = 0 ;
194 }
195 if(fPrimaries){
196 fPrimaries->Delete() ;
197 delete fPrimaries ;
198 }
677c8a30 199 if (fESD)
200 delete fESD ;
201 if (fESDTree)
66f895c8 202 delete fESDTree ;
203
7c193632 204 fgObjGetter = 0;
0ef40383 205}
206
207//____________________________________________________________________________
208void AliPHOSGetter::Reset()
209{
210 // resets things in case the getter is called consecutively with different files
211 // the PHOS Loader is already deleted by the Run Loader
212
213 if (fPrimaries) {
214 fPrimaries->Delete() ;
215 delete fPrimaries ;
216 }
217 fgPhosLoader = 0;
218 fgObjGetter = 0;
65549808 219}
4ae78bb1 220
221//____________________________________________________________________________
88cb7938 222AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
223{
e957fea8 224 // Returns pointer to the Clusterizer task
88cb7938 225 AliPHOSClusterizer * rv ;
226 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
227 if (!rv) {
228 Event(0, "R") ;
229 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
0c87da39 230 }
88cb7938 231 return rv ;
0c87da39 232}
233
234//____________________________________________________________________________
2bb77d5e 235TObjArray * AliPHOSGetter::CpvRecPoints() const
4ae78bb1 236{
88cb7938 237 // asks the Loader to return the CPV RecPoints container
238
239 TObjArray * rv = 0 ;
4ae78bb1 240
88cb7938 241 rv = PhosLoader()->CpvRecPoints() ;
242 if (!rv) {
243 PhosLoader()->MakeRecPointsArray() ;
244 rv = PhosLoader()->CpvRecPoints() ;
b134c32f 245 }
88cb7938 246 return rv ;
4ae78bb1 247}
248
249//____________________________________________________________________________
2bb77d5e 250TClonesArray * AliPHOSGetter::Digits() const
4ae78bb1 251{
88cb7938 252 // asks the Loader to return the Digits container
df25f7dd 253
88cb7938 254 TClonesArray * rv = 0 ;
255 rv = PhosLoader()->Digits() ;
7bb289a7 256
88cb7938 257 if( !rv ) {
258 PhosLoader()->MakeDigitsArray() ;
259 rv = PhosLoader()->Digits() ;
fbf811ec 260 }
88cb7938 261 return rv ;
fbf811ec 262}
d489fb96 263
fbf811ec 264//____________________________________________________________________________
88cb7938 265AliPHOSDigitizer * AliPHOSGetter::Digitizer()
266{
e957fea8 267 // Returns pointer to the Digitizer task
88cb7938 268 AliPHOSDigitizer * rv ;
269 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
270 if (!rv) {
271 Event(0, "D") ;
272 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
48f12df6 273 }
88cb7938 274 return rv ;
4ae78bb1 275}
276
88cb7938 277
4ae78bb1 278//____________________________________________________________________________
2bb77d5e 279TObjArray * AliPHOSGetter::EmcRecPoints() const
6ad0e528 280{
88cb7938 281 // asks the Loader to return the EMC RecPoints container
6ad0e528 282
88cb7938 283 TObjArray * rv = 0 ;
fbf811ec 284
88cb7938 285 rv = PhosLoader()->EmcRecPoints() ;
286 if (!rv) {
287 PhosLoader()->MakeRecPointsArray() ;
288 rv = PhosLoader()->EmcRecPoints() ;
289 }
290 return rv ;
6ad0e528 291}
292
293//____________________________________________________________________________
2bb77d5e 294TClonesArray * AliPHOSGetter::TrackSegments() const
6ad0e528 295{
88cb7938 296 // asks the Loader to return the TrackSegments container
0bc3b8ed 297
88cb7938 298 TClonesArray * rv = 0 ;
6ad0e528 299
88cb7938 300 rv = PhosLoader()->TrackSegments() ;
301 if (!rv) {
302 PhosLoader()->MakeTrackSegmentsArray() ;
303 rv = PhosLoader()->TrackSegments() ;
6ad0e528 304 }
88cb7938 305 return rv ;
6ad0e528 306}
307
308//____________________________________________________________________________
e957fea8 309AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
88cb7938 310{
e957fea8 311 // Returns pointer to the TrackSegmentMaker task
88cb7938 312 AliPHOSTrackSegmentMaker * rv ;
313 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
314 if (!rv) {
315 Event(0, "T") ;
316 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
317 }
7a9d98f9 318 return rv ;
88cb7938 319}
cb34a1fa 320
321//____________________________________________________________________________
2bb77d5e 322TClonesArray * AliPHOSGetter::RecParticles() const
88cb7938 323{
324 // asks the Loader to return the TrackSegments container
cb34a1fa 325
88cb7938 326 TClonesArray * rv = 0 ;
cb34a1fa 327
88cb7938 328 rv = PhosLoader()->RecParticles() ;
329 if (!rv) {
330 PhosLoader()->MakeRecParticlesArray() ;
331 rv = PhosLoader()->RecParticles() ;
cb34a1fa 332 }
88cb7938 333 return rv ;
cb34a1fa 334}
cb34a1fa 335//____________________________________________________________________________
fc7e2f43 336void AliPHOSGetter::Event(Int_t event, const char* opt)
88cb7938 337{
338 // Reads the content of all Tree's S, D and R
dbad285c 339
66f895c8 340// if ( event >= MaxEvent() ) {
341// Error("Event", "%d not found in TreeE !", event) ;
342// return ;
343// }
7a9d98f9 344
88cb7938 345 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 346
66f895c8 347// // checks if we are dealing with test-beam data
348// TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
349// if(btb){
350// if(!fBTE)
351// fBTE = new AliPHOSBeamTestEvent() ;
352// btb->SetAddress(&fBTE) ;
353// btb->GetEntry(event) ;
354// }
355// else{
356// if(fBTE){
357// delete fBTE ;
358// fBTE = 0 ;
359// }
360// }
f1611b7c 361
88cb7938 362 // Loads the type of object(s) requested
7a9d98f9 363
88cb7938 364 rl->GetEvent(event) ;
fbf811ec 365
66f895c8 366 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
88cb7938 367 ReadPrimaries() ;
66f895c8 368 }
369
370 if(strstr(opt,"H") ){
88cb7938 371 ReadTreeH();
66f895c8 372 }
373
374 if(strstr(opt,"S") ){
88cb7938 375 ReadTreeS() ;
66f895c8 376 }
377
378 if(strstr(opt,"D") ){
88cb7938 379 ReadTreeD() ;
66f895c8 380 }
381
382 if(strstr(opt,"R") ){
88cb7938 383 ReadTreeR() ;
66f895c8 384 }
b0bba0af 385
66f895c8 386 if( strstr(opt,"T") ){
88cb7938 387 ReadTreeT() ;
66f895c8 388 }
f1611b7c 389
66f895c8 390 if( strstr(opt,"P") ){
88cb7938 391 ReadTreeP() ;
66f895c8 392 }
677c8a30 393
66f895c8 394 if( strstr(opt,"E") ){
677c8a30 395 ReadTreeE(event) ;
3cf4f75f 396 }
397
398}
399
400
401//____________________________________________________________________________
f5eaa851 402void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt, Bool_t isOldRCUFormat)
3cf4f75f 403{
404 // Reads the raw event from rawReader
f5eaa851 405 // isOldRCUFormat defines whenever to assume
406 // the old RCU format or not
f88e2313 407
3cf4f75f 408 if( strstr(opt,"W") ){
e1c29d81 409 rawReader->NextEvent();
f5eaa851 410 ReadRaw(rawReader,isOldRCUFormat) ;
66f895c8 411 }
95635748 412
b0bba0af 413}
414
7a9d98f9 415
b0bba0af 416//____________________________________________________________________________
88cb7938 417Int_t AliPHOSGetter::EventNumber() const
418 {
419 // return the current event number
420 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
421 return static_cast<Int_t>(rl->GetEventNumber()) ;
b0bba0af 422}
423
b0bba0af 424//____________________________________________________________________________
2bb77d5e 425 TClonesArray * AliPHOSGetter::Hits() const
88cb7938 426{
427 // asks the loader to return the Hits container
428
429 TClonesArray * rv = 0 ;
b0bba0af 430
88cb7938 431 rv = PhosLoader()->Hits() ;
432 if ( !rv ) {
433 PhosLoader()->LoadHits("read");
434 rv = PhosLoader()->Hits() ;
435 }
436 return rv ;
b0bba0af 437}
548f0134 438
b0bba0af 439//____________________________________________________________________________
88cb7938 440AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
441{
442 // Creates and returns the pointer of the unique instance
443 // Must be called only when the environment has changed
444
88cb7938 445 if(!fgObjGetter){ // first time the getter is called
446 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
447 }
448 else { // the getter has been called previously
449 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
450 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
451 // check if the file is already open
452 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
453
454 if ( !galiceFile )
455 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
456
457 else { // the file is already open check the version name
458 TString currentVersionName = rl->GetEventFolder()->GetName() ;
459 TString newVersionName(version) ;
460 if (currentVersionName == newVersionName)
461 if(fgDebug)
462 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
463 else {
464 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
465 }
466 }
7a9d98f9 467 }
7fba1747 468 else {
ad4aeaf4 469 rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
e191bb57 470 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
1c221c70 471 delete rl ;
88cb7938 472 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
7fba1747 473 }
b0bba0af 474 }
88cb7938 475 if (!fgObjGetter)
95635748 476 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
88cb7938 477 else
478 if (fgDebug)
479 Print() ;
480
481 return fgObjGetter ;
b0bba0af 482}
7a9d98f9 483
b0bba0af 484//____________________________________________________________________________
88cb7938 485AliPHOSGetter * AliPHOSGetter::Instance()
0bc3b8ed 486{
88cb7938 487 // Returns the pointer of the unique instance already defined
b0bba0af 488
95635748 489 if(!fgObjGetter && fgDebug)
490 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
b0bba0af 491
88cb7938 492 return fgObjGetter ;
493
b0bba0af 494}
495
b0bba0af 496//____________________________________________________________________________
88cb7938 497Int_t AliPHOSGetter::MaxEvent() const
0bc3b8ed 498{
88cb7938 499 // returns the number of events in the run (from TE)
7a9d98f9 500
88cb7938 501 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
502 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
503}
7a9d98f9 504
b0bba0af 505//____________________________________________________________________________
88cb7938 506TParticle * AliPHOSGetter::Primary(Int_t index) const
0bc3b8ed 507{
88cb7938 508 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
509 return rl->Stack()->Particle(index) ;
7a9d98f9 510}
b0bba0af 511
b0bba0af 512//____________________________________________________________________________
88cb7938 513AliPHOS * AliPHOSGetter:: PHOS() const
514{
515 // returns the PHOS object
5c4bcd63 516 AliPHOSLoader * loader = 0;
517 static AliPHOSLoader * oldloader = 0;
518 static AliPHOS * phos = 0;
519
520 loader = PhosLoader();
521
522 if ( loader != oldloader) {
523 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
524 oldloader = loader;
525 }
88cb7938 526 if (!phos)
527 if (fgDebug)
528 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
529 return phos ;
530}
b0bba0af 531
b0bba0af 532
b0bba0af 533
b0bba0af 534//____________________________________________________________________________
e957fea8 535AliPHOSPID * AliPHOSGetter::PID()
88cb7938 536{
e957fea8 537 // Returns pointer to the PID task
88cb7938 538 AliPHOSPID * rv ;
539 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
540 if (!rv) {
541 Event(0, "P") ;
542 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
b0bba0af 543 }
88cb7938 544 return rv ;
b0bba0af 545}
546
547//____________________________________________________________________________
88cb7938 548AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
549{
550 // Returns PHOS geometry
7a9d98f9 551
88cb7938 552 AliPHOSGeometry * rv = 0 ;
553 if (PHOS() )
554 rv = PHOS()->GetGeometry() ;
52c5f046 555 else {
556 rv = AliPHOSGeometry::GetInstance();
557 if (!rv) {
558 AliError("Could not find PHOS geometry! Loading the default one !");
559 rv = AliPHOSGeometry::GetInstance("IHEP","");
560 }
561 }
88cb7938 562 return rv ;
7a9d98f9 563}
b0bba0af 564
565//____________________________________________________________________________
88cb7938 566TClonesArray * AliPHOSGetter::Primaries()
0bc3b8ed 567{
88cb7938 568 // creates the Primaries container if needed
569 if ( !fPrimaries ) {
570 if (fgDebug)
571 Info("Primaries", "Creating a new TClonesArray for primaries") ;
572 fPrimaries = new TClonesArray("TParticle", 1000) ;
573 }
574 return fPrimaries ;
b0bba0af 575}
576
577//____________________________________________________________________________
88cb7938 578void AliPHOSGetter::Print()
579{
580 // Print usefull information about the getter
581
582 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
583 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
b0bba0af 584}
7a9d98f9 585
b0bba0af 586//____________________________________________________________________________
88cb7938 587void AliPHOSGetter::ReadPrimaries()
588{
589 // Read Primaries from Kinematics.root
b0bba0af 590
88cb7938 591 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
7a9d98f9 592
88cb7938 593 // gets kine tree from the root file (Kinematics.root)
7fba1747 594 if ( ! rl->TreeK() ) { // load treeK the first time
88cb7938 595 rl->LoadKinematics() ;
7fba1747 596 }
7a9d98f9 597
7fba1747 598 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 599 if (fgDebug)
600 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
7a9d98f9 601
7a9d98f9 602
88cb7938 603 // first time creates the container
604 if ( Primaries() )
605 fPrimaries->Clear() ;
b0bba0af 606
88cb7938 607 Int_t index = 0 ;
608 for (index = 0 ; index < fNPrimaries; index++) {
609 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
b0bba0af 610 }
88cb7938 611}
7a9d98f9 612
b0bba0af 613//____________________________________________________________________________
d2713783 614Bool_t AliPHOSGetter::OpenESDFile()
95635748 615{
d2713783 616 //Open the ESD file
95635748 617 Bool_t rv = kTRUE ;
d2713783 618 if (!fESDFile) {
619 fESDFile = TFile::Open(fESDFileName) ;
620 if (!fESDFile )
621 return kFALSE ;
622 }
95635748 623 else if (fESDFile->IsOpen()) {
624 fESDFile->Close() ;
625 fESDFile = TFile::Open(fESDFileName) ;
626 }
627 if (!fESDFile->IsOpen())
628 rv = kFALSE ;
629 return rv ;
630}
631
632//____________________________________________________________________________
2bb77d5e 633void AliPHOSGetter::FitRaw(Bool_t lowGainFlag, TGraph * gLowGain, TGraph * gHighGain, TF1* signalF, Double_t & energy, Double_t & time) const
45c1ce6f 634{
635 // Fits the raw signal time distribution
636
637 const Int_t kNoiseThreshold = 0 ;
638 Double_t timezero1 = 0., timezero2 = 0., timemax = 0. ;
639 Double_t signal = 0., signalmax = 0. ;
44ae287e 640 time = 0. ;
641 energy = 0. ;
45c1ce6f 642
431a9211 643 // Create a shaper pulse object which contains all the shaper parameters
75d640cb 644 AliPHOSPulseGenerator pulse;
431a9211 645
45c1ce6f 646 if (lowGainFlag) {
647 timezero1 = timezero2 = signalmax = timemax = 0. ;
75d640cb 648 signalF->FixParameter(0, pulse.GetRawFormatLowCharge()) ;
649 signalF->FixParameter(1, pulse.GetRawFormatLowGain()) ;
45c1ce6f 650 Int_t index ;
75d640cb 651 for (index = 0; index < pulse.GetRawFormatTimeBins(); index++) {
45c1ce6f 652 gLowGain->GetPoint(index, time, signal) ;
653 if (signal > kNoiseThreshold && timezero1 == 0.)
654 timezero1 = time ;
655 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
656 timezero2 = time ;
657 if (signal > signalmax) {
658 signalmax = signal ;
659 timemax = time ;
660 }
661 }
431a9211 662 signalmax /=
75d640cb 663 pulse.RawResponseFunctionMax(pulse.GetRawFormatLowCharge(),
664 pulse.GetRawFormatLowGain()) ;
665 if ( timezero1 + pulse.GetRawFormatTimePeak() < pulse.GetRawFormatTimeMax() * 0.4 ) { // else its noise
45c1ce6f 666 signalF->SetParameter(2, signalmax) ;
667 signalF->SetParameter(3, timezero1) ;
2bb77d5e 668 gLowGain->Fit(signalF, "QRO", "", 0., timezero2); //, "QRON") ;
45c1ce6f 669 energy = signalF->GetParameter(2) ;
75d640cb 670 time = signalF->GetMaximumX() - pulse.GetRawFormatTimePeak() - pulse.GetRawFormatTimeTrigger() ;
45c1ce6f 671 }
672 } else {
673 timezero1 = timezero2 = signalmax = timemax = 0. ;
75d640cb 674 signalF->FixParameter(0, pulse.GetRawFormatHighCharge()) ;
675 signalF->FixParameter(1, pulse.GetRawFormatHighGain()) ;
45c1ce6f 676 Int_t index ;
75d640cb 677 for (index = 0; index < pulse.GetRawFormatTimeBins(); index++) {
45c1ce6f 678 gHighGain->GetPoint(index, time, signal) ;
679 if (signal > kNoiseThreshold && timezero1 == 0.)
680 timezero1 = time ;
681 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
682 timezero2 = time ;
683 if (signal > signalmax) {
684 signalmax = signal ;
685 timemax = time ;
686 }
687 }
75d640cb 688 signalmax /= pulse.RawResponseFunctionMax(pulse.GetRawFormatHighCharge(),
689 pulse.GetRawFormatHighGain()) ;;
690 if ( timezero1 + pulse.GetRawFormatTimePeak() < pulse.GetRawFormatTimeMax() * 0.4 ) { // else its noise
45c1ce6f 691 signalF->SetParameter(2, signalmax) ;
692 signalF->SetParameter(3, timezero1) ;
2bb77d5e 693 gHighGain->Fit(signalF, "QRO", "", 0., timezero2) ;
45c1ce6f 694 energy = signalF->GetParameter(2) ;
75d640cb 695 time = signalF->GetMaximumX() - pulse.GetRawFormatTimePeak() - pulse.GetRawFormatTimeTrigger() ;
45c1ce6f 696 }
697 }
44ae287e 698 if (time == 0) energy = 0 ;
45c1ce6f 699}
700
701//____________________________________________________________________________
44ae287e 702Int_t AliPHOSGetter::CalibrateRaw(Double_t energy, Int_t *relId)
703{
704 // Convert energy into digitized amplitude for a cell relId
705 // It is a user responsilibity to open CDB and set
706 // AliPHOSCalibData object by the following operators:
707 //
708 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
709 // AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
710 // ->Get(path_to_calibdata,run_number);
711 // AliPHOSGetter* gime = AliPHOSGetter::Instance("galice.root");
712 // gime->SetCalibData(clb);
713
714 if (CalibData() == 0)
f88e2313 715 Warning("CalibrateRaw","Calibration DB is not initiated!");
44ae287e 716
717 Int_t module = relId[0];
f88e2313 718 Int_t column = relId[3];
719 Int_t row = relId[2];
720
721 Float_t gainFactor = 0.0015; // width of one Emc ADC channel in GeV
722 Float_t pedestal = 0.005; // Emc pedestals
723
724 if(CalibData()) {
725 gainFactor = CalibData()->GetADCchannelEmc (module,column,row);
726 pedestal = CalibData()->GetADCpedestalEmc(module,column,row);
727 }
728
44ae287e 729 Int_t amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ;
730 return amp;
731}
732//____________________________________________________________________________
f5eaa851 733Int_t AliPHOSGetter::ReadRaw(AliRawReader *rawReader,Bool_t isOldRCUFormat)
a43c51c3 734{
735 // reads the raw format data, converts it into digits format and store digits in Digits()
736 // container.
f5eaa851 737 // isOldRCUFormat = kTRUE in case of the old RCU
02e48b45 738 // format used in the raw data readout.
739 // Reimplemented by Boris Polichtchouk (Jul 2006)
740 // to make it working with the Jul-Aug 2006 beam test data.
741
a29c28b6 742 //Create raw decoder.
743
744 AliPHOSRawDecoder dc(rawReader);
745 dc.SetOldRCUFormat(isOldRCUFormat);
746 dc.SubtractPedestals(kTRUE);
45c1ce6f 747
a43c51c3 748 TClonesArray * digits = Digits() ;
4fc0021f 749 AliPHOSRawDigiProducer pr;
750 pr.MakeDigits(digits,&dc);
e212b6d1 751
752 //ADC counts -> GeV
753 for(Int_t i=0; i<digits->GetEntries(); i++) {
754 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
755 digit->SetEnergy(digit->GetEnergy()/AliPHOSPulseGenerator::GeV2ADC());
756 }
757
69464fdb 758 //!!!!for debug!!!
759 Int_t modMax=-111;
760 Int_t colMax=-111;
761 Int_t rowMax=-111;
762 Float_t eMax=-333;
763 //!!!for debug!!!
764
4fc0021f 765 Int_t relId[4];
766 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
69464fdb 767 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
768 if(digit->GetEnergy()>eMax) {
769 PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
770 eMax=digit->GetEnergy();
771 modMax=relId[0];
772 rowMax=relId[2];
773 colMax=relId[3];
774 }
775 }
19309784 776
6a0d2265 777 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
778 modMax,colMax,rowMax,eMax));
69464fdb 779
e4d04cf1 780 return digits->GetEntriesFast() ;
a43c51c3 781}
45c1ce6f 782
a43c51c3 783//____________________________________________________________________________
fd31ff92 784Int_t AliPHOSGetter::ReadTreeD() const
88cb7938 785{
786 // Read the Digits
7a9d98f9 787
41c29fde 788 PhosLoader()->CleanDigits() ;
ff808dc7 789 PhosLoader()->LoadDigits("UPDATE") ;
790 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 791 return Digits()->GetEntries() ;
792}
7a9d98f9 793
b0bba0af 794//____________________________________________________________________________
fd31ff92 795Int_t AliPHOSGetter::ReadTreeH() const
0bc3b8ed 796{
88cb7938 797 // Read the Hits
41c29fde 798 PhosLoader()->CleanHits() ;
88cb7938 799 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 800 //if ( !IsLoaded("H") ) {
88cb7938 801 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 802 // SetLoaded("H") ;
803 //}
88cb7938 804 return Hits()->GetEntries() ;
805}
b0bba0af 806
807//____________________________________________________________________________
fd31ff92 808Int_t AliPHOSGetter::ReadTreeR() const
88cb7938 809{
810 // Read the RecPoints
b0bba0af 811
41c29fde 812 PhosLoader()->CleanRecPoints() ;
88cb7938 813 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 814 //if ( !IsLoaded("R") ) {
88cb7938 815 PhosLoader()->LoadRecPoints("UPDATE") ;
41c29fde 816 // SetLoaded("R") ;
817 //}
7a9d98f9 818
88cb7938 819 return EmcRecPoints()->GetEntries() ;
7bb289a7 820}
88cb7938 821
7bb289a7 822//____________________________________________________________________________
fd31ff92 823Int_t AliPHOSGetter::ReadTreeT() const
0bc3b8ed 824{
88cb7938 825 // Read the TrackSegments
7a9d98f9 826
41c29fde 827 PhosLoader()->CleanTracks() ;
88cb7938 828 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 829 //if ( !IsLoaded("T") ) {
88cb7938 830 PhosLoader()->LoadTracks("UPDATE") ;
831 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 832 // SetLoaded("T") ;
833 //}
7a9d98f9 834
88cb7938 835 return TrackSegments()->GetEntries() ;
836}
b0bba0af 837//____________________________________________________________________________
fd31ff92 838Int_t AliPHOSGetter::ReadTreeP() const
0bc3b8ed 839{
41c29fde 840 // Read the RecParticles
b0bba0af 841
41c29fde 842 PhosLoader()->CleanRecParticles() ;
843
88cb7938 844 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 845 // if ( !IsLoaded("P") ) {
88cb7938 846 PhosLoader()->LoadRecParticles("UPDATE") ;
847 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 848 // SetLoaded("P") ;
849 //}
b0bba0af 850
88cb7938 851 return RecParticles()->GetEntries() ;
4ae78bb1 852}
4ae78bb1 853//____________________________________________________________________________
fd31ff92 854Int_t AliPHOSGetter::ReadTreeS() const
88cb7938 855{
856 // Read the SDigits
7a9d98f9 857
41c29fde 858 PhosLoader()->CleanSDigits() ;
88cb7938 859 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 860 //if ( !IsLoaded("S") ) {
7b4c1168 861 PhosLoader()->LoadSDigits("READ") ;
862 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 863 // SetLoaded("S") ;
864 //}
7a9d98f9 865
88cb7938 866 return SDigits()->GetEntries() ;
9bd3caba 867}
868
869//____________________________________________________________________________
677c8a30 870Int_t AliPHOSGetter::ReadTreeE(Int_t event)
871{
872 // Read the ESD
873
874 // gets esdTree from the root file (AliESDs.root)
875 if (!fESDFile)
876 if ( !OpenESDFile() )
877 return -1 ;
878
879 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
880 fESD = new AliESD;
881 if (!fESDTree) {
882
883 Error("ReadTreeE", "no ESD tree found");
884 return -1;
885 }
886 fESDTree->SetBranchAddress("ESD", &fESD);
887 fESDTree->GetEvent(event);
888
889 return event ;
890}
891
892//____________________________________________________________________________
2bb77d5e 893TClonesArray * AliPHOSGetter::SDigits() const
9bd3caba 894{
88cb7938 895 // asks the Loader to return the Digits container
9bd3caba 896
88cb7938 897 TClonesArray * rv = 0 ;
9bd3caba 898
88cb7938 899 rv = PhosLoader()->SDigits() ;
900 if (!rv) {
901 PhosLoader()->MakeSDigitsArray() ;
902 rv = PhosLoader()->SDigits() ;
9bd3caba 903 }
88cb7938 904 return rv ;
9bd3caba 905}
906
7a9d98f9 907//____________________________________________________________________________
e957fea8 908AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 909{
e957fea8 910 // Returns pointer to the SDigitizer task
88cb7938 911 AliPHOSSDigitizer * rv ;
912 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
913 if (!rv) {
914 Event(0, "S") ;
915 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
9bd3caba 916 }
88cb7938 917 return rv ;
4ae78bb1 918}
919
920//____________________________________________________________________________
fc7e2f43 921TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
cb34a1fa 922{
923 // Return first (index=1) or second (index=2) secondary particle of primary particle p
924
925 if(index <= 0)
926 return 0 ;
927 if(index > 2)
928 return 0 ;
929
930 if(p) {
931 Int_t daughterIndex = p->GetDaughter(index-1) ;
88cb7938 932 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 933 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
cb34a1fa 934 }
935 else
936 return 0 ;
937}
938
939//____________________________________________________________________________
fc7e2f43 940void AliPHOSGetter::Track(Int_t itrack)
b0bba0af 941{
942 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
7a9d98f9 943
88cb7938 944 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
4ae78bb1 945
88cb7938 946 if( !TreeH() ) // load treeH the first time
947 rl->LoadHits() ;
59b46416 948
88cb7938 949 // first time create the container
950 TClonesArray * hits = Hits() ;
951 if ( hits )
952 hits->Clear() ;
fbf811ec 953
88cb7938 954 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
955 phosbranch->SetAddress(&hits) ;
956 phosbranch->GetEntry(itrack) ;
4ae78bb1 957}
958
959//____________________________________________________________________________
88cb7938 960TTree * AliPHOSGetter::TreeD() const
4ae78bb1 961{
e957fea8 962 // Returns pointer to the Digits Tree
88cb7938 963 TTree * rv = 0 ;
964 rv = PhosLoader()->TreeD() ;
965 if ( !rv ) {
966 PhosLoader()->MakeTree("D");
967 rv = PhosLoader()->TreeD() ;
968 }
b0bba0af 969
88cb7938 970 return rv ;
b0bba0af 971}
548f0134 972
b0bba0af 973//____________________________________________________________________________
88cb7938 974TTree * AliPHOSGetter::TreeH() const
0bc3b8ed 975{
e957fea8 976 // Returns pointer to the Hits Tree
88cb7938 977 TTree * rv = 0 ;
978 rv = PhosLoader()->TreeH() ;
979 if ( !rv ) {
980 PhosLoader()->MakeTree("H");
981 rv = PhosLoader()->TreeH() ;
7a9d98f9 982 }
4ae78bb1 983
88cb7938 984 return rv ;
4ae78bb1 985}
986
987//____________________________________________________________________________
88cb7938 988TTree * AliPHOSGetter::TreeR() const
4ae78bb1 989{
e957fea8 990 // Returns pointer to the RecPoints Tree
88cb7938 991 TTree * rv = 0 ;
992 rv = PhosLoader()->TreeR() ;
993 if ( !rv ) {
994 PhosLoader()->MakeTree("R");
995 rv = PhosLoader()->TreeR() ;
996 }
b0bba0af 997
88cb7938 998 return rv ;
4ae78bb1 999}
65549808 1000
1001//____________________________________________________________________________
88cb7938 1002TTree * AliPHOSGetter::TreeT() const
65549808 1003{
e957fea8 1004 // Returns pointer to the TrackSegments Tree
88cb7938 1005 TTree * rv = 0 ;
1006 rv = PhosLoader()->TreeT() ;
1007 if ( !rv ) {
1008 PhosLoader()->MakeTree("T");
1009 rv = PhosLoader()->TreeT() ;
1010 }
b134c32f 1011
88cb7938 1012 return rv ;
65549808 1013}
65549808 1014//____________________________________________________________________________
88cb7938 1015TTree * AliPHOSGetter::TreeP() const
65549808 1016{
e957fea8 1017 // Returns pointer to the RecParticles Tree
88cb7938 1018 TTree * rv = 0 ;
1019 rv = PhosLoader()->TreeP() ;
1020 if ( !rv ) {
1021 PhosLoader()->MakeTree("P");
1022 rv = PhosLoader()->TreeP() ;
1023 }
65549808 1024
88cb7938 1025 return rv ;
65549808 1026}
1027
1028//____________________________________________________________________________
88cb7938 1029TTree * AliPHOSGetter::TreeS() const
e957fea8 1030{
1031 // Returns pointer to the SDigits Tree
88cb7938 1032 TTree * rv = 0 ;
1033 rv = PhosLoader()->TreeS() ;
1034 if ( !rv ) {
1035 PhosLoader()->MakeTree("S");
1036 rv = PhosLoader()->TreeS() ;
1037 }
65549808 1038
88cb7938 1039 return rv ;
65549808 1040}
fbf811ec 1041
1042//____________________________________________________________________________
88cb7938 1043Bool_t AliPHOSGetter::VersionExists(TString & opt) const
0bc3b8ed 1044{
88cb7938 1045 // checks if the version with the present name already exists in the same directory
fbf811ec 1046
88cb7938 1047 Bool_t rv = kFALSE ;
1048
1049 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
1050 TString version( rl->GetEventFolder()->GetName() ) ;
fbf811ec 1051
88cb7938 1052 opt.ToLower() ;
fbf811ec 1053
88cb7938 1054 if ( opt == "sdigits") {
1055 // add the version name to the root file name
1056 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 1057 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1058 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1059 if ( !(gSystem->AccessPathName(fileName)) ) {
1060 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1061 rv = kTRUE ;
fbf811ec 1062 }
88cb7938 1063 PhosLoader()->SetSDigitsFileName(fileName) ;
fbf811ec 1064 }
fbf811ec 1065
88cb7938 1066 if ( opt == "digits") {
1067 // add the version name to the root file name
1068 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 1069 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1070 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1071 if ( !(gSystem->AccessPathName(fileName)) ) {
1072 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1073 rv = kTRUE ;
fbf811ec 1074 }
1075 }
1076
88cb7938 1077 return rv ;
fbf811ec 1078
1079}
88cb7938 1080
fbf811ec 1081//____________________________________________________________________________
88cb7938 1082UShort_t AliPHOSGetter::EventPattern(void) const
fbf811ec 1083{
88cb7938 1084 // Return the pattern (trigger bit register) of the beam-test event
1085 if(fBTE)
1086 return fBTE->GetPattern() ;
1087 else
1088 return 0 ;
fbf811ec 1089}
1090//____________________________________________________________________________
88cb7938 1091Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 1092{
88cb7938 1093 // Return the beam energy of the beam-test event
1094 if(fBTE)
1095 return fBTE->GetBeamEnergy() ;
1096 else
1097 return 0 ;
fbf811ec 1098}
7ca0684e 1099//____________________________________________________________________________
1100
1101AliPHOSCalibData* AliPHOSGetter::CalibData()
1102{
ef868168 1103 // Check if the instance of AliPHOSCalibData exists, and return it
7ca0684e 1104
2bb77d5e 1105 return fgCalibData;
7ca0684e 1106}