Hist2DProjImp.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // for max() and min() missing from Microsoft Visual C++.
14 #include "msdevstudio/MSconfig.h"
15 #endif //_MSC_VER
16 
17 #include "Hist2DProjImp.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 std::list;
32 using std::max;
33 using std::string;
34 using std::vector;
35 
36 namespace hippodraw {
37 
39  : BinningProjector ( 2 )
40 {
41  BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
42  BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
43  BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
44 
45  BinsFactory * factory = BinsFactory::instance ();
46  m_binner = factory->create ( "Bins2DHist" );
47 
50 
51  m_z_label_entries = "Entries / bin";
52  m_z_label_density = "Density";
53 
54  addPointReps();
55 }
56 
62 Hist2DProjImp ( const Hist2DProjImp & projector )
63  : ProjectorBase ( projector ),
64  BinningProjector ( projector ),
65  m_z_label_entries ( projector.m_z_label_entries ),
66  m_z_label_density ( projector.m_z_label_density ),
67  m_value_range( projector.m_value_range )
68 {
69  addPointReps();
70 }
71 
76 {
77 }
78 
80 {
81  return true;
82 }
83 
84 double
86 getPosOnValue () const
87 {
88  Range range = dataRangeOnValue ();
89 
90  return range.pos ();
91 }
92 
93 
94 Range
97 {
98  Range range = dataRangeOn ( axis );
99  if ( axis == Axes::Z ) {
100  range.setLow ( 0.0 );
101  }
102 
103  return range;
104 }
105 
106 namespace dp = hippodraw::DataPoint3DTuple;
107 
108 Range
111 {
112  Hist2DProjImp * p = const_cast < Hist2DProjImp * > ( this );
113  p->prepareValues ();
114  if ( m_proj_values -> empty () ) {
115  return Range ( 0.0, 1.0, 0.5 );
116  }
117 
118  const vector < double > & values = m_proj_values -> getColumn( dp::Z );
119  return Range ( values );
120 }
121 
123 {
124  return dataRangeOn ( Axes::Z );
125 }
126 
128 void
130 setRange ( hippodraw::Axes::Type axis, bool const_width )
131 {
132  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
133 
134  AxisModelBase * model = 0;
135  if ( axis == Axes::X ) {
136  model = m_x_axis;
137  } else if ( axis == Axes::Y ) {
138  model = m_y_axis;
139  }
140  if ( axis != Axes::Z ) {
141  const Range & range = model->getRange (false);
142  if( model->isLog() ) {
143  if( range.low() < 0.0 ) return;
144  model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
145  const Range & range2 = model->getRange ( false );
146  setBinnerRange ( axis, range2, const_width );
147  } else {
148  setBinnerRange ( axis, range, const_width );
149  }
150  }
151 }
152 
153 const Range &
155 setBinWidth ( hippodraw::Axes::Type axis, double width )
156 {
157  assert ( axis == Axes::X || axis == Axes::Y );
158 
159  const Range & range = m_binner->setBinWidth ( axis, width );
160  checkScaling ();
161 
162  setDirty ( true );
163 
164  return range;
165 }
166 
167 void
169 setOffset ( hippodraw::Axes::Type axis, double offset )
170 {
171  if ( axis == Axes::Z ) return;
172  assert ( axis == Axes::X || axis == Axes::Y );
173 
174  m_binner->setOffset ( axis, offset );
175  if( axis == Axes::X )
176  m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
177  else
178  m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
179 
180  setDirty ( true );
181 }
182 
183 
185 {
186  m_z_label_entries = "Entries / bin";
187 }
188 
189 const string & Hist2DProjImp::getZLabel() const
190 {
191  bool scaling = m_z_axis->isScaling ();
192 
193  if ( scaling ) return m_z_label_entries;
194  return m_z_label_density;
195 }
196 
198 {
199  return true;
200 }
201 
203 {
204  if ( m_z_axis == 0 ) return;
205 
206  bool yes = m_binner->hasEqualWidths ();
207 
208  if ( yes ) {
209  double width = m_binner->scaleFactor ();
210  m_z_axis->setScaleFactor ( width );
211  }
212  else {
213  m_z_axis->setScaling ( false );
214  }
215 
216 }
217 
219 {
220  m_pointreps.push_back ( "ColorBox" );
221  m_pointreps.push_back ( "Contour" );
222  //m_pointreps.push_back ( "ColorSymbol" );
223 }
224 
225 bool
227 wantsScaleFactor ( const std::string & axis ) const
228 {
229  return axis == "Z" || axis == "z";
230 }
231 
232 } // namespace hippodraw
233 
virtual void addPointReps()
Function to add the acceptable point reps.
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
Range dataRangeOnValue() const
Returns the data range on the Z axis.
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
AxisModelBase * m_z_axis
The AxisModel along the Z axis.
Definition: ProjectorBase.h:96
virtual void setOffset(hippodraw::Axes::Type axis, double value)=0
Sets the offset parameter on the specified axis.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
BinsBase * m_binner
The binner object.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double v)
This function sets the binWidth.
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
std::string m_z_label_density
The label of the z axis when displaying density.
Definition: Hist2DProjImp.h:42
double getPosOnValue() const
Returns the smallest positive value on the Y axis.
hippodraw::AxisModelBase class interface
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
void setScaleFactor(double)
Sets the value of the scale factor.
virtual bool hasEqualWidths() const =0
Returns true if all bins have the same width.
const std::string & getZLabel() const
Returns the label (title) of the z axis.
virtual void setRange(hippodraw::Axes::Type axis, bool)
Sets the range of the selected axis.
void setZLabel()
Sets the variable so that it can be modified.
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)=0
Sets the Range of the binner.
A derived class of BinningProjector projects to a two dimensional histogram.
Definition: Hist2DProjImp.h:33
virtual ~Hist2DProjImp()
The destructor.
hippodraw::DataPointTuple namespace interface
virtual bool hasZAxis() const
A test function.
virtual Range valueRange() const
Finds the range of the projected values.
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
Hist2DProjImp()
The default constructor.
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
virtual Range preferredRange(hippodraw::Axes::Type) const
Returns the preferred Range.
virtual double getPosOn(Axes::Type) const =0
Returns the minimum positive value.
hippodraw::Hist2DProjImp class interface
hippodraw::NTuple class interface.
A Factory singleton class for creating objects whose class derives from BinsBase. ...
Definition: BinsFactory.h:31
Namespace for HippoDraw.
Definition: AxesType.cxx:21
Type
Axes constants.
Definition: AxesType.h:31
hippodraw::BinsBase class interface
virtual Range dataRangeOn(Axes::Type) const =0
Returns the range of the raw data.
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
hippodraw::BinnerAxis class interface
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
std::string m_z_label_entries
The label of the z axis when displaying number of entries per bin.
Definition: Hist2DProjImp.h:39
virtual void checkScaling()
Checks the axis scaling.
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
bool isScaling() const
Returns true if the axis is being scaled.
void setLow(double x)
Sets the minimum of the range object.
Definition: Range.cxx:93
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual void setOffset(hippodraw::Axes::Type axis, double v)
Sets the bin offset.
A namespace to set the standard for indexing into 3 dimension data point tuple.
virtual bool isValueBinned() const
Returns true as the projected value is the result of accumulation into bins.
A Factory singleton class for creating objects whose class derives from BinnerAxis.
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double value)=0
Sets the bin width parameter on the specified axis.
virtual double scaleFactor() const
Returns the scale factor.
Definition: BinsBase.cxx:69
void setScaling(bool on=true)
Sets axis scaling on if on is true.
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
Expresses a range of values.
Definition: Range.h:33
A namespace to set the standard for indexing into 2 dimension data point tuple.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
virtual bool wantsScaleFactor(const std::string &axis) const
Returns true if axis is the Z axis.

Generated for HippoDraw Class Library by doxygen