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"
35 //====================================================================
36 AliFMDFlowBinned2D::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),
46 // nxbins Number of X bins
47 // xbins X Bin borders
48 // nybins Number of Y bins
49 // ybins Y Bin borders
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);
54 //____________________________________________________________________
55 AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order,
56 const AliFMDFlowAxis& xaxis,
57 const AliFMDFlowAxis& yaxis)
64 // xaxis X axis object
65 // yaxis Y axis object
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);
70 //____________________________________________________________________
71 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
78 // o Object to copy from
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]));
83 //____________________________________________________________________
85 AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
87 // Assignment operator
89 // o Object to assign from
91 // Returns reference to this object
93 UInt_t n = fXAxis.N() * fYAxis.N();
94 for (UInt_t i = 0; i < n; i++) delete fBins[i];
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]));
104 //____________________________________________________________________
105 AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
111 UInt_t n = fXAxis.N() * fYAxis.N();
112 for (UInt_t i = 0; i < n; i++) delete fBins[i];
116 //____________________________________________________________________
118 AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
120 // Get the ith,jth bin
125 // Return pointer to bin, or null.
126 if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
127 return fBins[i * fYAxis.N() + j];
129 //____________________________________________________________________
131 AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
133 // Get the bin that contains x,y
138 // Return pointer to bin, or null.
139 Int_t i = fXAxis.FindBin(x);
141 Int_t j = fYAxis.FindBin(y);
147 //____________________________________________________________________
149 AliFMDFlowBinned2D::Begin()
151 // Called at the beginning of an event
154 UInt_t n = fXAxis.N() * fYAxis.N();
155 for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
157 //____________________________________________________________________
159 AliFMDFlowBinned2D::End()
161 // Called at the end of an event
164 UInt_t n = fXAxis.N() * fYAxis.N();
165 for (UInt_t i = 0; i < n; i++) fBins[i]->End();
167 //____________________________________________________________________
169 AliFMDFlowBinned2D::Finish()
171 // Called at the end of an job
174 UInt_t n = fXAxis.N() * fYAxis.N();
175 for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
177 //____________________________________________________________________
179 AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi,
180 Double_t w, Bool_t a)
182 // Called to add a contribution to the event plane
184 // x X Bin value to fill into
185 // y Y Bin value to fill into
187 // phi The angle phi in radians
188 // a If true, add to sub-event A, otherwise sub-event B
190 // Return false if (x,y) falls outside the defined range, true otherwise
191 AliFMDFlowBin* bin = GetBin(x, y);
192 if (!bin) return kFALSE;
193 bin->AddToEventPlane(phi, w, a);
197 //____________________________________________________________________
199 AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi)
201 // Called to add a contribution to the harmonic
203 // x X Bin value to fill into
204 // y Y Bin value to fill into
205 // phi The angle phi in radians
207 // Return false if (x,y) falls outside the defined range, true otherwise
208 AliFMDFlowBin* bin = GetBin(x, y);
209 if (!bin) return kFALSE;
210 bin->AddToHarmonic(phi);
214 //____________________________________________________________________
216 AliFMDFlowBinned2D::Event(Double_t* phis, Double_t* xs, Double_t* ys,
217 Double_t* ws, ULong_t n)
219 // Process a full event.
221 // phis List of n phi=[0,2pi] angles
222 // xs List of n x values.
223 // ys List of n y values.
225 // n Size of phis and xs
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]);
235 //____________________________________________________________________
237 AliFMDFlowBinned2D::Browse(TBrowser* b)
239 // Browse this object
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));
249 //____________________________________________________________________