]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
update macro with updated default calibration setting, plotting for new SM
[u/mrichter/AliRoot.git] / EMCAL / macros / CalibrationDB / AliEMCALSetCDB.C
CommitLineData
29272b1f 1// Script to create calibration parameters and store them into CDB
16d3c94d 2// Thre sets of calibration parameters can be created:
29272b1f 3// 1) equal parameters
4// 2) randomly distributed parameters for decalibrated detector silumations
16d3c94d 5// 3) gausian distributed parameters for decalibrated detector silumations
6//
29272b1f 7// Modified from PHOS script for EMCAL by Gustavo Conesa
16d3c94d 8// May 3, 2007: Modified by Aleksei Pavlinov
9
10//.x $ALICE_ROOT/EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
29272b1f 11
12#if !defined(__CINT__)
16d3c94d 13#include <TControlBar.h>
14#include <TString.h>
15#include <TRandom.h>
16#include <TStyle.h>
17#include <TH2.h>
18#include <TF1.h>
19#include <TCanvas.h>
29272b1f 20
21#include "AliRun.h"
22#include "AliEMCALCalibData.h"
8cc543cb 23#include "AliEMCALGeoParams.h"
29272b1f 24#include "AliCDBMetaData.h"
25#include "AliCDBId.h"
26#include "AliCDBEntry.h"
27#include "AliCDBManager.h"
28#include "AliCDBStorage.h"
29#endif
30
31
32void AliEMCALSetCDB()
33{
34 TControlBar *menu = new TControlBar("vertical","EMCAL CDB");
35 menu->AddButton("Help to run EMCAL CDB","Help()",
36 "Explains how to use EMCAL CDS menus");
37 menu->AddButton("Equal CC","SetCC(0)",
38 "Set equal calibration coefficients");
16d3c94d 39 menu->AddButton("Random De-calibration","SetCC(1)",
29272b1f 40 "Set random decalibration calibration coefficients");
16d3c94d 41 menu->AddButton("Gaussian De-calibration","SetCC(2)",
42 "Set gausian decalibration calibration coefficients");
29272b1f 43 menu->AddButton("Read equal CC","GetCC(0)",
44 "Read initial equal calibration coefficients");
45 menu->AddButton("Read random CC","GetCC(1)",
46 "Read random decalibration calibration coefficients");
16d3c94d 47 menu->AddButton("Read gaussian CC","GetCC(2)",
48 "Read gausian decalibration calibration coefficients");
29272b1f 49 menu->Show();
50}
51
52//------------------------------------------------------------------------
53void Help()
54{
55 char *string =
56 "\nSet calibration parameters and write them into ALICE CDB. Press button \"Equal CC\" to create equal pedestals and gain factors. Press button \"Decalibrate\" to create random pedestals and gain factors to imitate decalibrated detector\n";
57 printf(string);
58}
59
60//------------------------------------------------------------------------
61void SetCC(Int_t flag=0)
62{
63 // Writing calibration coefficients into the Calibration DB
64 // Arguments:
65 // flag=0: all calibration coefficients are equal
66 // flag=1: all calibration coefficients random (decalibration)
16d3c94d 67 // flag=2: all calibration coefficients have Gaussian random distribution (decalibration)
29272b1f 68 // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
c0b38a1b 69
29272b1f 70 TString DBFolder;
16d3c94d 71 Int_t firstRun = 0; // What is this
29272b1f 72 Int_t lastRun = 10;
73 Int_t beamPeriod = 1;
74 char* objFormat = "";
c0b38a1b 75
76 if (flag == 0)
77 {
29272b1f 78 DBFolder ="local://InitCalibDB";
79 firstRun = 0;
8cc543cb 80 lastRun = 999999999;
29272b1f 81 objFormat = "EMCAL initial gain factors and pedestals";
82 }
c0b38a1b 83 else if (flag == 1)
84 {
29272b1f 85 DBFolder ="local://DeCalibDB";
86 firstRun = 0;
87 lastRun = 12;
88 objFormat = "EMCAL random pedestals and ADC gain factors (12x48x24)";
89 }
c0b38a1b 90 else if (flag == 2)
91 {
16d3c94d 92 DBFolder ="local://DeCalibDB"; // create directory DeCalibDB in current directory
93 firstRun = 0;
94 lastRun = 12; // Why 12 ?
95 objFormat = "EMCAL random pedestals and gausian ADC gain factors (12x48x24)";
96 }
29272b1f 97
98 AliEMCALCalibData *calibda=new AliEMCALCalibData("EMCAL");
99
c0b38a1b 100 Float_t fADCpedestal = 0.000;
101 Float_t fADCchannel = 0.0162; // 250 GeV / (16*1024)
102 Float_t rDecalibration = 0.02 * fADCchannel; // 2% decalibration - just a guess
16d3c94d 103 Float_t cc=0, ped;
c0b38a1b 104
29272b1f 105 TRandom rn;
8cc543cb 106 Int_t nSMod = AliEMCALGeoParams::fgkEMCALModules;
c0b38a1b 107
108 for(Int_t supermodule=0; supermodule < nSMod; supermodule++)
109 {
8cc543cb 110 Int_t nCol = AliEMCALGeoParams::fgkEMCALCols;
111 Int_t nRow = AliEMCALGeoParams::fgkEMCALRows;
112 if(supermodule /2 == 5)
113 nRow = nRow/2;
114 if(supermodule > 11)//not good solution
115 nCol = nCol*2/3;
c0b38a1b 116
117 for(Int_t column=0; column< nCol; column++)
118 {
119 for(Int_t row=0; row< nRow; row++)
120 {
16d3c94d 121 cc = fADCchannel;
122 ped = fADCpedestal;
c0b38a1b 123 if (flag == 1)
124 {
125 // Decalibration:
126 // Spread calibration coefficients uniformly with
127 // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
128 // and pedestals 0.005 +-10%
129 // fADCchannel = rn.Uniform(0.00075,0.00375);
130 cc = rn.Uniform(0.00140,0.00160);
131 ped = 0;
132 }
133 else if (flag == 2)
134 { // Gaussian
135 cc = rn.Gaus(fADCchannel, rDecalibration);
136 ped = rn.Uniform(0.0045,0.0055);
137 }
138
139 calibda->SetADCchannel (supermodule,column,row, cc);
140 calibda->SetADCchannelOnline(supermodule,column,row, cc);
141 calibda->SetADCpedestal (supermodule,column,row, ped);
142 cout<<"Set SM: "<<supermodule<<" col "<<column<<" row "<<row
143 <<" cc "<< cc <<" ped "<<ped<<endl;
29272b1f 144 }
145 }
146 }
c0b38a1b 147
29272b1f 148 //Store calibration data into database
149
150 AliCDBMetaData md;
151 md.SetComment(objFormat);
152 md.SetBeamPeriod(beamPeriod);
c0b38a1b 153 md.SetResponsible("Gustavo Conesa");
29272b1f 154
c0b38a1b 155 AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun); // create in EMCAL/Calib/Data DBFolder
156
157 AliCDBManager* man = AliCDBManager::Instance();
29272b1f 158 AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
159 loc->Put(calibda, id, &md);
c0b38a1b 160
29272b1f 161}
162
163//------------------------------------------------------------------------
164void GetCC(Int_t flag=0)
165{
166 // Read calibration coefficients into the Calibration DB
167 // Arguments:
168 // flag=0: all calibration coefficients are equal
169 // flag=1: all calibration coefficients random (decalibration)
170 // Author: Yuri.Kharlov at cern.ch
c0b38a1b 171
29272b1f 172 TString DBFolder;
c0b38a1b 173 int drawKey=2;
174
175 if (flag == 0)
176 {
29272b1f 177 DBFolder ="local://InitCalibDB";
178 }
c0b38a1b 179 else if (flag == 1 || flag == 2)
180 {
16d3c94d 181 // DBFolder ="local://DeCalibDB"; // Get DB in current folder
182 DBFolder ="local:///data/r22b/ALICE/PROD/CALIBRATION_May_2007/PI0/DeCalibDB"; // absolute name - Aug 31, 2007
183 TString HOST(gSystem->Getenv("HOST"));
184 if(HOST.Contains("pc")) { // pdsf; May 31, 2007
185 DBFolder ="local:///eliza5/alice/pavlinov/PROD/CALIBRATION_May_2007/PI0/10GEV/DECALIB/DeCalibDB";
186 }
29272b1f 187 }
c0b38a1b 188
189 const Int_t runNumber = 0;
29272b1f 190 AliEMCALCalibData* clb = (AliEMCALCalibData*)
c0b38a1b 191 (AliCDBManager::Instance()
192 ->GetStorage(DBFolder.Data())
193 ->Get("EMCAL/Calib/Data",runNumber)->GetObject());
194
195 const Int_t nSMod = AliEMCALGeoParams::fgkEMCALModules;
16d3c94d 196 Int_t nCC = 0;
c0b38a1b 197
198 TH2F *hPed[nSMod], *hGain[nSMod], *hGainOnline[nSMod];
199 TH1F *hCCSum = new TH1F("hCCSum"," CC summary (in MeV) ", 200, 0.0, 20.);
200 TH1F *hCCOnSum = new TH1F("hCCSumOn"," CC online summary (in MeV) ", 200, 0.0, 20.);
201 TH1F *hPedSum = new TH1F("hPedSum"," pedestal summary (in MeV) ", 100, 4., 6.);
202
203 TCanvas *cPed =0, *cGain =0, *cGainOn =0,
204 TCanvas *cPed2=0, *cGain2=0, *cGainOn2=0;
205 TCanvas *cPed3=0, *cGain3=0, *cGainOn3=0;
206 TCanvas *cPed4=0, *cGain4=0, *cGainOn4=0;
207
208 if(drawKey>1)
209 {
210 cPed = new TCanvas("cPed" ,"Pedestals Mod 0-5" , 10,10,400,800);
211 cGain = new TCanvas("cGain","Gain factors Mod 0-5", 410,10,400,800);
212 cGainOn = new TCanvas("cGainOn","Gain online factors Mod 0-5", 410,10,400,800);
213 cPed ->Divide(2,3);
214 cGain ->Divide(2,3);
215 cGainOn ->Divide(2,3);
216
217 cPed2 = new TCanvas("cPed2","Pedestals SMod 6-11", 10,10,400,800);
218 cGain2 = new TCanvas("cGain2","Gain factors SMod 6-11", 410,10,400,800);
219 cGainOn2 = new TCanvas("cGainOn2","Gain online factors SMod 6-11", 410,10,400,800);
220 cPed2 ->Divide(2,3);
221 cGain2 ->Divide(2,3);
222 cGainOn2->Divide(2,3);
223
224 cPed3 = new TCanvas("cPed3","Pedestals SMod 12-17", 10,10,400,800);
225 cGain3 = new TCanvas("cGain3","Gain factors SMod 12-17", 410,10,400,800);
226 cGainOn3 = new TCanvas("cGainOn3","Gain online factors SMod 7-17", 410,10,400,800);
227 cPed3 ->Divide(2,3);
228 cGain3 ->Divide(2,3);
229 cGainOn3->Divide(2,3);
230
231 cPed4 = new TCanvas("cPed4","Pedestals SMod 18-21", 10,10,400,400);
232 cGain4 = new TCanvas("cGain4","Gain factors SMod 18-21", 410,10,400,800);
233 cGainOn4 = new TCanvas("cGainOn4","Gain online factors SMod 18-21", 410,10,400,400);
234 cPed4 ->Divide(2,2);
235 cGain4 ->Divide(2,2);
236 cGainOn4->Divide(2,2);
29272b1f 237
16d3c94d 238 }
c0b38a1b 239
16d3c94d 240 TCanvas *cSum = new TCanvas("cSum" ,"summary" , 10,10,600,800);
c0b38a1b 241 cSum->Divide(1,2);
242
16d3c94d 243 cout<<endl;
c0b38a1b 244
245 for (Int_t supermodule=0; supermodule<nSMod; supermodule++)
246 {
8cc543cb 247 Int_t nCol = AliEMCALGeoParams::fgkEMCALCols;
248 Int_t nRow = AliEMCALGeoParams::fgkEMCALRows;
c0b38a1b 249
8cc543cb 250 if(supermodule /2 == 5)
c0b38a1b 251 nRow = nRow/2;
8cc543cb 252 if(supermodule > 11)
c0b38a1b 253 nCol = nCol*2/3;
254
29272b1f 255 TString namePed="hPed";
256 namePed+=supermodule;
257 TString titlePed="Pedestals in supermodule ";
258 titlePed+=supermodule;
6e91c38e 259 hPed[supermodule] = new TH2F(namePed.Data(),titlePed.Data(),
c0b38a1b 260 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
261
29272b1f 262 TString nameGain="hGain";
c0b38a1b 263 TString nameGainOnline="hGainOnline";
29272b1f 264 nameGain+=supermodule;
c0b38a1b 265 nameGainOnline+=supermodule;
29272b1f 266 TString titleGain="Gain factors in supermodule ";
267 titleGain+=supermodule;
c0b38a1b 268 TString titleGainOnline="Gain online factors in supermodule ";
269 titleGainOnline+=supermodule;
270 hGain [supermodule] = new TH2F(nameGain.Data(),titleGain.Data(),
271 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
272 hGainOnline[supermodule] = new TH2F(nameGainOnline.Data(),titleGainOnline.Data(),
273 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
274 for (Int_t column=0; column<nCol; column++)
275 {
276 for (Int_t row=0; row<nRow; row++)
277 {
278 Float_t ped = clb->GetADCpedestal (supermodule,column,row);
279 Float_t gainOn = clb->GetADCchannelOnline(supermodule,column,row);
280 Float_t gain = clb->GetADCchannel (supermodule,column,row);
281 //cout<<"Get SM: "<<supermodule<<" col "<<column<<" row "<<row
282 //<<" chan "<<gain<<endl;
283 hPed [supermodule]->SetBinContent(column+1,row+1,ped*1.e+3); // in mev
284 hGain [supermodule]->SetBinContent(column+1,row+1,gain*1.e+3); // in mev
285 hGainOnline[supermodule]->SetBinContent(column+1,row+1,gain*1.e+3); // in mev
286
287 hPedSum ->Fill(ped *1.e+3);
288 hCCSum ->Fill(gain *1.e+3);
289 hCCOnSum->Fill(gainOn*1.e+3);
290
16d3c94d 291 nCC++;
29272b1f 292 }
293 }
16d3c94d 294 cout<<" Fill cc for SM "<< supermodule << " nCC "<< nCC << endl;
295
c0b38a1b 296 if(drawKey>1)
297 {
298 if(supermodule < 6)
299 {
16d3c94d 300 cPed ->cd(supermodule+1);
301 hPed[supermodule]->Draw("lego2");
302 cGain->cd(supermodule+1);
303 hGain[supermodule]->Draw("lego2");
c0b38a1b 304 cGainOn->cd(supermodule+1);
305 hGainOnline[supermodule]->Draw("lego2");
16d3c94d 306 }
c0b38a1b 307 else if(supermodule < 12)
308 {
16d3c94d 309 cPed2 ->cd(supermodule-5);
310 hPed[supermodule]->Draw("lego2");
311 cGain2->cd(supermodule-5);
312 hGain[supermodule]->Draw("lego2");
c0b38a1b 313 cGainOn2->cd(supermodule-5);
314 hGainOnline[supermodule]->Draw("lego2");
315 }
316 else if(supermodule < 18)
317 {
318 cPed3 ->cd(supermodule-11);
319 hPed[supermodule]->Draw("lego2");
320 cGain3->cd(supermodule-11);
321 hGain[supermodule]->Draw("lego2");
322 cGainOn3->cd(supermodule-11);
323 hGainOnline[supermodule]->Draw("lego2");
324 }
325 else
326 {
327 cPed4 ->cd(supermodule-17);
328 hPed[supermodule]->Draw("lego2");
329 cGain4->cd(supermodule-17);
330 hGain[supermodule]->Draw("lego2");
331 cGainOn4->cd(supermodule-17);
332 hGainOnline[supermodule]->Draw("lego2");
16d3c94d 333 }
19c9c8e2 334 }
29272b1f 335 }
16d3c94d 336 cout << " Get "<<nCC<<" calibration coeffs"<<endl;
c0b38a1b 337
16d3c94d 338 cSum->cd(1);
339 gStyle->SetOptFit(111);
340 hCCSum->Fit("gaus");
341 hCCSum->SetLineWidth(2);
342 hCCSum->GetFunction("gaus")->SetLineColor(2);
343
344 cSum->cd(2);
345 hPedSum->Draw();
346 hPedSum->SetLineWidth(2);
c0b38a1b 347
16d3c94d 348 cSum->Update();
c0b38a1b 349
350 if(drawKey>1)
351 {
352 cPed ->Print("pedestals_SM_0_6.eps");
353 cGain ->Print("gains_SM_0_5.eps");
354 cPed2 ->Print("pedestals_SM_6_11.eps");
355 cGain2 ->Print("gains_SM_6_11.eps");
356 }
357
29272b1f 358}