standardizing access to AliEMCALRecParams through AliEMCALReconstructor
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALLoader.cxx
CommitLineData
88cb7938 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
803d1ab0 16/* $Id$ */
88cb7938 17
18//_________________________________________________________________________
19// A singleton. This class should be used in the analysis stage to get
20// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
5dee926e 21// instead of directly reading them from galice.root file.
88cb7938 22//
5dee926e 23// MvL Feb 2006:
24// The AliEMCALLoader now holds the TClonesArray and TObjArray for reading
25// Hits, Dgits, SDigits and RecPoints. Filling is managed in the GetEvent()
26// method.
27//
28// Creation/writing of files is managed by the relevant parts of the
29// reconstruction software (AliEMCALDigitiser etx)
30//
88cb7938 31//*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
32//*-- Completely redesigned by Dmitri Peressounko March 2001
33//
34//*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
5dee926e 35//*-- systematic usage of TFolders without changing the interface
36//
37//*-- Marco van Leeuwen, Jan 2006: complete revision to simplify reading
38//*-- and fit better in general ALICE scheme
39//
88cb7938 40//////////////////////////////////////////////////////////////////////////////
41
88cb7938 42// --- ROOT system ---
090026bf 43#include "TMath.h"
88cb7938 44#include "TTree.h"
88cb7938 45
46// --- Standard library ---
88cb7938 47
48// --- AliRoot header files ---
a9bbb414 49#include "AliEMCALLoader.h"
50#include "AliLog.h"
f565d89d 51#include "AliCDBLocal.h"
52#include "AliCDBStorage.h"
53#include "AliCDBManager.h"
1f337798 54#include "AliCDBEntry.h"
825fa573 55#include "AliEMCALHit.h"
88cb7938 56
57ClassImp(AliEMCALLoader)
d64c959b 58
88cb7938 59const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
14ce0a6e 60AliEMCALCalibData* AliEMCALLoader::fgCalibData = 0; //calibation data
d64c959b 61
88cb7938 62//____________________________________________________________________________
63AliEMCALLoader::AliEMCALLoader()
18a21c7c 64 : fDebug(0),
65 fHits(0),
66 fDigits(0),
67 fSDigits(0),
68 fRecPoints(0)
d64c959b 69{
14ce0a6e 70 //Default constructor for EMCAL Loader Class
71
88cb7938 72 fDebug = 0;
5dee926e 73 fHits = new TClonesArray("AliEMCALHit");
74 fDigits = new TClonesArray("AliEMCALDigit");
75 fSDigits = new TClonesArray("AliEMCALDigit");
76 fRecPoints = new TObjArray();
d64c959b 77}
78
88cb7938 79//____________________________________________________________________________
18a21c7c 80AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
81 : AliLoader(detname,eventfoldername),
82 fDebug(0),
83 fHits(0),
84 fDigits(0),
85 fSDigits(0),
86 fRecPoints(0)
88cb7938 87{
14ce0a6e 88 //Specific constructor for EMCAL Loader class
89
88cb7938 90 fDebug=0;
5dee926e 91 fHits = new TClonesArray("AliEMCALHit");
92 fDigits = new TClonesArray("AliEMCALDigit");
93 fSDigits = new TClonesArray("AliEMCALDigit");
94 fRecPoints = new TObjArray();
88cb7938 95}
88cb7938 96
6b299d9e 97//____________________________________________________________________________
98AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
99 : AliLoader(name,topfolder),
100 fDebug(0),
101 fHits(0),
102 fDigits(0),
103 fSDigits(0),
104 fRecPoints(0)
105{
106 //Specific constructor for EMCAL Loader class
107
108 fDebug=0;
109 fHits = new TClonesArray("AliEMCALHit");
110 fDigits = new TClonesArray("AliEMCALDigit");
111 fSDigits = new TClonesArray("AliEMCALDigit");
112 fRecPoints = new TObjArray();
113}
114
0a4cb131 115//____________________________________________________________________________
18a21c7c 116AliEMCALLoader::AliEMCALLoader(const AliEMCALLoader & obj)
117 : AliLoader(obj),
118 fDebug(obj.fDebug),
119 fHits(obj.fHits),
120 fDigits(obj.fDigits),
121 fSDigits(obj.fSDigits),
122 fRecPoints(obj.fRecPoints)
0a4cb131 123{
124 //copy ctor
0a4cb131 125}
126
d64c959b 127//____________________________________________________________________________
88cb7938 128AliEMCALLoader::~AliEMCALLoader()
129{
5dee926e 130 // Disconnect trees and remove arrays
131 if (TreeH())
132 TreeH()->SetBranchAddress(fDetectorName,0);
133 if (TreeD())
134 TreeD()->SetBranchAddress(fDetectorName,0);
135 if (TreeS())
136 TreeS()->SetBranchAddress(fDetectorName,0);
137 if (TreeR())
138 TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
ac169647 139 if (fHits) {
140 fHits->Delete();
141 delete fHits;
142 }
5dee926e 143 delete fDigits;
144 delete fSDigits;
145 delete fRecPoints;
146}
147
f565d89d 148//____________________________________________________________________________
149AliEMCALCalibData* AliEMCALLoader::CalibData()
150{
1f337798 151 // Check if the instance of AliEMCALCalibData exists, if not, create it if
152 // the OCDB is available, and finally return it.
f565d89d 153
1f337798 154 if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
155 {
156 AliCDBEntry *entry = (AliCDBEntry*)
157 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
158 if (entry) fgCalibData = (AliEMCALCalibData*) entry->GetObject();
159 }
160
161 if(!fgCalibData)
162 AliFatal("Calibration parameters not found in CDB!");
78cbbabb 163
14ce0a6e 164 return fgCalibData;
78cbbabb 165
f565d89d 166}
167
3a8be91c 168
169//____________________________________________________________________________
f565d89d 170Int_t AliEMCALLoader::CalibrateRaw(Double_t energy, Int_t module,
171 Int_t column, Int_t row)
172{
173 // Convert energy into digitized amplitude for a cell relId
174 // It is a user responsilibity to open CDB and set
175 // AliEMCALCalibData object by the following operators:
176 //
177 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
178 // AliEMCALCalibData* clb = (AliEMCALCalibData*)AliCDBStorage::Instance()
179 // ->Get(path_to_calibdata,run_number);
180 // AliEMCALGetter* gime = AliEMCALGetter::Instance("galice.root");
181 // gime->SetCalibData(clb);
182
183 if (CalibData() == 0)
184 Warning("CalibrateRaw","Calibration DB is not initiated!");
185
78cbbabb 186 Float_t gainFactor = 0.00305;//0.0015; // width of one ADC channel in GeV
187 Float_t pedestal = 0.009;//0.005; // pedestals
f565d89d 188
189 if(CalibData()) {
190 gainFactor = CalibData()->GetADCchannel (module,column,row);
191 pedestal = CalibData()->GetADCpedestal(module,column,row);
192 }
193
194 Int_t amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ;
195 return amp;
196}
197
ea6ddc2c 198//____________________________________________________________________________
14ce0a6e 199Int_t AliEMCALLoader::GetEvent()
200{
201 //Method to load all of the data
202 //members of the EMCAL for a given
203 //event from the Trees
204
ea6ddc2c 205 AliLoader::GetEvent(); // First call AliLoader to do all the groundwork
206
207 // Now connect and fill TClonesArray
208
209 // Hits
210 TTree *treeH = TreeH();
211
212 if (treeH) {
825fa573 213 Int_t nEnt = treeH->GetEntries(); // TreeH has array of hits for every primary
214 fHits->Clear();
215 Int_t index = 0;
ac169647 216 TClonesArray *tempArr = 0x0;
217 TBranch * branchH = treeH->GetBranch(fDetectorName);
218 branchH->SetAddress(&tempArr);
825fa573 219 for (Int_t iEnt = 0; iEnt < nEnt; iEnt++) {
220 treeH->GetEntry(iEnt);
ac169647 221 Int_t nHit = tempArr->GetEntriesFast();
825fa573 222 for (Int_t iHit = 0; iHit < nHit; iHit++) {
ac169647 223 new ((*fHits)[index]) AliEMCALHit(*((AliEMCALHit*)tempArr->At(iHit)));
825fa573 224 index++;
225 }
226 }
ac169647 227 branchH->ResetAddress();
228 if (tempArr) {
229 tempArr->Delete();
230 delete tempArr;
231 }
ea6ddc2c 232 }
825fa573 233
ea6ddc2c 234 // SDigits
235 TTree *treeS = TreeS();
236 if (treeS) {
ac169647 237 TBranch * branchS = treeS->GetBranch(fDetectorName);
238 branchS->ResetAddress();
239 if (fSDigits) {
9517d886 240 fSDigits->Clear();
ac169647 241 }
242 branchS->SetAddress(&fSDigits);
ea6ddc2c 243 treeS->GetEvent(0);
244 }
245
246 // Digits
247 TTree *treeD = TreeD();
248 if (treeD) {
ac169647 249 TBranch * branchD = treeD->GetBranch(fDetectorName);
250 branchD->ResetAddress();
251 if (fDigits) {
9517d886 252 fDigits->Clear();
ac169647 253 }
254 branchD->SetAddress(&fDigits);
ea6ddc2c 255 treeD->GetEvent(0);
256 }
257
258 // RecPoints
259 TTree *treeR = TreeR();
260 if (treeR) {
ac169647 261 TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
262 branchR->ResetAddress();
263 if (fRecPoints) {
9517d886 264 fRecPoints->Clear();
ac169647 265 }
266 branchR->SetAddress(&fRecPoints);
ea6ddc2c 267 treeR->GetEvent(0);
268 }
269
270 return 0;
88cb7938 271}