]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/flow/AliFMDFlowBinned2D.cxx
Added code to do flow analysis.
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowBinned2D.cxx
1 /** @file 
2     @brief Implementation of a 2-dimensional Flow "histogram" */
3 #include "flow/AliFMDFlowBinned2D.h"
4 #include "flow/AliFMDFlowBin.h"
5 #include <cmath>
6 #include <cstdlib>
7 #include <TString.h>
8 #include <TBrowser.h>
9
10 //====================================================================
11 AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order, 
12                          UShort_t nxbins, Double_t* xbins,
13                          UShort_t nybins, Double_t* ybins) 
14   : fXAxis(nxbins, xbins),
15     fYAxis(nybins, ybins),
16     fBins(0)
17 {
18   UInt_t n = fXAxis.N() * fYAxis.N();
19   fBins   = new AliFMDFlowBin*[n];
20   for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
21 }
22 //____________________________________________________________________
23 AliFMDFlowBinned2D::AliFMDFlowBinned2D(UShort_t order, 
24                          const AliFMDFlowAxis&    xaxis, 
25                          const AliFMDFlowAxis&    yaxis)
26   : fXAxis(xaxis), 
27     fYAxis(yaxis)
28 {
29   UShort_t n = fXAxis.N() * fYAxis.N();
30   fBins   = new AliFMDFlowBin*[n];
31   for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(order);
32 }
33 //____________________________________________________________________
34 AliFMDFlowBinned2D::AliFMDFlowBinned2D(const AliFMDFlowBinned2D& o)
35   : TObject(o), 
36     fXAxis(o.fXAxis), 
37     fYAxis(o.fYAxis)
38 {
39   UShort_t n = fXAxis.N() * fYAxis.N();
40   fBins   = new AliFMDFlowBin*[n];
41   for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
42 }
43 //____________________________________________________________________
44 AliFMDFlowBinned2D&
45 AliFMDFlowBinned2D::operator=(const AliFMDFlowBinned2D& o)
46 {
47   if (fBins) { 
48     UInt_t n = fXAxis.N() * fYAxis.N();
49     for (UInt_t i = 0; i < n; i++) delete fBins[i];
50     delete [] fBins;
51   }
52   fXAxis     = o.fXAxis;
53   UShort_t n = fXAxis.N() * fYAxis.N();
54   fBins   = new AliFMDFlowBin*[n];
55   for (UInt_t i = 0; i < n; i++) fBins[i]= new AliFMDFlowBin(*(o.fBins[i]));
56   return *this;
57 }
58
59 //____________________________________________________________________
60 AliFMDFlowBinned2D::~AliFMDFlowBinned2D()
61 {
62   if (fBins) { 
63     UInt_t n = fXAxis.N() * fYAxis.N();
64     for (UInt_t i = 0; i < n; i++) delete fBins[i];
65     delete [] fBins;
66   }
67 }
68 //____________________________________________________________________
69 AliFMDFlowBin* 
70 AliFMDFlowBinned2D::GetBin(UShort_t i, UShort_t j) const
71 {
72   if (i >= fXAxis.N() || j >= fYAxis.N()) return 0;
73   return fBins[i * fYAxis.N() + j];
74 }
75 //____________________________________________________________________
76 AliFMDFlowBin* 
77 AliFMDFlowBinned2D::GetBin(Double_t x, Double_t y) const
78 {
79   Int_t i = fXAxis.FindBin(x);
80   if (i < 0) return 0;
81   Int_t j = fYAxis.FindBin(y);
82   if (j < 0) return 0;
83   UShort_t k = i;
84   UShort_t l = j;
85   return GetBin(k, l);
86 }
87 //____________________________________________________________________
88 void 
89 AliFMDFlowBinned2D::Begin()
90 {
91   UInt_t n = fXAxis.N() * fYAxis.N();
92   for (UInt_t i = 0; i < n; i++) fBins[i]->Begin();
93 }
94 //____________________________________________________________________
95 void 
96 AliFMDFlowBinned2D::End()
97 {
98   UInt_t n = fXAxis.N() * fYAxis.N();
99   for (UInt_t i = 0; i < n; i++) fBins[i]->End();
100 }
101 //____________________________________________________________________
102 void 
103 AliFMDFlowBinned2D::Finish()
104 {
105   UInt_t n = fXAxis.N() * fYAxis.N();
106   for (UInt_t i = 0; i < n; i++) fBins[i]->Finish();
107 }
108 //____________________________________________________________________
109 Bool_t 
110 AliFMDFlowBinned2D::AddToEventPlane(Double_t x, Double_t y, Double_t phi, 
111                                 Double_t w, Bool_t a)
112 {
113   AliFMDFlowBin* bin = GetBin(x, y);
114   if (!bin) return kFALSE;
115   bin->AddToEventPlane(phi, w, a);
116   return kTRUE;
117 }
118
119 //____________________________________________________________________
120 Bool_t 
121 AliFMDFlowBinned2D::AddToHarmonic(Double_t x, Double_t y, Double_t phi)
122 {
123   AliFMDFlowBin* bin = GetBin(x, y);
124   if (!bin) return kFALSE;
125   bin->AddToHarmonic(phi);
126   return kTRUE;
127 }
128
129 //____________________________________________________________________
130 void 
131 AliFMDFlowBinned2D::Event(Double_t* phis, Double_t* xs, Double_t* ys, 
132                           Double_t* ws, ULong_t n)
133 {
134   Begin();
135   for (UInt_t i = 0; i < n; i++) 
136     AddToEventPlane(xs[i], ys[i], phis[i], (ws ? ws[i] : 1), 
137                     Float_t(rand()) / RAND_MAX > 0.5);
138   for (UInt_t i = 0; i < n; i++) 
139     AddToHarmonic(xs[i], ys[i], phis[i]);
140   End();
141 }
142
143 //____________________________________________________________________
144 void 
145 AliFMDFlowBinned2D::Browse(TBrowser* b)
146 {
147   b->Add(&fXAxis, "xaxis");
148   b->Add(&fYAxis, "yaxis");
149   for (UInt_t i = 0; i < fXAxis.N(); i++) { 
150     for (UInt_t j = 0; i < fYAxis.N(); j++) { 
151       b->Add(fBins[i*fXAxis.N()+j], Form("bin_%03d_%03d", i, j));
152     }
153   }
154 }
155
156 //____________________________________________________________________
157 //
158 // EOF
159 //