]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PMD/AliPMDRawToSDigits.cxx
* hmpid_digits.C, hmpid_raw.C
[u/mrichter/AliRoot.git] / PMD / AliPMDRawToSDigits.cxx
... / ...
CommitLineData
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{
98 // Converts RAW data to sdigits
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
113// const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
114 const Int_t kRow = 48;
115 const Int_t kCol = 96;
116 const Int_t kSMN = 48;
117
118 Int_t idet = 0;
119 Int_t indexsmn = 0;
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++)
126 {
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++)
132 {
133 for (Int_t k = 0; k < kCol; k++)
134 {
135 precpvADC[i][j][k] = 0;
136 }
137 }
138 }
139
140 AliPMDRawStream pmdinput(rawReader);
141 Int_t indexDDL = -1;
142 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
143 {
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
157 if (indexDDL < 4)
158 {
159 if (det != 0)
160 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
161 indexDDL, det));
162 indexsmn = smn;
163 }
164 else if (indexDDL == 4 || indexDDL == 5)
165 {
166 if (det != 1)
167 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
168 indexDDL, det));
169 indexsmn = smn + 24;
170 }
171
172 precpvADC[indexsmn][row][col] = sig;
173 }
174
175 pmdddlcont.Clear();
176
177 } // DDL Loop
178
179 // Add the sdigits here
180
181 for ( indexsmn = 0; indexsmn < kSMN; indexsmn++)
182 {
183
184 if (indexsmn < 23)
185 {
186 idet = 0;
187 ismn = indexsmn;
188 }
189 else if (indexsmn > 23)
190 {
191 idet = 0;
192 ismn = indexsmn - 24;
193 }
194 for (Int_t irow = 0; irow < kRow; irow++)
195 {
196 for (Int_t icol = 0; icol < kCol; icol++)
197 {
198
199 Int_t trno = -99999; // when extracted from raw data
200 Int_t trpid = -99999; // when extracted from raw data
201 Int_t sig1 = precpvADC[indexsmn][irow][icol];
202
203 // plug in a function to convert to adc to MeV
204 Float_t edep = 0.;
205 if (sig1 > 0)
206 {
207 AdcToMeV(sig1,edep);
208 AddSDigit(trno,trpid,idet,ismn,irow,icol,edep);
209 }
210 } // row
211 } // col
212
213 treeS->Fill();
214 ResetSDigit();
215 }
216
217 pmdLoader->WriteSDigits("OVERWRITE");
218
219 // Delete all the pointers
220
221 for (Int_t i = 0; i < kSMN; i++)
222 {
223 for (Int_t j = 0; j < kRow; j++)
224 {
225 delete [] precpvADC[i][j];
226 }
227 }
228 for (Int_t j = 0; j < kSMN; j++)
229 {
230 delete [] precpvADC[j];
231 }
232 delete [] precpvADC;
233
234}
235// ------------------------------------------------------------------------- //
236void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawReader)
237{
238 // Converts RAW data to digits
239 //
240 TObjArray pmdddlcont;
241
242 AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
243
244 TTree* treeD = pmdLoader->TreeD();
245 if (treeD == 0x0)
246 {
247 pmdLoader->MakeTree("D");
248 treeD = pmdLoader->TreeD();
249 }
250 Int_t bufsize = 16000;
251 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
252 treeD->Branch("PMDDigit", &fDigits, bufsize);
253
254// const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
255 const Int_t kRow = 48;
256 const Int_t kCol = 96;
257 const Int_t kSMN = 48;
258
259 Int_t idet = 0;
260 Int_t ismn = 0;
261 Int_t indexsmn = 0;
262
263 Int_t ***precpvADC;
264 precpvADC = new int **[kSMN];
265 for (Int_t i=0; i<kSMN; i++) precpvADC[i] = new int *[kRow];
266 for (Int_t i=0; i<kSMN;i++)
267 {
268 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
269 }
270 for (Int_t i = 0; i < kSMN; i++)
271 {
272 for (Int_t j = 0; j < kRow; j++)
273 {
274 for (Int_t k = 0; k < kCol; k++)
275 {
276 precpvADC[i][j][k] = 0;
277 }
278 }
279 }
280
281 AliPMDRawStream pmdinput(rawReader);
282 Int_t indexDDL = -1;
283 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
284 {
285 Int_t ientries = pmdddlcont.GetEntries();
286 for (Int_t ient = 0; ient < ientries; ient++)
287 {
288 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
289
290 Int_t det = pmdddl->GetDetector();
291 Int_t smn = pmdddl->GetSMN();
292 //Int_t mcm = pmdddl->GetMCM();
293 //Int_t chno = pmdddl->GetChannel();
294 Int_t row = pmdddl->GetRow();
295 Int_t col = pmdddl->GetColumn();
296 Int_t sig = pmdddl->GetSignal();
297
298
299 if (indexDDL < 4)
300 {
301 if (det != 0)
302 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
303 indexDDL, det));
304 indexsmn = smn ;
305 }
306 else if (indexDDL == 4 || indexDDL == 5)
307 {
308 if (det != 1)
309 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
310 indexDDL, det));
311 indexsmn = smn + 24;
312 }
313 precpvADC[indexsmn][row][col] = sig;
314 }
315
316 pmdddlcont.Clear();
317 } // DDL Loop
318
319 // Add the digits here
320 for (indexsmn = 0; indexsmn < kSMN; indexsmn++)
321 {
322 if (indexsmn < 23)
323 {
324 ismn = indexsmn;
325 idet = 0;
326 }
327 else if (indexsmn > 23)
328 {
329 ismn = indexsmn -24;
330 idet = 1;
331 }
332 for (Int_t irow = 0; irow < kRow; irow++)
333 {
334 for (Int_t icol = 0; icol < kCol; icol++)
335 {
336 Int_t trno = -99999; // when extracted from raw
337 Int_t trpid = -99999; // when extracted from raw
338 Int_t sig1 = precpvADC[indexsmn][irow][icol];
339
340 // plug in a function to convert to adc to MeV
341 if (sig1 > 0)
342 {
343 AddDigit(trno,trpid,idet,ismn,irow,icol,sig1);
344 }
345 } // row
346 } // col
347 treeD->Fill();
348 ResetDigit();
349 }
350
351 pmdLoader->WriteDigits("OVERWRITE");
352
353 // Delete all the pointers
354
355 for (Int_t i = 0; i < kSMN; i++)
356 {
357 for (Int_t j = 0; j < kRow; j++)
358 {
359 delete [] precpvADC[i][j];
360 }
361 }
362 for (Int_t j = 0; j < kSMN; j++)
363 {
364 delete [] precpvADC[j];
365 }
366 delete [] precpvADC;
367}
368// ------------------------------------------------------------------------- //
369
370void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep)
371{
372 // To be implemented, this is just for the test
373
374 const Float_t kConstant = 7.181;
375 // const Float_t kErConstant = 0.6899;
376 const Float_t kSlope = 35.93;
377 // const Float_t kErSlope = 0.306;
378
379
380
381 Float_t adc10bit = (Float_t) adc/4;
382 edep = (1000.0/kSlope)*(adc10bit - kConstant);
383}
384
385// ------------------------------------------------------------------------- //
386
387void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
388 Int_t smnumber,
389 Int_t irow, Int_t icol, Float_t adc)
390{
391 // Add SDigit
392 //
393 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
394 TClonesArray &lsdigits = *fSDigits;
395 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
396}
397
398// ------------------------------------------------------------------------- //
399void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
400 Int_t smnumber,
401 Int_t irow, Int_t icol, Float_t adc)
402{
403 // Add Digit
404 //
405 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
406 TClonesArray &ldigits = *fDigits;
407 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
408}
409
410// ------------------------------------------------------------------------- //
411void AliPMDRawToSDigits::ResetSDigit()
412{
413 // Clears SDigits
414 fNsdigit = 0;
415 if (fSDigits) fSDigits->Clear();
416}
417// ------------------------------------------------------------------------- //
418void AliPMDRawToSDigits::ResetDigit()
419{
420 // Clears SDigits
421 fNdigit = 0;
422 if (fDigits) fDigits->Clear();
423}