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 0.0; // by default no offset
322 //________________________________________________________________
323 Float_t AliPHOSCalibData::GetLGTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
325 // Return EMC calibration coefficient
326 // for channel defined by (module,column,row)
327 // module, column,raw should follow the internal PHOS convention:
328 // module 1:5, column 1:56, row 1:64
329 // if CBD instance exists, the value is taken from CDB.
330 // Otherwise it is an ideal one
333 return fCalibDataEmc->GetLGTimeShiftEmc(module,column,row);
335 return 0.0; // no offset by default
338 //________________________________________________________________
339 void AliPHOSCalibData::SetLGTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
341 // Set EMC calibration coefficient for (module,column,row)
344 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
346 fCalibDataEmc->SetLGTimeShiftEmc(module,column,row,value);
348 //________________________________________________________________
349 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
351 // Set EMC calibration coefficient for (module,column,row)
354 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
356 fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
358 //________________________________________________________________
359 Float_t AliPHOSCalibData::GetSampleTimeStep() const
361 //Get conversion coeff. from sample time step to seconds.
362 //Negative value means that it is not used in reconstruction
363 //but only in simulation of raw.
365 return fCalibDataEmc->GetSampleTimeStep();
367 return 0.0; // default width of one EMC ADC channel in GeV
369 //________________________________________________________________
370 void AliPHOSCalibData::SetSampleTimeStep(Float_t step)
372 //Set conversion coeff. from sample time step to seconds.
373 //Negative value means that it is not used in reconstruction
374 //but only in simulation of raw.
376 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
378 fCalibDataEmc->SetSampleTimeStep(step) ;
380 //________________________________________________________________
381 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
383 // Return ALTRO pedestal coefficient
384 // for channel defined by (module,column,row)
385 // module, column,raw should follow the internal PHOS convention:
386 // module 1:5, column 1:56, row 1:64
387 // if CBD instance exists, the value is taken from CDB.
388 // Otherwise it is an ideal one
391 return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
393 return 0; // default width of one EMC ADC channel in GeV
396 //________________________________________________________________
397 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
399 // Set altro offset for (module,column,row)
402 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
404 fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
408 //________________________________________________________________
409 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
411 // Return CPV calibration coefficient
412 // for channel defined by (module,column,row)
413 // module, column,raw should follow the internal CPV convention:
414 // module 1:5, column 1:56, row 1:128
415 // if CBD instance exists, the value is taken from CDB.
416 // Otherwise it is an ideal one
419 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
421 return 0.0012; // default width of one ADC channel in CPV arbitrary units
424 //________________________________________________________________
425 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
427 // Return CPV pedestal
428 // for channel defined by (module,column,row)
429 // module, column,raw should follow the internal CPV convention:
430 // module 1:5, column 1:56, row 1:128
431 // if CBD instance exists, the value is taken from CDB.
432 // Otherwise it is an ideal one
435 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
437 return 0.012; // default CPV ADC pedestal
440 //________________________________________________________________
441 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
443 // Set CPV calibration coefficient for (module,column,row)
446 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
448 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
451 //________________________________________________________________
452 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
454 // Set CPV pedestal for (module,column,row)
457 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
459 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
462 //________________________________________________________________
463 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
465 // Create decalibrated EMC with calibration coefficients and pedestals
466 // randomly distributed within hard-coded limits
467 // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
469 if(fCalibDataEmc) delete fCalibDataEmc;
470 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
473 rn.SetSeed(0); //the seed is set to the current machine clock
475 Float_t adcChannelEmc,adcPedestalEmc;
477 for(Int_t module=1; module<6; module++) {
478 for(Int_t column=1; column<57; column++) {
479 for(Int_t row=1; row<65; row++) {
480 adcChannelEmc =rn.Uniform(ccMin,ccMax);
481 adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
482 fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
483 fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
490 //________________________________________________________________
491 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
493 // Create decalibrated CPV with calibration coefficients and pedestals
494 // randomly distributed within hard-coded limits
495 // Default spread of calibration parameters is 0.0012 +- 25%
497 if(fCalibDataCpv) delete fCalibDataCpv;
498 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
501 rn.SetSeed(0); //the seed is set to the current machine clock
503 Float_t adcChannelCpv,adcPedestalCpv;
505 for(Int_t module=1; module<6; module++) {
506 for(Int_t column=1; column<57; column++) {
507 for(Int_t row=1; row<129; row++) {
508 adcChannelCpv =rn.Uniform(ccMin,ccMax);
509 adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
510 fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
511 fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
516 //________________________________________________________________
517 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
519 //If no bad channels map found, channel considered good
521 if(fEmcBadChannelsMap)
522 return fEmcBadChannelsMap->IsBadChannel(module,col,row);
527 //________________________________________________________________
528 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
530 if(fEmcBadChannelsMap)
531 return fEmcBadChannelsMap->GetNumOfBadChannels();
535 //________________________________________________________________
536 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
538 //Fill array badIds by the Ids of EMC bad channels.
539 //Array badIds of length GetNumOfBadChannels() should be prepared in advance.
541 if(fEmcBadChannelsMap)
542 fEmcBadChannelsMap->BadChannelIds(badIds);
545 //________________________________________________________________
546 Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
548 // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row).
549 // Used in simulation.
551 // module, column,raw should follow the internal PHOS convention:
552 // module 1:5, column 1:56, row 1:64
553 // if CBD instance exists, the value is taken from CDB.
554 // Otherwise it is an ideal one (no decalibration).
557 return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
559 return 1.0; // no decalibration by default
562 //________________________________________________________________
563 void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
565 // Set EMC (de)calibration factor for (module,column,row).
566 // Used in simulation.
569 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
571 fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);