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 an Axis in a Flow "histogram" */
20 #include "flow/AliFMDFlowAxis.h"
24 // Axis object for the
25 // AliFMDFlowBinned1D and
27 // "histograms" of objects
28 // of class AliFMDFlowBin.
30 //====================================================================
31 AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t* bins)
38 // bins Bin boundaries (n+1 elements)
39 fBins = new Double_t[fN+1];
40 for (UInt_t i = 0; i <= fN; i++) fBins[i] = bins[i];
42 //____________________________________________________________________
43 AliFMDFlowAxis::AliFMDFlowAxis(UShort_t n, Double_t min, Double_t max)
51 fBins = new Double_t[fN+1];
52 Double_t dx = (max-min)/fN;
53 for (UInt_t i = 0; i <= fN; i++) fBins[i] = min + i * dx;
55 //____________________________________________________________________
56 AliFMDFlowAxis::AliFMDFlowAxis(const AliFMDFlowAxis& other)
63 // other Object to copy from.
64 fBins = new Double_t[fN+1];
65 for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i];
67 //____________________________________________________________________
69 AliFMDFlowAxis::operator=(const AliFMDFlowAxis& other)
71 // Assignment operator
73 // other Object to assign from.
74 if (fBins) delete [] fBins;
76 fBins = new Double_t[fN+1];
77 for (UInt_t i = 0; i <= fN; i++) fBins[i] = other.fBins[i];
80 //____________________________________________________________________
81 AliFMDFlowAxis::~AliFMDFlowAxis()
86 if (fBins) delete [] fBins;
89 //____________________________________________________________________
91 AliFMDFlowAxis::FindBin(Double_t x) const
93 // Find a bin corresponding to x
95 // x Value to find bin number for
96 if (x < fBins[0]) return -1;
97 if (x > fBins[fN]) return -1;
98 UInt_t above, below, middle;
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;
109 //____________________________________________________________________
111 AliFMDFlowAxis::BinWidth(UShort_t i) const
115 // i bin number to get width of
116 if (i >= fN) return 0;
117 return (fBins[i+1] - fBins[i]);
119 //____________________________________________________________________
121 AliFMDFlowAxis::BinCenter(UShort_t i) const
125 // i bin number to get center of
126 if (i >= fN) return 0;
127 return fBins[i] + BinWidth(i) / 2;
129 //____________________________________________________________________
131 AliFMDFlowAxis::BinLower(UShort_t i) const
135 // i bin number to get center of
136 if (i >= fN) return 0;
139 //____________________________________________________________________
141 AliFMDFlowAxis::BinUpper(UShort_t i) const
145 // i bin number to get center of
146 if (i >= fN) return 0;
150 //____________________________________________________________________
152 AliFMDFlowAxis::Print(Option_t*) const
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; 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);
166 //____________________________________________________________________