]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
Correct to agree with ALICE numbering scheme, change name of storage directory from...
[u/mrichter/AliRoot.git] / EMCAL / macros / CalibrationDB / AliEMCALSetCDB.C
1
2 // Script to create calibration parameters and store them into CDB
3 // Two sets of calibration parameters can be created:
4 // 1) equal parameters
5 // 2) randomly distributed parameters for decalibrated detector silumations
6 // Modified from PHOS script for EMCAL by Gustavo Conesa
7
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 "AliEMCALCalibData.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
25 void AliEMCALSetCDB()
26 {
27   TControlBar *menu = new TControlBar("vertical","EMCAL CDB");
28   menu->AddButton("Help to run EMCAL CDB","Help()",
29                   "Explains how to use EMCAL 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();
39 }
40
41 //------------------------------------------------------------------------
42 void Help()
43 {
44   char *string =
45     "\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";
46   printf(string);
47 }
48
49 //------------------------------------------------------------------------
50 void SetCC(Int_t flag=0)
51 {
52   // Writing calibration coefficients into the Calibration DB
53   // Arguments:
54   //   flag=0: all calibration coefficients are equal
55   //   flag=1: all calibration coefficients random (decalibration)
56   // Author: Boris Polishchuk (Boris.Polichtchouk at cern.ch)
57
58   TString DBFolder;
59   Int_t firstRun   =  0;
60   Int_t lastRun    = 10;
61   Int_t beamPeriod =  1;
62   char* objFormat  = "";
63
64   if      (flag == 0) {
65     DBFolder  ="local://InitCalibDB";
66     firstRun  =  0;
67     lastRun   =  0;
68     objFormat = "EMCAL initial gain factors and pedestals";
69   }
70   else if (flag == 1) {
71     DBFolder  ="local://DeCalibDB";
72     firstRun  =  0;
73     lastRun   = 12;
74     objFormat = "EMCAL random pedestals and ADC gain factors (12x48x24)";
75   }
76   
77   AliEMCALCalibData *calibda=new AliEMCALCalibData("EMCAL");
78   
79   Float_t fADCpedestal = 0.009;
80   Float_t fADCchannel  = 0.00305;
81
82   TRandom rn;
83   Int_t nSMod  = 12;
84   Int_t nCol   = 48;
85   Int_t nRow   = 24;
86   Int_t nRow2  = 12; //Modules 11 and 12 are half modules
87
88   for(Int_t supermodule=0; supermodule < nSMod; supermodule++) {
89     for(Int_t column=0; column< nCol; column++) {
90       if(supermodule >= 10)
91         nRow = nRow2;
92       for(Int_t row=0; row< nRow; row++) {
93         if (flag == 1) {
94           // Decalibration:
95           // Spread calibration coefficients uniformly with
96           // Cmax/Cmin = 5, (Cmax-Cmin)/2 = 0.0015
97           // and pedestals 0.005 +-10%
98           fADCchannel  =rn.Uniform(0.00075,0.00375);
99           fADCpedestal=rn.Uniform(0.0045,0.0055);
100         }
101         calibda->SetADCchannel (supermodule,column,row,fADCchannel);
102         calibda->SetADCpedestal(supermodule,column,row,fADCpedestal);
103         cout<<"Set SM: "<<supermodule<<" col "<<column<<" row "<<row
104             <<" chan "<<fADCchannel<<" ped fADCpedestal"<<endl;
105       }
106     }
107   }
108
109   //Store calibration data into database
110   
111   AliCDBMetaData md;
112   md.SetComment(objFormat);
113   md.SetBeamPeriod(beamPeriod);
114   md.SetResponsible("Boris Polichtchouk");
115   
116   AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun);
117
118   AliCDBManager* man = AliCDBManager::Instance();  
119   AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
120   loc->Put(calibda, id, &md);
121
122 }
123
124 //------------------------------------------------------------------------
125 void GetCC(Int_t flag=0)
126 {
127   // Read calibration coefficients into the Calibration DB
128   // Arguments:
129   //   flag=0: all calibration coefficients are equal
130   //   flag=1: all calibration coefficients random (decalibration)
131   // Author: Yuri.Kharlov at cern.ch
132
133   TString DBFolder;
134
135   if      (flag == 0) {
136     DBFolder  ="local://InitCalibDB";
137   }
138   else if (flag == 1) {
139     DBFolder  ="local://DeCalibDB";
140   }
141
142   AliEMCALCalibData* clb  = (AliEMCALCalibData*)
143     (AliCDBManager::Instance()
144      ->GetStorage(DBFolder.Data())
145      ->Get("EMCAL/Calib/Data",
146            gAlice->GetRunNumber())->GetObject());
147
148   static const Int_t nSMod = 12;
149   static const Int_t nCol  = 48;
150   Int_t nRow  = 24;
151   Int_t nRow2 = 12; //Modules 11 and 12 are half modules
152
153   TH2F *hPed[nSMod], *hGain[nSMod];
154   TCanvas *cPed   = new TCanvas("cPed" ,"Pedestals Mod 1-6"   , 10,10,400,800);
155   TCanvas *cGain  = new TCanvas("cGain","Gain factors Mod 1-6", 410,10,400,800);
156   TCanvas *cPed2  = new TCanvas("cPed2","Pedestals SMod 7-12", 10,10,400,800);
157   TCanvas *cGain2 = new TCanvas("cGain2","Gain factors SMod 7-12", 410,10,400,800);
158   cPed   ->Divide(2,3);
159   cGain  ->Divide(2,3);
160   cPed2  ->Divide(2,3);
161   cGain2 ->Divide(2,3);
162   for (Int_t supermodule=0; supermodule<nSMod; supermodule++) {
163
164     if(supermodule >= 10)
165       nRow = nRow2;
166
167     TString namePed="hPed";
168     namePed+=supermodule;
169     TString titlePed="Pedestals in supermodule ";
170     titlePed+=supermodule;
171     hPed[supermodule] = new TH2F(namePed.Data(),titlePed.Data(),
172                             nCol,1.,1.*nCol,nRow,1.,1.*nRow);
173
174     TString nameGain="hGain";
175     nameGain+=supermodule;
176     TString titleGain="Gain factors in supermodule ";
177     titleGain+=supermodule;
178     hGain[supermodule] = new TH2F(nameGain.Data(),titleGain.Data(),
179                                     nCol,1.,1.*nCol,nRow,1.,1.*nRow);
180     for (Int_t column=0; column<nCol; column++) {
181       for (Int_t row=0; row<nRow; row++) {
182         Float_t ped  = clb->GetADCpedestal(supermodule,column,row);
183         Float_t gain = clb->GetADCchannel (supermodule,column,row);
184         //cout<<"Get SM: "<<supermodule<<" col "<<column<<" row "<<row
185         //  <<" chan "<<gain<<endl;
186         hPed[supermodule] ->SetBinContent(column,row,ped);
187         hGain[supermodule]->SetBinContent(column,row,gain);
188       }
189     }
190     if(supermodule < 7){
191       cPed ->cd(supermodule);
192       hPed[supermodule] ->Draw("lego2");
193       cGain->cd(supermodule);
194       hGain[supermodule]->Draw("lego2");
195     }
196     else{
197       cPed2 ->cd(supermodule-6);
198       hPed[supermodule] ->Draw("lego2");
199       cGain2->cd(supermodule-6);
200       hGain[supermodule]->Draw("lego2");
201     }
202
203   }
204   cPed   ->Print("pedestals_SM_1_6.eps");
205   cGain  ->Print("gains_SM_1-6.eps");
206   cPed2  ->Print("pedestals_SM_7-12.eps");
207   cGain2 ->Print("gains_SM_7-12.eps");
208 }