Line data Source code
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 :
19 : #include "TF1.h"
20 : #include "TFile.h"
21 : #include "TObjString.h"
22 : #include "TROOT.h"
23 : #include "TClonesArray.h"
24 : #include "TH1F.h"
25 : #include "TObjArray.h"
26 : #include "TMath.h"
27 :
28 : // --- Standard library ---
29 :
30 : // --- AliRoot header files ---
31 : #include "AliLog.h"
32 : #include "AliRawReaderFile.h"
33 : #include "AliPMDCalibrator.h"
34 : #include "AliRawReaderDate.h"
35 : #include "AliPMDRawStream.h"
36 : #include "AliPMDCalibData.h"
37 : #include "AliPMDddldata.h"
38 : #include "AliCDBManager.h"
39 : #include "AliCDBId.h"
40 : #include "AliCDBMetaData.h"
41 : #include "AliDAQ.h"
42 :
43 : //#include "AliPMDCleanNoise.h"
44 : //#include "AliPMDCleaner.h"
45 :
46 : #include "AliPMDPedestal.h"
47 : #include "AliCDBManager.h"
48 : #include "AliCDBEntry.h"
49 :
50 12 : ClassImp(AliPMDCalibrator)
51 :
52 :
53 : AliPMDCalibrator::AliPMDCalibrator():
54 0 : fCalibGain(new AliPMDCalibData()), fCalibPed(new AliPMDPedestal())
55 0 : {
56 : // Standard Constructor
57 0 : for(Int_t idet = 0; idet < kDet; idet++)
58 : {
59 0 : fHdetIso[idet] = NULL ;
60 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
61 : {
62 0 : fHsmIso[idet][ismn] = NULL ;
63 0 : for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
64 : {
65 0 : for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
66 : {
67 0 : fGainFact[idet][ismn][jrow][kcol] = 0.0;
68 0 : fHadcIso[idet][ismn][jrow][kcol] = NULL;
69 : }
70 : }
71 : }
72 : }
73 0 : }
74 : // ------------------------------------------------------------------------ //
75 : AliPMDCalibrator::AliPMDCalibrator(const AliPMDCalibrator &pmdcalibrator):
76 0 : fCalibGain(new AliPMDCalibData()), fCalibPed(new AliPMDPedestal())
77 0 : {
78 0 : for(Int_t idet = 0; idet < 2; idet++)
79 : {
80 0 : fHdetIso[idet] = pmdcalibrator.fHdetIso[idet] ;
81 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
82 : {
83 0 : fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
84 0 : for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
85 : {
86 0 : for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
87 : {
88 0 : fGainFact[idet][ismn][jrow][kcol] = pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
89 0 : fHadcIso[idet][ismn][jrow][kcol] = pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
90 : }
91 : }
92 : }
93 : }
94 :
95 0 : }
96 : // ------------------------------------------------------------------------ //
97 : AliPMDCalibrator &AliPMDCalibrator::operator=(const AliPMDCalibrator &pmdcalibrator)
98 : {
99 0 : if(this != &pmdcalibrator)
100 : {
101 0 : for(Int_t idet = 0; idet < kDet; idet++)
102 : {
103 0 : fHdetIso[idet] = pmdcalibrator.fHdetIso[idet] ;
104 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
105 : {
106 0 : fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
107 0 : for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
108 : {
109 0 : for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
110 : {
111 0 : fGainFact[idet][ismn][jrow][kcol] =
112 0 : pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
113 0 : fHadcIso[idet][ismn][jrow][kcol] =
114 0 : pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
115 : }
116 : }
117 : }
118 : }
119 0 : }
120 0 : return *this;
121 : }
122 : // ------------------------------------------------------------------------ //
123 : AliPMDCalibrator::~AliPMDCalibrator()
124 0 : {
125 : // destructor
126 0 : for (Int_t i=0; i<kDet; i++)
127 0 : delete fHdetIso[i] ;
128 0 : for (Int_t i=0; i<kDet; i++)
129 0 : for (Int_t j=0; j<kMaxSMN; j++)
130 0 : delete fHsmIso[i][j] ;
131 0 : for (Int_t i=0; i<kDet; i++)
132 0 : for (Int_t j=0; j<kMaxSMN; j++)
133 0 : for (Int_t k=0; k<kMaxRow; k++)
134 0 : for (Int_t l=0; l<kMaxCol; l++)
135 0 : delete fHadcIso[i][j][k][l] ;
136 0 : delete fCalibGain;
137 0 : delete fCalibPed;
138 0 : }
139 : // ------------------------------------------------------------------------ //
140 :
141 : void AliPMDCalibrator::Exec()
142 : {
143 : // reads parameters and does the calibration
144 0 : CalculateIsoCell() ;
145 0 : }
146 : // ------------------------------------------------------------------------ //
147 :
148 : void AliPMDCalibrator::Init()
149 : {
150 : // intializes everything
151 0 : char hname[50];
152 0 : char hname2[50];
153 0 : char hname24[50];
154 0 : char hnameiso[120];
155 0 : char htitle1[120];
156 0 : char htitle2[120];
157 :
158 0 : for(Int_t d = 0; d < kDet; d++) {
159 0 : snprintf(hname2,50,"Isolated cell adc for Det Plane %d",d);
160 0 : fHdetIso[d]= new TH1F(hname2,htitle2,100,0,1000);
161 0 : for(Int_t i1 = 0; i1 < kMaxSMN; i1++) {
162 0 : snprintf(hname,50,"det_%d_iso_sm_%2d",d,i1);
163 0 : snprintf(hname24,50,"det_%d_iso_sm_%2d",d,i1);
164 0 : fHsmIso[d][i1]= new TH1F(hname,hname24,100,0,1000);
165 0 : for(Int_t j1 = 0; j1 < kMaxRow; j1++) {
166 0 : for(Int_t k1 = 0; k1 < kMaxCol; k1++) {
167 0 : snprintf(hnameiso,120,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
168 : ,d,i1,j1,k1);
169 0 : snprintf(htitle1,120,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
170 : ,d,i1,j1,k1);
171 :
172 0 : TObject *old=gDirectory->GetList()->FindObject(hnameiso);
173 0 : if (old) gDirectory->GetList()->Remove(old);
174 0 : fHadcIso[d][i1][j1][k1] = new TH1F(hnameiso,htitle1,100,0.,1000.);
175 : }
176 : }
177 : }
178 : }
179 :
180 0 : }
181 :
182 : // ------------------------------------------------------------------------ //
183 :
184 : void AliPMDCalibrator::CalculateIsoCell()
185 : {
186 : // Calculates the ADC of isolated cell
187 :
188 0 : TObjArray pmdddlcont;
189 :
190 : const Int_t kCellNeighbour = 6;
191 :
192 0 : Int_t neibx[6] = {1,0,-1,-1,0,1};
193 0 : Int_t neiby[6] = {0,1,1,0,-1,-1};
194 :
195 : Int_t id1 = 0,jd1 = 0; //neighbour row/col
196 : Int_t countisocell = 0 ; //number of isilated cell
197 : Int_t isocount = 0; //number of neighbours with 0 signal
198 : Int_t maxhit = 0;
199 0 : Int_t nhit[kDet][kMaxSMN];
200 0 : Int_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
201 0 : Int_t nhitcell[kDet][kMaxSMN][kMaxRow][kMaxCol];
202 :
203 0 : for(Int_t idet = 0; idet < kDet; idet++)
204 : {
205 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
206 : {
207 0 : nhit[idet][ismn] = 0;
208 0 : for(Int_t irow = 0; irow < kMaxRow; irow++)
209 : {
210 0 : for(Int_t icol = 0; icol < kMaxCol; icol++)
211 : {
212 0 : d1[idet][ismn][irow][icol] = 0;
213 0 : nhitcell[idet][ismn][irow][icol] = 0;
214 : }
215 : }
216 : }
217 : }
218 :
219 0 : Float_t tempnhit1[kDet][kMaxSMN];
220 0 : Float_t tempnhit2[kDet][kMaxSMN];
221 0 : Float_t meannhit[kDet][kMaxSMN];
222 0 : Float_t meanSqnhit[kDet][kMaxSMN];
223 0 : Float_t sigmanhit[kDet][kMaxSMN];
224 0 : Float_t count[kDet][kMaxSMN];
225 0 : Float_t nhitcut[kDet][kMaxSMN];
226 :
227 0 : for (Int_t idet = 0; idet < kDet; idet++)
228 : {
229 0 : for (Int_t ismn = 0; ismn < kMaxSMN; ismn++)
230 : {
231 0 : tempnhit1[idet][ismn] = 0.;
232 0 : tempnhit2[idet][ismn] = 0.;
233 0 : meannhit[idet][ismn] = 0.;
234 0 : meanSqnhit[idet][ismn] = 0.;
235 0 : sigmanhit[idet][ismn] = 0.;
236 0 : count[idet][ismn] = 0.;
237 0 : nhitcut[idet][ismn] = 0.;
238 : }
239 : }
240 :
241 :
242 : //accessing raw data
243 0 : AliRawReaderFile reader(".");
244 0 : AliPMDRawStream stream(&reader);
245 0 : while(reader.NextEvent())
246 : {
247 : // New PMD Reader is plugged in
248 : Int_t iddl = -1;
249 0 : while ((iddl = stream.DdlData(&pmdddlcont)) >=0) {
250 :
251 : //reader.Select("PMD", iddl, iddl);
252 : //stream.DdlData(iddl,&pmdddlcont);
253 0 : Int_t ientries = pmdddlcont.GetEntries();
254 0 : for (Int_t ient = 0; ient < ientries; ient++)
255 : {
256 : AliPMDddldata *pmdddl =
257 0 : (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
258 0 : Int_t idet = pmdddl->GetDetector();
259 0 : Int_t ismn = pmdddl->GetSMN();
260 0 : Int_t irow = pmdddl->GetRow();
261 0 : Int_t icol = pmdddl->GetColumn();
262 0 : Float_t isig1 = pmdddl->GetSignal();
263 : // Pedestal Subtraction
264 : Int_t pedmeanrms =
265 0 : fCalibPed->GetPedMeanRms(idet,ismn,irow,icol);
266 0 : Int_t pedrms1 = (Int_t) pedmeanrms%100;
267 0 : Float_t pedrms = (Float_t)pedrms1/10.;
268 0 : Float_t pedmean = (Float_t) (pedmeanrms - pedrms1)/1000.0;
269 0 : Float_t isig = isig1 - (pedmean + 3.0*pedrms);
270 0 : if (isig>0)
271 : {
272 0 : d1[idet][ismn][irow][icol] = (Int_t)isig;
273 0 : nhitcell[idet][ismn][irow][icol] += 1;
274 0 : }
275 : }//ient loop
276 0 : pmdddlcont.Clear();
277 : }//iddl loop
278 : maxhit = 0;
279 0 : for(Int_t idet=0; idet < kDet; idet++)
280 : {
281 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
282 : {
283 0 : for(Int_t irow = 0; irow < kMaxRow; irow++)
284 : {
285 0 : for(Int_t icol = 0; icol < kMaxCol; icol++)
286 : {
287 0 : if(d1[idet][ismn][irow][icol] > 0)
288 : {
289 : isocount = 0;
290 0 : for(Int_t ii = 0; ii < kCellNeighbour; ii++)
291 : {
292 0 : id1 = irow + neibx[ii];
293 0 : jd1 = icol + neiby[ii];
294 0 : if(d1[idet][ismn][id1][jd1] == 0)
295 : {
296 0 : isocount++;
297 0 : if(isocount == kCellNeighbour)
298 : {
299 0 : countisocell++;
300 0 : maxhit++;
301 0 : fHdetIso[idet]->
302 0 : Fill(d1[idet][ismn][irow][icol]);
303 0 : fHsmIso[idet][ismn]->
304 0 : Fill(d1[idet][ismn][irow][icol]);
305 0 : fHadcIso[idet][ismn][irow][icol]->
306 0 : Fill(d1[idet][ismn][irow][icol]);
307 : }
308 : }
309 : } // neigh cell cond.
310 0 : } // d>0 cond.
311 : }
312 : }
313 : }
314 : } //det
315 : }//event loop
316 :
317 : // Mean and Sigma Calculations
318 0 : for(Int_t idet=0; idet < kDet; idet++){
319 0 : for(Int_t ismn = 0; ismn < kMaxSMN; ismn++){
320 0 : for(Int_t irow = 0; irow < kMaxRow; irow++){
321 0 : for(Int_t icol = 0; icol < kMaxCol; icol++){
322 0 : if(nhitcell[idet][ismn][irow][icol]>0){
323 0 : count[idet][ismn] += 1;
324 0 : tempnhit1[idet][ismn] += nhitcell[idet][ismn][irow][icol];
325 0 : tempnhit2[idet][ismn] += nhitcell[idet][ismn][irow][icol]
326 0 : *nhitcell[idet][ismn][irow][icol];
327 0 : }
328 : }
329 : }
330 : }
331 : }//det loop
332 :
333 : //cout<<"nhit cell = "<<idet<<" "<<ismn<<" "
334 : // <<irow<<" "<<icol<<" "<<nhitcell[idet][ismn][irow][icol]<<endl;
335 : //count[idet][ismn] += 1;
336 :
337 0 : for(Int_t i=0; i < kDet; i++)
338 : {
339 0 : for(Int_t j=0; j < kMaxSMN; j++)
340 : {
341 0 : if(count[i][j] > 0.)
342 : {
343 0 : meannhit[i][j] = tempnhit1[i][j]/count[i][j];
344 0 : meanSqnhit[i][j] = tempnhit2[i][j]/count[i][j];
345 0 : sigmanhit[i][j] = sqrt(meanSqnhit[i][j]-
346 0 : (meannhit[i][j]*meannhit[i][j]));
347 0 : nhitcut[i][j] = 3*sigmanhit[i][j] + meannhit[i][j];
348 0 : }
349 : }
350 : }
351 :
352 :
353 0 : Double_t histdetMean[kDet];
354 0 : Double_t histMean[kDet][kMaxSMN];
355 0 : Double_t isoMean[kDet][kMaxSMN][kMaxRow][kMaxCol];
356 0 : Double_t smNormFactor[kDet][kMaxSMN];
357 :
358 0 : for(Int_t det1 = 0; det1 < kDet; det1++)
359 : {
360 0 : histdetMean[det1]= fHdetIso[det1]->GetMean();
361 0 : for(Int_t i1 = 0; i1 < kMaxSMN; i1++)
362 : {
363 0 : histMean[det1][i1]= fHsmIso[det1][i1]->GetMean();
364 0 : if(histMean[det1][i1]>0.0 && histdetMean[det1]>0.0)
365 : {
366 0 : smNormFactor[det1][i1]= histdetMean[det1]/histMean[det1][i1];
367 0 : }
368 0 : for(Int_t j1 = 0; j1 < kMaxRow; j1++)
369 : {
370 0 : for(Int_t k1 = 0; k1 < kMaxCol; k1++)
371 : {
372 0 : if(nhitcell[det1][i1][j1][k1]> nhitcut[det1][i1]) fGainFact[det1][i1][j1][k1]=-99.0;
373 0 : if(nhitcell[det1][i1][j1][k1]< nhitcut[det1][i1])
374 : {
375 0 : isoMean[det1][i1][j1][k1]=fHadcIso[det1][i1][j1][k1]->
376 : GetMean();
377 0 : if(isoMean[det1][i1][j1][k1]>0.0 && histMean[det1][i1]>0.0)
378 : {
379 0 : fGainFact[det1][i1][j1][k1]=
380 0 : isoMean[det1][i1][j1][k1]/(histMean[det1][i1]*
381 0 : smNormFactor[det1][i1]);
382 :
383 0 : }
384 : }
385 0 : Float_t gain = fGainFact[det1][i1][j1][k1];
386 0 : fCalibGain->SetGainFact(det1,i1,j1,k1,gain);
387 : }
388 :
389 :
390 : }
391 : }
392 : }
393 0 : }//CalculateIsoCell()
394 :
395 : // ------------------------------------------------------------------------ //
396 :
397 : Bool_t AliPMDCalibrator::Store()
398 : {
399 0 : AliCDBManager *man = AliCDBManager::Instance();
400 : //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
401 0 : if(!man->IsDefaultStorageSet()) return kFALSE;
402 0 : AliCDBId id("PMD/Calib/Gain",0,999999999);
403 0 : AliCDBMetaData md;
404 0 : md.SetBeamPeriod(0);
405 0 : md.SetComment("Test");
406 :
407 0 : printf("\n\n\n fCalibData\n");
408 : //fCalibData->Print(0);
409 : //printf("\n\n\n fCalibData\n");
410 :
411 0 : Bool_t result = man->Put(fCalibGain,id,&md);
412 :
413 0 : return result;
414 0 : }
415 :
|