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