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 "AliEMCALLoader.h"
51 #include "AliEMCALHit.h"
52 #include "AliEMCALGetter.h"
54 ClassImp(AliEMCALLoader)
57 const TString AliEMCALLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event
58 const TString AliEMCALLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray
59 const TString AliEMCALLoader::fgkDigitsName("DIGITS");//Name for TClonesArray
60 const TString AliEMCALLoader::fgkECARecPointsName("ECARECPOINTS");//Name for TClonesArray
61 const TString AliEMCALLoader::fgkTracksName("TRACKS");//Name for TClonesArray
62 const TString AliEMCALLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray
64 const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
65 const TString AliEMCALLoader::fgkTrackSegmentsBranchName("EMCALTS");//Name for branch with TrackSegments
66 const TString AliEMCALLoader::fgkRecParticlesBranchName("EMCALRP");//Name for branch with Reconstructed Particles
68 //____________________________________________________________________________
69 AliEMCALLoader::AliEMCALLoader()
72 fRecParticlesLoaded = kFALSE;
75 //____________________________________________________________________________
76 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername):
77 AliLoader(detname,eventfoldername)
80 fRecParticlesLoaded = kFALSE;
83 //____________________________________________________________________________
84 AliEMCALLoader::~AliEMCALLoader()
86 //remove and delete arrays
88 Clean(fgkSDigitsName);
90 Clean(fgkECARecPointsName);
92 Clean(fgkRecParticlesName);
94 // set to 0x0 the objgetter in AliGetter ... weird isn it !
96 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
102 //____________________________________________________________________________
103 void AliEMCALLoader::CleanFolders()
106 AliLoader::CleanFolders();
109 //____________________________________________________________________________
110 Int_t AliEMCALLoader::SetEvent()
112 //Cleans loaded stuff and and sets Files and Directories
113 // do not post any data to folder/tasks
116 Int_t retval = AliLoader::SetEvent();
119 Error("SetEvent","AliLoader::SetEvent returned error");
124 if (Hits()) Hits()->Clear();
125 if (SDigits()) SDigits()->Clear();
126 if (Digits()) Digits()->Clear();
127 if (ECARecPoints()) ECARecPoints()->Clear();
128 if (TrackSegments()) TrackSegments()->Clear();
129 if (RecParticles()) RecParticles()->Clear();
134 //____________________________________________________________________________
135 Int_t AliEMCALLoader::GetEvent()
137 //Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method
138 //to add Rec Particles specific for EMCAL
140 //First call the original method to get whatever from std. setup is needed
143 retval = AliLoader::GetEvent();
146 Error("GetEvent","AliLoader::GetEvent returned error");
150 if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits();
151 if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits();
152 if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits();
153 if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints();
154 if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks();
155 if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles();
158 //Now, check if RecPart were loaded
162 //____________________________________________________________________________
163 const AliEMCAL * AliEMCALLoader::EMCAL()
165 // returns the EMCAL object
166 AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(GetModulesFolder()->FindObject(fDetectorName));
169 cout << "WARNING: AliEMCALLoader::EMCAL -> EMCAL module not found in Folders" << endl ;
173 //____________________________________________________________________________
174 const AliEMCALGeometry * AliEMCALLoader::EMCALGeometry()
176 // Gets the EMCAL Geometry object
177 AliEMCALGeometry * rv = 0 ;
179 rv = EMCAL()->GetGeometry();
183 //____________________________________________________________________________
184 Int_t AliEMCALLoader::LoadHits(Option_t* opt)
186 //------- Hits ----------------------
187 //Overload (extends) LoadHits implemented in AliLoader
191 //First call the AliLoader's method to send the TreeH to folder
192 res = AliLoader::LoadHits(opt);
196 AliError("returned error");
200 //read the data from tree in folder and send it to folder
205 //____________________________________________________________________________
206 Int_t AliEMCALLoader::LoadSDigits(Option_t* opt)
208 // Loads the SDigits array in the folder structure
210 //First call the AliLoader's method to send the TreeS to folder
211 res = AliLoader::LoadSDigits(opt);
214 Error("PostSDigits","AliLoader::LoadSDigits returned error");
217 return ReadSDigits();
221 //____________________________________________________________________________
222 Int_t AliEMCALLoader::LoadDigits(Option_t* opt)
224 // Loads the Digits array in the folder structure
227 //First call the AliLoader's method to send the TreeS to folder
228 res = AliLoader::LoadDigits(opt);
231 Error("LoadDigits","AliLoader::LoadDigits returned error");
237 //____________________________________________________________________________
238 Int_t AliEMCALLoader::LoadRecPoints(Option_t* opt)
240 // Loads the RecPoints array in the folder structure
242 //First call the AliLoader's method to send the TreeR to folder
243 res = AliLoader::LoadRecPoints(opt);
246 Error("LoadRecPoints","AliLoader::LoadRecPoints returned error");
250 TFolder * emcalFolder = GetDetectorDataFolder();
251 if ( emcalFolder == 0x0 )
253 Error("LoadRecPoints","Can not get detector data folder");
256 return ReadRecPoints();
259 //____________________________________________________________________________
260 Int_t AliEMCALLoader::LoadTracks(Option_t* opt)
262 //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts
263 AliDebug(1, Form("opt = %s",opt));
265 res = AliLoader::LoadTracks(opt);
268 AliError("returned error");
275 //____________________________________________________________________________
276 Int_t AliEMCALLoader::LoadRecParticles(Option_t* opt)
278 // Loads the RecParticles array in the folder structure
280 //First call the AliLoader's method to send the TreeS to folder
281 res = AliLoader::LoadRecParticles(opt);
284 Error("LoadRecParticles","AliLoader::LoadRecParticles returned error");
288 TFolder * emcalFolder = GetDetectorDataFolder();
289 if ( emcalFolder == 0x0 )
291 Error("PostDigits","Can not get detector data folder");
294 return ReadRecParticles();
297 //____________________________________________________________________________
298 Int_t AliEMCALLoader::PostHits()
301 Int_t reval = AliLoader::PostHits();
304 Error("PostHits","AliLoader:: returned error");
310 //____________________________________________________________________________
311 Int_t AliEMCALLoader::PostSDigits()
313 // Posts the SDigits array to the folder structure
314 Int_t reval = AliLoader::PostSDigits();
317 Error("PostSDigits","AliLoader::PostSDigits returned error");
320 return ReadSDigits();
323 //____________________________________________________________________________
324 Int_t AliEMCALLoader::PostDigits()
326 // Posts the Digits array to the folder structure
327 Int_t reval = AliLoader::PostDigits();
330 Error("PostDigits","AliLoader::PostDigits returned error");
336 //____________________________________________________________________________
337 Int_t AliEMCALLoader::PostRecPoints()
339 // Posts the RecPoints array to the folder structure
340 Int_t reval = AliLoader::PostRecPoints();
343 Error("PostRecPoints","AliLoader::PostRecPoints returned error");
346 return ReadRecPoints();
349 //____________________________________________________________________________
350 Int_t AliEMCALLoader::PostRecParticles()
352 // Posts the RecParticles array to the folder structure
354 Int_t reval = AliLoader::PostRecParticles();
357 Error("PostRecParticles","AliLoader::PostRecParticles returned error");
360 return ReadRecParticles();
363 //____________________________________________________________________________
364 Int_t AliEMCALLoader::PostTracks()
366 // Posts the Tracks array to the folder structure
367 Int_t reval = AliLoader::PostTracks();
370 Error("PostTracks","AliLoader::PostTracks returned error");
376 //____________________________________________________________________________
377 Int_t AliEMCALLoader::ReadHits()
379 // If there is no Clones Array in folder creates it and sends to folder
380 // then tries to read
381 // Reads the first entry of EMCAL branch in hit tree TreeH()
382 // Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder
384 TObject** hitref = HitsRef();
391 TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref);
393 TTree* treeh = TreeH();
397 AliError("Cannot read TreeH from folder");
401 TBranch * hitsbranch = treeh->GetBranch(fDetectorName);
404 AliError("Cannot find branch EMCAL");
408 AliDebug(1, "Reading Hits");
410 if (hitsbranch->GetEntries() > 1)
412 TClonesArray * tempo = new TClonesArray("AliEMCALHit",1000);
414 hitsbranch->SetAddress(&tempo);
417 for (i = 0 ; i < hitsbranch->GetEntries(); i++)
419 hitsbranch->GetEntry(i) ;
421 for ( j = 0 ; j < tempo->GetEntries() ; j++)
423 AliEMCALHit* hit = (AliEMCALHit*)tempo->At(j);
424 new((*hits)[index]) AliEMCALHit( *hit ) ;
433 hitsbranch->SetAddress(hitref);
434 hitsbranch->GetEntry(0) ;
440 //____________________________________________________________________________
441 Int_t AliEMCALLoader::ReadSDigits()
443 // Read the summable digits tree TreeS():
444 // Check if TClones is in folder
445 // if not create and add to folder
446 // connect to tree if available
449 TObject** sdref = SDigitsRef();
453 sdref = SDigitsRef();
456 TTree * treeS = TreeS();
459 //May happen if file is truncated or new in LoadSDigits
460 //Error("ReadSDigits","There is no SDigit Tree");
464 TBranch * branch = treeS->GetBranch(fDetectorName);
466 {//easy, maybe just a new tree
467 //Error("ReadSDigits"," Cannot find branch EMCAL");
471 branch->SetAddress(SDigitsRef());
476 //____________________________________________________________________________
477 Int_t AliEMCALLoader::ReadDigits()
479 // Read the summable digits tree TreeS():
480 // Check if TClones is in folder
481 // if not create and add to folder
482 // connect to tree if available
485 TObject** dref = DigitsRef();
487 {//if there is not array in folder, create it and put it there
492 TTree * treeD = TreeD();
495 //May happen if file is truncated or new in LoadSDigits
496 //Error("ReadDigits","There is no Digit Tree");
500 TBranch * branch = treeD->GetBranch(fDetectorName);
502 {//easy, maybe just a new tree
503 //Error("ReadDigits"," Cannot find branch ",fDetectorName.Data());
507 branch->SetAddress(dref);//connect branch to buffer sitting in folder
508 branch->GetEntry(0);//get first event
513 //____________________________________________________________________________
514 void AliEMCALLoader::UnloadRecParticles()
516 // Unloads the RecParticles array fromthe folder structure
517 fRecParticlesLoaded = kFALSE;
519 if (fTracksLoaded == kFALSE) UnloadTracks();
522 //____________________________________________________________________________
523 void AliEMCALLoader::UnloadTracks()
525 // Unloads the Tracks array fromthe folder structure
526 CleanTracks();//free the memory
527 //in case RecPart are loaded we can not onload tree and close the file
528 if (fRecParticlesLoaded == kFALSE) AliLoader::UnloadTracks();
529 fTracksLoaded = kFALSE;//mark that nobody needs them
532 //____________________________________________________________________________
533 void AliEMCALLoader::Track(Int_t itrack)
535 // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
540 Error("Track","Can not load hits.");
545 TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
548 cout << "WARNING: AliEMCALLoader::ReadTreeH -> Cannot find branch EMCAL" << endl ;
551 if(!Hits()) PostHits();
553 hitsbranch->SetAddress(HitsRef());
554 hitsbranch->GetEntry(itrack);
558 //____________________________________________________________________________
559 Int_t AliEMCALLoader::ReadRecPoints()
561 //Creates and posts to folder an array container,
562 //connects branch in tree (if exists), and reads data to array
564 MakeRecPointsArray();
566 TObjArray * eca = 0x0 ;
568 TTree * treeR = TreeR();
572 //May happen if file is truncated or new in LoadSDigits
578 TBranch * ecabranch = treeR->GetBranch(fgkECARecPointsBranchName);
579 if (ecabranch == 0x0)
581 Error("ReadRecPoints","Can not get branch with ECA Rec. Points named %s",fgkECARecPointsBranchName.Data());
586 ecabranch->SetAddress(&eca);
587 ecabranch->GetEntry(0) ;
593 Int_t maxeca = eca->GetEntries() ;
594 for ( ii= 0 ; ii < maxeca ; ii++ )
595 ECARecPoints()->Add(eca->At(ii)) ;
600 //____________________________________________________________________________
601 Int_t AliEMCALLoader::ReadTracks()
603 //Creates and posts to folder an array container,
604 //connects branch in tree (if exists), and reads data to arry
606 TObject** trkref = TracksRef();
608 {//Create and post array
609 MakeTrackSegmentsArray();
610 trkref = TracksRef();
613 TTree * treeT = TreeT();
616 //May happen if file is truncated or new in LoadSDigits, or the file is in update mode,
617 //but tracking was not performed yet for a current event
618 //Error("ReadTracks","There is no Tree with Tracks");
622 TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
624 {//easy, maybe just a new tree
625 Error("ReadTracks"," Cannot find branch named %s",fgkTrackSegmentsBranchName.Data());
629 branch->SetAddress(trkref);//connect branch to buffer sitting in folder
630 branch->GetEntry(0);//get first event
635 //____________________________________________________________________________
636 Int_t AliEMCALLoader::ReadRecParticles()
638 //Reads Reconstructed Particles from file
639 //Creates and posts to folder an array container,
640 //connects branch in tree (if exists), and reads data to arry
642 TObject** recpartref = RecParticlesRef();
644 if ( recpartref == 0x0 )
645 {//Create and post array
646 MakeRecParticlesArray();
647 recpartref = RecParticlesRef();
650 TTree * treeP = TreeP();
653 //May happen if file is truncated or new in LoadSDigits,
654 //or the file is in update mode,
655 //but tracking was not performed yet for a current event
656 // Error("ReadRecParticles","There is no Tree with Tracks and Reconstructed Particles");
660 TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
662 {//easy, maybe just a new tree
663 Error("ReadRecParticles"," Cannot find branch %s",fgkRecParticlesBranchName.Data());
667 branch->SetAddress(recpartref);//connect branch to buffer sitting in folder
668 branch->GetEntry(0);//get first event
673 //____________________________________________________________________________
674 AliEMCALGeometry* AliEMCALLoader::GetEMCALGeometry()
676 //returns EMCAL geometry from gAlice
677 //static Method used by some classes where it is not convienient to pass eventfoldername
680 AliEMCAL* emcal=dynamic_cast<AliEMCAL*>(gAlice->GetDetector("EMCAL"));
683 return emcal->GetGeometry();
686 //____________________________________________________________________________
687 AliEMCALLoader* AliEMCALLoader::GetEMCALLoader(const char* eventfoldername)
689 // Get an instance of the EMCALLoader object
690 AliRunLoader* rn = AliRunLoader::GetRunLoader(eventfoldername);
693 cerr<<"Error: <AliEMCALLoader::GetEMCALLoader>: "
694 << "Can not find Run Loader in folder "<<eventfoldername<<endl;
697 return dynamic_cast<AliEMCALLoader*>(rn->GetLoader("EMCALLoader"));
700 //____________________________________________________________________________
701 Bool_t AliEMCALLoader::BranchExists(const TString& recName)
703 // Check is branch exists
704 if (fBranchTitle.IsNull()) return kFALSE;
705 TString dataname, zername ;
707 if(recName == "SDigits") {
709 dataname = GetDetectorName();
710 zername = "AliEMCALSDigitizer" ;
712 else if(recName == "Digits"){
714 dataname = GetDetectorName();
715 zername = "AliEMCALDigitizer" ;
717 else if(recName == "ECARecPoints"){
719 dataname = fgkECARecPointsBranchName;
720 zername = "AliEMCALClusterizer" ;
722 else if(recName == "TrackSegments"){
724 dataname = fgkTrackSegmentsBranchName;
725 zername = "AliEMCALTrackSegmentMaker";
727 else if(recName == "RecParticles"){
729 dataname = fgkRecParticlesBranchName;
730 zername = "AliEMCALPID";
738 TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
740 TBranch * branch = 0 ;
741 TString titleName(fBranchTitle);
744 while ((branch = (static_cast<TBranch*>(next())))) {
745 TString branchName(branch->GetName() ) ;
746 TString branchTitle(branch->GetTitle() ) ;
747 if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){
748 Warning("BranchExists","branch %s with title %s ",dataname.Data(),fBranchTitle.Data());
751 if ( branchName.BeginsWith(zername) && branchTitle.BeginsWith(titleName) ){
752 Warning("BranchExists","branch AliEMCAL... with title %s ",branch->GetTitle());
760 //____________________________________________________________________________
761 void AliEMCALLoader::SetBranchTitle(const TString& btitle)
763 // Gives a name to a branch in the folder structure
764 if (btitle.CompareTo(fBranchTitle) == 0) return;
765 fBranchTitle = btitle;
769 //____________________________________________________________________________
770 void AliEMCALLoader::CleanHits()
773 AliLoader::CleanHits();
775 TClonesArray* hits = Hits();
780 //____________________________________________________________________________
781 void AliEMCALLoader::CleanSDigits()
783 // Cleans the SDigits array in the folder structure
784 AliLoader::CleanSDigits();
785 TClonesArray* sdigits = SDigits();
786 if (sdigits) sdigits->Clear();
789 //____________________________________________________________________________
791 void AliEMCALLoader::CleanDigits()
793 // Cleans the Digits array in the folder structure
794 AliLoader::CleanDigits();
795 TClonesArray* digits = Digits();
796 if (digits) digits->Clear();
799 //____________________________________________________________________________
800 void AliEMCALLoader::CleanRecPoints()
802 // Cleans the RecPoints array in the folder structure
803 AliLoader::CleanRecPoints();
804 TObjArray* recpoints = ECARecPoints();
805 if (recpoints) recpoints->Clear();
809 //____________________________________________________________________________
810 void AliEMCALLoader::CleanTracks()
812 // Cleans the Tracks array in the folder structure
813 AliLoader::CleanTracks();//tree
814 //and clear the array
815 TClonesArray* tracks = TrackSegments();
820 //____________________________________________________________________________
821 void AliEMCALLoader::CleanRecParticles()
823 // Cleans the RecParticles array in the folder structure
824 TClonesArray *recpar = RecParticles();
829 //____________________________________________________________________________
830 // void AliEMCALLoader::ReadCalibrationDB(const char * database,const char * filename)
833 // if(fcdb && (strcmp(database,fcdb->GetTitle())==0))
836 // TFile * file = gROOT->GetFile(filename) ;
838 // file = TFile::Open(filename);
840 // Error ("ReadCalibrationDB", "Cannot open file %s", filename) ;
845 // fcdb = dynamic_cast<AliEMCALCalibrationDB *>(file->Get("AliEMCALCalibrationDB")) ;
847 // Error ("ReadCalibrationDB", "No database %s in file %s", database, filename) ;
849 //____________________________________________________________________________
851 // AliEMCALSDigitizer* AliEMCALLoader::EMCALSDigitizer()
853 // //return EMCAL SDigitizer
854 // return dynamic_cast<AliEMCALSDigitizer*>(SDigitizer()) ;
857 //____________________________________________________________________________
858 void AliEMCALLoader::MakeHitsArray()
860 // Create the array for Hits
862 TClonesArray* hits = new TClonesArray("AliEMCALHit",1000);
863 hits->SetName(fgkHitsName);
864 GetDetectorDataFolder()->Add(hits);
867 //____________________________________________________________________________
868 void AliEMCALLoader::MakeSDigitsArray()
870 // Create the array for SDigits
871 if ( SDigits()) return;
872 TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",1);
873 sdigits->SetName(fgkSDigitsName);
874 GetDetectorDataFolder()->Add(sdigits);
877 //____________________________________________________________________________
878 void AliEMCALLoader::MakeDigitsArray()
880 // Create the array for Digits
881 if ( Digits()) return;
882 TClonesArray* digits = new TClonesArray("AliEMCALDigit",1);
883 digits->SetName(fgkDigitsName);
884 GetDetectorDataFolder()->Add(digits);
888 //____________________________________________________________________________
889 void AliEMCALLoader::MakeRecPointsArray()
891 // Make recpoints array
892 if ( ECARecPoints() == 0x0)
894 AliDebug(9, "Making array for ECA");
895 TObjArray* eca = new TObjArray(100) ;
896 eca->SetName(fgkECARecPointsName) ;
897 GetDetectorDataFolder()->Add(eca);
901 //____________________________________________________________________________
902 void AliEMCALLoader::MakeTrackSegmentsArray()
904 // Create the array for TrackSegments
905 if ( TrackSegments())
907 TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
908 ts->SetName(fgkTracksName);
909 GetDetectorDataFolder()->Add(ts);
912 //____________________________________________________________________________
913 void AliEMCALLoader::MakeRecParticlesArray()
915 // Create the array for RecParticles
916 if ( RecParticles()) return;
917 TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
918 rp->SetName(fgkRecParticlesName);
919 GetDetectorDataFolder()->Add(rp);