]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALCalibCoefs.cxx
Added #include <cassert> by request of Mateusz Ploskon
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALCalibCoefs.cxx
CommitLineData
16d3c94d 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
dfa8c64c 15/* History of cvs commits:
16 *
17* $Log$
18* Revision 1.3 2007/10/16 14:36:39 pavlinov
19* fixed code violation (almost)
20*
21* Revision 1.2 2007/09/11 19:38:15 pavlinov
22* added pi0 calibration, linearity, shower profile
23* co: warning: `$Log' is obsolescent; use ` * $Log'.
24* Revision 1.1 2007/08/08 15:58:01 hristov
25*/
0fc11500 26
16d3c94d 27
28//_________________________________________________________________________
b217491f 29// Calibration coefficients
30// The place for holding all information after calibration
31// - not only calibration coefficients.
32// For flash Adc we should keep at least ratio of high/low gains
16d3c94d 33//
34//*-- Author: Aleksei Pavlinov (WSU, Detroit, USA)
35
36#include "AliEMCALCalibCoefs.h"
37
38#include "AliRun.h"
39#include "AliEMCALCalibData.h"
40#include "AliCDBMetaData.h"
41#include "AliCDBId.h"
42#include "AliCDBEntry.h"
43#include "AliCDBManager.h"
44#include "AliCDBStorage.h"
45#include "AliEMCALGeometry.h"
46
47#include "TH1F.h"
0fc11500 48#include <TString.h>
16d3c94d 49
b217491f 50ClassImp(AliEMCALCalibCoef)
6f377f0c 51// ----------------------------------------------------------------------
b217491f 52AliEMCALCalibCoef::AliEMCALCalibCoef() : fAbsId(-1), fCc(-1), fECc(-1)
53{
54 // default constructor
55}
6f377f0c 56
57// ----------------------------------------------------------------------
b217491f 58AliEMCALCalibCoef::AliEMCALCalibCoef(const Int_t id, const Double_t c, const Double_t ec) :
59fAbsId(id), fCc(c), fECc(ec)
60{
61 // Oct 16, 2007
62}
6f377f0c 63
0fc11500 64
65ClassImp(AliEMCALCalibCoefs)
66
6f377f0c 67// ----------------------------------------------------------------------
0fc11500 68AliEMCALCalibCoefs::AliEMCALCalibCoefs() : TNamed("",""), fTable(0), fCurrentInd(0), fCalibMethod(0)
69{
b217491f 70 // default constructor
0fc11500 71}
72
6f377f0c 73// ----------------------------------------------------------------------
74AliEMCALCalibCoefs::AliEMCALCalibCoefs(const AliEMCALCalibCoefs& coefs)
75 : TNamed(coefs), fTable(coefs.fTable),
76 fCurrentInd(coefs.fCurrentInd), fCalibMethod(coefs.fCalibMethod)
77{
78 // copy constructor
79}
80
81// ----------------------------------------------------------------------
0fc11500 82AliEMCALCalibCoefs::AliEMCALCalibCoefs(const char* name, const Int_t nrow) : TNamed(name,"table of cell information") , fTable(0), fCurrentInd(0), fCalibMethod(0)
83{
b217491f 84 // Oct 16, 2007
0fc11500 85 fTable = new TObjArray(nrow);
86}
87
6f377f0c 88// ----------------------------------------------------------------------
b217491f 89void AliEMCALCalibCoefs::AddAt(AliEMCALCalibCoef* r)
16d3c94d 90{
b217491f 91 // Oct 16, 2007
92 (*fTable)[fCurrentInd] = new AliEMCALCalibCoef(*r);
0fc11500 93 fCurrentInd++;
94}
95
6f377f0c 96// ----------------------------------------------------------------------
0fc11500 97AliEMCALCalibCoefs::~AliEMCALCalibCoefs()
98{
b217491f 99 // Destructor
0fc11500 100 if(fTable) {
101 fTable->Delete();
102 delete fTable;
103 }
104}
105
6f377f0c 106// ----------------------------------------------------------------------
b217491f 107AliEMCALCalibCoef* AliEMCALCalibCoefs::GetTable(Int_t i) const
0fc11500 108{
b217491f 109 // Oct 16, 2007
110 return (AliEMCALCalibCoef*)fTable->At(i);
0fc11500 111}
112
6f377f0c 113// ----------------------------------------------------------------------
0fc11500 114// Get initial Calib Data from DB
115AliEMCALCalibCoefs* AliEMCALCalibCoefs::GetCalibTableFromDb(const char *tn, AliEMCALCalibData **calData)
116{
117 //
118 // See ~/macros/ALICE/sim.C for choice of CDB
119 // Get calib. table which was used than calculated rec.points
120 //
121 static char *calibType = "EMCAL/Calib/*";
122 static char *calibTypeData = "EMCAL/Calib/Data";
123 // Initial cc
124 calData[0] = 0;
125
126 AliCDBManager* man = AliCDBManager::Instance();
127 AliCDBStorage* specificStorage = man->GetSpecificStorage(calibType);
128
16d3c94d 129 AliEMCALCalibData* caldata = (AliEMCALCalibData*)
0fc11500 130 specificStorage->Get(calibTypeData, gAlice->GetRunNumber())->GetObject();
16d3c94d 131 if(caldata == 0) return 0;
132
0fc11500 133 AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
134
135 AliEMCALCalibCoefs *tab = new AliEMCALCalibCoefs(tn,g->GetNCells());
16d3c94d 136 tab->SetCalibMethod(AliEMCALCalibCoefs::kMC);
137
16d3c94d 138 for(Int_t id=0; id<g->GetNCells(); id++){
139 Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0, iphiCell=0, ietaCell=0;
140 g->GetCellIndex(id, nSupMod, nModule, nIphi, nIeta);
141 g->GetCellPhiEtaIndexInSModule(nSupMod, nModule, nIphi, nIeta, iphiCell, ietaCell);
142
b217491f 143 AliEMCALCalibCoef r;
144 r.fAbsId = id;
145 r.fCc = caldata->GetADCchannel(nSupMod, ietaCell, iphiCell); // column(ietaCell) : row(iphiCell)
146 r.fECc = 0.0;
16d3c94d 147
148 tab->AddAt(&r);
149 }
0fc11500 150 // tab->Purge();
16d3c94d 151 tab->SetCalibMethod(AliEMCALCalibCoefs::kPI0);
0fc11500 152 calData[0] = caldata;
153
154 printf("\n <I> AliEMCALCalibCoefs::GetCalibTableFromDb \n name |%s| title |%s| | storage |%s|\n",
155 caldata->GetName(), caldata->GetTitle(), specificStorage->GetURI().Data());
16d3c94d 156
157 return tab;
158}
159
6f377f0c 160// ----------------------------------------------------------------------
16d3c94d 161TH1F* AliEMCALCalibCoefs::GetHistOfCalibTableFromDb(const char *tn)
162{
163 // First SM only
0fc11500 164 AliEMCALCalibData *calData[1]; // unused here
16d3c94d 165
0fc11500 166 AliEMCALCalibCoefs* tab = GetCalibTableFromDb(tn, calData);
16d3c94d 167 if(tab==0) return 0;
168
b217491f 169 TH1F *h = new TH1F("hCCfirst", " fCc first (in MeV)", 70, 12., 19.);
170 AliEMCALCalibCoef *r;
0fc11500 171 for(Int_t i=0; i<tab->GetSize(); i++){
16d3c94d 172 r = tab->GetTable(i);
173 if(i>=1152) break;
b217491f 174 h->Fill(r->fCc*1000.); // GEV ->MeV
16d3c94d 175 }
176 delete tab;
177 return h;
178}
179
6f377f0c 180// ----------------------------------------------------------------------
0fc11500 181AliEMCALCalibData* AliEMCALCalibCoefs::GetCalibTableForDb(const AliEMCALCalibCoefs *tab, const char* dbLocation,
182const char* coment)
183{
0fc11500 184 // See EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
185 // Define and save to CDB
b217491f 186 printf("<I> AliEMCALCalibCoefs::GetCalibTableForDb started \n");
0fc11500 187 AliEMCALCalibData* caldata=0;
188 if(tab==0) return caldata;
189
190 Int_t firstRun = 0;
191 Int_t lastRun = 10;
192 Int_t beamPeriod = 1;
193 char* objFormat = "";
194 caldata = new AliEMCALCalibData("EMCAL");
195 caldata->SetTitle(coment);
196
197 AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
198
199 for(int id=0; id<tab->GetSize(); id++){
200 Float_t ped=0.;
201
202 Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0, iphiCell=0, ietaCell=0;
203 g->GetCellIndex(id, nSupMod, nModule, nIphi, nIeta);
204 g->GetCellPhiEtaIndexInSModule(nSupMod, nModule, nIphi, nIeta, iphiCell, ietaCell);
205
b217491f 206 AliEMCALCalibCoef *r = tab->GetTable(id);
0fc11500 207 // ietaCell - column; iphiCell - row
b217491f 208 caldata->SetADCchannel (nSupMod, ietaCell, iphiCell, r->fCc);
0fc11500 209 caldata->SetADCpedestal(nSupMod, ietaCell, iphiCell, ped);
210 }
211 printf("<I> Fill AliEMCALCalibData table \n");
212 //Store calibration data into database
213
214 AliCDBMetaData md;
215 md.SetComment(objFormat);
216 md.SetBeamPeriod(beamPeriod);
217 md.SetResponsible("Aleksei Pavlinov");
218
219 AliCDBManager* man = AliCDBManager::Instance();
220 if(man == 0) {
221 printf("<E> AliEMCALCalibCoefs::GetCalibTableForDb : define AliCDBManager, NO saving !! \n");
222 } else {
223 printf("<I> AliCDBManager %p \n", man);
224 AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun); // create in EMCAL/Calib/Data DBFolder
b217491f 225 TString dBFolder(dbLocation);
226 AliCDBStorage* loc = man->GetStorage(dBFolder.Data());
0fc11500 227 loc->Put(caldata, id, &md);
228 }
229
230 return caldata;
231}
232
6f377f0c 233// ----------------------------------------------------------------------
b217491f 234AliEMCALCalibCoef *AliEMCALCalibCoefs::GetRow(const int absId)
16d3c94d 235{
b217491f 236 // Oct 16, 2007
237 AliEMCALCalibCoef *r=0;
0fc11500 238 for(int id=0; id<fTable->GetSize(); id++){
16d3c94d 239 r = GetTable(id);
b217491f 240 if(r->fAbsId == absId) return r;
16d3c94d 241 }
242 return 0;
243}
244
6f377f0c 245// ----------------------------------------------------------------------
16d3c94d 246void AliEMCALCalibCoefs::PrintTable()
247{
b217491f 248 // Oct 16, 2007
0fc11500 249 printf(" Table : %s : nrows %i \n", GetName(), int(fTable->GetSize()));
250 for(int i=0; i<fTable->GetSize(); i++) PrintTable(i);
16d3c94d 251}
252
6f377f0c 253// ----------------------------------------------------------------------
16d3c94d 254void AliEMCALCalibCoefs::PrintTable(const Int_t i)
255{
b217491f 256 // Oct 16, 2007
0fc11500 257 if(i>=fTable->GetSize()) return;
16d3c94d 258 printf("row %i \n", i);
259 PrintRec(GetTable(i));
260}
261
6f377f0c 262// ----------------------------------------------------------------------
b217491f 263void AliEMCALCalibCoefs::PrintRec(AliEMCALCalibCoef* r)
16d3c94d 264{
b217491f 265 // Oct 16, 2007
16d3c94d 266 if(r==0) return;
b217491f 267 printf(" abs Id %5.5i fCc %7.6f fECc %7.6f \n", r->fAbsId, r->fCc, r->fECc);
16d3c94d 268}