]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGetter.cxx
Moving the alignment-related static methods from AliAlignObj to the new geometry...
[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()
4ae78bb1 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();
88cb7938 126 }
fbf811ec 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);
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
88cb7938 147}
9bd3caba 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
88cb7938 183//____________________________________________________________________________
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;
88cb7938 219}
fbf811ec 220
88cb7938 221//____________________________________________________________________________
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()) ;
230 }
231 return rv ;
232}
4ae78bb1 233
88cb7938 234//____________________________________________________________________________
2bb77d5e 235TObjArray * AliPHOSGetter::CpvRecPoints() const
88cb7938 236{
237 // asks the Loader to return the CPV RecPoints container
4ae78bb1 238
88cb7938 239 TObjArray * rv = 0 ;
240
241 rv = PhosLoader()->CpvRecPoints() ;
242 if (!rv) {
243 PhosLoader()->MakeRecPointsArray() ;
244 rv = PhosLoader()->CpvRecPoints() ;
245 }
246 return rv ;
247}
dca3a7c4 248
88cb7938 249//____________________________________________________________________________
2bb77d5e 250TClonesArray * AliPHOSGetter::Digits() const
88cb7938 251{
252 // asks the Loader to return the Digits container
7bb289a7 253
88cb7938 254 TClonesArray * rv = 0 ;
255 rv = PhosLoader()->Digits() ;
7bb289a7 256
88cb7938 257 if( !rv ) {
258 PhosLoader()->MakeDigitsArray() ;
259 rv = PhosLoader()->Digits() ;
4ae78bb1 260 }
88cb7938 261 return rv ;
262}
4b808d52 263
88cb7938 264//____________________________________________________________________________
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()) ;
273 }
274 return rv ;
4ae78bb1 275}
fbf811ec 276
88cb7938 277
4ae78bb1 278//____________________________________________________________________________
2bb77d5e 279TObjArray * AliPHOSGetter::EmcRecPoints() const
0bc3b8ed 280{
88cb7938 281 // asks the Loader to return the EMC RecPoints container
d489fb96 282
88cb7938 283 TObjArray * rv = 0 ;
65549808 284
88cb7938 285 rv = PhosLoader()->EmcRecPoints() ;
286 if (!rv) {
287 PhosLoader()->MakeRecPointsArray() ;
288 rv = PhosLoader()->EmcRecPoints() ;
89165262 289 }
88cb7938 290 return rv ;
81bb1a45 291}
7a9d98f9 292
65549808 293//____________________________________________________________________________
2bb77d5e 294TClonesArray * AliPHOSGetter::TrackSegments() const
65549808 295{
88cb7938 296 // asks the Loader to return the TrackSegments container
297
298 TClonesArray * rv = 0 ;
299
300 rv = PhosLoader()->TrackSegments() ;
301 if (!rv) {
302 PhosLoader()->MakeTrackSegmentsArray() ;
303 rv = PhosLoader()->TrackSegments() ;
304 }
305 return rv ;
65549808 306}
4ae78bb1 307
0c87da39 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()) ;
0c87da39 317 }
88cb7938 318 return rv ;
0c87da39 319}
320
4ae78bb1 321//____________________________________________________________________________
2bb77d5e 322TClonesArray * AliPHOSGetter::RecParticles() const
4ae78bb1 323{
88cb7938 324 // asks the Loader to return the TrackSegments container
325
326 TClonesArray * rv = 0 ;
4ae78bb1 327
88cb7938 328 rv = PhosLoader()->RecParticles() ;
329 if (!rv) {
330 PhosLoader()->MakeRecParticlesArray() ;
331 rv = PhosLoader()->RecParticles() ;
b134c32f 332 }
88cb7938 333 return rv ;
4ae78bb1 334}
4ae78bb1 335//____________________________________________________________________________
fc7e2f43 336void AliPHOSGetter::Event(Int_t event, const char* opt)
4ae78bb1 337{
88cb7938 338 // Reads the content of all Tree's S, D and R
548f0134 339
66f895c8 340// if ( event >= MaxEvent() ) {
341// Error("Event", "%d not found in TreeE !", event) ;
342// return ;
343// }
4ae78bb1 344
88cb7938 345 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
df25f7dd 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// }
88cb7938 361
362 // Loads the type of object(s) requested
b134c32f 363
88cb7938 364 rl->GetEvent(event) ;
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 }
88cb7938 385
66f895c8 386 if( strstr(opt,"T") ){
88cb7938 387 ReadTreeT() ;
66f895c8 388 }
88cb7938 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
88cb7938 413}
414
415
416//____________________________________________________________________________
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()) ;
fbf811ec 422}
d489fb96 423
fbf811ec 424//____________________________________________________________________________
2bb77d5e 425 TClonesArray * AliPHOSGetter::Hits() const
fbf811ec 426{
88cb7938 427 // asks the loader to return the Hits container
428
429 TClonesArray * rv = 0 ;
430
431 rv = PhosLoader()->Hits() ;
432 if ( !rv ) {
433 PhosLoader()->LoadHits("read");
434 rv = PhosLoader()->Hits() ;
fbf811ec 435 }
88cb7938 436 return rv ;
437}
fbf811ec 438
88cb7938 439//____________________________________________________________________________
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
d489fb96 444
88cb7938 445 if(!fgObjGetter){ // first time the getter is called
446 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
fbf811ec 447 }
88cb7938 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 }
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 }
48f12df6 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() ;
4ae78bb1 480
88cb7938 481 return fgObjGetter ;
4ae78bb1 482}
483
6ad0e528 484//____________________________________________________________________________
88cb7938 485AliPHOSGetter * AliPHOSGetter::Instance()
6ad0e528 486{
88cb7938 487 // Returns the pointer of the unique instance already defined
fbf811ec 488
95635748 489 if(!fgObjGetter && fgDebug)
490 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
6ad0e528 491
88cb7938 492 return fgObjGetter ;
493
6ad0e528 494}
495
496//____________________________________________________________________________
88cb7938 497Int_t AliPHOSGetter::MaxEvent() const
6ad0e528 498{
88cb7938 499 // returns the number of events in the run (from TE)
0bc3b8ed 500
88cb7938 501 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
502 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
6ad0e528 503}
504
505//____________________________________________________________________________
88cb7938 506TParticle * AliPHOSGetter::Primary(Int_t index) const
6ad0e528 507{
88cb7938 508 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
509 return rl->Stack()->Particle(index) ;
510}
6ad0e528 511
4ae78bb1 512//____________________________________________________________________________
88cb7938 513AliPHOS * AliPHOSGetter:: PHOS() const
4ae78bb1 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 }
7a9d98f9 526 if (!phos)
88cb7938 527 if (fgDebug)
528 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
7a9d98f9 529 return phos ;
4ae78bb1 530}
531
88cb7938 532
533
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()) ;
543 }
544 return rv ;
545}
546
4ae78bb1 547//____________________________________________________________________________
88cb7938 548AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
4ae78bb1 549{
0bc3b8ed 550 // Returns PHOS geometry
551
7a9d98f9 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 }
7a9d98f9 562 return rv ;
563}
4ae78bb1 564
cb34a1fa 565//____________________________________________________________________________
88cb7938 566TClonesArray * AliPHOSGetter::Primaries()
567{
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 ;
575}
576
577//____________________________________________________________________________
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() ) ;
584}
cb34a1fa 585
88cb7938 586//____________________________________________________________________________
587void AliPHOSGetter::ReadPrimaries()
588{
589 // Read Primaries from Kinematics.root
cb34a1fa 590
88cb7938 591 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
cb34a1fa 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 }
88cb7938 597
7fba1747 598 fNPrimaries = (rl->GetHeader())->GetNtrack();
88cb7938 599 if (fgDebug)
600 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
cb34a1fa 601
cb34a1fa 602
88cb7938 603 // first time creates the container
604 if ( Primaries() )
605 fPrimaries->Clear() ;
cb34a1fa 606
88cb7938 607 Int_t index = 0 ;
608 for (index = 0 ; index < fNPrimaries; index++) {
609 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
cb34a1fa 610 }
cb34a1fa 611}
612
95635748 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
45c1ce6f 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
44ae287e 701//____________________________________________________________________________
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}
a43c51c3 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);
69464fdb 751
752 //!!!!for debug!!!
753 Int_t modMax=-111;
754 Int_t colMax=-111;
755 Int_t rowMax=-111;
756 Float_t eMax=-333;
757 //!!!for debug!!!
758
4fc0021f 759 Int_t relId[4];
760 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
69464fdb 761 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
762 if(digit->GetEnergy()>eMax) {
763 PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
764 eMax=digit->GetEnergy();
765 modMax=relId[0];
766 rowMax=relId[2];
767 colMax=relId[3];
768 }
769 }
19309784 770
6a0d2265 771 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
772 modMax,colMax,rowMax,eMax));
69464fdb 773
e4d04cf1 774 return digits->GetEntriesFast() ;
a43c51c3 775}
45c1ce6f 776
b0bba0af 777//____________________________________________________________________________
fd31ff92 778Int_t AliPHOSGetter::ReadTreeD() const
88cb7938 779{
780 // Read the Digits
b0bba0af 781
41c29fde 782 PhosLoader()->CleanDigits() ;
ff808dc7 783 PhosLoader()->LoadDigits("UPDATE") ;
784 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 785 return Digits()->GetEntries() ;
786}
7a9d98f9 787
b0bba0af 788//____________________________________________________________________________
fd31ff92 789Int_t AliPHOSGetter::ReadTreeH() const
88cb7938 790{
791 // Read the Hits
41c29fde 792 PhosLoader()->CleanHits() ;
88cb7938 793 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 794 //if ( !IsLoaded("H") ) {
88cb7938 795 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 796 // SetLoaded("H") ;
797 //}
88cb7938 798 return Hits()->GetEntries() ;
799}
4ae78bb1 800
88cb7938 801//____________________________________________________________________________
fd31ff92 802Int_t AliPHOSGetter::ReadTreeR() const
88cb7938 803{
804 // Read the RecPoints
b0bba0af 805
41c29fde 806 PhosLoader()->CleanRecPoints() ;
88cb7938 807 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 808 //if ( !IsLoaded("R") ) {
88cb7938 809 PhosLoader()->LoadRecPoints("UPDATE") ;
810 PhosLoader()->LoadClusterizer("UPDATE") ;
41c29fde 811 // SetLoaded("R") ;
812 //}
f1611b7c 813
88cb7938 814 return EmcRecPoints()->GetEntries() ;
b0bba0af 815}
7a9d98f9 816
b0bba0af 817//____________________________________________________________________________
fd31ff92 818Int_t AliPHOSGetter::ReadTreeT() const
88cb7938 819{
820 // Read the TrackSegments
7a9d98f9 821
41c29fde 822 PhosLoader()->CleanTracks() ;
88cb7938 823 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 824 //if ( !IsLoaded("T") ) {
88cb7938 825 PhosLoader()->LoadTracks("UPDATE") ;
826 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 827 // SetLoaded("T") ;
828 //}
fbf811ec 829
88cb7938 830 return TrackSegments()->GetEntries() ;
831}
b0bba0af 832//____________________________________________________________________________
fd31ff92 833Int_t AliPHOSGetter::ReadTreeP() const
88cb7938 834{
41c29fde 835 // Read the RecParticles
88cb7938 836
41c29fde 837 PhosLoader()->CleanRecParticles() ;
838
88cb7938 839 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 840 // if ( !IsLoaded("P") ) {
88cb7938 841 PhosLoader()->LoadRecParticles("UPDATE") ;
842 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 843 // SetLoaded("P") ;
844 //}
7a9d98f9 845
88cb7938 846 return RecParticles()->GetEntries() ;
847}
848//____________________________________________________________________________
fd31ff92 849Int_t AliPHOSGetter::ReadTreeS() const
88cb7938 850{
851 // Read the SDigits
852
41c29fde 853 PhosLoader()->CleanSDigits() ;
88cb7938 854 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 855 //if ( !IsLoaded("S") ) {
7b4c1168 856 PhosLoader()->LoadSDigits("READ") ;
857 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 858 // SetLoaded("S") ;
859 //}
b0bba0af 860
88cb7938 861 return SDigits()->GetEntries() ;
862}
f1611b7c 863
677c8a30 864//____________________________________________________________________________
865Int_t AliPHOSGetter::ReadTreeE(Int_t event)
866{
867 // Read the ESD
868
869 // gets esdTree from the root file (AliESDs.root)
870 if (!fESDFile)
871 if ( !OpenESDFile() )
872 return -1 ;
873
874 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
875 fESD = new AliESD;
876 if (!fESDTree) {
877
878 Error("ReadTreeE", "no ESD tree found");
879 return -1;
880 }
881 fESDTree->SetBranchAddress("ESD", &fESD);
882 fESDTree->GetEvent(event);
883
884 return event ;
885}
886
88cb7938 887//____________________________________________________________________________
2bb77d5e 888TClonesArray * AliPHOSGetter::SDigits() const
88cb7938 889{
890 // asks the Loader to return the Digits container
b0bba0af 891
88cb7938 892 TClonesArray * rv = 0 ;
893
894 rv = PhosLoader()->SDigits() ;
895 if (!rv) {
896 PhosLoader()->MakeSDigitsArray() ;
897 rv = PhosLoader()->SDigits() ;
898 }
899 return rv ;
b0bba0af 900}
901
902//____________________________________________________________________________
e957fea8 903AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 904{
e957fea8 905 // Returns pointer to the SDigitizer task
88cb7938 906 AliPHOSSDigitizer * rv ;
907 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
908 if (!rv) {
909 Event(0, "S") ;
910 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
b0bba0af 911 }
88cb7938 912 return rv ;
b0bba0af 913}
7a9d98f9 914
b0bba0af 915//____________________________________________________________________________
fc7e2f43 916TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
88cb7938 917{
918 // Return first (index=1) or second (index=2) secondary particle of primary particle p
919
920 if(index <= 0)
921 return 0 ;
922 if(index > 2)
923 return 0 ;
b0bba0af 924
88cb7938 925 if(p) {
926 Int_t daughterIndex = p->GetDaughter(index-1) ;
927 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 928 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
88cb7938 929 }
930 else
931 return 0 ;
932}
4ae78bb1 933
88cb7938 934//____________________________________________________________________________
fc7e2f43 935void AliPHOSGetter::Track(Int_t itrack)
88cb7938 936{
937 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
938
939 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
b0bba0af 940
88cb7938 941 if( !TreeH() ) // load treeH the first time
942 rl->LoadHits() ;
b0bba0af 943
88cb7938 944 // first time create the container
945 TClonesArray * hits = Hits() ;
946 if ( hits )
947 hits->Clear() ;
b0bba0af 948
88cb7938 949 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
950 phosbranch->SetAddress(&hits) ;
951 phosbranch->GetEntry(itrack) ;
b0bba0af 952}
953
b0bba0af 954//____________________________________________________________________________
88cb7938 955TTree * AliPHOSGetter::TreeD() const
956{
e957fea8 957 // Returns pointer to the Digits Tree
88cb7938 958 TTree * rv = 0 ;
959 rv = PhosLoader()->TreeD() ;
960 if ( !rv ) {
961 PhosLoader()->MakeTree("D");
962 rv = PhosLoader()->TreeD() ;
b0bba0af 963 }
b0bba0af 964
88cb7938 965 return rv ;
b0bba0af 966}
548f0134 967
b0bba0af 968//____________________________________________________________________________
88cb7938 969TTree * AliPHOSGetter::TreeH() const
970{
e957fea8 971 // Returns pointer to the Hits Tree
88cb7938 972 TTree * rv = 0 ;
973 rv = PhosLoader()->TreeH() ;
974 if ( !rv ) {
975 PhosLoader()->MakeTree("H");
976 rv = PhosLoader()->TreeH() ;
977 }
978
979 return rv ;
b0bba0af 980}
7a9d98f9 981
b0bba0af 982//____________________________________________________________________________
88cb7938 983TTree * AliPHOSGetter::TreeR() const
0bc3b8ed 984{
e957fea8 985 // Returns pointer to the RecPoints Tree
88cb7938 986 TTree * rv = 0 ;
987 rv = PhosLoader()->TreeR() ;
988 if ( !rv ) {
989 PhosLoader()->MakeTree("R");
990 rv = PhosLoader()->TreeR() ;
991 }
b0bba0af 992
88cb7938 993 return rv ;
b0bba0af 994}
995
b0bba0af 996//____________________________________________________________________________
88cb7938 997TTree * AliPHOSGetter::TreeT() const
0bc3b8ed 998{
e957fea8 999 // Returns pointer to the TrackSegments Tree
88cb7938 1000 TTree * rv = 0 ;
1001 rv = PhosLoader()->TreeT() ;
1002 if ( !rv ) {
1003 PhosLoader()->MakeTree("T");
1004 rv = PhosLoader()->TreeT() ;
1005 }
b0bba0af 1006
88cb7938 1007 return rv ;
b0bba0af 1008}
b0bba0af 1009//____________________________________________________________________________
88cb7938 1010TTree * AliPHOSGetter::TreeP() const
0bc3b8ed 1011{
e957fea8 1012 // Returns pointer to the RecParticles Tree
88cb7938 1013 TTree * rv = 0 ;
1014 rv = PhosLoader()->TreeP() ;
1015 if ( !rv ) {
1016 PhosLoader()->MakeTree("P");
1017 rv = PhosLoader()->TreeP() ;
1018 }
4ae78bb1 1019
88cb7938 1020 return rv ;
b0bba0af 1021}
1022
1023//____________________________________________________________________________
88cb7938 1024TTree * AliPHOSGetter::TreeS() const
e957fea8 1025{
1026 // Returns pointer to the SDigits Tree
88cb7938 1027 TTree * rv = 0 ;
1028 rv = PhosLoader()->TreeS() ;
1029 if ( !rv ) {
1030 PhosLoader()->MakeTree("S");
1031 rv = PhosLoader()->TreeS() ;
b0bba0af 1032 }
b0bba0af 1033
88cb7938 1034 return rv ;
b0bba0af 1035}
7a9d98f9 1036
b0bba0af 1037//____________________________________________________________________________
88cb7938 1038Bool_t AliPHOSGetter::VersionExists(TString & opt) const
1039{
1040 // checks if the version with the present name already exists in the same directory
7a9d98f9 1041
88cb7938 1042 Bool_t rv = kFALSE ;
1043
1044 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
1045 TString version( rl->GetEventFolder()->GetName() ) ;
7a9d98f9 1046
88cb7938 1047 opt.ToLower() ;
b0bba0af 1048
88cb7938 1049 if ( opt == "sdigits") {
1050 // add the version name to the root file name
1051 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 1052 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1053 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1054 if ( !(gSystem->AccessPathName(fileName)) ) {
1055 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1056 rv = kTRUE ;
4ae78bb1 1057 }
88cb7938 1058 PhosLoader()->SetSDigitsFileName(fileName) ;
b0bba0af 1059 }
7a9d98f9 1060
88cb7938 1061 if ( opt == "digits") {
1062 // add the version name to the root file name
1063 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 1064 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1065 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1066 if ( !(gSystem->AccessPathName(fileName)) ) {
1067 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1068 rv = kTRUE ;
7a9d98f9 1069 }
b0bba0af 1070 }
7a9d98f9 1071
88cb7938 1072 return rv ;
7a9d98f9 1073
b0bba0af 1074}
88cb7938 1075
7bb289a7 1076//____________________________________________________________________________
88cb7938 1077UShort_t AliPHOSGetter::EventPattern(void) const
0bc3b8ed 1078{
1079 // Return the pattern (trigger bit register) of the beam-test event
7bb289a7 1080 if(fBTE)
1081 return fBTE->GetPattern() ;
1082 else
1083 return 0 ;
1084}
1085//____________________________________________________________________________
88cb7938 1086Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 1087{
1088 // Return the beam energy of the beam-test event
7bb289a7 1089 if(fBTE)
1090 return fBTE->GetBeamEnergy() ;
1091 else
1092 return 0 ;
1093}
7ca0684e 1094//____________________________________________________________________________
1095
1096AliPHOSCalibData* AliPHOSGetter::CalibData()
1097{
ef868168 1098 // Check if the instance of AliPHOSCalibData exists, and return it
7ca0684e 1099
2bb77d5e 1100 return fgCalibData;
7ca0684e 1101}