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