1 /***************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //-----------------------------------------------------//
18 // Date : October 09 2006 //
19 // converts raw to sdigit and digit //
21 //-----------------------------------------------------//
23 #include <Riostream.h>
25 #include <TObjArray.h>
26 #include <TClonesArray.h>
30 #include "AliRunLoader.h"
31 #include "AliLoader.h"
32 #include "AliRawReader.h"
34 #include "AliPMDsdigit.h"
35 #include "AliPMDdigit.h"
36 #include "AliPMDRawToSDigits.h"
37 #include "AliPMDRawStream.h"
38 #include "AliPMDddldata.h"
41 ClassImp(AliPMDRawToSDigits)
43 AliPMDRawToSDigits::AliPMDRawToSDigits():
44 fSDigits(new TClonesArray("AliPMDsdigit", 1000)),
45 fDigits(new TClonesArray("AliPMDdigit", 1000)),
54 // ------------------------------------------------------------------------- //
55 AliPMDRawToSDigits::AliPMDRawToSDigits(const AliPMDRawToSDigits & /*pmdr2sd*/):
56 TObject(/* pmdr2sd */),
63 AliFatal("Copy constructor not implemented");
65 // ------------------------------------------------------------------------- //
68 AliPMDRawToSDigits &AliPMDRawToSDigits::operator=(const AliPMDRawToSDigits &/* pmdr2sd */)
70 // assignment operator
71 AliFatal("Assignment operator not implemented");
75 // ------------------------------------------------------------------------- //
77 AliPMDRawToSDigits::~AliPMDRawToSDigits()
94 // ------------------------------------------------------------------------- //
96 void AliPMDRawToSDigits::Raw2SDigits(AliRunLoader *runLoader, AliRawReader *rawReader)
98 // Converts RAW data to sdigits
100 TObjArray pmdddlcont;
101 AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
103 TTree* treeS = pmdLoader->TreeS();
106 pmdLoader->MakeTree("S");
107 treeS = pmdLoader->TreeS();
109 Int_t bufsize = 16000;
110 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
111 treeS->Branch("PMDSDigit", &fSDigits, bufsize);
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;
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++)
127 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
129 for (Int_t i = 0; i < kSMN; i++)
131 for (Int_t j = 0; j < kRow; j++)
133 for (Int_t k = 0; k < kCol; k++)
135 precpvADC[i][j][k] = 0;
140 AliPMDRawStream pmdinput(rawReader);
142 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
144 Int_t ientries = pmdddlcont.GetEntries();
145 for (Int_t ient = 0; ient < ientries; ient++)
147 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
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();
160 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
164 else if (indexDDL == 4 || indexDDL == 5)
167 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
172 precpvADC[indexsmn][row][col] = sig;
179 // Add the sdigits here
181 for ( indexsmn = 0; indexsmn < kSMN; indexsmn++)
189 else if (indexsmn > 23)
192 ismn = indexsmn - 24;
194 for (Int_t irow = 0; irow < kRow; irow++)
196 for (Int_t icol = 0; icol < kCol; icol++)
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];
203 // plug in a function to convert to adc to MeV
208 AddSDigit(trno,trpid,idet,ismn,irow,icol,edep);
217 pmdLoader->WriteSDigits("OVERWRITE");
219 // Delete all the pointers
221 for (Int_t i = 0; i < kSMN; i++)
223 for (Int_t j = 0; j < kRow; j++)
225 delete [] precpvADC[i][j];
228 for (Int_t j = 0; j < kSMN; j++)
230 delete [] precpvADC[j];
235 // ------------------------------------------------------------------------- //
236 void AliPMDRawToSDigits::Raw2Digits(AliRunLoader *runLoader, AliRawReader *rawReader)
238 // Converts RAW data to digits
240 TObjArray pmdddlcont;
242 AliLoader *pmdLoader = runLoader->GetLoader("PMDLoader");
244 TTree* treeD = pmdLoader->TreeD();
247 pmdLoader->MakeTree("D");
248 treeD = pmdLoader->TreeD();
250 Int_t bufsize = 16000;
251 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
252 treeD->Branch("PMDDigit", &fDigits, bufsize);
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;
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++)
268 for (Int_t j=0; j<kRow; j++) precpvADC[i][j] = new int [kCol];
270 for (Int_t i = 0; i < kSMN; i++)
272 for (Int_t j = 0; j < kRow; j++)
274 for (Int_t k = 0; k < kCol; k++)
276 precpvADC[i][j][k] = 0;
281 AliPMDRawStream pmdinput(rawReader);
283 while ((indexDDL = pmdinput.DdlData(&pmdddlcont)) >=0)
285 Int_t ientries = pmdddlcont.GetEntries();
286 for (Int_t ient = 0; ient < ientries; ient++)
288 AliPMDddldata *pmdddl = (AliPMDddldata*)pmdddlcont.UncheckedAt(ient);
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();
302 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
306 else if (indexDDL == 4 || indexDDL == 5)
309 AliError(Form("*DDL %d and Detector NUMBER %d NOT MATCHING *",
313 precpvADC[indexsmn][row][col] = sig;
319 // Add the digits here
320 for (indexsmn = 0; indexsmn < kSMN; indexsmn++)
327 else if (indexsmn > 23)
332 for (Int_t irow = 0; irow < kRow; irow++)
334 for (Int_t icol = 0; icol < kCol; icol++)
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];
340 // plug in a function to convert to adc to MeV
343 AddDigit(trno,trpid,idet,ismn,irow,icol,sig1);
351 pmdLoader->WriteDigits("OVERWRITE");
353 // Delete all the pointers
355 for (Int_t i = 0; i < kSMN; i++)
357 for (Int_t j = 0; j < kRow; j++)
359 delete [] precpvADC[i][j];
362 for (Int_t j = 0; j < kSMN; j++)
364 delete [] precpvADC[j];
368 // ------------------------------------------------------------------------- //
370 void AliPMDRawToSDigits::AdcToMeV(Int_t adc, Float_t &edep)
372 // These constants are from Test Beam 2010
374 const Float_t kConstant = 0.612796;
375 const Float_t kSlope = 130.158;
377 edep = (1000.0/kSlope)*(adc - kConstant);
380 // ------------------------------------------------------------------------- //
382 void AliPMDRawToSDigits::AddSDigit(Int_t trnumber, Int_t trpid, Int_t det,
384 Int_t irow, Int_t icol, Float_t adc)
388 if (!fSDigits) fSDigits = new TClonesArray("AliPMDsdigit", 1000);
389 TClonesArray &lsdigits = *fSDigits;
390 new(lsdigits[fNsdigit++]) AliPMDsdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
393 // ------------------------------------------------------------------------- //
394 void AliPMDRawToSDigits::AddDigit(Int_t trnumber, Int_t trpid, Int_t det,
396 Int_t irow, Int_t icol, Float_t adc)
400 if (!fDigits) fDigits = new TClonesArray("AliPMDdigit", 1000);
401 TClonesArray &ldigits = *fDigits;
402 new(ldigits[fNdigit++]) AliPMDdigit(trnumber,trpid,det,smnumber,irow,icol,adc);
405 // ------------------------------------------------------------------------- //
406 void AliPMDRawToSDigits::ResetSDigit()
410 if (fSDigits) fSDigits->Clear();
412 // ------------------------------------------------------------------------- //
413 void AliPMDRawToSDigits::ResetDigit()
417 if (fDigits) fDigits->Clear();