]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibData.cxx
Fix: Changed version of AliPHOSTriggerParameters to 1.
[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 //________________________________________________________________
107 AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
108 {
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);
113   if (this != &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;
120   }
121   else {
122     AliFatal("Self assignment!");
123   }
124   return *this;
125 }
126
127 //________________________________________________________________
128 void AliPHOSCalibData::Reset()
129 {
130   // Set all pedestals to 0 and all ADC channels to 1,
131   // and all channels are good (alive)
132
133   fCalibDataEmc     ->Reset();
134   fCalibDataCpv     ->Reset();
135   fEmcBadChannelsMap->Reset();
136 }
137
138 //________________________________________________________________
139 void  AliPHOSCalibData::Print(Option_t *option) const
140 {
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);
146 }
147
148 //________________________________________________________________
149 void AliPHOSCalibData::CreateNew()
150 {
151   // Create new EMC and CPV calibration containers with ideal coefficients
152
153   if(fCalibDataEmc) delete fCalibDataEmc;
154   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
155
156   if(fCalibDataCpv) delete fCalibDataCpv;
157   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
158
159   if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
160   fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
161
162 }
163
164 //________________________________________________________________
165 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
166 {
167   // Write EMC calibration container to CDB
168
169   if(!fCalibDataEmc) return kFALSE;
170
171   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
172   if(!storage)
173     storage = AliCDBManager::Instance()->GetDefaultStorage();
174
175   if(storage) { 
176     AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
177     storage->Put(fCalibDataEmc,id, md);
178     return kTRUE;
179   }
180   else
181     return kFALSE;
182
183 }
184
185 //________________________________________________________________
186 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
187 {
188   // Write CPV calibration container to CDB
189
190   if(!fCalibDataCpv) return kFALSE;
191   
192   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
193   if(!storage)
194     storage = AliCDBManager::Instance()->GetDefaultStorage();
195
196   if(storage) { 
197     AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
198     storage->Put(fCalibDataCpv,id, md);
199     return kTRUE;
200   }
201   else
202     return kFALSE;
203
204 }
205
206
207 //________________________________________________________________
208 Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
209 {
210   //Write EMC bad channels map into CDB.
211
212   if(!fEmcBadChannelsMap) return kFALSE;
213   
214   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
215   if(!storage)
216     storage = AliCDBManager::Instance()->GetDefaultStorage();
217
218   if(storage) { 
219     AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
220     storage->Put(fEmcBadChannelsMap,id, md);
221     return kTRUE;
222   }
223   else
224     return kFALSE;
225 }
226
227 //________________________________________________________________
228 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
229 {
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
236
237   if(fCalibDataEmc) 
238     return fCalibDataEmc->GetADCchannelEmc(module,column,row);
239   else
240     return 1.0; // default width of one EMC ADC channel in GeV
241 }
242
243 //________________________________________________________________
244 void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
245 {
246   // Set EMC calibration coefficient for (module,column,row)
247
248   if(!fCalibDataEmc)
249     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
250
251   fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
252 }
253
254 //________________________________________________________________
255 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
256 {
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
262
263   if(fCalibDataEmc) 
264     return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
265   else
266     return 0.0; // default EMC ADC pedestal
267 }
268
269 //________________________________________________________________
270 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
271 {
272   // Set EMC pedestal for (module,column,row)
273
274   if(!fCalibDataEmc)
275     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
276
277   fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
278 }
279
280 //________________________________________________________________
281 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
282 {
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
289  
290   if(fCalibDataEmc)
291     return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
292   else
293     return 1.0; // default width of one EMC ADC channel in GeV
294 }
295  
296 //________________________________________________________________
297 void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
298 {
299   // Set EMC calibration coefficient for (module,column,row)
300  
301   if(!fCalibDataEmc)
302     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
303  
304   fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
305 }
306  
307 //________________________________________________________________
308 Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
309
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  
316   
317   if(fCalibDataEmc)
318     return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
319   else
320     return 1.0; // default width of one EMC ADC channel in GeV
321 }
322  
323 //________________________________________________________________
324 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
325 {
326   // Set EMC calibration coefficient for (module,column,row)
327  
328   if(!fCalibDataEmc)
329     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
330  
331   fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
332 }
333 //________________________________________________________________
334 Float_t AliPHOSCalibData::GetSampleTimeStep() const 
335 {
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.
339   if(fCalibDataEmc)
340     return fCalibDataEmc->GetSampleTimeStep();
341   else
342     return 0.0; // default width of one EMC ADC channel in GeV
343 }
344 //________________________________________________________________
345 void   AliPHOSCalibData::SetSampleTimeStep(Float_t step)
346 {
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.
350   if(!fCalibDataEmc)
351     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
352
353   fCalibDataEmc->SetSampleTimeStep(step) ;
354 }
355 //________________________________________________________________
356 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
357 {
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
364  
365   if(fCalibDataEmc)
366     return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
367   else
368     return 0; // default width of one EMC ADC channel in GeV
369 }
370  
371 //________________________________________________________________
372 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
373 {
374   // Set altro offset for (module,column,row)
375  
376   if(!fCalibDataEmc)
377     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
378  
379   fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
380 }
381
382  
383 //________________________________________________________________
384 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
385 {
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
392
393   if(fCalibDataCpv) 
394     return fCalibDataCpv->GetADCchannelCpv(module,column,row);
395   else
396     return 0.0012; // default width of one ADC channel in CPV arbitrary units
397 }
398
399 //________________________________________________________________
400 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
401 {
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
408
409   if(fCalibDataCpv) 
410     return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
411   else
412     return 0.012; // default CPV ADC pedestal
413 }
414
415 //________________________________________________________________
416 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
417 {
418   // Set CPV calibration coefficient for (module,column,row)
419
420   if(!fCalibDataCpv)
421     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
422
423   fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
424 }
425
426 //________________________________________________________________
427 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
428 {
429   // Set CPV pedestal for (module,column,row)
430
431   if(!fCalibDataCpv)
432     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
433
434   fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
435 }
436
437 //________________________________________________________________
438 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
439 {
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
443
444   if(fCalibDataEmc) delete fCalibDataEmc;
445   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
446
447   TRandom rn;
448   rn.SetSeed(0); //the seed is set to the current  machine clock
449   
450   Float_t adcChannelEmc,adcPedestalEmc;
451
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);
459       }
460     }
461   }
462
463 }
464
465 //________________________________________________________________
466 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
467 {
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%
471
472   if(fCalibDataCpv) delete fCalibDataCpv;
473   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
474
475   TRandom rn;
476   rn.SetSeed(0); //the seed is set to the current  machine clock
477   
478   Float_t adcChannelCpv,adcPedestalCpv;
479
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);
487       }
488     }
489   }
490 }
491 //________________________________________________________________
492 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
493 {
494   //If no bad channels map found, channel considered good
495
496   if(fEmcBadChannelsMap) 
497     return fEmcBadChannelsMap->IsBadChannel(module,col,row);
498   else
499     return kFALSE;
500 }
501
502 //________________________________________________________________
503 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
504 {
505   if(fEmcBadChannelsMap)
506     return fEmcBadChannelsMap->GetNumOfBadChannels();
507   else
508     return 0;
509 }
510 //________________________________________________________________
511 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
512 {
513   //Fill array badIds by the Ids of EMC bad channels.
514   //Array badIds of length GetNumOfBadChannels() should be prepared in advance. 
515
516   if(fEmcBadChannelsMap)              
517     fEmcBadChannelsMap->BadChannelIds(badIds);
518 }
519
520 //________________________________________________________________
521 Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
522 {
523   // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row). 
524   // Used in simulation.
525   
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).
530   
531   if(fCalibDataEmc) 
532     return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
533   else
534     return 1.0; // no decalibration by default
535 }
536
537 //________________________________________________________________
538 void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
539 {
540   // Set EMC (de)calibration factor for (module,column,row).
541   // Used in simulation.
542   
543   if(!fCalibDataEmc)
544     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
545   
546   fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);
547 }