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
52 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data());
54 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
57 AliWarning("Calibration parameters for PHOS EMC not found. Create a new set.\n");
59 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data());
61 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
64 AliWarning("Calibration parameters for PHOS CPV not found. Create a new set.\n");
66 AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->Get(fEmcBadChannelsMapPath.Data());
68 fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject();
72 //________________________________________________________________
73 AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
74 TNamed("phosCalib","PHOS Calibration Data Manager"),
75 fCalibDataEmc(0x0), fCalibDataCpv(0x0), fEmcBadChannelsMap(0x0),
76 fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
77 fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
78 fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
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
84 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
86 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
89 AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction!\n");
91 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
93 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
96 AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction!\n");
98 AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->
99 Get(fEmcBadChannelsMapPath.Data(),runNumber);
101 fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject();
105 //________________________________________________________________
106 AliPHOSCalibData::AliPHOSCalibData(AliPHOSCalibData & phosCDB) :
108 fCalibDataEmc(phosCDB.fCalibDataEmc),
109 fCalibDataCpv(phosCDB.fCalibDataCpv),
110 fEmcBadChannelsMap(phosCDB.fEmcBadChannelsMap),
111 fEmcDataPath(phosCDB.fEmcDataPath),
112 fCpvDataPath(phosCDB.fCpvDataPath),
113 fEmcBadChannelsMapPath(phosCDB.fEmcBadChannelsMapPath)
117 //________________________________________________________________
118 AliPHOSCalibData::~AliPHOSCalibData()
124 AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
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;
132 fEmcBadChannelsMap = rhs.fEmcBadChannelsMap;
133 fEmcDataPath = rhs.fEmcDataPath;
134 fCpvDataPath = rhs.fCpvDataPath;
135 fEmcBadChannelsMapPath = rhs.fEmcBadChannelsMapPath;
140 //________________________________________________________________
141 void AliPHOSCalibData::Reset()
143 // Set all pedestals to 0 and all ADC channels to 1,
144 // and all channels are good (alive)
146 fCalibDataEmc ->Reset();
147 fCalibDataCpv ->Reset();
148 fEmcBadChannelsMap->Reset();
151 //________________________________________________________________
152 void AliPHOSCalibData::Print(Option_t *option) const
154 // Print EMC and CPV calibration containers
155 // Input: option="ped" to print pedestals
156 // option="gain" to print calibration coefficients
157 if (fCalibDataEmc) fCalibDataEmc->Print(option);
158 if (fCalibDataCpv) fCalibDataCpv->Print(option);
161 //________________________________________________________________
162 void AliPHOSCalibData::CreateNew()
164 // Create new EMC and CPV calibration containers with ideal coefficients
166 if(fCalibDataEmc) delete fCalibDataEmc;
167 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
169 if(fCalibDataCpv) delete fCalibDataCpv;
170 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
172 if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
173 fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
177 //________________________________________________________________
178 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
180 // Write EMC calibration container to CDB
182 if(!fCalibDataEmc) return kFALSE;
184 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
186 storage = AliCDBManager::Instance()->GetDefaultStorage();
189 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
190 storage->Put(fCalibDataEmc,id, md);
198 //________________________________________________________________
199 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
201 // Write CPV calibration container to CDB
203 if(!fCalibDataCpv) return kFALSE;
205 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
207 storage = AliCDBManager::Instance()->GetDefaultStorage();
210 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
211 storage->Put(fCalibDataCpv,id, md);
220 //________________________________________________________________
221 Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
223 //Write EMC bad channels map into CDB.
225 if(!fEmcBadChannelsMap) return kFALSE;
227 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
229 storage = AliCDBManager::Instance()->GetDefaultStorage();
232 AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
233 storage->Put(fEmcBadChannelsMap,id, md);
240 //________________________________________________________________
241 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
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
251 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
253 return 1.0; // default width of one EMC ADC channel in GeV
256 //________________________________________________________________
257 void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
259 // Set EMC calibration coefficient for (module,column,row)
262 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
264 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
267 //________________________________________________________________
268 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
270 // Return EMC pedestal for channel defined by (module,column,row)
271 // module, column,raw should follow the internal PHOS convention:
272 // module 1:5, column 1:56, row 1:64
273 // if CBD instance exists, the value is taken from CDB.
274 // Otherwise it is an ideal one
277 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
279 return 0.0; // default EMC ADC pedestal
282 //________________________________________________________________
283 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
285 // Set EMC pedestal for (module,column,row)
288 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
290 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
293 //________________________________________________________________
294 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
296 // Return EMC calibration coefficient
297 // for channel defined by (module,column,row)
298 // module, column,raw should follow the internal PHOS convention:
299 // module 1:5, column 1:56, row 1:64
300 // if CBD instance exists, the value is taken from CDB.
301 // Otherwise it is an ideal one
304 return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
306 return 1.0; // default width of one EMC ADC channel in GeV
309 //________________________________________________________________
310 void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
312 // Set EMC calibration coefficient for (module,column,row)
315 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
317 fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
320 //________________________________________________________________
321 Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
323 // Return EMC calibration coefficient
324 // for channel defined by (module,column,row)
325 // module, column,raw should follow the internal PHOS convention:
326 // module 1:5, column 1:56, row 1:64
327 // if CBD instance exists, the value is taken from CDB.
328 // Otherwise it is an ideal one
331 return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
333 return 1.0; // default width of one EMC ADC channel in GeV
336 //________________________________________________________________
337 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
339 // Set EMC calibration coefficient for (module,column,row)
342 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
344 fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
346 //________________________________________________________________
347 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
349 // Return ALTRO pedestal coefficient
350 // for channel defined by (module,column,row)
351 // module, column,raw should follow the internal PHOS convention:
352 // module 1:5, column 1:56, row 1:64
353 // if CBD instance exists, the value is taken from CDB.
354 // Otherwise it is an ideal one
357 return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
359 return 0; // default width of one EMC ADC channel in GeV
362 //________________________________________________________________
363 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
365 // Set altro offset for (module,column,row)
368 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
370 fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
374 //________________________________________________________________
375 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
377 // Return CPV calibration coefficient
378 // for channel defined by (module,column,row)
379 // module, column,raw should follow the internal CPV convention:
380 // module 1:5, column 1:56, row 1:128
381 // if CBD instance exists, the value is taken from CDB.
382 // Otherwise it is an ideal one
385 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
387 return 0.0012; // default width of one ADC channel in CPV arbitrary units
390 //________________________________________________________________
391 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
393 // Return CPV pedestal
394 // for channel defined by (module,column,row)
395 // module, column,raw should follow the internal CPV convention:
396 // module 1:5, column 1:56, row 1:128
397 // if CBD instance exists, the value is taken from CDB.
398 // Otherwise it is an ideal one
401 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
403 return 0.012; // default CPV ADC pedestal
406 //________________________________________________________________
407 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
409 // Set CPV calibration coefficient for (module,column,row)
412 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
414 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
417 //________________________________________________________________
418 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
420 // Set CPV pedestal for (module,column,row)
423 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
425 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
428 //________________________________________________________________
429 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
431 // Create decalibrated EMC with calibration coefficients and pedestals
432 // randomly distributed within hard-coded limits
433 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
435 if(fCalibDataEmc) delete fCalibDataEmc;
436 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
439 rn.SetSeed(0); //the seed is set to the current machine clock
441 Float_t adcChannelEmc,adcPedestalEmc;
443 for(Int_t module=1; module<6; module++) {
444 for(Int_t column=1; column<57; column++) {
445 for(Int_t row=1; row<65; row++) {
446 adcChannelEmc =rn.Uniform(ccMin,ccMax);
447 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
448 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
449 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
456 //________________________________________________________________
457 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
459 // Create decalibrated CPV with calibration coefficients and pedestals
460 // randomly distributed within hard-coded limits
461 // Default spread of calibration parameters is 0.0012 +- 25%
463 if(fCalibDataCpv) delete fCalibDataCpv;
464 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
467 rn.SetSeed(0); //the seed is set to the current machine clock
469 Float_t adcChannelCpv,adcPedestalCpv;
471 for(Int_t module=1; module<6; module++) {
472 for(Int_t column=1; column<57; column++) {
473 for(Int_t row=1; row<129; row++) {
474 adcChannelCpv =rn.Uniform(ccMin,ccMax);
475 adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
476 fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
477 fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
483 //________________________________________________________________
484 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
486 //If no bad channels map found, channel considered good
488 if(fEmcBadChannelsMap)
489 return fEmcBadChannelsMap->IsBadChannel(module,col,row);
494 //________________________________________________________________
495 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
497 if(fEmcBadChannelsMap)
498 return fEmcBadChannelsMap->GetNumOfBadChannels();
503 //________________________________________________________________
504 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
506 //Fill array badIds by the Ids of EMC bad channels.
507 //Array badIds of length GetNumOfBadChannels() should be prepared in advance.
509 if(fEmcBadChannelsMap)
510 fEmcBadChannelsMap->BadChannelIds(badIds);