]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSGetter.cxx
3-par fitting for better quality estimate
[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"
7d87fe94 73#include "AliPHOSReconstructor.h"
74#include "AliPHOSRecoParam.h"
88cb7938 75
4ae78bb1 76ClassImp(AliPHOSGetter)
77
2bb77d5e 78AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
79AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
80AliPHOSCalibData* AliPHOSGetter::fgCalibData = 0;
88cb7938 81Int_t AliPHOSGetter::fgDebug = 0;
82
83// TFile * AliPHOSGetter::fgFile = 0 ;
4ae78bb1 84
3663622c 85AliPHOSGetter::AliPHOSGetter() :
86 fBTE(0),
87 fLoadingStatus(),
88 fNPrimaries(0),
89 fPrimaries(0),
90 fESDFile(0),
91 fESDFileName(),
92 fESD(0),
93 fESDTree(0),
94 fRawDigits(kFALSE),
95 fcdb(0)
96{
97 // ctor: this is a singleton, the ctor should never be called but cint needs it as public
98 Fatal("ctor", "AliPHOSGetter is a singleton default ctor not callable") ;
99}
100
101
4ae78bb1 102//____________________________________________________________________________
3663622c 103AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption) :
104 fBTE(0),
105 fLoadingStatus(),
106 fNPrimaries(0),
107 fPrimaries(0),
108 fESDFile(0),
109 fESDFileName(),
110 fESD(0),
111 fESDTree(0),
112 fRawDigits(kFALSE),
113 fcdb(0)
4ae78bb1 114{
88cb7938 115 // ctor only called by Instance()
4ae78bb1 116
88cb7938 117 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
118 if (!rl) {
119 rl = AliRunLoader::Open(headerFile, version, openingOption);
120 if (!rl) {
121 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
122 return ;
123 }
124 if (rl->GetAliRun() == 0x0) {
125 rl->LoadgAlice();
126 gAlice = rl->GetAliRun(); // should be removed
12a7cec1 127 rl->LoadHeader();
88cb7938 128 }
fbf811ec 129 }
88cb7938 130 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
131 if ( !fgPhosLoader )
132 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
133 else
134 fgPhosLoader->SetTitle(version);
135
88cb7938 136 // initialize data members
137 SetDebug(0) ;
138 fBTE = 0 ;
139 fPrimaries = 0 ;
140 fLoadingStatus = "" ;
d2713783 141
142 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
143 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
95635748 144 fESDFile = 0 ;
677c8a30 145 fESD = 0 ;
146 fESDTree = 0 ;
66f895c8 147 fRawDigits = kFALSE ;
7ca0684e 148
88cb7938 149}
9bd3caba 150
3663622c 151AliPHOSGetter::AliPHOSGetter(const AliPHOSGetter & obj) :
152 TObject(obj),
153 fBTE(0),
154 fLoadingStatus(),
155 fNPrimaries(0),
156 fPrimaries(0),
157 fESDFile(0),
158 fESDFileName(),
159 fESD(0),
160 fESDTree(0),
161 fRawDigits(kFALSE),
162 fcdb(0)
163{
164 // cpy ctor requested by Coding Convention
165 Fatal("cpy ctor", "not implemented") ;
166}
167
168//____________________________________________________________________________
169AliPHOSGetter::AliPHOSGetter(Int_t /*i*/) :
170 fBTE(0),
171 fLoadingStatus(),
172 fNPrimaries(0),
173 fPrimaries(0),
174 fESDFile(0),
175 fESDFileName(),
176 fESD(0),
177 fESDTree(0),
178 fRawDigits(kFALSE),
179 fcdb(0)
180{
181 // special constructor for onflight
182}
183
184
88cb7938 185//____________________________________________________________________________
186AliPHOSGetter::~AliPHOSGetter()
187{
188 // dtor
66f895c8 189 if(fgPhosLoader){
190 delete fgPhosLoader ;
191 fgPhosLoader = 0 ;
192 }
193 if(fBTE){
194 delete fBTE ;
195 fBTE = 0 ;
196 }
197 if(fPrimaries){
198 fPrimaries->Delete() ;
199 delete fPrimaries ;
200 }
677c8a30 201 if (fESD)
202 delete fESD ;
203 if (fESDTree)
66f895c8 204 delete fESDTree ;
205
7c193632 206 fgObjGetter = 0;
0ef40383 207}
208
209//____________________________________________________________________________
210void AliPHOSGetter::Reset()
211{
212 // resets things in case the getter is called consecutively with different files
213 // the PHOS Loader is already deleted by the Run Loader
214
215 if (fPrimaries) {
216 fPrimaries->Delete() ;
217 delete fPrimaries ;
218 }
219 fgPhosLoader = 0;
220 fgObjGetter = 0;
88cb7938 221}
fbf811ec 222
88cb7938 223//____________________________________________________________________________
224AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
225{
e957fea8 226 // Returns pointer to the Clusterizer task
88cb7938 227 AliPHOSClusterizer * rv ;
228 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
229 if (!rv) {
230 Event(0, "R") ;
231 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
232 }
233 return rv ;
234}
4ae78bb1 235
88cb7938 236//____________________________________________________________________________
2bb77d5e 237TObjArray * AliPHOSGetter::CpvRecPoints() const
88cb7938 238{
239 // asks the Loader to return the CPV RecPoints container
4ae78bb1 240
88cb7938 241 TObjArray * rv = 0 ;
242
243 rv = PhosLoader()->CpvRecPoints() ;
244 if (!rv) {
245 PhosLoader()->MakeRecPointsArray() ;
246 rv = PhosLoader()->CpvRecPoints() ;
247 }
248 return rv ;
249}
dca3a7c4 250
88cb7938 251//____________________________________________________________________________
2bb77d5e 252TClonesArray * AliPHOSGetter::Digits() const
88cb7938 253{
254 // asks the Loader to return the Digits container
7bb289a7 255
88cb7938 256 TClonesArray * rv = 0 ;
257 rv = PhosLoader()->Digits() ;
7bb289a7 258
88cb7938 259 if( !rv ) {
260 PhosLoader()->MakeDigitsArray() ;
261 rv = PhosLoader()->Digits() ;
4ae78bb1 262 }
88cb7938 263 return rv ;
264}
4b808d52 265
88cb7938 266//____________________________________________________________________________
267AliPHOSDigitizer * AliPHOSGetter::Digitizer()
268{
e957fea8 269 // Returns pointer to the Digitizer task
88cb7938 270 AliPHOSDigitizer * rv ;
271 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
272 if (!rv) {
273 Event(0, "D") ;
274 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
275 }
276 return rv ;
4ae78bb1 277}
fbf811ec 278
88cb7938 279
4ae78bb1 280//____________________________________________________________________________
2bb77d5e 281TObjArray * AliPHOSGetter::EmcRecPoints() const
0bc3b8ed 282{
88cb7938 283 // asks the Loader to return the EMC RecPoints container
d489fb96 284
88cb7938 285 TObjArray * rv = 0 ;
65549808 286
88cb7938 287 rv = PhosLoader()->EmcRecPoints() ;
288 if (!rv) {
289 PhosLoader()->MakeRecPointsArray() ;
290 rv = PhosLoader()->EmcRecPoints() ;
89165262 291 }
88cb7938 292 return rv ;
81bb1a45 293}
7a9d98f9 294
65549808 295//____________________________________________________________________________
2bb77d5e 296TClonesArray * AliPHOSGetter::TrackSegments() const
65549808 297{
88cb7938 298 // asks the Loader to return the TrackSegments container
299
300 TClonesArray * rv = 0 ;
301
302 rv = PhosLoader()->TrackSegments() ;
303 if (!rv) {
304 PhosLoader()->MakeTrackSegmentsArray() ;
305 rv = PhosLoader()->TrackSegments() ;
306 }
307 return rv ;
65549808 308}
4ae78bb1 309
0c87da39 310//____________________________________________________________________________
e957fea8 311AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
88cb7938 312{
e957fea8 313 // Returns pointer to the TrackSegmentMaker task
88cb7938 314 AliPHOSTrackSegmentMaker * rv ;
315 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
316 if (!rv) {
317 Event(0, "T") ;
318 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
0c87da39 319 }
88cb7938 320 return rv ;
0c87da39 321}
322
4ae78bb1 323//____________________________________________________________________________
2bb77d5e 324TClonesArray * AliPHOSGetter::RecParticles() const
4ae78bb1 325{
88cb7938 326 // asks the Loader to return the TrackSegments container
327
328 TClonesArray * rv = 0 ;
4ae78bb1 329
88cb7938 330 rv = PhosLoader()->RecParticles() ;
331 if (!rv) {
332 PhosLoader()->MakeRecParticlesArray() ;
333 rv = PhosLoader()->RecParticles() ;
b134c32f 334 }
88cb7938 335 return rv ;
4ae78bb1 336}
4ae78bb1 337//____________________________________________________________________________
fc7e2f43 338void AliPHOSGetter::Event(Int_t event, const char* opt)
4ae78bb1 339{
88cb7938 340 // Reads the content of all Tree's S, D and R
548f0134 341
66f895c8 342// if ( event >= MaxEvent() ) {
343// Error("Event", "%d not found in TreeE !", event) ;
344// return ;
345// }
4ae78bb1 346
88cb7938 347 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
df25f7dd 348
66f895c8 349// // checks if we are dealing with test-beam data
350// TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
351// if(btb){
352// if(!fBTE)
353// fBTE = new AliPHOSBeamTestEvent() ;
354// btb->SetAddress(&fBTE) ;
355// btb->GetEntry(event) ;
356// }
357// else{
358// if(fBTE){
359// delete fBTE ;
360// fBTE = 0 ;
361// }
362// }
88cb7938 363
364 // Loads the type of object(s) requested
b134c32f 365
88cb7938 366 rl->GetEvent(event) ;
367
66f895c8 368 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
88cb7938 369 ReadPrimaries() ;
66f895c8 370 }
371
372 if(strstr(opt,"H") ){
88cb7938 373 ReadTreeH();
66f895c8 374 }
375
376 if(strstr(opt,"S") ){
88cb7938 377 ReadTreeS() ;
66f895c8 378 }
379
380 if(strstr(opt,"D") ){
88cb7938 381 ReadTreeD() ;
66f895c8 382 }
383
384 if(strstr(opt,"R") ){
88cb7938 385 ReadTreeR() ;
66f895c8 386 }
88cb7938 387
66f895c8 388 if( strstr(opt,"T") ){
88cb7938 389 ReadTreeT() ;
66f895c8 390 }
88cb7938 391
66f895c8 392 if( strstr(opt,"P") ){
88cb7938 393 ReadTreeP() ;
66f895c8 394 }
677c8a30 395
66f895c8 396 if( strstr(opt,"E") ){
677c8a30 397 ReadTreeE(event) ;
3cf4f75f 398 }
399
400}
401
402
403//____________________________________________________________________________
f5eaa851 404void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt, Bool_t isOldRCUFormat)
3cf4f75f 405{
406 // Reads the raw event from rawReader
f5eaa851 407 // isOldRCUFormat defines whenever to assume
408 // the old RCU format or not
f88e2313 409
3cf4f75f 410 if( strstr(opt,"W") ){
e1c29d81 411 rawReader->NextEvent();
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 {
ad4aeaf4 471 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
431a9211 645 // Create a shaper pulse object which contains all the shaper parameters
75d640cb 646 AliPHOSPulseGenerator pulse;
431a9211 647
45c1ce6f 648 if (lowGainFlag) {
649 timezero1 = timezero2 = signalmax = timemax = 0. ;
75d640cb 650 signalF->FixParameter(0, pulse.GetRawFormatLowCharge()) ;
651 signalF->FixParameter(1, pulse.GetRawFormatLowGain()) ;
45c1ce6f 652 Int_t index ;
75d640cb 653 for (index = 0; index < pulse.GetRawFormatTimeBins(); index++) {
45c1ce6f 654 gLowGain->GetPoint(index, time, signal) ;
655 if (signal > kNoiseThreshold && timezero1 == 0.)
656 timezero1 = time ;
657 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
658 timezero2 = time ;
659 if (signal > signalmax) {
660 signalmax = signal ;
661 timemax = time ;
662 }
663 }
431a9211 664 signalmax /=
75d640cb 665 pulse.RawResponseFunctionMax(pulse.GetRawFormatLowCharge(),
666 pulse.GetRawFormatLowGain()) ;
667 if ( timezero1 + pulse.GetRawFormatTimePeak() < pulse.GetRawFormatTimeMax() * 0.4 ) { // else its noise
45c1ce6f 668 signalF->SetParameter(2, signalmax) ;
669 signalF->SetParameter(3, timezero1) ;
2bb77d5e 670 gLowGain->Fit(signalF, "QRO", "", 0., timezero2); //, "QRON") ;
45c1ce6f 671 energy = signalF->GetParameter(2) ;
75d640cb 672 time = signalF->GetMaximumX() - pulse.GetRawFormatTimePeak() - pulse.GetRawFormatTimeTrigger() ;
45c1ce6f 673 }
674 } else {
675 timezero1 = timezero2 = signalmax = timemax = 0. ;
75d640cb 676 signalF->FixParameter(0, pulse.GetRawFormatHighCharge()) ;
677 signalF->FixParameter(1, pulse.GetRawFormatHighGain()) ;
45c1ce6f 678 Int_t index ;
75d640cb 679 for (index = 0; index < pulse.GetRawFormatTimeBins(); index++) {
45c1ce6f 680 gHighGain->GetPoint(index, time, signal) ;
681 if (signal > kNoiseThreshold && timezero1 == 0.)
682 timezero1 = time ;
683 if (signal <= kNoiseThreshold && timezero1 > 0. && timezero2 == 0.)
684 timezero2 = time ;
685 if (signal > signalmax) {
686 signalmax = signal ;
687 timemax = time ;
688 }
689 }
75d640cb 690 signalmax /= pulse.RawResponseFunctionMax(pulse.GetRawFormatHighCharge(),
691 pulse.GetRawFormatHighGain()) ;;
692 if ( timezero1 + pulse.GetRawFormatTimePeak() < pulse.GetRawFormatTimeMax() * 0.4 ) { // else its noise
45c1ce6f 693 signalF->SetParameter(2, signalmax) ;
694 signalF->SetParameter(3, timezero1) ;
2bb77d5e 695 gHighGain->Fit(signalF, "QRO", "", 0., timezero2) ;
45c1ce6f 696 energy = signalF->GetParameter(2) ;
75d640cb 697 time = signalF->GetMaximumX() - pulse.GetRawFormatTimePeak() - pulse.GetRawFormatTimeTrigger() ;
45c1ce6f 698 }
699 }
44ae287e 700 if (time == 0) energy = 0 ;
45c1ce6f 701}
702
44ae287e 703//____________________________________________________________________________
704Int_t AliPHOSGetter::CalibrateRaw(Double_t energy, Int_t *relId)
705{
706 // Convert energy into digitized amplitude for a cell relId
707 // It is a user responsilibity to open CDB and set
708 // AliPHOSCalibData object by the following operators:
709 //
710 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
711 // AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
712 // ->Get(path_to_calibdata,run_number);
713 // AliPHOSGetter* gime = AliPHOSGetter::Instance("galice.root");
714 // gime->SetCalibData(clb);
715
716 if (CalibData() == 0)
f88e2313 717 Warning("CalibrateRaw","Calibration DB is not initiated!");
44ae287e 718
719 Int_t module = relId[0];
f88e2313 720 Int_t column = relId[3];
721 Int_t row = relId[2];
722
723 Float_t gainFactor = 0.0015; // width of one Emc ADC channel in GeV
724 Float_t pedestal = 0.005; // Emc pedestals
725
726 if(CalibData()) {
727 gainFactor = CalibData()->GetADCchannelEmc (module,column,row);
728 pedestal = CalibData()->GetADCpedestalEmc(module,column,row);
729 }
730
44ae287e 731 Int_t amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ;
732 return amp;
733}
a43c51c3 734//____________________________________________________________________________
f5eaa851 735Int_t AliPHOSGetter::ReadRaw(AliRawReader *rawReader,Bool_t isOldRCUFormat)
a43c51c3 736{
737 // reads the raw format data, converts it into digits format and store digits in Digits()
738 // container.
f5eaa851 739 // isOldRCUFormat = kTRUE in case of the old RCU
02e48b45 740 // format used in the raw data readout.
741 // Reimplemented by Boris Polichtchouk (Jul 2006)
742 // to make it working with the Jul-Aug 2006 beam test data.
743
a29c28b6 744 //Create raw decoder.
745
746 AliPHOSRawDecoder dc(rawReader);
747 dc.SetOldRCUFormat(isOldRCUFormat);
7d87fe94 748 dc.SubtractPedestals(AliPHOSReconstructor::GetRecoParamEmc()->SubtractPedestals());
45c1ce6f 749
a43c51c3 750 TClonesArray * digits = Digits() ;
4fc0021f 751 AliPHOSRawDigiProducer pr;
752 pr.MakeDigits(digits,&dc);
e212b6d1 753
754 //ADC counts -> GeV
755 for(Int_t i=0; i<digits->GetEntries(); i++) {
756 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(i);
757 digit->SetEnergy(digit->GetEnergy()/AliPHOSPulseGenerator::GeV2ADC());
758 }
759
69464fdb 760 //!!!!for debug!!!
761 Int_t modMax=-111;
762 Int_t colMax=-111;
763 Int_t rowMax=-111;
764 Float_t eMax=-333;
765 //!!!for debug!!!
766
4fc0021f 767 Int_t relId[4];
768 for(Int_t iDigit=0; iDigit<digits->GetEntries(); iDigit++) {
69464fdb 769 AliPHOSDigit* digit = (AliPHOSDigit*)digits->At(iDigit);
770 if(digit->GetEnergy()>eMax) {
771 PHOSGeometry()->AbsToRelNumbering(digit->GetId(),relId);
772 eMax=digit->GetEnergy();
773 modMax=relId[0];
774 rowMax=relId[2];
775 colMax=relId[3];
776 }
777 }
19309784 778
6a0d2265 779 AliDebug(1,Form("Digit with max. energy: modMax %d colMax %d rowMax %d eMax %f\n\n",
780 modMax,colMax,rowMax,eMax));
69464fdb 781
e4d04cf1 782 return digits->GetEntriesFast() ;
a43c51c3 783}
45c1ce6f 784
b0bba0af 785//____________________________________________________________________________
fd31ff92 786Int_t AliPHOSGetter::ReadTreeD() const
88cb7938 787{
788 // Read the Digits
b0bba0af 789
41c29fde 790 PhosLoader()->CleanDigits() ;
ff808dc7 791 PhosLoader()->LoadDigits("UPDATE") ;
792 PhosLoader()->LoadDigitizer("UPDATE") ;
88cb7938 793 return Digits()->GetEntries() ;
794}
7a9d98f9 795
b0bba0af 796//____________________________________________________________________________
fd31ff92 797Int_t AliPHOSGetter::ReadTreeH() const
88cb7938 798{
799 // Read the Hits
41c29fde 800 PhosLoader()->CleanHits() ;
88cb7938 801 // gets TreeH from the root file (PHOS.Hit.root)
41c29fde 802 //if ( !IsLoaded("H") ) {
88cb7938 803 PhosLoader()->LoadHits("UPDATE") ;
41c29fde 804 // SetLoaded("H") ;
805 //}
88cb7938 806 return Hits()->GetEntries() ;
807}
4ae78bb1 808
88cb7938 809//____________________________________________________________________________
fd31ff92 810Int_t AliPHOSGetter::ReadTreeR() const
88cb7938 811{
812 // Read the RecPoints
b0bba0af 813
41c29fde 814 PhosLoader()->CleanRecPoints() ;
88cb7938 815 // gets TreeR from the root file (PHOS.RecPoints.root)
41c29fde 816 //if ( !IsLoaded("R") ) {
88cb7938 817 PhosLoader()->LoadRecPoints("UPDATE") ;
41c29fde 818 // SetLoaded("R") ;
819 //}
f1611b7c 820
88cb7938 821 return EmcRecPoints()->GetEntries() ;
b0bba0af 822}
7a9d98f9 823
b0bba0af 824//____________________________________________________________________________
fd31ff92 825Int_t AliPHOSGetter::ReadTreeT() const
88cb7938 826{
827 // Read the TrackSegments
7a9d98f9 828
41c29fde 829 PhosLoader()->CleanTracks() ;
88cb7938 830 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 831 //if ( !IsLoaded("T") ) {
88cb7938 832 PhosLoader()->LoadTracks("UPDATE") ;
833 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
41c29fde 834 // SetLoaded("T") ;
835 //}
fbf811ec 836
88cb7938 837 return TrackSegments()->GetEntries() ;
838}
b0bba0af 839//____________________________________________________________________________
fd31ff92 840Int_t AliPHOSGetter::ReadTreeP() const
88cb7938 841{
41c29fde 842 // Read the RecParticles
88cb7938 843
41c29fde 844 PhosLoader()->CleanRecParticles() ;
845
88cb7938 846 // gets TreeT from the root file (PHOS.TrackSegments.root)
41c29fde 847 // if ( !IsLoaded("P") ) {
88cb7938 848 PhosLoader()->LoadRecParticles("UPDATE") ;
849 PhosLoader()->LoadPID("UPDATE") ;
41c29fde 850 // SetLoaded("P") ;
851 //}
7a9d98f9 852
88cb7938 853 return RecParticles()->GetEntries() ;
854}
855//____________________________________________________________________________
fd31ff92 856Int_t AliPHOSGetter::ReadTreeS() const
88cb7938 857{
858 // Read the SDigits
859
41c29fde 860 PhosLoader()->CleanSDigits() ;
88cb7938 861 // gets TreeS from the root file (PHOS.SDigits.root)
41c29fde 862 //if ( !IsLoaded("S") ) {
7b4c1168 863 PhosLoader()->LoadSDigits("READ") ;
864 PhosLoader()->LoadSDigitizer("READ") ;
41c29fde 865 // SetLoaded("S") ;
866 //}
b0bba0af 867
88cb7938 868 return SDigits()->GetEntries() ;
869}
f1611b7c 870
677c8a30 871//____________________________________________________________________________
872Int_t AliPHOSGetter::ReadTreeE(Int_t event)
873{
874 // Read the ESD
875
876 // gets esdTree from the root file (AliESDs.root)
877 if (!fESDFile)
878 if ( !OpenESDFile() )
879 return -1 ;
880
881 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
882 fESD = new AliESD;
883 if (!fESDTree) {
884
885 Error("ReadTreeE", "no ESD tree found");
886 return -1;
887 }
888 fESDTree->SetBranchAddress("ESD", &fESD);
889 fESDTree->GetEvent(event);
890
891 return event ;
892}
893
88cb7938 894//____________________________________________________________________________
2bb77d5e 895TClonesArray * AliPHOSGetter::SDigits() const
88cb7938 896{
897 // asks the Loader to return the Digits container
b0bba0af 898
88cb7938 899 TClonesArray * rv = 0 ;
900
901 rv = PhosLoader()->SDigits() ;
902 if (!rv) {
903 PhosLoader()->MakeSDigitsArray() ;
904 rv = PhosLoader()->SDigits() ;
905 }
906 return rv ;
b0bba0af 907}
908
909//____________________________________________________________________________
e957fea8 910AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
88cb7938 911{
e957fea8 912 // Returns pointer to the SDigitizer task
88cb7938 913 AliPHOSSDigitizer * rv ;
914 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
915 if (!rv) {
916 Event(0, "S") ;
917 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
b0bba0af 918 }
88cb7938 919 return rv ;
b0bba0af 920}
7a9d98f9 921
b0bba0af 922//____________________________________________________________________________
fc7e2f43 923TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
88cb7938 924{
925 // Return first (index=1) or second (index=2) secondary particle of primary particle p
926
927 if(index <= 0)
928 return 0 ;
929 if(index > 2)
930 return 0 ;
b0bba0af 931
88cb7938 932 if(p) {
933 Int_t daughterIndex = p->GetDaughter(index-1) ;
934 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
5d12ce38 935 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
88cb7938 936 }
937 else
938 return 0 ;
939}
4ae78bb1 940
88cb7938 941//____________________________________________________________________________
fc7e2f43 942void AliPHOSGetter::Track(Int_t itrack)
88cb7938 943{
944 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
945
946 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
b0bba0af 947
88cb7938 948 if( !TreeH() ) // load treeH the first time
949 rl->LoadHits() ;
b0bba0af 950
88cb7938 951 // first time create the container
952 TClonesArray * hits = Hits() ;
953 if ( hits )
954 hits->Clear() ;
b0bba0af 955
88cb7938 956 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
957 phosbranch->SetAddress(&hits) ;
958 phosbranch->GetEntry(itrack) ;
b0bba0af 959}
960
b0bba0af 961//____________________________________________________________________________
88cb7938 962TTree * AliPHOSGetter::TreeD() const
963{
e957fea8 964 // Returns pointer to the Digits Tree
88cb7938 965 TTree * rv = 0 ;
966 rv = PhosLoader()->TreeD() ;
967 if ( !rv ) {
968 PhosLoader()->MakeTree("D");
969 rv = PhosLoader()->TreeD() ;
b0bba0af 970 }
b0bba0af 971
88cb7938 972 return rv ;
b0bba0af 973}
548f0134 974
b0bba0af 975//____________________________________________________________________________
88cb7938 976TTree * AliPHOSGetter::TreeH() const
977{
e957fea8 978 // Returns pointer to the Hits Tree
88cb7938 979 TTree * rv = 0 ;
980 rv = PhosLoader()->TreeH() ;
981 if ( !rv ) {
982 PhosLoader()->MakeTree("H");
983 rv = PhosLoader()->TreeH() ;
984 }
985
986 return rv ;
b0bba0af 987}
7a9d98f9 988
b0bba0af 989//____________________________________________________________________________
88cb7938 990TTree * AliPHOSGetter::TreeR() const
0bc3b8ed 991{
e957fea8 992 // Returns pointer to the RecPoints Tree
88cb7938 993 TTree * rv = 0 ;
994 rv = PhosLoader()->TreeR() ;
995 if ( !rv ) {
996 PhosLoader()->MakeTree("R");
997 rv = PhosLoader()->TreeR() ;
998 }
b0bba0af 999
88cb7938 1000 return rv ;
b0bba0af 1001}
1002
b0bba0af 1003//____________________________________________________________________________
88cb7938 1004TTree * AliPHOSGetter::TreeT() const
0bc3b8ed 1005{
e957fea8 1006 // Returns pointer to the TrackSegments Tree
88cb7938 1007 TTree * rv = 0 ;
1008 rv = PhosLoader()->TreeT() ;
1009 if ( !rv ) {
1010 PhosLoader()->MakeTree("T");
1011 rv = PhosLoader()->TreeT() ;
1012 }
b0bba0af 1013
88cb7938 1014 return rv ;
b0bba0af 1015}
b0bba0af 1016//____________________________________________________________________________
88cb7938 1017TTree * AliPHOSGetter::TreeP() const
0bc3b8ed 1018{
e957fea8 1019 // Returns pointer to the RecParticles Tree
88cb7938 1020 TTree * rv = 0 ;
1021 rv = PhosLoader()->TreeP() ;
1022 if ( !rv ) {
1023 PhosLoader()->MakeTree("P");
1024 rv = PhosLoader()->TreeP() ;
1025 }
4ae78bb1 1026
88cb7938 1027 return rv ;
b0bba0af 1028}
1029
1030//____________________________________________________________________________
88cb7938 1031TTree * AliPHOSGetter::TreeS() const
e957fea8 1032{
1033 // Returns pointer to the SDigits Tree
88cb7938 1034 TTree * rv = 0 ;
1035 rv = PhosLoader()->TreeS() ;
1036 if ( !rv ) {
1037 PhosLoader()->MakeTree("S");
1038 rv = PhosLoader()->TreeS() ;
b0bba0af 1039 }
b0bba0af 1040
88cb7938 1041 return rv ;
b0bba0af 1042}
7a9d98f9 1043
b0bba0af 1044//____________________________________________________________________________
88cb7938 1045Bool_t AliPHOSGetter::VersionExists(TString & opt) const
1046{
1047 // checks if the version with the present name already exists in the same directory
7a9d98f9 1048
88cb7938 1049 Bool_t rv = kFALSE ;
1050
1051 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
1052 TString version( rl->GetEventFolder()->GetName() ) ;
7a9d98f9 1053
88cb7938 1054 opt.ToLower() ;
b0bba0af 1055
88cb7938 1056 if ( opt == "sdigits") {
1057 // add the version name to the root file name
1058 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
e191bb57 1059 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1060 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1061 if ( !(gSystem->AccessPathName(fileName)) ) {
1062 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1063 rv = kTRUE ;
4ae78bb1 1064 }
88cb7938 1065 PhosLoader()->SetSDigitsFileName(fileName) ;
b0bba0af 1066 }
7a9d98f9 1067
88cb7938 1068 if ( opt == "digits") {
1069 // add the version name to the root file name
1070 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
e191bb57 1071 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
88cb7938 1072 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
1073 if ( !(gSystem->AccessPathName(fileName)) ) {
1074 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
1075 rv = kTRUE ;
7a9d98f9 1076 }
b0bba0af 1077 }
7a9d98f9 1078
88cb7938 1079 return rv ;
7a9d98f9 1080
b0bba0af 1081}
88cb7938 1082
7bb289a7 1083//____________________________________________________________________________
88cb7938 1084UShort_t AliPHOSGetter::EventPattern(void) const
0bc3b8ed 1085{
1086 // Return the pattern (trigger bit register) of the beam-test event
7bb289a7 1087 if(fBTE)
1088 return fBTE->GetPattern() ;
1089 else
1090 return 0 ;
1091}
1092//____________________________________________________________________________
88cb7938 1093Float_t AliPHOSGetter::BeamEnergy(void) const
0bc3b8ed 1094{
1095 // Return the beam energy of the beam-test event
7bb289a7 1096 if(fBTE)
1097 return fBTE->GetBeamEnergy() ;
1098 else
1099 return 0 ;
1100}
7ca0684e 1101//____________________________________________________________________________
1102
1103AliPHOSCalibData* AliPHOSGetter::CalibData()
1104{
ef868168 1105 // Check if the instance of AliPHOSCalibData exists, and return it
7ca0684e 1106
2bb77d5e 1107 return fgCalibData;
7ca0684e 1108}