BinnerAxisLinear.cxx
Go to the documentation of this file.
1 
11 // for math defect
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include "BinnerAxisLinear.h"
17 
18 #include <algorithm>
19 
20 #include <cmath> // for ciel()
21 
22 #include <cassert>
23 
24 
25 using namespace hippodraw;
26 
28  : BinnerAxis ( "BinnerLinear" )
29 {
31 }
32 
35  : BinnerAxis ( binner )
36 {
37 }
38 
40 {
41 }
42 
43 BinnerAxis *
45 {
46  return new BinnerAxisLinear( *this );
47 }
48 
49 bool
51 {
52  return true;
53 }
54 
55 void
57 {
58  m_num_bins = nb;
60 }
61 
66 int
68 {
69  double lo = m_range.low ();
70  double width = axisBinWidth ( 1 );
71  double f = 1.0 + ( x - lo ) / width;
72  int i = static_cast < int > ( f );
73  i = std::max ( i, 0 );
74  i = std::min ( i, m_num_bins + 1 );
75 
76  return i;
77 }
78 
79 double
81 getCoordinate ( int i ) const
82 {
83  return m_range.low() + i * ( m_range.length () / m_num_bins );
84 }
85 
86 double
88 {
89  double width = m_range.length() / m_num_bins;
90 
91  return width;
92 }
93 
94 const Range &
96 setBinWidth ( double width )
97 {
98  assert ( width > 0.0 );
99 
100  m_width = width;
101 
102  m_num_bins = getNob ( width );
103  m_range.setLength ( m_num_bins * width );
104  return m_range;
105 }
106 
107 double
109 calcWidthParm ( int number ) const
110 {
111  double new_width = ( m_range.high() - m_range.low () ) /
112  ( static_cast < double > ( number ) );
113 
114  return new_width;
115 }
116 
117 double
118 BinnerAxisLinear::calcOffset ( int parm, bool dragging ) const
119 {
120  setStartRange ( dragging );
121 
122  return ( parm - 50 ) / 50.0;
123 }
124 
125 double
127 {
128  return m_offset;
129 }
130 
131 const void
133 {
134  double oldoff = m_offset;
135  m_offset = offset;
136  double change = offset - oldoff;
137 
138  if( offset == 0.0 ) return; // resetting...
139  Range r( m_range.low() + change * m_width,
140  m_range.high() + change * m_width );
141 
142  m_range = r;
143 }
144 
151 const Range &
153 setRange ( const Range & range, bool hold_width )
154 {
155  m_range = range;
156 
157  if ( hold_width && m_width < m_range.length() ) {
158 #ifdef MATH_DEFECT
159  double number = std::ceil ( m_range.length() / m_width );
160 #else
161  double number = ceil ( m_range.length() / m_width );
162 #endif
163  m_num_bins = static_cast< int > ( number );
164  m_range.setLength ( m_num_bins * m_width );
165  }
166  else { // calc new width.
168  }
169  return m_range;
170 }
171 
172 double
174 {
175  return axisBinWidth( 1 );
176  //This should really return the const width variable... but this
177  //raises issues with when the variable needs to be recalculated.
178  //return m_const_wid;
179 }
180 
181 double
183 getBinWidth ( ) const
184 {
185  return getConstWid ();
186 }
187 
188 void
190 {
191  m_width = axisBinWidth( 1 );
192 }
193 
194 double
196 {
197  return getConstWid();
198 }
199 
200 int BinnerAxisLinear::getNob ( const Range & range ) const
201 {
202  double width = getConstWid ();
203 #ifdef MATH_DEFECT
204  int tmp
205  = static_cast < int > ( std::floor ( range.length () / width + 0.5 ) );
206 #else
207  int tmp
208  = static_cast < int > ( floor ( range.length() / width + 0.5 ) );
209 #endif
210 
211  return tmp ? tmp : 1;
212 }
213 
214 int BinnerAxisLinear::getNob ( double wid ) const
215 {
216  int tmp = m_range.numberOfBins( wid );
217 
218  return tmp ? tmp : 1;
219 }
unsigned int i
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
BinnerAxisLinear()
The default constructor.
virtual bool hasEqualWidths() const
Returns true.
virtual double calcOffset(int parm, bool dragging) const
Calculates and returns a double corresponding to a bin offset when dragging a slider control...
virtual void setConstWid()
Sets the constant width parameter.
void setStartRange(bool dragging) const
Sets the starting Range.
Definition: BinnerAxis.cxx:90
Range m_range
The range of the bins.
Definition: BinnerAxis.h:68
virtual double getCoordinate(int i) const
Returns the coordinate.
virtual int getNob(double wid) const
Returns the number of bins given the width parameter width.
virtual int axisBinNumber(double x) const
Returns the number of the bin in which the x value is situated.
virtual double getBinWidth() const
Returns the bin width parameter.
void setLength(double val, bool high_hold=false)
Sets the length of the range.
Definition: Range.cxx:135
virtual const Range & setBinWidth(double width)
Sets the bin width and adjusts the range and number of bins accordingly.
double m_width
The width parameter for the binning.
Definition: BinnerAxis.h:75
virtual double calcWidthParm(int number) const
Calculates the bin width parameter given the number of bins.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
virtual void axisSetNumberOfBins(int nb)
Sets m_num_bins.
double length() const
Returns the length of the range object.
Definition: Range.h:156
virtual double getOffset() const
Returns the offset.
virtual const void setOffset(double offset)
Sets the offset and adjusts the range accordingly.
virtual double axisBinWidth(int i) const
Returns the width of each bin.
virtual double getConstWid() const
Returns the constant width parameter.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
double m_offset
The offset.
Definition: BinnerAxis.h:71
hippodraw::BinnerAxisLinear class interface
BinnerAxis * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
Expresses a range of values.
Definition: Range.h:33
virtual double scaleFactorWid()
Returns the bin width associated with the scale factor - in the case of linear binning, this is the const.
virtual const Range & setRange(const Range &, bool hold_width=true)
int m_num_bins
The number of bins.
Definition: BinnerAxis.h:64
int numberOfBins(double width) const
Returns the number of bins of width width required to fill the range.
Definition: Range.cxx:199
virtual ~BinnerAxisLinear()
The destructor.
The class for the constant width bins.

Generated for HippoDraw Class Library by doxygen