1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for PHOS calibration //
22 ///////////////////////////////////////////////////////////////////////////////
26 #include "AliPHOSCalibData.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
30 #include "AliCDBEntry.h"
31 #include "AliPHOSEmcCalibData.h"
32 #include "AliPHOSCpvCalibData.h"
33 #include "AliPHOSEmcBadChannelsMap.h"
34 #include "AliCDBMetaData.h"
36 ClassImp(AliPHOSCalibData)
38 //________________________________________________________________
39 AliPHOSCalibData::AliPHOSCalibData():
43 fEmcBadChannelsMap(0x0),
44 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
45 fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
46 fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
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
54 //________________________________________________________________
55 AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
56 TNamed("phosCalib","PHOS Calibration Data Manager"),
57 fCalibDataEmc(0x0), fCalibDataCpv(0x0), fEmcBadChannelsMap(0x0),
58 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
59 fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
60 fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
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
66 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
68 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
71 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction!\n");
73 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
75 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
78 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction!\n");
80 AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->
81 Get(fEmcBadChannelsMapPath.Data(),runNumber);
83 fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject();
87 //________________________________________________________________
88 AliPHOSCalibData::AliPHOSCalibData(AliPHOSCalibData & phosCDB) :
90 fCalibDataEmc(phosCDB.fCalibDataEmc),
91 fCalibDataCpv(phosCDB.fCalibDataCpv),
92 fEmcBadChannelsMap(phosCDB.fEmcBadChannelsMap),
93 fEmcDataPath(phosCDB.fEmcDataPath),
94 fCpvDataPath(phosCDB.fCpvDataPath),
95 fEmcBadChannelsMapPath(phosCDB.fEmcBadChannelsMapPath)
99 //________________________________________________________________
100 AliPHOSCalibData::~AliPHOSCalibData()
106 AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
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;
114 fEmcBadChannelsMap = rhs.fEmcBadChannelsMap;
115 fEmcDataPath = rhs.fEmcDataPath;
116 fCpvDataPath = rhs.fCpvDataPath;
117 fEmcBadChannelsMapPath = rhs.fEmcBadChannelsMapPath;
122 //________________________________________________________________
123 void AliPHOSCalibData::Reset()
125 // Set all pedestals to 0 and all ADC channels to 1,
126 // and all channels are good (alive)
128 fCalibDataEmc ->Reset();
129 fCalibDataCpv ->Reset();
130 fEmcBadChannelsMap->Reset();
133 //________________________________________________________________
134 void AliPHOSCalibData::Print(Option_t *option) const
136 // Print EMC and CPV calibration containers
137 // Input: option="ped" to print pedestals
138 // option="gain" to print calibration coefficients
139 if (fCalibDataEmc) fCalibDataEmc->Print(option);
140 if (fCalibDataCpv) fCalibDataCpv->Print(option);
143 //________________________________________________________________
144 void AliPHOSCalibData::CreateNew()
146 // Create new EMC and CPV calibration containers with ideal coefficients
148 if(fCalibDataEmc) delete fCalibDataEmc;
149 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
151 if(fCalibDataCpv) delete fCalibDataCpv;
152 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
154 if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
155 fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
159 //________________________________________________________________
160 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
162 // Write EMC calibration container to CDB
164 if(!fCalibDataEmc) return kFALSE;
166 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
168 storage = AliCDBManager::Instance()->GetDefaultStorage();
171 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
172 storage->Put(fCalibDataEmc,id, md);
180 //________________________________________________________________
181 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
183 // Write CPV calibration container to CDB
185 if(!fCalibDataCpv) return kFALSE;
187 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
189 storage = AliCDBManager::Instance()->GetDefaultStorage();
192 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
193 storage->Put(fCalibDataCpv,id, md);
202 //________________________________________________________________
203 Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
205 //Write EMC bad channels map into CDB.
207 if(!fEmcBadChannelsMap) return kFALSE;
209 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
211 storage = AliCDBManager::Instance()->GetDefaultStorage();
214 AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
215 storage->Put(fEmcBadChannelsMap,id, md);
222 //________________________________________________________________
223 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
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
233 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
235 return 1.0; // default width of one EMC ADC channel in GeV
238 //________________________________________________________________
239 void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
241 // Set EMC calibration coefficient for (module,column,row)
244 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
246 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
249 //________________________________________________________________
250 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
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
259 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
261 return 0.0; // default EMC ADC pedestal
264 //________________________________________________________________
265 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
267 // Set EMC pedestal for (module,column,row)
270 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
272 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
275 //________________________________________________________________
276 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
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
286 return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
288 return 1.0; // default width of one EMC ADC channel in GeV
291 //________________________________________________________________
292 void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
294 // Set EMC calibration coefficient for (module,column,row)
297 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
299 fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
302 //________________________________________________________________
303 Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
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
313 return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
315 return 1.0; // default width of one EMC ADC channel in GeV
318 //________________________________________________________________
319 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
321 // Set EMC calibration coefficient for (module,column,row)
324 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
326 fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
328 //________________________________________________________________
329 Float_t AliPHOSCalibData::GetSampleTimeStep() const
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.
335 return fCalibDataEmc->GetSampleTimeStep();
337 return 0.0; // default width of one EMC ADC channel in GeV
339 //________________________________________________________________
340 void AliPHOSCalibData::SetSampleTimeStep(Float_t step)
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.
346 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
348 fCalibDataEmc->SetSampleTimeStep(step) ;
350 //________________________________________________________________
351 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
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
361 return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
363 return 0; // default width of one EMC ADC channel in GeV
366 //________________________________________________________________
367 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
369 // Set altro offset for (module,column,row)
372 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
374 fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
378 //________________________________________________________________
379 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
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
389 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
391 return 0.0012; // default width of one ADC channel in CPV arbitrary units
394 //________________________________________________________________
395 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
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
405 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
407 return 0.012; // default CPV ADC pedestal
410 //________________________________________________________________
411 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
413 // Set CPV calibration coefficient for (module,column,row)
416 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
418 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
421 //________________________________________________________________
422 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
424 // Set CPV pedestal for (module,column,row)
427 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
429 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
432 //________________________________________________________________
433 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
435 // Create decalibrated EMC with calibration coefficients and pedestals
436 // randomly distributed within hard-coded limits
437 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
439 if(fCalibDataEmc) delete fCalibDataEmc;
440 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
443 rn.SetSeed(0); //the seed is set to the current machine clock
445 Float_t adcChannelEmc,adcPedestalEmc;
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++) {
450 adcChannelEmc =rn.Uniform(ccMin,ccMax);
451 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
452 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
453 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
460 //________________________________________________________________
461 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
463 // Create decalibrated CPV with calibration coefficients and pedestals
464 // randomly distributed within hard-coded limits
465 // Default spread of calibration parameters is 0.0012 +- 25%
467 if(fCalibDataCpv) delete fCalibDataCpv;
468 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
471 rn.SetSeed(0); //the seed is set to the current machine clock
473 Float_t adcChannelCpv,adcPedestalCpv;
475 for(Int_t module=1; module<6; module++) {
476 for(Int_t column=1; column<57; column++) {
477 for(Int_t row=1; row<129; row++) {
478 adcChannelCpv =rn.Uniform(ccMin,ccMax);
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);
486 //________________________________________________________________
487 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
489 //If no bad channels map found, channel considered good
491 if(fEmcBadChannelsMap)
492 return fEmcBadChannelsMap->IsBadChannel(module,col,row);
497 //________________________________________________________________
498 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
500 if(fEmcBadChannelsMap)
501 return fEmcBadChannelsMap->GetNumOfBadChannels();
505 //________________________________________________________________
506 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
508 //Fill array badIds by the Ids of EMC bad channels.
509 //Array badIds of length GetNumOfBadChannels() should be prepared in advance.
511 if(fEmcBadChannelsMap)
512 fEmcBadChannelsMap->BadChannelIds(badIds);
515 //________________________________________________________________
516 Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
518 // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row).
519 // Used in simulation.
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).
527 return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
529 return 1.0; // no decalibration by default
532 //________________________________________________________________
533 void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
535 // Set EMC (de)calibration factor for (module,column,row).
536 // Used in simulation.
539 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
541 fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);