Change ECM calibration due to modifications in EMC amplitude units
[u/mrichter/AliRoot.git] / PHOS / macros / CalibrationDB / AliPHOSSetCDB.C
CommitLineData
83a8ef25 1/* $Id$ */
2
3// Script to create calibration parameters and store them into CDB
4// Two sets of calibration parameters can be created:
5// 1) equal parameters
6// 2) randomly distributed parameters for decalibrated detector silumations
7
18fdb171 8#if !defined(__CINT__)
9#include "TControlBar.h"
10#include "TString.h"
11#include "TRandom.h"
12#include "TH2F.h"
13#include "TCanvas.h"
14
15#include "AliRun.h"
16#include "AliPHOSCalibData.h"
17#include "AliCDBMetaData.h"
18#include "AliCDBId.h"
19#include "AliCDBEntry.h"
20#include "AliCDBManager.h"
21#include "AliCDBStorage.h"
22#endif
23
f162be9a 24static const Int_t nMod = 5;
25static const Int_t nCol = 56;
26static const Int_t nRow = 64;
18fdb171 27
83a8ef25 28void AliPHOSSetCDB()
29{
18fdb171 30 TControlBar *menu = new TControlBar("vertical","PHOS CDB");
31 menu->AddButton("Help to run PHOS CDB","Help()",
32 "Explains how to use PHOS CDS menus");
33 menu->AddButton("Equal CC","SetCC(0)",
34 "Set equal calibration coefficients");
35 menu->AddButton("Decalibrate","SetCC(1)",
36 "Set random decalibration calibration coefficients");
f162be9a 37 menu->AddButton("Set calibration equal to invers decalibration coefficients","SetCC(2)",
38 "Set calibration coefficients inverse to decalibration ones");
18fdb171 39 menu->AddButton("Read equal CC","GetCC(0)",
40 "Read initial equal calibration coefficients");
41 menu->AddButton("Read random CC","GetCC(1)",
42 "Read random decalibration calibration coefficients");
f162be9a 43 menu->AddButton("Read inverse CC","GetCC(2)",
44 "Read calibration coefficients inverse to decalibration ones");
18fdb171 45 menu->Show();
83a8ef25 46}
47
48//------------------------------------------------------------------------
18fdb171 49void Help()
83a8ef25 50{
51 char *string =
52 "\nSet calibration parameters and write them into ALICE CDB.
53Press button \"Equal CC\" to create equal pedestals and gain factors.
54Press button \"Decalibrate\" to create random pedestals and gain factors to imitate decalibrated detector\n";
55 printf(string);
56}
3a429efa 57
83a8ef25 58//------------------------------------------------------------------------
18fdb171 59void SetCC(Int_t flag=0)
83a8ef25 60{
61 // Writing calibration coefficients into the Calibration DB
62 // Arguments:
63 // flag=0: all calibration coefficients are equal
f162be9a 64 // flag=1: decalibration coefficients
65 // flag=2: calibration coefficients equal to inverse decalibration ones
3a429efa 66 // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
83a8ef25 67
68 TString DBFolder;
69 Int_t firstRun = 0;
f162be9a 70 Int_t lastRun = 0;
83a8ef25 71 Int_t beamPeriod = 1;
18fdb171 72 char* objFormat = "";
83a8ef25 73
69d5d19c 74 AliPHOSCalibData* cdb = 0;
75
83a8ef25 76 if (flag == 0) {
16b8ada8 77 DBFolder ="local://InitCalibDB";
83a8ef25 78 firstRun = 0;
f162be9a 79 lastRun = 0;
d53cb5cc 80 objFormat = "PHOS initial pedestals and ADC gain factors (5x64x56)";
69d5d19c 81 cdb = new AliPHOSCalibData();
82 cdb->CreateNew();
83a8ef25 83 }
69d5d19c 84
83a8ef25 85 else if (flag == 1) {
18fdb171 86 DBFolder ="local://DeCalibDB";
f162be9a 87 firstRun = 100;
88 lastRun = 100;
89 objFormat = "PHOS decalibration pedestals and ADC gain factors (5x64x56)";
69d5d19c 90
91 cdb = new AliPHOSCalibData();
92 cdb->RandomEmc();
93 cdb->RandomCpv();
83a8ef25 94 }
16b8ada8 95
f162be9a 96 else if (flag == 2) {
97 // First read decalibration DB
98 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
99 AliCDBManager::Instance()->SetSpecificStorage("PHOS","local://DeCalibDB");
100 AliPHOSCalibData* cdbDecalib = new AliPHOSCalibData(100);
101
102 DBFolder ="local://InverseCalibDB";
103 firstRun = 200;
104 lastRun = 200;
105 objFormat = "PHOS calibration parameters equal to inverse decalibration ones (5x64x56)";
106 cdb = new AliPHOSCalibData();
107
108 // Read EMC decalibration parameters and put inverse values to a new artificial CDB
109
110 for (Int_t module=1; module<=nMod; module++) {
111 for (Int_t column=1; column<=nCol; column++) {
112 for (Int_t row=1; row<=nRow; row++) {
113 Float_t valueGain = cdbDecalib->GetADCchannelEmc (module,column,row);
114 Float_t valuePed = cdbDecalib->GetADCpedestalEmc(module,column,row);
115 cdb->SetADCchannelEmc(module,column,row,1./valueGain);
116 cdb->SetADCpedestalEmc(module,column,row,valuePed);
117 }
118 }
119 }
120
121 // Read CPV decalibration parameters and put inverse values to a new artificial CDB
122
123 for (Int_t module=1; module<=nMod; module++) {
124 for (Int_t column=1; column<=nCol*2; column++) {
125 for (Int_t row=1; row<=nRow; row++) {
126 Float_t valueGain = cdbDecalib->GetADCchannelCpv (module,column,row);
127 Float_t valuePed = cdbDecalib->GetADCpedestalCpv(module,column,row);
128 cdb->SetADCchannelCpv(module,column,row,1./valueGain);
129 cdb->SetADCpedestalCpv(module,column,row,valuePed);
130 }
131 }
132 }
133 }
134 else if (flag == 3) {
135 // First read decalibration DB
136 DBFolder ="local://DeCalibDB";
137 firstRun = 0;
138 lastRun = 10;
139 objFormat = "PHOS decalibration pedestals and ADC gain factors (5x64x56)";
140
141 cdb = new AliPHOSCalibData();
142
143 for (Int_t module=1; module<=nMod; module++) {
144 for (Int_t column=1; column<=nCol; column++) {
145 for (Int_t row=1; row<=nRow; row++) {
146 cdb->SetADCchannelEmc(module,column,row,2.);
147 cdb->SetADCpedestalEmc(module,column,row,0.5);
148 }
149 }
150 }
151
152 for (Int_t module=1; module<=nMod; module++) {
153 for (Int_t column=1; column<=nCol*2; column++) {
154 for (Int_t row=1; row<=nRow; row++) {
155 cdb->SetADCchannelCpv(module,column,row,3.);
156 cdb->SetADCpedestalCpv(module,column,row,1.5);
157 }
158 }
159 }
160 }
161
83a8ef25 162 //Store calibration data into database
16b8ada8 163
164 AliCDBMetaData md;
165 md.SetComment(objFormat);
166 md.SetBeamPeriod(beamPeriod);
167 md.SetResponsible("Boris Polichtchouk");
168
69d5d19c 169 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
170 AliCDBManager::Instance()->SetSpecificStorage("PHOS",DBFolder.Data());
83a8ef25 171
69d5d19c 172 cdb->WriteEmc(firstRun,lastRun,&md);
173 cdb->WriteCpv(firstRun,lastRun,&md);
83a8ef25 174
83a8ef25 175}
3a429efa 176
177//------------------------------------------------------------------------
18fdb171 178void GetCC(Int_t flag=0)
3a429efa 179{
180 // Read calibration coefficients into the Calibration DB
181 // Arguments:
182 // flag=0: all calibration coefficients are equal
f162be9a 183 // flag=1: decalibration coefficients
184 // flag=2: calibration coefficients equal to inverse decalibration ones
3a429efa 185 // Author: Yuri.Kharlov at cern.ch
186
187 TString DBFolder;
f162be9a 188 Int_t runNumber;
3a429efa 189
190 if (flag == 0) {
16b8ada8 191 DBFolder ="local://InitCalibDB";
f162be9a 192 runNumber = 0;
3a429efa 193 }
194 else if (flag == 1) {
18fdb171 195 DBFolder ="local://DeCalibDB";
f162be9a 196 runNumber = 100;
197 }
198 else if (flag == 2) {
199 DBFolder ="local://InverseCalibDB";
200 runNumber = 200;
3a429efa 201 }
16b8ada8 202
69d5d19c 203 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
f162be9a 204 AliCDBManager::Instance()->SetSpecificStorage("PHOS",DBFolder.Data());
3a429efa 205
f162be9a 206 AliPHOSCalibData* clb = new AliPHOSCalibData(runNumber);
3a429efa 207
69d5d19c 208 TH2::AddDirectory(kFALSE);
209
210 TH2F* hPed[5];
211 TH2F* hGain[5];
212
213 TCanvas *cPed = new TCanvas("cPed" ,"PHOS EMC Pedestals" , 10,10,400,800);
214 TCanvas *cGain = new TCanvas("cGain","PHOS EMC Gain factors",410,10,400,800);
3a429efa 215 cPed ->Divide(1,5);
216 cGain->Divide(1,5);
217
f162be9a 218// for (Int_t module=1; module<=nMod; module++) {
219 for (Int_t module=1; module<=1; module++) {
3a429efa 220 TString namePed="hPed";
221 namePed+=module;
222 TString titlePed="Pedestals in module ";
223 titlePed+=module;
224 hPed[module-1] = new TH2F(namePed.Data(),titlePed.Data(),
225 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
226
227 TString nameGain="hGain";
228 nameGain+=module;
229 TString titleGain="Gain factors in module ";
230 titleGain+=module;
231 hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(),
232 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
233
234 for (Int_t column=1; column<=nCol; column++) {
235 for (Int_t row=1; row<=nRow; row++) {
236 Float_t ped = clb->GetADCpedestalEmc(module,column,row);
237 Float_t gain = clb->GetADCchannelEmc (module,column,row);
69d5d19c 238 hPed[module-1]->SetBinContent(column,row,ped);
3a429efa 239 hGain[module-1]->SetBinContent(column,row,gain);
240 }
241 }
242 cPed ->cd(module);
69d5d19c 243 hPed[module-1]->Draw("lego2");
3a429efa 244 cGain->cd(module);
245 hGain[module-1]->Draw("lego2");
246 }
247 cPed ->Print("pedestals.eps");
248 cGain->Print("gains.eps");
249}