Line data Source code
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 42 : ClassImp(AliEMCALRawDigit)
32 :
33 : //____________________________________________________________________________
34 37 : AliEMCALRawDigit::AliEMCALRawDigit() : TObject(),
35 37 : fId(-1),
36 37 : fNSamples(0),
37 37 : fSamples(0x0),
38 37 : fAmplitude(0),
39 37 : fTime(0)
40 111 : {
41 : // default ctor
42 37 : }
43 :
44 : //____________________________________________________________________________
45 142 : AliEMCALRawDigit::AliEMCALRawDigit(Int_t id, Int_t timeSamples[], Int_t nSamples) : TObject(),
46 142 : fId(id),
47 142 : fNSamples(nSamples),
48 142 : fSamples(0x0),
49 142 : fAmplitude(0),
50 142 : fTime(0)
51 426 : {
52 : //
53 284 : fSamples = new Int_t[fNSamples];
54 2460 : for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
55 142 : }
56 :
57 : //____________________________________________________________________________
58 : AliEMCALRawDigit::~AliEMCALRawDigit()
59 358 : {
60 : //dtor, delete array of time samples
61 531 : if(fSamples) delete [] fSamples;
62 179 : }
63 :
64 : //____________________________________________________________________________
65 : void AliEMCALRawDigit::Clear(Option_t *)
66 : {
67 : // clear, delete array of time samples
68 0 : if(fSamples) delete [] fSamples;
69 0 : }
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 4224 : if (iSample > fNSamples || iSample < 0) return kFALSE;
78 :
79 2112 : amp = (Short_t)(fSamples[iSample] & 0xFFFF);
80 2112 : timeBin = (Short_t)(fSamples[iSample] >> 16 );
81 :
82 2112 : return kTRUE;
83 2112 : }
84 :
85 : //____________________________________________________________________________
86 : void AliEMCALRawDigit::SetTimeSamples(const Int_t timeSamples[], const Int_t nSamples)
87 : {
88 : // Sets the time samples
89 :
90 0 : if (fSamples)
91 : {
92 0 : AliDebug(1,"Samples already filled: delete first!");
93 0 : fNSamples = 0;
94 0 : delete [] fSamples;
95 : }
96 :
97 0 : fNSamples = nSamples;
98 0 : fSamples = new Int_t[fNSamples];
99 0 : for (Int_t i = 0; i < fNSamples; i++) fSamples[i] = timeSamples[i];
100 0 : }
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 284 : if (!fNSamples)
108 : {
109 324 : AliDebug(1,"Digit has no time sample");
110 108 : return kFALSE;
111 : }
112 :
113 34 : amplitude = 0;
114 2244 : for (Int_t i = 0; i < fNSamples; i++)
115 : {
116 1088 : Int_t t, a;
117 1088 : if (GetTimeSample(i, t, a))
118 : {
119 1088 : if (a > amplitude)
120 : {
121 74 : amplitude = a;
122 74 : time = t;
123 74 : }
124 : }
125 1088 : }
126 :
127 34 : return kTRUE;
128 142 : }
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 0 : AliEMCALRawDigit* digit = (AliEMCALRawDigit*)obj;
139 :
140 0 : Int_t iddiff = fId - digit->GetId();
141 :
142 0 : if (iddiff > 0)
143 0 : rv = 1;
144 0 : else if (iddiff < 0)
145 0 : rv = -1;
146 : else
147 : rv = 0;
148 :
149 0 : return rv;
150 : }
151 :
152 : //____________________________________________________________________________
153 : void AliEMCALRawDigit::Print(const Option_t* /*opt*/) const
154 : {
155 : // print
156 :
157 0 : printf("===\n| Digit id: %4d / %d Time Samples: \n",fId,fNSamples);
158 0 : for (Int_t i=0; i < fNSamples; i++)
159 : {
160 0 : Int_t timeBin=-1, amp=0;
161 0 : GetTimeSample(i, timeBin, amp);
162 0 : printf("| (%d,%d) ",timeBin,amp);
163 0 : }
164 :
165 0 : printf("\n");
166 0 : }
|