]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibData.cxx
Changes to compile with Root6 on macosx64
[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 0.0; // by default no offset
321 }
322 //________________________________________________________________
323 Float_t AliPHOSCalibData::GetLGTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
324
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  
331   
332   if(fCalibDataEmc)
333     return fCalibDataEmc->GetLGTimeShiftEmc(module,column,row);
334   else
335     return 0.0; // no offset by default
336 }
337  
338 //________________________________________________________________
339 void AliPHOSCalibData::SetLGTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
340 {
341   // Set EMC calibration coefficient for (module,column,row)
342  
343   if(!fCalibDataEmc)
344     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
345  
346   fCalibDataEmc->SetLGTimeShiftEmc(module,column,row,value);
347 }
348 //________________________________________________________________
349 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
350 {
351   // Set EMC calibration coefficient for (module,column,row)
352  
353   if(!fCalibDataEmc)
354     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
355  
356   fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
357 }
358 //________________________________________________________________
359 Float_t AliPHOSCalibData::GetSampleTimeStep() const 
360 {
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.
364   if(fCalibDataEmc)
365     return fCalibDataEmc->GetSampleTimeStep();
366   else
367     return 0.0; // default width of one EMC ADC channel in GeV
368 }
369 //________________________________________________________________
370 void   AliPHOSCalibData::SetSampleTimeStep(Float_t step)
371 {
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.
375   if(!fCalibDataEmc)
376     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
377
378   fCalibDataEmc->SetSampleTimeStep(step) ;
379 }
380 //________________________________________________________________
381 Int_t AliPHOSCalibData::GetAltroOffsetEmc(Int_t module, Int_t column, Int_t row) const
382 {
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
389  
390   if(fCalibDataEmc)
391     return fCalibDataEmc->GetAltroOffsetEmc(module,column,row);
392   else
393     return 0; // default width of one EMC ADC channel in GeV
394 }
395  
396 //________________________________________________________________
397 void AliPHOSCalibData::SetAltroOffsetEmc(Int_t module, Int_t column, Int_t row, Int_t value)
398 {
399   // Set altro offset for (module,column,row)
400  
401   if(!fCalibDataEmc)
402     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
403  
404   fCalibDataEmc->SetAltroOffsetEmc(module,column,row,value);
405 }
406
407  
408 //________________________________________________________________
409 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
410 {
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
417
418   if(fCalibDataCpv) 
419     return fCalibDataCpv->GetADCchannelCpv(module,column,row);
420   else
421     return 0.0012; // default width of one ADC channel in CPV arbitrary units
422 }
423
424 //________________________________________________________________
425 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
426 {
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
433
434   if(fCalibDataCpv) 
435     return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
436   else
437     return 0.012; // default CPV ADC pedestal
438 }
439
440 //________________________________________________________________
441 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
442 {
443   // Set CPV calibration coefficient for (module,column,row)
444
445   if(!fCalibDataCpv)
446     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
447
448   fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
449 }
450
451 //________________________________________________________________
452 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
453 {
454   // Set CPV pedestal for (module,column,row)
455
456   if(!fCalibDataCpv)
457     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
458
459   fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
460 }
461
462 //________________________________________________________________
463 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
464 {
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
468
469   if(fCalibDataEmc) delete fCalibDataEmc;
470   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
471
472   TRandom rn;
473   rn.SetSeed(0); //the seed is set to the current  machine clock
474   
475   Float_t adcChannelEmc,adcPedestalEmc;
476
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);
484       }
485     }
486   }
487
488 }
489
490 //________________________________________________________________
491 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
492 {
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%
496
497   if(fCalibDataCpv) delete fCalibDataCpv;
498   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
499
500   TRandom rn;
501   rn.SetSeed(0); //the seed is set to the current  machine clock
502   
503   Float_t adcChannelCpv,adcPedestalCpv;
504
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);
512       }
513     }
514   }
515 }
516 //________________________________________________________________
517 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
518 {
519   //If no bad channels map found, channel considered good
520
521   if(fEmcBadChannelsMap) 
522     return fEmcBadChannelsMap->IsBadChannel(module,col,row);
523   else
524     return kFALSE;
525 }
526
527 //________________________________________________________________
528 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
529 {
530   if(fEmcBadChannelsMap)
531     return fEmcBadChannelsMap->GetNumOfBadChannels();
532   else
533     return 0;
534 }
535 //________________________________________________________________
536 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
537 {
538   //Fill array badIds by the Ids of EMC bad channels.
539   //Array badIds of length GetNumOfBadChannels() should be prepared in advance. 
540
541   if(fEmcBadChannelsMap)              
542     fEmcBadChannelsMap->BadChannelIds(badIds);
543 }
544
545 //________________________________________________________________
546 Float_t AliPHOSCalibData::GetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row) const
547 {
548   // Return random EMC (de)calibration factor O(1) for channel defined by (module,column,row). 
549   // Used in simulation.
550   
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).
555   
556   if(fCalibDataEmc) 
557     return fCalibDataEmc->GetADCchannelEmcDecalib(module,column,row);
558   else
559     return 1.0; // no decalibration by default
560 }
561
562 //________________________________________________________________
563 void AliPHOSCalibData::SetADCchannelEmcDecalib(Int_t module, Int_t column, Int_t row, Float_t value)
564 {
565   // Set EMC (de)calibration factor for (module,column,row).
566   // Used in simulation.
567   
568   if(!fCalibDataEmc)
569     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
570   
571   fCalibDataEmc->SetADCchannelEmcDecalib(module,column,row,value);
572 }