Memory leak
[u/mrichter/AliRoot.git] / PMD / AliPMDCalibPedestal.cxx
CommitLineData
24e8f6b2 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16
17//Root includes
18#include <TObjArray.h>
19#include <TH1F.h>
20#include <TString.h>
21#include <TMath.h>
22#include <TF1.h>
23#include <TRandom.h>
24#include <TDirectory.h>
25#include <TFile.h>
26#include "TTreeStream.h"
27
28//AliRoot includes
9d7353e3 29#include "AliDAQ.h"
30#include "AliLog.h"
24e8f6b2 31#include "AliRawReader.h"
32#include "AliPMDRawStream.h"
33#include "AliPMDddldata.h"
722ccc67 34#include "AliBitPacking.h"
24e8f6b2 35//header file
36#include "AliPMDCalibPedestal.h"
37
38
39ClassImp(AliPMDCalibPedestal)
40
41
42AliPMDCalibPedestal::AliPMDCalibPedestal() :
43 TObject()
44{
45 //
46 // default constructor
47 //
48
0ab3a530 49 for (int i = 0; i < kDet; i++)
24e8f6b2 50 {
0ab3a530 51 for (int j = 0; j < kMaxSMN; j++)
24e8f6b2 52 {
0ab3a530 53 for (int k = 0; k < kMaxRow; k++)
24e8f6b2 54 {
0ab3a530 55 for (int l = 0; l < kMaxCol; l++)
24e8f6b2 56 {
0ab3a530 57 fPedVal[i][j][k][l] = 0.;
58 fPedValSq[i][j][k][l] = 0.;
59 fPedCount[i][j][k][l] = 0.;
722ccc67 60 fPedChain[i][j][k][l] = 0;
24e8f6b2 61 }
62 }
63 }
64 }
65
66
67}
68//_____________________________________________________________________
69AliPMDCalibPedestal::AliPMDCalibPedestal(const AliPMDCalibPedestal &ped) :
70 TObject(ped)
71{
72 //
73 // copy constructor
74 //
0ab3a530 75 for (int i = 0; i < kDet; i++)
24e8f6b2 76 {
0ab3a530 77 for (int j = 0; j < kMaxSMN; j++)
24e8f6b2 78 {
0ab3a530 79 for (int k = 0; k < kMaxRow; k++)
24e8f6b2 80 {
0ab3a530 81 for (int l = 0; l < kMaxCol; l++)
24e8f6b2 82 {
0ab3a530 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];
722ccc67 86 fPedChain[i][j][k][l] = ped.fPedChain[i][j][k][l];
24e8f6b2 87 }
88 }
89 }
90 }
91
92}
93//_____________________________________________________________________
94AliPMDCalibPedestal& AliPMDCalibPedestal::operator = (const AliPMDCalibPedestal &source)
95{
96 //
97 // assignment operator
98 //
99 if (&source == this) return *this;
100 new (this) AliPMDCalibPedestal(source);
101
102 return *this;
103}
104//_____________________________________________________________________
105AliPMDCalibPedestal::~AliPMDCalibPedestal()
106{
107 //
108 // destructor
109 //
24e8f6b2 110}
111//_____________________________________________________________________
112Bool_t AliPMDCalibPedestal::ProcessEvent(AliRawReader *rawReader)
113{
114 //
115 // Event processing loop - AliRawReader
116 //
9d7353e3 117
118 const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
119
722ccc67 120 UInt_t busmcmch;
121 UInt_t pbus, mcm, chno;
122
24e8f6b2 123 AliPMDRawStream rawStream(rawReader);
124
125 TObjArray pmdddlcont;
722ccc67 126 Int_t iddl = -1;
127 Int_t numberofDDLs = 0;
24e8f6b2 128
722ccc67 129 while ((iddl = rawStream.DdlData(&pmdddlcont)) >=0) {
130 numberofDDLs++;
131 Int_t ientries = pmdddlcont.GetEntries();
132 //printf("iddl = %d ientries = %d\n",iddl, ientries);
133 for (Int_t ient = 0; ient < ientries; ient++)
24e8f6b2 134 {
135 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
136
137 Int_t det = pmdddl->GetDetector();
138 Int_t smn = pmdddl->GetSMN();
24e8f6b2 139 Int_t row = pmdddl->GetRow();
140 Int_t col = pmdddl->GetColumn();
0ab3a530 141 Float_t sig = (Float_t) pmdddl->GetSignal();
24e8f6b2 142
722ccc67 143 pbus = (UInt_t) pmdddl->GetPatchBusId();
144 mcm = (UInt_t) pmdddl->GetMCM();
145 chno = (UInt_t) pmdddl->GetChannel();
146
147 busmcmch = 0;
148 AliBitPacking::PackWord(chno,busmcmch,0,7);
149 AliBitPacking::PackWord(mcm,busmcmch,8,15);
150 AliBitPacking::PackWord(pbus,busmcmch,16,23);
151
152
153 if (fPedChain[det][smn][row][col] == 0)
154 fPedChain[det][smn][row][col] = busmcmch;
155
0ab3a530 156 fPedVal[det][smn][row][col] += sig;
157 fPedValSq[det][smn][row][col] += sig*sig;
158 fPedCount[det][smn][row][col]++;
24e8f6b2 159 }
b8064c22 160 pmdddlcont.Delete();
24e8f6b2 161 }
722ccc67 162 if (numberofDDLs < kDDL)
163 return kFALSE;
164 return kTRUE;
24e8f6b2 165}
166//_____________________________________________________________________
167
9d7353e3 168void AliPMDCalibPedestal::Analyse(TTree *pedtree)
24e8f6b2 169{
170 //
171 // Calculate pedestal Mean and RMS
172 //
722ccc67 173
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");
180
181 UInt_t busmcmch;
182 UInt_t pbus, mcm, chno;
183 Int_t ddlno;
0ab3a530 184 Int_t det, sm, row, col;
185 Float_t mean, rms;
186 Float_t meansq, diff;
187
188
722ccc67 189
0ab3a530 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");
196
197 for (int idet = 0; idet < kDet; idet++)
24e8f6b2 198 {
0ab3a530 199 for (int ism = 0; ism < kMaxSMN; ism++)
24e8f6b2 200 {
722ccc67 201 ConvertDDL(idet,ism,ddlno);
0ab3a530 202 for (int irow = 0; irow < kMaxRow; irow++)
24e8f6b2 203 {
0ab3a530 204 for (int icol = 0; icol < kMaxCol; icol++)
24e8f6b2 205 {
0ab3a530 206 det = idet;
207 sm = ism;
208 row = irow;
209 col = icol;
722ccc67 210 mean = 0.;
211 rms = 0.;
212
0ab3a530 213 if (fPedCount[idet][ism][irow][icol] > 0)
214 {
722ccc67 215 mean = fPedVal[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
0ab3a530 216
722ccc67 217 meansq = fPedValSq[idet][ism][irow][icol]/fPedCount[idet][ism][irow][icol];
0ab3a530 218
219 diff = meansq - mean*mean;
220 if (diff > 0.)
221 {
222 rms = sqrt(diff);
223 }
224 else
225 {
226 rms = 0.;
227 }
722ccc67 228 pedtree->Fill();
229
230 busmcmch = fPedChain[idet][ism][irow][icol];
0ab3a530 231
722ccc67 232 chno = busmcmch & 0x00FF;
233 mcm = (busmcmch >> 8) & 0x00FF;
234 pbus = (busmcmch >> 16) & 0x00FF;
235
236 if (ddlno == 0)
237 {
238 fprintf(fpw0,"%d %d %d %f %f\n",
239 pbus, mcm, chno, mean, rms);
240 }
241 else if (ddlno == 1)
242 {
243 fprintf(fpw1,"%d %d %d %f %f\n",
244 pbus, mcm, chno, mean, rms);
245 }
246 else if (ddlno == 2)
247 {
248 fprintf(fpw2,"%d %d %d %f %f\n",
249 pbus, mcm, chno, mean, rms);
250 }
251 else if (ddlno == 3)
252 {
253 fprintf(fpw3,"%d %d %d %f %f\n",
254 pbus, mcm, chno, mean, rms);
255 }
256 else if (ddlno == 4)
257 {
258 fprintf(fpw4,"%d %d %d %f %f\n",
259 pbus, mcm, chno, mean, rms);
260 }
261 else if (ddlno == 5)
262 {
263 fprintf(fpw5,"%d %d %d %f %f\n",
264 pbus, mcm, chno, mean, rms);
265 }
266
267 }
268
24e8f6b2 269 }
270 }
271 }
272 }
722ccc67 273
274 fclose(fpw0);
275 fclose(fpw1);
276 fclose(fpw2);
277 fclose(fpw3);
278 fclose(fpw4);
279 fclose(fpw5);
24e8f6b2 280}
722ccc67 281
282
283// -------------------------------------------------------------------
284
285void AliPMDCalibPedestal::ConvertDDL(Int_t det, Int_t smn, Int_t &ddlno)
286{
287// Given the plane number and serial module number, ddlno is calculated
288
289 if (det == 0)
290 {
291 if (smn <= 5)
292 {
293 ddlno = 0;
294 }
295 else if (smn > 5 && smn <= 11)
296 {
297 ddlno = 1;
298 }
299 else if (smn > 11 && smn <= 17)
300 {
301 ddlno = 2;
302 }
303 else if (smn > 17 && smn <= 23)
304 {
305 ddlno = 3;
306 }
307 }
308 else if (det == 1)
309 {
310 if (smn <= 5 || (smn >= 18 && smn <=23))
311 {
312 ddlno = 4;
313 }
314 else if (smn >= 6 && smn <= 17)
315 {
316 ddlno = 5;
317 }
318 }
319
320}
321