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