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 AliEMCALAnalyser):
28 // for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
29 // AliEMCALRecParticle * part = gime->RecParticle(1) ;
31 // please->GetEvent(event) ; // reads new event from galice.root
33 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
34 //*-- Completely redesigned by Dmitri Peressounko March 2001
36 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
37 //*-- systematic usage of TFolders without changing the interface
38 //////////////////////////////////////////////////////////////////////////////
41 // --- ROOT system ---
45 // --- Standard library ---
47 // --- AliRoot header files ---
49 #include "AliEMCALGetter.h"
50 #include "AliEMCALHit.h"
51 #include "AliEMCALLoader.h"
53 #include "AliObjectLoader.h"
55 ClassImp(AliEMCALLoader)
58 const TString AliEMCALLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event
59 const TString AliEMCALLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray
60 const TString AliEMCALLoader::fgkDigitsName("DIGITS");//Name for TClonesArray
61 const TString AliEMCALLoader::fgkECARecPointsName("ECARECPOINTS");//Name for TClonesArray
62 const TString AliEMCALLoader::fgkTracksName("TRACKS");//Name for TClonesArray
63 const TString AliEMCALLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray
65 const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
66 const TString AliEMCALLoader::fgkTrackSegmentsBranchName("EMCALTS");//Name for branch with TrackSegments
67 const TString AliEMCALLoader::fgkRecParticlesBranchName("EMCALRP");//Name for branch with Reconstructed Particles
69 //____________________________________________________________________________
70 AliEMCALLoader::AliEMCALLoader()
73 fRecParticlesLoaded = kFALSE;
76 //____________________________________________________________________________
77 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
78 AliLoader(detname,eventfoldername)
81 fRecParticlesLoaded = kFALSE;
84 //____________________________________________________________________________
85 AliEMCALLoader::~AliEMCALLoader()
87 //remove and delete arrays
89 Clean(fgkSDigitsName);
91 Clean(fgkECARecPointsName);
93 Clean(fgkRecParticlesName);
95 // set to 0x0 the objgetter in AliGetter ... weird isn it !
97 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
103 //____________________________________________________________________________
104 void AliEMCALLoader::CleanFolders()
107 AliLoader::CleanFolders();
110 //____________________________________________________________________________
111 Int_t AliEMCALLoader::SetEvent()
113 //Cleans loaded stuff and and sets Files and Directories
114 // do not post any data to folder/tasks
117 Int_t retval = AliLoader::SetEvent();
120 Error("SetEvent","AliLoader::SetEvent returned error");
125 if (Hits()) Hits()->Clear();
126 if (SDigits()) SDigits()->Clear();
127 if (Digits()) Digits()->Clear();
128 if (ECARecPoints()) ECARecPoints()->Clear();
129 if (TrackSegments()) TrackSegments()->Clear();
130 if (RecParticles()) RecParticles()->Clear();
135 //____________________________________________________________________________
136 Int_t AliEMCALLoader::GetEvent()
138 //Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method
139 //to add Rec Particles specific for EMCAL
141 //First call the original method to get whatever from std. setup is needed
144 retval = AliLoader::GetEvent();
147 Error("GetEvent","AliLoader::GetEvent returned error");
151 if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits();
152 if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits();
153 if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits();
154 if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints();
155 if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks();
156 if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles();
159 //Now, check if RecPart were loaded
163 //____________________________________________________________________________
164 const AliEMCAL * AliEMCALLoader::EMCAL()
166 // returns the EMCAL object
167 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(GetModulesFolder()->FindObject(fDetectorName));
170 cout << "WARNING: AliEMCALLoader::EMCAL -> EMCAL module not found in Folders" << endl ;
174 //____________________________________________________________________________
175 const AliEMCALGeometry * AliEMCALLoader::EMCALGeometry()
177 // Gets the EMCAL Geometry object
178 AliEMCALGeometry * rv = 0 ;
180 rv = EMCAL()->GetGeometry();
184 //____________________________________________________________________________
185 Int_t AliEMCALLoader::LoadHits(Option_t* opt)
187 //------- Hits ----------------------
188 //Overload (extends) LoadHits implemented in AliLoader
192 //First call the AliLoader's method to send the TreeH to folder
193 res = AliLoader::LoadHits(opt);
197 AliError("returned error");
201 //read the data from tree in folder and send it to folder
206 //____________________________________________________________________________
207 Int_t AliEMCALLoader::LoadSDigits(Option_t* opt)
209 // Loads the SDigits array in the folder structure
211 //First call the AliLoader's method to send the TreeS to folder
212 res = AliLoader::LoadSDigits(opt);
215 Error("PostSDigits","AliLoader::LoadSDigits returned error");
218 return ReadSDigits();
222 //____________________________________________________________________________
223 Int_t AliEMCALLoader::LoadDigits(Option_t* opt)
225 // Loads the Digits array in the folder structure
228 //First call the AliLoader's method to send the TreeS to folder
229 res = AliLoader::LoadDigits(opt);
232 Error("LoadDigits","AliLoader::LoadDigits returned error");
238 //____________________________________________________________________________
239 Int_t AliEMCALLoader::LoadRecPoints(Option_t* opt)
241 // Loads the RecPoints array in the folder structure
243 //First call the AliLoader's method to send the TreeR to folder
244 res = AliLoader::LoadRecPoints(opt);
247 Error("LoadRecPoints","AliLoader::LoadRecPoints returned error");
251 TFolder * emcalFolder = GetDetectorDataFolder();
252 if ( emcalFolder == 0x0 )
254 Error("LoadRecPoints","Can not get detector data folder");
257 return ReadRecPoints();
260 //____________________________________________________________________________
261 Int_t AliEMCALLoader::LoadTracks(Option_t* opt)
263 //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts
264 AliDebug(1, Form("opt = %s",opt));
266 res = AliLoader::LoadTracks(opt);
269 AliError("returned error");
276 //____________________________________________________________________________
277 Int_t AliEMCALLoader::LoadRecParticles(Option_t* opt)
279 // Loads the RecParticles array in the folder structure
281 //First call the AliLoader's method to send the TreeS to folder
282 res = AliLoader::LoadRecParticles(opt);
285 Error("LoadRecParticles","AliLoader::LoadRecParticles returned error");
289 TFolder * emcalFolder = GetDetectorDataFolder();
290 if ( emcalFolder == 0x0 )
292 Error("PostDigits","Can not get detector data folder");
295 return ReadRecParticles();
298 //____________________________________________________________________________
299 Int_t AliEMCALLoader::PostHits()
302 Int_t reval = AliLoader::PostHits();
305 Error("PostHits","AliLoader:: returned error");
311 //____________________________________________________________________________
312 Int_t AliEMCALLoader::PostSDigits()
314 // Posts the SDigits array to the folder structure
315 Int_t reval = AliLoader::PostSDigits();
318 Error("PostSDigits","AliLoader::PostSDigits returned error");
321 return ReadSDigits();
324 //____________________________________________________________________________
325 Int_t AliEMCALLoader::PostDigits()
327 // Posts the Digits array to the folder structure
328 Int_t reval = AliLoader::PostDigits();
331 Error("PostDigits","AliLoader::PostDigits returned error");
337 //____________________________________________________________________________
338 Int_t AliEMCALLoader::PostRecPoints()
340 // Posts the RecPoints array to the folder structure
341 Int_t reval = AliLoader::PostRecPoints();
344 Error("PostRecPoints","AliLoader::PostRecPoints returned error");
347 return ReadRecPoints();
350 //____________________________________________________________________________
351 Int_t AliEMCALLoader::PostRecParticles()
353 // Posts the RecParticles array to the folder structure
355 Int_t reval = AliLoader::PostRecParticles();
358 Error("PostRecParticles","AliLoader::PostRecParticles returned error");
361 return ReadRecParticles();
364 //____________________________________________________________________________
365 Int_t AliEMCALLoader::PostTracks()
367 // Posts the Tracks array to the folder structure
368 Int_t reval = AliLoader::PostTracks();
371 Error("PostTracks","AliLoader::PostTracks returned error");
377 //____________________________________________________________________________
378 Int_t AliEMCALLoader::ReadHits()
380 // If there is no Clones Array in folder creates it and sends to folder
381 // then tries to read
382 // Reads the first entry of EMCAL branch in hit tree TreeH()
383 // Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder
385 TObject** hitref = HitsRef();
392 TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref);
394 TTree* treeh = TreeH();
398 AliError("Cannot read TreeH from folder");
402 TBranch * hitsbranch = treeh->GetBranch(fDetectorName);
405 AliError("Cannot find branch EMCAL");
409 AliDebug(1, "Reading Hits");
411 if (hitsbranch->GetEntries() > 1)
413 TClonesArray * tempo = new TClonesArray("AliEMCALHit",1000);
415 hitsbranch->SetAddress(&tempo);
418 for (i = 0 ; i < hitsbranch->GetEntries(); i++)
420 hitsbranch->GetEntry(i) ;
422 for ( j = 0 ; j < tempo->GetEntries() ; j++)
424 AliEMCALHit* hit = (AliEMCALHit*)tempo->At(j);
425 new((*hits)[index]) AliEMCALHit( *hit ) ;
434 hitsbranch->SetAddress(hitref);
435 hitsbranch->GetEntry(0) ;
441 //____________________________________________________________________________
442 Int_t AliEMCALLoader::ReadSDigits()
444 // Read the summable digits tree TreeS():
445 // Check if TClones is in folder
446 // if not create and add to folder
447 // connect to tree if available
450 TObject** sdref = SDigitsRef();
454 sdref = SDigitsRef();
457 TTree * treeS = TreeS();
460 //May happen if file is truncated or new in LoadSDigits
461 //Error("ReadSDigits","There is no SDigit Tree");
465 TBranch * branch = treeS->GetBranch(fDetectorName);
467 {//easy, maybe just a new tree
468 //Error("ReadSDigits"," Cannot find branch EMCAL");
472 branch->SetAddress(SDigitsRef());
477 //____________________________________________________________________________
478 Int_t AliEMCALLoader::ReadDigits()
480 // Read the summable digits tree TreeS():
481 // Check if TClones is in folder
482 // if not create and add to folder
483 // connect to tree if available
486 TObject** dref = DigitsRef();
488 {//if there is not array in folder, create it and put it there
493 TTree * treeD = TreeD();
496 //May happen if file is truncated or new in LoadSDigits
497 //Error("ReadDigits","There is no Digit Tree");
501 TBranch * branch = treeD->GetBranch(fDetectorName);
503 {//easy, maybe just a new tree
504 //Error("ReadDigits"," Cannot find branch ",fDetectorName.Data());
508 branch->SetAddress(dref);//connect branch to buffer sitting in folder
509 branch->GetEntry(0);//get first event
514 //____________________________________________________________________________
515 void AliEMCALLoader::UnloadRecParticles()
517 // Unloads the RecParticles array fromthe folder structure
518 fRecParticlesLoaded = kFALSE;
520 if (fTracksLoaded == kFALSE) UnloadTracks();
523 //____________________________________________________________________________
524 void AliEMCALLoader::UnloadTracks()
526 // Unloads the Tracks array fromthe folder structure
527 CleanTracks();//free the memory
528 //in case RecPart are loaded we can not onload tree and close the file
529 if (fRecParticlesLoaded == kFALSE) AliLoader::UnloadTracks();
530 fTracksLoaded = kFALSE;//mark that nobody needs them
533 //____________________________________________________________________________
534 void AliEMCALLoader::Track(Int_t itrack)
536 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
541 Error("Track","Can not load hits.");
546 TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
549 cout << "WARNING: AliEMCALLoader::ReadTreeH -> Cannot find branch EMCAL" << endl ;
552 if(!Hits()) PostHits();
554 hitsbranch->SetAddress(HitsRef());
555 hitsbranch->GetEntry(itrack);
559 //____________________________________________________________________________
560 Int_t AliEMCALLoader::ReadRecPoints()
562 //Creates and posts to folder an array container,
563 //connects branch in tree (if exists), and reads data to array
565 MakeRecPointsArray();
567 TObjArray * eca = 0x0 ;
569 TTree * treeR = TreeR();
573 //May happen if file is truncated or new in LoadSDigits
579 TBranch * ecabranch = treeR->GetBranch(fgkECARecPointsBranchName);
580 if (ecabranch == 0x0)
582 Error("ReadRecPoints","Can not get branch with ECA Rec. Points named %s",fgkECARecPointsBranchName.Data());
587 ecabranch->SetAddress(&eca);
588 ecabranch->GetEntry(0) ;
594 Int_t maxeca = eca->GetEntries() ;
595 for ( ii= 0 ; ii < maxeca ; ii++ )
596 ECARecPoints()->Add(eca->At(ii)) ;
601 //____________________________________________________________________________
602 Int_t AliEMCALLoader::ReadTracks()
604 //Creates and posts to folder an array container,
605 //connects branch in tree (if exists), and reads data to arry
607 TObject** trkref = TracksRef();
609 {//Create and post array
610 MakeTrackSegmentsArray();
611 trkref = TracksRef();
614 TTree * treeT = TreeT();
617 //May happen if file is truncated or new in LoadSDigits, or the file is in update mode,
618 //but tracking was not performed yet for a current event
619 //Error("ReadTracks","There is no Tree with Tracks");
623 TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
625 {//easy, maybe just a new tree
626 Error("ReadTracks"," Cannot find branch named %s",fgkTrackSegmentsBranchName.Data());
630 branch->SetAddress(trkref);//connect branch to buffer sitting in folder
631 branch->GetEntry(0);//get first event
636 //____________________________________________________________________________
637 Int_t AliEMCALLoader::ReadRecParticles()
639 //Reads Reconstructed Particles from file
640 //Creates and posts to folder an array container,
641 //connects branch in tree (if exists), and reads data to arry
643 TObject** recpartref = RecParticlesRef();
645 if ( recpartref == 0x0 )
646 {//Create and post array
647 MakeRecParticlesArray();
648 recpartref = RecParticlesRef();
651 TTree * treeP = TreeP();
654 //May happen if file is truncated or new in LoadSDigits,
655 //or the file is in update mode,
656 //but tracking was not performed yet for a current event
657 // Error("ReadRecParticles","There is no Tree with Tracks and Reconstructed Particles");
661 TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
663 {//easy, maybe just a new tree
664 Error("ReadRecParticles"," Cannot find branch %s",fgkRecParticlesBranchName.Data());
668 branch->SetAddress(recpartref);//connect branch to buffer sitting in folder
669 branch->GetEntry(0);//get first event
674 //____________________________________________________________________________
675 AliEMCALGeometry* AliEMCALLoader::GetEMCALGeometry()
677 //returns EMCAL geometry from gAlice
678 //static Method used by some classes where it is not convienient to pass eventfoldername
681 AliEMCAL* emcal=dynamic_cast<AliEMCAL*>(gAlice->GetDetector("EMCAL"));
684 return emcal->GetGeometry();
687 //____________________________________________________________________________
688 AliEMCALLoader* AliEMCALLoader::GetEMCALLoader(const char* eventfoldername)
690 // Get an instance of the EMCALLoader object
691 AliRunLoader* rn = AliRunLoader::GetRunLoader(eventfoldername);
694 cerr<<"Error: <AliEMCALLoader::GetEMCALLoader>: "
695 << "Can not find Run Loader in folder "<<eventfoldername<<endl;
698 return dynamic_cast<AliEMCALLoader*>(rn->GetLoader("EMCALLoader"));
701 //____________________________________________________________________________
702 Bool_t AliEMCALLoader::BranchExists(const TString& recName)
704 // Check is branch exists
705 if (fBranchTitle.IsNull()) return kFALSE;
706 TString dataname, zername ;
708 if(recName == "SDigits") {
710 dataname = GetDetectorName();
711 zername = "AliEMCALSDigitizer" ;
713 else if(recName == "Digits"){
715 dataname = GetDetectorName();
716 zername = "AliEMCALDigitizer" ;
718 else if(recName == "ECARecPoints"){
720 dataname = fgkECARecPointsBranchName;
721 zername = "AliEMCALClusterizer" ;
723 else if(recName == "TrackSegments"){
725 dataname = fgkTrackSegmentsBranchName;
726 zername = "AliEMCALTrackSegmentMaker";
728 else if(recName == "RecParticles"){
730 dataname = fgkRecParticlesBranchName;
731 zername = "AliEMCALPID";
739 TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
741 TBranch * branch = 0 ;
742 TString titleName(fBranchTitle);
745 while ((branch = (static_cast<TBranch*>(next())))) {
746 TString branchName(branch->GetName() ) ;
747 TString branchTitle(branch->GetTitle() ) ;
748 if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){
749 Warning("BranchExists","branch %s with title %s ",dataname.Data(),fBranchTitle.Data());
752 if ( branchName.BeginsWith(zername) && branchTitle.BeginsWith(titleName) ){
753 Warning("BranchExists","branch AliEMCAL... with title %s ",branch->GetTitle());
761 //____________________________________________________________________________
762 void AliEMCALLoader::SetBranchTitle(const TString& btitle)
764 // Gives a name to a branch in the folder structure
765 if (btitle.CompareTo(fBranchTitle) == 0) return;
766 fBranchTitle = btitle;
770 //____________________________________________________________________________
771 void AliEMCALLoader::CleanHits()
774 AliLoader::CleanHits();
776 TClonesArray* hits = Hits();
781 //____________________________________________________________________________
782 void AliEMCALLoader::CleanSDigits()
784 // Cleans the SDigits array in the folder structure
785 AliLoader::CleanSDigits();
786 TClonesArray* sdigits = SDigits();
787 if (sdigits) sdigits->Clear();
790 //____________________________________________________________________________
792 void AliEMCALLoader::CleanDigits()
794 // Cleans the Digits array in the folder structure
795 AliLoader::CleanDigits();
796 TClonesArray* digits = Digits();
797 if (digits) digits->Clear();
800 //____________________________________________________________________________
801 void AliEMCALLoader::CleanRecPoints()
803 // Cleans the RecPoints array in the folder structure
804 AliLoader::CleanRecPoints();
805 TObjArray* recpoints = ECARecPoints();
806 if (recpoints) recpoints->Clear();
810 //____________________________________________________________________________
811 void AliEMCALLoader::CleanTracks()
813 // Cleans the Tracks array in the folder structure
814 AliLoader::CleanTracks();//tree
815 //and clear the array
816 TClonesArray* tracks = TrackSegments();
821 //____________________________________________________________________________
822 void AliEMCALLoader::CleanRecParticles()
824 // Cleans the RecParticles array in the folder structure
825 TClonesArray *recpar = RecParticles();
830 //____________________________________________________________________________
831 // void AliEMCALLoader::ReadCalibrationDB(const char * database,const char * filename)
834 // if(fcdb && (strcmp(database,fcdb->GetTitle())==0))
837 // TFile * file = gROOT->GetFile(filename) ;
839 // file = TFile::Open(filename);
841 // Error ("ReadCalibrationDB", "Cannot open file %s", filename) ;
846 // fcdb = dynamic_cast<AliEMCALCalibrationDB *>(file->Get("AliEMCALCalibrationDB")) ;
848 // Error ("ReadCalibrationDB", "No database %s in file %s", database, filename) ;
850 //____________________________________________________________________________
852 // AliEMCALSDigitizer* AliEMCALLoader::EMCALSDigitizer()
854 // //return EMCAL SDigitizer
855 // return dynamic_cast<AliEMCALSDigitizer*>(SDigitizer()) ;
858 //____________________________________________________________________________
859 void AliEMCALLoader::MakeHitsArray()
861 // Create the array for Hits
863 TClonesArray* hits = new TClonesArray("AliEMCALHit",1000);
864 hits->SetName(fgkHitsName);
865 GetDetectorDataFolder()->Add(hits);
868 //____________________________________________________________________________
869 void AliEMCALLoader::MakeSDigitsArray()
871 // Create the array for SDigits
872 if ( SDigits()) return;
873 TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",1);
874 sdigits->SetName(fgkSDigitsName);
875 GetDetectorDataFolder()->Add(sdigits);
878 //____________________________________________________________________________
879 void AliEMCALLoader::MakeDigitsArray()
881 // Create the array for Digits
882 if ( Digits()) return;
883 TClonesArray* digits = new TClonesArray("AliEMCALDigit",1);
884 digits->SetName(fgkDigitsName);
885 GetDetectorDataFolder()->Add(digits);
889 //____________________________________________________________________________
890 void AliEMCALLoader::MakeRecPointsArray()
892 // Make recpoints array
893 if ( ECARecPoints() == 0x0)
895 AliDebug(9, "Making array for ECA");
896 TObjArray* eca = new TObjArray(100) ;
897 eca->SetName(fgkECARecPointsName) ;
898 GetDetectorDataFolder()->Add(eca);
902 //____________________________________________________________________________
903 void AliEMCALLoader::MakeTrackSegmentsArray()
905 // Create the array for TrackSegments
906 if ( TrackSegments())
908 TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
909 ts->SetName(fgkTracksName);
910 GetDetectorDataFolder()->Add(ts);
913 //____________________________________________________________________________
914 void AliEMCALLoader::MakeRecParticlesArray()
916 // Create the array for RecParticles
917 if ( RecParticles()) return;
918 TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
919 rp->SetName(fgkRecParticlesName);
920 GetDetectorDataFolder()->Add(rp);