StHist1DProjector.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 "StHist1DProjector.h"
18 
19 #include "ProjectorHelper.h"
20 
21 #include "axes/AxisModelBase.h"
22 
23 #include "binners/BinsBase.h"
24 #include "binners/BinsFactory.h"
25 
26 #include <cassert>
27 
28 using namespace hippodraw;
29 
30 #ifdef ITERATOR_MEMBER_DEFECT
31 using namespace std;
32 #else
33 using std::list;
34 using std::max;
35 using std::string;
36 using std::vector;
37 #endif
38 
40  : Hist1DProjImp ( )
41 {
42  m_y_label = "Entries / bin";
43 }
44 
51 StHist1DProjector ( const StHist1DProjector & projector )
52  : ProjectorBase ( projector ),
53  Hist1DProjImp ( projector ),
54  m_title ( projector.m_title ),
55  m_x_label ( projector.m_x_label ),
56  m_y_label ( projector.m_y_label )
57 {
58 }
59 
61 {
62  return new StHist1DProjector ( *this );
63 }
64 
65 /* virtual */
66 bool StHist1DProjector::isAxisBinned ( const std::string & axis ) const
67 {
68  return axis == "x" || axis == "X";
69 }
70 
74 double
77 {
78  assert ( axis == Axes::X || axis == Axes::Y );
79 
80  return getPosOnValue ();
81 }
82 
83 Range
86 {
87  assert ( axis == Axes::X || axis == Axes::Y );
88 
89  if ( axis == Axes::X ) {
90  return m_binner->getRange ( axis );
91  }
92 
93  // Y
94  return dataRangeOnValue ();
95 }
96 
97 const string & StHist1DProjector::getXLabel() const
98 {
99  return m_x_label;
100 }
101 
103 {
105 }
106 
107 const string & StHist1DProjector::getYLabel ( bool ) const
108 {
109  return m_y_label;
110 }
111 
112 double
115 {
116  StHist1DProjector * p = const_cast < StHist1DProjector * > ( this );
117  p -> prepareValues (); // might yet be done.
118 
119  ProjectorHelper helper( getProjectedValues () );
120 
121  double mean = 0.0;
122 
123  if ( axis == Axes::X ) {
124  mean = helper.meanCoord();
125  }
126  else if ( axis == Axes::Y ) {
127  mean = helper.meanValue() * m_y_axis->getScaleFactor();
128  }
129  p -> setDirty ( true );
130  return mean;
131 }
132 
133 /* virtual */
134 const std::string & StHist1DProjector::getTitle () const
135 {
136  return m_title;
137 }
138 
139 int
142 {
143  double sum = m_binner->getNumberOfEntries ();
144 
145  return static_cast < int > ( sum );
146 }
147 
148 int
150 getUnderflow () const
151 {
152  int underflow = m_binner->getUnderflow ();
153  return underflow;
154 }
155 
156 int
158 getOverflow () const
159 {
160  int overflow = m_binner->getOverflow ();
161  return overflow;
162 }
163 
164 
165 void
167 addValues ( const std::vector < double > & v )
168 {
169  double x = v[0];
170  double w = v.size() == 2 ? v[1] : 1.0;
171 
172  m_binner -> accumulate ( x, w );
173  setDirty ();
174 
175  notifyObservers ();
176 }
177 
178 bool
180 isEmpty () const
181 {
182  return false;
183 }
184 
185 void
188  const Range & range,
189  bool const_width )
190 {
191  if ( m_binner -> isEmpty () ) {
192  m_binner -> setRange ( axis, range, const_width );
193  checkScaling ();
194  }
195  setDirty ( true );
196 }
197 
198 void
201 {
202  m_binner -> reset ();
203  setDirty( true );
204 }
205 
StHist1DProjector()
The default constructor.
virtual double meanValue() const
Returns the mean of the values in the data set.
const std::string & getXLabel() const
Returns the label (title) of the x axis.
virtual void notifyObservers() const
Notifies Observer objects of a change.
Definition: Observable.cxx:93
A derived class of ProjectorBase that projects data accumulated by calls to its fill function into a ...
std::string m_y_label
The label of the y axis.
A derived class of BinningProjector that implements the member function common to classes implementin...
Definition: Hist1DProjImp.h:32
virtual void reset()
Resets the bins.
virtual int getOverflow() const =0
Returns the overflow.
const std::string & getYLabel(bool flag=false) const
Returns the label for the Y axis.
std::string m_title
The title of the histogram.
virtual void addValues(const std::vector< double > &v)
Add the values to the histogram.
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
virtual bool isAxisBinned(const std::string &axis) const
Returns true if the intended axis is &quot;X&quot;, otherwise returns false.
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
virtual double meanCoord() const
Returns the mean of the coordinates along the X axis in the data set.
virtual void setRange(hippodraw::Axes::Type, bool)
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual int getUnderflow() const =0
Returns the underflow.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
bool isEmpty() const
Returns false as this class&#39; data source is never empty even if no filling has occurred yet...
const DataSource * getProjectedValues() const
Returns DataSource representation of projected values.
virtual Range dataRangeOn(hippodraw::Axes::Type axis) const
Returns the range of the data on a specified axis.
Range dataRangeOnValue() const
Returns the data range on the Y axis.
hippodraw::BinsBase class interface
BinsBase * m_binner
The binner object.
StHist1DProjector class interface.
ViewBase * v
Definition: PlotTable.cxx:104
std::string m_x_label
The label of the x axis.
double getScaleFactor() const
Returns the scale factor.
virtual int getNumberOfEntries() const =0
Returns the true number of entries.
void setYLabel()
Sets the Y axis label.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
virtual const std::string & getTitle() const
Finds the title of the plot.
hippodraw::AxisModelBase class interface
virtual double getAverage(hippodraw::Axes::Type axis) const
Get the Average of all projected values on the specified axis.
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
A concreate implementation of the FunctionHelper class.
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)
Sets the Range of the binner.
virtual int getNumberOfEntries() const
Returns the total number of entries that went into creating the projected values. ...
virtual int getOverflow() const
Returns the number of overflow.
Expresses a range of values.
Definition: Range.h:33
double getPosOnValue() const
Returns the smallest positive value on the Y axis.
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
virtual void checkScaling()
Checks the axis scaling.
ProjectorHelper class interface.
virtual int getUnderflow() const
Returns the number of underflow.
Type
Axes constants.
Definition: AxesType.h:31
std::string m_y_label_entries
The label of the y axis when axis is scaled.
Definition: Hist1DProjImp.h:40

Generated for HippoDraw Class Library by doxygen