]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/flow/AliFMDFlowBinned2D.cxx
Misalignment-related bug fixed
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowBinned2D.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 a 2-dimensional Flow "histogram" */
97e94238 20//____________________________________________________________________
21//
22// A histogram of flow bins. The axis can by anything
23// (pseudo-rapidity, transvers momentum) - there's no assumption on
24// what is the basis of the histogram. The method Event can be used
25// to calculate everything in one go. Alternatively, one can use the
26// methods AddToEventPlane and AddToHarmonic. See also the example
27// TestFlow.C
39eefe19 28#include "flow/AliFMDFlowBinned2D.h"
29#include "flow/AliFMDFlowBin.h"
30#include <cmath>
31#include <cstdlib>
32#include <TString.h>
33#include <TBrowser.h>
34
35//====================================================================
36AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order,
37 UShort_t nxbins, Double_t* xbins,
38 UShort_t nybins, Double_t* ybins)
39 : fXAxis(nxbins, xbins),
40 fYAxis(nybins, ybins),
41 fBins(0)
42{
97e94238 43 // Constructor
44 // Parameters:
45 // Order Order
46 // nxbins Number of X bins
47 // xbins X Bin borders
48 // nybins Number of Y bins
49 // ybins Y Bin borders
39eefe19 50 UInt_t n = fXAxis.N() * fYAxis.N();
51 fBins = new AliFMDFlowBin*[n];
52 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
53}
54//____________________________________________________________________
55AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order,
97e94238 56 const AliFMDFlowAxis& xaxis,
57 const AliFMDFlowAxis& yaxis)
39eefe19 58 : fXAxis(xaxis),
59 fYAxis(yaxis)
60{
97e94238 61 // Constructor
62 // Parameters:
63 // Order Order
64 // xaxis X axis object
65 // yaxis Y axis object
39eefe19 66 UShort_t n = fXAxis.N() * fYAxis.N();
67 fBins = new AliFMDFlowBin*[n];
68 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
69}
70//____________________________________________________________________
71AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
72 : TObject(o),
73 fXAxis(o.fXAxis),
74 fYAxis(o.fYAxis)
75{
97e94238 76 // Copy constructor
77 // Parameters:
78 // o Object to copy from
39eefe19 79 UShort_t n = fXAxis.N() * fYAxis.N();
80 fBins = new AliFMDFlowBin*[n];
81 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
82}
83//____________________________________________________________________
84AliFMDFlowBinned2D&
85AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
86{
97e94238 87 // Assignment operator
88 // Parameters:
89 // o Object to assign from
90 //
91 // Returns reference to this object
39eefe19 92 if (fBins) {
93 UInt_t n = fXAxis.N() * fYAxis.N();
94 for (UInt_t i = 0; i < n; i++) delete fBins[i];
95 delete [] fBins;
96 }
97 fXAxis = o.fXAxis;
98 UShort_t n = fXAxis.N() * fYAxis.N();
99 fBins = new AliFMDFlowBin*[n];
100 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
101 return *this;
102}
103
104//____________________________________________________________________
105AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
106{
97e94238 107 // Destructor
108 // Parameters:
109 // none
39eefe19 110 if (fBins) {
111 UInt_t n = fXAxis.N() * fYAxis.N();
112 for (UInt_t i = 0; i < n; i++) delete fBins[i];
113 delete [] fBins;
114 }
115}
116//____________________________________________________________________
117AliFMDFlowBin*
118AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
119{
97e94238 120 // Get the ith,jth bin
121 // Parameters:
122 // i X Bin number
123 // j Y Bin number
124 //
125 // Return pointer to bin, or null.
39eefe19 126 if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
127 return fBins[i * fYAxis.N() + j];
128}
129//____________________________________________________________________
130AliFMDFlowBin*
131AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
132{
97e94238 133 // Get the bin that contains x,y
134 // Parameters:
135 // x X axis value
136 // y X axis value
137 //
138 // Return pointer to bin, or null.
39eefe19 139 Int_t i = fXAxis.FindBin(x);
140 if (i < 0) return 0;
141 Int_t j = fYAxis.FindBin(y);
142 if (j < 0) return 0;
143 UShort_t k = i;
144 UShort_t l = j;
145 return GetBin(k, l);
146}
147//____________________________________________________________________
148void
149AliFMDFlowBinned2D::Begin()
150{
97e94238 151 // Called at the beginning of an event
152 // Parameters:
153 // none
39eefe19 154 UInt_t n = fXAxis.N() * fYAxis.N();
155 for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
156}
157//____________________________________________________________________
158void
159AliFMDFlowBinned2D::End()
160{
97e94238 161 // Called at the end of an event
162 // Parameters:
163 // none
39eefe19 164 UInt_t n = fXAxis.N() * fYAxis.N();
165 for (UInt_t i = 0; i < n; i++) fBins[i]->End();
166}
167//____________________________________________________________________
168void
169AliFMDFlowBinned2D::Finish()
170{
97e94238 171 // Called at the end of an job
172 // Parameters:
173 // none
39eefe19 174 UInt_t n = fXAxis.N() * fYAxis.N();
175 for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
176}
177//____________________________________________________________________
178Bool_t
179AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi,
180 Double_t w, Bool_t a)
181{
97e94238 182 // Called to add a contribution to the event plane
183 // Parameters:
184 // x X Bin value to fill into
185 // y Y Bin value to fill into
186 // w Weight
187 // phi The angle phi in radians
188 // a If true, add to sub-event A, otherwise sub-event B
189 //
190 // Return false if (x,y) falls outside the defined range, true otherwise
39eefe19 191 AliFMDFlowBin* bin = GetBin(x, y);
192 if (!bin) return kFALSE;
193 bin->AddToEventPlane(phi, w, a);
194 return kTRUE;
195}
196
197//____________________________________________________________________
198Bool_t
199AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi)
200{
97e94238 201 // Called to add a contribution to the harmonic
202 // Parameters:
203 // x X Bin value to fill into
204 // y Y Bin value to fill into
205 // phi The angle phi in radians
206 //
207 // Return false if (x,y) falls outside the defined range, true otherwise
39eefe19 208 AliFMDFlowBin* bin = GetBin(x, y);
209 if (!bin) return kFALSE;
210 bin->AddToHarmonic(phi);
211 return kTRUE;
212}
213
214//____________________________________________________________________
215void
216AliFMDFlowBinned2D::Event(Double_t* phis, Double_t* xs, Double_t* ys,
217 Double_t* ws, ULong_t n)
218{
97e94238 219 // Process a full event.
220 // Parameters:
221 // phis List of n phi=[0,2pi] angles
222 // xs List of n x values.
223 // ys List of n y values.
224 // ws Weights
225 // n Size of phis and xs
39eefe19 226 Begin();
227 for (UInt_t i = 0; i < n; i++)
228 AddToEventPlane(xs[i], ys[i], phis[i], (ws ? ws[i] : 1),
229 Float_t(rand()) / RAND_MAX > 0.5);
230 for (UInt_t i = 0; i < n; i++)
231 AddToHarmonic(xs[i], ys[i], phis[i]);
232 End();
233}
234
235//____________________________________________________________________
236void
237AliFMDFlowBinned2D::Browse(TBrowser* b)
238{
97e94238 239 // Browse this object
39eefe19 240 b->Add(&fXAxis, "xaxis");
241 b->Add(&fYAxis, "yaxis");
242 for (UInt_t i = 0; i < fXAxis.N(); i++) {
243 for (UInt_t j = 0; i < fYAxis.N(); j++) {
244 b->Add(fBins[i*fXAxis.N()+j], Form("bin_%03d_%03d", i, j));
245 }
246 }
247}
248
249//____________________________________________________________________
250//
251// EOF
252//