]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALLoader.cxx
move some methods from protected to public, in case of unfolding, fraction is not...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 /* $Id$ */
17
18 //_________________________________________________________________________
19 //  The AliEMCALLoader gets the TClonesArray and TObjArray for reading
20 //  Hits, Dgits, SDigits and RecPoints. Filling is managed in the GetEvent()
21 //  method.
22 //  It also provides acces methods to the calibration and simulation OCDB parameters 
23 //
24 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
25 //*--         Completely redesigned by Dmitri Peressounko March 2001  
26 //
27 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
28 //*--         systematic usage of TFolders without changing the interface
29 // 
30 //*-- Marco van Leeuwen, Jan 2006: complete revision to simplify reading
31 //*--         and fit better in general ALICE scheme
32 //*-- GCB: Remove TClonesArrays and TObjArrays data members, they are created elsewhere.
33 //*--      Provide access to OCDB calibration and simulation parameters.          
34 //
35 //////////////////////////////////////////////////////////////////////////////
36
37 // --- ROOT system ---
38 #include "TMath.h"
39 #include "TTree.h"
40 // --- Standard library ---
41
42 // --- AliRoot header files ---
43 #include "AliEMCALLoader.h"
44 #include "AliLog.h"
45 #include "AliCDBLocal.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBManager.h"
48 #include "AliCDBEntry.h"
49 #include "AliEMCALHit.h"
50
51  ClassImp(AliEMCALLoader)
52   
53 const TString         AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
54 const TString         AliEMCALLoader::fgkECADigitsBranchName("DIGITS");//Name for branch with ECA Digits
55 const TString         AliEMCALLoader::fgkECASDigitsBranchName("SDIGITS");//Name for branch with ECA SDigits
56 const TString         AliEMCALLoader::fgkECAHitsBranchName("HITS");//Name for branch with ECA Hits
57
58 AliEMCALCalibData*    AliEMCALLoader::fgCalibData = 0; //calibration data
59 //AliCaloCalibPedestal* AliEMCALLoader::fgCaloPed   = 0; //dead map data
60 AliEMCALSimParam*     AliEMCALLoader::fgSimParam  = 0; //simulation parameters
61
62 //____________________________________________________________________________ 
63 AliEMCALLoader::AliEMCALLoader()
64 : fDebug(0), fTempArr(0x0)
65 {
66   //Default constructor for EMCAL Loader Class
67   fTempArr =  new TClonesArray("AliEMCALHit",0);
68
69 }
70
71 //____________________________________________________________________________ 
72 AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
73   : AliLoader(detname,eventfoldername), fDebug(0), fTempArr(0x0)
74 {
75   //Specific constructor for EMCAL Loader class
76   fTempArr =  new TClonesArray("AliEMCALHit",0);
77
78 }
79
80 //____________________________________________________________________________
81 AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
82   : AliLoader(name,topfolder), fDebug(0), fTempArr(0x0)
83 {
84   //Specific constructor for EMCAL Loader class
85   fTempArr =  new TClonesArray("AliEMCALHit",0);
86
87 }
88
89 //____________________________________________________________________________ 
90 AliEMCALLoader::~AliEMCALLoader()
91 {
92   // Disconnect trees and remove arrays
93 //  if (TreeH())
94 //    TreeH()->SetBranchAddress(fDetectorName,0);
95 //  if (TreeD())
96 //    TreeD()->SetBranchAddress(fDetectorName,0);
97 //  if (TreeS())
98 //    TreeS()->SetBranchAddress(fDetectorName,0);
99 //  if (TreeR())
100 //    TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
101         
102         Clean(fgkECAHitsBranchName);
103         Clean(fgkECASDigitsBranchName);
104         Clean(fgkECADigitsBranchName);
105         Clean(fgkECARecPointsBranchName);
106         
107         AliLoader::CleanFolders();
108         
109         if (fTempArr) {
110                 fTempArr->Delete();
111                 delete fTempArr;
112         }
113         
114 }
115
116 //____________________________________________________________________________ 
117 AliEMCALCalibData* AliEMCALLoader::CalibData()
118
119   // Check if the instance of AliEMCALCalibData exists, if not, create it if 
120   // the OCDB is available, and finally return it.
121   
122   if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
123     {
124       AliCDBEntry *entry = (AliCDBEntry*) 
125         AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
126       if (entry) fgCalibData =  (AliEMCALCalibData*) entry->GetObject();
127     }
128   
129   if(!fgCalibData)
130     AliFatal("Calibration parameters not found in CDB!");
131   
132   return fgCalibData;
133   
134 }
135
136 //____________________________________________________________________________ 
137 //AliCaloCalibPedestal* AliEMCALLoader::PedestalData()
138 //{ 
139 //      // Check if the instance of AliCaloCalibPedestal exists, if not, create it if 
140 //      // the OCDB is available, and finally return it.
141 //      
142 //      if(!fgCaloPed && (AliCDBManager::Instance()->IsDefaultStorageSet()))
143 //    {
144 //              AliCDBEntry *entry = (AliCDBEntry*) 
145 //              AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
146 //              if (entry) fgCaloPed =  (AliCaloCalibPedestal*) entry->GetObject();
147 //    }
148 //      
149 //      if(!fgCaloPed)
150 //              AliFatal("Pedestal info not found in CDB!");
151 //      
152 //      return fgCaloPed;
153 //      
154 //}
155
156 //____________________________________________________________________________ 
157 AliEMCALSimParam* AliEMCALLoader::SimulationParameters()
158
159   // Check if the instance of AliEMCALSimParam exists, if not, create it if 
160   // the OCDB is available, and finally return it.
161   
162   if(!fgSimParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
163     {
164       AliCDBEntry *entry = (AliCDBEntry*) 
165         AliCDBManager::Instance()->Get("EMCAL/Calib/SimParam");
166       if (entry) fgSimParam =  (AliEMCALSimParam*) entry->GetObject();
167       
168     }
169   
170   if(!fgSimParam)
171     AliFatal("Simulations parameters not found in CDB!");
172   
173   return fgSimParam;
174   
175 }
176
177 //____________________________________________________________________________ 
178 Int_t AliEMCALLoader::GetEvent() 
179 {
180   //Method to load all of the data
181   //members of the EMCAL for a given
182   //event from the Trees
183   
184   AliLoader::GetEvent();  // First call AliLoader to do all the groundwork
185   
186   // *** Hits ***
187   // Initialize the Hits TClonesArray, only if it did not existed before
188   MakeHitsArray();
189   
190   TTree *treeH = TreeH();       
191   if (treeH) {
192     Int_t nEnt = treeH->GetEntries();  // TreeH has array of hits for every primary
193     Int_t index = 0;
194     TBranch * branchH = treeH->GetBranch(fDetectorName);
195     branchH->SetAddress(&fTempArr);
196     TClonesArray* hits = const_cast<AliEMCALLoader *>(this)->Hits();
197     if (hits) hits->Clear();
198     for (Int_t iEnt = 0; iEnt < nEnt; iEnt++) {
199       branchH->GetEntry(iEnt);
200       Int_t nHit = fTempArr->GetEntriesFast();
201       for (Int_t iHit = 0; iHit < nHit; iHit++) {
202         new ((*hits)[index]) AliEMCALHit(*((AliEMCALHit*)fTempArr->At(iHit)));
203         index++;
204       }
205     }
206     branchH->ResetAddress();
207         if (fTempArr) {
208                   fTempArr->Clear();
209         }
210   }
211   
212   // *** SDigits ***
213   // Initialize the SDigits TClonesArray, only if it did not existed before
214   MakeSDigitsArray();
215   
216   TTree *treeS = TreeS();
217   if (treeS) {
218     TBranch * branchS = treeS->GetBranch(fDetectorName);
219     
220     // Reset SDigits array and branch
221     branchS->ResetAddress();
222     TClonesArray* sdigits = const_cast<AliEMCALLoader *>(this)->SDigits();
223     if (sdigits) sdigits->Clear();
224     
225     branchS->SetAddress(&sdigits);
226     branchS->GetEntry(0);
227   }
228   
229   // *** Digits ***
230   // Initialize the Digits TClonesArray, only if it did not existed before
231   MakeDigitsArray();
232   
233   TTree *treeD = TreeD();
234   if (treeD) {
235     TBranch * branchD = treeD->GetBranch(fDetectorName);
236     
237     // Reset Digits array and branch
238     branchD->ResetAddress();
239     TClonesArray* digits = const_cast<AliEMCALLoader *>(this)->Digits();
240     if (digits) digits->Clear();
241     
242     branchD->SetAddress(&digits);
243     branchD->GetEntry(0);
244   }
245   
246   // *** RecPoints ***  
247   // Initialize the RecPoints TObjArray, only if it did not existed before
248   MakeRecPointsArray();
249   
250   TTree *treeR = TreeR();
251   if (treeR) {
252     TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
253     
254     // Reset RecPoints array and branch
255     branchR->ResetAddress();
256     TObjArray* rp = const_cast<AliEMCALLoader *>(this)->RecPoints();
257     if (rp) rp->Clear();
258     
259     branchR->SetAddress(&rp);
260     branchR->GetEntry(0);
261   }
262   
263   return 0;
264 }
265
266 //____________________________________________________________________________
267 void AliEMCALLoader::MakeHitsArray(){
268   // Add Hits array to the data folder
269   if (Hits()) return;
270   TClonesArray* hits = new TClonesArray("AliEMCALHit",0);
271   hits->SetName(fgkECAHitsBranchName);
272   GetDetectorDataFolder()->Add(hits);
273 }
274
275 //____________________________________________________________________________
276 void AliEMCALLoader::MakeSDigitsArray(){
277   // Add SDigits array to the data folder
278   if (SDigits()) return;
279   TClonesArray* sdigits = new TClonesArray("AliEMCALDigit",0);
280   sdigits->SetName(fgkECASDigitsBranchName);
281   GetDetectorDataFolder()->Add(sdigits);
282 }
283
284 //____________________________________________________________________________
285 void AliEMCALLoader::MakeDigitsArray(){
286   // Add Digits array to the data folder
287   if (Digits()) return;
288   TClonesArray* digits = new TClonesArray("AliEMCALDigit",0);
289   digits->SetName(fgkECADigitsBranchName);
290   GetDetectorDataFolder()->Add(digits);
291 }
292
293 //____________________________________________________________________________
294 void AliEMCALLoader::MakeRecPointsArray(){
295   // Add RecPoints array to the data folder
296   if (RecPoints()) return;
297   TObjArray* rp = new TObjArray(0);
298   rp->SetName(fgkECARecPointsBranchName);
299   GetDetectorDataFolder()->Add(rp);
300 }