]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALRawDigit.cxx
Increase back the number of SM to 22
[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         // returns the time and amplitude of a given time sample and if the sample was ok
76   
77         if (iSample > fNSamples || iSample < 0) return kFALSE;
78         
79   amp     = (Short_t)(fSamples[iSample] & 0xFFFF);
80   timeBin = (Short_t)(fSamples[iSample] >> 16 );
81
82         return kTRUE;
83 }
84
85 //____________________________________________________________________________
86 void AliEMCALRawDigit::SetTimeSamples(const Int_t timeSamples[], const Int_t nSamples) 
87 {
88   // Sets the time samples
89   
90         if (fSamples) 
91         {
92                 AliDebug(1,"Samples already filled: delete first!");
93                 fNSamples = 0;
94                 delete [] fSamples;
95         }
96         
97         fNSamples = nSamples;
98         fSamples = new Int_t[fNSamples];
99         for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
100 }
101
102 //____________________________________________________________________________
103 Bool_t AliEMCALRawDigit::GetMaximum(Int_t& amplitude, Int_t& time) const
104 {
105         // Checks the maximum amplitude in the time sample
106   
107         if (!fNSamples)
108         {
109                 AliDebug(1,"Digit has no time sample");
110                 return kFALSE;
111         }
112                 
113         amplitude = 0;
114         for (Int_t i = 0; i < fNSamples; i++)
115         {
116                 Int_t t, a;
117                 if (GetTimeSample(i, t, a))
118                 {
119                         if (a > amplitude)
120                         {
121                                 amplitude = a;
122                                 time      = t;
123                         }
124                 }
125         }
126         
127         return kTRUE;
128 }
129
130 //____________________________________________________________________________
131 Int_t AliEMCALRawDigit::Compare(const TObject * obj) const
132 {
133         // Compares two digits with respect to its Id
134         // to sort according increasing Id
135         
136         Int_t rv=0;
137         
138         AliEMCALRawDigit* digit = (AliEMCALRawDigit*)obj; 
139         
140         Int_t iddiff = fId - digit->GetId();
141         
142         if (iddiff > 0) 
143                 rv =  1;
144         else if (iddiff < 0)
145                 rv = -1; 
146         else
147                 rv =  0;
148         
149         return rv; 
150 }
151
152 //____________________________________________________________________________
153 void AliEMCALRawDigit::Print(const Option_t* /*opt*/) const
154 {
155         // print
156   
157         printf("===\n| Digit id: %4d / %d Time Samples: \n",fId,fNSamples);
158         for (Int_t i=0; i < fNSamples; i++) 
159         {
160                 Int_t timeBin=-1, amp=0;
161                 GetTimeSample(i, timeBin, amp);
162                 printf("| (%d,%d) ",timeBin,amp);
163         }
164         
165         printf("\n");
166 }