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