Remove obsolete OCDB calibration files
[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");
e2e977c3 39 menu->AddButton("Residual calibration","SetCC(3)",
40 "Set residual decalibration calibration coefficients");
41
18fdb171 42 menu->AddButton("Read equal CC","GetCC(0)",
43 "Read initial equal calibration coefficients");
44 menu->AddButton("Read random CC","GetCC(1)",
45 "Read random decalibration calibration coefficients");
f162be9a 46 menu->AddButton("Read inverse CC","GetCC(2)",
47 "Read calibration coefficients inverse to decalibration ones");
e2e977c3 48 menu->AddButton("Read residual CC","GetCC(3)",
49 "Read residial calibration coefficients");
18fdb171 50 menu->Show();
83a8ef25 51}
52
53//------------------------------------------------------------------------
18fdb171 54void Help()
83a8ef25 55{
56 char *string =
57 "\nSet calibration parameters and write them into ALICE CDB.
58Press button \"Equal CC\" to create equal pedestals and gain factors.
59Press button \"Decalibrate\" to create random pedestals and gain factors to imitate decalibrated detector\n";
60 printf(string);
61}
3a429efa 62
83a8ef25 63//------------------------------------------------------------------------
18fdb171 64void SetCC(Int_t flag=0)
83a8ef25 65{
66 // Writing calibration coefficients into the Calibration DB
67 // Arguments:
68 // flag=0: all calibration coefficients are equal
f162be9a 69 // flag=1: decalibration coefficients
70 // flag=2: calibration coefficients equal to inverse decalibration ones
3a429efa 71 // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
83a8ef25 72
73 TString DBFolder;
74 Int_t firstRun = 0;
f162be9a 75 Int_t lastRun = 0;
83a8ef25 76 Int_t beamPeriod = 1;
18fdb171 77 char* objFormat = "";
83a8ef25 78
69d5d19c 79 AliPHOSCalibData* cdb = 0;
80
83a8ef25 81 if (flag == 0) {
16b8ada8 82 DBFolder ="local://InitCalibDB";
83a8ef25 83 firstRun = 0;
c87f07e5 84 lastRun = 999999;
d53cb5cc 85 objFormat = "PHOS initial pedestals and ADC gain factors (5x64x56)";
69d5d19c 86 cdb = new AliPHOSCalibData();
87 cdb->CreateNew();
83a8ef25 88 }
69d5d19c 89
83a8ef25 90 else if (flag == 1) {
18fdb171 91 DBFolder ="local://DeCalibDB";
c87f07e5 92 firstRun = 0;
93 lastRun = 999999;
f162be9a 94 objFormat = "PHOS decalibration pedestals and ADC gain factors (5x64x56)";
69d5d19c 95
96 cdb = new AliPHOSCalibData();
97 cdb->RandomEmc();
98 cdb->RandomCpv();
83a8ef25 99 }
16b8ada8 100
f162be9a 101 else if (flag == 2) {
102 // First read decalibration DB
103 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
c87f07e5 104 AliCDBManager::Instance()->SetSpecificStorage("PHOS/*","local://DeCalibDB");
f162be9a 105 AliPHOSCalibData* cdbDecalib = new AliPHOSCalibData(100);
106
107 DBFolder ="local://InverseCalibDB";
c87f07e5 108 firstRun = 0;
109 lastRun = 999999;
f162be9a 110 objFormat = "PHOS calibration parameters equal to inverse decalibration ones (5x64x56)";
111 cdb = new AliPHOSCalibData();
112
113 // Read EMC decalibration parameters and put inverse values to a new artificial CDB
114
115 for (Int_t module=1; module<=nMod; module++) {
116 for (Int_t column=1; column<=nCol; column++) {
117 for (Int_t row=1; row<=nRow; row++) {
118 Float_t valueGain = cdbDecalib->GetADCchannelEmc (module,column,row);
119 Float_t valuePed = cdbDecalib->GetADCpedestalEmc(module,column,row);
120 cdb->SetADCchannelEmc(module,column,row,1./valueGain);
121 cdb->SetADCpedestalEmc(module,column,row,valuePed);
122 }
123 }
124 }
125
126 // Read CPV decalibration parameters and put inverse values to a new artificial CDB
127
128 for (Int_t module=1; module<=nMod; module++) {
129 for (Int_t column=1; column<=nCol*2; column++) {
130 for (Int_t row=1; row<=nRow; row++) {
131 Float_t valueGain = cdbDecalib->GetADCchannelCpv (module,column,row);
132 Float_t valuePed = cdbDecalib->GetADCpedestalCpv(module,column,row);
133 cdb->SetADCchannelCpv(module,column,row,1./valueGain);
134 cdb->SetADCpedestalCpv(module,column,row,valuePed);
135 }
136 }
137 }
138 }
139 else if (flag == 3) {
e2e977c3 140 DBFolder ="local://ResidualCalibDB";
f162be9a 141 firstRun = 0;
e2e977c3 142 lastRun = 999999;
143 objFormat = "PHOS residual ADC gain factors (5x64x56)";
144
f162be9a 145 cdb = new AliPHOSCalibData();
e2e977c3 146 cdb->RandomEmc(0.98,1.02);
147 cdb->RandomCpv(0.00115,0.00125);
f162be9a 148 }
149
83a8ef25 150 //Store calibration data into database
16b8ada8 151
152 AliCDBMetaData md;
153 md.SetComment(objFormat);
154 md.SetBeamPeriod(beamPeriod);
155 md.SetResponsible("Boris Polichtchouk");
156
69d5d19c 157 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
c87f07e5 158 AliCDBManager::Instance()->SetSpecificStorage("PHOS/*",DBFolder.Data());
83a8ef25 159
69d5d19c 160 cdb->WriteEmc(firstRun,lastRun,&md);
161 cdb->WriteCpv(firstRun,lastRun,&md);
83a8ef25 162
83a8ef25 163}
3a429efa 164
165//------------------------------------------------------------------------
18fdb171 166void GetCC(Int_t flag=0)
3a429efa 167{
168 // Read calibration coefficients into the Calibration DB
169 // Arguments:
170 // flag=0: all calibration coefficients are equal
f162be9a 171 // flag=1: decalibration coefficients
172 // flag=2: calibration coefficients equal to inverse decalibration ones
3a429efa 173 // Author: Yuri.Kharlov at cern.ch
174
175 TString DBFolder;
f162be9a 176 Int_t runNumber;
3a429efa 177
178 if (flag == 0) {
16b8ada8 179 DBFolder ="local://InitCalibDB";
f162be9a 180 runNumber = 0;
3a429efa 181 }
182 else if (flag == 1) {
18fdb171 183 DBFolder ="local://DeCalibDB";
f162be9a 184 runNumber = 100;
185 }
186 else if (flag == 2) {
187 DBFolder ="local://InverseCalibDB";
188 runNumber = 200;
3a429efa 189 }
e2e977c3 190 else if (flag == 2) {
191 DBFolder ="local://ResidualCalibDB";
192 runNumber = 0;
193 }
16b8ada8 194
69d5d19c 195 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
c87f07e5 196 AliCDBManager::Instance()->SetSpecificStorage("PHOS/*",DBFolder.Data());
3a429efa 197
f162be9a 198 AliPHOSCalibData* clb = new AliPHOSCalibData(runNumber);
3a429efa 199
69d5d19c 200 TH2::AddDirectory(kFALSE);
201
202 TH2F* hPed[5];
203 TH2F* hGain[5];
204
205 TCanvas *cPed = new TCanvas("cPed" ,"PHOS EMC Pedestals" , 10,10,400,800);
206 TCanvas *cGain = new TCanvas("cGain","PHOS EMC Gain factors",410,10,400,800);
3a429efa 207 cPed ->Divide(1,5);
208 cGain->Divide(1,5);
209
e2e977c3 210 for (Int_t module=1; module<=nMod; module++) {
3a429efa 211 TString namePed="hPed";
212 namePed+=module;
213 TString titlePed="Pedestals in module ";
214 titlePed+=module;
215 hPed[module-1] = new TH2F(namePed.Data(),titlePed.Data(),
216 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
217
218 TString nameGain="hGain";
219 nameGain+=module;
220 TString titleGain="Gain factors in module ";
221 titleGain+=module;
222 hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(),
223 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
224
225 for (Int_t column=1; column<=nCol; column++) {
226 for (Int_t row=1; row<=nRow; row++) {
227 Float_t ped = clb->GetADCpedestalEmc(module,column,row);
228 Float_t gain = clb->GetADCchannelEmc (module,column,row);
69d5d19c 229 hPed[module-1]->SetBinContent(column,row,ped);
3a429efa 230 hGain[module-1]->SetBinContent(column,row,gain);
231 }
232 }
233 cPed ->cd(module);
69d5d19c 234 hPed[module-1]->Draw("lego2");
3a429efa 235 cGain->cd(module);
236 hGain[module-1]->Draw("lego2");
237 }
238 cPed ->Print("pedestals.eps");
239 cGain->Print("gains.eps");
240}