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