]>
Commit | Line | Data |
---|---|---|
39eefe19 | 1 | /** @file |
2 | @brief Implementation of an Axis in a Flow "histogram" */ | |
3 | #include "flow/AliFMDFlowAxis.h" | |
4 | #include <cmath> | |
824e71c1 | 5 | #include <iostream> |
6 | #include <iomanip> | |
39eefe19 | 7 | |
8 | //==================================================================== | |
9 | AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t* bins) | |
10 | : fN(n), | |
11 | fBins(0) | |
12 | { | |
13 | fBins = new Double_t[fN+1]; | |
14 | for (UInt_t i = 0; i <= fN; i++) fBins[i] = bins[i]; | |
15 | } | |
16 | //____________________________________________________________________ | |
17 | AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t min, Double_t max) | |
18 | : fN(n), | |
19 | fBins(0) | |
20 | { | |
21 | fBins = new Double_t[fN+1]; | |
22 | Double_t dx = (max-min)/fN; | |
23 | for (UInt_t i = 0; i <= fN; i++) fBins[i] = min + i * dx; | |
24 | } | |
25 | //____________________________________________________________________ | |
26 | AliFMDFlowAxis::AliFMDFlowAxis(const AliFMDFlowAxis& other) | |
27 | : fN(other.fN), | |
28 | fBins(0) | |
29 | { | |
30 | fBins = new Double_t[fN+1]; | |
31 | for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i]; | |
32 | } | |
33 | //____________________________________________________________________ | |
34 | AliFMDFlowAxis& | |
35 | AliFMDFlowAxis::operator=(const AliFMDFlowAxis& other) | |
36 | { | |
37 | if (fBins) delete [] fBins; | |
38 | fN = other.fN; | |
39 | fBins = new Double_t[fN+1]; | |
40 | for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i]; | |
41 | return *this; | |
42 | } | |
43 | //____________________________________________________________________ | |
44 | AliFMDFlowAxis::~AliFMDFlowAxis() | |
45 | { | |
46 | if (fBins) delete [] fBins; | |
47 | fBins = 0; | |
48 | } | |
49 | //____________________________________________________________________ | |
50 | Int_t | |
51 | AliFMDFlowAxis::FindBin(Double_t x) const | |
52 | { | |
53 | if (x < fBins[0]) return -1; | |
54 | if (x > fBins[fN]) return -1; | |
55 | UInt_t above, below, middle; | |
56 | above = fN+2; | |
57 | below = 0; | |
58 | while((above - below) > 1) { | |
59 | middle = (above + below) / 2; | |
60 | if (x == fBins[middle-1]) return middle-1; | |
61 | if (x < fBins[middle-1]) above = middle; | |
62 | else below = middle; | |
63 | } | |
64 | return below-1; | |
65 | } | |
66 | //____________________________________________________________________ | |
67 | Double_t | |
68 | AliFMDFlowAxis::BinWidth(UShort_t i) const | |
69 | { | |
70 | if (i >= fN) return 0; | |
71 | return (fBins[i+1] - fBins[i]); | |
72 | } | |
73 | //____________________________________________________________________ | |
74 | Double_t | |
75 | AliFMDFlowAxis::BinCenter(UShort_t i) const | |
76 | { | |
77 | if (i >= fN) return 0; | |
78 | return fBins[i] + BinWidth(i) / 2; | |
79 | } | |
80 | //____________________________________________________________________ | |
81 | Double_t | |
82 | AliFMDFlowAxis::BinLower(UShort_t i) const | |
83 | { | |
84 | if (i >= fN) return 0; | |
85 | return fBins[i]; | |
86 | } | |
87 | //____________________________________________________________________ | |
88 | Double_t | |
89 | AliFMDFlowAxis::BinUpper(UShort_t i) const | |
90 | { | |
91 | if (i >= fN) return 0; | |
92 | return fBins[i+1]; | |
93 | } | |
94 | ||
824e71c1 | 95 | //____________________________________________________________________ |
96 | void | |
97 | AliFMDFlowAxis::Print(Option_t*) const | |
98 | { | |
99 | std::ios_base::fmtflags old_flags = std::cout.setf(std::ios_base::fixed, | |
100 | std::ios_base::floatfield); | |
101 | for (UShort_t i = 0; i < fN; i++) | |
102 | std::cout << std::setw(5) << BinLower(i) << " - " | |
103 | << std::setw(5) << BinUpper(i) << std::endl; | |
104 | std::cout.setf(old_flags, std::ios_base::floatfield); | |
105 | } | |
106 | ||
107 | ||
39eefe19 | 108 | //____________________________________________________________________ |
109 | // | |
110 | // EOF | |
111 | // |