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 1-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/AliFMDFlowBinned1D.h"
29 #include "flow/AliFMDFlowBin.h"
39 //====================================================================
40 AliFMDFlowBinned1D::AliFMDFlowBinned1D(UShort_t order,
43 : fXAxis(nxbins, xbins),
49 // nxbins Number of bins
51 UShort_t n = fXAxis.N();
52 fBins = new AliFMDFlowBin*[n];
53 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
55 //____________________________________________________________________
56 AliFMDFlowBinned1D::AliFMDFlowBinned1D(UShort_t order,
57 const AliFMDFlowAxis& xaxis)
63 // xaxis X axis object
64 UShort_t n = fXAxis.N();
65 fBins = new AliFMDFlowBin*[n];
66 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
68 //____________________________________________________________________
69 AliFMDFlowBinned1D::AliFMDFlowBinned1D(const AliFMDFlowBinned1D& o)
75 // o Object to copy from
76 UShort_t n = fXAxis.N();
77 fBins = new AliFMDFlowBin*[n];
78 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
80 //____________________________________________________________________
82 AliFMDFlowBinned1D::operator=(const AliFMDFlowBinned1D& o)
84 // Assignment operator
86 // o Object to assign from
88 // Returns reference to this object
90 for (UInt_t i = 0; i < fXAxis.N(); i++) delete fBins[i];
94 UShort_t n = fXAxis.N();
95 fBins = new AliFMDFlowBin*[n];
96 for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
100 //____________________________________________________________________
101 AliFMDFlowBinned1D::~AliFMDFlowBinned1D()
107 for (UInt_t i = 0; i < fXAxis.N(); i++) delete fBins[i];
112 //____________________________________________________________________
114 AliFMDFlowBinned1D::GetBin(UShort_t i) const
120 // Return pointer to bin, or null.
121 if (i >= fXAxis.N()) return 0;
124 //____________________________________________________________________
126 AliFMDFlowBinned1D::GetBin(Double_t x) const
128 // Get the bin that contains x
132 // Return pointer to bin, or null.
133 Int_t i = fXAxis.FindBin(x);
139 //____________________________________________________________________
141 AliFMDFlowBinned1D::Begin()
143 // Called at the beginning of an event
146 for (UInt_t i = 0; i < fXAxis.N(); i++) fBins[i]->Begin();
148 //____________________________________________________________________
150 AliFMDFlowBinned1D::End()
152 // Called at the end of an event
155 for (UInt_t i = 0; i < fXAxis.N(); i++) fBins[i]->End();
157 //____________________________________________________________________
159 AliFMDFlowBinned1D::Finish()
161 // Called at the end of an job
164 for (UInt_t i = 0; i < fXAxis.N(); i++) fBins[i]->Finish();
166 //____________________________________________________________________
168 AliFMDFlowBinned1D::AddToEventPlane(Double_t x, Double_t phi,
169 Double_t w, Bool_t a)
171 // Called to add a contribution to the event plane
173 // x Bin to fill into
175 // phi The angle phi in radians
176 // a If true, add to sub-event A, otherwise sub-event B
178 // Return false if x falls outside the defined range, true otherwise
179 AliFMDFlowBin* bin = GetBin(x);
180 if (!bin) return kFALSE;
181 bin->AddToEventPlane(phi, w, a);
185 //____________________________________________________________________
187 AliFMDFlowBinned1D::AddToHarmonic(Double_t x, Double_t phi)
189 // Called to add a contribution to the harmonic
191 // x Bin to fill into
192 // phi The angle phi in radians
194 // Return false if x falls outside the defined range, true otherwise
195 AliFMDFlowBin* bin = GetBin(x);
196 if (!bin) return kFALSE;
197 bin->AddToHarmonic(phi);
201 //____________________________________________________________________
203 AliFMDFlowBinned1D::Event(Double_t* phis, Double_t* xs, Double_t* ws, ULong_t n)
205 // Process a full event.
207 // phis List of n phi=[0,2pi] angles
208 // xs List of n x values.
210 // n Size of phis and xs
212 for (UInt_t i = 0; i < n; i++)
213 AddToEventPlane(xs[i], phis[i], (ws ? ws[i] : 1),
214 Float_t(rand()) / RAND_MAX > 0.5);
215 for (UInt_t i = 0; i < n; i++)
216 AddToHarmonic(xs[i], phis[i]);
220 //____________________________________________________________________
222 AliFMDFlowBinned1D::Browse(TBrowser* b)
224 // Browse this object.
225 b->Add(&fXAxis, "xaxis");
226 for (UInt_t i = 0; i < fXAxis.N(); i++)
227 b->Add(fBins[i], Form("bin_%03d", i));
230 //____________________________________________________________________
232 AliFMDFlowBinned1D::Draw(Option_t* option)
234 // Draw the distribution of the harmonics or the event plane
237 // option String of options
240 // b Draw bare averages of cos(n(phi-Psi))
241 // n Draw harmonic scaled by naive correction
242 // s Draw harmonic scaled by STAR correction
243 // t Draw harmonic scaled by TDR correction
244 // r Draw resolution rather than harmonic
246 // If more than one of b, n, s, or t is given, a 2D histogram is
250 const char* names[] = { "Bare", "Naive", "STAR", "TDR" };
251 const AliFMDFlowBin::CorType types[] = { AliFMDFlowBin::kNone,
252 AliFMDFlowBin::kNaive,
253 AliFMDFlowBin::kStar,
254 AliFMDFlowBin::kTdr };
255 Bool_t meths[] = { opt.Contains("b"),
259 Bool_t res = opt.Contains("r");
262 for (UShort_t i = 0; i < 4; i++) { if (meths[i]) { nm++; sm = i; } }
265 h = new TH2D((res ? "res" : "flow"), (res ? "Resolution" : "Flow"),
266 fXAxis.N(), fXAxis.Bins(), nm, 0, nm);
268 h->SetYTitle("method");
269 h->GetYaxis()->SetNdivisions(nm+1, kFALSE);
270 h->SetZTitle((res ? "<cos(n(#Psi_{m}-#Psi_{R}))>" : "v"));
272 for (UShort_t i = 0; i < 4; i++)
273 if (meths[i]) h->GetYaxis()->SetBinLabel(++j, names[i]);
276 h = new TH1D(Form("%s_%s", (res ? "res" : "flow"), names[sm]),
277 Form("%s_%s", (res ? "Resolution" : "Flow"), names[sm]),
278 fXAxis.N(), fXAxis.Bins());
280 h->SetYTitle((res ? "<cos(n(#Psi_{m}-#Psi_{R}))>" : "v"));
283 for (UShort_t i = 0; i < fXAxis.N(); i++) {
284 Double_t x = fXAxis.BinCenter(i);
285 AliFMDFlowBin* bin = GetBin(x);
288 if (res) v = bin->Correction(e2, types[sm]);
289 else v = bin->Value(e2, types[sm]);
290 h->SetBinContent(i+1, v);
291 h->SetBinError(i+1, sqrt(e2));
295 for (UShort_t k = 0; k < 4; k++) {
296 if (!meths[k]) continue;
297 if (res) v = bin->Correction(e2, types[k]);
298 else v = bin->Value(e2, types[k]);
299 h->SetBinContent(i+1, j+1, v);
300 h->SetBinError(i+1, j+1, sqrt(e2));
309 //____________________________________________________________________
311 AliFMDFlowBinned1D::Print(Option_t* option) const
313 // Print information to standard output.
315 // option String of options
323 Bool_t det = opt.Contains("d");
324 Bool_t sum = opt.Contains("s");
326 for (UShort_t i = 0; i < fXAxis.N(); i++) {
327 Double_t x = fXAxis.BinCenter(i);
328 std::streamsize oldP = std::cout.precision(3);
329 std::ios_base::fmtflags oldF = std::cout.setf(std::ios_base::fixed,
330 std::ios_base::floatfield);
331 std::cout << "x=" << std::setw(5) << x << std::endl;
333 std::cout.precision(oldP);
334 std::cout.setf(oldF, std::ios_base::floatfield);
340 const char* names[] = { "Bare", "Naive", "STAR", "TDR" };
341 AliFMDFlowBin::CorType types[] = { AliFMDFlowBin::kNone,
342 AliFMDFlowBin::kNaive,
343 AliFMDFlowBin::kStar,
344 AliFMDFlowBin::kTdr };
346 for (UInt_t i = 0; i < nType; i++)
347 std::cout << " | " << std::setw(6+6+5) << names[i];
348 std::cout << "\n-----" << std::setfill('-');
349 for (UInt_t i = 0; i < nType; i++)
350 std::cout << "-+-" << std::setw(6+6+5) << "-";
351 std::cout << std::setfill(' ') << std::endl;
353 std::streamsize oldP = std::cout.precision(2);
354 std::ios_base::fmtflags oldF = std::cout.setf(std::ios_base::fixed,
355 std::ios_base::floatfield);
356 for (UShort_t i = 0; i < fXAxis.N(); i++) {
357 Double_t x = fXAxis.BinCenter(i);
358 std::cout << std::setprecision(2) << std::setw(5) << x << std::flush;
359 for (UShort_t j = 0; j < nType; j++) {
361 Double_t v = fBins[i]->Value(e2v, types[j]);
362 std::cout << std::setprecision(3) << " | "
363 << std::setw(6) << 100 * v << " +/- "
364 << std::setw(6) << 100 * sqrt(e2v);
366 std::cout << std::endl;
368 std::cout.precision(oldP);
369 std::cout.setf(oldF, std::ios_base::floatfield);
374 //____________________________________________________________________