]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALDigit.cxx
Fixing memory leak (L.Gaudichet)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALDigit.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 /* $Id:  */
17
18 //_________________________________________________________________________
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 
24 //
25 //*-- Author: Sahal Yacoob (LBL)
26 // based on : AliPHOSDigit
27 //__________________________________________________________________________
28
29 // --- ROOT system ---
30
31 // --- Standard library ---
32
33 #include <Riostream.h>
34
35 // --- AliRoot header files ---
36
37 #include "AliEMCALDigit.h"
38 #include "AliEMCALGeometry.h"
39
40 ClassImp(AliEMCALDigit)
41
42 //____________________________________________________________________________
43   AliEMCALDigit::AliEMCALDigit()  
44 {
45   // default ctor 
46
47   fIndexInList = -1 ; 
48   fNprimary    = 0 ;  
49   fNMaxPrimary = 5 ; 
50   fNiparent    = 0 ;
51   fNMaxiparent = 5; 
52   fPrimary = 0 ;
53   fIparent = 0 ;
54   fMaxIter = 0;
55   fTime = 0. ; 
56   fTimeR = 0. ; 
57 }
58
59 //____________________________________________________________________________
60 AliEMCALDigit::AliEMCALDigit(Int_t primary, Int_t iparent, Int_t id, Int_t DigEnergy, Float_t time, Int_t index) 
61 {  
62   // ctor with all data 
63
64   fNMaxPrimary = 25 ; 
65   fNMaxiparent = 150 ; 
66   fPrimary = new Int_t[fNMaxPrimary] ;
67   fIparent = new Int_t[fNMaxiparent] ; 
68   fAmp         = DigEnergy ;
69   fTime        = time ;
70   fTimeR       = fTime ;
71   fId          = id ;
72   fIndexInList = index ; 
73   fMaxIter     = 5;
74   if( primary != -1){
75     fNprimary    = 1 ; 
76     fPrimary[0]  = primary ;  
77     fNiparent   = 1 ;
78     fIparent[0] = iparent ;    
79 }
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
91   for ( i =1; i< fNMaxiparent ; i++)
92     fIparent[i] = -1 ;  
93 }
94
95 //____________________________________________________________________________
96 AliEMCALDigit::AliEMCALDigit(const AliEMCALDigit & digit) : AliDigitNew(digit)
97 {
98   // copy ctor
99   
100
101   fNMaxPrimary = digit.fNMaxPrimary ;  
102   fNMaxiparent = digit.fNMaxiparent ;
103   fPrimary = new Int_t[fNMaxPrimary] ;
104   fIparent = new Int_t[fNMaxiparent] ; 
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 ;
112   fTime        = digit.fTime ;
113   fTimeR       = digit.fTimeR ;
114   fId          = digit.fId;
115   fMaxIter     = digit.fMaxIter;
116   fIndexInList = digit.fIndexInList ; 
117   fNprimary    = digit.fNprimary ;
118   fNiparent    = digit.fNiparent ;
119 }
120
121 //____________________________________________________________________________
122 AliEMCALDigit::~AliEMCALDigit() 
123 {
124   // Delete array of primiries if any
125     delete [] fPrimary ;
126     delete [] fIparent ; 
127 }
128
129 //____________________________________________________________________________
130 Int_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 //____________________________________________________________________________
153 Float_t AliEMCALDigit::GetEta() const
154 { // should be change in EMCALGeometry - 19-nov-04
155   Float_t eta=-10., phi=-10.;
156   Int_t id = GetId();
157   const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
158   g->EtaPhiFromIndex(id,eta,phi);
159   return eta ;
160 }
161
162 //____________________________________________________________________________
163 Float_t AliEMCALDigit::GetPhi() const
164 { // should be change in EMCALGeometry - 19-nov-04
165   Float_t eta=-10., phi=-10.;
166   Int_t id = GetId();
167   const AliEMCALGeometry *g = AliEMCALGeometry::GetInstance();
168   g->EtaPhiFromIndex(id,eta,phi);
169   return phi ;
170 }
171
172 //____________________________________________________________________________
173 Int_t AliEMCALDigit::GetPrimary(Int_t index) const
174 {
175   // retrieves the primary particle number given its index in the list 
176   Int_t rv = -1 ;
177   if ( (index <= fNprimary) && (index > 0)){
178     rv = fPrimary[index-1] ;
179   } 
180
181   return rv ; 
182   
183 }
184
185 //____________________________________________________________________________
186 Int_t AliEMCALDigit::GetIparent(Int_t index) const
187 {
188   // retrieves the primary particle number given its index in the list 
189   Int_t rv = -1 ;
190   if ( index <= fNiparent ){
191     rv = fIparent[index-1] ;
192   } 
193
194   return rv ; 
195   
196 }
197
198 //____________________________________________________________________________
199 void AliEMCALDigit::ShiftPrimary(Int_t shift){
200   //shifts primary number to BIG offset, to separate primary in different TreeK
201   Int_t index  ;
202   for(index = 0; index <fNprimary; index++ ){
203     fPrimary[index] = fPrimary[index]+ shift * 10000000   ;}
204   for(index =0; index <fNiparent; index++){
205     fIparent[index] = fIparent[index] + shift * 10000000 ;}
206 }
207 //____________________________________________________________________________
208 Bool_t AliEMCALDigit::operator==(AliEMCALDigit const & digit) const 
209 {
210   // Two digits are equal if they have the same Id
211   
212   if ( fId == digit.fId ) 
213     return kTRUE ;
214   else 
215     return kFALSE ;
216 }
217  
218 //____________________________________________________________________________
219 AliEMCALDigit& AliEMCALDigit::operator+(AliEMCALDigit const & digit) 
220 {
221   // Adds the amplitude of digits and completes the list of primary particles
222   // if amplitude is larger than 
223   
224   fAmp += digit.fAmp ;
225   if(fTime > digit.fTime)
226     fTime = digit.fTime ;
227   fTimeR = fTime ; 
228
229   Int_t max1 = fNprimary ; 
230   Int_t max2 = fNiparent ;  
231   Int_t index ; 
232   for (index = 0 ; index < digit.fNprimary  ; index++){
233     Bool_t deja = kTRUE ;
234     Int_t old ;
235     for ( old = 0 ; (old < max1) && deja; old++) { //already have this primary?
236       if(fPrimary[old] == digit.fPrimary[index])
237         deja = kFALSE;
238     }
239     if(deja){
240       if(max1<fNMaxPrimary){ fPrimary[max1] = digit.fPrimary[index] ; 
241       fNprimary++ ;
242       max1++;}
243       if(fNprimary==fNMaxPrimary) {
244
245         TString mess = " NMaxPrimary  =  " ; 
246         mess += fNMaxPrimary ; 
247         mess += " is too small" ; 
248         Fatal("AliEMCALDigit::Operator+ -->" , mess.Data()) ; 
249
250       }
251     }
252   }
253   
254   for (index = 0 ; index < digit.fNiparent ; index++){
255     Bool_t dejavu = kTRUE ;
256     Int_t old ;
257     for ( old = 0 ; (old < max2) && dejavu; old++) { //already have this primary?
258       if(fIparent[old] == digit.fIparent[index])
259         dejavu = kFALSE;
260     }
261     if(dejavu){
262      if(max2<fNMaxiparent){ fIparent[max2] = digit.fIparent[index] ; 
263       fNiparent++ ;
264       max2++;}
265       if(fNiparent==fNMaxiparent) {
266
267         TString mess = " NMaxiparent  =  " ; 
268         mess += fNMaxiparent ; 
269         mess += " is too small" ; 
270         Fatal("AliEMCALDigit::Operator+ -->", mess.Data()) ; 
271
272       }
273     }
274   }
275   
276   return *this ;
277 }
278
279 //____________________________________________________________________________
280 AliEMCALDigit& AliEMCALDigit::operator*(Float_t factor) 
281 {
282   // Multiplies the amplitude by a factor
283   
284   Float_t tempo = static_cast<Float_t>(fAmp) ; 
285   tempo *= factor ; 
286   fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ; 
287   return *this ;
288 }
289
290 //____________________________________________________________________________
291 ostream& operator << ( ostream& out , const AliEMCALDigit & digit)
292 {
293   // Prints the data of the digit
294   
295   out << "ID " << digit.fId << " Energy = " << digit.fAmp <<  " Time = " << digit.fTime << endl ; 
296   Int_t i,j ;
297   for(i=0;i<digit.fNprimary;i++)
298     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
299    
300   for(j=0;j<digit.fNiparent;j++)
301     out << "Iparent " << j+1 << " = " << digit.fIparent[j] << endl ;
302  out << "Position in list = " << digit.fIndexInList << endl ; 
303   return out ;
304 }
305
306