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 
Hist2DProjImp()
The default constructor.
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual bool hasEqualWidths() const =0
Returns true if all bins have the same width.
A Factory singleton class for creating objects whose class derives from BinnerAxis.
A Factory singleton class for creating objects whose class derives from BinsBase. ...
Definition: BinsFactory.h:31
hippodraw::Hist2DProjImp class interface
void setZLabel()
Sets the variable so that it can be modified.
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 setOffset(hippodraw::Axes::Type axis, double value)=0
Sets the offset parameter on the specified axis.
virtual Range valueRange() const
Finds the range of the projected values.
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
std::string m_z_label_density
The label of the z axis when displaying density.
Definition: Hist2DProjImp.h:42
void setLow(double x)
Sets the minimum of the range object.
Definition: Range.cxx:93
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
return yes
Definition: CanvasView.cxx:883
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
AxisModelBase * m_z_axis
The AxisModel along the Z axis.
Definition: ProjectorBase.h:96
hippodraw::NTuple class interface.
virtual bool hasZAxis() const
A test function.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double value)=0
Sets the bin width parameter on the specified axis.
hippodraw::BinsBase class interface
BinsBase * m_binner
The binner object.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
virtual Range dataRangeOn(Axes::Type) const =0
Returns the range of the raw data.
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
virtual void addPointReps()
Function to add the acceptable point reps.
virtual void setRange(hippodraw::Axes::Type axis, bool)
Sets the range of the selected axis.
Range dataRangeOnValue() const
Returns the data range on the Z axis.
virtual bool isValueBinned() const
Returns true as the projected value is the result of accumulation into bins.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
virtual ~Hist2DProjImp()
The destructor.
void setScaleFactor(double)
Sets the value of the scale factor.
virtual void checkScaling()
Checks the axis scaling.
hippodraw::AxisModelBase class interface
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
A derived class of BinningProjector projects to a two dimensional histogram.
Definition: Hist2DProjImp.h:33
virtual double scaleFactor() const
Returns the scale factor.
Definition: BinsBase.cxx:69
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 setScaling(bool on=true)
Sets axis scaling on if on is true.
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 const Range & setBinWidth(hippodraw::Axes::Type axis, double v)
This function sets the binWidth.
Expresses a range of values.
Definition: Range.h:33
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
virtual void setOffset(hippodraw::Axes::Type axis, double v)
Sets the bin offset.
hippodraw::DataPointTuple namespace interface
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
double getPosOnValue() const
Returns the smallest positive value on the Y axis.
virtual bool wantsScaleFactor(const std::string &axis) const
Returns true if axis is the Z axis.
const std::string & getZLabel() const
Returns the label (title) of the z axis.
hippodraw::BinnerAxis class interface
virtual double getPosOn(Axes::Type) const =0
Returns the minimum positive value.
Type
Axes constants.
Definition: AxesType.h:31
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)=0
Sets the Range of the binner.

Generated for HippoDraw Class Library by doxygen