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