]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSJet.cxx
Library with PHOS geometry transformations for AliRoot-independent analysis
[u/mrichter/AliRoot.git] / PHOS / AliPHOSJet.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 // Class to calculate jet chararacteristics
20 //
21 // This class implements for PHOS a jet finder for PHOS. It depends on a 
22 // energy seed
23 // minimum energy, cone radius and movement of the cone.
24 //*-- Author :  D.Peressounko
25 //////////////////////////////////////////////////////////////////////////////
26
27 // --- ROOT system ---
28 #include "TParticle.h"
29
30 // --- Standard library ---
31
32 // --- AliRoot header files ---
33 #include "AliPHOSJet.h"
34
35 ClassImp(AliPHOSJet)
36   
37 //____________________________________________________________________________ 
38 AliPHOSJet::AliPHOSJet():
39   fNpart(0),
40   fList(0),
41   fConeRad(0),
42   fMaxConeMove(0),
43   fMinConeMove(0),
44   fSumEnergy(0),
45   fSumEta(0),
46   fSumPhi(0),
47   fEnergy(0),
48   fEta(0),
49   fPhi(0),
50   fLEnergy(0),
51   fLEta(0),
52   fLPhi(0) 
53 {
54   //Initialize members
55 }
56
57 //____________________________________________________________________________ 
58 AliPHOSJet::AliPHOSJet(const AliPHOSJet & jet) : 
59   TObject(jet),
60   fNpart(0),
61   fList(0),
62   fConeRad(0),
63   fMaxConeMove(0),
64   fMinConeMove(0),
65   fSumEnergy(0),
66   fSumEta(0),
67   fSumPhi(0),
68   fEnergy(0),
69   fEta(0),
70   fPhi(0),
71   fLEnergy(0),
72   fLEta(0),
73   fLPhi(0) 
74 {
75   // copy ctor: no implementation yet
76   Fatal("cpy ctor", "not implemented") ;
77 }
78
79
80 //____________________________________________________________________________ 
81 AliPHOSJet::~AliPHOSJet(){
82   //dtor
83   if(fList){
84     delete fList ;
85     fList = 0 ;
86   }
87   
88 }
89 //____________________________________________________________________________ 
90 void AliPHOSJet::AddParticle(const TParticle * p, Int_t index){
91   //adds particle to jet. Calculates change in jet direction, 
92   //due to addition of this particle and if it is smaller, than fMaxDev, 
93   //add particle, axcept new direction and return true.
94   
95   fSumEnergy+=p->Energy() ;
96   if(p->Pt()/p->Energy() > 0.001)
97     fSumEta+=p->Eta()*p->Energy() ;
98   else
99     fSumEta+=100.*p->Pz() ; 
100   fSumPhi+=p->Phi()*p->Energy() ;    
101   
102   //check if this a leading particle?
103   if(fLEnergy < p->Energy()){
104     fLEnergy = p->Energy() ;
105     if(p->Pt()/p->Energy() > 0.001)
106       fLEta = p->Eta() ;
107     else 
108       fLEta = 100.*p->Pz()/p->Energy() ;
109     fLPhi = p->Phi() ;
110   }
111
112   if(index >=0){ //add index to list of indexes
113     if(!fList){
114       fList = new TArrayI(100) ;
115     }
116     if(fList->GetSize()<=fNpart+1){
117       TArrayI * tmp = new TArrayI(fNpart*2) ;
118       tmp->Adopt(fList->GetSize(),fList->GetArray()) ; //note, we should not delete old array!
119       fList=tmp ;
120     }
121     fList->AddAt(index,fNpart++) ;
122   }
123 }
124 //____________________________________________________________________________ 
125 void AliPHOSJet::AddDigit(Double_t e, Double_t eta, Double_t phi, Int_t index){
126   //adds particle to jet. Calculates change in jet direction, 
127   //due to addition of this particle and if it is smaller, than fMaxDev, 
128   //add particle, axcept new direction and return true.
129   
130   fSumEnergy+=e ;
131   fSumEta+=eta*e ;
132   fSumPhi+=phi*e ;    
133   
134   //check if this a leading particle?
135   if(fLEnergy < e){
136     fLEnergy = e;
137     fLEta = eta ;
138     fLPhi = phi ;
139   }
140
141   if(index >=0){ //add index to list of indexes
142     if(!fList){
143       fList = new TArrayI(100) ;
144     }
145     if(fList->GetSize()<=fNpart+1){
146       TArrayI * tmp = new TArrayI(fNpart*2) ;
147       tmp->Adopt(fList->GetSize(),fList->GetArray()) ; //note, we should not delete old array!
148       fList=tmp ;
149     }
150     fList->AddAt(index,fNpart++) ;
151   }
152 }
153 // //____________________________________________________________________________ 
154 // Bool_t AliPHOSJet::IsInJet(TParticle * p,Int_t mode)
155 // {
156 //   Double_t dEta ;
157 //   Double_t dPhi ;
158 //   Double_t energy ;
159 //   if(!fEnergy){ //Final values not calculated yet, use intermediate
160 //     if(fSumEnergy==0)
161 //       return kTRUE ; //First particle
162 // note p->Eta() causes fpe! 
163 //     dEta=(p->Eta() - fSumEta/fSumEnergy) ;
164 //     dPhi=(p->Phi() - fSumPhi/fSumEnergy) ;
165 //     energy = fSumEnergy ;
166 //   }
167 //   else{ //calculated with respect to final 
168 //     dEta=(p->Eta() - fEta) ;
169 //     dPhi=(p->Phi() - fPhi) ;
170 //     energy = fEnergy ;    
171 //   }
172   
173 //   switch (mode){
174 //   case 0: 
175 //     return IsInCone(eta,phi) ; //pure geometrical comparison
176 //   case 1: 
177 //     return AcceptConeDeviation(dEta,dPhi,p->Energy() );
178 //   default:
179 //     AliError(Form("Unknown mode of cone calculation %d \n",mode ));
180 //   }
181 //   return kFALSE ;
182 //}
183 //____________________________________________________________________________ 
184 Bool_t AliPHOSJet::AcceptConeDeviation(const TParticle * p)const
185 { //Calculate cone deviation in case of inclusion of the given
186   //particle to jet. 
187
188   Double_t tmpEnergy = fSumEnergy + p->Energy() ;  
189   Double_t tmpEta = fSumEta ;
190   if(p->Pt()/p->Energy() >0.001)
191     tmpEta+= p->Eta()*p->Energy() ;
192   else
193     tmpEta+= 100.*p->Pz() ;
194   tmpEta = tmpEta/tmpEnergy / (fSumEta/fSumEnergy) - 1 ;
195   Double_t tmpPhi = fSumPhi + p->Phi()*p->Energy() ;
196   tmpPhi = tmpPhi/tmpEnergy /(fSumPhi/fSumEnergy) - 1 ;
197   Double_t dev = TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi) ;
198   if(dev < fMaxConeMove)
199     return kTRUE ;
200   else
201     return kFALSE ;
202 }
203 //____________________________________________________________________________ 
204 Bool_t AliPHOSJet::AcceptConeDeviation(Double_t e, Double_t eta, Double_t phi)const
205 { //Calculate cone deviation in case of inclusion of the given
206   //particle to jet. 
207
208   Double_t tmpEnergy = fSumEnergy + e ;
209   Double_t tmpEta = fSumEta + eta*e ;
210   tmpEta = tmpEta/tmpEnergy / (fSumEta/fSumEnergy) ;
211   Double_t tmpPhi = fSumPhi + phi*e ;
212   tmpPhi = tmpPhi/tmpEnergy /(fSumPhi/fSumEnergy) ;
213   Double_t dev = TMath::Sqrt(tmpEta*tmpEta + tmpPhi*tmpPhi) ;
214   if(dev<fMaxConeMove && dev > fMinConeMove)
215     return kTRUE ;
216   else
217     return kFALSE ;
218 }
219 //____________________________________________________________________________ 
220 Bool_t AliPHOSJet::IsInCone(const TParticle * p)const
221 {
222   //Say if  particle is inside the defined cone
223   Double_t dEta ;
224   Double_t dPhi ;
225   if(!fEnergy){ //Final values not calculated yet, use intermediate
226     if(fSumEnergy==0)
227       return kTRUE ; //First particle    
228     if(p->Pt()/p->Energy() > 0.001)
229       dEta=(p->Eta() - fSumEta/fSumEnergy) ;
230     else
231       dEta=(100.*p->Pz()/p->Energy() - fSumEta/fSumEnergy) ;
232     dPhi=(p->Phi() - fSumPhi/fSumEnergy) ;
233   }
234   else{ //calculated with respect to final 
235     if(p->Pt()/p->Energy() > 0.001)
236       dEta=(p->Eta() - fEta) ;
237     else
238       dEta=(100.*p->Pz()/p->Energy() - fEta) ;
239     dPhi=(p->Phi() - fPhi) ;
240   }
241   if(TMath::Sqrt(dEta*dEta + dPhi*dPhi) < fConeRad)
242     return kTRUE ;
243   else
244     return kFALSE ;
245 }
246 //____________________________________________________________________________ 
247 Bool_t AliPHOSJet::IsInCone(Double_t eta, Double_t phi)const
248 {
249   //Says if particle is inside the defined cone
250   Double_t dEta ;
251   Double_t dPhi ;
252   if(!fEnergy){ //Final values not calculated yet, use intermediate
253     if(fSumEnergy==0)
254       return kTRUE ; //First particle    
255     dEta=(eta - fSumEta/fSumEnergy) ;
256     dPhi=(phi - fSumPhi/fSumEnergy) ;
257   }
258   else{ //calculated with respect to final 
259     dEta=(eta - fEta) ;
260     dPhi=(phi - fPhi) ;
261   }
262   if(TMath::Sqrt(dEta*dEta + dPhi*dPhi) < fConeRad)
263     return kTRUE ;
264   else
265     return kFALSE ;
266 }
267 //____________________________________________________________________________ 
268 Double_t AliPHOSJet::DistanceToJet(const TParticle *p)const{
269   //Calculate radius 
270   Double_t dEta ;
271   Double_t dPhi ;
272   if(!fEnergy){ //Final values not calculated yet, use intermediate
273     if(fSumEnergy==0)
274       return kTRUE ; //First particle    
275     if(p->Pt()/p->Energy() > 0.001)
276       dEta=(p->Eta() - fSumEta/fSumEnergy) ;
277     else
278       dEta=(100.*p->Pz()/p->Energy() - fSumEta/fSumEnergy) ;      
279     dPhi=(p->Phi() - fSumPhi/fSumEnergy) ;
280   }
281   else{ //calculated with respect to final 
282     if(p->Pt()/p->Energy() > 0.001)
283       dEta=(p->Eta() - fEta) ;
284     else
285       dEta=(100*p->Pz()/p->Energy() - fEta) ;    
286     dPhi=(p->Phi() - fPhi) ;
287   }
288   return TMath::Sqrt(dEta*dEta + dPhi*dPhi) ;
289
290 }
291 //____________________________________________________________________________ 
292 void AliPHOSJet::CalculateAll(void){
293   //Calculate all jet parameters
294   if(fSumEnergy==0)
295     return  ; //Nothing to calculate    
296   
297   fEta = fSumEta/fSumEnergy ;
298   fPhi = fSumPhi/fSumEnergy ;
299   fEnergy = fSumEnergy ;
300   
301   fSumEnergy = 0. ;
302   fSumEta = 0. ;
303   fSumPhi = 0. ;
304 }
305 //____________________________________________________________________________ 
306 void AliPHOSJet::Print(const Option_t *) const {
307   //Print jet parameters
308   printf("-------------- AliPHOSJet ------------\n") ;
309   printf(" Energy............. %f \n",fEnergy) ;
310   printf(" Eta................ %f \n",fEta ) ;
311   printf(" Phi................ %f \n",fPhi ) ;
312   printf(" Leading Energy..... %f \n",fLEnergy) ;
313   printf(" Leading Eta........ %f \n",fLEta) ;
314   printf(" Leading Phi........ %f \n",fLPhi) ;
315   printf(" N particles in jet  %d \n",fNpart) ;
316   printf("----------------------------------\n") ;
317 }
318
319
320