Corrected delete (Panos)
[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
70479d0e 33#include <Riostream.h>
61e0abb5 34
35// --- AliRoot header files ---
36
37#include "AliEMCALDigit.h"
814ad4bf 38#include "AliEMCALGeometry.h"
61e0abb5 39
40ClassImp(AliEMCALDigit)
41
42//____________________________________________________________________________
da98933e 43 AliEMCALDigit::AliEMCALDigit()
61e0abb5 44{
45 // default ctor
46
88cb7938 47 fIndexInList = -1 ;
61e0abb5 48 fNprimary = 0 ;
88cb7938 49 fNMaxPrimary = 5 ;
50 fNiparent = 0 ;
51 fNMaxiparent = 5;
ef733077 52 fPrimary = 0 ;
53 fIparent = 0 ;
0c22a365 54 fMaxIter = 0;
04f0bda3 55 fTime = 0. ;
56 fTimeR = 0. ;
61e0abb5 57}
58
59//____________________________________________________________________________
814ad4bf 60AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t time, Int_t index)
61e0abb5 61{
62 // ctor with all data
63
451bc3c5 64 fNMaxPrimary = 25 ;
fb8b329a 65 fNMaxiparent = 150 ;
88d764f0 66 fPrimary = new Int_t[fNMaxPrimary] ;
67 fIparent = new Int_t[fNMaxiparent] ;
61e0abb5 68 fAmp = DigEnergy ;
814ad4bf 69 fTime = time ;
04f0bda3 70 fTimeR = fTime ;
61e0abb5 71 fId = id ;
72 fIndexInList = index ;
0c22a365 73 fMaxIter = 5;
61e0abb5 74 if( primary != -1){
75 fNprimary = 1 ;
7b62cd84 76 fPrimary[0] = primary ;
61e0abb5 77 fNiparent = 1 ;
78 fIparent[0] = iparent ;
7b62cd84 79}
61e0abb5 80 else{ //If the contribution of this primary smaller than fDigitThreshold (AliEMCALv1)
81 fNprimary = 0 ;
82 fPrimary[0] = -1 ;
83 fNiparent = 0 ;
84 fIparent[0] = -1 ;
85
86 }
87 Int_t i ;
88 for ( i = 1; i < fNMaxPrimary ; i++)
89 fPrimary[i] = -1 ;
90
f807c3bd 91 for ( i =1; i< fNMaxiparent ; i++)
92 fIparent[i] = -1 ;
61e0abb5 93}
94
95//____________________________________________________________________________
9e5d2067 96AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit) : AliDigitNew(digit)
61e0abb5 97{
98 // copy ctor
99
100
101 fNMaxPrimary = digit.fNMaxPrimary ;
102 fNMaxiparent = digit.fNMaxiparent ;
88d764f0 103 fPrimary = new Int_t[fNMaxPrimary] ;
104 fIparent = new Int_t[fNMaxiparent] ;
61e0abb5 105 Int_t i ;
106 for ( i = 0; i < fNMaxPrimary ; i++)
107 fPrimary[i] = digit.fPrimary[i] ;
108 Int_t j ;
109 for (j = 0; j< fNMaxiparent ; j++)
110 fIparent[j] = digit.fIparent[j] ;
111 fAmp = digit.fAmp ;
814ad4bf 112 fTime = digit.fTime ;
04f0bda3 113 fTimeR = digit.fTimeR ;
61e0abb5 114 fId = digit.fId;
0c22a365 115 fMaxIter = digit.fMaxIter;
61e0abb5 116 fIndexInList = digit.fIndexInList ;
117 fNprimary = digit.fNprimary ;
118 fNiparent = digit.fNiparent ;
119}
120
121//____________________________________________________________________________
122AliEMCALDigit::~AliEMCALDigit()
123{
124 // Delete array of primiries if any
88d764f0 125 delete [] fPrimary ;
126 delete [] fIparent ;
61e0abb5 127}
128
129//____________________________________________________________________________
130Int_t AliEMCALDigit::Compare(const TObject * obj) const
131{
132 // Compares two digits with respect to its Id
133 // to sort according increasing Id
134
135 Int_t rv ;
136
137 AliEMCALDigit * digit = (AliEMCALDigit *)obj ;
138
139 Int_t iddiff = fId - digit->GetId() ;
140
141 if ( iddiff > 0 )
142 rv = 1 ;
143 else if ( iddiff < 0 )
144 rv = -1 ;
145 else
146 rv = 0 ;
147
148 return rv ;
149
150}
151
152//____________________________________________________________________________
88cb7938 153Float_t AliEMCALDigit::GetEta() const
14ce0a6e 154{
155 //return pseudorapidity for this digit
156 // should be change in EMCALGeometry - 19-nov-04
814ad4bf 157 Float_t eta=-10., phi=-10.;
563aa66c 158 Int_t id = GetId();
5dee926e 159 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
563aa66c 160 g->EtaPhiFromIndex(id,eta,phi);
814ad4bf 161 return eta ;
162}
163
164//____________________________________________________________________________
88cb7938 165Float_t AliEMCALDigit::GetPhi() const
14ce0a6e 166{
167 //return phi coordinate of digit
168 // should be change in EMCALGeometry - 19-nov-04
814ad4bf 169 Float_t eta=-10., phi=-10.;
563aa66c 170 Int_t id = GetId();
5dee926e 171 const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
563aa66c 172 g->EtaPhiFromIndex(id,eta,phi);
814ad4bf 173 return phi ;
174}
175
176//____________________________________________________________________________
61e0abb5 177Int_t AliEMCALDigit::GetPrimary(Int_t index) const
178{
179 // retrieves the primary particle number given its index in the list
180 Int_t rv = -1 ;
fdebddeb 181 if ( (index <= fNprimary) && (index > 0)){
61e0abb5 182 rv = fPrimary[index-1] ;
183 }
184
185 return rv ;
186
187}
188
189//____________________________________________________________________________
190Int_t AliEMCALDigit::GetIparent(Int_t index) const
191{
192 // retrieves the primary particle number given its index in the list
193 Int_t rv = -1 ;
194 if ( index <= fNiparent ){
195 rv = fIparent[index-1] ;
196 }
197
198 return rv ;
199
200}
201
61e0abb5 202//____________________________________________________________________________
203void AliEMCALDigit::ShiftPrimary(Int_t shift){
fdebddeb 204 //shifts primary number to BIG offset, to separate primary in different TreeK
61e0abb5 205 Int_t index ;
206 for(index = 0; index <fNprimary; index++ ){
207 fPrimary[index] = fPrimary[index]+ shift * 10000000 ;}
208 for(index =0; index <fNiparent; index++){
209 fIparent[index] = fIparent[index] + shift * 10000000 ;}
210}
211//____________________________________________________________________________
212Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const
213{
214 // Two digits are equal if they have the same Id
215
216 if ( fId == digit.fId )
217 return kTRUE ;
218 else
219 return kFALSE ;
220}
221
222//____________________________________________________________________________
223AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit)
224{
225 // Adds the amplitude of digits and completes the list of primary particles
226 // if amplitude is larger than
227
228 fAmp += digit.fAmp ;
814ad4bf 229 if(fTime > digit.fTime)
230 fTime = digit.fTime ;
04f0bda3 231 fTimeR = fTime ;
7b62cd84 232
61e0abb5 233 Int_t max1 = fNprimary ;
234 Int_t max2 = fNiparent ;
235 Int_t index ;
7b62cd84 236 for (index = 0 ; index < digit.fNprimary ; index++){
61e0abb5 237 Bool_t deja = kTRUE ;
238 Int_t old ;
239 for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
7b62cd84 240 if(fPrimary[old] == digit.fPrimary[index])
61e0abb5 241 deja = kFALSE;
242 }
243 if(deja){
7b62cd84 244 if(max1<fNMaxPrimary){ fPrimary[max1] = digit.fPrimary[index] ;
61e0abb5 245 fNprimary++ ;
7b62cd84 246 max1++;}
247 if(fNprimary==fNMaxPrimary) {
8704424d 248
451bc3c5 249 TString mess = " NMaxPrimary = " ;
250 mess += fNMaxPrimary ;
251 mess += " is too small" ;
252 Fatal("AliEMCALDigit::Operator+ -->" , mess.Data()) ;
8704424d 253
61e0abb5 254 }
255 }
256 }
257
258 for (index = 0 ; index < digit.fNiparent ; index++){
259 Bool_t dejavu = kTRUE ;
260 Int_t old ;
261 for ( old = 0 ; (old < max2) && dejavu; old++) { //already have this primary?
7b62cd84 262 if(fIparent[old] == digit.fIparent[index])
61e0abb5 263 dejavu = kFALSE;
264 }
265 if(dejavu){
7b62cd84 266 if(max2<fNMaxiparent){ fIparent[max2] = digit.fIparent[index] ;
61e0abb5 267 fNiparent++ ;
7b62cd84 268 max2++;}
269 if(fNiparent==fNMaxiparent) {
8704424d 270
451bc3c5 271 TString mess = " NMaxiparent = " ;
272 mess += fNMaxiparent ;
273 mess += " is too small" ;
274 Fatal("AliEMCALDigit::Operator+ -->", mess.Data()) ;
8704424d 275
61e0abb5 276 }
277 }
278 }
279
280 return *this ;
281}
282
283//____________________________________________________________________________
563aa66c 284AliEMCALDigit& AliEMCALDigit::operator*(Float_t factor)
285{
286 // Multiplies the amplitude by a factor
287
288 Float_t tempo = static_cast<Float_t>(fAmp) ;
289 tempo *= factor ;
290 fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ;
291 return *this ;
292}
293
294//____________________________________________________________________________
61e0abb5 295ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
296{
297 // Prints the data of the digit
298
814ad4bf 299 out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ;
61e0abb5 300 Int_t i,j ;
301 for(i=0;i<digit.fNprimary;i++)
302 out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
303
304 for(j=0;j<digit.fNiparent;j++)
305 out << "Iparent " << j+1 << " = " << digit.fIparent[j] << endl ;
306 out << "Position in list = " << digit.fIndexInList << endl ;
307 return out ;
308}
309
310