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