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>
49 //#include <TCanvas.h>
52 // --- Standard library ---
54 // --- AliRoot header files ---
56 #include "AliHeader.h"
59 #include "AliPHOSBeamTestEvent.h"
60 #include "AliPHOSGetter.h"
61 #include "AliPHOSLoader.h"
62 #include "AliRunLoader.h"
64 #include "AliPHOSRawStream.h"
65 #include "AliRawReaderFile.h"
68 ClassImp(AliPHOSGetter)
70 AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ;
71 AliPHOSLoader * AliPHOSGetter::fgPhosLoader = 0;
72 Int_t AliPHOSGetter::fgDebug = 0;
74 // TFile * AliPHOSGetter::fgFile = 0 ;
76 //____________________________________________________________________________
77 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* version, Option_t * openingOption)
79 // ctor only called by Instance()
81 AliRunLoader* rl = AliRunLoader::GetRunLoader(version) ;
83 rl = AliRunLoader::Open(headerFile, version, openingOption);
85 Fatal("AliPHOSGetter", "Could not find the Run Loader for %s - %s",headerFile, version) ;
88 if (rl->GetAliRun() == 0x0) {
90 gAlice = rl->GetAliRun(); // should be removed
93 fgPhosLoader = dynamic_cast<AliPHOSLoader*>(rl->GetLoader("PHOSLoader"));
95 Error("AliPHOSGetter", "Could not find PHOSLoader") ;
97 fgPhosLoader->SetTitle(version);
99 // initialize data members
103 fLoadingStatus = "" ;
105 fESDFileName = rl->GetFileName() ; // this should be the galice.root file
106 fESDFileName.ReplaceAll("galice.root", "AliESDs.root") ;
110 fRawDigits = kFALSE ;
113 //____________________________________________________________________________
114 AliPHOSGetter::~AliPHOSGetter()
118 delete fgPhosLoader ;
126 fPrimaries->Delete() ;
137 //____________________________________________________________________________
138 void AliPHOSGetter::Reset()
140 // resets things in case the getter is called consecutively with different files
141 // the PHOS Loader is already deleted by the Run Loader
144 fPrimaries->Delete() ;
151 //____________________________________________________________________________
152 AliPHOSClusterizer * AliPHOSGetter::Clusterizer()
154 // Returns pointer to the Clusterizer task
155 AliPHOSClusterizer * rv ;
156 rv = dynamic_cast<AliPHOSClusterizer *>(PhosLoader()->Reconstructioner()) ;
159 rv = dynamic_cast<AliPHOSClusterizer*>(PhosLoader()->Reconstructioner()) ;
164 //____________________________________________________________________________
165 TObjArray * AliPHOSGetter::CpvRecPoints()
167 // asks the Loader to return the CPV RecPoints container
171 rv = PhosLoader()->CpvRecPoints() ;
173 PhosLoader()->MakeRecPointsArray() ;
174 rv = PhosLoader()->CpvRecPoints() ;
179 //____________________________________________________________________________
180 TClonesArray * AliPHOSGetter::Digits()
182 // asks the Loader to return the Digits container
184 TClonesArray * rv = 0 ;
185 rv = PhosLoader()->Digits() ;
188 PhosLoader()->MakeDigitsArray() ;
189 rv = PhosLoader()->Digits() ;
194 //____________________________________________________________________________
195 AliPHOSDigitizer * AliPHOSGetter::Digitizer()
197 // Returns pointer to the Digitizer task
198 AliPHOSDigitizer * rv ;
199 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
202 rv = dynamic_cast<AliPHOSDigitizer *>(PhosLoader()->Digitizer()) ;
208 //____________________________________________________________________________
209 TObjArray * AliPHOSGetter::EmcRecPoints()
211 // asks the Loader to return the EMC RecPoints container
215 rv = PhosLoader()->EmcRecPoints() ;
217 PhosLoader()->MakeRecPointsArray() ;
218 rv = PhosLoader()->EmcRecPoints() ;
223 //____________________________________________________________________________
224 TClonesArray * AliPHOSGetter::TrackSegments()
226 // asks the Loader to return the TrackSegments container
228 TClonesArray * rv = 0 ;
230 rv = PhosLoader()->TrackSegments() ;
232 PhosLoader()->MakeTrackSegmentsArray() ;
233 rv = PhosLoader()->TrackSegments() ;
238 //____________________________________________________________________________
239 AliPHOSTrackSegmentMaker * AliPHOSGetter::TrackSegmentMaker()
241 // Returns pointer to the TrackSegmentMaker task
242 AliPHOSTrackSegmentMaker * rv ;
243 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
246 rv = dynamic_cast<AliPHOSTrackSegmentMaker *>(PhosLoader()->TrackSegmentMaker()) ;
251 //____________________________________________________________________________
252 TClonesArray * AliPHOSGetter::RecParticles()
254 // asks the Loader to return the TrackSegments container
256 TClonesArray * rv = 0 ;
258 rv = PhosLoader()->RecParticles() ;
260 PhosLoader()->MakeRecParticlesArray() ;
261 rv = PhosLoader()->RecParticles() ;
265 //____________________________________________________________________________
266 void AliPHOSGetter::Event(Int_t event, const char* opt)
268 // Reads the content of all Tree's S, D and R
270 // if ( event >= MaxEvent() ) {
271 // Error("Event", "%d not found in TreeE !", event) ;
275 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
277 // // checks if we are dealing with test-beam data
278 // TBranch * btb = rl->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
281 // fBTE = new AliPHOSBeamTestEvent() ;
282 // btb->SetAddress(&fBTE) ;
283 // btb->GetEntry(event) ;
292 // Loads the type of object(s) requested
294 rl->GetEvent(event) ;
296 if(strstr(opt,"X") || (strcmp(opt,"")==0)){
300 if(strstr(opt,"H") ){
304 if(strstr(opt,"S") ){
308 if(strstr(opt,"D") ){
312 if(strstr(opt,"R") ){
316 if( strstr(opt,"T") ){
320 if( strstr(opt,"P") ){
324 if( strstr(opt,"E") ){
331 //____________________________________________________________________________
332 void AliPHOSGetter::Event(AliRawReader *rawReader, const char* opt)
334 // Reads the raw event from rawReader
336 if( strstr(opt,"W") ){
343 //____________________________________________________________________________
344 Int_t AliPHOSGetter::EventNumber() const
346 // return the current event number
347 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
348 return static_cast<Int_t>(rl->GetEventNumber()) ;
351 //____________________________________________________________________________
352 TClonesArray * AliPHOSGetter::Hits()
354 // asks the loader to return the Hits container
356 TClonesArray * rv = 0 ;
358 rv = PhosLoader()->Hits() ;
360 PhosLoader()->LoadHits("read");
361 rv = PhosLoader()->Hits() ;
366 //____________________________________________________________________________
367 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
369 // Creates and returns the pointer of the unique instance
370 // Must be called only when the environment has changed
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(AliRawReader *rawReader)
555 // reads the raw format data, converts it into digits format and store digits in Digits()
558 AliPHOSRawStream in(rawReader);
560 TClonesArray * digits = Digits() ;
564 while ( in.Next() ) { // PHOS entries loop
566 Int_t amp = in.GetSignal() ;
567 Double_t time = in.GetTime() ;
570 relId[0] = in.GetModule() ;
571 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
572 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
575 relId[2] = in.GetRow() ;
576 relId[3] = in.GetColumn() ;
577 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
579 if (amp > 0 && id >=0 ) {
580 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
584 } // PHOS entries loop
588 return digits->GetEntriesFast() ;
590 //____________________________________________________________________________
591 Int_t AliPHOSGetter::ReadTreeD()
595 PhosLoader()->CleanDigits() ;
596 PhosLoader()->LoadDigits("UPDATE") ;
597 PhosLoader()->LoadDigitizer("UPDATE") ;
598 return Digits()->GetEntries() ;
601 //____________________________________________________________________________
602 Int_t AliPHOSGetter::ReadTreeH()
605 PhosLoader()->CleanHits() ;
606 // gets TreeH from the root file (PHOS.Hit.root)
607 //if ( !IsLoaded("H") ) {
608 PhosLoader()->LoadHits("UPDATE") ;
611 return Hits()->GetEntries() ;
614 //____________________________________________________________________________
615 Int_t AliPHOSGetter::ReadTreeR()
617 // Read the RecPoints
619 PhosLoader()->CleanRecPoints() ;
620 // gets TreeR from the root file (PHOS.RecPoints.root)
621 //if ( !IsLoaded("R") ) {
622 PhosLoader()->LoadRecPoints("UPDATE") ;
623 PhosLoader()->LoadClusterizer("UPDATE") ;
627 return EmcRecPoints()->GetEntries() ;
630 //____________________________________________________________________________
631 Int_t AliPHOSGetter::ReadTreeT()
633 // Read the TrackSegments
635 PhosLoader()->CleanTracks() ;
636 // gets TreeT from the root file (PHOS.TrackSegments.root)
637 //if ( !IsLoaded("T") ) {
638 PhosLoader()->LoadTracks("UPDATE") ;
639 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
643 return TrackSegments()->GetEntries() ;
645 //____________________________________________________________________________
646 Int_t AliPHOSGetter::ReadTreeP()
648 // Read the RecParticles
650 PhosLoader()->CleanRecParticles() ;
652 // gets TreeT from the root file (PHOS.TrackSegments.root)
653 // if ( !IsLoaded("P") ) {
654 PhosLoader()->LoadRecParticles("UPDATE") ;
655 PhosLoader()->LoadPID("UPDATE") ;
659 return RecParticles()->GetEntries() ;
661 //____________________________________________________________________________
662 Int_t AliPHOSGetter::ReadTreeS()
666 PhosLoader()->CleanSDigits() ;
667 // gets TreeS from the root file (PHOS.SDigits.root)
668 //if ( !IsLoaded("S") ) {
669 PhosLoader()->LoadSDigits("READ") ;
670 PhosLoader()->LoadSDigitizer("READ") ;
674 return SDigits()->GetEntries() ;
677 //____________________________________________________________________________
678 Int_t AliPHOSGetter::ReadTreeE(Int_t event)
682 // gets esdTree from the root file (AliESDs.root)
684 if ( !OpenESDFile() )
687 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
691 Error("ReadTreeE", "no ESD tree found");
694 fESDTree->SetBranchAddress("ESD", &fESD);
695 fESDTree->GetEvent(event);
700 //____________________________________________________________________________
701 TClonesArray * AliPHOSGetter::SDigits()
703 // asks the Loader to return the Digits container
705 TClonesArray * rv = 0 ;
707 rv = PhosLoader()->SDigits() ;
709 PhosLoader()->MakeSDigitsArray() ;
710 rv = PhosLoader()->SDigits() ;
715 //____________________________________________________________________________
716 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
718 // Returns pointer to the SDigitizer task
719 AliPHOSSDigitizer * rv ;
720 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
723 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
728 //____________________________________________________________________________
729 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
731 // Return first (index=1) or second (index=2) secondary particle of primary particle p
739 Int_t daughterIndex = p->GetDaughter(index-1) ;
740 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
741 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
747 //____________________________________________________________________________
748 void AliPHOSGetter::Track(Int_t itrack)
750 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
752 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
754 if( !TreeH() ) // load treeH the first time
757 // first time create the container
758 TClonesArray * hits = Hits() ;
762 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
763 phosbranch->SetAddress(&hits) ;
764 phosbranch->GetEntry(itrack) ;
767 //____________________________________________________________________________
768 TTree * AliPHOSGetter::TreeD() const
770 // Returns pointer to the Digits Tree
772 rv = PhosLoader()->TreeD() ;
774 PhosLoader()->MakeTree("D");
775 rv = PhosLoader()->TreeD() ;
781 //____________________________________________________________________________
782 TTree * AliPHOSGetter::TreeH() const
784 // Returns pointer to the Hits Tree
786 rv = PhosLoader()->TreeH() ;
788 PhosLoader()->MakeTree("H");
789 rv = PhosLoader()->TreeH() ;
795 //____________________________________________________________________________
796 TTree * AliPHOSGetter::TreeR() const
798 // Returns pointer to the RecPoints Tree
800 rv = PhosLoader()->TreeR() ;
802 PhosLoader()->MakeTree("R");
803 rv = PhosLoader()->TreeR() ;
809 //____________________________________________________________________________
810 TTree * AliPHOSGetter::TreeT() const
812 // Returns pointer to the TrackSegments Tree
814 rv = PhosLoader()->TreeT() ;
816 PhosLoader()->MakeTree("T");
817 rv = PhosLoader()->TreeT() ;
822 //____________________________________________________________________________
823 TTree * AliPHOSGetter::TreeP() const
825 // Returns pointer to the RecParticles Tree
827 rv = PhosLoader()->TreeP() ;
829 PhosLoader()->MakeTree("P");
830 rv = PhosLoader()->TreeP() ;
836 //____________________________________________________________________________
837 TTree * AliPHOSGetter::TreeS() const
839 // Returns pointer to the SDigits Tree
841 rv = PhosLoader()->TreeS() ;
843 PhosLoader()->MakeTree("S");
844 rv = PhosLoader()->TreeS() ;
850 //____________________________________________________________________________
851 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
853 // checks if the version with the present name already exists in the same directory
857 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
858 TString version( rl->GetEventFolder()->GetName() ) ;
862 if ( opt == "sdigits") {
863 // add the version name to the root file name
864 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
865 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
866 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
867 if ( !(gSystem->AccessPathName(fileName)) ) {
868 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
871 PhosLoader()->SetSDigitsFileName(fileName) ;
874 if ( opt == "digits") {
875 // add the version name to the root file name
876 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
877 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
878 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
879 if ( !(gSystem->AccessPathName(fileName)) ) {
880 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
889 //____________________________________________________________________________
890 UShort_t AliPHOSGetter::EventPattern(void) const
892 // Return the pattern (trigger bit register) of the beam-test event
894 return fBTE->GetPattern() ;
898 //____________________________________________________________________________
899 Float_t AliPHOSGetter::BeamEnergy(void) const
901 // Return the beam energy of the beam-test event
903 return fBTE->GetBeamEnergy() ;