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