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