]>
Commit | Line | Data |
---|---|---|
916f1e76 | 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 | **************************************************************************/ | |
de39a0ff | 15 | /* |
16 | ||
17 | ||
18 | ||
19 | ||
20 | Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3 | |
21 | */ | |
916f1e76 | 22 | |
23 | // --- ROOT system --- | |
24 | #include <Riostream.h> | |
25 | #include <TMath.h> | |
26 | ||
916f1e76 | 27 | // --- AliRoot header files --- |
916f1e76 | 28 | #include "AliEMCALRawDigit.h" |
de39a0ff | 29 | #include "AliLog.h" |
916f1e76 | 30 | |
31 | ClassImp(AliEMCALRawDigit) | |
32 | ||
33 | //____________________________________________________________________________ | |
34 | AliEMCALRawDigit::AliEMCALRawDigit() : TObject(), | |
35 | fId(-1), | |
36 | fNSamples(0), | |
de39a0ff | 37 | fSamples(0x0), |
38 | fAmplitude(0), | |
39 | fTime(0) | |
916f1e76 | 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), | |
de39a0ff | 48 | fSamples(0x0), |
49 | fAmplitude(0), | |
50 | fTime(0) | |
916f1e76 | 51 | { |
52 | // | |
de39a0ff | 53 | fSamples = new Int_t[fNSamples]; |
54 | for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i]; | |
916f1e76 | 55 | } |
56 | ||
57 | //____________________________________________________________________________ | |
58 | AliEMCALRawDigit::~AliEMCALRawDigit() | |
59 | { | |
de39a0ff | 60 | //dtor, delete array of time samples |
b57cc9b9 | 61 | if(fSamples) delete [] fSamples; |
916f1e76 | 62 | } |
63 | ||
e0dc3f7d | 64 | //____________________________________________________________________________ |
65 | void AliEMCALRawDigit::Clear(Option_t *) | |
66 | { | |
de39a0ff | 67 | // clear, delete array of time samples |
b57cc9b9 | 68 | if(fSamples) delete [] fSamples; |
e0dc3f7d | 69 | } |
70 | ||
71 | ||
916f1e76 | 72 | //____________________________________________________________________________ |
73 | Bool_t AliEMCALRawDigit::GetTimeSample(const Int_t iSample, Int_t& timeBin, Int_t& amp) const | |
74 | { | |
a520bcd0 | 75 | // returns the time and amplitude of a given time sample and if the sample was ok |
76 | ||
916f1e76 | 77 | if (iSample > fNSamples || iSample < 0) return kFALSE; |
78 | ||
79 | amp = fSamples[iSample] & 0xFFF; | |
80 | timeBin = (fSamples[iSample] >> 12) & 0xFF; | |
81 | ||
82 | return kTRUE; | |
83 | } | |
84 | ||
85 | //____________________________________________________________________________ | |
de39a0ff | 86 | void AliEMCALRawDigit::SetTimeSamples(const Int_t timeSamples[], const Int_t nSamples) |
916f1e76 | 87 | { |
a520bcd0 | 88 | // Sets the time samples |
89 | ||
de39a0ff | 90 | if (fSamples) |
916f1e76 | 91 | { |
aa878a7b | 92 | AliDebug(1,"Samples already filled: delete first!"); |
de39a0ff | 93 | fNSamples = 0; |
94 | delete [] fSamples; | |
916f1e76 | 95 | } |
96 | ||
de39a0ff | 97 | fNSamples = nSamples; |
98 | fSamples = new Int_t[fNSamples]; | |
99 | for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i]; | |
916f1e76 | 100 | } |
101 | ||
102 | //____________________________________________________________________________ | |
de39a0ff | 103 | Bool_t AliEMCALRawDigit::GetMaximum(Int_t& amplitude, Int_t& time) const |
104 | { | |
a520bcd0 | 105 | // Checks the maximum amplitude in the time sample |
106 | ||
de39a0ff | 107 | if (!fNSamples) |
108 | { | |
aa878a7b | 109 | AliDebug(1,"Digit has no time sample"); |
de39a0ff | 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 | |
916f1e76 | 132 | { |
133 | // Compares two digits with respect to its Id | |
134 | // to sort according increasing Id | |
de39a0ff | 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) | |
916f1e76 | 145 | rv = -1; |
146 | else | |
de39a0ff | 147 | rv = 0; |
148 | ||
916f1e76 | 149 | return rv; |
150 | } | |
151 | ||
152 | //____________________________________________________________________________ | |
de39a0ff | 153 | void AliEMCALRawDigit::Print(const Option_t* /*opt*/) const |
916f1e76 | 154 | { |
a520bcd0 | 155 | |
156 | ||
de39a0ff | 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"); | |
916f1e76 | 166 | } |