Calibration objects for EMC and CPV
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibData.cxx
CommitLineData
52783dbc 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
fc6706cb 24#include "TMath.h"
25#include "TRandom.h"
52783dbc 26#include "AliPHOSCalibData.h"
fc6706cb 27#include "AliCDBManager.h"
28#include "AliCDBStorage.h"
29#include "AliCDBId.h"
30#include "AliCDBEntry.h"
52783dbc 31
32ClassImp(AliPHOSCalibData)
33
34//________________________________________________________________
fc6706cb 35 AliPHOSCalibData::AliPHOSCalibData():
36 TNamed(), fCalibDataEmc(0x0), fCalibDataCpv(0x0)
52783dbc 37{
fc6706cb 38 // Default constructor
39
40 fEmcDataPath="PHOS/Emc/GainFactors_and_Pedestals";
41 fCpvDataPath="PHOS/Cpv/GainFactors_and_Pedestals";
42
52783dbc 43}
44
45//________________________________________________________________
fc6706cb 46AliPHOSCalibData::AliPHOSCalibData(Int_t runNumber) :
47 TNamed("phosCalib","PHOS Calibration Data Manager"),
48 fCalibDataEmc(0x0), fCalibDataCpv(0x0)
52783dbc 49{
50 // Constructor
fc6706cb 51
52 fEmcDataPath="PHOS/Emc/GainFactors_and_Pedestals";
53 fCpvDataPath="PHOS/Cpv/GainFactors_and_Pedestals";
54
55 AliCDBEntry* entryEmc = AliCDBManager::Instance()->Get(fEmcDataPath.Data(),runNumber);
56 if(entryEmc)
57 fCalibDataEmc = (AliPHOSEmcCalibData*)entryEmc->GetObject();
58
59 AliCDBEntry* entryCpv = AliCDBManager::Instance()->Get(fCpvDataPath.Data(),runNumber);
60 if(entryCpv)
61 fCalibDataCpv = (AliPHOSCpvCalibData*)entryCpv->GetObject();
52783dbc 62
52783dbc 63}
64
65//________________________________________________________________
66AliPHOSCalibData::~AliPHOSCalibData()
67{
68 // Destructor
fc6706cb 69
70 if(fCalibDataEmc) delete fCalibDataEmc;
71 if(fCalibDataCpv) delete fCalibDataCpv;
72
52783dbc 73}
74
75//________________________________________________________________
76void AliPHOSCalibData::Reset()
77{
78 // Set all pedestals to 0 and all ADC channels to 1
fc6706cb 79
80 fCalibDataEmc->Reset();
81 fCalibDataCpv->Reset();
52783dbc 82}
83
84//________________________________________________________________
85void AliPHOSCalibData::Print(Option_t *option) const
86{
fc6706cb 87
88}
89
90//________________________________________________________________
91void AliPHOSCalibData::CreateNew()
92{
93 if(fCalibDataEmc) delete fCalibDataEmc;
94 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
95
96 if(fCalibDataCpv) delete fCalibDataCpv;
97 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
98
99}
100
101//________________________________________________________________
102Bool_t AliPHOSCalibData::WriteEmc(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
103{
104
105 if(!fCalibDataEmc) return kFALSE;
106
107 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS");
108 if(storage) {
109 AliCDBId id(fEmcDataPath.Data(),firstRun,lastRun);
110 storage->Put(fCalibDataEmc,id, md);
111 return kTRUE;
52783dbc 112 }
fc6706cb 113 else
114 return kFALSE;
52783dbc 115
fc6706cb 116}
117
118//________________________________________________________________
119Bool_t AliPHOSCalibData::WriteCpv(Int_t firstRun, Int_t lastRun, AliCDBMetaData *md)
120{
121
122 if(!fCalibDataCpv) return kFALSE;
123
124 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("PHOS");
125 if(storage) {
126 AliCDBId id(fCpvDataPath.Data(),firstRun,lastRun);
127 storage->Put(fCalibDataCpv,id, md);
128 return kTRUE;
52783dbc 129 }
fc6706cb 130 else
131 return kFALSE;
132
52783dbc 133}
072de3a8 134
fc6706cb 135//________________________________________________________________
072de3a8 136Float_t AliPHOSCalibData::GetADCchannelEmc(Int_t module, Int_t column, Int_t row) const
137{
138 //module, column,raw should follow the internal PHOS convention:
139 //module 1:5, column 1:56, row 1:64
140
fc6706cb 141 if(fCalibDataEmc)
142 return fCalibDataEmc->GetADCchannelEmc(module,column,row);
143 else
144 return 0.0015; // default width of one EMC ADC channel in GeV
072de3a8 145}
146
147Float_t AliPHOSCalibData::GetADCpedestalEmc(Int_t module, Int_t column, Int_t row) const
148{
fc6706cb 149 if(fCalibDataEmc)
150 return fCalibDataEmc->GetADCpedestalEmc(module,column,row);
151 else
152 return 0.005; // default EMC ADC pedestal
072de3a8 153}
154
155void AliPHOSCalibData::SetADCchannelEmc(Int_t module, Int_t column, Int_t row, Float_t value)
156{
fc6706cb 157 if(!fCalibDataEmc)
158 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
159
160 fCalibDataEmc->SetADCchannelEmc(module,column,row,value);
072de3a8 161}
162
163void AliPHOSCalibData::SetADCpedestalEmc(Int_t module, Int_t column, Int_t row, Float_t value)
164{
fc6706cb 165 if(!fCalibDataEmc)
166 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
167
168 fCalibDataEmc->SetADCpedestalEmc(module,column,row,value);
169}
170
171//________________________________________________________________
172Float_t AliPHOSCalibData::GetADCchannelCpv(Int_t module, Int_t column, Int_t row) const
173{
174 //module, column,raw should follow the internal CPV convention:
175 //module 1:5, column 1:64, row 1:128
176
177 if(fCalibDataCpv)
178 return fCalibDataCpv->GetADCchannelCpv(module,column,row);
179 else
180 return 0.0012; // default width of one ADC channel in CPV 'popugais'
181}
182
183Float_t AliPHOSCalibData::GetADCpedestalCpv(Int_t module, Int_t column, Int_t row) const
184{
185 if(fCalibDataCpv)
186 return fCalibDataCpv->GetADCpedestalCpv(module,column,row);
187 else
188 return 0.012; // default CPV ADC pedestal
189}
190
191void AliPHOSCalibData::SetADCchannelCpv(Int_t module, Int_t column, Int_t row, Float_t value)
192{
193 if(!fCalibDataCpv)
194 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
195
196 fCalibDataCpv->SetADCchannelCpv(module,column,row,value);
197}
198
199void AliPHOSCalibData::SetADCpedestalCpv(Int_t module, Int_t column, Int_t row, Float_t value)
200{
201 if(!fCalibDataCpv)
202 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
203
204 fCalibDataCpv->SetADCpedestalCpv(module,column,row,value);
205}
206
207//________________________________________________________________
208void AliPHOSCalibData::RandomEmc()
209{
210
211 if(fCalibDataEmc) delete fCalibDataEmc;
212 fCalibDataEmc = new AliPHOSEmcCalibData("PHOS-EMC");
213
214 TRandom rn;
215 rn.SetSeed(0); //the seed is set to the current machine clock
216
217 Float_t ADCchanelEmc,ADCpedestalEmc;
218
219 for(Int_t module=1; module<6; module++) {
220 for(Int_t column=1; column<57; column++) {
221 for(Int_t row=1; row<65; row++) {
222 ADCchanelEmc=rn.Uniform(0.00075,0.00375); // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
223 ADCpedestalEmc=rn.Uniform(0.0045,0.0055); //+-10% spread of pedestals from 0.005
224 fCalibDataEmc->SetADCchannelEmc(module,column,row,ADCchanelEmc);
225 fCalibDataEmc->SetADCpedestalEmc(module,column,row,ADCpedestalEmc);
226 }
227 }
228 }
229
230}
231
232//________________________________________________________________
233void AliPHOSCalibData::RandomCpv()
234{
235
236 if(fCalibDataCpv) delete fCalibDataCpv;
237 fCalibDataCpv = new AliPHOSCpvCalibData("PHOS-CPV");
238
239 TRandom rn;
240 rn.SetSeed(0); //the seed is set to the current machine clock
241
242 Float_t ADCchanelCpv,ADCpedestalCpv;
243
244 for(Int_t module=1; module<6; module++) {
245 for(Int_t column=1; column<65; column++) {
246 for(Int_t row=1; row<129; row++) {
247 ADCchanelCpv=TMath::Abs(rn.Uniform(0.0009,0.0015)); // 0.0012 +- 25%
248 ADCpedestalCpv=rn.Uniform(0.0048,0.0192); // Ped[max]/Ped[min] = 4, <Ped> = 0.012
249 fCalibDataCpv->SetADCchannelCpv(module,column,row,ADCchanelCpv);
250 fCalibDataCpv->SetADCpedestalCpv(module,column,row,ADCpedestalCpv);
251 }
252 }
253 }
072de3a8 254}