New default calibration parameters (Yu.Kharlov)
[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
69d5d19c 66 AliPHOSCalibData* cdb = 0;
67
83a8ef25 68 if (flag == 0) {
16b8ada8 69 DBFolder ="local://InitCalibDB";
83a8ef25 70 firstRun = 0;
d53cb5cc 71 lastRun = 10;
72 objFormat = "PHOS initial pedestals and ADC gain factors (5x64x56)";
69d5d19c 73 cdb = new AliPHOSCalibData();
74 cdb->CreateNew();
83a8ef25 75 }
69d5d19c 76
83a8ef25 77 else if (flag == 1) {
18fdb171 78 DBFolder ="local://DeCalibDB";
83a8ef25 79 firstRun = 0;
80 lastRun = 10;
81 objFormat = "PHOS random pedestals and ADC gain factors (5x64x56)";
69d5d19c 82
83 cdb = new AliPHOSCalibData();
84 cdb->RandomEmc();
85 cdb->RandomCpv();
83a8ef25 86 }
16b8ada8 87
83a8ef25 88 //Store calibration data into database
16b8ada8 89
90 AliCDBMetaData md;
91 md.SetComment(objFormat);
92 md.SetBeamPeriod(beamPeriod);
93 md.SetResponsible("Boris Polichtchouk");
94
69d5d19c 95 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
96 AliCDBManager::Instance()->SetSpecificStorage("PHOS",DBFolder.Data());
83a8ef25 97
69d5d19c 98 cdb->WriteEmc(firstRun,lastRun,&md);
99 cdb->WriteCpv(firstRun,lastRun,&md);
83a8ef25 100
83a8ef25 101}
3a429efa 102
103//------------------------------------------------------------------------
18fdb171 104void GetCC(Int_t flag=0)
3a429efa 105{
106 // Read calibration coefficients into the Calibration DB
107 // Arguments:
108 // flag=0: all calibration coefficients are equal
109 // flag=1: all calibration coefficients random (decalibration)
110 // Author: Yuri.Kharlov at cern.ch
111
112 TString DBFolder;
3a429efa 113
114 if (flag == 0) {
16b8ada8 115 DBFolder ="local://InitCalibDB";
3a429efa 116 }
117 else if (flag == 1) {
18fdb171 118 DBFolder ="local://DeCalibDB";
3a429efa 119 }
16b8ada8 120
69d5d19c 121 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
d53cb5cc 122// AliCDBManager::Instance()->SetSpecificStorage("PHOS",DBFolder.Data());
69d5d19c 123
124 AliPHOSCalibData* clb = new AliPHOSCalibData(gAlice->GetRunNumber());
3a429efa 125
126 static const Int_t nMod = 5;
127 static const Int_t nCol = 56;
128 static const Int_t nRow = 64;
129
69d5d19c 130 TH2::AddDirectory(kFALSE);
131
132 TH2F* hPed[5];
133 TH2F* hGain[5];
134
135 TCanvas *cPed = new TCanvas("cPed" ,"PHOS EMC Pedestals" , 10,10,400,800);
136 TCanvas *cGain = new TCanvas("cGain","PHOS EMC Gain factors",410,10,400,800);
3a429efa 137 cPed ->Divide(1,5);
138 cGain->Divide(1,5);
139
140 for (Int_t module=1; module<=nMod; module++) {
141 TString namePed="hPed";
142 namePed+=module;
143 TString titlePed="Pedestals in module ";
144 titlePed+=module;
145 hPed[module-1] = new TH2F(namePed.Data(),titlePed.Data(),
146 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
147
148 TString nameGain="hGain";
149 nameGain+=module;
150 TString titleGain="Gain factors in module ";
151 titleGain+=module;
152 hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(),
153 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
154
155 for (Int_t column=1; column<=nCol; column++) {
156 for (Int_t row=1; row<=nRow; row++) {
157 Float_t ped = clb->GetADCpedestalEmc(module,column,row);
158 Float_t gain = clb->GetADCchannelEmc (module,column,row);
69d5d19c 159 hPed[module-1]->SetBinContent(column,row,ped);
3a429efa 160 hGain[module-1]->SetBinContent(column,row,gain);
161 }
162 }
163 cPed ->cd(module);
69d5d19c 164 hPed[module-1]->Draw("lego2");
3a429efa 165 cGain->cd(module);
166 hGain[module-1]->Draw("lego2");
167 }
168 cPed ->Print("pedestals.eps");
169 cGain->Print("gains.eps");
170}