]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/flow/AliFMDFlowEventPlane.cxx
Added code to do flow analysis.
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowEventPlane.cxx
1 /** @file 
2     @brief Implementation of an EventPlane class */
3 #include "flow/AliFMDFlowEventPlane.h"
4 #include "flow/AliFMDFlowUtil.h"
5 // #include <cmath>
6 #ifndef _GNU_SOURCE
7 extern "C" 
8 {
9   /** Function to caculate @f$ \sin(a), \cos(a)@f$ in one go.  Note,
10       that with GCC, this is a built-in, and we only have this to
11       serve as a replacement function 
12       @ingroup utils */
13   inline void sincos(Double_t a, Double_t* sina, Double_t* cosa) {
14     *sina = sin(a);
15     *cosa = cos(a);
16   }
17 }
18 #endif
19
20 //====================================================================
21 void 
22 AliFMDFlowEventPlane::Clear(Option_t*) 
23
24   fSumSinMPhi = 0;
25   fSumCosMPhi = 0;
26   fCache      = -1;
27 }
28 //____________________________________________________________________
29 void 
30 AliFMDFlowEventPlane::Add(Double_t phi, Double_t weight) 
31
32   Double_t a = NormalizeAngle(fOrder * phi);
33   Double_t s, c;
34   sincos(a, &s, &c);
35   if (isnan(s) || isinf(s) || isnan(c) || isinf(s)) return;
36   fSumSinMPhi += weight * s;
37   fSumCosMPhi += weight * c;
38 }
39 //____________________________________________________________________
40 Double_t 
41 AliFMDFlowEventPlane::Psi() const  
42
43   if (fCache < 0) fCache = DoPsi(fSumSinMPhi, fSumCosMPhi);
44   return fCache;
45 }
46 //____________________________________________________________________
47 Double_t 
48 AliFMDFlowEventPlane::Psi(Double_t phi, Double_t w) const  
49
50   Double_t a = NormalizeAngle(fOrder * phi);
51   Double_t s, c;
52   sincos(a, &s, &c);
53   if (isnan(s) || isinf(s) || isnan(c) || isinf(s)) return Psi();
54   Double_t psi = DoPsi(fSumSinMPhi - w * s, fSumCosMPhi - w * c);
55   return psi;
56 }
57
58 //____________________________________________________________________
59 Double_t 
60 AliFMDFlowEventPlane::DoPsi(Double_t sumsin, Double_t sumcos) const
61 {
62   Double_t psi = 0;
63   // Make sure we get an angle everywhere 
64   if      (sumcos != 0) psi =  atan2(sumsin, sumcos);
65   else if (sumsin == 0) psi =  0;
66   else if (sumsin >  0) psi =  M_PI / 2;
67   else                  psi = -M_PI / 2;
68   psi =  NormalizeAngle(psi);
69   psi /= fOrder;
70   return psi;
71 }
72
73 //____________________________________________________________________
74 //
75 // EOF
76 //
77