changing to AMANDA protocol version 2
[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 **************************************************************************/
15
0fc11500 16/* $Log$co: warning: `/* $Log' is obsolescent; use ` * $Log'.
17
18 * Revision 1.1 2007/08/08 15:58:01 hristov
19 * */
20
16d3c94d 21
22//_________________________________________________________________________
23// Calibration coefficients
24//
25//*-- Author: Aleksei Pavlinov (WSU, Detroit, USA)
26
27#include "AliEMCALCalibCoefs.h"
28
29#include "AliRun.h"
30#include "AliEMCALCalibData.h"
31#include "AliCDBMetaData.h"
32#include "AliCDBId.h"
33#include "AliCDBEntry.h"
34#include "AliCDBManager.h"
35#include "AliCDBStorage.h"
36#include "AliEMCALGeometry.h"
37
38#include "TH1F.h"
0fc11500 39#include <TString.h>
16d3c94d 40
0fc11500 41ClassImp(calibCoef)
16d3c94d 42
0fc11500 43calibCoef::calibCoef() : absId(-1), cc(-1), eCc(-1)
44{ }
45calibCoef::calibCoef(const Int_t id, const Double_t c, const Double_t ec) :
46absId(id), cc(c), eCc(ec)
47{}
48// ----------------------------------------------------------------------
49
50ClassImp(AliEMCALCalibCoefs)
51
52AliEMCALCalibCoefs::AliEMCALCalibCoefs() : TNamed("",""), fTable(0), fCurrentInd(0), fCalibMethod(0)
53{
54}
55
56AliEMCALCalibCoefs::AliEMCALCalibCoefs(const char* name, const Int_t nrow) : TNamed(name,"table of cell information") , fTable(0), fCurrentInd(0), fCalibMethod(0)
57{
58 fTable = new TObjArray(nrow);
59}
60
61void AliEMCALCalibCoefs::AddAt(calibCoef* r)
16d3c94d 62{
0fc11500 63 (*fTable)[fCurrentInd] = new calibCoef(*r);
64 fCurrentInd++;
65}
66
67AliEMCALCalibCoefs::~AliEMCALCalibCoefs()
68{
69 if(fTable) {
70 fTable->Delete();
71 delete fTable;
72 }
73}
74
75calibCoef* AliEMCALCalibCoefs::GetTable(Int_t i) const
76{
77 return (calibCoef*)fTable->At(i);
78}
79
80
81// Get initial Calib Data from DB
82AliEMCALCalibCoefs* AliEMCALCalibCoefs::GetCalibTableFromDb(const char *tn, AliEMCALCalibData **calData)
83{
84 //
85 // See ~/macros/ALICE/sim.C for choice of CDB
86 // Get calib. table which was used than calculated rec.points
87 //
88 static char *calibType = "EMCAL/Calib/*";
89 static char *calibTypeData = "EMCAL/Calib/Data";
90 // Initial cc
91 calData[0] = 0;
92
93 AliCDBManager* man = AliCDBManager::Instance();
94 AliCDBStorage* specificStorage = man->GetSpecificStorage(calibType);
95
16d3c94d 96 AliEMCALCalibData* caldata = (AliEMCALCalibData*)
0fc11500 97 specificStorage->Get(calibTypeData, gAlice->GetRunNumber())->GetObject();
16d3c94d 98 if(caldata == 0) return 0;
99
0fc11500 100 AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
101
102 AliEMCALCalibCoefs *tab = new AliEMCALCalibCoefs(tn,g->GetNCells());
16d3c94d 103 tab->SetCalibMethod(AliEMCALCalibCoefs::kMC);
104
16d3c94d 105 for(Int_t id=0; id<g->GetNCells(); id++){
106 Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0, iphiCell=0, ietaCell=0;
107 g->GetCellIndex(id, nSupMod, nModule, nIphi, nIeta);
108 g->GetCellPhiEtaIndexInSModule(nSupMod, nModule, nIphi, nIeta, iphiCell, ietaCell);
109
110 calibCoef r;
111 r.absId = id;
0fc11500 112 r.cc = caldata->GetADCchannel(nSupMod, ietaCell, iphiCell); // column(ietaCell) : row(iphiCell)
16d3c94d 113 r.eCc = 0.0;
114
115 tab->AddAt(&r);
116 }
0fc11500 117 // tab->Purge();
16d3c94d 118 tab->SetCalibMethod(AliEMCALCalibCoefs::kPI0);
0fc11500 119 calData[0] = caldata;
120
121 printf("\n <I> AliEMCALCalibCoefs::GetCalibTableFromDb \n name |%s| title |%s| | storage |%s|\n",
122 caldata->GetName(), caldata->GetTitle(), specificStorage->GetURI().Data());
16d3c94d 123
124 return tab;
125}
126
127TH1F* AliEMCALCalibCoefs::GetHistOfCalibTableFromDb(const char *tn)
128{
129 // First SM only
0fc11500 130 AliEMCALCalibData *calData[1]; // unused here
16d3c94d 131
0fc11500 132 AliEMCALCalibCoefs* tab = GetCalibTableFromDb(tn, calData);
16d3c94d 133 if(tab==0) return 0;
134
135 TH1F *h = new TH1F("hCCfirst", " cc first (in MeV)", 70, 12., 19.);
136 calibCoef *r;
0fc11500 137 for(Int_t i=0; i<tab->GetSize(); i++){
16d3c94d 138 r = tab->GetTable(i);
139 if(i>=1152) break;
0fc11500 140 h->Fill(r->cc*1000.); // GEV ->MeV
16d3c94d 141 }
142 delete tab;
143 return h;
144}
145
0fc11500 146AliEMCALCalibData* AliEMCALCalibCoefs::GetCalibTableForDb(const AliEMCALCalibCoefs *tab, const char* dbLocation,
147const char* coment)
148{
149 printf("<I> AliEMCALCalibCoefs::GetCalibTableForDb started \n");
150 // See EMCAL/macros/CalibrationDB/AliEMCALSetCDB.C
151 // Define and save to CDB
152 AliEMCALCalibData* caldata=0;
153 if(tab==0) return caldata;
154
155 Int_t firstRun = 0;
156 Int_t lastRun = 10;
157 Int_t beamPeriod = 1;
158 char* objFormat = "";
159 caldata = new AliEMCALCalibData("EMCAL");
160 caldata->SetTitle(coment);
161
162 AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
163
164 for(int id=0; id<tab->GetSize(); id++){
165 Float_t ped=0.;
166
167 Int_t nSupMod=0, nModule=0, nIphi=0, nIeta=0, iphiCell=0, ietaCell=0;
168 g->GetCellIndex(id, nSupMod, nModule, nIphi, nIeta);
169 g->GetCellPhiEtaIndexInSModule(nSupMod, nModule, nIphi, nIeta, iphiCell, ietaCell);
170
171 calibCoef *r = tab->GetTable(id);
172 // ietaCell - column; iphiCell - row
173 caldata->SetADCchannel (nSupMod, ietaCell, iphiCell, r->cc);
174 caldata->SetADCpedestal(nSupMod, ietaCell, iphiCell, ped);
175 }
176 printf("<I> Fill AliEMCALCalibData table \n");
177 //Store calibration data into database
178
179 AliCDBMetaData md;
180 md.SetComment(objFormat);
181 md.SetBeamPeriod(beamPeriod);
182 md.SetResponsible("Aleksei Pavlinov");
183
184 AliCDBManager* man = AliCDBManager::Instance();
185 if(man == 0) {
186 printf("<E> AliEMCALCalibCoefs::GetCalibTableForDb : define AliCDBManager, NO saving !! \n");
187 } else {
188 printf("<I> AliCDBManager %p \n", man);
189 AliCDBId id("EMCAL/Calib/Data",firstRun,lastRun); // create in EMCAL/Calib/Data DBFolder
190 TString DBFolder(dbLocation);
191 AliCDBStorage* loc = man->GetStorage(DBFolder.Data());
192 loc->Put(caldata, id, &md);
193 }
194
195 return caldata;
196}
197
16d3c94d 198calibCoef *AliEMCALCalibCoefs::GetRow(const int absId)
199{
200 calibCoef *r=0;
0fc11500 201 for(int id=0; id<fTable->GetSize(); id++){
16d3c94d 202 r = GetTable(id);
203 if(r->absId == absId) return r;
204 }
205 return 0;
206}
207
208void AliEMCALCalibCoefs::PrintTable()
209{
0fc11500 210 printf(" Table : %s : nrows %i \n", GetName(), int(fTable->GetSize()));
211 for(int i=0; i<fTable->GetSize(); i++) PrintTable(i);
16d3c94d 212}
213
214void AliEMCALCalibCoefs::PrintTable(const Int_t i)
215{
0fc11500 216 if(i>=fTable->GetSize()) return;
16d3c94d 217 printf("row %i \n", i);
218 PrintRec(GetTable(i));
219}
220
221void AliEMCALCalibCoefs::PrintRec(calibCoef* r)
222{
223 if(r==0) return;
224 printf(" abs Id %5.5i cc %7.6f eCc %7.6f \n", r->absId, r->cc, r->eCc);
225}