Removing shadowed variables
[u/mrichter/AliRoot.git] / PMD / AliPMDCalibrator.cxx
CommitLineData
06810de6 1//////////////////////////////////////////////////////////////////////////////
2//
3// * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4// * *
5// * Author: The ALICE Off-line Project. *
6// * Contributors are mentioned in the code where appropriate. *
7// * *
8// * Permission to use, copy, modify and distribute this software and its *
9// * documentation strictly for non-commercial purposes is hereby granted *
10// * without fee, provided that the above copyright notice appears in all *
11// * copies and that both the copyright notice and this permission notice *
12// * appear in the supporting documentation. The authors make no claims *
13// * about the suitability of this software for any purpose. It is *
14// * provided "as is" without express or implied warranty. *
15// **************************************************************************/
16//
17//////////////////////////////////////////////////////////////////////////////
18// Author : Z. Ahamed
19
20#include "TF1.h"
21#include "TFile.h"
22#include "TObjString.h"
23#include "TROOT.h"
24#include "TClonesArray.h"
25#include "TH1F.h"
df42ab21 26#include "TObjArray.h"
06810de6 27
28// --- Standard library ---
29
30// --- AliRoot header files ---
31#include "AliLog.h"
df42ab21 32#include "AliRawReaderFile.h"
06810de6 33#include "AliPMDCalibrator.h"
34#include "AliRawReaderDate.h"
35#include "AliPMDRawStream.h"
06810de6 36#include "AliPMDCalibData.h"
df42ab21 37#include "AliPMDddldata.h"
06810de6 38#include "AliCDBManager.h"
39#include "AliCDBId.h"
40#include "AliCDBMetaData.h"
df42ab21 41#include "AliDAQ.h"
06810de6 42
43ClassImp(AliPMDCalibrator)
44
35535af7 45//const Int_t kDet = 2;
46//const Int_t kMaxSMN = 24;
47//const Int_t kMaxRow = 48;
48//const Int_t kMaxCol = 96;
06810de6 49
a48edddd 50AliPMDCalibrator::AliPMDCalibrator():
35535af7 51 fCalibGain(new AliPMDCalibData())
06810de6 52{
53 // Standard Constructor
35535af7 54 for(Int_t idet = 0; idet < kDet; idet++)
06810de6 55 {
35535af7 56 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
06810de6 57 {
35535af7 58 fHsmIso[idet][ismn] = NULL ;
59 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
06810de6 60 {
35535af7 61 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
06810de6 62 {
35535af7 63 fGainFact[idet][ismn][jrow][kcol] = 0.0;
64 fHadcIso[idet][ismn][jrow][kcol] = NULL;
06810de6 65 }
66 }
67 }
68 }
69}
70// ------------------------------------------------------------------------ //
a48edddd 71AliPMDCalibrator::AliPMDCalibrator(const AliPMDCalibrator &pmdcalibrator):
35535af7 72 fCalibGain(new AliPMDCalibData())
a48edddd 73{
35535af7 74 for(Int_t idet = 0; idet < 2; idet++)
a48edddd 75 {
35535af7 76 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
a48edddd 77 {
35535af7 78 fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
79 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
a48edddd 80 {
35535af7 81 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
a48edddd 82 {
35535af7 83 fGainFact[idet][ismn][jrow][kcol] = pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
84 fHadcIso[idet][ismn][jrow][kcol] = pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
a48edddd 85 }
86 }
87 }
88 }
06810de6 89
a48edddd 90}
91// ------------------------------------------------------------------------ //
92AliPMDCalibrator &AliPMDCalibrator::operator=(const AliPMDCalibrator &pmdcalibrator)
93{
94 if(this != &pmdcalibrator)
95 {
35535af7 96 for(Int_t idet = 0; idet < kDet; idet++)
a48edddd 97 {
35535af7 98 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
a48edddd 99 {
35535af7 100 fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
101 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
a48edddd 102 {
35535af7 103 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
a48edddd 104 {
35535af7 105 fGainFact[idet][ismn][jrow][kcol] =
106 pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
107 fHadcIso[idet][ismn][jrow][kcol] =
108 pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
a48edddd 109 }
110 }
111 }
112 }
113 }
114 return *this;
115}
116// ------------------------------------------------------------------------ //
06810de6 117AliPMDCalibrator::~AliPMDCalibrator()
118{
119 // dtor
120 if(fHsmIso) delete fHsmIso ;
121 if(fHadcIso) delete fHadcIso ;
35535af7 122 delete fCalibGain;
06810de6 123}
124// ------------------------------------------------------------------------ //
125
126void AliPMDCalibrator::Exec()
127{
128 // reads parameters and does the calibration
129 CalculateIsoCell() ;
130
131}
132// ------------------------------------------------------------------------ //
133
134void AliPMDCalibrator::Init()
135{
136 // intializes everything
137 char hname[kMaxSMN];
138 char hname24[kMaxSMN];
139 char hnameiso[120];
140 char htitle1[120];
141
35535af7 142 for(Int_t d = 0; d < kDet; d++) {
143 for(Int_t i1 = 0; i1 < kMaxSMN; i1++) {
06810de6 144 sprintf(hname,"det_%d_iso_sm_%2d",d,i1);
145 sprintf(hname24,"det_%d_iso_sm_%2d",d,i1);
146 fHsmIso[d][i1]= new TH1F(hname,hname24,100,0,1000);
147 for(Int_t j1 = 0; j1 < kMaxRow; j1++) {
148 for(Int_t k1 = 0; k1 < kMaxCol; k1++) {
149 sprintf(hnameiso,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
150 ,d,i1,j1,k1);
151 sprintf(htitle1,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
152 ,d,i1,j1,k1);
153
154 TObject *old=gDirectory->GetList()->FindObject(hnameiso);
155 if (old) gDirectory->GetList()->Remove(old);
156 fHadcIso[d][i1][j1][k1] = new TH1F(hnameiso,htitle1,100,0.,4000.);
157 }
158 }
159 }
160 }
161
162}
163
164// ------------------------------------------------------------------------ //
165
166void AliPMDCalibrator::CalculateIsoCell()
167{
168 // Calculates the ADC of isolated cell
169
df42ab21 170 TObjArray pmdddlcont;
171 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
06810de6 172 const Int_t kMaxHit = 60000;
173 const Int_t kCellNeighbour = 6;
174
175 Int_t neibx[6] = {1,0,-1,-1,0,1};
176 Int_t neiby[6] = {0,1,1,0,-1,-1};
177
178 Int_t id1,jd1; //neighbour row/col
179 Int_t countisocell = 0 ;//number of isilated cell
180 Int_t isocount; //number of neighbours with 0 signal
181 Int_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
182 Int_t ch[kDet][kMaxSMN][kMaxRow][kMaxCol];
183 Int_t maxhit;
184
185
186 Int_t det[kMaxHit],smn[kMaxHit];
187 Int_t row[kMaxHit],col[kMaxHit],sig[kMaxHit],chno[kMaxHit];
188
189 for(Int_t idet = 0; idet < kDet; idet++)
190 {
191 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
192 {
193 for(Int_t irow = 0; irow < kMaxRow; irow++)
194 {
195 for(Int_t icol = 0; icol < kMaxCol; icol++)
196 {
197 d1[idet][ismn][irow][icol] = 0;
198 ch[idet][ismn][irow][icol] = 0;
199 }
200 }
201 }
202 }
203 //accessing raw data
204 AliRawReaderFile reader(".");
205 AliPMDRawStream stream(&reader);
206 while(reader.NextEvent())
207 {
df42ab21 208 // New PMD Reader is plugged in
06810de6 209
df42ab21 210 for (Int_t iddl = 0; iddl < kDDL; iddl++)
211 {
212 reader.Select("PMD", iddl, iddl);
2332574a 213 stream.DdlData(iddl,&pmdddlcont);
df42ab21 214
215 Int_t ientries = pmdddlcont.GetEntries();
216 for (Int_t ient = 0; ient < ientries; ient++)
217 {
218 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
219
220 Int_t idet = pmdddl->GetDetector();
221 Int_t ismn = pmdddl->GetSMN();
222 //Int_t mcm = pmdddl->GetMCM();
223 Int_t ichno = pmdddl->GetChannel();
224 Int_t irow = pmdddl->GetRow();
225 Int_t icol = pmdddl->GetColumn();
226 Int_t isig = pmdddl->GetSignal();
227
228 if (isig>0)
229 {
230 d1[idet][ismn][irow][icol] = isig;
231 ch[idet][ismn][irow][icol] = ichno;
232 }
233 }
234 pmdddlcont.Clear();
235 }
236
237
06810de6 238 maxhit = 0;
239
240 for(Int_t idet=0; idet < kDet; idet++)
241 {
242 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
243 {
244 for(Int_t irow = 0; irow < kMaxRow; irow++)
245 {
246 for(Int_t icol = 0; icol < kMaxCol; icol++)
247 {
248
249 //printf("d1[%d][%d][%d][%d]=%d\n",
250 //det,ksmn,irow,jcol, d1[det][ksmn][irow][jcol] );
251 //printf("ch[%d][%d][%d][%d]=%d\n",
252 //det,ksmn,irow,jcol, ch[det][ksmn][irow][jcol] );
253
254 if(d1[idet][ismn][irow][icol] > 0)
255 {
256 isocount = 0;
257 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
258 {
259 id1 = irow + neibx[ii];
260 jd1 = icol + neiby[ii];
261 if(d1[idet][ismn][id1][jd1] == 0)
262 {
263 isocount++;
264 if(isocount == kCellNeighbour)
265 {
266 countisocell++;
267 det[maxhit] = idet;
268 smn[maxhit] = ismn;
269 row[maxhit] = irow;
270 col[maxhit] = icol;
271 sig[maxhit] = d1[idet][ismn][irow][icol];
272 chno[maxhit] = ch[idet][ismn][irow][icol];
273 maxhit++;
274 fHsmIso[idet][ismn]->Fill(d1[idet][ismn][irow][icol]);
275 fHadcIso[idet][ismn][irow][icol]->Fill(d1[idet][ismn][irow][icol]);
276 }
277 }
278 } // neigh cell cond.
279 } // d>0 cond.
280 }
281 }
282 }
283 } //event loop
284 }
35535af7 285 Double_t histMean[kDet][kMaxSMN];
286 Double_t isoMean[kDet][kMaxSMN][kMaxRow][kMaxCol];
287
288 for(Int_t d1 = 0; d1 < kDet; d1++)
06810de6 289 {
35535af7 290 for(Int_t i1 = 0; i1 < kMaxSMN; i1++)
06810de6 291 {
292 histMean[d1][i1]= fHsmIso[d1][i1]->GetMean();
35535af7 293 for(Int_t j1 = 0; j1 < kMaxRow; j1++)
06810de6 294 {
35535af7 295 for(Int_t k1 = 0; k1 < kMaxCol; k1++)
06810de6 296 {
297 isoMean[d1][i1][j1][k1]=fHadcIso[d1][i1][j1][k1]->GetMean();
298 if(isoMean[d1][i1][j1][k1]>0.0 && histMean[d1][i1]>0.0)
299 {
300 fGainFact[d1][i1][j1][k1]=isoMean[d1][i1][k1][j1]/histMean[d1][i1];
35535af7 301 Float_t gain = fGainFact[d1][i1][j1][k1];
302 fCalibGain->SetGainFact(d1,i1,j1,k1,gain);
06810de6 303 }
304 }
305 }
306 }
307 }
308
309}
310// ------------------------------------------------------------------------ //
311Bool_t AliPMDCalibrator::Store()
312{
313 AliCDBManager *man = AliCDBManager::Instance();
0dd3d6f9 314 //man->SetDefaultStorage("local://$ALICE_ROOT");
315 if(!man->IsDefaultStorageSet()) return kFALSE;
06810de6 316 AliCDBId id("PMD/Calib/Data",0,0);
317 AliCDBMetaData md;
318 md.SetResponsible("Zubayer");
319 md.SetBeamPeriod(0);
320 md.SetAliRootVersion("28.02.2006");
321 md.SetComment("Test");
322
323 printf("\n\n\n fCalibData\n");
324 //fCalibData->Print(0);
325 //printf("\n\n\n fCalibData\n");
326
35535af7 327 Bool_t result = man->Put(fCalibGain,id,&md);
06810de6 328
329 return result;
330}
331