1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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.
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) ;
32 // gime->Event(event) ; // reads new event from galice.root
34 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
35 //*-- Completely redesigned by Dmitri Peressounko March 2001
37 //*-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
38 //*-- systematic usage of TFolders without changing the interface
39 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
46 #include <TParticle.h>
50 //#include <TCanvas.h>
53 // --- Standard library ---
55 // --- AliRoot header files ---
57 #include "AliHeader.h"
60 #include "AliPHOSBeamTestEvent.h"
61 #include "AliPHOSGetter.h"
62 #include "AliPHOSLoader.h"
63 #include "AliRunLoader.h"
65 #include "AliPHOSRawStream.h"
66 #include "AliRawReaderFile.h"
69 ClassImp(AliPHOSGetter)
71 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
72 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
73 Int_t AliPHOSGetter::fgDebug = 0;
75 // TFile * AliPHOSGetter::fgFile = 0 ;
77 //____________________________________________________________________________
78 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
80 // ctor only called by Instance()
82 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
84 rl = AliRunLoader::Open(headerFile, version, openingOption);
86 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
89 if (rl->GetAliRun() == 0x0) {
91 gAlice = rl->GetAliRun(); // should be removed
94 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
96 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
98 fgPhosLoader->SetTitle(version);
100 // initialize data members
104 fLoadingStatus = "" ;
106 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
107 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
111 fRawDigits = kFALSE ;
114 //____________________________________________________________________________
115 AliPHOSGetter::~AliPHOSGetter()
119 delete fgPhosLoader ;
127 fPrimaries->Delete() ;
138 //____________________________________________________________________________
139 void AliPHOSGetter::Reset()
141 // resets things in case the getter is called consecutively with different files
142 // the PHOS Loader is already deleted by the Run Loader
145 fPrimaries->Delete() ;
152 //____________________________________________________________________________
153 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
155 // Returns pointer to the Clusterizer task
156 AliPHOSClusterizer * rv ;
157 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
160 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
165 //____________________________________________________________________________
166 TObjArray * AliPHOSGetter::CpvRecPoints()
168 // asks the Loader to return the CPV RecPoints container
172 rv = PhosLoader()->CpvRecPoints() ;
174 PhosLoader()->MakeRecPointsArray() ;
175 rv = PhosLoader()->CpvRecPoints() ;
180 //____________________________________________________________________________
181 TClonesArray * AliPHOSGetter::Digits()
183 // asks the Loader to return the Digits container
185 TClonesArray * rv = 0 ;
186 rv = PhosLoader()->Digits() ;
189 PhosLoader()->MakeDigitsArray() ;
190 rv = PhosLoader()->Digits() ;
195 //____________________________________________________________________________
196 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
198 // Returns pointer to the Digitizer task
199 AliPHOSDigitizer * rv ;
200 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
203 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
209 //____________________________________________________________________________
210 TObjArray * AliPHOSGetter::EmcRecPoints()
212 // asks the Loader to return the EMC RecPoints container
216 rv = PhosLoader()->EmcRecPoints() ;
218 PhosLoader()->MakeRecPointsArray() ;
219 rv = PhosLoader()->EmcRecPoints() ;
224 //____________________________________________________________________________
225 TClonesArray * AliPHOSGetter::TrackSegments()
227 // asks the Loader to return the TrackSegments container
229 TClonesArray * rv = 0 ;
231 rv = PhosLoader()->TrackSegments() ;
233 PhosLoader()->MakeTrackSegmentsArray() ;
234 rv = PhosLoader()->TrackSegments() ;
239 //____________________________________________________________________________
240 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
242 // Returns pointer to the TrackSegmentMaker task
243 AliPHOSTrackSegmentMaker * rv ;
244 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
247 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
252 //____________________________________________________________________________
253 TClonesArray * AliPHOSGetter::RecParticles()
255 // asks the Loader to return the TrackSegments container
257 TClonesArray * rv = 0 ;
259 rv = PhosLoader()->RecParticles() ;
261 PhosLoader()->MakeRecParticlesArray() ;
262 rv = PhosLoader()->RecParticles() ;
266 //____________________________________________________________________________
267 void AliPHOSGetter::Event(Int_t event, const char* opt)
269 // Reads the content of all Tree's S, D and R
271 // if ( event >= MaxEvent() ) {
272 // Error("Event", "%d not found in TreeE !", event) ;
276 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
278 // // checks if we are dealing with test-beam data
279 // TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
282 // fBTE = new AliPHOSBeamTestEvent() ;
283 // btb->SetAddress(&fBTE) ;
284 // btb->GetEntry(event) ;
293 // Loads the type of object(s) requested
295 rl->GetEvent(event) ;
297 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
301 if(strstr(opt,"H") ){
305 if(strstr(opt,"S") ){
309 if(strstr(opt,"D") ){
313 if(strstr(opt,"R") ){
317 if( strstr(opt,"T") ){
321 if( strstr(opt,"P") ){
325 if( strstr(opt,"E") ){
329 if( strstr(opt,"W") ){
334 // if( strstr(opt,"Q") && (fCurentEvent[9]!=event) )
341 //____________________________________________________________________________
342 Int_t AliPHOSGetter::EventNumber() const
344 // return the current event number
345 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
346 return static_cast<Int_t>(rl->GetEventNumber()) ;
349 //____________________________________________________________________________
350 TClonesArray * AliPHOSGetter::Hits()
352 // asks the loader to return the Hits container
354 TClonesArray * rv = 0 ;
356 rv = PhosLoader()->Hits() ;
358 PhosLoader()->LoadHits("read");
359 rv = PhosLoader()->Hits() ;
364 //____________________________________________________________________________
365 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
367 // Creates and returns the pointer of the unique instance
368 // Must be called only when the environment has changed
370 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
372 if(!fgObjGetter){ // first time the getter is called
373 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
375 else { // the getter has been called previously
376 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
377 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
378 // check if the file is already open
379 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
382 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
384 else { // the file is already open check the version name
385 TString currentVersionName = rl->GetEventFolder()->GetName() ;
386 TString newVersionName(version) ;
387 if (currentVersionName == newVersionName)
389 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
391 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
396 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
397 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
399 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
403 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
411 //____________________________________________________________________________
412 AliPHOSGetter * AliPHOSGetter::Instance()
414 // Returns the pointer of the unique instance already defined
416 if(!fgObjGetter && fgDebug)
417 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
423 //____________________________________________________________________________
424 Int_t AliPHOSGetter::MaxEvent() const
426 // returns the number of events in the run (from TE)
428 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
429 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
432 //____________________________________________________________________________
433 TParticle * AliPHOSGetter::Primary(Int_t index) const
435 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
436 return rl->Stack()->Particle(index) ;
439 //____________________________________________________________________________
440 AliPHOS * AliPHOSGetter:: PHOS() const
442 // returns the PHOS object
443 AliPHOSLoader * loader = 0;
444 static AliPHOSLoader * oldloader = 0;
445 static AliPHOS * phos = 0;
447 loader = PhosLoader();
449 if ( loader != oldloader) {
450 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
455 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
461 //____________________________________________________________________________
462 AliPHOSPID * AliPHOSGetter::PID()
464 // Returns pointer to the PID task
466 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
469 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
474 //____________________________________________________________________________
475 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
477 // Returns PHOS geometry
479 AliPHOSGeometry * rv = 0 ;
481 rv = PHOS()->GetGeometry() ;
485 //____________________________________________________________________________
486 TClonesArray * AliPHOSGetter::Primaries()
488 // creates the Primaries container if needed
491 Info("Primaries", "Creating a new TClonesArray for primaries") ;
492 fPrimaries = new TClonesArray("TParticle", 1000) ;
497 //____________________________________________________________________________
498 void AliPHOSGetter::Print()
500 // Print usefull information about the getter
502 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
503 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
506 //____________________________________________________________________________
507 void AliPHOSGetter::ReadPrimaries()
509 // Read Primaries from Kinematics.root
511 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
513 // gets kine tree from the root file (Kinematics.root)
514 if ( ! rl->TreeK() ) { // load treeK the first time
515 rl->LoadKinematics() ;
518 fNPrimaries = (rl->GetHeader())->GetNtrack();
520 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
523 // first time creates the container
525 fPrimaries->Clear() ;
528 for (index = 0 ; index < fNPrimaries; index++) {
529 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
533 //____________________________________________________________________________
534 Bool_t AliPHOSGetter::OpenESDFile()
539 fESDFile = TFile::Open(fESDFileName) ;
543 else if (fESDFile->IsOpen()) {
545 fESDFile = TFile::Open(fESDFileName) ;
547 if (!fESDFile->IsOpen())
552 //____________________________________________________________________________
553 Int_t AliPHOSGetter::ReadRaw(Int_t event)
555 // reads the raw format data, converts it into digits format and store digits in Digits()
558 AliRawReaderFile rawReader(event) ;
559 AliPHOSRawStream in(&rawReader);
561 TClonesArray * digits = Digits() ;
565 while ( in.Next() ) { // PHOS entries loop
567 Int_t amp = in.GetSignal() ;
568 Double_t time = in.GetTime() ;
571 relId[0] = in.GetModule() ;
572 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
573 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
576 relId[2] = in.GetRow() ;
577 relId[3] = in.GetColumn() ;
578 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
580 if (amp > 0 && id >=0 ) {
581 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
585 } // PHOS entries loop
589 return digits->GetEntriesFast() ;
591 //____________________________________________________________________________
592 Int_t AliPHOSGetter::ReadTreeD()
596 PhosLoader()->CleanDigits() ;
597 PhosLoader()->LoadDigits("UPDATE") ;
598 PhosLoader()->LoadDigitizer("UPDATE") ;
599 return Digits()->GetEntries() ;
602 //____________________________________________________________________________
603 Int_t AliPHOSGetter::ReadTreeH()
606 PhosLoader()->CleanHits() ;
607 // gets TreeH from the root file (PHOS.Hit.root)
608 //if ( !IsLoaded("H") ) {
609 PhosLoader()->LoadHits("UPDATE") ;
612 return Hits()->GetEntries() ;
615 //____________________________________________________________________________
616 Int_t AliPHOSGetter::ReadTreeR()
618 // Read the RecPoints
620 PhosLoader()->CleanRecPoints() ;
621 // gets TreeR from the root file (PHOS.RecPoints.root)
622 //if ( !IsLoaded("R") ) {
623 PhosLoader()->LoadRecPoints("UPDATE") ;
624 PhosLoader()->LoadClusterizer("UPDATE") ;
628 return EmcRecPoints()->GetEntries() ;
631 //____________________________________________________________________________
632 Int_t AliPHOSGetter::ReadTreeT()
634 // Read the TrackSegments
636 PhosLoader()->CleanTracks() ;
637 // gets TreeT from the root file (PHOS.TrackSegments.root)
638 //if ( !IsLoaded("T") ) {
639 PhosLoader()->LoadTracks("UPDATE") ;
640 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
644 return TrackSegments()->GetEntries() ;
646 //____________________________________________________________________________
647 Int_t AliPHOSGetter::ReadTreeP()
649 // Read the RecParticles
651 PhosLoader()->CleanRecParticles() ;
653 // gets TreeT from the root file (PHOS.TrackSegments.root)
654 // if ( !IsLoaded("P") ) {
655 PhosLoader()->LoadRecParticles("UPDATE") ;
656 PhosLoader()->LoadPID("UPDATE") ;
660 return RecParticles()->GetEntries() ;
662 //____________________________________________________________________________
663 Int_t AliPHOSGetter::ReadTreeS()
667 PhosLoader()->CleanSDigits() ;
668 // gets TreeS from the root file (PHOS.SDigits.root)
669 //if ( !IsLoaded("S") ) {
670 PhosLoader()->LoadSDigits("READ") ;
671 PhosLoader()->LoadSDigitizer("READ") ;
675 return SDigits()->GetEntries() ;
678 //____________________________________________________________________________
679 Int_t AliPHOSGetter::ReadTreeE(Int_t event)
683 // gets esdTree from the root file (AliESDs.root)
685 if ( !OpenESDFile() )
688 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
692 Error("ReadTreeE", "no ESD tree found");
695 fESDTree->SetBranchAddress("ESD", &fESD);
696 fESDTree->GetEvent(event);
701 //____________________________________________________________________________
702 TClonesArray * AliPHOSGetter::SDigits()
704 // asks the Loader to return the Digits container
706 TClonesArray * rv = 0 ;
708 rv = PhosLoader()->SDigits() ;
710 PhosLoader()->MakeSDigitsArray() ;
711 rv = PhosLoader()->SDigits() ;
716 //____________________________________________________________________________
717 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
719 // Returns pointer to the SDigitizer task
720 AliPHOSSDigitizer * rv ;
721 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
724 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
729 //____________________________________________________________________________
730 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
732 // Return first (index=1) or second (index=2) secondary particle of primary particle p
740 Int_t daughterIndex = p->GetDaughter(index-1) ;
741 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
742 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
748 //____________________________________________________________________________
749 void AliPHOSGetter::Track(Int_t itrack)
751 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
753 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
755 if( !TreeH() ) // load treeH the first time
758 // first time create the container
759 TClonesArray * hits = Hits() ;
763 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
764 phosbranch->SetAddress(&hits) ;
765 phosbranch->GetEntry(itrack) ;
768 //____________________________________________________________________________
769 TTree * AliPHOSGetter::TreeD() const
771 // Returns pointer to the Digits Tree
773 rv = PhosLoader()->TreeD() ;
775 PhosLoader()->MakeTree("D");
776 rv = PhosLoader()->TreeD() ;
782 //____________________________________________________________________________
783 TTree * AliPHOSGetter::TreeH() const
785 // Returns pointer to the Hits Tree
787 rv = PhosLoader()->TreeH() ;
789 PhosLoader()->MakeTree("H");
790 rv = PhosLoader()->TreeH() ;
796 //____________________________________________________________________________
797 TTree * AliPHOSGetter::TreeR() const
799 // Returns pointer to the RecPoints Tree
801 rv = PhosLoader()->TreeR() ;
803 PhosLoader()->MakeTree("R");
804 rv = PhosLoader()->TreeR() ;
810 //____________________________________________________________________________
811 TTree * AliPHOSGetter::TreeT() const
813 // Returns pointer to the TrackSegments Tree
815 rv = PhosLoader()->TreeT() ;
817 PhosLoader()->MakeTree("T");
818 rv = PhosLoader()->TreeT() ;
823 //____________________________________________________________________________
824 TTree * AliPHOSGetter::TreeP() const
826 // Returns pointer to the RecParticles Tree
828 rv = PhosLoader()->TreeP() ;
830 PhosLoader()->MakeTree("P");
831 rv = PhosLoader()->TreeP() ;
837 //____________________________________________________________________________
838 TTree * AliPHOSGetter::TreeS() const
840 // Returns pointer to the SDigits Tree
842 rv = PhosLoader()->TreeS() ;
844 PhosLoader()->MakeTree("S");
845 rv = PhosLoader()->TreeS() ;
851 //____________________________________________________________________________
852 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
854 // checks if the version with the present name already exists in the same directory
858 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
859 TString version( rl->GetEventFolder()->GetName() ) ;
863 if ( opt == "sdigits") {
864 // add the version name to the root file name
865 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
866 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
867 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
868 if ( !(gSystem->AccessPathName(fileName)) ) {
869 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
872 PhosLoader()->SetSDigitsFileName(fileName) ;
875 if ( opt == "digits") {
876 // add the version name to the root file name
877 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
878 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
879 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
880 if ( !(gSystem->AccessPathName(fileName)) ) {
881 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
890 //____________________________________________________________________________
891 UShort_t AliPHOSGetter::EventPattern(void) const
893 // Return the pattern (trigger bit register) of the beam-test event
895 return fBTE->GetPattern() ;
899 //____________________________________________________________________________
900 Float_t AliPHOSGetter::BeamEnergy(void) const
902 // Return the beam energy of the beam-test event
904 return fBTE->GetBeamEnergy() ;