]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSCalibData.cxx
ACORDEv1 is now the default
[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    AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data());
53   if(entryEmc)
54     fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
55
56   if(!fCalibDataEmc)
57     AliWarning("Calibration parameters for PHOS EMC not found. Create a new set.\n");
58     
59   AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data());
60   if(entryCpv)
61     fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
62
63   if(!fCalibDataCpv)
64     AliWarning("Calibration parameters for PHOS CPV not found. Create a new set.\n");
65
66   AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->Get(fEmcBadChannelsMapPath.Data());
67   if(entryEmcBadMap)
68     fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject(); 
69
70 }
71
72 //________________________________________________________________
73 AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
74   TNamed("phosCalib","PHOS Calibration Data Manager"),
75   fCalibDataEmc(0x0), fCalibDataCpv(0x0), fEmcBadChannelsMap(0x0),
76   fEmcDataPath("PHOS/Calib/EmcGainPedestals"),
77   fCpvDataPath("PHOS/Calib/CpvGainPedestals"),
78   fEmcBadChannelsMapPath("PHOS/Calib/EmcBadChannels")
79 {
80   // Constructor
81   // Open CDB entry, get EMC and CPV calibration data and bad channel map.
82   // If EMC or CPV calibration data does not exist, stop the run
83
84   AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
85   if(entryEmc)
86     fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
87
88   if(!fCalibDataEmc)
89     AliFatal("Calibration parameters for PHOS EMC not found. Stop reconstruction!\n");
90   
91   AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
92   if(entryCpv)
93     fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
94
95   if(!fCalibDataCpv)
96     AliFatal("Calibration parameters for PHOS CPV not found. Stop reconstruction!\n");
97   
98   AliCDBEntry* entryEmcBadMap = AliCDBManager::Instance()->
99     Get(fEmcBadChannelsMapPath.Data(),runNumber);
100   if(entryEmcBadMap)
101     fEmcBadChannelsMap = (AliPHOSEmcBadChannelsMap*)entryEmcBadMap->GetObject(); 
102
103 }
104
105 //________________________________________________________________
106 AliPHOSCalibData::AliPHOSCalibData(AliPHOSCalibData & phosCDB) :
107   TNamed(phosCDB),
108   fCalibDataEmc(phosCDB.fCalibDataEmc),
109   fCalibDataCpv(phosCDB.fCalibDataCpv),
110   fEmcBadChannelsMap(phosCDB.fEmcBadChannelsMap),
111   fEmcDataPath(phosCDB.fEmcDataPath),
112   fCpvDataPath(phosCDB.fCpvDataPath),
113   fEmcBadChannelsMapPath(phosCDB.fEmcBadChannelsMapPath)
114 {
115   // Copy constructor
116 }
117 //________________________________________________________________
118 AliPHOSCalibData::~AliPHOSCalibData()
119 {
120   // Destructor
121  
122 }
123
124 AliPHOSCalibData & AliPHOSCalibData::operator = (const AliPHOSCalibData & rhs)
125 {
126   //Copy-assignment. Does not delete anything (see destructor)
127   //compiler generated is ok, but ... because -Weffc++ and pointer
128   //members we have to define it explicitly.
129   TNamed::operator=(rhs);
130   fCalibDataEmc = rhs.fCalibDataEmc;
131   fCalibDataCpv = rhs.fCalibDataCpv;
132   fEmcBadChannelsMap = rhs.fEmcBadChannelsMap;
133   fEmcDataPath  = rhs.fEmcDataPath;
134   fCpvDataPath  = rhs.fCpvDataPath;
135   fEmcBadChannelsMapPath = rhs.fEmcBadChannelsMapPath;
136   
137   return *this;
138 }
139
140 //________________________________________________________________
141 void AliPHOSCalibData::Reset()
142 {
143   // Set all pedestals to 0 and all ADC channels to 1,
144   // and all channels are good (alive)
145
146   fCalibDataEmc     ->Reset();
147   fCalibDataCpv     ->Reset();
148   fEmcBadChannelsMap->Reset();
149 }
150
151 //________________________________________________________________
152 void  AliPHOSCalibData::Print(Option_t *option) const
153 {
154   // Print EMC and CPV calibration containers
155   // Input: option="ped"  to print pedestals
156   //        option="gain" to print calibration coefficients
157   if (fCalibDataEmc) fCalibDataEmc->Print(option);
158   if (fCalibDataCpv) fCalibDataCpv->Print(option);
159 }
160
161 //________________________________________________________________
162 void AliPHOSCalibData::CreateNew()
163 {
164   // Create new EMC and CPV calibration containers with ideal coefficients
165
166   if(fCalibDataEmc) delete fCalibDataEmc;
167   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
168
169   if(fCalibDataCpv) delete fCalibDataCpv;
170   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
171
172   if(fEmcBadChannelsMap) delete fEmcBadChannelsMap;
173   fEmcBadChannelsMap = new AliPHOSEmcBadChannelsMap();
174
175 }
176
177 //________________________________________________________________
178 Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
179 {
180   // Write EMC calibration container to CDB
181
182   if(!fCalibDataEmc) return kFALSE;
183
184   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
185   if(!storage)
186     storage = AliCDBManager::Instance()->GetDefaultStorage();
187
188   if(storage) { 
189     AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
190     storage->Put(fCalibDataEmc,id, md);
191     return kTRUE;
192   }
193   else
194     return kFALSE;
195
196 }
197
198 //________________________________________________________________
199 Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
200 {
201   // Write CPV calibration container to CDB
202
203   if(!fCalibDataCpv) return kFALSE;
204   
205   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
206   if(!storage)
207     storage = AliCDBManager::Instance()->GetDefaultStorage();
208
209   if(storage) { 
210     AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
211     storage->Put(fCalibDataCpv,id, md);
212     return kTRUE;
213   }
214   else
215     return kFALSE;
216
217 }
218
219
220 //________________________________________________________________
221 Bool_t AliPHOSCalibData::WriteEmcBadChannelsMap(Int_t firstRun,Int_t lastRun,AliCDBMetaData *md)
222 {
223   //Write EMC bad channels map into CDB.
224
225   if(!fEmcBadChannelsMap) return kFALSE;
226   
227   AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS/*");
228   if(!storage)
229     storage = AliCDBManager::Instance()->GetDefaultStorage();
230
231   if(storage) { 
232     AliCDBId id(fEmcBadChannelsMapPath.Data(),firstRun,lastRun);
233     storage->Put(fEmcBadChannelsMap,id, md);
234     return kTRUE;
235   }
236   else
237     return kFALSE;
238 }
239
240 //________________________________________________________________
241 Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
242 {
243   // Return EMC calibration coefficient
244   // for channel defined by (module,column,row)
245   // module, column,raw should follow the internal PHOS convention:
246   // module 1:5, column 1:56, row 1:64
247   // if CBD instance exists, the value is taken from CDB.
248   // Otherwise it is an ideal one
249
250   if(fCalibDataEmc) 
251     return fCalibDataEmc->GetADCchannelEmc(module,column,row);
252   else
253     return 1.0; // default width of one EMC ADC channel in GeV
254 }
255
256 //________________________________________________________________
257 void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
258 {
259   // Set EMC calibration coefficient for (module,column,row)
260
261   if(!fCalibDataEmc)
262     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
263
264   fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
265 }
266
267 //________________________________________________________________
268 Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
269 {
270   // Return EMC pedestal for channel defined by (module,column,row)
271   // module, column,raw should follow the internal PHOS convention:
272   // module 1:5, column 1:56, row 1:64
273   // if CBD instance exists, the value is taken from CDB.
274   // Otherwise it is an ideal one
275
276   if(fCalibDataEmc) 
277     return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
278   else
279     return 0.0; // default EMC ADC pedestal
280 }
281
282 //________________________________________________________________
283 void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
284 {
285   // Set EMC pedestal for (module,column,row)
286
287   if(!fCalibDataEmc)
288     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
289
290   fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
291 }
292
293 //________________________________________________________________
294 Float_t AliPHOSCalibData::GetHighLowRatioEmc(Int_t module, Int_t column, Int_t row) const
295 {
296   // Return EMC calibration coefficient
297   // for channel defined by (module,column,row)
298   // module, column,raw should follow the internal PHOS convention:
299   // module 1:5, column 1:56, row 1:64
300   // if CBD instance exists, the value is taken from CDB.
301   // Otherwise it is an ideal one
302  
303   if(fCalibDataEmc)
304     return fCalibDataEmc->GetHighLowRatioEmc(module,column,row);
305   else
306     return 1.0; // default width of one EMC ADC channel in GeV
307 }
308  
309 //________________________________________________________________
310 void AliPHOSCalibData::SetHighLowRatioEmc(Int_t module, Int_t column, Int_t row, Float_t value)
311 {
312   // Set EMC calibration coefficient for (module,column,row)
313  
314   if(!fCalibDataEmc)
315     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
316  
317   fCalibDataEmc->SetHighLowRatioEmc(module,column,row,value);
318 }
319  
320 //________________________________________________________________
321 Float_t AliPHOSCalibData::GetTimeShiftEmc(Int_t module, Int_t column, Int_t row) const
322
323   // Return EMC calibration coefficient 
324   // for channel defined by (module,column,row)                                
325   // module, column,raw should follow the internal PHOS convention:            
326   // module 1:5, column 1:56, row 1:64 
327   // if CBD instance exists, the value is taken from CDB. 
328   // Otherwise it is an ideal one  
329   
330   if(fCalibDataEmc)
331     return fCalibDataEmc->GetTimeShiftEmc(module,column,row);
332   else
333     return 1.0; // default width of one EMC ADC channel in GeV
334 }
335  
336 //________________________________________________________________
337 void AliPHOSCalibData::SetTimeShiftEmc(Int_t module, Int_t column, Int_t row, Float_t value)
338 {
339   // Set EMC calibration coefficient for (module,column,row)
340  
341   if(!fCalibDataEmc)
342     fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
343  
344   fCalibDataEmc->SetTimeShiftEmc(module,column,row,value);
345 }
346  
347 //________________________________________________________________
348 Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
349 {
350   // Return CPV calibration coefficient
351   // for channel defined by (module,column,row)
352   // module, column,raw should follow the internal CPV convention:
353   // module 1:5, column 1:56, row 1:128
354   // if CBD instance exists, the value is taken from CDB.
355   // Otherwise it is an ideal one
356
357   if(fCalibDataCpv) 
358     return fCalibDataCpv->GetADCchannelCpv(module,column,row);
359   else
360     return 0.0012; // default width of one ADC channel in CPV arbitrary units
361 }
362
363 //________________________________________________________________
364 Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
365 {
366   // Return CPV pedestal
367   // for channel defined by (module,column,row)
368   // module, column,raw should follow the internal CPV convention:
369   // module 1:5, column 1:56, row 1:128
370   // if CBD instance exists, the value is taken from CDB.
371   // Otherwise it is an ideal one
372
373   if(fCalibDataCpv) 
374     return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
375   else
376     return 0.012; // default CPV ADC pedestal
377 }
378
379 //________________________________________________________________
380 void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
381 {
382   // Set CPV calibration coefficient for (module,column,row)
383
384   if(!fCalibDataCpv)
385     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
386
387   fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
388 }
389
390 //________________________________________________________________
391 void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
392 {
393   // Set CPV pedestal for (module,column,row)
394
395   if(!fCalibDataCpv)
396     fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
397
398   fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
399 }
400
401 //________________________________________________________________
402 void AliPHOSCalibData::RandomEmc(Float_t ccMin, Float_t ccMax)
403 {
404   // Create decalibrated EMC with calibration coefficients and pedestals
405   // randomly distributed within hard-coded limits
406   // Default spread of calibration parameters is Cmax/Cmin = 4, (Cmax-Cmin)/2 = 1
407
408   if(fCalibDataEmc) delete fCalibDataEmc;
409   fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
410
411   TRandom rn;
412   rn.SetSeed(0); //the seed is set to the current  machine clock
413   
414   Float_t adcChannelEmc,adcPedestalEmc;
415
416   for(Int_t module=1; module<6; module++) {
417     for(Int_t column=1; column<57; column++) {
418       for(Int_t row=1; row<65; row++) {
419         adcChannelEmc =rn.Uniform(ccMin,ccMax);
420         adcPedestalEmc=rn.Uniform(0.0,0.0); // 0 spread of pedestals
421         fCalibDataEmc->SetADCchannelEmc(module,column,row,adcChannelEmc);
422         fCalibDataEmc->SetADCpedestalEmc(module,column,row,adcPedestalEmc);
423       }
424     }
425   }
426
427 }
428
429 //________________________________________________________________
430 void AliPHOSCalibData::RandomCpv(Float_t ccMin, Float_t ccMax)
431 {
432   // Create decalibrated CPV with calibration coefficients and pedestals
433   // randomly distributed within hard-coded limits
434   // Default spread of calibration parameters is  0.0012 +- 25%
435
436   if(fCalibDataCpv) delete fCalibDataCpv;
437   fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
438
439   TRandom rn;
440   rn.SetSeed(0); //the seed is set to the current  machine clock
441   
442   Float_t adcChannelCpv,adcPedestalCpv;
443
444   for(Int_t module=1; module<6; module++) {
445     for(Int_t column=1; column<57; column++) {
446       for(Int_t row=1; row<129; row++) {
447         adcChannelCpv =rn.Uniform(ccMin,ccMax);
448         adcPedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
449         fCalibDataCpv->SetADCchannelCpv(module,column,row,adcChannelCpv);
450         fCalibDataCpv->SetADCpedestalCpv(module,column,row,adcPedestalCpv);
451       }
452     }
453   }
454 }
455
456 //________________________________________________________________
457 Bool_t AliPHOSCalibData::IsBadChannelEmc(Int_t module, Int_t col, Int_t row) const
458 {
459   //If no bad channels map found, channel considered good
460
461   if(fEmcBadChannelsMap) 
462     return fEmcBadChannelsMap->IsBadChannel(module,col,row);
463   else
464     return kFALSE;
465 }
466
467 //________________________________________________________________
468 Int_t AliPHOSCalibData::GetNumOfEmcBadChannels() const
469 {
470   if(fEmcBadChannelsMap)
471     return fEmcBadChannelsMap->GetNumOfBadChannels();
472   else
473     return 0;
474 }
475
476 //________________________________________________________________
477 void AliPHOSCalibData::EmcBadChannelIds(Int_t *badIds)
478 {
479   //Fill array badIds by the Ids of EMC bad channels.
480   //Array badIds of length GetNumOfBadChannels() should be prepared in advance. 
481
482   if(fEmcBadChannelsMap)              
483     fEmcBadChannelsMap->BadChannelIds(badIds);
484 }