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") ){
328 if( strstr(opt,"W") ){
335 //____________________________________________________________________________
336 Int_t AliPHOSGetter::EventNumber() const
338 // return the current event number
339 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
340 return static_cast<Int_t>(rl->GetEventNumber()) ;
343 //____________________________________________________________________________
344 TClonesArray * AliPHOSGetter::Hits()
346 // asks the loader to return the Hits container
348 TClonesArray * rv = 0 ;
350 rv = PhosLoader()->Hits() ;
352 PhosLoader()->LoadHits("read");
353 rv = PhosLoader()->Hits() ;
358 //____________________________________________________________________________
359 AliPHOSGetter * AliPHOSGetter::Instance(const char* alirunFileName, const char* version, Option_t * openingOption)
361 // Creates and returns the pointer of the unique instance
362 // Must be called only when the environment has changed
364 //::Info("Instance","alirunFileName=%s version=%s openingOption=%s",alirunFileName,version,openingOption);
366 if(!fgObjGetter){ // first time the getter is called
367 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
369 else { // the getter has been called previously
370 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
371 if ( rl->GetFileName() == alirunFileName ) {// the alirunFile has the same name
372 // check if the file is already open
373 TFile * galiceFile = dynamic_cast<TFile *>(gROOT->FindObject(rl->GetFileName()) ) ;
376 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
378 else { // the file is already open check the version name
379 TString currentVersionName = rl->GetEventFolder()->GetName() ;
380 TString newVersionName(version) ;
381 if (currentVersionName == newVersionName)
383 ::Warning( "Instance", "Files with version %s already open", currentVersionName.Data() ) ;
385 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
390 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle()) ;
391 if ( strstr(version, AliConfig::GetDefaultEventFolderName()) ) // false in case of merging
393 fgObjGetter = new AliPHOSGetter(alirunFileName, version, openingOption) ;
397 ::Error("AliPHOSGetter::Instance", "Failed to create the PHOS Getter object") ;
405 //____________________________________________________________________________
406 AliPHOSGetter * AliPHOSGetter::Instance()
408 // Returns the pointer of the unique instance already defined
410 if(!fgObjGetter && fgDebug)
411 ::Warning("AliPHOSGetter::Instance", "Getter not initialized") ;
417 //____________________________________________________________________________
418 Int_t AliPHOSGetter::MaxEvent() const
420 // returns the number of events in the run (from TE)
422 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
423 return static_cast<Int_t>(rl->GetNumberOfEvents()) ;
426 //____________________________________________________________________________
427 TParticle * AliPHOSGetter::Primary(Int_t index) const
429 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
430 return rl->Stack()->Particle(index) ;
433 //____________________________________________________________________________
434 AliPHOS * AliPHOSGetter:: PHOS() const
436 // returns the PHOS object
437 AliPHOSLoader * loader = 0;
438 static AliPHOSLoader * oldloader = 0;
439 static AliPHOS * phos = 0;
441 loader = PhosLoader();
443 if ( loader != oldloader) {
444 phos = dynamic_cast<AliPHOS*>(loader->GetModulesFolder()->FindObject("PHOS")) ;
449 Warning("PHOS", "PHOS module not found in module folders: %s", PhosLoader()->GetModulesFolder()->GetName() ) ;
455 //____________________________________________________________________________
456 AliPHOSPID * AliPHOSGetter::PID()
458 // Returns pointer to the PID task
460 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
463 rv = dynamic_cast<AliPHOSPID *>(PhosLoader()->PIDTask()) ;
468 //____________________________________________________________________________
469 AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() const
471 // Returns PHOS geometry
473 AliPHOSGeometry * rv = 0 ;
475 rv = PHOS()->GetGeometry() ;
479 //____________________________________________________________________________
480 TClonesArray * AliPHOSGetter::Primaries()
482 // creates the Primaries container if needed
485 Info("Primaries", "Creating a new TClonesArray for primaries") ;
486 fPrimaries = new TClonesArray("TParticle", 1000) ;
491 //____________________________________________________________________________
492 void AliPHOSGetter::Print()
494 // Print usefull information about the getter
496 AliRunLoader * rl = AliRunLoader::GetRunLoader(fgPhosLoader->GetTitle());
497 ::Info( "Print", "gAlice file is %s -- version name is %s", (rl->GetFileName()).Data(), rl->GetEventFolder()->GetName() ) ;
500 //____________________________________________________________________________
501 void AliPHOSGetter::ReadPrimaries()
503 // Read Primaries from Kinematics.root
505 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
507 // gets kine tree from the root file (Kinematics.root)
508 if ( ! rl->TreeK() ) { // load treeK the first time
509 rl->LoadKinematics() ;
512 fNPrimaries = (rl->GetHeader())->GetNtrack();
514 Info( "ReadTreeK", "Found %d particles in event # %d", fNPrimaries, EventNumber() ) ;
517 // first time creates the container
519 fPrimaries->Clear() ;
522 for (index = 0 ; index < fNPrimaries; index++) {
523 new ((*fPrimaries)[index]) TParticle(*(Primary(index)));
527 //____________________________________________________________________________
528 Bool_t AliPHOSGetter::OpenESDFile()
533 fESDFile = TFile::Open(fESDFileName) ;
537 else if (fESDFile->IsOpen()) {
539 fESDFile = TFile::Open(fESDFileName) ;
541 if (!fESDFile->IsOpen())
546 //____________________________________________________________________________
547 Int_t AliPHOSGetter::ReadRaw(Int_t event)
549 // reads the raw format data, converts it into digits format and store digits in Digits()
552 AliRawReaderFile rawReader(event) ;
553 AliPHOSRawStream in(&rawReader);
555 TClonesArray * digits = Digits() ;
559 while ( in.Next() ) { // PHOS entries loop
561 Int_t amp = in.GetSignal() ;
562 Double_t time = in.GetTime() ;
565 relId[0] = in.GetModule() ;
566 if ( relId[0] >= PHOS()->GetRawFormatLowGainOffset() ) {
567 relId[0] -= PHOS()->GetRawFormatLowGainOffset() ;
570 relId[2] = in.GetRow() ;
571 relId[3] = in.GetColumn() ;
572 PHOSGeometry()->RelToAbsNumbering(relId, id) ;
574 if (amp > 0 && id >=0 ) {
575 new((*digits)[idigit]) AliPHOSDigit( -1, id, amp, time) ;
579 } // PHOS entries loop
583 return digits->GetEntriesFast() ;
585 //____________________________________________________________________________
586 Int_t AliPHOSGetter::ReadTreeD()
590 PhosLoader()->CleanDigits() ;
591 PhosLoader()->LoadDigits("UPDATE") ;
592 PhosLoader()->LoadDigitizer("UPDATE") ;
593 return Digits()->GetEntries() ;
596 //____________________________________________________________________________
597 Int_t AliPHOSGetter::ReadTreeH()
600 PhosLoader()->CleanHits() ;
601 // gets TreeH from the root file (PHOS.Hit.root)
602 //if ( !IsLoaded("H") ) {
603 PhosLoader()->LoadHits("UPDATE") ;
606 return Hits()->GetEntries() ;
609 //____________________________________________________________________________
610 Int_t AliPHOSGetter::ReadTreeR()
612 // Read the RecPoints
614 PhosLoader()->CleanRecPoints() ;
615 // gets TreeR from the root file (PHOS.RecPoints.root)
616 //if ( !IsLoaded("R") ) {
617 PhosLoader()->LoadRecPoints("UPDATE") ;
618 PhosLoader()->LoadClusterizer("UPDATE") ;
622 return EmcRecPoints()->GetEntries() ;
625 //____________________________________________________________________________
626 Int_t AliPHOSGetter::ReadTreeT()
628 // Read the TrackSegments
630 PhosLoader()->CleanTracks() ;
631 // gets TreeT from the root file (PHOS.TrackSegments.root)
632 //if ( !IsLoaded("T") ) {
633 PhosLoader()->LoadTracks("UPDATE") ;
634 PhosLoader()->LoadTrackSegmentMaker("UPDATE") ;
638 return TrackSegments()->GetEntries() ;
640 //____________________________________________________________________________
641 Int_t AliPHOSGetter::ReadTreeP()
643 // Read the RecParticles
645 PhosLoader()->CleanRecParticles() ;
647 // gets TreeT from the root file (PHOS.TrackSegments.root)
648 // if ( !IsLoaded("P") ) {
649 PhosLoader()->LoadRecParticles("UPDATE") ;
650 PhosLoader()->LoadPID("UPDATE") ;
654 return RecParticles()->GetEntries() ;
656 //____________________________________________________________________________
657 Int_t AliPHOSGetter::ReadTreeS()
661 PhosLoader()->CleanSDigits() ;
662 // gets TreeS from the root file (PHOS.SDigits.root)
663 //if ( !IsLoaded("S") ) {
664 PhosLoader()->LoadSDigits("READ") ;
665 PhosLoader()->LoadSDigitizer("READ") ;
669 return SDigits()->GetEntries() ;
672 //____________________________________________________________________________
673 Int_t AliPHOSGetter::ReadTreeE(Int_t event)
677 // gets esdTree from the root file (AliESDs.root)
679 if ( !OpenESDFile() )
682 fESDTree = static_cast<TTree*>(fESDFile->Get("esdTree")) ;
686 Error("ReadTreeE", "no ESD tree found");
689 fESDTree->SetBranchAddress("ESD", &fESD);
690 fESDTree->GetEvent(event);
695 //____________________________________________________________________________
696 TClonesArray * AliPHOSGetter::SDigits()
698 // asks the Loader to return the Digits container
700 TClonesArray * rv = 0 ;
702 rv = PhosLoader()->SDigits() ;
704 PhosLoader()->MakeSDigitsArray() ;
705 rv = PhosLoader()->SDigits() ;
710 //____________________________________________________________________________
711 AliPHOSSDigitizer * AliPHOSGetter::SDigitizer()
713 // Returns pointer to the SDigitizer task
714 AliPHOSSDigitizer * rv ;
715 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
718 rv = dynamic_cast<AliPHOSSDigitizer *>(PhosLoader()->SDigitizer()) ;
723 //____________________________________________________________________________
724 TParticle * AliPHOSGetter::Secondary(const TParticle* p, Int_t index) const
726 // Return first (index=1) or second (index=2) secondary particle of primary particle p
734 Int_t daughterIndex = p->GetDaughter(index-1) ;
735 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
736 return rl->GetAliRun()->GetMCApp()->Particle(daughterIndex) ;
742 //____________________________________________________________________________
743 void AliPHOSGetter::Track(Int_t itrack)
745 // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
747 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
749 if( !TreeH() ) // load treeH the first time
752 // first time create the container
753 TClonesArray * hits = Hits() ;
757 TBranch * phosbranch = dynamic_cast<TBranch*>(TreeH()->GetBranch("PHOS")) ;
758 phosbranch->SetAddress(&hits) ;
759 phosbranch->GetEntry(itrack) ;
762 //____________________________________________________________________________
763 TTree * AliPHOSGetter::TreeD() const
765 // Returns pointer to the Digits Tree
767 rv = PhosLoader()->TreeD() ;
769 PhosLoader()->MakeTree("D");
770 rv = PhosLoader()->TreeD() ;
776 //____________________________________________________________________________
777 TTree * AliPHOSGetter::TreeH() const
779 // Returns pointer to the Hits Tree
781 rv = PhosLoader()->TreeH() ;
783 PhosLoader()->MakeTree("H");
784 rv = PhosLoader()->TreeH() ;
790 //____________________________________________________________________________
791 TTree * AliPHOSGetter::TreeR() const
793 // Returns pointer to the RecPoints Tree
795 rv = PhosLoader()->TreeR() ;
797 PhosLoader()->MakeTree("R");
798 rv = PhosLoader()->TreeR() ;
804 //____________________________________________________________________________
805 TTree * AliPHOSGetter::TreeT() const
807 // Returns pointer to the TrackSegments Tree
809 rv = PhosLoader()->TreeT() ;
811 PhosLoader()->MakeTree("T");
812 rv = PhosLoader()->TreeT() ;
817 //____________________________________________________________________________
818 TTree * AliPHOSGetter::TreeP() const
820 // Returns pointer to the RecParticles Tree
822 rv = PhosLoader()->TreeP() ;
824 PhosLoader()->MakeTree("P");
825 rv = PhosLoader()->TreeP() ;
831 //____________________________________________________________________________
832 TTree * AliPHOSGetter::TreeS() const
834 // Returns pointer to the SDigits Tree
836 rv = PhosLoader()->TreeS() ;
838 PhosLoader()->MakeTree("S");
839 rv = PhosLoader()->TreeS() ;
845 //____________________________________________________________________________
846 Bool_t AliPHOSGetter::VersionExists(TString & opt) const
848 // checks if the version with the present name already exists in the same directory
852 AliRunLoader * rl = AliRunLoader::GetRunLoader(PhosLoader()->GetTitle());
853 TString version( rl->GetEventFolder()->GetName() ) ;
857 if ( opt == "sdigits") {
858 // add the version name to the root file name
859 TString fileName( PhosLoader()->GetSDigitsFileName() ) ;
860 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
861 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
862 if ( !(gSystem->AccessPathName(fileName)) ) {
863 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
866 PhosLoader()->SetSDigitsFileName(fileName) ;
869 if ( opt == "digits") {
870 // add the version name to the root file name
871 TString fileName( PhosLoader()->GetDigitsFileName() ) ;
872 if (version != AliConfig::GetDefaultEventFolderName()) // only if not the default folder name
873 fileName = fileName.ReplaceAll(".root", "") + "_" + version + ".root" ;
874 if ( !(gSystem->AccessPathName(fileName)) ) {
875 Warning("VersionExists", "The file %s already exists", fileName.Data()) ;
884 //____________________________________________________________________________
885 UShort_t AliPHOSGetter::EventPattern(void) const
887 // Return the pattern (trigger bit register) of the beam-test event
889 return fBTE->GetPattern() ;
893 //____________________________________________________________________________
894 Float_t AliPHOSGetter::BeamEnergy(void) const
896 // Return the beam energy of the beam-test event
898 return fBTE->GetBeamEnergy() ;