]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/flow/AliFMDFlowAxis.cxx
Added code to do flow analysis.
[u/mrichter/AliRoot.git] / FMD / flow / AliFMDFlowAxis.cxx
1 /** @file 
2     @brief Implementation of an Axis in a Flow "histogram" */
3 #include "flow/AliFMDFlowAxis.h"
4 #include <cmath>
5
6 //====================================================================
7 AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t* bins) 
8   : fN(n), 
9     fBins(0)
10 {
11   fBins = new Double_t[fN+1];
12   for (UInt_t i = 0; i <= fN; i++) fBins[i] = bins[i];
13 }
14 //____________________________________________________________________
15 AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t min, Double_t max)
16   : fN(n), 
17     fBins(0)
18 {
19   fBins     = new Double_t[fN+1];
20   Double_t dx = (max-min)/fN;
21   for (UInt_t i = 0; i <= fN; i++) fBins[i] = min + i * dx;
22 }
23 //____________________________________________________________________
24 AliFMDFlowAxis::AliFMDFlowAxis(const AliFMDFlowAxis& other)
25   : fN(other.fN), 
26     fBins(0)
27 {
28   fBins = new Double_t[fN+1];
29   for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i];
30 }
31 //____________________________________________________________________
32 AliFMDFlowAxis& 
33 AliFMDFlowAxis::operator=(const AliFMDFlowAxis& other)
34 {
35   if (fBins) delete [] fBins;
36   fN    = other.fN;
37   fBins = new Double_t[fN+1];
38   for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i];
39   return *this;
40 }
41 //____________________________________________________________________
42 AliFMDFlowAxis::~AliFMDFlowAxis()
43 {
44   if (fBins) delete [] fBins;
45   fBins = 0;
46 }
47 //____________________________________________________________________
48 Int_t 
49 AliFMDFlowAxis::FindBin(Double_t x) const 
50 {
51   if (x < fBins[0])  return -1;
52   if (x > fBins[fN]) return -1;
53   UInt_t above, below, middle;
54   above = fN+2;
55   below = 0;
56   while((above - below) > 1) {
57     middle = (above + below) / 2;
58     if (x == fBins[middle-1]) return middle-1;
59     if (x  < fBins[middle-1]) above = middle;
60     else                      below = middle;
61   }
62   return below-1;
63 }
64 //____________________________________________________________________
65 Double_t 
66 AliFMDFlowAxis::BinWidth(UShort_t i) const
67 {
68   if (i >= fN) return 0;
69   return (fBins[i+1] - fBins[i]);
70 }
71 //____________________________________________________________________
72 Double_t 
73 AliFMDFlowAxis::BinCenter(UShort_t i) const
74 {
75   if (i >= fN) return 0;
76   return fBins[i] + BinWidth(i) / 2;
77 }
78 //____________________________________________________________________
79 Double_t 
80 AliFMDFlowAxis::BinLower(UShort_t i) const
81 {
82   if (i >= fN) return 0;
83   return fBins[i];
84 }
85 //____________________________________________________________________
86 Double_t 
87 AliFMDFlowAxis::BinUpper(UShort_t i) const
88 {
89   if (i >= fN) return 0;
90   return fBins[i+1];
91 }
92
93 //____________________________________________________________________
94 //
95 // EOF
96 //