]>
Commit | Line | Data |
---|---|---|
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 an Axis in a Flow "histogram" */ | |
20 | #include "flow/AliFMDFlowAxis.h" | |
21 | #include <cmath> | |
22 | #include <iostream> | |
23 | #include <iomanip> | |
24 | // Axis object for the | |
25 | // AliFMDFlowBinned1D and | |
26 | // AliFMDFlowBinned2D | |
27 | // "histograms" of objects | |
28 | // of class AliFMDFlowBin. | |
29 | // | |
30 | //==================================================================== | |
31 | AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t* bins) | |
32 | : fN(n+1), | |
33 | fBins(0) | |
34 | { | |
35 | // Constructor. | |
36 | // Parameters | |
37 | // n Number of bins | |
38 | // bins Bin boundaries (n+1 elements) | |
39 | fBins = new Double_t[fN]; | |
40 | for (Int_t i = 0; i < fN; i++) fBins[i] = bins[i]; | |
41 | } | |
42 | //____________________________________________________________________ | |
43 | AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t min, Double_t max) | |
44 | : fN(n+1), | |
45 | fBins(0) | |
46 | { | |
47 | // Constructor | |
48 | // n Number of bins. | |
49 | // min Axis minimum | |
50 | // max Axis maximum | |
51 | fBins = new Double_t[fN]; | |
52 | Double_t dx = (max-min)/fN; | |
53 | for (Int_t i = 0; i < fN; i++) fBins[i] = min + i * dx; | |
54 | } | |
55 | //____________________________________________________________________ | |
56 | AliFMDFlowAxis::AliFMDFlowAxis(const AliFMDFlowAxis& other) | |
57 | : TObject(other), | |
58 | fN(other.fN), | |
59 | fBins(0) | |
60 | { | |
61 | // Copy constructor | |
62 | // Parameters | |
63 | // other Object to copy from. | |
64 | fBins = new Double_t[fN]; | |
65 | for (Int_t i = 0; i < fN; i++) fBins[i] = other.fBins[i]; | |
66 | } | |
67 | //____________________________________________________________________ | |
68 | AliFMDFlowAxis& | |
69 | AliFMDFlowAxis::operator=(const AliFMDFlowAxis& other) | |
70 | { | |
71 | // Assignment operator | |
72 | // Parameters | |
73 | // other Object to assign from. | |
74 | if (fBins) delete [] fBins; | |
75 | fN = other.fN; | |
76 | fBins = new Double_t[fN]; | |
77 | for (Int_t i = 0; i < fN; i++) fBins[i] = other.fBins[i]; | |
78 | return *this; | |
79 | } | |
80 | //____________________________________________________________________ | |
81 | AliFMDFlowAxis::~AliFMDFlowAxis() | |
82 | { | |
83 | // destructor | |
84 | // Parameters | |
85 | // none | |
86 | if (fBins) delete [] fBins; | |
87 | fBins = 0; | |
88 | } | |
89 | //____________________________________________________________________ | |
90 | Int_t | |
91 | AliFMDFlowAxis::FindBin(Double_t x) const | |
92 | { | |
93 | // Find a bin corresponding to x | |
94 | // Param | |
95 | // x Value to find bin number for | |
96 | if (x < fBins[0]) return -1; | |
97 | if (x > fBins[fN-1]) return -1; | |
98 | UInt_t above, below, middle; | |
99 | above = fN+1; | |
100 | below = 0; | |
101 | while((above - below) > 1) { | |
102 | middle = (above + below) / 2; | |
103 | if (x == fBins[middle-1]) return middle-1; | |
104 | if (x < fBins[middle-1]) above = middle; | |
105 | else below = middle; | |
106 | } | |
107 | return below-1; | |
108 | } | |
109 | //____________________________________________________________________ | |
110 | Double_t | |
111 | AliFMDFlowAxis::BinWidth(UShort_t i) const | |
112 | { | |
113 | // Width of bin i | |
114 | // Parameter | |
115 | // i bin number to get width of | |
116 | if (i >= fN-1) return 0; | |
117 | return (fBins[i+1] - fBins[i]); | |
118 | } | |
119 | //____________________________________________________________________ | |
120 | Double_t | |
121 | AliFMDFlowAxis::BinCenter(UShort_t i) const | |
122 | { | |
123 | // Center of bin i | |
124 | // Parameter | |
125 | // i bin number to get center of | |
126 | if (i >= fN-1) return 0; | |
127 | return fBins[i] + BinWidth(i) / 2; | |
128 | } | |
129 | //____________________________________________________________________ | |
130 | Double_t | |
131 | AliFMDFlowAxis::BinLower(UShort_t i) const | |
132 | { | |
133 | // Center of bin i | |
134 | // Parameter | |
135 | // i bin number to get center of | |
136 | if (i >= fN-1) return 0; | |
137 | return fBins[i]; | |
138 | } | |
139 | //____________________________________________________________________ | |
140 | Double_t | |
141 | AliFMDFlowAxis::BinUpper(UShort_t i) const | |
142 | { | |
143 | // Center of bin i | |
144 | // Parameter | |
145 | // i bin number to get center of | |
146 | if (i >= fN-1) return 0; | |
147 | return fBins[i+1]; | |
148 | } | |
149 | ||
150 | //____________________________________________________________________ | |
151 | void | |
152 | AliFMDFlowAxis::Print(Option_t*) const | |
153 | { | |
154 | // Print out | |
155 | // Parameter | |
156 | // none | |
157 | std::ios_base::fmtflags oldF = std::cout.setf(std::ios_base::fixed, | |
158 | std::ios_base::floatfield); | |
159 | for (UShort_t i = 0; i < fN-1; i++) | |
160 | std::cout << std::setw(5) << BinLower(i) << " - " | |
161 | << std::setw(5) << BinUpper(i) << std::endl; | |
162 | std::cout.setf(oldF, std::ios_base::floatfield); | |
163 | } | |
164 | ||
165 | ||
166 | //____________________________________________________________________ | |
167 | // | |
168 | // EOF | |
169 | // |