]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
-mcompilation warning
[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 "AliCDBMetaData.h"
24 #include "AliCDBId.h"
25 #include "AliCDBEntry.h"
26 #include "AliCDBManager.h"
27 #include "AliCDBStorage.h"
28 #endif
29
30
31 void AliEMCALSetCDB()
32 {
33   TControlBar *menu = new TControlBar("vertical","EMCAL CDB");
34   menu->AddButton("Help to run EMCAL CDB","Help()",
35                   "Explains how to use EMCAL CDS menus");
36   menu->AddButton("Equal CC","SetCC(0)",
37                   "Set equal calibration coefficients");
38   menu->AddButton("Random De-calibration","SetCC(1)",
39                   "Set random decalibration calibration coefficients");
40   menu->AddButton("Gaussian De-calibration","SetCC(2)",
41                   "Set gausian decalibration calibration coefficients");
42   menu->AddButton("Read equal CC","GetCC(0)",
43                   "Read initial equal calibration coefficients");
44   menu->AddButton("Read random CC","GetCC(1)",
45                   "Read random decalibration calibration coefficients");
46   menu->AddButton("Read gaussian CC","GetCC(2)",
47                   "Read gausian decalibration calibration coefficients");
48   menu->Show();
49 }
50
51 //------------------------------------------------------------------------
52 void Help()
53 {
54   char *string =
55     "\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";
56   printf(string);
57 }
58
59 //------------------------------------------------------------------------
60 void SetCC(Int_t flag=0)
61 {
62   // Writing calibration coefficients into the Calibration DB
63   // Arguments:
64   //   flag=0: all calibration coefficients are equal
65   //   flag=1: all calibration coefficients random (decalibration)
66   //   flag=2: all calibration coefficients have Gaussian random distribution (decalibration)
67   // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
68
69   TString DBFolder;
70   Int_t firstRun   =  0; // What is this
71   Int_t lastRun    = 10;
72   Int_t beamPeriod =  1;
73   char* objFormat  = "";
74
75   if      (flag == 0) {
76     DBFolder  ="local://InitCalibDB";
77     firstRun  =  0;
78     lastRun   =  0;
79     objFormat = "EMCAL initial gain factors and pedestals";
80   }
81   else if (flag == 1) {
82     DBFolder  ="local://DeCalibDB";
83     firstRun  =  0;
84     lastRun   = 12;
85     objFormat = "EMCAL random pedestals and ADC gain factors (12x48x24)";
86   }
87   else if (flag == 2) {
88     DBFolder  ="local://DeCalibDB"; // create directory DeCalibDB in current directory
89     firstRun  =  0;
90     lastRun   = 12; // Why 12 ?
91     objFormat = "EMCAL random pedestals and gausian ADC gain factors (12x48x24)";
92   }
93   
94   AliEMCALCalibData *calibda=new AliEMCALCalibData("EMCAL");
95   
96   Float_t fADCpedestal = 0.009;
97   Float_t fADCchannel  = 0.0153;  // 250 GeV / (16*1024)
98   //  Float_t fADCchannel  = 0.00305;
99   Float_t rDecalibration  = 0.1 * fADCchannel; // 10% decalibration - just a guess
100   Float_t cc=0, ped;
101
102   TRandom rn;
103   Int_t nSMod  = 12;
104   Int_t nCol   = 48;
105   Int_t nRow   = 24;
106   Int_t nRow2  = 12; //Modules 11 and 12 are half modules
107
108   for(Int_t supermodule=0; supermodule < nSMod; supermodule++) {
109     for(Int_t column=0; column< nCol; column++) {
110       if(supermodule >= 10)
111         nRow = nRow2;
112       for(Int_t row=0; row< nRow; row++) {
113         cc  = fADCchannel;
114         ped = fADCpedestal;
115         if (flag == 1) {
116           // Decalibration:
117           // Spread calibration coefficients uniformly with
118           // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
119           // and pedestals 0.005 +-10%
120           //      fADCchannel  = rn.Uniform(0.00075,0.00375);
121           cc  = rn.Uniform(0.00140,0.00160);
122           ped = 0;
123         } else if (flag == 2) { // Gaussian
124           cc  = rn.Gaus(fADCchannel, rDecalibration);
125           ped = rn.Uniform(0.0045,0.0055);
126         }
127         calibda->SetADCchannel (supermodule,column,row, cc);
128         calibda->SetADCpedestal(supermodule,column,row, ped);
129         cout<<"Set SM: "<<supermodule<<" col "<<column<<" row "<<row
130             <<" cc "<< cc <<" ped "<<ped<<endl;
131       }
132     }
133   }
134
135   //Store calibration data into database
136   
137   AliCDBMetaData md;
138   md.SetComment(objFormat);
139   md.SetBeamPeriod(beamPeriod);
140   md.SetResponsible("Aleksei Pavlinov");
141   
142   AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun); // create in EMCAL/Calib/Data DBFolder 
143
144   AliCDBManager* man = AliCDBManager::Instance();  
145   AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
146   loc->Put(calibda, id, &md);
147
148 }
149
150 //------------------------------------------------------------------------
151 void GetCC(Int_t flag=0)
152 {
153   // Read calibration coefficients into the Calibration DB
154   // Arguments:
155   //   flag=0: all calibration coefficients are equal
156   //   flag=1: all calibration coefficients random (decalibration)
157   // Author: Yuri.Kharlov at cern.ch
158
159   TString DBFolder;
160   int drawKey=1;
161
162   if      (flag == 0) {
163     DBFolder  ="local://InitCalibDB";
164   }
165   else if (flag == 1 || flag == 2) {
166     //    DBFolder  ="local://DeCalibDB"; // Get DB in current folder
167     DBFolder  ="local:///data/r22b/ALICE/PROD/CALIBRATION_May_2007/PI0/DeCalibDB"; // absolute name - Aug 31, 2007
168     TString HOST(gSystem->Getenv("HOST"));
169     if(HOST.Contains("pc")) { // pdsf; May 31, 2007
170       DBFolder  ="local:///eliza5/alice/pavlinov/PROD/CALIBRATION_May_2007/PI0/10GEV/DECALIB/DeCalibDB";
171     }
172   }
173
174   AliEMCALCalibData* clb  = (AliEMCALCalibData*)
175     (AliCDBManager::Instance()
176      ->GetStorage(DBFolder.Data())
177      ->Get("EMCAL/Calib/Data",
178            gAlice->GetRunNumber())->GetObject());
179
180   static const Int_t nSMod = 12;
181   static const Int_t nCol  = 48;
182   Int_t nRow  = 24;
183   Int_t nRow2 = 12; //Modules 11 and 12 are half modules
184   Int_t nCC   = 0;
185
186   TH2F *hPed[nSMod], *hGain[nSMod];
187   TH1F *hCCSum = new TH1F("hCCSum"," CC summary (in MeV) ", 200, 0.0, 20.);
188   TH1F *hPedSum = new TH1F("hPedSum"," pedestal summary (in MeV) ", 100, 4., 6.);
189
190   TCanvas *cPed=0, *cGain=0, *cPed2=0, *cGain2=0;
191   if(drawKey>1) {
192     cPed   = new TCanvas("cPed" ,"Pedestals Mod 0-5"   , 10,10,400,800);
193     cGain  = new TCanvas("cGain","Gain factors Mod 0-5", 410,10,400,800);
194     cPed2  = new TCanvas("cPed2","Pedestals SMod 6-11", 10,10,400,800);
195     cGain2 = new TCanvas("cGain2","Gain factors SMod 6-11", 410,10,400,800);
196     cPed   ->Divide(2,3);
197     cGain  ->Divide(2,3);
198     cPed2  ->Divide(2,3);
199     cGain2 ->Divide(2,3);
200   }
201   TCanvas *cSum   = new TCanvas("cSum" ,"summary"   , 10,10,600,800);
202   cSum->Divide(1,2); 
203
204   cout<<endl;
205   for (Int_t supermodule=0; supermodule<nSMod; supermodule++) {
206
207     if(supermodule >= 10)
208       nRow = nRow2;
209
210     TString namePed="hPed";
211     namePed+=supermodule;
212     TString titlePed="Pedestals in supermodule ";
213     titlePed+=supermodule;
214     hPed[supermodule] = new TH2F(namePed.Data(),titlePed.Data(),
215                             nCol,1.,1.*nCol,nRow,1.,1.*nRow);
216
217     TString nameGain="hGain";
218     nameGain+=supermodule;
219     TString titleGain="Gain factors in supermodule ";
220     titleGain+=supermodule;
221     hGain[supermodule] = new TH2F(nameGain.Data(),titleGain.Data(),
222                                     nCol,1.,1.*nCol,nRow,1.,1.*nRow);
223     for (Int_t column=0; column<nCol; column++) {
224       for (Int_t row=0; row<nRow; row++) {
225         Float_t ped  = clb->GetADCpedestal(supermodule,column,row);
226         Float_t gain = clb->GetADCchannel (supermodule,column,row);
227         //cout<<"Get SM: "<<supermodule<<" col "<<column<<" row "<<row
228         //<<" chan "<<gain<<endl;
229         hPed[supermodule] ->SetBinContent(column+1,row+1,ped*1.e+3);  // in mev
230         hGain[supermodule]->SetBinContent(column+1,row+1,gain*1.e+3); // in mev
231
232         hPedSum->Fill(ped*1.e+3);
233         hCCSum->Fill(gain*1.e+3); 
234
235         nCC++;
236       }
237     }
238     cout<<" Fill cc for SM "<< supermodule << " nCC "<< nCC << endl;
239     
240     if(drawKey>1) {
241       if(supermodule < 6){
242         cPed ->cd(supermodule+1);
243         hPed[supermodule]->Draw("lego2");
244         cGain->cd(supermodule+1);
245         hGain[supermodule]->Draw("lego2");
246       }
247       else{
248         cPed2 ->cd(supermodule-5);
249         hPed[supermodule]->Draw("lego2");
250         cGain2->cd(supermodule-5);
251         hGain[supermodule]->Draw("lego2");
252       }
253     }
254
255   }
256   cout << " Get "<<nCC<<" calibration coeffs"<<endl;
257
258   cSum->cd(1);
259   gStyle->SetOptFit(111);
260   hCCSum->Fit("gaus");
261   hCCSum->SetLineWidth(2);
262   hCCSum->GetFunction("gaus")->SetLineColor(2);
263   
264   cSum->cd(2);
265   hPedSum->Draw();
266   hPedSum->SetLineWidth(2);
267
268   cSum->Update();
269
270   /*
271   cPed   ->Print("pedestals_SM_0_6.eps");
272   cGain  ->Print("gains_SM_0_5.eps");
273   cPed2  ->Print("pedestals_SM_6_11.eps");
274   cGain2 ->Print("gains_SM_6_11.eps");
275   */
276 }