]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PMD/AliPMDRawToSDigits.cxx
QA update by Sylwester
[u/mrichter/AliRoot.git] / PMD / AliPMDRawToSDigits.cxx
CommitLineData
1d9f57cc 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// //
18// Date : October 09 2006 //
19// converts raw to sdigit and digit //
20// //
21//-----------------------------------------------------//
22
23#include <Riostream.h>
24#include <TTree.h>
25#include <TObjArray.h>
26#include <TClonesArray.h>
27
28#include "AliDAQ.h"
29#include "AliLog.h"
30#include "AliRunLoader.h"
31#include "AliLoader.h"
32#include "AliRawReader.h"
33
34#include "AliPMDsdigit.h"
35#include "AliPMDdigit.h"
36#include "AliPMDRawToSDigits.h"
37#include "AliPMDRawStream.h"
38#include "AliPMDddldata.h"
39
40
41ClassImp(AliPMDRawToSDigits)
42
43AliPMDRawToSDigits::AliPMDRawToSDigits():
44 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
45 fDigits(new TClonesArray("AliPMDdigit", 1000)),
46 fNsdigit(0),
47 fNdigit(0)
48{
49 //
50// Constructor
51//
52
53}
54// ------------------------------------------------------------------------- //
55AliPMDRawToSDigits::AliPMDRawToSDigits(const AliPMDRawToSDigits & /*pmdr2sd*/):
56 TObject(/* pmdr2sd */),
57 fSDigits(NULL),
58 fDigits(NULL),
59 fNsdigit(0),
60 fNdigit(0)
61{
62 // copy constructor
63 AliFatal("Copy constructor not implemented");
64}
65// ------------------------------------------------------------------------- //
66
67
68AliPMDRawToSDigits &AliPMDRawToSDigits::operator=(const AliPMDRawToSDigits &/* pmdr2sd */)
69{
70 // assignment operator
71 AliFatal("Assignment operator not implemented");
72 return *this;
73}
74
75// ------------------------------------------------------------------------- //
76
77AliPMDRawToSDigits::~AliPMDRawToSDigits()
78{
79 // Destructor
80 if (fSDigits)
81 {
82 fSDigits->Delete();
83 delete fSDigits;
84 fSDigits=0;
85 }
86 if (fDigits)
87 {
88 fDigits->Delete();
89 delete fDigits;
90 fDigits=0;
91 }
92
93}
94// ------------------------------------------------------------------------- //
95
96void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawReader)
97{
93622f4a 98 // Converts RAW data to sdigits
1d9f57cc 99 //
100 TObjArray pmdddlcont;
101 AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
102
103 TTree* treeS = pmdLoader->TreeS();
104 if (treeS == 0x0)
105 {
106 pmdLoader->MakeTree("S");
107 treeS = pmdLoader->TreeS();
108 }
109 Int_t bufsize = 16000;
110 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
111 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
112
722ccc67 113// const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
1d9f57cc 114 const Int_t kRow = 48;
115 const Int_t kCol = 96;
93622f4a 116 const Int_t kSMN = 48;
1d9f57cc 117
118 Int_t idet = 0;
1d9f57cc 119 Int_t indexsmn = 0;
93622f4a 120 Int_t ismn = 0;
121
122 Int_t ***precpvADC;
123 precpvADC = new int **[kSMN];
124 for (Int_t i=0; i<kSMN; i++) precpvADC[i] = new int *[kRow];
125 for (Int_t i=0; i<kSMN;i++)
1d9f57cc 126 {
93622f4a 127 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
128 }
129 for (Int_t i = 0; i < kSMN; i++)
130 {
131 for (Int_t j = 0; j < kRow; j++)
1d9f57cc 132 {
93622f4a 133 for (Int_t k = 0; k < kCol; k++)
1d9f57cc 134 {
93622f4a 135 precpvADC[i][j][k] = 0;
1d9f57cc 136 }
137 }
93622f4a 138 }
139
722ccc67 140 AliPMDRawStream pmdinput(rawReader);
141 Int_t indexDDL = -1;
142 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
143 {
1d9f57cc 144 Int_t ientries = pmdddlcont.GetEntries();
145 for (Int_t ient = 0; ient < ientries; ient++)
146 {
147 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
148
149 Int_t det = pmdddl->GetDetector();
150 Int_t smn = pmdddl->GetSMN();
151 //Int_t mcm = pmdddl->GetMCM();
152 //Int_t chno = pmdddl->GetChannel();
153 Int_t row = pmdddl->GetRow();
154 Int_t col = pmdddl->GetColumn();
155 Int_t sig = pmdddl->GetSignal();
156
1d9f57cc 157 if (indexDDL < 4)
158 {
159 if (det != 0)
160 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
161 indexDDL, det));
93622f4a 162 indexsmn = smn;
1d9f57cc 163 }
93622f4a 164 else if (indexDDL == 4 || indexDDL == 5)
1d9f57cc 165 {
166 if (det != 1)
167 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
168 indexDDL, det));
93622f4a 169 indexsmn = smn + 24;
1d9f57cc 170 }
93622f4a 171
1d9f57cc 172 precpvADC[indexsmn][row][col] = sig;
173 }
174
175 pmdddlcont.Clear();
176
93622f4a 177 } // DDL Loop
178
179 // Add the sdigits here
180
181 for ( indexsmn = 0; indexsmn < kSMN; indexsmn++)
182 {
1d9f57cc 183
722ccc67 184 if (indexsmn < 23)
1d9f57cc 185 {
93622f4a 186 idet = 0;
187 ismn = indexsmn;
188 }
189 else if (indexsmn > 23)
190 {
722ccc67 191 idet = 0;
93622f4a 192 ismn = indexsmn - 24;
193 }
194 for (Int_t irow = 0; irow < kRow; irow++)
195 {
196 for (Int_t icol = 0; icol < kCol; icol++)
1d9f57cc 197 {
1d9f57cc 198
93622f4a 199 Int_t trno = -99999;
200 Int_t sig1 = precpvADC[indexsmn][irow][icol];
201
202 // plug in a function to convert to adc to MeV
203 Float_t edep = 0.;
204 if (sig1 > 0)
1d9f57cc 205 {
93622f4a 206 AdcToMeV(sig1,edep);
207 AddSDigit(trno,idet,ismn,irow,icol,edep);
208 }
209 } // row
210 } // col
211
212 treeS->Fill();
213 ResetSDigit();
214 }
1d9f57cc 215
216 pmdLoader->WriteSDigits("OVERWRITE");
93622f4a 217
218 // Delete all the pointers
219
220 for (Int_t i = 0; i < kSMN; i++)
221 {
222 for (Int_t j = 0; j < kRow; j++)
223 {
224 delete [] precpvADC[i][j];
225 }
226 }
227 for (Int_t j = 0; j < kSMN; j++)
228 {
229 delete [] precpvADC[j];
230 }
231 delete [] precpvADC;
1d9f57cc 232
233}
234// ------------------------------------------------------------------------- //
235void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawReader)
236{
237 // Converts RAW data to digits
238 //
239 TObjArray pmdddlcont;
93622f4a 240
1d9f57cc 241 AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
242
243 TTree* treeD = pmdLoader->TreeD();
244 if (treeD == 0x0)
245 {
246 pmdLoader->MakeTree("D");
247 treeD = pmdLoader->TreeD();
248 }
249 Int_t bufsize = 16000;
250 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
251 treeD->Branch("PMDDigit", &fDigits, bufsize);
93622f4a 252
722ccc67 253// const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
1d9f57cc 254 const Int_t kRow = 48;
255 const Int_t kCol = 96;
93622f4a 256 const Int_t kSMN = 48;
257
1d9f57cc 258 Int_t idet = 0;
93622f4a 259 Int_t ismn = 0;
1d9f57cc 260 Int_t indexsmn = 0;
93622f4a 261
262 Int_t ***precpvADC;
263 precpvADC = new int **[kSMN];
264 for (Int_t i=0; i<kSMN; i++) precpvADC[i] = new int *[kRow];
265 for (Int_t i=0; i<kSMN;i++)
1d9f57cc 266 {
93622f4a 267 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
268 }
269 for (Int_t i = 0; i < kSMN; i++)
270 {
271 for (Int_t j = 0; j < kRow; j++)
1d9f57cc 272 {
93622f4a 273 for (Int_t k = 0; k < kCol; k++)
1d9f57cc 274 {
93622f4a 275 precpvADC[i][j][k] = 0;
1d9f57cc 276 }
277 }
93622f4a 278 }
722ccc67 279
280 AliPMDRawStream pmdinput(rawReader);
281 Int_t indexDDL = -1;
282 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
283 {
1d9f57cc 284 Int_t ientries = pmdddlcont.GetEntries();
285 for (Int_t ient = 0; ient < ientries; ient++)
286 {
287 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
288
289 Int_t det = pmdddl->GetDetector();
290 Int_t smn = pmdddl->GetSMN();
291 //Int_t mcm = pmdddl->GetMCM();
292 //Int_t chno = pmdddl->GetChannel();
293 Int_t row = pmdddl->GetRow();
294 Int_t col = pmdddl->GetColumn();
295 Int_t sig = pmdddl->GetSignal();
296
297
298 if (indexDDL < 4)
299 {
300 if (det != 0)
301 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
302 indexDDL, det));
93622f4a 303 indexsmn = smn ;
1d9f57cc 304 }
93622f4a 305 else if (indexDDL == 4 || indexDDL == 5)
1d9f57cc 306 {
307 if (det != 1)
308 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
309 indexDDL, det));
93622f4a 310 indexsmn = smn + 24;
1d9f57cc 311 }
312 precpvADC[indexsmn][row][col] = sig;
313 }
314
315 pmdddlcont.Clear();
93622f4a 316 } // DDL Loop
1d9f57cc 317
93622f4a 318 // Add the digits here
319 for (indexsmn = 0; indexsmn < kSMN; indexsmn++)
320 {
722ccc67 321 if (indexsmn < 23)
1d9f57cc 322 {
93622f4a 323 ismn = indexsmn;
324 idet = 0;
325 }
326 else if (indexsmn > 23)
327 {
328 ismn = indexsmn -24;
329 idet = 1;
330 }
331 for (Int_t irow = 0; irow < kRow; irow++)
332 {
333 for (Int_t icol = 0; icol < kCol; icol++)
1d9f57cc 334 {
93622f4a 335 Int_t trno = -99999;
336 Int_t sig1 = precpvADC[indexsmn][irow][icol];
337
338 // plug in a function to convert to adc to MeV
339 if (sig1 > 0)
1d9f57cc 340 {
93622f4a 341 AddDigit(trno,idet,ismn,irow,icol,sig1);
1d9f57cc 342 }
93622f4a 343 } // row
344 } // col
345 treeD->Fill();
346 ResetDigit();
347 }
1d9f57cc 348
349 pmdLoader->WriteDigits("OVERWRITE");
350
93622f4a 351 // Delete all the pointers
352
353 for (Int_t i = 0; i < kSMN; i++)
354 {
355 for (Int_t j = 0; j < kRow; j++)
356 {
357 delete [] precpvADC[i][j];
358 }
359 }
360 for (Int_t j = 0; j < kSMN; j++)
361 {
362 delete [] precpvADC[j];
363 }
364 delete [] precpvADC;
1d9f57cc 365}
366// ------------------------------------------------------------------------- //
367
368void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep)
369{
370 // To be implemented, this is just for the test
371
722ccc67 372 const Float_t kConstant = 7.181;
373 // const Float_t kErConstant = 0.6899;
374 const Float_t kSlope = 35.93;
375 // const Float_t kErSlope = 0.306;
1d9f57cc 376
377
378
722ccc67 379 Float_t adc10bit = (Float_t) adc/4;
380 edep = (1000.0/kSlope)*(adc10bit - kConstant);
1d9f57cc 381}
382
722ccc67 383// ------------------------------------------------------------------------- //
1d9f57cc 384
385void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber,
386 Int_t irow, Int_t icol, Float_t adc)
387{
388 // Add SDigit
389 //
390 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
391 TClonesArray &lsdigits = *fSDigits;
392 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc);
393}
394
395// ------------------------------------------------------------------------- //
396void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber,
397 Int_t irow, Int_t icol, Float_t adc)
398{
399 // Add Digit
400 //
401 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
402 TClonesArray &ldigits = *fDigits;
403 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc);
404}
405
406// ------------------------------------------------------------------------- //
407void AliPMDRawToSDigits::ResetSDigit()
408{
409 // Clears SDigits
410 fNsdigit = 0;
411 if (fSDigits) fSDigits->Clear();
412}
413// ------------------------------------------------------------------------- //
414void AliPMDRawToSDigits::ResetDigit()
415{
416 // Clears SDigits
417 fNdigit = 0;
418 if (fDigits) fDigits->Clear();
419}