]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibData.cxx
coverity fix
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibData.cxx
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
24 #include "TRandom.h"
25 #include "AliLog.h"
26 #include "AliPHOSCalibData.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #include "AliCDBId.h"
30 #include "AliCDBEntry.h"
31 #include "AliPHOSEmcCalibData.h"
32 #include "AliPHOSCpvCalibData.h"
33 #include "AliPHOSEmcBadChannelsMap.h"
34 #include "AliCDBMetaData.h"
35
36 ClassImp(AliPHOSCalibData)
37
38 //________________________________________________________________
39   AliPHOSCalibData::AliPHOSCalibData(): 
40     TNamed(), 
41     fCalibDataEmc(0x0), 
42     fCalibDataCpv(0x0),
43     fEmcBadChannelsMap(0x0),
44     fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
45     fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
46     fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
47 {
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
51  
52 }
53
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")
61 {
62   // Constructor
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
66   AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
67   if(entryEmc)
68     fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
69
70   if(!fCalibDataEmc)
71     AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction!\n");
72   
73   AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
74   if(entryCpv)
75     fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
76
77   if(!fCalibDataCpv)
78     AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction!\n");
79   
80   AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->
81     Get(fEmcBadChannelsMapPath.Data(),runNumber);
82   if(entryEmcBadMap)
83     fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject(); 
84
85 }
86
87 //________________________________________________________________
88 AliPHOSCalibData::AliPHOSCalibData(AliPHOSCalibData & phosCDB) :
89   TNamed(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)
96 {
97   // Copy constructor
98 }
99 //________________________________________________________________
100 AliPHOSCalibData::~AliPHOSCalibData()
101 {
102   // Destructor
103  
104 }
105
106 AliPHOSCalibData & 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;
114   fEmcBadChannelsMap = rhs.fEmcBadChannelsMap;
115   fEmcDataPath  = rhs.fEmcDataPath;
116   fCpvDataPath  = rhs.fCpvDataPath;
117   fEmcBadChannelsMapPath = rhs.fEmcBadChannelsMapPath;
118   
119   return *this;
120 }
121
122 //________________________________________________________________
123 void AliPHOSCalibData::Reset()
124 {
125   // Set all pedestals to 0 and all ADC channels to 1,
126   // and all channels are good (alive)
127
128   fCalibDataEmc     ->Reset();
129   fCalibDataCpv     ->Reset();
130   fEmcBadChannelsMap->Reset();
131 }
132
133 //________________________________________________________________
134 void  AliPHOSCalibData::Print(Option_t *option) const
135 {
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);
141 }
142
143 //________________________________________________________________
144 void AliPHOSCalibData::CreateNew()
145 {
146   // Create new EMC and CPV calibration containers with ideal coefficients
147
148   if(fCalibDataEmc) delete fCalibDataEmc;
149   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
150
151   if(fCalibDataCpv) delete fCalibDataCpv;
152   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
153
154   if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
155   fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
156
157 }
158
159 //________________________________________________________________
160 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
161 {
162   // Write EMC calibration container to CDB
163
164   if(!fCalibDataEmc) return kFALSE;
165
166   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
167   if(!storage)
168     storage = AliCDBManager::Instance()->GetDefaultStorage();
169
170   if(storage) { 
171     AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
172     storage->Put(fCalibDataEmc,id, md);
173     return kTRUE;
174   }
175   else
176     return kFALSE;
177
178 }
179
180 //________________________________________________________________
181 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
182 {
183   // Write CPV calibration container to CDB
184
185   if(!fCalibDataCpv) return kFALSE;
186   
187   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
188   if(!storage)
189     storage = AliCDBManager::Instance()->GetDefaultStorage();
190
191   if(storage) { 
192     AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
193     storage->Put(fCalibDataCpv,id, md);
194     return kTRUE;
195   }
196   else
197     return kFALSE;
198
199 }
200
201
202 //________________________________________________________________
203 Bool_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
222 //________________________________________________________________
223 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
224 {
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
231
232   if(fCalibDataEmc) 
233     return fCalibDataEmc->GetADCchannelEmc(module,column,row);
234   else
235     return 1.0; // default width of one EMC ADC channel in GeV
236 }
237
238 //________________________________________________________________
239 void 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 //________________________________________________________________
250 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
251 {
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
258   if(fCalibDataEmc) 
259     return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
260   else
261     return 0.0; // default EMC ADC pedestal
262 }
263
264 //________________________________________________________________
265 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
266 {
267   // Set EMC pedestal for (module,column,row)
268
269   if(!fCalibDataEmc)
270     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
271
272   fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
273 }
274
275 //________________________________________________________________
276 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
277 {
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 //________________________________________________________________
292 void 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  
296   if(!fCalibDataEmc)
297     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
298  
299   fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
300 }
301  
302 //________________________________________________________________
303 Float_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 //________________________________________________________________
319 void 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 }
328 //________________________________________________________________
329 Float_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 //________________________________________________________________
340 void   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 //________________________________________________________________
351 Int_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 //________________________________________________________________
367 void 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
377  
378 //________________________________________________________________
379 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
380 {
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
387
388   if(fCalibDataCpv) 
389     return fCalibDataCpv->GetADCchannelCpv(module,column,row);
390   else
391     return 0.0012; // default width of one ADC channel in CPV arbitrary units
392 }
393
394 //________________________________________________________________
395 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
396 {
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
404   if(fCalibDataCpv) 
405     return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
406   else
407     return 0.012; // default CPV ADC pedestal
408 }
409
410 //________________________________________________________________
411 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
412 {
413   // Set CPV calibration coefficient for (module,column,row)
414
415   if(!fCalibDataCpv)
416     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
417
418   fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
419 }
420
421 //________________________________________________________________
422 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
423 {
424   // Set CPV pedestal for (module,column,row)
425
426   if(!fCalibDataCpv)
427     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
428
429   fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
430 }
431
432 //________________________________________________________________
433 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
434 {
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
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   
445   Float_t adcChannelEmc,adcPedestalEmc;
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++) {
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);
454       }
455     }
456   }
457
458 }
459
460 //________________________________________________________________
461 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
462 {
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%
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   
473   Float_t adcChannelCpv,adcPedestalCpv;
474
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);
482       }
483     }
484   }
485 }
486 //________________________________________________________________
487 Bool_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 //________________________________________________________________
498 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
499 {
500   if(fEmcBadChannelsMap)
501     return fEmcBadChannelsMap->GetNumOfBadChannels();
502   else
503     return 0;
504 }
505 //________________________________________________________________
506 void 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 }
514
515 //________________________________________________________________
516 Float_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 //________________________________________________________________
533 void 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 }