How to Merge events (Zaida)
[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) {
50 DBFolder ="InitCalibDB";
51 firstRun = 0;
52 lastRun = 0;
53 objFormat = "PHOS initial gain factors and pedestals";
54 }
55 else if (flag == 1) {
56 DBFolder ="DeCalibDB";
57 firstRun = 0;
58 lastRun = 10;
59 objFormat = "PHOS random pedestals and ADC gain factors (5x64x56)";
60 }
61
62 // create DB directory
63 if(!gSystem->OpenDirectory(DBFolder)){
64 printf("Warning: folder %s does not exist, I will create it!",
65 DBFolder.Data());
66 TString command = "mkdir "+ DBFolder;
67 gSystem->Exec(command.Data());
68 }
69
70 AliPHOSCalibData *calibda=new AliPHOSCalibData("PHOS");
71
72 Float_t fADCpedestalEmc = 0.005;
73 Float_t fADCchanelEmc = 0.0015;
74
75 TRandom rn;
76
77 for(Int_t module=1; module<6; module++) {
78 for(Int_t column=1; column<57; column++) {
79 for(Int_t row=1; row<65; row++) {
3a429efa 80 if (flag == 1) {
83a8ef25 81 // Decalibration:
82 // Spread calibration coefficients uniformly with
83 // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
84 // and pedestals 0.005 +-10%
85 fADCchanelEmc =rn.Uniform(0.00075,0.00375);
86 fADCpedestalEmc=rn.Uniform(0.0045,0.0055);
87 }
88 calibda->SetADCchannelEmc (module,column,row,fADCchanelEmc);
89 calibda->SetADCpedestalEmc(module,column,row,fADCpedestalEmc);
90 }
91 }
92 }
93
94 //Store calibration data into database
95
96 AliCDBMetaData md("PHOS/Calib/GainFactors_and_Pedestals",
97 firstRun,lastRun,beamPeriod,
98 objFormat,
99 "B. Polishchuk",
100 "PHOS calibration");
101
102 AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
103 AliCDBStorage::Instance()->Put(calibda, md);
104 AliCDBStorage::Instance()->Delete();
105}
3a429efa 106
107//------------------------------------------------------------------------
108GetCC(Int_t flag=0)
109{
110 // Read calibration coefficients into the Calibration DB
111 // Arguments:
112 // flag=0: all calibration coefficients are equal
113 // flag=1: all calibration coefficients random (decalibration)
114 // Author: Yuri.Kharlov at cern.ch
115
116 TString DBFolder;
117 Int_t firstRun = 0;
118 Int_t lastRun = 10;
119 Int_t beamPeriod = 1;
120 char* objFormat;
121
122 if (flag == 0) {
123 DBFolder ="InitCalibDB";
124 }
125 else if (flag == 1) {
126 DBFolder ="DeCalibDB";
127 }
128 AliCDBLocal *loc = new AliCDBLocal(DBFolder.Data());
129 AliPHOSCalibData* clb = (AliPHOSCalibData*)AliCDBStorage::Instance()
130 ->Get("PHOS/Calib/GainFactors_and_Pedestals",gAlice->GetRunNumber());
131
132 static const Int_t nMod = 5;
133 static const Int_t nCol = 56;
134 static const Int_t nRow = 64;
135
136 TH2F *hPed[nMod], *hGain[nMod];
137 TCanvas *cPed = new TCanvas("cPed" ,"Pedestals" , 10,10,400,800);
138 TCanvas *cGain = new TCanvas("cGain","Gain factors",410,10,400,800);
139 cPed ->Divide(1,5);
140 cGain->Divide(1,5);
141
142 for (Int_t module=1; module<=nMod; module++) {
143 TString namePed="hPed";
144 namePed+=module;
145 TString titlePed="Pedestals in module ";
146 titlePed+=module;
147 hPed[module-1] = new TH2F(namePed.Data(),titlePed.Data(),
148 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
149
150 TString nameGain="hGain";
151 nameGain+=module;
152 TString titleGain="Gain factors in module ";
153 titleGain+=module;
154 hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(),
155 nCol,1.,1.*nCol,nRow,1.,1.*nRow);
156
157 for (Int_t column=1; column<=nCol; column++) {
158 for (Int_t row=1; row<=nRow; row++) {
159 Float_t ped = clb->GetADCpedestalEmc(module,column,row);
160 Float_t gain = clb->GetADCchannelEmc (module,column,row);
161 hPed[module-1] ->SetBinContent(column,row,ped);
162 hGain[module-1]->SetBinContent(column,row,gain);
163 }
164 }
165 cPed ->cd(module);
166 hPed[module-1] ->Draw("lego2");
167 cGain->cd(module);
168 hGain[module-1]->Draw("lego2");
169 }
170 cPed ->Print("pedestals.eps");
171 cGain->Print("gains.eps");
172}