]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/flow/AliFMDFlowEventPlane.cxx
Fix coding convention violations
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowEventPlane.cxx
1 /* Copyright (C) 2007 Christian Holm Christensen <cholm@nbi.dk>
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License
5  * as published by the Free Software Foundation; either version 2.1 of
6  * the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16  * USA
17  */
18 /** @file 
19     @brief Implementation of an EventPlane class */
20 //____________________________________________________________________
21 //
22 // Class to determine the event plane 
23 // 
24 // The event plane is calculated as 
25 // 
26 //    Psi_n = 1/n * atan((sum_i(w_i sin(n phi_i)))
27 //                        sum_i(w_i cos(n phi_i))))
28 //
29 // where i runs over all observations of phi in an event, and 
30 // w_i is the weight of the ith observation of phi
31 #include "flow/AliFMDFlowEventPlane.h"
32 #include "flow/AliFMDFlowUtil.h"
33 #include <TMath.h>
34 // #include <cmath>
35 #ifndef _GNU_SOURCE
36 extern "C" 
37 {
38   /** Function to caculate @f$ \sin(a), \cos(a)@f$ in one go.  Note,
39       that with GCC, this is a built-in, and we only have this to
40       serve as a replacement function 
41       @ingroup utils */
42   inline void sincos(Double_t a, Double_t* sina, Double_t* cosa) {
43     *sina = sin(a);
44     *cosa = cos(a);
45   }
46 }
47 #endif
48
49 //====================================================================
50 AliFMDFlowEventPlane::AliFMDFlowEventPlane(const AliFMDFlowEventPlane& o)
51   : TObject(o), 
52     fSumSinMPhi(o.fSumSinMPhi),
53     fSumCosMPhi(o.fSumCosMPhi),
54     fOrder(o.fOrder),
55     fCache(-1)
56 {
57   // copy cosntructor 
58   // Parameters 
59   //   o  Object to copy from. 
60 }
61 //____________________________________________________________________
62 AliFMDFlowEventPlane&
63 AliFMDFlowEventPlane::operator=(const AliFMDFlowEventPlane& o)
64 {
65   // Assignment operator. 
66   // Parameters: 
67   //  o Object to assign from 
68   fSumSinMPhi = o.fSumSinMPhi;
69   fSumCosMPhi = o.fSumCosMPhi;
70   fOrder      = o.fOrder;
71   fCache      = -1;
72   return *this;
73 }
74
75 //____________________________________________________________________
76 void 
77 AliFMDFlowEventPlane::Clear(Option_t*) 
78
79   // clear internal variables. 
80   fSumSinMPhi = 0;
81   fSumCosMPhi = 0;
82   fCache      = -1;
83 }
84 //____________________________________________________________________
85 void 
86 AliFMDFlowEventPlane::Add(Double_t phi, Double_t weight) 
87
88   // Add a data point 
89   // Parameters: 
90   //   phi     The angle phi in[0,2pi]
91   //   weight  The weight 
92   Double_t a = NormalizeAngle(fOrder * phi);
93   Double_t s, c;
94   sincos(a, &s, &c);
95   if (TMath::IsNaN(s) || !TMath::Finite(s) || 
96       TMath::IsNaN(c) || !TMath::Finite(s)) return;
97   fSumSinMPhi += weight * s;
98   fSumCosMPhi += weight * c;
99 }
100 //____________________________________________________________________
101 Double_t 
102 AliFMDFlowEventPlane::Psi() const  
103
104   // Get the event plane 
105   // Parameters: 
106   //   none
107   if (fCache < 0) fCache = DoPsi(fSumSinMPhi, fSumCosMPhi);
108   return fCache;
109 }
110 //____________________________________________________________________
111 Double_t 
112 AliFMDFlowEventPlane::Psi(Double_t phi, Double_t w) const  
113
114   // Get the event plane angle Psi_k disregarding the contribution
115   // from the observation phi with weight w.  This is to avoid
116   // auto-correlations  
117   // 
118   // Parameters: 
119   //  phi   The observation  phi
120   //  w     The weight w of the obervation. 
121   // 
122   // Returns The event plane angle Psi with out the contribution from
123   // phi_i
124   Double_t a = NormalizeAngle(fOrder * phi);
125   Double_t s, c;
126   sincos(a, &s, &c);
127   if (TMath::IsNaN(s) || !TMath::Finite(s) || 
128       TMath::IsNaN(c) || !TMath::Finite(s)) return Psi();
129   Double_t psi = DoPsi(fSumSinMPhi - w * s, fSumCosMPhi - w * c);
130   return psi;
131 }
132
133 //____________________________________________________________________
134 Double_t 
135 AliFMDFlowEventPlane::DoPsi(Double_t sumsin, Double_t sumcos) const
136 {
137   // Calculate the event plane 
138   // Parameters: 
139   //   sumsin    Sum of sines 
140   //   sumcos    Sum of cosines 
141   Double_t psi = 0;
142   // Make sure we get an angle everywhere 
143   if      (sumcos != 0) psi =  atan2(sumsin, sumcos);
144   else if (sumsin == 0) psi =  0;
145   else if (sumsin >  0) psi =  M_PI / 2;
146   else                  psi = -M_PI / 2;
147   psi =  NormalizeAngle(psi);
148   psi /= fOrder;
149   return psi;
150 }
151
152 //____________________________________________________________________
153 //
154 // EOF
155 //
156