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 | |
f162be9a |
24 | static const Int_t nMod = 5; |
25 | static const Int_t nCol = 56; |
26 | static const Int_t nRow = 64; |
18fdb171 |
27 | |
83a8ef25 |
28 | void AliPHOSSetCDB() |
29 | { |
18fdb171 |
30 | TControlBar *menu = new TControlBar("vertical","PHOS CDB"); |
31 | menu->AddButton("Help to run PHOS CDB","Help()", |
6404864b |
32 | "Explains how to use PHOS CDB menus"); |
5195577f |
33 | menu->AddButton("Create ideal calibration","SetCC(0)", |
6404864b |
34 | "Set equal CC"); |
5195577f |
35 | menu->AddButton("Create full decalibration","SetCC(1)", |
6404864b |
36 | "Set random decalibration CC"); |
5195577f |
37 | menu->AddButton("Create residual decalibration","SetCC(2)", |
e2e977c3 |
38 | "Set residual decalibration calibration coefficients"); |
39 | |
5195577f |
40 | menu->AddButton("Read ideal calibration","GetCC(0)", |
6404864b |
41 | "Read equal calibration coefficients"); |
5195577f |
42 | menu->AddButton("Read full decalibration","GetCC(1)", |
18fdb171 |
43 | "Read random decalibration calibration coefficients"); |
5195577f |
44 | menu->AddButton("Read residual calibration","GetCC(2)", |
e2e977c3 |
45 | "Read residial calibration coefficients"); |
6404864b |
46 | menu->AddButton("Exit","gApplication->Terminate(0)","Quit aliroot session"); |
18fdb171 |
47 | menu->Show(); |
83a8ef25 |
48 | } |
49 | |
5195577f |
50 | //----------------------------------------------------------------------- |
18fdb171 |
51 | void Help() |
83a8ef25 |
52 | { |
6404864b |
53 | TString string="\nSet calibration parameters and write them into ALICE OCDB:"; |
54 | string += "\n\tPress button \"Equal CC\" to create equal calibration coefficients;"; |
55 | string += "\n\tPress button \"Full decalibration\" to create \n\t random calibration coefficients with 20\% spread \n\t to imitate fully decalibrated detector;"; |
56 | string += "\n\tPress button \"Residual decalibration\" to create \n\t random calibration coefficients with +-2\% spread\n\t to imitate decalibrated detector after initial calibration.\n"; |
57 | printf("%s",string.Data()); |
83a8ef25 |
58 | } |
3a429efa |
59 | |
83a8ef25 |
60 | //------------------------------------------------------------------------ |
18fdb171 |
61 | void SetCC(Int_t flag=0) |
83a8ef25 |
62 | { |
63 | // Writing calibration coefficients into the Calibration DB |
64 | // Arguments: |
65 | // flag=0: all calibration coefficients are equal |
f162be9a |
66 | // flag=1: decalibration coefficients |
67 | // flag=2: calibration coefficients equal to inverse decalibration ones |
3a429efa |
68 | // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch) |
83a8ef25 |
69 | |
70 | TString DBFolder; |
71 | Int_t firstRun = 0; |
f162be9a |
72 | Int_t lastRun = 0; |
83a8ef25 |
73 | Int_t beamPeriod = 1; |
18fdb171 |
74 | char* objFormat = ""; |
83a8ef25 |
75 | |
69d5d19c |
76 | AliPHOSCalibData* cdb = 0; |
77 | |
83a8ef25 |
78 | if (flag == 0) { |
5195577f |
79 | // Ideal calibration with all channels at nominal value 0.005 |
16b8ada8 |
80 | DBFolder ="local://InitCalibDB"; |
83a8ef25 |
81 | firstRun = 0; |
c87f07e5 |
82 | lastRun = 999999; |
5195577f |
83 | objFormat = "PHOS ideal pedestals and ADC gain factors (5x64x56)"; |
69d5d19c |
84 | cdb = new AliPHOSCalibData(); |
85 | cdb->CreateNew(); |
83a8ef25 |
86 | } |
69d5d19c |
87 | |
83a8ef25 |
88 | else if (flag == 1) { |
5195577f |
89 | // Full decalibration is +-10% of the nominal value |
6404864b |
90 | DBFolder ="local://FullDecalibDB"; |
c87f07e5 |
91 | firstRun = 0; |
92 | lastRun = 999999; |
6404864b |
93 | objFormat = "PHOS fully decalibrated calibration coefficients (5x64x56)"; |
69d5d19c |
94 | |
95 | cdb = new AliPHOSCalibData(); |
5195577f |
96 | cdb->RandomEmc(0.045,0.055); |
6404864b |
97 | cdb->RandomCpv(0.0008,0.0016); |
83a8ef25 |
98 | } |
16b8ada8 |
99 | |
f162be9a |
100 | else if (flag == 2) { |
5195577f |
101 | // Residual decalibration is +-1% of the nominal value |
e2e977c3 |
102 | DBFolder ="local://ResidualCalibDB"; |
f162be9a |
103 | firstRun = 0; |
e2e977c3 |
104 | lastRun = 999999; |
6404864b |
105 | objFormat = "PHOS residual calibration coefficients (5x64x56)"; |
e2e977c3 |
106 | |
f162be9a |
107 | cdb = new AliPHOSCalibData(); |
5195577f |
108 | cdb->RandomEmc(0.00495,0.00505); |
e2e977c3 |
109 | cdb->RandomCpv(0.00115,0.00125); |
f162be9a |
110 | } |
111 | |
83a8ef25 |
112 | //Store calibration data into database |
16b8ada8 |
113 | |
114 | AliCDBMetaData md; |
115 | md.SetComment(objFormat); |
116 | md.SetBeamPeriod(beamPeriod); |
117 | md.SetResponsible("Boris Polichtchouk"); |
118 | |
162637e4 |
119 | AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); |
6404864b |
120 | if(gSystem->Getenv("STORAGE")){ |
121 | cout << "Setting specific storage" << endl; |
122 | AliCDBManager::Instance()->SetSpecificStorage("PHOS/*",DBFolder.Data()); |
123 | } |
83a8ef25 |
124 | |
69d5d19c |
125 | cdb->WriteEmc(firstRun,lastRun,&md); |
126 | cdb->WriteCpv(firstRun,lastRun,&md); |
6404864b |
127 | cdb->WriteEmcBadChannelsMap(firstRun,lastRun,&md); |
83a8ef25 |
128 | |
83a8ef25 |
129 | } |
3a429efa |
130 | |
131 | //------------------------------------------------------------------------ |
18fdb171 |
132 | void GetCC(Int_t flag=0) |
3a429efa |
133 | { |
134 | // Read calibration coefficients into the Calibration DB |
135 | // Arguments: |
136 | // flag=0: all calibration coefficients are equal |
f162be9a |
137 | // flag=1: decalibration coefficients |
138 | // flag=2: calibration coefficients equal to inverse decalibration ones |
3a429efa |
139 | // Author: Yuri.Kharlov at cern.ch |
140 | |
6404864b |
141 | gStyle->SetPalette(1); |
142 | gStyle->SetOptStat(0); |
3a429efa |
143 | TString DBFolder; |
f162be9a |
144 | Int_t runNumber; |
3a429efa |
145 | |
146 | if (flag == 0) { |
16b8ada8 |
147 | DBFolder ="local://InitCalibDB"; |
f162be9a |
148 | runNumber = 0; |
3a429efa |
149 | } |
150 | else if (flag == 1) { |
6404864b |
151 | DBFolder ="local://FullDecalibDB"; |
152 | runNumber = 0; |
3a429efa |
153 | } |
e2e977c3 |
154 | else if (flag == 2) { |
155 | DBFolder ="local://ResidualCalibDB"; |
156 | runNumber = 0; |
157 | } |
16b8ada8 |
158 | |
162637e4 |
159 | AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); |
6404864b |
160 | if(gSystem->Getenv("STORAGE")){ |
161 | cout << "Setting specific storage" << endl; |
162 | AliCDBManager::Instance()->SetSpecificStorage("PHOS/*",DBFolder.Data()); |
163 | } |
3a429efa |
164 | |
f162be9a |
165 | AliPHOSCalibData* clb = new AliPHOSCalibData(runNumber); |
3a429efa |
166 | |
69d5d19c |
167 | TH2::AddDirectory(kFALSE); |
168 | |
69d5d19c |
169 | TH2F* hGain[5]; |
170 | |
6404864b |
171 | TCanvas *cGain = new TCanvas("cGain","PHOS EMC Gain factors",10,10,700,500); |
172 | cGain->Divide(3,2); |
3a429efa |
173 | |
e2e977c3 |
174 | for (Int_t module=1; module<=nMod; module++) { |
3a429efa |
175 | TString nameGain="hGain"; |
176 | nameGain+=module; |
177 | TString titleGain="Gain factors in module "; |
178 | titleGain+=module; |
179 | hGain[module-1] = new TH2F(nameGain.Data(),titleGain.Data(), |
180 | nCol,1.,1.*nCol,nRow,1.,1.*nRow); |
181 | |
182 | for (Int_t column=1; column<=nCol; column++) { |
183 | for (Int_t row=1; row<=nRow; row++) { |
6404864b |
184 | Float_t gain = clb->GetADCchannelEmc (module,column,row); |
3a429efa |
185 | hGain[module-1]->SetBinContent(column,row,gain); |
186 | } |
187 | } |
3a429efa |
188 | cGain->cd(module); |
6404864b |
189 | hGain[module-1]->SetMinimum(0); |
190 | hGain[module-1]->Draw("colz"); |
3a429efa |
191 | } |
3a429efa |
192 | cGain->Print("gains.eps"); |
193 | } |