1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include <TObjArray.h>
24 #include <TDirectory.h>
26 #include "TTreeStream.h"
31 #include "AliRawReader.h"
32 #include "AliPMDRawStream.h"
33 #include "AliPMDddldata.h"
34 #include "AliBitPacking.h"
36 #include "AliPMDCalibPedestal.h"
39 ClassImp(AliPMDCalibPedestal)
42 AliPMDCalibPedestal::AliPMDCalibPedestal() :
46 // default constructor
49 for (int i = 0; i < kDet; i++)
51 for (int j = 0; j < kMaxSMN; j++)
53 for (int k = 0; k < kMaxRow; k++)
55 for (int l = 0; l < kMaxCol; l++)
57 fPedVal[i][j][k][l] = 0.;
58 fPedValSq[i][j][k][l] = 0.;
59 fPedCount[i][j][k][l] = 0.;
60 fPedChain[i][j][k][l] = 0;
68 //_____________________________________________________________________
69 AliPMDCalibPedestal::AliPMDCalibPedestal(const AliPMDCalibPedestal &ped) :
75 for (int i = 0; i < kDet; i++)
77 for (int j = 0; j < kMaxSMN; j++)
79 for (int k = 0; k < kMaxRow; k++)
81 for (int l = 0; l < kMaxCol; l++)
83 fPedVal[i][j][k][l] = ped.fPedVal[i][j][k][l];
84 fPedValSq[i][j][k][l] = ped.fPedValSq[i][j][k][l];
85 fPedCount[i][j][k][l] = ped.fPedCount[i][j][k][l];
86 fPedChain[i][j][k][l] = ped.fPedChain[i][j][k][l];
93 //_____________________________________________________________________
94 AliPMDCalibPedestal& AliPMDCalibPedestal::operator = (const AliPMDCalibPedestal &source)
97 // assignment operator
99 if (&source == this) return *this;
100 new (this) AliPMDCalibPedestal(source);
104 //_____________________________________________________________________
105 AliPMDCalibPedestal::~AliPMDCalibPedestal()
111 //_____________________________________________________________________
112 Bool_t AliPMDCalibPedestal::ProcessEvent(AliRawReader *rawReader)
115 // Event processing loop - AliRawReader
118 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
121 UInt_t pbus, mcm, chno;
123 AliPMDRawStream rawStream(rawReader);
125 TObjArray pmdddlcont;
127 Int_t numberofDDLs = 0;
129 while ((iddl = rawStream.DdlData(&pmdddlcont)) >=0) {
131 Int_t ientries = pmdddlcont.GetEntries();
132 //printf("iddl = %d ientries = %d\n",iddl, ientries);
133 for (Int_t ient = 0; ient < ientries; ient++)
135 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
137 Int_t det = pmdddl->GetDetector();
138 Int_t smn = pmdddl->GetSMN();
139 Int_t row = pmdddl->GetRow();
140 Int_t col = pmdddl->GetColumn();
141 Float_t sig = (Float_t) pmdddl->GetSignal();
143 pbus = (UInt_t) pmdddl->GetPatchBusId();
144 mcm = (UInt_t) pmdddl->GetMCM();
145 chno = (UInt_t) pmdddl->GetChannel();
148 AliBitPacking::PackWord(chno,busmcmch,0,7);
149 AliBitPacking::PackWord(mcm,busmcmch,8,15);
150 AliBitPacking::PackWord(pbus,busmcmch,16,23);
153 if (fPedChain[det][smn][row][col] == 0)
154 fPedChain[det][smn][row][col] = busmcmch;
156 fPedVal[det][smn][row][col] += sig;
157 fPedValSq[det][smn][row][col] += sig*sig;
158 fPedCount[det][smn][row][col]++;
162 if (numberofDDLs < kDDL)
166 //_____________________________________________________________________
168 void AliPMDCalibPedestal::Analyse(TTree *pedtree)
171 // Calculate pedestal Mean and RMS
174 FILE *fpw0 = fopen("pedestal2304.ped","w");
175 FILE *fpw1 = fopen("pedestal2305.ped","w");
176 FILE *fpw2 = fopen("pedestal2306.ped","w");
177 FILE *fpw3 = fopen("pedestal2307.ped","w");
178 FILE *fpw4 = fopen("pedestal2308.ped","w");
179 FILE *fpw5 = fopen("pedestal2309.ped","w");
182 UInt_t pbus, mcm, chno;
184 Int_t det, sm, row, col;
186 Float_t meansq, diff;
190 pedtree->Branch("det",&det,"det/I");
191 pedtree->Branch("sm",&sm,"sm/I");
192 pedtree->Branch("row",&row,"row/I");
193 pedtree->Branch("col",&col,"col/I");
194 pedtree->Branch("mean",&mean,"mean/F");
195 pedtree->Branch("rms",&rms,"rms/F");
197 for (int idet = 0; idet < kDet; idet++)
199 for (int ism = 0; ism < kMaxSMN; ism++)
201 ConvertDDL(idet,ism,ddlno);
202 for (int irow = 0; irow < kMaxRow; irow++)
204 for (int icol = 0; icol < kMaxCol; icol++)
213 if (fPedCount[idet][ism][irow][icol] > 0)
215 mean = fPedVal[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
217 meansq = fPedValSq[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
219 diff = meansq - mean*mean;
230 busmcmch = fPedChain[idet][ism][irow][icol];
232 chno = busmcmch & 0x00FF;
233 mcm = (busmcmch >> 8) & 0x00FF;
234 pbus = (busmcmch >> 16) & 0x00FF;
238 fprintf(fpw0,"%d %d %d %f %f\n",
239 pbus, mcm, chno, mean, rms);
243 fprintf(fpw1,"%d %d %d %f %f\n",
244 pbus, mcm, chno, mean, rms);
248 fprintf(fpw2,"%d %d %d %f %f\n",
249 pbus, mcm, chno, mean, rms);
253 fprintf(fpw3,"%d %d %d %f %f\n",
254 pbus, mcm, chno, mean, rms);
258 fprintf(fpw4,"%d %d %d %f %f\n",
259 pbus, mcm, chno, mean, rms);
263 fprintf(fpw5,"%d %d %d %f %f\n",
264 pbus, mcm, chno, mean, rms);
283 // -------------------------------------------------------------------
285 void AliPMDCalibPedestal::ConvertDDL(Int_t det, Int_t smn, Int_t &ddlno)
287 // Given the plane number and serial module number, ddlno is calculated
295 else if (smn > 5 && smn <= 11)
299 else if (smn > 11 && smn <= 17)
303 else if (smn > 17 && smn <= 23)
310 if (smn <= 5 || (smn >= 18 && smn <=23))
314 else if (smn >= 6 && smn <= 17)