Modifications needed to run analysis with proof.
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibData.cxx
CommitLineData
52783dbc 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// //
20// class for PHOS calibration //
21// //
22///////////////////////////////////////////////////////////////////////////////
23
fc6706cb 24#include "TRandom.h"
52783dbc 25#include "AliPHOSCalibData.h"
fc6706cb 26#include "AliCDBManager.h"
27#include "AliCDBStorage.h"
28#include "AliCDBId.h"
29#include "AliCDBEntry.h"
1fdb1c5e 30#include "AliPHOSEmcCalibData.h"
31#include "AliPHOSCpvCalibData.h"
32#include "AliCDBMetaData.h"
52783dbc 33
34ClassImp(AliPHOSCalibData)
35
36//________________________________________________________________
fc6706cb 37 AliPHOSCalibData::AliPHOSCalibData():
3f7dbdb7 38 TNamed(),
39 fCalibDataEmc(0x0),
40 fCalibDataCpv(0x0),
41 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
42 fCpvDataPath("PHOS/Calib/CpvGainPedestals")
52783dbc 43{
3f7dbdb7 44 // Default constructor
45
abcff5fc 46 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data());
47 if(entryEmc)
48 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
49
50 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data());
51 if(entryCpv)
52 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
53
52783dbc 54}
55
56//________________________________________________________________
fc6706cb 57AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
58 TNamed("phosCalib","PHOS Calibration Data Manager"),
3f7dbdb7 59 fCalibDataEmc(0x0), fCalibDataCpv(0x0),
60 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
61 fCpvDataPath("PHOS/Calib/CpvGainPedestals")
52783dbc 62{
63 // Constructor
fc6706cb 64 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
65 if(entryEmc)
66 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
67
68 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
69 if(entryCpv)
70 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
52783dbc 71
52783dbc 72}
73
74//________________________________________________________________
1fdb1c5e 75AliPHOSCalibData::AliPHOSCalibData(AliPHOSCalibData & phosCDB) :
3f7dbdb7 76 TNamed(phosCDB),
77 fCalibDataEmc(phosCDB.fCalibDataEmc),
78 fCalibDataCpv(phosCDB.fCalibDataCpv),
79 fEmcDataPath(phosCDB.fEmcDataPath),
80 fCpvDataPath(phosCDB.fCpvDataPath)
1fdb1c5e 81{
82 // Copy constructor
1fdb1c5e 83}
84//________________________________________________________________
52783dbc 85AliPHOSCalibData::~AliPHOSCalibData()
86{
87 // Destructor
fc6706cb 88
52783dbc 89}
90
3f7dbdb7 91AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
92{
93 //Copy-assignment. Does not delete anything (see destructor)
94 //compiler generated is ok, but ... because -Weffc++ and pointer
95 //members we have to define it explicitly.
96 TNamed::operator=(rhs);
97 fCalibDataEmc = rhs.fCalibDataEmc;
98 fCalibDataCpv = rhs.fCalibDataCpv;
99 fEmcDataPath = rhs.fEmcDataPath;
100 fCpvDataPath = rhs.fCpvDataPath;
101
102 return *this;
103}
104
52783dbc 105//________________________________________________________________
106void AliPHOSCalibData::Reset()
107{
108 // Set all pedestals to 0 and all ADC channels to 1
fc6706cb 109
110 fCalibDataEmc->Reset();
111 fCalibDataCpv->Reset();
52783dbc 112}
113
114//________________________________________________________________
115void AliPHOSCalibData::Print(Option_t *option) const
116{
1fdb1c5e 117 // Print EMC and CPV calibration containers
118 // Input: option="ped" to print pedestals
119 // option="gain" to print calibration coefficients
df0d5123 120 if (fCalibDataEmc) fCalibDataEmc->Print(option);
121 if (fCalibDataCpv) fCalibDataCpv->Print(option);
fc6706cb 122}
123
124//________________________________________________________________
125void AliPHOSCalibData::CreateNew()
126{
1fdb1c5e 127 // Create new EMC and CPV calibration containers with ideal coefficients
128
fc6706cb 129 if(fCalibDataEmc) delete fCalibDataEmc;
130 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
131
132 if(fCalibDataCpv) delete fCalibDataCpv;
133 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
134
135}
136
137//________________________________________________________________
138Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
139{
1fdb1c5e 140 // Write EMC calibration container to CDB
fc6706cb 141
142 if(!fCalibDataEmc) return kFALSE;
143
18669c5c 144 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
df0d5123 145 if(!storage)
146 storage = AliCDBManager::Instance()->GetDefaultStorage();
147
fc6706cb 148 if(storage) {
149 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
150 storage->Put(fCalibDataEmc,id, md);
151 return kTRUE;
52783dbc 152 }
fc6706cb 153 else
154 return kFALSE;
52783dbc 155
fc6706cb 156}
157
158//________________________________________________________________
159Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
160{
1fdb1c5e 161 // Write CPV calibration container to CDB
fc6706cb 162
163 if(!fCalibDataCpv) return kFALSE;
164
18669c5c 165 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
df0d5123 166 if(!storage)
167 storage = AliCDBManager::Instance()->GetDefaultStorage();
168
fc6706cb 169 if(storage) {
170 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
171 storage->Put(fCalibDataCpv,id, md);
172 return kTRUE;
52783dbc 173 }
fc6706cb 174 else
175 return kFALSE;
176
52783dbc 177}
072de3a8 178
fc6706cb 179//________________________________________________________________
072de3a8 180Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
181{
1fdb1c5e 182 // Return EMC calibration coefficient
183 // for channel defined by (module,column,row)
184 // module, column,raw should follow the internal PHOS convention:
185 // module 1:5, column 1:56, row 1:64
186 // if CBD instance exists, the value is taken from CDB.
187 // Otherwise it is an ideal one
072de3a8 188
fc6706cb 189 if(fCalibDataEmc)
190 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
191 else
5f8bb860 192 return 1.0; // default width of one EMC ADC channel in GeV
072de3a8 193}
194
1fdb1c5e 195//________________________________________________________________
072de3a8 196Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
197{
1fdb1c5e 198 // Return EMC pedestal for channel defined by (module,column,row)
199 // module, column,raw should follow the internal PHOS convention:
200 // module 1:5, column 1:56, row 1:64
201 // if CBD instance exists, the value is taken from CDB.
202 // Otherwise it is an ideal one
203
fc6706cb 204 if(fCalibDataEmc)
205 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
206 else
5f8bb860 207 return 0.0; // default EMC ADC pedestal
072de3a8 208}
209
1fdb1c5e 210//________________________________________________________________
072de3a8 211void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
212{
1fdb1c5e 213 // Set EMC calibration coefficient for (module,column,row)
214
fc6706cb 215 if(!fCalibDataEmc)
216 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
217
218 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
072de3a8 219}
220
1fdb1c5e 221//________________________________________________________________
072de3a8 222void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
223{
1fdb1c5e 224 // Set EMC pedestal for (module,column,row)
225
fc6706cb 226 if(!fCalibDataEmc)
227 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
228
229 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
230}
231
232//________________________________________________________________
233Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
234{
1fdb1c5e 235 // Return CPV calibration coefficient
236 // for channel defined by (module,column,row)
237 // module, column,raw should follow the internal CPV convention:
238 // module 1:5, column 1:56, row 1:128
239 // if CBD instance exists, the value is taken from CDB.
240 // Otherwise it is an ideal one
fc6706cb 241
242 if(fCalibDataCpv)
243 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
244 else
5f8bb860 245 return 0.0012; // default width of one ADC channel in CPV arbitrary units
fc6706cb 246}
247
1fdb1c5e 248//________________________________________________________________
fc6706cb 249Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
250{
1fdb1c5e 251 // Return CPV pedestal
252 // for channel defined by (module,column,row)
253 // module, column,raw should follow the internal CPV convention:
254 // module 1:5, column 1:56, row 1:128
255 // if CBD instance exists, the value is taken from CDB.
256 // Otherwise it is an ideal one
257
fc6706cb 258 if(fCalibDataCpv)
259 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
260 else
261 return 0.012; // default CPV ADC pedestal
262}
263
1fdb1c5e 264//________________________________________________________________
fc6706cb 265void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
266{
1fdb1c5e 267 // Set CPV calibration coefficient for (module,column,row)
268
fc6706cb 269 if(!fCalibDataCpv)
270 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
271
272 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
273}
274
1fdb1c5e 275//________________________________________________________________
fc6706cb 276void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
277{
1fdb1c5e 278 // Set CPV pedestal for (module,column,row)
279
fc6706cb 280 if(!fCalibDataCpv)
281 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
282
283 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
284}
285
286//________________________________________________________________
e2e977c3 287void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
fc6706cb 288{
1fdb1c5e 289 // Create decalibrated EMC with calibration coefficients and pedestals
290 // randomly distributed within hard-coded limits
e2e977c3 291 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
fc6706cb 292
293 if(fCalibDataEmc) delete fCalibDataEmc;
294 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
295
296 TRandom rn;
297 rn.SetSeed(0); //the seed is set to the current machine clock
298
1fdb1c5e 299 Float_t adcChannelEmc,adcPedestalEmc;
fc6706cb 300
301 for(Int_t module=1; module<6; module++) {
302 for(Int_t column=1; column<57; column++) {
303 for(Int_t row=1; row<65; row++) {
e2e977c3 304 adcChannelEmc =rn.Uniform(ccMin,ccMax);
5f8bb860 305 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
1fdb1c5e 306 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
307 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
fc6706cb 308 }
309 }
310 }
311
312}
313
314//________________________________________________________________
e2e977c3 315void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
fc6706cb 316{
1fdb1c5e 317 // Create decalibrated CPV with calibration coefficients and pedestals
318 // randomly distributed within hard-coded limits
e2e977c3 319 // Default spread of calibration parameters is 0.0012 +- 25%
fc6706cb 320
321 if(fCalibDataCpv) delete fCalibDataCpv;
322 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
323
324 TRandom rn;
325 rn.SetSeed(0); //the seed is set to the current machine clock
326
1fdb1c5e 327 Float_t adcChannelCpv,adcPedestalCpv;
fc6706cb 328
329 for(Int_t module=1; module<6; module++) {
5f8bb860 330 for(Int_t column=1; column<57; column++) {
fc6706cb 331 for(Int_t row=1; row<129; row++) {
e2e977c3 332 adcChannelCpv =rn.Uniform(ccMin,ccMax);
1fdb1c5e 333 adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
334 fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
335 fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
fc6706cb 336 }
337 }
338 }
072de3a8 339}