Hist1DProjImp.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // Include max() and min() missing from Microsoft Visual C++.
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "Hist1DProjImp.h"
18 
19 #include "axes/AxisModelBase.h"
20 
21 #include "binners/BinsBase.h"
22 #include "binners/BinsFactory.h"
23 #include "binners/BinnerAxis.h"
25 
27 #include "datasrcs/NTuple.h"
28 
29 #include <cassert>
30 
31 using namespace hippodraw;
32 
33 #ifdef ITERATOR_MEMBER_DEFECT
34 using namespace std;
35 #else
36 using std::list;
37 using std::max;
38 using std::string;
39 using std::vector;
40 #endif
41 
43  : BinningProjector ( 1 )
44 {
45  BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
46  BinnerAxis * binner = binner_factory -> create ( "BinnerLinear" );
47 
48  BinsFactory * factory = BinsFactory::instance ();
49  m_binner = factory->create ( "Bins1DHist" );
50 
51  m_binner->setBinnerOn ( binner, Axes::X );
52 
53  m_y_label_entries = "Entries / bin";
54  m_y_label_density = "Density";
55 
56  addPointReps();
57 }
58 
64 Hist1DProjImp ( const Hist1DProjImp & projector )
65  : BinningProjector ( projector ),
68 {
69  addPointReps();
70 }
71 
72 
75 {
76 }
77 
78 void
81 {
82  m_pointreps.push_back ( "Column" );
83  m_pointreps.push_back ( "FilledColumn" );
84  m_pointreps.push_back ( "Symbol" );
85  m_pointreps.push_back ( "Line" );
86 }
87 
88 void
91 {
92  if ( m_y_axis == 0 ) return;
93 
94  bool yes = m_binner->hasEqualWidths ();
95  if ( yes ) {
96  double width = m_binner->scaleFactor ();
97  m_y_axis->setScaleFactor ( width );
98  }
99  else {
100  m_y_axis->setScaling ( false );
101  }
102 }
103 
104 bool
107 {
108  return true;
109 }
110 
111 double
114 {
115  Range range = dataRangeOnValue ();
116 
117  return range.pos ();
118 }
119 
120 Range
123 {
124  Range range = dataRangeOn ( axis );
125  if ( axis == Axes::Y ) {
126  range.setLow ( 0.0 );
127  }
128 
129  return range;
130 }
131 
132 
133 namespace dp = hippodraw::DataPoint2DTuple;
134 
135 Range
138 {
139  Hist1DProjImp * p = const_cast < Hist1DProjImp * > ( this );
140  p->prepareValues ();
141  if ( m_proj_values -> empty () ) {
142  return Range ( 0.0, 1.0, 0.5 );
143  }
144 
145  const vector < double > & values = m_proj_values -> getColumn( dp::Y );
146  return Range ( values );
147 }
148 
150 void
152 setRange ( hippodraw::Axes::Type axis, bool const_width )
153 {
154  assert ( m_binner );
155  assert ( axis == Axes::X || axis == Axes::Y );
156 
157  if ( axis == Axes::X ) {
158  const Range & range = m_x_axis->getRange( false );
159 
160  if( m_x_axis->isLog() ) {
161  if( range.low() < 0.0 ) return;
162  m_x_axis->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
163  const Range & range2 = m_x_axis->getRange( false );
164  setBinnerRange ( axis, range2, const_width );
165  }
166  else {
167  setBinnerRange ( axis, range, const_width );
168  }
169  }
170 }
171 
172 void
175 {
176 }
177 
178 Range
180 valueRange () const
181 {
182  return dataRangeOn ( Axes::Y );
183 }
184 
185 bool
187 wantsScaleFactor ( const std::string & axis ) const
188 {
189  return axis == "Y" || axis == "y";
190 }
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
A namespace to set the standard for indexing into 2 dimension data point tuple.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
void setScaleFactor(double)
Sets the value of the scale factor.
virtual void addPointReps()
Function to add the acceptable point reps.
virtual void checkScaling()
Checks the axis scaling.
Hist1DProjImp class interface.
virtual double getPosOn(Axes::Type) const =0
Returns the minimum positive value.
hippodraw::AxisModelBase class interface
Type
Axes constants.
Definition: AxesType.h:31
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
BinsBase * m_binner
The binner object.
A Factory singleton class for creating objects whose class derives from BinnerAxis.
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
void setScaling(bool on=true)
Sets axis scaling on if on is true.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual void reset()
Resets the bins.
virtual double scaleFactor() const
Returns the scale factor.
Definition: BinsBase.cxx:69
Namespace for HippoDraw.
Definition: AxesType.cxx:21
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
hippodraw::NTuple class interface.
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
A Factory singleton class for creating objects whose class derives from BinsBase. ...
Definition: BinsFactory.h:31
virtual Range dataRangeOn(Axes::Type) const =0
Returns the range of the raw data.
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
Hist1DProjImp()
The default constructor.
void setLow(double x)
Sets the minimum of the range object.
Definition: Range.cxx:93
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
STL namespace.
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
double getPosOnValue() const
Returns the smallest positive value on the Y axis.
Expresses a range of values.
Definition: Range.h:33
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
virtual Range valueRange() const
Finds the range of the projected values.
hippodraw::DataPointTuple namespace interface
std::string m_y_label_density
The label of the y axis when axis is not scaled.
Definition: Hist1DProjImp.h:44
A derived class of BinningProjector that implements the member function common to classes implementin...
Definition: Hist1DProjImp.h:32
virtual void setRange(hippodraw::Axes::Type, bool)
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
virtual bool isValueBinned() const
Returns true as the projected value is the result of accumulation into bins.
hippodraw::BinnerAxis class interface
virtual Range preferredRange(hippodraw::Axes::Type) const
Returns the preferred Range.
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
virtual ~Hist1DProjImp()
The Destructor.
virtual bool wantsScaleFactor(const std::string &axis) const
Returns true if axis is the Y axis.
std::string m_y_label_entries
The label of the y axis when axis is scaled.
Definition: Hist1DProjImp.h:40
hippodraw::BinsBase class interface
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)=0
Sets the Range of the binner.
virtual bool hasEqualWidths() const =0
Returns true if all bins have the same width.
Range dataRangeOnValue() const
Returns the data range on the Y axis.

Generated for HippoDraw Class Library by doxygen