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