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 a 2-dimensional Flow "histogram" */
20 //____________________________________________________________________
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
28 #include "flow/AliFMDFlowBinned2D.h"
29 #include "flow/AliFMDFlowBin.h"
30 #include "flow/AliFMDFlowSplitter.h"
36 //====================================================================
37 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const char* name,
40 UShort_t nxbins, Double_t* xbins,
41 UShort_t nybins, Double_t* ybins,
42 AliFMDFlowSplitter* splitter)
43 : TNamed(name, title),
44 fXAxis(nxbins, xbins),
45 fYAxis(nybins, ybins),
52 // nxbins Number of X bins
53 // xbins X Bin borders
54 // nybins Number of Y bins
55 // ybins Y Bin borders
56 UInt_t n = fXAxis.N() * fYAxis.N();
57 fBins = new AliFMDFlowBin*[n];
58 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
59 if (!fSplitter) fSplitter = new AliFMDFlowShuffle;
61 //____________________________________________________________________
62 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const char* name,
65 const AliFMDFlowAxis& xaxis,
66 const AliFMDFlowAxis& yaxis,
67 AliFMDFlowSplitter* splitter)
68 : TNamed(name, title),
77 // xaxis X axis object
78 // yaxis Y axis object
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(order);
82 if (!fSplitter) fSplitter = new AliFMDFlowShuffle;
84 //____________________________________________________________________
85 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
97 // o Object to copy from
98 UShort_t n = fXAxis.N() * fYAxis.N();
99 fSplitter = new AliFMDFlowShuffle;
100 fBins = new AliFMDFlowBin*[n];
101 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
103 //____________________________________________________________________
105 AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
107 // Assignment operator
109 // o Object to assign from
111 // Returns reference to this object
112 SetLineColor(o.GetLineColor());
113 SetLineStyle(o.GetLineStyle());
114 SetLineWidth(o.GetLineWidth());
115 SetFillColor(o.GetFillColor());
116 SetFillStyle(o.GetFillStyle());
117 SetMarkerColor(o.GetMarkerColor());
118 SetMarkerStyle(o.GetMarkerStyle());
119 SetMarkerSize(o.GetMarkerSize());
121 UInt_t n = fXAxis.N() * fYAxis.N();
122 for (UInt_t i = 0; i < n; i++) delete fBins[i];
126 UShort_t n = fXAxis.N() * fYAxis.N();
127 fSplitter = new AliFMDFlowShuffle;
128 fBins = new AliFMDFlowBin*[n];
129 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
133 //____________________________________________________________________
134 AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
140 UInt_t n = fXAxis.N() * fYAxis.N();
141 for (UInt_t i = 0; i < n; i++) delete fBins[i];
144 if (fSplitter) delete fSplitter;
146 //____________________________________________________________________
148 AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
150 // Get the ith,jth bin
155 // Return pointer to bin, or null.
156 if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
157 return fBins[i * fYAxis.N() + j];
159 //____________________________________________________________________
161 AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
163 // Get the bin that contains x,y
168 // Return pointer to bin, or null.
169 Int_t i = fXAxis.FindBin(x);
171 Int_t j = fYAxis.FindBin(y);
177 //____________________________________________________________________
179 AliFMDFlowBinned2D::Begin()
181 // Called at the beginning of an event
184 UInt_t n = fXAxis.N() * fYAxis.N();
185 for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
187 //____________________________________________________________________
189 AliFMDFlowBinned2D::End()
191 // Called at the end of an event
194 UInt_t n = fXAxis.N() * fYAxis.N();
195 for (UInt_t i = 0; i < n; i++) fBins[i]->End();
197 //____________________________________________________________________
199 AliFMDFlowBinned2D::Finish()
201 // Called at the end of an job
204 UInt_t n = fXAxis.N() * fYAxis.N();
205 for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
207 //____________________________________________________________________
209 AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi,
210 Double_t w, Bool_t a)
212 // Called to add a contribution to the event plane
214 // x X Bin value to fill into
215 // y Y Bin value to fill into
217 // phi The angle phi in radians
218 // a If true, add to sub-event A, otherwise sub-event B
220 // Return false if (x,y) falls outside the defined range, true otherwise
221 AliFMDFlowBin* bin = GetBin(x, y);
222 if (!bin) return kFALSE;
223 bin->AddToEventPlane(phi, w, a);
227 //____________________________________________________________________
229 AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi,
230 Double_t wp, Double_t wh)
232 // Called to add a contribution to the harmonic
234 // x X Bin value to fill into
235 // y Y Bin value to fill into
236 // phi The angle phi in radians
238 // Return false if (x,y) falls outside the defined range, true otherwise
239 AliFMDFlowBin* bin = GetBin(x, y);
240 if (!bin) return kFALSE;
241 bin->AddToHarmonic(phi, wp, wh);
245 //____________________________________________________________________
247 AliFMDFlowBinned2D::Event(ULong_t n, Double_t* phis,
248 Double_t* xs, Double_t* ys,
249 Double_t* wp, Double_t* wh)
251 // Process a full event.
253 // phis List of n phi=[0,2pi] angles
254 // xs List of n x values.
255 // ys List of n y values.
256 // wp Weights for event plane
257 // wh Weights for harmonic
258 // n Size of phis and xs
260 fSplitter->Event(phis, xs, n);
261 for (UInt_t i = 0; i < n; i++)
262 AddToEventPlane(xs[i], ys[i], phis[i], (wp ? wp[i] : 1),
263 fSplitter->Select(i));
264 for (UInt_t i = 0; i < n; i++)
265 AddToHarmonic(xs[i], ys[i], phis[i], (wp ? wh[i] : 1), (wp ? wh[i] : 1));
269 //____________________________________________________________________
271 AliFMDFlowBinned2D::Browse(TBrowser* b)
273 // Browse this object
274 b->Add(&fXAxis, "xaxis");
275 b->Add(&fYAxis, "yaxis");
276 for (UInt_t i = 0; i < fXAxis.N(); i++) {
277 for (UInt_t j = 0; i < fYAxis.N(); j++) {
278 b->Add(fBins[i*fXAxis.N()+j], Form("bin_%03d_%03d", i, j));
283 //____________________________________________________________________