coverity 15108 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"
9b98d361 30#include "flow/AliFMDFlowSplitter.h"
39eefe19 31#include <cmath>
32#include <cstdlib>
33#include <TString.h>
34#include <TBrowser.h>
35
36//====================================================================
9b98d361 37AliFMDFlowBinned2D::AliFMDFlowBinned2D(const char* name,
38 const char* title,
39 UShort_t order,
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),
39eefe19 45 fYAxis(nybins, ybins),
9b98d361 46 fBins(0),
47 fSplitter(splitter)
39eefe19 48{
97e94238 49 // Constructor
50 // Parameters:
51 // Order Order
52 // nxbins Number of X bins
53 // xbins X Bin borders
54 // nybins Number of Y bins
55 // ybins Y Bin borders
39eefe19 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);
9b98d361 59 if (!fSplitter) fSplitter = new AliFMDFlowShuffle;
39eefe19 60}
61//____________________________________________________________________
9b98d361 62AliFMDFlowBinned2D::AliFMDFlowBinned2D(const char* name,
63 const char* title,
64 UShort_t order,
65 const AliFMDFlowAxis& xaxis,
66 const AliFMDFlowAxis& yaxis,
67 AliFMDFlowSplitter* splitter)
68 : TNamed(name, title),
69 fXAxis(xaxis),
70 fYAxis(yaxis),
6ce810fc 71 fBins(0),
9b98d361 72 fSplitter(splitter)
39eefe19 73{
97e94238 74 // Constructor
75 // Parameters:
76 // Order Order
77 // xaxis X axis object
78 // yaxis Y axis object
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(order);
9b98d361 82 if (!fSplitter) fSplitter = new AliFMDFlowShuffle;
39eefe19 83}
84//____________________________________________________________________
85AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
9b98d361 86 : TNamed(o),
87 TAttLine(o),
88 TAttFill(o),
89 TAttMarker(o),
39eefe19 90 fXAxis(o.fXAxis),
9b98d361 91 fYAxis(o.fYAxis),
6ce810fc 92 fBins(0),
9b98d361 93 fSplitter(0)
39eefe19 94{
97e94238 95 // Copy constructor
96 // Parameters:
97 // o Object to copy from
39eefe19 98 UShort_t n = fXAxis.N() * fYAxis.N();
9b98d361 99 fSplitter = new AliFMDFlowShuffle;
100 fBins = new AliFMDFlowBin*[n];
39eefe19 101 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
102}
103//____________________________________________________________________
104AliFMDFlowBinned2D&
105AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
106{
97e94238 107 // Assignment operator
108 // Parameters:
109 // o Object to assign from
110 //
111 // Returns reference to this object
9b98d361 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());
39eefe19 120 if (fBins) {
121 UInt_t n = fXAxis.N() * fYAxis.N();
122 for (UInt_t i = 0; i < n; i++) delete fBins[i];
123 delete [] fBins;
124 }
125 fXAxis = o.fXAxis;
126 UShort_t n = fXAxis.N() * fYAxis.N();
9b98d361 127 fSplitter = new AliFMDFlowShuffle;
128 fBins = new AliFMDFlowBin*[n];
39eefe19 129 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
130 return *this;
131}
132
133//____________________________________________________________________
134AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
135{
97e94238 136 // Destructor
137 // Parameters:
138 // none
39eefe19 139 if (fBins) {
140 UInt_t n = fXAxis.N() * fYAxis.N();
141 for (UInt_t i = 0; i < n; i++) delete fBins[i];
142 delete [] fBins;
143 }
9b98d361 144 if (fSplitter) delete fSplitter;
39eefe19 145}
146//____________________________________________________________________
147AliFMDFlowBin*
148AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
149{
97e94238 150 // Get the ith,jth bin
151 // Parameters:
152 // i X Bin number
153 // j Y Bin number
154 //
155 // Return pointer to bin, or null.
39eefe19 156 if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
157 return fBins[i * fYAxis.N() + j];
158}
159//____________________________________________________________________
160AliFMDFlowBin*
161AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
162{
97e94238 163 // Get the bin that contains x,y
164 // Parameters:
165 // x X axis value
166 // y X axis value
167 //
168 // Return pointer to bin, or null.
39eefe19 169 Int_t i = fXAxis.FindBin(x);
170 if (i < 0) return 0;
171 Int_t j = fYAxis.FindBin(y);
172 if (j < 0) return 0;
173 UShort_t k = i;
174 UShort_t l = j;
175 return GetBin(k, l);
176}
177//____________________________________________________________________
178void
179AliFMDFlowBinned2D::Begin()
180{
97e94238 181 // Called at the beginning of an event
182 // Parameters:
183 // none
39eefe19 184 UInt_t n = fXAxis.N() * fYAxis.N();
185 for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
186}
187//____________________________________________________________________
188void
189AliFMDFlowBinned2D::End()
190{
97e94238 191 // Called at the end of an event
192 // Parameters:
193 // none
39eefe19 194 UInt_t n = fXAxis.N() * fYAxis.N();
195 for (UInt_t i = 0; i < n; i++) fBins[i]->End();
196}
197//____________________________________________________________________
198void
199AliFMDFlowBinned2D::Finish()
200{
97e94238 201 // Called at the end of an job
202 // Parameters:
203 // none
39eefe19 204 UInt_t n = fXAxis.N() * fYAxis.N();
205 for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
206}
207//____________________________________________________________________
208Bool_t
209AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi,
9b98d361 210 Double_t w, Bool_t a)
39eefe19 211{
97e94238 212 // Called to add a contribution to the event plane
213 // Parameters:
214 // x X Bin value to fill into
215 // y Y Bin value to fill into
216 // w Weight
217 // phi The angle phi in radians
218 // a If true, add to sub-event A, otherwise sub-event B
219 //
220 // Return false if (x,y) falls outside the defined range, true otherwise
39eefe19 221 AliFMDFlowBin* bin = GetBin(x, y);
222 if (!bin) return kFALSE;
223 bin->AddToEventPlane(phi, w, a);
224 return kTRUE;
225}
226
227//____________________________________________________________________
228Bool_t
9b98d361 229AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi,
230 Double_t wp, Double_t wh)
39eefe19 231{
97e94238 232 // Called to add a contribution to the harmonic
233 // Parameters:
234 // x X Bin value to fill into
235 // y Y Bin value to fill into
236 // phi The angle phi in radians
237 //
238 // Return false if (x,y) falls outside the defined range, true otherwise
39eefe19 239 AliFMDFlowBin* bin = GetBin(x, y);
240 if (!bin) return kFALSE;
9b98d361 241 bin->AddToHarmonic(phi, wp, wh);
39eefe19 242 return kTRUE;
243}
244
245//____________________________________________________________________
246void
9b98d361 247AliFMDFlowBinned2D::Event(ULong_t n, Double_t* phis,
248 Double_t* xs, Double_t* ys,
249 Double_t* wp, Double_t* wh)
39eefe19 250{
97e94238 251 // Process a full event.
252 // Parameters:
253 // phis List of n phi=[0,2pi] angles
254 // xs List of n x values.
255 // ys List of n y values.
9b98d361 256 // wp Weights for event plane
257 // wh Weights for harmonic
97e94238 258 // n Size of phis and xs
39eefe19 259 Begin();
9b98d361 260 fSplitter->Event(phis, xs, n);
39eefe19 261 for (UInt_t i = 0; i < n; i++)
9b98d361 262 AddToEventPlane(xs[i], ys[i], phis[i], (wp ? wp[i] : 1),
263 fSplitter->Select(i));
39eefe19 264 for (UInt_t i = 0; i < n; i++)
9b98d361 265 AddToHarmonic(xs[i], ys[i], phis[i], (wp ? wh[i] : 1), (wp ? wh[i] : 1));
39eefe19 266 End();
267}
268
269//____________________________________________________________________
270void
271AliFMDFlowBinned2D::Browse(TBrowser* b)
272{
97e94238 273 // Browse this object
39eefe19 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));
279 }
280 }
281}
282
283//____________________________________________________________________
284//
285// EOF
286//