1 /* Copyright (C) 2007 Christian Holm Christensen <cholm@nbi.dk>
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.
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.
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
19 @brief Implementation of an EventPlane class */
20 //____________________________________________________________________
22 // Class to determine the event plane
24 // The event plane is calculated as
26 // Psi_n = 1/n * atan((sum_i(w_i sin(n phi_i)))
27 // sum_i(w_i cos(n phi_i))))
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"
35 // #include <iostream>
38 //#warning Using private implementation of sincos
41 /** Function to caculate @f$ \sin(a), \cos(a)@f$ in one go. Note,
42 that with GCC, this is a built-in, and we only have this to
43 serve as a replacement function
45 inline void sincos(Double_t a, Double_t* sina, Double_t* cosa) {
52 //====================================================================
53 AliFMDFlowEventPlane::AliFMDFlowEventPlane(UShort_t m)
58 fSum("sum", Form("#sumw#cos(%d#varphi) vs #sum#sin(%d#varphi)", m, m),
59 100, -1.1, 1.1, 100, -1.1, 1.1),
60 fPsi("psi", Form("#Psi_{%d}", m), 80, 0, 2*TMath::Pi()),
65 fSum.SetXTitle(Form("#sum_{i}w_{i}cos(%d#varphi_{i})", fOrder));
66 fSum.SetYTitle(Form("#sum_{i}w_{i}sin(%d#varphi_{i})", fOrder));
67 fSum.SetMarkerStyle(20);
69 fPsi.SetXTitle(Form("#Psi_{%d}", fOrder));
72 //____________________________________________________________________
73 AliFMDFlowEventPlane::AliFMDFlowEventPlane(const AliFMDFlowEventPlane& o)
75 fSumSinMPhi(o.fSumSinMPhi),
76 fSumCosMPhi(o.fSumCosMPhi),
85 // o Object to copy from.
87 fSum.SetXTitle(Form("#sum_{i}w_{i}cos(%d#varphi_{i})", fOrder));
88 fSum.SetYTitle(Form("#sum_{i}w_{i}sin(%d#varphi_{i})", fOrder));
89 fSum.SetMarkerStyle(20);
91 fPsi.SetXTitle(Form("#Psi_{%d}", fOrder));
93 //____________________________________________________________________
95 AliFMDFlowEventPlane::operator=(const AliFMDFlowEventPlane& o)
97 // Assignment operator.
99 // o Object to assign from
100 fSumSinMPhi = o.fSumSinMPhi;
101 fSumCosMPhi = o.fSumCosMPhi;
114 //____________________________________________________________________
116 AliFMDFlowEventPlane::Clear(Option_t*)
118 // clear internal variables.
124 //____________________________________________________________________
126 AliFMDFlowEventPlane::Add(Double_t phi, Double_t weight)
130 // phi The angle phi in[0,2pi]
132 Double_t a = NormalizeAngle(fOrder * phi);
135 if (TMath::IsNaN(s) || !TMath::Finite(s) ||
136 TMath::IsNaN(c) || !TMath::Finite(s)) return;
137 if (weight == 0) return;
139 fSumSinMPhi += weight * s;
140 fSumCosMPhi += weight * c;
143 //____________________________________________________________________
145 AliFMDFlowEventPlane::End()
147 Double_t r2 = fSumCosMPhi*fSumCosMPhi + fSumSinMPhi*fSumSinMPhi;
148 Double_t r = (r2 < 0 ? 1 : TMath::Sqrt(r2));
149 fSum.Fill(fSumCosMPhi/(r!=0?r:1),fSumSinMPhi/(r!=0?r:1));
153 //____________________________________________________________________
155 AliFMDFlowEventPlane::Browse(TBrowser* b)
161 //____________________________________________________________________
163 AliFMDFlowEventPlane::Psi() const
165 // Get the event plane
169 fCache = DoPsi(fSumSinMPhi, fSumCosMPhi);
173 //____________________________________________________________________
175 AliFMDFlowEventPlane::Psi(Double_t phi, Double_t w) const
177 // Get the event plane angle Psi_k disregarding the contribution
178 // from the observation phi with weight w. This is to avoid
182 // phi The observation phi
183 // w The weight w of the obervation.
185 // Returns The event plane angle Psi with out the contribution from
187 Double_t a = NormalizeAngle(fOrder * phi);
190 if (TMath::IsNaN(s) || !TMath::Finite(s) ||
191 TMath::IsNaN(c) || !TMath::Finite(s)) return Psi();
192 Double_t psi = DoPsi(fSumSinMPhi - w * s, fSumCosMPhi - w * c);
196 //____________________________________________________________________
198 AliFMDFlowEventPlane::DoPsi(Double_t sumsin, Double_t sumcos) const
200 // Calculate the event plane
202 // sumsin Sum of sines
203 // sumcos Sum of cosines
205 // Make sure we get an angle everywhere
206 if (sumcos != 0) psi = atan2(sumsin, sumcos);
207 else if (sumsin == 0) psi = 0;
208 else if (sumsin > 0) psi = M_PI / 2;
209 else psi = -M_PI / 2;
210 psi = NormalizeAngle(psi);
215 //____________________________________________________________________