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