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