Adding total dNdetadphi including SPD inner layer analysis
[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
6569f329 59const TString AliEMCALLoader::fgkECARecPointsBranchName("EMCALECARP");//Name for branch with ECA Reconstructed Points
60AliEMCALCalibData* AliEMCALLoader::fgCalibData = 0; //calibration data
40164976 61AliCaloCalibPedestal* AliEMCALLoader::fgCaloPed = 0; //dead map data
6569f329 62AliEMCALSimParam* AliEMCALLoader::fgSimParam = 0; //simulation parameters
d64c959b 63
88cb7938 64//____________________________________________________________________________
65AliEMCALLoader::AliEMCALLoader()
18a21c7c 66 : fDebug(0),
67 fHits(0),
68 fDigits(0),
69 fSDigits(0),
70 fRecPoints(0)
d64c959b 71{
14ce0a6e 72 //Default constructor for EMCAL Loader Class
73
88cb7938 74 fDebug = 0;
5dee926e 75 fHits = new TClonesArray("AliEMCALHit");
76 fDigits = new TClonesArray("AliEMCALDigit");
77 fSDigits = new TClonesArray("AliEMCALDigit");
78 fRecPoints = new TObjArray();
d64c959b 79}
80
88cb7938 81//____________________________________________________________________________
18a21c7c 82AliEMCALLoader::AliEMCALLoader(const Char_t *detname,const Char_t *eventfoldername)
83 : AliLoader(detname,eventfoldername),
84 fDebug(0),
0dc91659 85 fHits(new TClonesArray("AliEMCALHit")),
86 fDigits(new TClonesArray("AliEMCALDigit")),
87 fSDigits(new TClonesArray("AliEMCALDigit")),
88 fRecPoints(new TObjArray())
88cb7938 89{
14ce0a6e 90 //Specific constructor for EMCAL Loader class
88cb7938 91}
88cb7938 92
0a4cb131 93//____________________________________________________________________________
6b299d9e 94AliEMCALLoader::AliEMCALLoader(const Char_t *name, TFolder *topfolder)
95 : AliLoader(name,topfolder),
96 fDebug(0),
0dc91659 97 fHits(new TClonesArray("AliEMCALHit")),
98 fDigits(new TClonesArray("AliEMCALDigit")),
99 fSDigits(new TClonesArray("AliEMCALDigit")),
100 fRecPoints(new TObjArray())
6b299d9e 101{
102 //Specific constructor for EMCAL Loader class
6b299d9e 103}
104
d64c959b 105//____________________________________________________________________________
88cb7938 106AliEMCALLoader::~AliEMCALLoader()
107{
5dee926e 108 // Disconnect trees and remove arrays
109 if (TreeH())
110 TreeH()->SetBranchAddress(fDetectorName,0);
111 if (TreeD())
112 TreeD()->SetBranchAddress(fDetectorName,0);
113 if (TreeS())
114 TreeS()->SetBranchAddress(fDetectorName,0);
115 if (TreeR())
116 TreeR()->SetBranchAddress(fgkECARecPointsBranchName,0);
ac169647 117 if (fHits) {
118 fHits->Delete();
119 delete fHits;
120 }
5dee926e 121 delete fDigits;
122 delete fSDigits;
123 delete fRecPoints;
124}
125
126//____________________________________________________________________________
f565d89d 127AliEMCALCalibData* AliEMCALLoader::CalibData()
128{
1f337798 129 // Check if the instance of AliEMCALCalibData exists, if not, create it if
130 // the OCDB is available, and finally return it.
f565d89d 131
1f337798 132 if(!fgCalibData && (AliCDBManager::Instance()->IsDefaultStorageSet()))
133 {
134 AliCDBEntry *entry = (AliCDBEntry*)
135 AliCDBManager::Instance()->Get("EMCAL/Calib/Data");
136 if (entry) fgCalibData = (AliEMCALCalibData*) entry->GetObject();
137 }
138
139 if(!fgCalibData)
140 AliFatal("Calibration parameters not found in CDB!");
78cbbabb 141
14ce0a6e 142 return fgCalibData;
78cbbabb 143
f565d89d 144}
145
40164976 146//____________________________________________________________________________
147AliCaloCalibPedestal* AliEMCALLoader::PedestalData()
148{
149 // Check if the instance of AliCaloCalibPedestal exists, if not, create it if
150 // the OCDB is available, and finally return it.
151
152 if(!fgCaloPed && (AliCDBManager::Instance()->IsDefaultStorageSet()))
153 {
154 AliCDBEntry *entry = (AliCDBEntry*)
155 AliCDBManager::Instance()->Get("EMCAL/Calib/Pedestals");
156 if (entry) fgCaloPed = (AliCaloCalibPedestal*) entry->GetObject();
157 }
158
159 if(!fgCaloPed)
160 AliFatal("Pedestal info not found in CDB!");
161
162 return fgCaloPed;
163
164}
165
6569f329 166//____________________________________________________________________________
167AliEMCALSimParam* AliEMCALLoader::SimulationParameters()
168{
169 // Check if the instance of AliEMCALSimParam exists, if not, create it if
170 // the OCDB is available, and finally return it.
171
172 if(!fgSimParam && (AliCDBManager::Instance()->IsDefaultStorageSet()))
173 {
174 AliCDBEntry *entry = (AliCDBEntry*)
175 AliCDBManager::Instance()->Get("EMCAL/Calib/SimParam");
176 if (entry) fgSimParam = (AliEMCALSimParam*) entry->GetObject();
177
178 }
179
180 if(!fgSimParam)
181 AliFatal("Simulations parameters not found in CDB!");
182
183 return fgSimParam;
184
185}
3a8be91c 186
187//____________________________________________________________________________
f565d89d 188Int_t AliEMCALLoader::CalibrateRaw(Double_t energy, Int_t module,
189 Int_t column, Int_t row)
190{
191 // Convert energy into digitized amplitude for a cell relId
192 // It is a user responsilibity to open CDB and set
193 // AliEMCALCalibData object by the following operators:
194 //
195 // AliCDBLocal *loc = new AliCDBLocal("deCalibDB");
196 // AliEMCALCalibData* clb = (AliEMCALCalibData*)AliCDBStorage::Instance()
197 // ->Get(path_to_calibdata,run_number);
198 // AliEMCALGetter* gime = AliEMCALGetter::Instance("galice.root");
199 // gime->SetCalibData(clb);
200
201 if (CalibData() == 0)
202 Warning("CalibrateRaw","Calibration DB is not initiated!");
203
78cbbabb 204 Float_t gainFactor = 0.00305;//0.0015; // width of one ADC channel in GeV
205 Float_t pedestal = 0.009;//0.005; // pedestals
f565d89d 206
207 if(CalibData()) {
208 gainFactor = CalibData()->GetADCchannel (module,column,row);
209 pedestal = CalibData()->GetADCpedestal(module,column,row);
210 }
211
212 Int_t amp = static_cast<Int_t>( (energy - pedestal) / gainFactor + 0.5 ) ;
213 return amp;
214}
215
f565d89d 216//____________________________________________________________________________
14ce0a6e 217Int_t AliEMCALLoader::GetEvent()
218{
219 //Method to load all of the data
220 //members of the EMCAL for a given
221 //event from the Trees
222
ea6ddc2c 223 AliLoader::GetEvent(); // First call AliLoader to do all the groundwork
224
225 // Now connect and fill TClonesArray
226
227 // Hits
228 TTree *treeH = TreeH();
229
230 if (treeH) {
825fa573 231 Int_t nEnt = treeH->GetEntries(); // TreeH has array of hits for every primary
232 fHits->Clear();
233 Int_t index = 0;
ac169647 234 TClonesArray *tempArr = 0x0;
235 TBranch * branchH = treeH->GetBranch(fDetectorName);
236 branchH->SetAddress(&tempArr);
825fa573 237 for (Int_t iEnt = 0; iEnt < nEnt; iEnt++) {
0341167b 238 //treeH->GetEntry(iEnt);
239 branchH->GetEntry(iEnt);
ac169647 240 Int_t nHit = tempArr->GetEntriesFast();
825fa573 241 for (Int_t iHit = 0; iHit < nHit; iHit++) {
ac169647 242 new ((*fHits)[index]) AliEMCALHit(*((AliEMCALHit*)tempArr->At(iHit)));
825fa573 243 index++;
244 }
245 }
ac169647 246 branchH->ResetAddress();
247 if (tempArr) {
248 tempArr->Delete();
249 delete tempArr;
250 }
ea6ddc2c 251 }
825fa573 252
ea6ddc2c 253 // SDigits
254 TTree *treeS = TreeS();
255 if (treeS) {
ac169647 256 TBranch * branchS = treeS->GetBranch(fDetectorName);
257 branchS->ResetAddress();
258 if (fSDigits) {
9517d886 259 fSDigits->Clear();
ac169647 260 }
261 branchS->SetAddress(&fSDigits);
0341167b 262 branchS->GetEntry(0);
263 //treeS->GetEvent(0);
ea6ddc2c 264 }
265
266 // Digits
267 TTree *treeD = TreeD();
268 if (treeD) {
ac169647 269 TBranch * branchD = treeD->GetBranch(fDetectorName);
270 branchD->ResetAddress();
271 if (fDigits) {
9517d886 272 fDigits->Clear();
ac169647 273 }
274 branchD->SetAddress(&fDigits);
0341167b 275 branchD->GetEntry(0);
276 //treeD->GetEvent(0);
ea6ddc2c 277 }
278
279 // RecPoints
280 TTree *treeR = TreeR();
281 if (treeR) {
ac169647 282 TBranch * branchR = treeR->GetBranch(fgkECARecPointsBranchName);
283 branchR->ResetAddress();
284 if (fRecPoints) {
9517d886 285 fRecPoints->Clear();
ac169647 286 }
287 branchR->SetAddress(&fRecPoints);
0341167b 288 //treeR->GetEvent(0);
289 branchR->GetEntry(0);
ea6ddc2c 290 }
291
292 return 0;
88cb7938 293}