]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALRawDigit.cxx
Be sure to load mapping when needed
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALRawDigit.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
19  
20  Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
21 */
22
23 // --- ROOT system ---
24 #include <Riostream.h>
25 #include <TMath.h>
26
27 // --- AliRoot header files ---
28 #include "AliEMCALRawDigit.h"
29 #include "AliLog.h"
30
31 ClassImp(AliEMCALRawDigit)
32
33 //____________________________________________________________________________
34 AliEMCALRawDigit::AliEMCALRawDigit() : TObject(),
35 fId(-1),
36 fNSamples(0),
37 fSamples(0x0),
38 fAmplitude(0),
39 fTime(0)
40 {
41         // default ctor 
42 }
43
44 //____________________________________________________________________________
45 AliEMCALRawDigit::AliEMCALRawDigit(Int_t id, Int_t timeSamples[], Int_t nSamples) : TObject(),
46 fId(id),
47 fNSamples(nSamples),
48 fSamples(0x0),
49 fAmplitude(0),
50 fTime(0)
51 {
52         //
53         fSamples = new Int_t[fNSamples];
54         for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
55 }
56
57 //____________________________________________________________________________
58 AliEMCALRawDigit::~AliEMCALRawDigit() 
59 {
60   //dtor, delete array of time samples
61   if(fSamples) delete [] fSamples;
62 }
63
64 //____________________________________________________________________________
65 void AliEMCALRawDigit::Clear(Option_t *) 
66 {
67   // clear, delete array of time samples
68   if(fSamples) delete [] fSamples;
69 }
70
71
72 //____________________________________________________________________________
73 Bool_t AliEMCALRawDigit::GetTimeSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const
74 {
75         //
76         if (iSample > fNSamples || iSample < 0) return kFALSE;
77         
78         amp     =  fSamples[iSample] & 0xFFF;
79         timeBin = (fSamples[iSample] >> 12) & 0xFF;
80
81         return kTRUE;
82 }
83
84 //____________________________________________________________________________
85 void AliEMCALRawDigit::SetTimeSamples(const Int_t timeSamples[], const Int_t nSamples) 
86 {
87         //
88         if (fSamples) 
89         {
90                 AliDebug(1,"Samples already filled: delete first!");
91                 fNSamples = 0;
92                 delete [] fSamples;
93         }
94         
95         fNSamples = nSamples;
96         fSamples = new Int_t[fNSamples];
97         for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
98 }
99
100 //____________________________________________________________________________
101 Bool_t AliEMCALRawDigit::GetMaximum(Int_t& amplitude, Int_t& time) const
102 {
103         //
104         if (!fNSamples)
105         {
106                 AliDebug(1,"Digit has no time sample");
107                 return kFALSE;
108         }
109                 
110         amplitude = 0;
111         for (Int_t i = 0; i < fNSamples; i++)
112         {
113                 Int_t t, a;
114                 if (GetTimeSample(i, t, a))
115                 {
116                         if (a > amplitude)
117                         {
118                                 amplitude = a;
119                                 time      = t;
120                         }
121                 }
122         }
123         
124         return kTRUE;
125 }
126
127 //____________________________________________________________________________
128 Int_t AliEMCALRawDigit::Compare(const TObject * obj) const
129 {
130         // Compares two digits with respect to its Id
131         // to sort according increasing Id
132         
133         Int_t rv=0;
134         
135         AliEMCALRawDigit* digit = (AliEMCALRawDigit*)obj; 
136         
137         Int_t iddiff = fId - digit->GetId();
138         
139         if (iddiff > 0) 
140                 rv =  1;
141         else if (iddiff < 0)
142                 rv = -1; 
143         else
144                 rv =  0;
145         
146         return rv; 
147 }
148
149 //____________________________________________________________________________
150 void AliEMCALRawDigit::Print(const Option_t* /*opt*/) const
151 {
152         //
153         printf("===\n| Digit id: %4d / %d Time Samples: \n",fId,fNSamples);
154         for (Int_t i=0; i < fNSamples; i++) 
155         {
156                 Int_t timeBin=-1, amp=0;
157                 GetTimeSample(i, timeBin, amp);
158                 printf("| (%d,%d) ",timeBin,amp);
159         }
160         
161         printf("\n");
162 }