]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
set the default infinity value for run ranges, remove SM type dependency, consider...
[u/mrichter/AliRoot.git] / EMCAL / macros / CalibrationDB / AliEMCALSetCDB.C
1 // Script to create calibration parameters and store them into CDB
2 // Thre sets of calibration parameters can be created:
3 // 1) equal parameters
4 // 2) randomly distributed parameters for decalibrated detector silumations
5 // 3) gausian  distributed parameters for decalibrated detector silumations
6 // 
7 // Modified from PHOS script for EMCAL by Gustavo Conesa
8 // May 3, 2007: Modified by Aleksei Pavlinov
9
10 //.x $ALICE_ROOT/EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
11
12 #if !defined(__CINT__)
13 #include <TControlBar.h>
14 #include <TString.h>
15 #include <TRandom.h>
16 #include <TStyle.h>
17 #include <TH2.h>
18 #include <TF1.h>
19 #include <TCanvas.h>
20
21 #include "AliRun.h"
22 #include "AliEMCALCalibData.h"
23 #include "AliEMCALGeoParams.h"
24 #include "AliCDBMetaData.h"
25 #include "AliCDBId.h"
26 #include "AliCDBEntry.h"
27 #include "AliCDBManager.h"
28 #include "AliCDBStorage.h"
29 #endif
30
31
32 void AliEMCALSetCDB()
33 {
34   TControlBar *menu = new TControlBar("vertical","EMCAL CDB");
35   menu->AddButton("Help to run EMCAL CDB","Help()",
36                   "Explains how to use EMCAL CDS menus");
37   menu->AddButton("Equal CC","SetCC(0)",
38                   "Set equal calibration coefficients");
39   menu->AddButton("Random De-calibration","SetCC(1)",
40                   "Set random decalibration calibration coefficients");
41   menu->AddButton("Gaussian De-calibration","SetCC(2)",
42                   "Set gausian decalibration calibration coefficients");
43   menu->AddButton("Read equal CC","GetCC(0)",
44                   "Read initial equal calibration coefficients");
45   menu->AddButton("Read random CC","GetCC(1)",
46                   "Read random decalibration calibration coefficients");
47   menu->AddButton("Read gaussian CC","GetCC(2)",
48                   "Read gausian decalibration calibration coefficients");
49   menu->Show();
50 }
51
52 //------------------------------------------------------------------------
53 void Help()
54 {
55   char *string =
56     "\nSet calibration parameters and write them into ALICE CDB. Press button \"Equal CC\" to create equal pedestals and gain factors. Press button \"Decalibrate\" to create random pedestals and gain factors to imitate decalibrated detector\n";
57   printf(string);
58 }
59
60 //------------------------------------------------------------------------
61 void SetCC(Int_t flag=0)
62 {
63   // Writing calibration coefficients into the Calibration DB
64   // Arguments:
65   //   flag=0: all calibration coefficients are equal
66   //   flag=1: all calibration coefficients random (decalibration)
67   //   flag=2: all calibration coefficients have Gaussian random distribution (decalibration)
68   // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
69   
70   TString DBFolder;
71   Int_t firstRun   =  0; // What is this
72   Int_t lastRun    = 10;
73   Int_t beamPeriod =  1;
74   char* objFormat  = "";
75   
76   if      (flag == 0)
77   {
78     DBFolder  ="local://InitCalibDB";
79     firstRun  =  0;
80     lastRun   =  AliCDBRunRange::Infinity();
81     objFormat = "EMCAL initial gain factors and pedestals";
82   }
83   else if (flag == 1)
84   {
85     DBFolder  ="local://DeCalibDB";
86     firstRun  =  0;
87     lastRun   = AliCDBRunRange::Infinity();
88     objFormat = "EMCAL random pedestals and ADC gain factors (12x48x24)";
89   }
90   else if (flag == 2)
91   {
92     DBFolder  ="local://DeCalibDB"; // create directory DeCalibDB in current directory
93     firstRun  =  0;
94     lastRun   = AliCDBRunRange::Infinity();
95     objFormat = "EMCAL random pedestals and gausian ADC gain factors (12x48x24)";
96   }
97   
98   AliEMCALCalibData *calibda=new AliEMCALCalibData("EMCAL");
99   
100   Float_t fADCpedestal = 0.000;
101   Float_t fADCchannel  = 0.0162;  // 250 GeV / (16*1024)
102   Float_t rDecalibration  = 0.02 * fADCchannel; // 2% decalibration - just a guess
103   Float_t cc=0, ped;
104   
105   TRandom rn;
106   Int_t nSMod = AliEMCALGeoParams::fgkEMCALModules;
107   
108   for(Int_t supermodule=0; supermodule < nSMod; supermodule++)
109   {
110     Int_t nCol  = AliEMCALGeoParams::fgkEMCALCols;
111     Int_t nRow  = AliEMCALGeoParams::fgkEMCALRows;
112     
113     // Set all the channels even the known to not exist in 1/3 sm and DCAL
114     for(Int_t column=0; column< nCol; column++)
115     {
116       for(Int_t row=0; row< nRow; row++)
117       {
118         cc  = fADCchannel;
119         ped = fADCpedestal;
120         if (flag == 1)
121         {
122           // Decalibration:
123           // Spread calibration coefficients uniformly with
124           // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
125           // and pedestals 0.005 +-10%
126           //      fADCchannel  = rn.Uniform(0.00075,0.00375);
127           cc  = rn.Uniform(0.00140,0.00160);
128           ped = 0;
129         }
130         else if (flag == 2)
131         { // Gaussian
132           cc  = rn.Gaus(fADCchannel, rDecalibration);
133           ped = rn.Uniform(0.0045,0.0055);
134         }
135         
136         calibda->SetADCchannel      (supermodule,column,row, cc);
137         calibda->SetADCchannelOnline(supermodule,column,row, cc);
138         calibda->SetADCpedestal     (supermodule,column,row, ped);
139         cout<<"Set SM: "<<supermodule<<" col "<<column<<" row "<<row
140         <<" cc "<< cc <<" ped "<<ped<<endl;
141       }
142     }
143   }
144   
145   //Store calibration data into database
146   
147   AliCDBMetaData md;
148   md.SetComment(objFormat);
149   md.SetBeamPeriod(beamPeriod);
150   md.SetResponsible("Gustavo Conesa");
151   
152   AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun); // create in EMCAL/Calib/Data DBFolder
153   
154   AliCDBManager* man = AliCDBManager::Instance();
155   AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
156   loc->Put(calibda, id, &md);
157   
158 }
159
160 //------------------------------------------------------------------------
161 void GetCC(Int_t flag=0)
162 {
163   // Read calibration coefficients into the Calibration DB
164   // Arguments:
165   //   flag=0: all calibration coefficients are equal
166   //   flag=1: all calibration coefficients random (decalibration)
167   // Author: Yuri.Kharlov at cern.ch
168   
169   TString DBFolder;
170   int drawKey=2;
171   
172   if      (flag == 0)
173   {
174     DBFolder  ="local://InitCalibDB";
175   }
176   else if (flag == 1 || flag == 2)
177   {
178     //    DBFolder  ="local://DeCalibDB"; // Get DB in current folder
179     DBFolder  ="local:///data/r22b/ALICE/PROD/CALIBRATION_May_2007/PI0/DeCalibDB"; // absolute name - Aug 31, 2007
180     TString HOST(gSystem->Getenv("HOST"));
181     if(HOST.Contains("pc")) { // pdsf; May 31, 2007
182       DBFolder  ="local:///eliza5/alice/pavlinov/PROD/CALIBRATION_May_2007/PI0/10GEV/DECALIB/DeCalibDB";
183     }
184   }
185   
186   const Int_t runNumber = 0;
187   AliEMCALCalibData* clb  = (AliEMCALCalibData*)
188   (AliCDBManager::Instance()
189    ->GetStorage(DBFolder.Data())
190    ->Get("EMCAL/Calib/Data",runNumber)->GetObject());
191   
192   const Int_t nSMod = AliEMCALGeoParams::fgkEMCALModules;
193   Int_t nCC   = 0;
194   
195   TH2F *hPed[nSMod], *hGain[nSMod], *hGainOnline[nSMod];
196   TH1F *hCCSum    = new TH1F("hCCSum"," CC summary (in MeV) ", 200, 0.0, 20.);
197   TH1F *hCCOnSum  = new TH1F("hCCSumOn"," CC online summary (in MeV) ", 200, 0.0, 20.);
198   TH1F *hPedSum   = new TH1F("hPedSum"," pedestal summary (in MeV) ", 100, 4., 6.);
199   
200   TCanvas *cPed =0, *cGain =0, *cGainOn =0,
201   TCanvas *cPed2=0, *cGain2=0, *cGainOn2=0;
202   TCanvas *cPed3=0, *cGain3=0, *cGainOn3=0;
203   TCanvas *cPed4=0, *cGain4=0, *cGainOn4=0;
204   
205   if(drawKey>1)
206   {
207     cPed     = new TCanvas("cPed" ,"Pedestals Mod 0-5"   , 10,10,400,800);
208     cGain    = new TCanvas("cGain","Gain factors Mod 0-5", 410,10,400,800);
209     cGainOn  = new TCanvas("cGainOn","Gain online factors Mod 0-5", 410,10,400,800);
210     cPed    ->Divide(2,3);
211     cGain   ->Divide(2,3);
212     cGainOn ->Divide(2,3);
213     
214     cPed2    = new TCanvas("cPed2","Pedestals SMod 6-11", 10,10,400,800);
215     cGain2   = new TCanvas("cGain2","Gain factors SMod 6-11", 410,10,400,800);
216     cGainOn2 = new TCanvas("cGainOn2","Gain online factors SMod 6-11", 410,10,400,800);
217     cPed2   ->Divide(2,3);
218     cGain2  ->Divide(2,3);
219     cGainOn2->Divide(2,3);
220     
221     cPed3    = new TCanvas("cPed3","Pedestals SMod 12-17", 10,10,400,800);
222     cGain3   = new TCanvas("cGain3","Gain factors SMod 12-17", 410,10,400,800);
223     cGainOn3 = new TCanvas("cGainOn3","Gain online factors SMod 7-17", 410,10,400,800);
224     cPed3   ->Divide(2,3);
225     cGain3  ->Divide(2,3);
226     cGainOn3->Divide(2,3);
227     
228     cPed4    = new TCanvas("cPed4","Pedestals SMod 18-21", 10,10,400,400);
229     cGain4   = new TCanvas("cGain4","Gain factors SMod 18-21", 410,10,400,800);
230     cGainOn4 = new TCanvas("cGainOn4","Gain online factors SMod 18-21", 410,10,400,400);
231     cPed4   ->Divide(2,2);
232     cGain4  ->Divide(2,2);
233     cGainOn4->Divide(2,2);
234
235   }
236   
237   TCanvas *cSum   = new TCanvas("cSum" ,"summary"   , 10,10,600,800);
238   cSum->Divide(1,2);
239   
240   cout<<endl;
241   
242   for (Int_t supermodule=0; supermodule<nSMod; supermodule++)
243   {
244     Int_t nCol  = AliEMCALGeoParams::fgkEMCALCols;
245     Int_t nRow  = AliEMCALGeoParams::fgkEMCALRows;
246     
247 //    if(supermodule /2 == 5)
248 //    nRow = nRow/2;
249 //    if(supermodule > 11)
250 //    nCol  = nCol*2/3;
251     
252     TString namePed="hPed";
253     namePed+=supermodule;
254     TString titlePed="Pedestals in supermodule ";
255     titlePed+=supermodule;
256     hPed[supermodule] = new TH2F(namePed.Data(),titlePed.Data(),
257                                  nCol,1.,1.*nCol,nRow,1.,1.*nRow);
258     
259     TString nameGain="hGain";
260     TString nameGainOnline="hGainOnline";
261     nameGain+=supermodule;
262     nameGainOnline+=supermodule;
263     TString titleGain="Gain factors in supermodule ";
264     titleGain+=supermodule;
265     TString titleGainOnline="Gain online factors in supermodule ";
266     titleGainOnline+=supermodule;
267     hGain      [supermodule] = new TH2F(nameGain.Data(),titleGain.Data(),
268                                         nCol,1.,1.*nCol,nRow,1.,1.*nRow);
269     hGainOnline[supermodule] = new TH2F(nameGainOnline.Data(),titleGainOnline.Data(),
270                                         nCol,1.,1.*nCol,nRow,1.,1.*nRow);
271     for (Int_t column=0; column<nCol; column++)
272     {
273       for (Int_t row=0; row<nRow; row++)
274       {
275         Float_t ped    = clb->GetADCpedestal     (supermodule,column,row);
276         Float_t gainOn = clb->GetADCchannelOnline(supermodule,column,row);
277         Float_t gain   = clb->GetADCchannel      (supermodule,column,row);
278         //cout<<"Get SM: "<<supermodule<<" col "<<column<<" row "<<row
279         //<<" chan "<<gain<<endl;
280         hPed       [supermodule]->SetBinContent(column+1,row+1,ped*1.e+3);  // in mev
281         hGain      [supermodule]->SetBinContent(column+1,row+1,gain*1.e+3); // in mev
282         hGainOnline[supermodule]->SetBinContent(column+1,row+1,gain*1.e+3); // in mev
283         
284         hPedSum ->Fill(ped   *1.e+3);
285         hCCSum  ->Fill(gain  *1.e+3);
286         hCCOnSum->Fill(gainOn*1.e+3);
287         
288         nCC++;
289       }
290     }
291     cout<<" Fill cc for SM "<< supermodule << " nCC "<< nCC << endl;
292     
293     if(drawKey>1)
294     {
295       if(supermodule < 6)
296       {
297         cPed ->cd(supermodule+1);
298         hPed[supermodule]->Draw("lego2");
299         cGain->cd(supermodule+1);
300         hGain[supermodule]->Draw("lego2");
301         cGainOn->cd(supermodule+1);
302         hGainOnline[supermodule]->Draw("lego2");
303       }
304       else if(supermodule < 12)
305       {
306         cPed2 ->cd(supermodule-5);
307         hPed[supermodule]->Draw("lego2");
308         cGain2->cd(supermodule-5);
309         hGain[supermodule]->Draw("lego2");
310         cGainOn2->cd(supermodule-5);
311         hGainOnline[supermodule]->Draw("lego2");
312       }
313       else if(supermodule < 18)
314       {
315         cPed3 ->cd(supermodule-11);
316         hPed[supermodule]->Draw("lego2");
317         cGain3->cd(supermodule-11);
318         hGain[supermodule]->Draw("lego2");
319         cGainOn3->cd(supermodule-11);
320         hGainOnline[supermodule]->Draw("lego2");
321       }
322       else
323       {
324         cPed4 ->cd(supermodule-17);
325         hPed[supermodule]->Draw("lego2");
326         cGain4->cd(supermodule-17);
327         hGain[supermodule]->Draw("lego2");
328         cGainOn4->cd(supermodule-17);
329         hGainOnline[supermodule]->Draw("lego2");
330       }
331     }
332   }
333   cout << " Get "<<nCC<<" calibration coeffs"<<endl;
334   
335   cSum->cd(1);
336   gStyle->SetOptFit(111);
337   hCCSum->Fit("gaus");
338   hCCSum->SetLineWidth(2);
339   hCCSum->GetFunction("gaus")->SetLineColor(2);
340   
341   cSum->cd(2);
342   hPedSum->Draw();
343   hPedSum->SetLineWidth(2);
344   
345   cSum->Update();
346   
347   if(drawKey>1)
348   {
349    cPed   ->Print("pedestals_SM_0_6.eps");
350    cGain  ->Print("gains_SM_0_5.eps");
351    cPed2  ->Print("pedestals_SM_6_11.eps");
352    cGain2 ->Print("gains_SM_6_11.eps");
353   }
354   
355 }