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 //________________________________________________________________
107 AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
109 //Copy-assignment. Does not delete anything (see destructor)
110 //compiler generated is ok, but ... because -Weffc++ and pointer
111 //members we have to define it explicitly.
112 TNamed::operator=(rhs);
114 fCalibDataEmc = rhs.fCalibDataEmc;
115 fCalibDataCpv = rhs.fCalibDataCpv;
116 fEmcBadChannelsMap = rhs.fEmcBadChannelsMap;
117 fEmcDataPath = rhs.fEmcDataPath;
118 fCpvDataPath = rhs.fCpvDataPath;
119 fEmcBadChannelsMapPath = rhs.fEmcBadChannelsMapPath;
122 AliFatal("Self assignment!");
127 //________________________________________________________________
128 void AliPHOSCalibData::Reset()
130 // Set all pedestals to 0 and all ADC channels to 1,
131 // and all channels are good (alive)
133 fCalibDataEmc ->Reset();
134 fCalibDataCpv ->Reset();
135 fEmcBadChannelsMap->Reset();
138 //________________________________________________________________
139 void AliPHOSCalibData::Print(Option_t *option) const
141 // Print EMC and CPV calibration containers
142 // Input: option="ped" to print pedestals
143 // option="gain" to print calibration coefficients
144 if (fCalibDataEmc) fCalibDataEmc->Print(option);
145 if (fCalibDataCpv) fCalibDataCpv->Print(option);
148 //________________________________________________________________
149 void AliPHOSCalibData::CreateNew()
151 // Create new EMC and CPV calibration containers with ideal coefficients
153 if(fCalibDataEmc) delete fCalibDataEmc;
154 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
156 if(fCalibDataCpv) delete fCalibDataCpv;
157 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
159 if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
160 fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
164 //________________________________________________________________
165 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
167 // Write EMC calibration container to CDB
169 if(!fCalibDataEmc) return kFALSE;
171 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
173 storage = AliCDBManager::Instance()->GetDefaultStorage();
176 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
177 storage->Put(fCalibDataEmc,id, md);
185 //________________________________________________________________
186 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
188 // Write CPV calibration container to CDB
190 if(!fCalibDataCpv) return kFALSE;
192 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
194 storage = AliCDBManager::Instance()->GetDefaultStorage();
197 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
198 storage->Put(fCalibDataCpv,id, md);
207 //________________________________________________________________
208 Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
210 //Write EMC bad channels map into CDB.
212 if(!fEmcBadChannelsMap) return kFALSE;
214 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
216 storage = AliCDBManager::Instance()->GetDefaultStorage();
219 AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
220 storage->Put(fEmcBadChannelsMap,id, md);
227 //________________________________________________________________
228 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
230 // Return EMC calibration coefficient
231 // for channel defined by (module,column,row)
232 // module, column,raw should follow the internal PHOS convention:
233 // module 1:5, column 1:56, row 1:64
234 // if CBD instance exists, the value is taken from CDB.
235 // Otherwise it is an ideal one
238 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
240 return 1.0; // default width of one EMC ADC channel in GeV
243 //________________________________________________________________
244 void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
246 // Set EMC calibration coefficient for (module,column,row)
249 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
251 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
254 //________________________________________________________________
255 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
257 // Return EMC pedestal for channel defined by (module,column,row)
258 // module, column,raw should follow the internal PHOS convention:
259 // module 1:5, column 1:56, row 1:64
260 // if CBD instance exists, the value is taken from CDB.
261 // Otherwise it is an ideal one
264 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
266 return 0.0; // default EMC ADC pedestal
269 //________________________________________________________________
270 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
272 // Set EMC pedestal for (module,column,row)
275 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
277 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
280 //________________________________________________________________
281 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
283 // Return EMC calibration coefficient
284 // for channel defined by (module,column,row)
285 // module, column,raw should follow the internal PHOS convention:
286 // module 1:5, column 1:56, row 1:64
287 // if CBD instance exists, the value is taken from CDB.
288 // Otherwise it is an ideal one
291 return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
293 return 1.0; // default width of one EMC ADC channel in GeV
296 //________________________________________________________________
297 void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
299 // Set EMC calibration coefficient for (module,column,row)
302 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
304 fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
307 //________________________________________________________________
308 Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
310 // Return EMC calibration coefficient
311 // for channel defined by (module,column,row)
312 // module, column,raw should follow the internal PHOS convention:
313 // module 1:5, column 1:56, row 1:64
314 // if CBD instance exists, the value is taken from CDB.
315 // Otherwise it is an ideal one
318 return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
320 return 1.0; // default width of one EMC ADC channel in GeV
323 //________________________________________________________________
324 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
326 // Set EMC calibration coefficient for (module,column,row)
329 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
331 fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
333 //________________________________________________________________
334 Float_t AliPHOSCalibData::GetSampleTimeStep() const
336 //Get conversion coeff. from sample time step to seconds.
337 //Negative value means that it is not used in reconstruction
338 //but only in simulation of raw.
340 return fCalibDataEmc->GetSampleTimeStep();
342 return 0.0; // default width of one EMC ADC channel in GeV
344 //________________________________________________________________
345 void AliPHOSCalibData::SetSampleTimeStep(Float_t step)
347 //Set conversion coeff. from sample time step to seconds.
348 //Negative value means that it is not used in reconstruction
349 //but only in simulation of raw.
351 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
353 fCalibDataEmc->SetSampleTimeStep(step) ;
355 //________________________________________________________________
356 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
358 // Return ALTRO pedestal coefficient
359 // for channel defined by (module,column,row)
360 // module, column,raw should follow the internal PHOS convention:
361 // module 1:5, column 1:56, row 1:64
362 // if CBD instance exists, the value is taken from CDB.
363 // Otherwise it is an ideal one
366 return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
368 return 0; // default width of one EMC ADC channel in GeV
371 //________________________________________________________________
372 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
374 // Set altro offset for (module,column,row)
377 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
379 fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
383 //________________________________________________________________
384 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
386 // Return CPV calibration coefficient
387 // for channel defined by (module,column,row)
388 // module, column,raw should follow the internal CPV convention:
389 // module 1:5, column 1:56, row 1:128
390 // if CBD instance exists, the value is taken from CDB.
391 // Otherwise it is an ideal one
394 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
396 return 0.0012; // default width of one ADC channel in CPV arbitrary units
399 //________________________________________________________________
400 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
402 // Return CPV pedestal
403 // for channel defined by (module,column,row)
404 // module, column,raw should follow the internal CPV convention:
405 // module 1:5, column 1:56, row 1:128
406 // if CBD instance exists, the value is taken from CDB.
407 // Otherwise it is an ideal one
410 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
412 return 0.012; // default CPV ADC pedestal
415 //________________________________________________________________
416 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
418 // Set CPV calibration coefficient for (module,column,row)
421 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
423 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
426 //________________________________________________________________
427 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
429 // Set CPV pedestal for (module,column,row)
432 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
434 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
437 //________________________________________________________________
438 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
440 // Create decalibrated EMC with calibration coefficients and pedestals
441 // randomly distributed within hard-coded limits
442 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
444 if(fCalibDataEmc) delete fCalibDataEmc;
445 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
448 rn.SetSeed(0); //the seed is set to the current machine clock
450 Float_t adcChannelEmc,adcPedestalEmc;
452 for(Int_t module=1; module<6; module++) {
453 for(Int_t column=1; column<57; column++) {
454 for(Int_t row=1; row<65; row++) {
455 adcChannelEmc =rn.Uniform(ccMin,ccMax);
456 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
457 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
458 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
465 //________________________________________________________________
466 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
468 // Create decalibrated CPV with calibration coefficients and pedestals
469 // randomly distributed within hard-coded limits
470 // Default spread of calibration parameters is 0.0012 +- 25%
472 if(fCalibDataCpv) delete fCalibDataCpv;
473 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
476 rn.SetSeed(0); //the seed is set to the current machine clock
478 Float_t adcChannelCpv,adcPedestalCpv;
480 for(Int_t module=1; module<6; module++) {
481 for(Int_t column=1; column<57; column++) {
482 for(Int_t row=1; row<129; row++) {
483 adcChannelCpv =rn.Uniform(ccMin,ccMax);
484 adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
485 fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
486 fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
491 //________________________________________________________________
492 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
494 //If no bad channels map found, channel considered good
496 if(fEmcBadChannelsMap)
497 return fEmcBadChannelsMap->IsBadChannel(module,col,row);
502 //________________________________________________________________
503 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
505 if(fEmcBadChannelsMap)
506 return fEmcBadChannelsMap->GetNumOfBadChannels();
510 //________________________________________________________________
511 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
513 //Fill array badIds by the Ids of EMC bad channels.
514 //Array badIds of length GetNumOfBadChannels() should be prepared in advance.
516 if(fEmcBadChannelsMap)
517 fEmcBadChannelsMap->BadChannelIds(badIds);
520 //________________________________________________________________
521 Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
523 // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row).
524 // Used in simulation.
526 // module, column,raw should follow the internal PHOS convention:
527 // module 1:5, column 1:56, row 1:64
528 // if CBD instance exists, the value is taken from CDB.
529 // Otherwise it is an ideal one (no decalibration).
532 return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
534 return 1.0; // no decalibration by default
537 //________________________________________________________________
538 void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
540 // Set EMC (de)calibration factor for (module,column,row).
541 // Used in simulation.
544 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
546 fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);