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