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 //////////////////////////////////////////////////////////////////////////////
21 #include "TObjString.h"
23 #include "TClonesArray.h"
25 #include "TObjArray.h"
28 // --- Standard library ---
30 // --- AliRoot header files ---
33 #include "AliRawReader.h"
34 #include "AliPMDRawStream.h"
35 #include "AliPMDddldata.h"
36 #include "AliPMDCalibGain.h"
38 ClassImp(AliPMDCalibGain)
40 AliPMDCalibGain::AliPMDCalibGain():
44 // Standard Constructor
45 for(Int_t idet = 0; idet < kDet; idet++)
48 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
50 fSMIso[idet][ismn] = 0.;
51 fSMCount[idet][ismn] = 0.;
52 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
54 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
56 fCellIso[idet][ismn][jrow][kcol] = 0.;
57 fCellCount[idet][ismn][jrow][kcol] = 0.;
58 fPedMeanRMS[idet][ismn][jrow][kcol] = 0.;
68 // ------------------------------------------------------------------------ //
69 AliPMDCalibGain::AliPMDCalibGain(const AliPMDCalibGain &pmdcalibgain):
70 TObject(pmdcalibgain),
73 for(Int_t idet = 0; idet < kDet; idet++)
75 fDetCount[idet] = pmdcalibgain.fDetCount[idet];
76 fDetIso[idet] = pmdcalibgain.fDetIso[idet];
77 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
79 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn] ;
80 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn] ;
81 for(Int_t jrow = 0; jrow < kMaxRow; jrow++)
83 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
85 fCellIso[idet][ismn][jrow][kcol] =
86 pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
87 fCellCount[idet][ismn][jrow][kcol] =
88 pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
89 fPedMeanRMS[idet][ismn][jrow][kcol] =
90 pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
98 // ------------------------------------------------------------------------ //
99 AliPMDCalibGain &AliPMDCalibGain::operator=(const AliPMDCalibGain &pmdcalibgain)
101 if(this != &pmdcalibgain)
103 this->fpw = pmdcalibgain.fpw;
104 for(Int_t idet = 0; idet < kDet; idet++)
106 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
108 fSMIso[idet][ismn] = pmdcalibgain.fSMIso[idet][ismn];
109 fSMCount[idet][ismn] = pmdcalibgain.fSMCount[idet][ismn];
110 for(Int_t jrow = 0; jrow < kMaxRow;jrow++)
112 for(Int_t kcol = 0; kcol < kMaxCol; kcol++)
114 fCellIso[idet][ismn][jrow][kcol] =
115 pmdcalibgain.fCellIso[idet][ismn][jrow][kcol];
116 fCellCount[idet][ismn][jrow][kcol] =
117 pmdcalibgain.fCellCount[idet][ismn][jrow][kcol];
118 fPedMeanRMS[idet][ismn][jrow][kcol] =
119 pmdcalibgain.fPedMeanRMS[idet][ismn][jrow][kcol];
128 // ------------------------------------------------------------------------ //
129 AliPMDCalibGain::~AliPMDCalibGain()
135 // ------------------------------------------------------------------------ //
137 Int_t AliPMDCalibGain::ExtractPedestal(const Char_t *rootFile)
139 // Pedestal extraction from the PMD_PED.root file
140 // To be called once at the beginning
142 Int_t det, sm, row, col;
145 TFile *pedfile = new TFile(rootFile);
149 printf("ERROR --- NO PEDESTAL (PMD_PED1.root) FILE IS FOUND --- STOP GAIN DA\n");
154 TTree *ped =(TTree*)pedfile->Get("ped");
156 ped->SetBranchAddress("det",&det);
157 ped->SetBranchAddress("sm",&sm);
158 ped->SetBranchAddress("row",&row);
159 ped->SetBranchAddress("col",&col);
160 ped->SetBranchAddress("mean",&mean);
161 ped->SetBranchAddress("rms",&rms);
163 Int_t nentries = (Int_t)ped->GetEntries();
165 for (Int_t ient = 0; ient < nentries; ient++)
168 fPedMeanRMS[det][sm][row][col] = mean + 3.*rms;
169 //printf("Mean= %f, RMS= %f, PedMeanRMS=%f\n",mean,rms,fPedMeanRMS[det][sm][row][col]);
179 // ------------------------------------------------------------------------ //
181 void AliPMDCalibGain::ReadTempFile(const Char_t *tempFile)
183 // Read the variables from the file
185 fpw = fopen(tempFile,"r");
187 Float_t detcount, detiso;
188 Float_t smcount, smiso;
189 Float_t cellcount, celliso;
191 for (Int_t idet = 0; idet < kDet; idet++)
193 fscanf(fpw,"%d %f %f",&idet,&detcount,&detiso);
194 fDetCount[idet] = detcount;
195 fDetIso[idet] = detiso;
198 for (Int_t idet = 0; idet < kDet; idet++)
200 for (Int_t ism = 0; ism < kMaxSMN; ism++)
202 fscanf(fpw,"%d %d %f %f",&idet,&ism,&smcount,&smiso);
204 fSMCount[idet][ism] = smcount;
205 fSMIso[idet][ism] = smiso;
209 for (Int_t idet = 0; idet < kDet; idet++)
211 for (Int_t ism = 0; ism < kMaxSMN; ism++)
213 for (Int_t irow = 0; irow < kMaxRow; irow++)
215 for (Int_t icol = 0; icol < kMaxCol; icol++)
217 fscanf(fpw,"%d %d %d %d %f %f",&idet,&ism,&irow,&icol,
218 &cellcount,&celliso);
220 fCellCount[idet][ism][irow][icol] = cellcount;
221 fCellIso[idet][ism][irow][icol] = celliso;
230 // ------------------------------------------------------------------------ //
231 void AliPMDCalibGain::WriteTempFile(const Char_t *tempFile)
233 // Write the Temporary file if the required statics is not achieved
237 Following variables to be written to a file
240 fCellIso[idet][ismn][irow][icol];
243 fSMCount[idet][ismn];
244 fCellCount[idet][ismn][irow][icol];
248 fpw = fopen(tempFile,"w+");
250 for (Int_t idet = 0; idet < kDet; idet++)
252 fprintf(fpw,"%d %f %f\n",idet,fDetCount[idet],fDetIso[idet]);
255 for (Int_t idet = 0; idet < kDet; idet++)
257 for (Int_t ism = 0; ism < kMaxSMN; ism++)
259 fprintf(fpw,"%d %d %f %f\n",idet,ism, fSMCount[idet][ism],fSMIso[idet][ism]);
263 for (Int_t idet = 0; idet < kDet; idet++)
265 for (Int_t ism = 0; ism < kMaxSMN; ism++)
267 for (Int_t irow = 0; irow < kMaxRow; irow++)
269 for (Int_t icol = 0; icol < kMaxCol; icol++)
271 fprintf(fpw,"%d %d %d %d %f %f\n",idet,ism,irow,icol,
272 fCellCount[idet][ism][irow][icol],
273 fCellIso[idet][ism][irow][icol]);
283 // ------------------------------------------------------------------------ //
285 Bool_t AliPMDCalibGain::ProcessEvent(AliRawReader *rawReader, TObjArray *pmdddlcont)
287 // Calculates the ADC of isolated cell
289 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
290 const Int_t kCellNeighbour = 6;
291 Int_t neibx[6] = {1,0,-1,-1,0,1};
292 Int_t neiby[6] = {0,1,1,0,-1,-1};
294 Int_t id1,jd1; //neighbour row/col
295 Int_t isocount; //number of neighbours with 0 signal
297 Float_t d1[kDet][kMaxSMN][kMaxRow][kMaxCol];
299 for(Int_t idet = 0; idet < kDet; idet++)
301 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
303 for(Int_t irow = 0; irow < kMaxRow; irow++)
305 for(Int_t icol = 0; icol < kMaxCol; icol++)
307 d1[idet][ismn][irow][icol] = 0.;
313 AliPMDRawStream rawStream(rawReader);
317 Int_t numberofDDLs = 0;
319 while ((iddl = rawStream.DdlData(pmdddlcont)) >=0) {
322 Int_t ientries = pmdddlcont->GetEntries();
324 for (Int_t ient = 0; ient < ientries; ient++)
326 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont->UncheckedAt(ient);
328 Int_t idet = pmdddl->GetDetector();
329 Int_t ismn = pmdddl->GetSMN();
330 Int_t mcm = pmdddl->GetMCM();
331 //Int_t ichno = pmdddl->GetChannel();
332 Int_t irow = pmdddl->GetRow();
333 Int_t icol = pmdddl->GetColumn();
334 Int_t isig = pmdddl->GetSignal();
336 // This is the protection not to crash the code
338 if(mcm == 0) continue;
339 if (irow < 0 || icol < 0 || irow > 47 || icol > 95) continue;
341 // Pedestal subtraction
345 d1[idet][ismn][irow][icol] =
346 (Float_t) isig - fPedMeanRMS[idet][ismn][irow][icol];
347 //printf("Signal_ped_subtracted=%f, pedestal=%f\n",d1[idet][ismn][irow][icol]),fPedMeanRMS[idet][ismn][irow][icol];
350 pmdddlcont->Delete();
353 for(Int_t idet=0; idet < kDet; idet++)
355 for(Int_t ismn = 0; ismn < kMaxSMN; ismn++)
357 for(Int_t irow = 0; irow < kMaxRow; irow++)
359 for(Int_t icol = 0; icol < kMaxCol; icol++)
361 if(d1[idet][ismn][irow][icol] > 0)
364 for(Int_t ii = 0; ii < kCellNeighbour; ii++)
366 id1 = irow + neibx[ii];
367 jd1 = icol + neiby[ii];
368 if(d1[idet][ismn][id1][jd1] == 0)
371 if(isocount == kCellNeighbour)
373 fDetIso[idet] += d1[idet][ismn][irow][icol];
374 fSMIso[idet][ismn] += d1[idet][ismn][irow][icol];
375 fCellIso[idet][ismn][irow][icol] += d1[idet][ismn][irow][icol];
377 fSMCount[idet][ismn]++;
378 fCellCount[idet][ismn][irow][icol]++;
382 } // neigh cell cond.
389 if (numberofDDLs < kDDL)
394 // ------------------------------------------------------------------------ //
395 void AliPMDCalibGain::Analyse(TTree *gaintree)
397 // Calculates the mean
398 Int_t det, sm, row, col;
400 Float_t modmean = 0.;
401 Float_t cellmean = 0.;
404 gaintree->Branch("det",&det,"det/I");
405 gaintree->Branch("sm",&sm,"sm/I");
406 gaintree->Branch("row",&row,"row/I");
407 gaintree->Branch("col",&col,"col/I");
408 gaintree->Branch("gain",&gain,"gain/F");
410 for(Int_t idet = 0; idet < kDet; idet++)
412 if (fDetCount[idet]>0 )
413 detmean=fDetIso[idet]/fDetCount[idet];
414 for(Int_t ism = 0; ism < kMaxSMN; ism++)
416 if (fSMCount[idet][ism] > 0)
417 modmean = fSMIso[idet][ism]/fSMCount[idet][ism];
418 for(Int_t irow = 0; irow < kMaxRow; irow++)
420 for(Int_t icol = 0; icol < kMaxCol; icol++)
422 if (fCellCount[idet][ism][irow][icol] > 0.)
424 cellmean = fCellIso[idet][ism][irow][icol]/fCellCount[idet][ism][irow][icol];
430 if (cellmean > 0.0 && fCellCount[idet][ism][irow][icol]>0.)
432 gain = cellmean/detmean;
438 //if(fCellCount[idet][ism][irow][icol]>0.) printf("CellCount =%f, gain= %f\n",fCellCount[idet][ism][irow][icol],gain);
446 // ------------------------------------------------------------------------ //