]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/flow/AliFMDFlowBinned2D.cxx
Fix coding convention violations
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowBinned2D.cxx
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  */
18 /** @file 
19     @brief Implementation of a 2-dimensional Flow "histogram" */
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 
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 //====================================================================
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),
41     fBins(0)
42 {
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 
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 //____________________________________________________________________
55 AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order, 
56                                        const AliFMDFlowAxis&    xaxis, 
57                                        const AliFMDFlowAxis&    yaxis)
58   : fXAxis(xaxis), 
59     fYAxis(yaxis)
60 {
61   // Constructor 
62   // Parameters: 
63   //   Order    Order 
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);
69 }
70 //____________________________________________________________________
71 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
72   : TObject(o), 
73     fXAxis(o.fXAxis), 
74     fYAxis(o.fYAxis)
75 {
76   // Copy constructor 
77   // Parameters: 
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]));
82 }
83 //____________________________________________________________________
84 AliFMDFlowBinned2D&
85 AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
86 {
87   // Assignment operator
88   // Parameters: 
89   //   o Object to assign from 
90   // 
91   // Returns reference to this object 
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 //____________________________________________________________________
105 AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
106 {
107   // Destructor 
108   // Parameters: 
109   //    none 
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 //____________________________________________________________________
117 AliFMDFlowBin* 
118 AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
119 {
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. 
126   if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
127   return fBins[i * fYAxis.N() + j];
128 }
129 //____________________________________________________________________
130 AliFMDFlowBin* 
131 AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
132 {
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. 
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 //____________________________________________________________________
148 void 
149 AliFMDFlowBinned2D::Begin()
150 {
151   // Called at the beginning of an event
152   // Parameters: 
153   //   none
154   UInt_t n = fXAxis.N() * fYAxis.N();
155   for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
156 }
157 //____________________________________________________________________
158 void 
159 AliFMDFlowBinned2D::End()
160 {
161   // Called at the end of an event
162   // Parameters: 
163   //   none
164   UInt_t n = fXAxis.N() * fYAxis.N();
165   for (UInt_t i = 0; i < n; i++) fBins[i]->End();
166 }
167 //____________________________________________________________________
168 void 
169 AliFMDFlowBinned2D::Finish()
170 {
171   // Called at the end of an job
172   // Parameters: 
173   //   none
174   UInt_t n = fXAxis.N() * fYAxis.N();
175   for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
176 }
177 //____________________________________________________________________
178 Bool_t 
179 AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi, 
180                                 Double_t w, Bool_t a)
181 {
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
191   AliFMDFlowBin* bin = GetBin(x, y);
192   if (!bin) return kFALSE;
193   bin->AddToEventPlane(phi, w, a);
194   return kTRUE;
195 }
196
197 //____________________________________________________________________
198 Bool_t 
199 AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi)
200 {
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
208   AliFMDFlowBin* bin = GetBin(x, y);
209   if (!bin) return kFALSE;
210   bin->AddToHarmonic(phi);
211   return kTRUE;
212 }
213
214 //____________________________________________________________________
215 void 
216 AliFMDFlowBinned2D::Event(Double_t* phis, Double_t* xs, Double_t* ys, 
217                           Double_t* ws, ULong_t n)
218 {
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
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 //____________________________________________________________________
236 void 
237 AliFMDFlowBinned2D::Browse(TBrowser* b)
238 {
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));
245     }
246   }
247 }
248
249 //____________________________________________________________________
250 //
251 // EOF
252 //