Preprocessor modified not to send the correct gain file
[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
920e13db 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];
93622f4a 202
203 // plug in a function to convert to adc to MeV
204 Float_t edep = 0.;
205 if (sig1 > 0)
1d9f57cc 206 {
93622f4a 207 AdcToMeV(sig1,edep);
920e13db 208 AddSDigit(trno,trpid,idet,ismn,irow,icol,edep);
93622f4a 209 }
210 } // row
211 } // col
212
213 treeS->Fill();
214 ResetSDigit();
215 }
1d9f57cc 216
217 pmdLoader->WriteSDigits("OVERWRITE");
93622f4a 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;
1d9f57cc 233
234}
235// ------------------------------------------------------------------------- //
236void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawReader)
237{
238 // Converts RAW data to digits
239 //
240 TObjArray pmdddlcont;
93622f4a 241
1d9f57cc 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);
93622f4a 253
722ccc67 254// const Int_t kDDL = AliDAQ::NumberOfDdls("PMD");
1d9f57cc 255 const Int_t kRow = 48;
256 const Int_t kCol = 96;
93622f4a 257 const Int_t kSMN = 48;
258
1d9f57cc 259 Int_t idet = 0;
93622f4a 260 Int_t ismn = 0;
1d9f57cc 261 Int_t indexsmn = 0;
93622f4a 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++)
1d9f57cc 267 {
93622f4a 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++)
1d9f57cc 273 {
93622f4a 274 for (Int_t k = 0; k < kCol; k++)
1d9f57cc 275 {
93622f4a 276 precpvADC[i][j][k] = 0;
1d9f57cc 277 }
278 }
93622f4a 279 }
722ccc67 280
281 AliPMDRawStream pmdinput(rawReader);
282 Int_t indexDDL = -1;
283 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
284 {
1d9f57cc 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));
93622f4a 304 indexsmn = smn ;
1d9f57cc 305 }
93622f4a 306 else if (indexDDL == 4 || indexDDL == 5)
1d9f57cc 307 {
308 if (det != 1)
309 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
310 indexDDL, det));
93622f4a 311 indexsmn = smn + 24;
1d9f57cc 312 }
313 precpvADC[indexsmn][row][col] = sig;
314 }
315
316 pmdddlcont.Clear();
93622f4a 317 } // DDL Loop
1d9f57cc 318
93622f4a 319 // Add the digits here
320 for (indexsmn = 0; indexsmn < kSMN; indexsmn++)
321 {
722ccc67 322 if (indexsmn < 23)
1d9f57cc 323 {
93622f4a 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++)
1d9f57cc 335 {
920e13db 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];
93622f4a 339
340 // plug in a function to convert to adc to MeV
341 if (sig1 > 0)
1d9f57cc 342 {
920e13db 343 AddDigit(trno,trpid,idet,ismn,irow,icol,sig1);
1d9f57cc 344 }
93622f4a 345 } // row
346 } // col
347 treeD->Fill();
348 ResetDigit();
349 }
1d9f57cc 350
351 pmdLoader->WriteDigits("OVERWRITE");
352
93622f4a 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;
1d9f57cc 367}
368// ------------------------------------------------------------------------- //
369
370void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep)
371{
372 // To be implemented, this is just for the test
373
722ccc67 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;
1d9f57cc 378
379
380
722ccc67 381 Float_t adc10bit = (Float_t) adc/4;
382 edep = (1000.0/kSlope)*(adc10bit - kConstant);
1d9f57cc 383}
384
722ccc67 385// ------------------------------------------------------------------------- //
1d9f57cc 386
920e13db 387void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
388 Int_t smnumber,
1d9f57cc 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;
920e13db 395 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
1d9f57cc 396}
397
398// ------------------------------------------------------------------------- //
920e13db 399void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
400 Int_t smnumber,
1d9f57cc 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;
920e13db 407 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
1d9f57cc 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}