]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG/FLOW/Base/AliFlowTrackSimple.cxx
coverity fix (Ruben)
[u/mrichter/AliRoot.git] / PWG / FLOW / Base / AliFlowTrackSimple.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 // AliFlowTrackSimple:
19 // A simple track class to the the AliFlowEventSimple for flow analysis
20 //
21 //
22 // author: N. van der Kolk (kolk@nikhef.nl)
23 // mods: Mikolaj Krzewicki (mikolaj.krzewicki@cern.ch)
24
25 #include "TObject.h"
26 #include "TParticle.h"
27 #include "TParticlePDG.h"
28 #include "AliFlowTrackSimple.h"
29 #include "TRandom.h"
30 #include "TMath.h"
31
32 ClassImp(AliFlowTrackSimple)
33
34 //-----------------------------------------------------------------------
35 AliFlowTrackSimple::AliFlowTrackSimple():
36   TObject(),
37   fEta(0),
38   fPt(0),
39   fPhi(0),
40   fTrackWeight(1.),
41   fCharge(0),
42   fFlowBits(0),
43   fSubEventBits(0),
44   fID(-1)
45 {
46   //constructor 
47 }
48
49 //-----------------------------------------------------------------------
50 AliFlowTrackSimple::AliFlowTrackSimple(Double_t phi, Double_t eta, Double_t pt, Double_t weight, Int_t charge):
51   TObject(),
52   fEta(eta),
53   fPt(pt),
54   fPhi(phi),
55   fTrackWeight(weight),
56   fCharge(charge),
57   fFlowBits(0),
58   fSubEventBits(0),
59   fID(-1)
60 {
61   //constructor 
62 }
63
64 //-----------------------------------------------------------------------
65 AliFlowTrackSimple::AliFlowTrackSimple( TParticle* p ):
66   TObject(),
67   fEta(p->Eta()),
68   fPt(p->Pt()),
69   fPhi(p->Phi()),
70   fTrackWeight(1.),
71   fCharge(0),
72   fFlowBits(0),
73   fSubEventBits(0),
74   fID(-1)
75 {
76   //ctor
77   TParticlePDG* ppdg = p->GetPDG();
78   fCharge = TMath::Nint(ppdg->Charge()/3.0);
79 }
80
81 //-----------------------------------------------------------------------
82 void AliFlowTrackSimple::Set(TParticle* p)
83 {
84   //set from a TParticle
85   fEta = p->Eta();
86   fPt = p->Pt();
87   fPhi = p->Phi();
88   fTrackWeight = 1.;
89   TParticlePDG* ppdg = p->GetPDG();
90   fCharge = TMath::Nint(ppdg->Charge()/3.0);
91 }
92
93 //-----------------------------------------------------------------------
94 AliFlowTrackSimple::AliFlowTrackSimple(const AliFlowTrackSimple& aTrack):
95   TObject(aTrack),
96   fEta(aTrack.fEta),
97   fPt(aTrack.fPt),
98   fPhi(aTrack.fPhi),
99   fTrackWeight(aTrack.fTrackWeight),
100   fCharge(aTrack.fCharge),
101   fFlowBits(aTrack.fFlowBits),
102   fSubEventBits(aTrack.fSubEventBits),
103   fID(aTrack.fID)
104 {
105   //copy constructor 
106 }
107
108 //-----------------------------------------------------------------------
109 AliFlowTrackSimple* AliFlowTrackSimple::Clone(const char* /*option*/) const
110 {
111   //clone "constructor"
112   return new AliFlowTrackSimple(*this);
113 }
114
115 //-----------------------------------------------------------------------
116 AliFlowTrackSimple& AliFlowTrackSimple::operator=(const AliFlowTrackSimple& aTrack)
117 {
118   //assignment
119   if (&aTrack==this) return *this; //handle self assignmnet
120   fEta = aTrack.fEta;
121   fPt = aTrack.fPt;
122   fPhi = aTrack.fPhi;
123   fTrackWeight = aTrack.fTrackWeight;
124   fCharge = aTrack.fCharge;
125   fFlowBits = aTrack.fFlowBits;
126   fSubEventBits = aTrack.fSubEventBits;
127   fID = aTrack.fID;
128
129   return *this;
130 }
131
132 //----------------------------------------------------------------------- 
133 AliFlowTrackSimple::~AliFlowTrackSimple()
134 {
135   //destructor
136   
137 }
138
139 //----------------------------------------------------------------------- 
140 void AliFlowTrackSimple::ResolutionPt(Double_t res)
141 {
142   //smear the pt by a gaussian with sigma=res
143   fPt += gRandom->Gaus(0.,res);
144 }
145
146 //----------------------------------------------------------------------- 
147 void AliFlowTrackSimple::AddV1( Double_t v1,
148                                 Double_t reactionPlaneAngle,
149                                 Double_t precisionPhi,
150                                 Int_t maxNumberOfIterations )
151 {
152   //afterburner, adds v1, uses Newton-Raphson iteration
153   Double_t phi0=fPhi;
154   Double_t f=0.;
155   Double_t fp=0.;
156   Double_t phiprev=0.;
157
158   for (Int_t i=0; i<maxNumberOfIterations; i++)
159   {
160     phiprev=fPhi; //store last value for comparison
161     f =  fPhi-phi0+2.0*v1*TMath::Sin(fPhi-reactionPlaneAngle);
162     fp = 1.0+2.0*v1*TMath::Cos(fPhi-reactionPlaneAngle); //first derivative
163     fPhi -= f/fp;
164     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
165   }
166 }
167
168 //----------------------------------------------------------------------- 
169 void AliFlowTrackSimple::AddV2( Double_t v2,
170                                 Double_t reactionPlaneAngle,
171                                 Double_t precisionPhi,
172                                 Int_t maxNumberOfIterations )
173 {
174   //afterburner, adds v2, uses Newton-Raphson iteration
175   Double_t phi0=fPhi;
176   Double_t f=0.;
177   Double_t fp=0.;
178   Double_t phiprev=0.;
179
180   for (Int_t i=0; i<maxNumberOfIterations; i++)
181   {
182     phiprev=fPhi; //store last value for comparison
183     f =  fPhi-phi0+v2*TMath::Sin(2.*(fPhi-reactionPlaneAngle));
184     fp = 1.0+2.0*v2*TMath::Cos(2.*(fPhi-reactionPlaneAngle)); //first derivative
185     fPhi -= f/fp;
186     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
187   }
188 }
189
190 //----------------------------------------------------------------------- 
191 void AliFlowTrackSimple::AddV3( Double_t v3,
192                                 Double_t reactionPlaneAngle,
193                                 Double_t precisionPhi,
194                                 Int_t maxNumberOfIterations )
195 {
196   //afterburner, adds v3, uses Newton-Raphson iteration
197   Double_t phi0=fPhi;
198   Double_t f=0.;
199   Double_t fp=0.;
200   Double_t phiprev=0.;
201
202   for (Int_t i=0; i<maxNumberOfIterations; i++)
203   {
204     phiprev=fPhi; //store last value for comparison
205     f =  fPhi-phi0+2./3.*v3*TMath::Sin(3.*(fPhi-reactionPlaneAngle));
206     fp = 1.0+2.0*v3*TMath::Cos(3.*(fPhi-reactionPlaneAngle)); //first derivative
207     fPhi -= f/fp;
208     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
209   }
210 }
211
212 //----------------------------------------------------------------------- 
213 void AliFlowTrackSimple::AddV4( Double_t v4,
214                                 Double_t reactionPlaneAngle,
215                                 Double_t precisionPhi,
216                                 Int_t maxNumberOfIterations )
217 {
218   //afterburner, adds v4, uses Newton-Raphson iteration
219   Double_t phi0=fPhi;
220   Double_t f=0.;
221   Double_t fp=0.;
222   Double_t phiprev=0.;
223
224   for (Int_t i=0; i<maxNumberOfIterations; i++)
225   {
226     phiprev=fPhi; //store last value for comparison
227     f =  fPhi-phi0+0.5*v4*TMath::Sin(4.*(fPhi-reactionPlaneAngle));
228     fp = 1.0+2.0*v4*TMath::Cos(4.*(fPhi-reactionPlaneAngle)); //first derivative
229     fPhi -= f/fp;
230     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
231   }
232 }
233
234 //----------------------------------------------------------------------- 
235 void AliFlowTrackSimple::AddV5( Double_t v5,
236                                 Double_t reactionPlaneAngle,
237                                 Double_t precisionPhi,
238                                 Int_t maxNumberOfIterations )
239 {
240   //afterburner, adds v4, uses Newton-Raphson iteration
241   Double_t phi0=fPhi;
242   Double_t f=0.;
243   Double_t fp=0.;
244   Double_t phiprev=0.;
245
246   for (Int_t i=0; i<maxNumberOfIterations; i++)
247   {
248     phiprev=fPhi; //store last value for comparison
249     f =  fPhi-phi0+0.4*v5*TMath::Sin(5.*(fPhi-reactionPlaneAngle));
250     fp = 1.0+2.0*v5*TMath::Cos(5.*(fPhi-reactionPlaneAngle)); //first derivative
251     fPhi -= f/fp;
252     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
253   }
254 }
255
256 //______________________________________________________________________________
257 void AliFlowTrackSimple::AddFlow( Double_t v1,
258                                   Double_t v2,
259                                   Double_t v3,
260                                   Double_t v4,
261                                   Double_t v5,
262                                   Double_t rp1,
263                                   Double_t rp2,
264                                   Double_t rp3,
265                                   Double_t rp4,
266                                   Double_t rp5,
267                                   Double_t precisionPhi,
268                                   Int_t maxNumberOfIterations )
269 {
270   //afterburner, adds v1,v2,v4 uses Newton-Raphson iteration
271   Double_t phi0=fPhi;
272   Double_t f=0.;
273   Double_t fp=0.;
274   Double_t phiprev=0.;
275
276   for (Int_t i=0; i<maxNumberOfIterations; i++)
277   {
278     phiprev=fPhi; //store last value for comparison
279     f =  fPhi-phi0
280         +2.0*  v1*TMath::Sin(    fPhi-rp1)
281         +      v2*TMath::Sin(2.*(fPhi-rp2))
282         +2./3.*v3*TMath::Sin(3.*(fPhi-rp3))
283         +0.5*  v4*TMath::Sin(4.*(fPhi-rp4))
284         +0.4*  v5*TMath::Sin(5.*(fPhi-rp5))
285         ;
286     fp =  1.0
287          +2.0*(
288            +v1*TMath::Cos(    fPhi-rp1)
289            +v2*TMath::Cos(2.*(fPhi-rp2))
290            +v3*TMath::Cos(3.*(fPhi-rp3))
291            +v4*TMath::Cos(4.*(fPhi-rp4))
292            +v5*TMath::Cos(5.*(fPhi-rp5))
293          ); //first derivative
294     fPhi -= f/fp;
295     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
296   }
297 }
298
299 //______________________________________________________________________________
300 void AliFlowTrackSimple::AddFlow( Double_t v1,
301                                   Double_t v2,
302                                   Double_t v3,
303                                   Double_t v4,
304                                   Double_t v5,
305                                   Double_t rp,
306                                   Double_t precisionPhi,
307                                   Int_t maxNumberOfIterations )
308 {
309   //afterburner, adds v1,v2,v4 uses Newton-Raphson iteration
310   AddFlow(v1,v2,v3,v4,v5,rp,rp,rp,rp,rp,precisionPhi,maxNumberOfIterations);
311 }
312
313 //______________________________________________________________________________
314 void AliFlowTrackSimple::AddFlow( Double_t v1,
315                                   Double_t v2,
316                                   Double_t v3,
317                                   Double_t v4,
318                                   Double_t reactionPlaneAngle,
319                                   Double_t precisionPhi,
320                                   Int_t maxNumberOfIterations )
321 {
322   //afterburner, adds v1,v2,v4 uses Newton-Raphson iteration
323   Double_t phi0=fPhi;
324   Double_t f=0.;
325   Double_t fp=0.;
326   Double_t phiprev=0.;
327
328   for (Int_t i=0; i<maxNumberOfIterations; i++)
329   {
330     phiprev=fPhi; //store last value for comparison
331     f =  fPhi-phi0
332         +2.0*  v1*TMath::Sin(    fPhi-reactionPlaneAngle)
333         +      v2*TMath::Sin(2.*(fPhi-reactionPlaneAngle))
334         +2./3.*v3*TMath::Sin(3.*(fPhi-reactionPlaneAngle))
335         +0.5*  v4*TMath::Sin(4.*(fPhi-reactionPlaneAngle))
336         ;
337     fp =  1.0
338          +2.0*(
339            +v1*TMath::Cos(    fPhi-reactionPlaneAngle)
340            +v2*TMath::Cos(2.*(fPhi-reactionPlaneAngle))
341            +v3*TMath::Cos(3.*(fPhi-reactionPlaneAngle))
342            +v4*TMath::Cos(4.*(fPhi-reactionPlaneAngle))
343          ); //first derivative
344     fPhi -= f/fp;
345     if (TMath::AreEqualAbs(phiprev,fPhi,precisionPhi)) break;
346   }
347 }
348
349 //______________________________________________________________________________
350 void AliFlowTrackSimple::Print( Option_t* /*option*/ ) const
351 {
352   //print stuff
353   printf("Phi: %.3f, Eta: %+.3f, Pt: %.3f, weight: %.3f",fPhi,fEta,fPt,fTrackWeight);
354   if (InRPSelection()) printf(", RP");
355   if (InPOISelection()) printf(", POI");
356   for (Int_t i=0; i<2; i++)
357   {
358     if (InSubevent(i)) printf(", subevent %i",i);
359   }
360   printf("\n");
361 }
362
363 //______________________________________________________________________________
364 void AliFlowTrackSimple::Clear(Option_t*)
365 {
366   //clear track
367   fEta=0.0;
368   fPt=0.0;
369   fPhi=0.0;
370   fTrackWeight=1.0;
371   fCharge=0;
372   fFlowBits.ResetAllBits();
373   fSubEventBits.ResetAllBits();
374   fID=-1;
375 }