]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/flow/AliFMDFlowEventPlane.cxx
coding conventions and compilation warnings
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowEventPlane.cxx
CommitLineData
97e94238 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 */
39eefe19 18/** @file
19 @brief Implementation of an EventPlane class */
97e94238 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
39eefe19 31#include "flow/AliFMDFlowEventPlane.h"
32#include "flow/AliFMDFlowUtil.h"
57f71fe4 33#include <TMath.h>
9b98d361 34#include <TBrowser.h>
35// #include <iostream>
39eefe19 36// #include <cmath>
37#ifndef _GNU_SOURCE
9b98d361 38#warning Using private implementation of sincos
39eefe19 39extern "C"
40{
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
44 @ingroup utils */
45 inline void sincos(Double_t a, Double_t* sina, Double_t* cosa) {
46 *sina = sin(a);
47 *cosa = cos(a);
48 }
49}
50#endif
51
52//====================================================================
9b98d361 53AliFMDFlowEventPlane::AliFMDFlowEventPlane(UShort_t m)
54 : fSumSinMPhi(0),
55 fSumCosMPhi(0),
56 fOrder(m),
57 fCache(0),
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())
61{
62 Clear();
63 fSum.SetDirectory(0);
64 fSum.SetXTitle(Form("#sum_{i}w_{i}cos(%d#varphi_{i})", fOrder));
65 fSum.SetYTitle(Form("#sum_{i}w_{i}sin(%d#varphi_{i})", fOrder));
66 fSum.SetMarkerStyle(20);
67 fPsi.SetDirectory(0);
68 fPsi.SetXTitle(Form("#Psi_{%d}", fOrder));
69}
70
71//____________________________________________________________________
97e94238 72AliFMDFlowEventPlane::AliFMDFlowEventPlane(const AliFMDFlowEventPlane& o)
73 : TObject(o),
74 fSumSinMPhi(o.fSumSinMPhi),
75 fSumCosMPhi(o.fSumCosMPhi),
76 fOrder(o.fOrder),
9b98d361 77 fCache(-1),
78 fSum(o.fSum),
79 fPsi(o.fPsi)
97e94238 80{
81 // copy cosntructor
82 // Parameters
83 // o Object to copy from.
9b98d361 84 fSum.SetDirectory(0);
85 fSum.SetXTitle(Form("#sum_{i}w_{i}cos(%d#varphi_{i})", fOrder));
86 fSum.SetYTitle(Form("#sum_{i}w_{i}sin(%d#varphi_{i})", fOrder));
87 fSum.SetMarkerStyle(20);
88 fPsi.SetDirectory(0);
89 fPsi.SetXTitle(Form("#Psi_{%d}", fOrder));
97e94238 90}
91//____________________________________________________________________
92AliFMDFlowEventPlane&
93AliFMDFlowEventPlane::operator=(const AliFMDFlowEventPlane& o)
94{
95 // Assignment operator.
96 // Parameters:
97 // o Object to assign from
98 fSumSinMPhi = o.fSumSinMPhi;
99 fSumCosMPhi = o.fSumCosMPhi;
100 fOrder = o.fOrder;
101 fCache = -1;
9b98d361 102
103 fSum.Reset();
104 fSum.Add(&o.fSum);
105 fPsi.Reset();
106 fPsi.Add(&o.fPsi);
107
97e94238 108 return *this;
109}
110
111//____________________________________________________________________
39eefe19 112void
113AliFMDFlowEventPlane::Clear(Option_t*)
114{
97e94238 115 // clear internal variables.
39eefe19 116 fSumSinMPhi = 0;
117 fSumCosMPhi = 0;
118 fCache = -1;
9b98d361 119 fScale = 0;
39eefe19 120}
121//____________________________________________________________________
122void
123AliFMDFlowEventPlane::Add(Double_t phi, Double_t weight)
124{
97e94238 125 // Add a data point
126 // Parameters:
127 // phi The angle phi in[0,2pi]
128 // weight The weight
39eefe19 129 Double_t a = NormalizeAngle(fOrder * phi);
130 Double_t s, c;
131 sincos(a, &s, &c);
57f71fe4 132 if (TMath::IsNaN(s) || !TMath::Finite(s) ||
133 TMath::IsNaN(c) || !TMath::Finite(s)) return;
9b98d361 134 if (weight == 0) return;
135 fScale += 1./weight;
39eefe19 136 fSumSinMPhi += weight * s;
137 fSumCosMPhi += weight * c;
138}
9b98d361 139
140//____________________________________________________________________
141void
142AliFMDFlowEventPlane::End()
143{
144 Double_t r2 = fSumCosMPhi*fSumCosMPhi + fSumSinMPhi*fSumSinMPhi;
145 Double_t r = (r2 < 0 ? 1 : TMath::Sqrt(r2));
146 fSum.Fill(fSumCosMPhi/(r!=0?r:1),fSumSinMPhi/(r!=0?r:1));
147 fPsi.Fill(Psi());
148}
149
150//____________________________________________________________________
151void
152AliFMDFlowEventPlane::Browse(TBrowser* b)
153{
154 b->Add(&fSum);
155 b->Add(&fPsi);
156}
157
39eefe19 158//____________________________________________________________________
159Double_t
160AliFMDFlowEventPlane::Psi() const
161{
97e94238 162 // Get the event plane
163 // Parameters:
164 // none
9b98d361 165 if (fCache < 0) {
166 fCache = DoPsi(fSumSinMPhi, fSumCosMPhi);
167 }
39eefe19 168 return fCache;
169}
170//____________________________________________________________________
171Double_t
172AliFMDFlowEventPlane::Psi(Double_t phi, Double_t w) const
173{
97e94238 174 // Get the event plane angle Psi_k disregarding the contribution
175 // from the observation phi with weight w. This is to avoid
176 // auto-correlations
177 //
178 // Parameters:
179 // phi The observation phi
180 // w The weight w of the obervation.
181 //
182 // Returns The event plane angle Psi with out the contribution from
183 // phi_i
39eefe19 184 Double_t a = NormalizeAngle(fOrder * phi);
185 Double_t s, c;
186 sincos(a, &s, &c);
57f71fe4 187 if (TMath::IsNaN(s) || !TMath::Finite(s) ||
188 TMath::IsNaN(c) || !TMath::Finite(s)) return Psi();
39eefe19 189 Double_t psi = DoPsi(fSumSinMPhi - w * s, fSumCosMPhi - w * c);
190 return psi;
191}
192
193//____________________________________________________________________
194Double_t
195AliFMDFlowEventPlane::DoPsi(Double_t sumsin, Double_t sumcos) const
196{
97e94238 197 // Calculate the event plane
198 // Parameters:
199 // sumsin Sum of sines
200 // sumcos Sum of cosines
39eefe19 201 Double_t psi = 0;
202 // Make sure we get an angle everywhere
203 if (sumcos != 0) psi = atan2(sumsin, sumcos);
204 else if (sumsin == 0) psi = 0;
205 else if (sumsin > 0) psi = M_PI / 2;
206 else psi = -M_PI / 2;
207 psi = NormalizeAngle(psi);
208 psi /= fOrder;
209 return psi;
210}
211
212//____________________________________________________________________
213//
214// EOF
215//
216