First commit.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigit.cxx
CommitLineData
61e0abb5 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
ffa6d63b 16/* $Id: */
61e0abb5 17
18//_________________________________________________________________________
ffa6d63b 19// EMCAL digit:
20// A Digit is the sum of the energy lost in an EMCAL Tower
21// It also stores information on Primary, and enterring particle
22// tracknumbers Digits are created using AliEMCALSDigitizer, followed
23// by AliEMCALDigitizer
61e0abb5 24//
ffa6d63b 25//*-- Author: Sahal Yacoob (LBL)
26// based on : AliPHOSDigit
814ad4bf 27//__________________________________________________________________________
61e0abb5 28
29// --- ROOT system ---
30
31// --- Standard library ---
32
33#include <iostream.h>
34
35// --- AliRoot header files ---
36
37#include "AliEMCALDigit.h"
814ad4bf 38#include "AliEMCALGeometry.h"
61e0abb5 39
40
41ClassImp(AliEMCALDigit)
42
43//____________________________________________________________________________
44 AliEMCALDigit::AliEMCALDigit()
45{
46 // default ctor
47
48 fIndexInList = -1 ;
49 fNprimary = 0 ;
d75bea67 50 fNMaxPrimary = 21 ;
61e0abb5 51 fNiparent = 0 ;
52 fNMaxiparent = fNMaxPrimary*10;
53}
54
55//____________________________________________________________________________
814ad4bf 56AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t time, Int_t index)
61e0abb5 57{
58 // ctor with all data
59
d75bea67 60 fNMaxPrimary = 21 ;
61e0abb5 61 fNMaxiparent = fNMaxPrimary*10;
62 fAmp = DigEnergy ;
814ad4bf 63 fTime = time ;
61e0abb5 64 fId = id ;
65 fIndexInList = index ;
66 if( primary != -1){
67 fNprimary = 1 ;
68 fPrimary[0] = primary ;
69 fNiparent = 1 ;
70 fIparent[0] = iparent ;
71
72 }
73 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
74 fNprimary = 0 ;
75 fPrimary[0] = -1 ;
76 fNiparent = 0 ;
77 fIparent[0] = -1 ;
78
79 }
80 Int_t i ;
81 for ( i = 1; i < fNMaxPrimary ; i++)
82 fPrimary[i] = -1 ;
83
84 for ( Int_t j =1; j< fNMaxiparent ; j++)
85 fIparent[j] = -1 ;
86}
87
88//____________________________________________________________________________
89AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit)
90{
91 // copy ctor
92
93
94 fNMaxPrimary = digit.fNMaxPrimary ;
95 fNMaxiparent = digit.fNMaxiparent ;
96 Int_t i ;
97 for ( i = 0; i < fNMaxPrimary ; i++)
98 fPrimary[i] = digit.fPrimary[i] ;
99 Int_t j ;
100 for (j = 0; j< fNMaxiparent ; j++)
101 fIparent[j] = digit.fIparent[j] ;
102 fAmp = digit.fAmp ;
814ad4bf 103 fTime = digit.fTime ;
61e0abb5 104 fId = digit.fId;
105 fIndexInList = digit.fIndexInList ;
106 fNprimary = digit.fNprimary ;
107 fNiparent = digit.fNiparent ;
108}
109
110//____________________________________________________________________________
111AliEMCALDigit::~AliEMCALDigit()
112{
113 // Delete array of primiries if any
114
115}
116
117//____________________________________________________________________________
118Int_t AliEMCALDigit::Compare(const TObject * obj) const
119{
120 // Compares two digits with respect to its Id
121 // to sort according increasing Id
122
123 Int_t rv ;
124
125 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
126
127 Int_t iddiff = fId - digit->GetId() ;
128
129 if ( iddiff > 0 )
130 rv = 1 ;
131 else if ( iddiff < 0 )
132 rv = -1 ;
133 else
134 rv = 0 ;
135
136 return rv ;
137
138}
139
140//____________________________________________________________________________
814ad4bf 141const Float_t AliEMCALDigit::GetEta() const
142{
143 Float_t eta=-10., phi=-10.;
144 AliEMCALGeometry::GetInstance()->EtaPhiFromIndex(fId,eta,phi);
145 return eta ;
146}
147
148//____________________________________________________________________________
149const Float_t AliEMCALDigit::GetPhi() const
150{
151 Float_t eta=-10., phi=-10.;
152 AliEMCALGeometry::GetInstance()->EtaPhiFromIndex(fId,eta,phi);
153 return phi ;
154}
155
156//____________________________________________________________________________
61e0abb5 157Int_t AliEMCALDigit::GetPrimary(Int_t index) const
158{
159 // retrieves the primary particle number given its index in the list
160 Int_t rv = -1 ;
814ad4bf 161 if ( index <= fNprimary && index > 0){
61e0abb5 162 rv = fPrimary[index-1] ;
163 }
164
165 return rv ;
166
167}
168
169//____________________________________________________________________________
170Int_t AliEMCALDigit::GetIparent(Int_t index) const
171{
172 // retrieves the primary particle number given its index in the list
173 Int_t rv = -1 ;
174 if ( index <= fNiparent ){
175 rv = fIparent[index-1] ;
176 }
177
178 return rv ;
179
180}
181
182
183//____________________________________________________________________________
184void AliEMCALDigit::ShiftPrimary(Int_t shift){
185 //shifts primary nimber to BIG offset, to separate primary in different TreeK
186 Int_t index ;
187 for(index = 0; index <fNprimary; index++ ){
188 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
189 for(index =0; index <fNiparent; index++){
190 fIparent[index] = fIparent[index] + shift * 10000000 ;}
191}
192//____________________________________________________________________________
193Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
194{
195 // Two digits are equal if they have the same Id
196
197 if ( fId == digit.fId )
198 return kTRUE ;
199 else
200 return kFALSE ;
201}
202
203//____________________________________________________________________________
204AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit)
205{
206 // Adds the amplitude of digits and completes the list of primary particles
207 // if amplitude is larger than
208
209 fAmp += digit.fAmp ;
814ad4bf 210 if(fTime > digit.fTime)
211 fTime = digit.fTime ;
61e0abb5 212
213 Int_t max1 = fNprimary ;
214 Int_t max2 = fNiparent ;
215 Int_t index ;
216 for (index = 0 ; index < digit.fNprimary ; index++){
217 Bool_t deja = kTRUE ;
218 Int_t old ;
219 for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
220 if(fPrimary[old] == (digit.fPrimary)[index])
221 deja = kFALSE;
222 }
223 if(deja){
224 fPrimary[fNprimary] = (digit.fPrimary)[index] ;
225 fNprimary++ ;
226 if(fNprimary>fNMaxPrimary) {
227 cout << "AliEMCALDigit >> Increase NMaxPrimary "<< endl ;
228 return *this ;
229 }
230 }
231 }
232
233 for (index = 0 ; index < digit.fNiparent ; index++){
234 Bool_t dejavu = kTRUE ;
235 Int_t old ;
236 for ( old = 0 ; (old < max2) && dejavu; old++) { //already have this primary?
237 if(fIparent[old] == (digit.fIparent)[index])
238 dejavu = kFALSE;
239 }
240 if(dejavu){
241 fIparent[fNiparent] = (digit.fIparent)[index] ;
242 fNiparent++ ;
243 if(fNiparent>fNMaxiparent) {
244 cout << "AliEMCALDigit >> Increase NMaxiparent "<< endl ;
245 return *this ;
246 }
247 }
248 }
249
250 return *this ;
251}
252
253//____________________________________________________________________________
254ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
255{
256 // Prints the data of the digit
257
814ad4bf 258 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
61e0abb5 259 Int_t i,j ;
260 for(i=0;i<digit.fNprimary;i++)
261 out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
262
263 for(j=0;j<digit.fNiparent;j++)
264 out << "Iparent " << j+1 << " = " << digit.fIparent[j] << endl ;
265 out << "Position in list = " << digit.fIndexInList << endl ;
266 return out ;
267}
268
269