L1phase shift corrected
[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
49519b04 51
52783dbc 52}
53
54//________________________________________________________________
fc6706cb 55AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
56 TNamed("phosCalib","PHOS Calibration Data Manager"),
81701069 57 fCalibDataEmc(0x0), fCalibDataCpv(0x0), fEmcBadChannelsMap(0x0),
3f7dbdb7 58 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
81701069 59 fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
60 fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
52783dbc 61{
62 // Constructor
76d78b7a 63 // Open CDB entry, get EMC and CPV calibration data and bad channel map.
64 // If EMC or CPV calibration data does not exist, stop the run
65
fc6706cb 66 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
67 if(entryEmc)
68 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
76d78b7a 69
70 if(!fCalibDataEmc)
71 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction!\n");
fc6706cb 72
73 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
74 if(entryCpv)
75 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
52783dbc 76
76d78b7a 77 if(!fCalibDataCpv)
78 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction!\n");
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{
b8628054 125 // Set all pedestals to 0 and all ADC channels to 1,
126 // and all channels are good (alive)
fc6706cb 127
b8628054 128 fCalibDataEmc ->Reset();
129 fCalibDataCpv ->Reset();
130 fEmcBadChannelsMap->Reset();
52783dbc 131}
132
133//________________________________________________________________
134void AliPHOSCalibData::Print(Option_t *option) const
135{
1fdb1c5e 136 // Print EMC and CPV calibration containers
137 // Input: option="ped" to print pedestals
138 // option="gain" to print calibration coefficients
df0d5123 139 if (fCalibDataEmc) fCalibDataEmc->Print(option);
140 if (fCalibDataCpv) fCalibDataCpv->Print(option);
fc6706cb 141}
142
143//________________________________________________________________
144void AliPHOSCalibData::CreateNew()
145{
1fdb1c5e 146 // Create new EMC and CPV calibration containers with ideal coefficients
147
fc6706cb 148 if(fCalibDataEmc) delete fCalibDataEmc;
149 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
150
151 if(fCalibDataCpv) delete fCalibDataCpv;
152 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
153
81701069 154 if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
155 fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
156
fc6706cb 157}
158
159//________________________________________________________________
160Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
161{
1fdb1c5e 162 // Write EMC calibration container to CDB
fc6706cb 163
164 if(!fCalibDataEmc) return kFALSE;
165
18669c5c 166 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
df0d5123 167 if(!storage)
168 storage = AliCDBManager::Instance()->GetDefaultStorage();
169
fc6706cb 170 if(storage) {
171 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
172 storage->Put(fCalibDataEmc,id, md);
173 return kTRUE;
52783dbc 174 }
fc6706cb 175 else
176 return kFALSE;
52783dbc 177
fc6706cb 178}
179
180//________________________________________________________________
181Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
182{
1fdb1c5e 183 // Write CPV calibration container to CDB
fc6706cb 184
185 if(!fCalibDataCpv) return kFALSE;
186
18669c5c 187 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
df0d5123 188 if(!storage)
189 storage = AliCDBManager::Instance()->GetDefaultStorage();
190
fc6706cb 191 if(storage) {
192 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
193 storage->Put(fCalibDataCpv,id, md);
194 return kTRUE;
52783dbc 195 }
fc6706cb 196 else
197 return kFALSE;
198
52783dbc 199}
072de3a8 200
81701069 201
202//________________________________________________________________
203Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
204{
205 //Write EMC bad channels map into CDB.
206
207 if(!fEmcBadChannelsMap) return kFALSE;
208
209 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
210 if(!storage)
211 storage = AliCDBManager::Instance()->GetDefaultStorage();
212
213 if(storage) {
214 AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
215 storage->Put(fEmcBadChannelsMap,id, md);
216 return kTRUE;
217 }
218 else
219 return kFALSE;
220}
221
fc6706cb 222//________________________________________________________________
072de3a8 223Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
224{
1fdb1c5e 225 // Return EMC calibration coefficient
226 // for channel defined by (module,column,row)
227 // module, column,raw should follow the internal PHOS convention:
228 // module 1:5, column 1:56, row 1:64
229 // if CBD instance exists, the value is taken from CDB.
230 // Otherwise it is an ideal one
072de3a8 231
fc6706cb 232 if(fCalibDataEmc)
233 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
234 else
5f8bb860 235 return 1.0; // default width of one EMC ADC channel in GeV
072de3a8 236}
237
1fdb1c5e 238//________________________________________________________________
e3310625 239void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
240{
241 // Set EMC calibration coefficient for (module,column,row)
242
243 if(!fCalibDataEmc)
244 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
245
246 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
247}
248
249//________________________________________________________________
072de3a8 250Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
251{
1fdb1c5e 252 // Return EMC pedestal for channel defined by (module,column,row)
253 // module, column,raw should follow the internal PHOS convention:
254 // module 1:5, column 1:56, row 1:64
255 // if CBD instance exists, the value is taken from CDB.
256 // Otherwise it is an ideal one
257
fc6706cb 258 if(fCalibDataEmc)
259 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
260 else
5f8bb860 261 return 0.0; // default EMC ADC pedestal
072de3a8 262}
263
1fdb1c5e 264//________________________________________________________________
e3310625 265void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
072de3a8 266{
e3310625 267 // Set EMC pedestal for (module,column,row)
1fdb1c5e 268
fc6706cb 269 if(!fCalibDataEmc)
270 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
271
e3310625 272 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
072de3a8 273}
274
1fdb1c5e 275//________________________________________________________________
e3310625 276Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
072de3a8 277{
e3310625 278 // Return EMC calibration coefficient
279 // for channel defined by (module,column,row)
280 // module, column,raw should follow the internal PHOS convention:
281 // module 1:5, column 1:56, row 1:64
282 // if CBD instance exists, the value is taken from CDB.
283 // Otherwise it is an ideal one
284
285 if(fCalibDataEmc)
286 return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
287 else
288 return 1.0; // default width of one EMC ADC channel in GeV
289}
290
291//________________________________________________________________
292void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
293{
294 // Set EMC calibration coefficient for (module,column,row)
295
fc6706cb 296 if(!fCalibDataEmc)
297 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
e3310625 298
299 fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
fc6706cb 300}
e3310625 301
302//________________________________________________________________
303Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
304{
305 // Return EMC calibration coefficient
306 // for channel defined by (module,column,row)
307 // module, column,raw should follow the internal PHOS convention:
308 // module 1:5, column 1:56, row 1:64
309 // if CBD instance exists, the value is taken from CDB.
310 // Otherwise it is an ideal one
311
312 if(fCalibDataEmc)
313 return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
314 else
315 return 1.0; // default width of one EMC ADC channel in GeV
316}
317
318//________________________________________________________________
319void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
320{
321 // Set EMC calibration coefficient for (module,column,row)
322
323 if(!fCalibDataEmc)
324 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
325
326 fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
327}
bafc1087 328//________________________________________________________________
6f47f50d 329Float_t AliPHOSCalibData::GetSampleTimeStep() const
330{
331 //Get conversion coeff. from sample time step to seconds.
332 //Negative value means that it is not used in reconstruction
333 //but only in simulation of raw.
334 if(fCalibDataEmc)
335 return fCalibDataEmc->GetSampleTimeStep();
336 else
337 return 0.0; // default width of one EMC ADC channel in GeV
338}
339//________________________________________________________________
340void AliPHOSCalibData::SetSampleTimeStep(Float_t step)
341{
342 //Set conversion coeff. from sample time step to seconds.
343 //Negative value means that it is not used in reconstruction
344 //but only in simulation of raw.
345 if(!fCalibDataEmc)
346 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
347
348 fCalibDataEmc->SetSampleTimeStep(step) ;
349}
350//________________________________________________________________
bafc1087 351Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
352{
353 // Return ALTRO pedestal coefficient
354 // for channel defined by (module,column,row)
355 // module, column,raw should follow the internal PHOS convention:
356 // module 1:5, column 1:56, row 1:64
357 // if CBD instance exists, the value is taken from CDB.
358 // Otherwise it is an ideal one
359
360 if(fCalibDataEmc)
361 return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
362 else
363 return 0; // default width of one EMC ADC channel in GeV
364}
365
366//________________________________________________________________
367void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
368{
369 // Set altro offset for (module,column,row)
370
371 if(!fCalibDataEmc)
372 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
373
374 fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
375}
376
e3310625 377
fc6706cb 378//________________________________________________________________
379Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
380{
1fdb1c5e 381 // Return CPV calibration coefficient
382 // for channel defined by (module,column,row)
383 // module, column,raw should follow the internal CPV convention:
384 // module 1:5, column 1:56, row 1:128
385 // if CBD instance exists, the value is taken from CDB.
386 // Otherwise it is an ideal one
fc6706cb 387
388 if(fCalibDataCpv)
389 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
390 else
5f8bb860 391 return 0.0012; // default width of one ADC channel in CPV arbitrary units
fc6706cb 392}
393
1fdb1c5e 394//________________________________________________________________
fc6706cb 395Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
396{
1fdb1c5e 397 // Return CPV pedestal
398 // for channel defined by (module,column,row)
399 // module, column,raw should follow the internal CPV convention:
400 // module 1:5, column 1:56, row 1:128
401 // if CBD instance exists, the value is taken from CDB.
402 // Otherwise it is an ideal one
403
fc6706cb 404 if(fCalibDataCpv)
405 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
406 else
407 return 0.012; // default CPV ADC pedestal
408}
409
1fdb1c5e 410//________________________________________________________________
fc6706cb 411void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
412{
1fdb1c5e 413 // Set CPV calibration coefficient for (module,column,row)
414
fc6706cb 415 if(!fCalibDataCpv)
416 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
417
418 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
419}
420
1fdb1c5e 421//________________________________________________________________
fc6706cb 422void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
423{
1fdb1c5e 424 // Set CPV pedestal for (module,column,row)
425
fc6706cb 426 if(!fCalibDataCpv)
427 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
428
429 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
430}
431
432//________________________________________________________________
e2e977c3 433void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
fc6706cb 434{
1fdb1c5e 435 // Create decalibrated EMC with calibration coefficients and pedestals
436 // randomly distributed within hard-coded limits
e2e977c3 437 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
fc6706cb 438
439 if(fCalibDataEmc) delete fCalibDataEmc;
440 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
441
442 TRandom rn;
443 rn.SetSeed(0); //the seed is set to the current machine clock
444
1fdb1c5e 445 Float_t adcChannelEmc,adcPedestalEmc;
fc6706cb 446
447 for(Int_t module=1; module<6; module++) {
448 for(Int_t column=1; column<57; column++) {
449 for(Int_t row=1; row<65; row++) {
e2e977c3 450 adcChannelEmc =rn.Uniform(ccMin,ccMax);
5f8bb860 451 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
1fdb1c5e 452 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
453 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
fc6706cb 454 }
455 }
456 }
457
458}
459
460//________________________________________________________________
e2e977c3 461void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
fc6706cb 462{
1fdb1c5e 463 // Create decalibrated CPV with calibration coefficients and pedestals
464 // randomly distributed within hard-coded limits
e2e977c3 465 // Default spread of calibration parameters is 0.0012 +- 25%
fc6706cb 466
467 if(fCalibDataCpv) delete fCalibDataCpv;
468 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
469
470 TRandom rn;
471 rn.SetSeed(0); //the seed is set to the current machine clock
472
1fdb1c5e 473 Float_t adcChannelCpv,adcPedestalCpv;
fc6706cb 474
475 for(Int_t module=1; module<6; module++) {
5f8bb860 476 for(Int_t column=1; column<57; column++) {
fc6706cb 477 for(Int_t row=1; row<129; row++) {
e2e977c3 478 adcChannelCpv =rn.Uniform(ccMin,ccMax);
1fdb1c5e 479 adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
480 fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
481 fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
fc6706cb 482 }
483 }
484 }
072de3a8 485}
81701069 486//________________________________________________________________
487Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
488{
489 //If no bad channels map found, channel considered good
490
491 if(fEmcBadChannelsMap)
492 return fEmcBadChannelsMap->IsBadChannel(module,col,row);
493 else
494 return kFALSE;
495}
496
497//________________________________________________________________
498Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
499{
500 if(fEmcBadChannelsMap)
501 return fEmcBadChannelsMap->GetNumOfBadChannels();
502 else
503 return 0;
504}
d940eb29 505//________________________________________________________________
506void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
507{
508 //Fill array badIds by the Ids of EMC bad channels.
509 //Array badIds of length GetNumOfBadChannels() should be prepared in advance.
510
511 if(fEmcBadChannelsMap)
512 fEmcBadChannelsMap->BadChannelIds(badIds);
513}
d5b302a6 514
515//________________________________________________________________
516Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
517{
518 // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row).
519 // Used in simulation.
520
521 // module, column,raw should follow the internal PHOS convention:
522 // module 1:5, column 1:56, row 1:64
523 // if CBD instance exists, the value is taken from CDB.
524 // Otherwise it is an ideal one (no decalibration).
525
526 if(fCalibDataEmc)
527 return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
528 else
529 return 1.0; // no decalibration by default
530}
531
532//________________________________________________________________
533void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
534{
535 // Set EMC (de)calibration factor for (module,column,row).
536 // Used in simulation.
537
538 if(!fCalibDataEmc)
539 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
540
541 fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);
542}