1 //////////////////////////////////////////////////////////////////////////////
3 // * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 // * Author: The ALICE Off-line Project. *
6 // * Contributors are mentioned in the code where appropriate. *
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 // **************************************************************************/
17 //////////////////////////////////////////////////////////////////////////////
22 #include "TObjString.h"
24 #include "TClonesArray.h"
26 #include "TObjArray.h"
28 // --- Standard library ---
30 // --- AliRoot header files ---
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"
40 #include "AliCDBMetaData.h"
43 ClassImp(AliPMDCalibrator)
45 //const Int_t kDet = 2;
46 //const Int_t kMaxSMN = 24;
47 //const Int_t kMaxRow = 48;
48 //const Int_t kMaxCol = 96;
50 AliPMDCalibrator::AliPMDCalibrator():
51 fCalibGain(new AliPMDCalibData())
53 // Standard Constructor
54 for(Int_t idet = 0; idet < kDet; idet++)
56 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
58 fHsmIso[idet][ismn] = NULL ;
59 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
61 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
63 fGainFact[idet][ismn][jrow][kcol] = 0.0;
64 fHadcIso[idet][ismn][jrow][kcol] = NULL;
70 // ------------------------------------------------------------------------ //
71 AliPMDCalibrator::AliPMDCalibrator(const AliPMDCalibrator &pmdcalibrator):
72 fCalibGain(new AliPMDCalibData())
74 for(Int_t idet = 0; idet < 2; idet++)
76 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
78 fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
79 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
81 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
83 fGainFact[idet][ismn][jrow][kcol] = pmdcalibrator.fGainFact[idet][ismn][jrow][kcol];
84 fHadcIso[idet][ismn][jrow][kcol] = pmdcalibrator.fHadcIso[idet][ismn][jrow][kcol];
91 // ------------------------------------------------------------------------ //
92 AliPMDCalibrator &AliPMDCalibrator::operator=(const AliPMDCalibrator &pmdcalibrator)
94 if(this != &pmdcalibrator)
96 for(Int_t idet = 0; idet < kDet; idet++)
98 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
100 fHsmIso[idet][ismn] = pmdcalibrator.fHsmIso[idet][ismn] ;
101 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
103 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
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];
116 // ------------------------------------------------------------------------ //
117 AliPMDCalibrator::~AliPMDCalibrator()
120 if(fHsmIso) delete fHsmIso ;
121 if(fHadcIso) delete fHadcIso ;
124 // ------------------------------------------------------------------------ //
126 void AliPMDCalibrator::Exec()
128 // reads parameters and does the calibration
132 // ------------------------------------------------------------------------ //
134 void AliPMDCalibrator::Init()
136 // intializes everything
138 char hname24[kMaxSMN];
142 for(Int_t d = 0; d < kDet; d++) {
143 for(Int_t i1 = 0; i1 < kMaxSMN; i1++) {
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"
151 sprintf(htitle1,"Isolated Cell ADC for det_%d_cell_sm%d_row%d_col%d"
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.);
164 // ------------------------------------------------------------------------ //
166 void AliPMDCalibrator::CalculateIsoCell()
168 // Calculates the ADC of isolated cell
170 TObjArray pmdddlcont;
171 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
172 const Int_t kMaxHit = 60000;
173 const Int_t kCellNeighbour = 6;
175 Int_t neibx[6] = {1,0,-1,-1,0,1};
176 Int_t neiby[6] = {0,1,1,0,-1,-1};
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];
186 Int_t det[kMaxHit],smn[kMaxHit];
187 Int_t row[kMaxHit],col[kMaxHit],sig[kMaxHit],chno[kMaxHit];
189 for(Int_t idet = 0; idet < kDet; idet++)
191 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
193 for(Int_t irow = 0; irow < kMaxRow; irow++)
195 for(Int_t icol = 0; icol < kMaxCol; icol++)
197 d1[idet][ismn][irow][icol] = 0;
198 ch[idet][ismn][irow][icol] = 0;
204 AliRawReaderFile reader(".");
205 AliPMDRawStream stream(&reader);
206 while(reader.NextEvent())
208 // New PMD Reader is plugged in
210 for (Int_t iddl = 0; iddl < kDDL; iddl++)
212 reader.Select("PMD", iddl, iddl);
213 stream.DdlData(iddl,&pmdddlcont);
215 Int_t ientries = pmdddlcont.GetEntries();
216 for (Int_t ient = 0; ient < ientries; ient++)
218 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
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();
230 d1[idet][ismn][irow][icol] = isig;
231 ch[idet][ismn][irow][icol] = ichno;
240 for(Int_t idet=0; idet < kDet; idet++)
242 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
244 for(Int_t irow = 0; irow < kMaxRow; irow++)
246 for(Int_t icol = 0; icol < kMaxCol; icol++)
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] );
254 if(d1[idet][ismn][irow][icol] > 0)
257 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
259 id1 = irow + neibx[ii];
260 jd1 = icol + neiby[ii];
261 if(d1[idet][ismn][id1][jd1] == 0)
264 if(isocount == kCellNeighbour)
271 sig[maxhit] = d1[idet][ismn][irow][icol];
272 chno[maxhit] = ch[idet][ismn][irow][icol];
274 fHsmIso[idet][ismn]->Fill(d1[idet][ismn][irow][icol]);
275 fHadcIso[idet][ismn][irow][icol]->Fill(d1[idet][ismn][irow][icol]);
278 } // neigh cell cond.
285 Double_t histMean[kDet][kMaxSMN];
286 Double_t isoMean[kDet][kMaxSMN][kMaxRow][kMaxCol];
288 for(Int_t d1 = 0; d1 < kDet; d1++)
290 for(Int_t i1 = 0; i1 < kMaxSMN; i1++)
292 histMean[d1][i1]= fHsmIso[d1][i1]->GetMean();
293 for(Int_t j1 = 0; j1 < kMaxRow; j1++)
295 for(Int_t k1 = 0; k1 < kMaxCol; k1++)
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)
300 fGainFact[d1][i1][j1][k1]=isoMean[d1][i1][k1][j1]/histMean[d1][i1];
301 Float_t gain = fGainFact[d1][i1][j1][k1];
302 fCalibGain->SetGainFact(d1,i1,j1,k1,gain);
310 // ------------------------------------------------------------------------ //
311 Bool_t AliPMDCalibrator::Store()
313 AliCDBManager *man = AliCDBManager::Instance();
314 //man->SetDefaultStorage("local://$ALICE_ROOT");
315 if(!man->IsDefaultStorageSet()) return kFALSE;
316 AliCDBId id("PMD/Calib/Data",0,0);
318 md.SetResponsible("Zubayer");
320 md.SetAliRootVersion("28.02.2006");
321 md.SetComment("Test");
323 printf("\n\n\n fCalibData\n");
324 //fCalibData->Print(0);
325 //printf("\n\n\n fCalibData\n");
327 Bool_t result = man->Put(fCalibGain,id,&md);