Corrections for CINT compilation
[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
24
83a8ef25 25void AliPHOSSetCDB()
26{
18fdb171 27 TControlBar *menu = new TControlBar("vertical","PHOS CDB");
28 menu->AddButton("Help to run PHOS CDB","Help()",
29 "Explains how to use PHOS CDS menus");
30 menu->AddButton("Equal CC","SetCC(0)",
31 "Set equal calibration coefficients");
32 menu->AddButton("Decalibrate","SetCC(1)",
33 "Set random decalibration calibration coefficients");
34 menu->AddButton("Read equal CC","GetCC(0)",
35 "Read initial equal calibration coefficients");
36 menu->AddButton("Read random CC","GetCC(1)",
37 "Read random decalibration calibration coefficients");
38 menu->Show();
83a8ef25 39}
40
41//------------------------------------------------------------------------
18fdb171 42void Help()
83a8ef25 43{
44 char *string =
45 "\nSet calibration parameters and write them into ALICE CDB.
46Press button \"Equal CC\" to create equal pedestals and gain factors.
47Press button \"Decalibrate\" to create random pedestals and gain factors to imitate decalibrated detector\n";
48 printf(string);
49}
3a429efa 50
83a8ef25 51//------------------------------------------------------------------------
18fdb171 52void SetCC(Int_t flag=0)
83a8ef25 53{
54 // Writing calibration coefficients into the Calibration DB
55 // Arguments:
56 // flag=0: all calibration coefficients are equal
57 // flag=1: all calibration coefficients random (decalibration)
3a429efa 58 // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
83a8ef25 59
60 TString DBFolder;
61 Int_t firstRun = 0;
62 Int_t lastRun = 10;
63 Int_t beamPeriod = 1;
18fdb171 64 char* objFormat = "";
83a8ef25 65
66 if (flag == 0) {
16b8ada8 67 DBFolder ="local://InitCalibDB";
83a8ef25 68 firstRun = 0;
69 lastRun = 0;
70 objFormat = "PHOS initial gain factors and pedestals";
71 }
72 else if (flag == 1) {
18fdb171 73 DBFolder ="local://DeCalibDB";
83a8ef25 74 firstRun = 0;
75 lastRun = 10;
76 objFormat = "PHOS random pedestals and ADC gain factors (5x64x56)";
77 }
16b8ada8 78
83a8ef25 79 AliPHOSCalibData *calibda=new AliPHOSCalibData("PHOS");
80
81 Float_t fADCpedestalEmc = 0.005;
82 Float_t fADCchanelEmc = 0.0015;
16b8ada8 83
83a8ef25 84 TRandom rn;
16b8ada8 85
83a8ef25 86 for(Int_t module=1; module<6; module++) {
87 for(Int_t column=1; column<57; column++) {
88 for(Int_t row=1; row<65; row++) {
3a429efa 89 if (flag == 1) {
83a8ef25 90 // Decalibration:
91 // Spread calibration coefficients uniformly with
92 // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
93 // and pedestals 0.005 +-10%
94 fADCchanelEmc =rn.Uniform(0.00075,0.00375);
95 fADCpedestalEmc=rn.Uniform(0.0045,0.0055);
96 }
97 calibda->SetADCchannelEmc (module,column,row,fADCchanelEmc);
98 calibda->SetADCpedestalEmc(module,column,row,fADCpedestalEmc);
99 }
100 }
101 }
102
103 //Store calibration data into database
16b8ada8 104
105 AliCDBMetaData md;
106 md.SetComment(objFormat);
107 md.SetBeamPeriod(beamPeriod);
108 md.SetResponsible("Boris Polichtchouk");
109
110 AliCDBId id("PHOS/Calib/GainFactors_and_Pedestals",firstRun,lastRun);
83a8ef25 111
16b8ada8 112 AliCDBManager* man = AliCDBManager::Instance();
113 AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
114 loc->Put(calibda, id, &md);
83a8ef25 115
83a8ef25 116}
3a429efa 117
118//------------------------------------------------------------------------
18fdb171 119void GetCC(Int_t flag=0)
3a429efa 120{
121 // Read calibration coefficients into the Calibration DB
122 // Arguments:
123 // flag=0: all calibration coefficients are equal
124 // flag=1: all calibration coefficients random (decalibration)
125 // Author: Yuri.Kharlov at cern.ch
126
127 TString DBFolder;
3a429efa 128
129 if (flag == 0) {
16b8ada8 130 DBFolder ="local://InitCalibDB";
3a429efa 131 }
132 else if (flag == 1) {
18fdb171 133 DBFolder ="local://DeCalibDB";
3a429efa 134 }
16b8ada8 135
18fdb171 136 AliPHOSCalibData* clb = (AliPHOSCalibData*)
137 (AliCDBManager::Instance()
138 ->GetStorage(DBFolder.Data())
139 ->Get("PHOS/Calib/GainFactors_and_Pedestals",
140 gAlice->GetRunNumber())->GetObject());
3a429efa 141
142 static const Int_t nMod = 5;
143 static const Int_t nCol = 56;
144 static const Int_t nRow = 64;
145
146 TH2F *hPed[nMod], *hGain[nMod];
147 TCanvas *cPed = new TCanvas("cPed" ,"Pedestals" , 10,10,400,800);
148 TCanvas *cGain = new TCanvas("cGain","Gain factors",410,10,400,800);
149 cPed ->Divide(1,5);
150 cGain->Divide(1,5);
151
152 for (Int_t module=1; module<=nMod; module++) {
153 TString namePed="hPed";
154 namePed+=module;
155 TString titlePed="Pedestals in module ";
156 titlePed+=module;
157 hPed[module-1] = new TH2F(namePed.Data(),titlePed.Data(),
158 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
159
160 TString nameGain="hGain";
161 nameGain+=module;
162 TString titleGain="Gain factors in module ";
163 titleGain+=module;
164 hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(),
165 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
166
167 for (Int_t column=1; column<=nCol; column++) {
168 for (Int_t row=1; row<=nRow; row++) {
169 Float_t ped = clb->GetADCpedestalEmc(module,column,row);
170 Float_t gain = clb->GetADCchannelEmc (module,column,row);
171 hPed[module-1] ->SetBinContent(column,row,ped);
172 hGain[module-1]->SetBinContent(column,row,gain);
173 }
174 }
175 cPed ->cd(module);
176 hPed[module-1] ->Draw("lego2");
177 cGain->cd(module);
178 hGain[module-1]->Draw("lego2");
179 }
180 cPed ->Print("pedestals.eps");
181 cGain->Print("gains.eps");
182}