]>
Commit | Line | Data |
---|---|---|
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 | ||
41 | ClassImp(AliPMDRawToSDigits) | |
42 | ||
43 | AliPMDRawToSDigits::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 | // ------------------------------------------------------------------------- // | |
55 | AliPMDRawToSDigits::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 | ||
68 | AliPMDRawToSDigits &AliPMDRawToSDigits::operator=(const AliPMDRawToSDigits &/* pmdr2sd */) | |
69 | { | |
70 | // assignment operator | |
71 | AliFatal("Assignment operator not implemented"); | |
72 | return *this; | |
73 | } | |
74 | ||
75 | // ------------------------------------------------------------------------- // | |
76 | ||
77 | AliPMDRawToSDigits::~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 | ||
96 | void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawReader) | |
97 | { | |
98 | // Converts RAW data to digits | |
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 | ||
117 | Int_t idet = 0; | |
118 | Int_t iSMN = 0; | |
119 | Int_t indexsmn = 0; | |
120 | ||
121 | for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++) | |
122 | { | |
123 | ||
124 | if (indexDDL < 4) | |
125 | { | |
126 | iSMN = 6; | |
127 | } | |
128 | else if (indexDDL >= 4) | |
129 | { | |
130 | iSMN = 12; | |
131 | } | |
132 | Int_t ***precpvADC; | |
133 | precpvADC = new int **[iSMN]; | |
134 | for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow]; | |
135 | for (Int_t i=0; i<iSMN;i++) | |
136 | { | |
137 | for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol]; | |
138 | } | |
139 | for (Int_t i = 0; i < iSMN; i++) | |
140 | { | |
141 | for (Int_t j = 0; j < kRow; j++) | |
142 | { | |
143 | for (Int_t k = 0; k < kCol; k++) | |
144 | { | |
145 | precpvADC[i][j][k] = 0; | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | rawReader->Reset(); | |
151 | AliPMDRawStream pmdinput(rawReader); | |
152 | rawReader->Select("PMD", indexDDL, indexDDL); | |
153 | ||
154 | pmdinput.DdlData(indexDDL,&pmdddlcont); | |
155 | ||
156 | Int_t ientries = pmdddlcont.GetEntries(); | |
157 | for (Int_t ient = 0; ient < ientries; ient++) | |
158 | { | |
159 | AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient); | |
160 | ||
161 | Int_t det = pmdddl->GetDetector(); | |
162 | Int_t smn = pmdddl->GetSMN(); | |
163 | //Int_t mcm = pmdddl->GetMCM(); | |
164 | //Int_t chno = pmdddl->GetChannel(); | |
165 | Int_t row = pmdddl->GetRow(); | |
166 | Int_t col = pmdddl->GetColumn(); | |
167 | Int_t sig = pmdddl->GetSignal(); | |
168 | ||
169 | ||
170 | if (indexDDL < 4) | |
171 | { | |
172 | if (det != 0) | |
173 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
174 | indexDDL, det)); | |
175 | indexsmn = smn - indexDDL * 6; | |
176 | } | |
177 | else if (indexDDL == 4) | |
178 | { | |
179 | if (det != 1) | |
180 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
181 | indexDDL, det)); | |
182 | if (smn < 6) | |
183 | { | |
184 | indexsmn = smn; | |
185 | } | |
186 | else if (smn >= 18 && smn < 24) | |
187 | { | |
188 | indexsmn = smn - 12; | |
189 | } | |
190 | } | |
191 | else if (indexDDL == 5) | |
192 | { | |
193 | if (det != 1) | |
194 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
195 | indexDDL, det)); | |
196 | if (smn >= 6 && smn < 12) | |
197 | { | |
198 | indexsmn = smn - 6; | |
199 | } | |
200 | else if (smn >= 12 && smn < 18) | |
201 | { | |
202 | indexsmn = smn - 6; | |
203 | } | |
204 | } | |
205 | precpvADC[indexsmn][row][col] = sig; | |
206 | } | |
207 | ||
208 | pmdddlcont.Clear(); | |
209 | ||
210 | // Add the sdigits here | |
211 | ||
212 | Int_t ismn = 0; | |
213 | for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++) | |
214 | { | |
215 | if (indexDDL < 4) | |
216 | { | |
217 | ismn = indexsmn + indexDDL * 6; | |
218 | idet = 0; | |
219 | } | |
220 | else if (indexDDL == 4) | |
221 | { | |
222 | if (indexsmn < 6) | |
223 | { | |
224 | ismn = indexsmn; | |
225 | } | |
226 | else if (indexsmn >= 6 && indexsmn < 12) | |
227 | { | |
228 | ismn = indexsmn + 12; | |
229 | } | |
230 | idet = 1; | |
231 | } | |
232 | else if (indexDDL == 5) | |
233 | { | |
234 | if (indexsmn < 6) | |
235 | { | |
236 | ismn = indexsmn + 6; | |
237 | } | |
238 | else if (indexsmn >= 6 && indexsmn < 12) | |
239 | { | |
240 | ismn = indexsmn + 6; | |
241 | } | |
242 | idet = 1; | |
243 | } | |
244 | ||
245 | for (Int_t irow = 0; irow < kRow; irow++) | |
246 | { | |
247 | for (Int_t icol = 0; icol < kCol; icol++) | |
248 | { | |
249 | ||
250 | Int_t trno = -99999; | |
251 | Int_t sig1 = precpvADC[indexsmn][irow][icol]; | |
252 | ||
253 | // plug in a function to convert to adc to MeV | |
254 | Float_t edep = 0.; | |
255 | if (sig1 > 0) | |
256 | { | |
257 | AdcToMeV(sig1,edep); | |
258 | AddSDigit(trno,idet,ismn,irow,icol,edep); | |
259 | } | |
260 | } // row | |
261 | } // col | |
262 | ||
263 | treeS->Fill(); | |
264 | ResetSDigit(); | |
265 | } | |
266 | } // DDL Loop | |
267 | ||
268 | pmdLoader->WriteSDigits("OVERWRITE"); | |
269 | ||
270 | } | |
271 | // ------------------------------------------------------------------------- // | |
272 | void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawReader) | |
273 | { | |
274 | // Converts RAW data to digits | |
275 | // | |
276 | TObjArray pmdddlcont; | |
277 | ||
278 | AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader"); | |
279 | ||
280 | TTree* treeD = pmdLoader->TreeD(); | |
281 | if (treeD == 0x0) | |
282 | { | |
283 | pmdLoader->MakeTree("D"); | |
284 | treeD = pmdLoader->TreeD(); | |
285 | } | |
286 | Int_t bufsize = 16000; | |
287 | if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000); | |
288 | treeD->Branch("PMDDigit", &fDigits, bufsize); | |
289 | ||
290 | const Int_t kDDL = AliDAQ::NumberOfDdls("PMD"); | |
291 | const Int_t kRow = 48; | |
292 | const Int_t kCol = 96; | |
293 | ||
294 | Int_t idet = 0; | |
295 | Int_t iSMN = 0; | |
296 | Int_t indexsmn = 0; | |
297 | ||
298 | for (Int_t indexDDL = 0; indexDDL < kDDL; indexDDL++) | |
299 | { | |
300 | ||
301 | if (indexDDL < 4) | |
302 | { | |
303 | iSMN = 6; | |
304 | } | |
305 | else if (indexDDL >= 4) | |
306 | { | |
307 | iSMN = 12; | |
308 | } | |
309 | Int_t ***precpvADC; | |
310 | precpvADC = new int **[iSMN]; | |
311 | for (Int_t i=0; i<iSMN; i++) precpvADC[i] = new int *[kRow]; | |
312 | for (Int_t i=0; i<iSMN;i++) | |
313 | { | |
314 | for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol]; | |
315 | } | |
316 | for (Int_t i = 0; i < iSMN; i++) | |
317 | { | |
318 | for (Int_t j = 0; j < kRow; j++) | |
319 | { | |
320 | for (Int_t k = 0; k < kCol; k++) | |
321 | { | |
322 | precpvADC[i][j][k] = 0; | |
323 | } | |
324 | } | |
325 | } | |
326 | ||
327 | rawReader->Reset(); | |
328 | AliPMDRawStream pmdinput(rawReader); | |
329 | rawReader->Select("PMD", indexDDL, indexDDL); | |
330 | ||
331 | //pmdinput.DdlData(&pmdddlcont); | |
332 | pmdinput.DdlData(indexDDL,&pmdddlcont); | |
333 | ||
334 | ||
335 | Int_t ientries = pmdddlcont.GetEntries(); | |
336 | for (Int_t ient = 0; ient < ientries; ient++) | |
337 | { | |
338 | AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient); | |
339 | ||
340 | Int_t det = pmdddl->GetDetector(); | |
341 | Int_t smn = pmdddl->GetSMN(); | |
342 | //Int_t mcm = pmdddl->GetMCM(); | |
343 | //Int_t chno = pmdddl->GetChannel(); | |
344 | Int_t row = pmdddl->GetRow(); | |
345 | Int_t col = pmdddl->GetColumn(); | |
346 | Int_t sig = pmdddl->GetSignal(); | |
347 | ||
348 | ||
349 | if (indexDDL < 4) | |
350 | { | |
351 | if (det != 0) | |
352 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
353 | indexDDL, det)); | |
354 | indexsmn = smn - indexDDL * 6; | |
355 | } | |
356 | else if (indexDDL == 4) | |
357 | { | |
358 | if (det != 1) | |
359 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
360 | indexDDL, det)); | |
361 | if (smn < 6) | |
362 | { | |
363 | indexsmn = smn; | |
364 | } | |
365 | else if (smn >= 18 && smn < 24) | |
366 | { | |
367 | indexsmn = smn - 12; | |
368 | } | |
369 | } | |
370 | else if (indexDDL == 5) | |
371 | { | |
372 | if (det != 1) | |
373 | AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *", | |
374 | indexDDL, det)); | |
375 | if (smn >= 6 && smn < 12) | |
376 | { | |
377 | indexsmn = smn - 6; | |
378 | } | |
379 | else if (smn >= 12 && smn < 18) | |
380 | { | |
381 | indexsmn = smn - 6; | |
382 | } | |
383 | } | |
384 | precpvADC[indexsmn][row][col] = sig; | |
385 | } | |
386 | ||
387 | pmdddlcont.Clear(); | |
388 | ||
389 | // Add the digits here | |
390 | ||
391 | Int_t ismn = 0; | |
392 | for (Int_t indexsmn = 0; indexsmn < iSMN; indexsmn++) | |
393 | { | |
394 | if (indexDDL < 4) | |
395 | { | |
396 | ismn = indexsmn + indexDDL * 6; | |
397 | idet = 0; | |
398 | } | |
399 | else if (indexDDL == 4) | |
400 | { | |
401 | if (indexsmn < 6) | |
402 | { | |
403 | ismn = indexsmn; | |
404 | } | |
405 | else if (indexsmn >= 6 && indexsmn < 12) | |
406 | { | |
407 | ismn = indexsmn + 12; | |
408 | } | |
409 | idet = 1; | |
410 | } | |
411 | else if (indexDDL == 5) | |
412 | { | |
413 | if (indexsmn < 6) | |
414 | { | |
415 | ismn = indexsmn + 6; | |
416 | } | |
417 | else if (indexsmn >= 6 && indexsmn < 12) | |
418 | { | |
419 | ismn = indexsmn + 6; | |
420 | } | |
421 | idet = 1; | |
422 | } | |
423 | ||
424 | for (Int_t irow = 0; irow < kRow; irow++) | |
425 | { | |
426 | for (Int_t icol = 0; icol < kCol; icol++) | |
427 | { | |
428 | Int_t trno = -99999; | |
429 | Int_t sig1 = precpvADC[indexsmn][irow][icol]; | |
430 | ||
431 | // plug in a function to convert to adc to MeV | |
432 | if (sig1 > 0) | |
433 | { | |
434 | AddDigit(trno,idet,ismn,irow,icol,sig1); | |
435 | } | |
436 | } // row | |
437 | } // col | |
438 | treeD->Fill(); | |
439 | ResetDigit(); | |
440 | } | |
441 | ||
442 | } // DDL Loop | |
443 | ||
444 | pmdLoader->WriteDigits("OVERWRITE"); | |
445 | ||
446 | } | |
447 | // ------------------------------------------------------------------------- // | |
448 | ||
449 | void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep) | |
450 | { | |
451 | // To be implemented, this is just for the test | |
452 | ||
453 | const Float_t kConstant = 7.181; | |
454 | // const Float_t kErConstant = 0.6899; | |
455 | const Float_t kSlope = 35.93; | |
456 | // const Float_t kErSlope = 0.306; | |
457 | ||
458 | ||
459 | ||
460 | Float_t adc10bit = (Float_t) adc/4; | |
461 | edep = (1000.0/kSlope)*(adc10bit - kConstant); | |
462 | } | |
463 | ||
464 | // ------------------------------------------------------------------------- // | |
465 | ||
466 | void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t det, Int_t smnumber, | |
467 | Int_t irow, Int_t icol, Float_t adc) | |
468 | { | |
469 | // Add SDigit | |
470 | // | |
471 | if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000); | |
472 | TClonesArray &lsdigits = *fSDigits; | |
473 | new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,det,smnumber,irow,icol,adc); | |
474 | } | |
475 | ||
476 | // ------------------------------------------------------------------------- // | |
477 | void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t det, Int_t smnumber, | |
478 | Int_t irow, Int_t icol, Float_t adc) | |
479 | { | |
480 | // Add Digit | |
481 | // | |
482 | if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000); | |
483 | TClonesArray &ldigits = *fDigits; | |
484 | new(ldigits[fNdigit++]) AliPMDdigit(trnumber,det,smnumber,irow,icol,adc); | |
485 | } | |
486 | ||
487 | // ------------------------------------------------------------------------- // | |
488 | void AliPMDRawToSDigits::ResetSDigit() | |
489 | { | |
490 | // Clears SDigits | |
491 | fNsdigit = 0; | |
492 | if (fSDigits) fSDigits->Clear(); | |
493 | } | |
494 | // ------------------------------------------------------------------------- // | |
495 | void AliPMDRawToSDigits::ResetDigit() | |
496 | { | |
497 | // Clears SDigits | |
498 | fNdigit = 0; | |
499 | if (fDigits) fDigits->Clear(); | |
500 | } |