StHist2DProjector.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 "StHist2DProjector.h"
18 
19 #include "axes/AxisModelBase.h"
20 
21 #include "binners/BinsBase.h"
22 #include "binners/BinsFactory.h"
23 
25 #include "datasrcs/DataSource.h"
26 
27 #include <numeric>
28 
29 #include <cassert>
30 
31 using namespace hippodraw;
32 
33 #ifdef ITERATOR_MEMBER_DEFECT
34 using namespace std;
35 #else
36 using std::accumulate;
37 using std::inner_product;
38 using std::list;
39 using std::max;
40 using std::string;
41 using std::vector;
42 #endif
43 
45  : Hist2DProjImp ( )
46 {
47  m_z_label = "Entries / bin";
48 }
49 
56 StHist2DProjector ( const StHist2DProjector & projector )
57  : ProjectorBase ( projector ),
58  Hist2DProjImp ( projector ),
59  m_title ( projector.m_title ),
60  m_x_label ( projector.m_x_label ),
61  m_y_label ( projector.m_y_label ),
62  m_z_label ( projector.m_y_label )
63 {
64 }
65 
67 {
68  return new StHist2DProjector ( *this );
69 }
70 
75 bool StHist2DProjector::isAxisBinned ( const std::string & axis ) const
76 {
77  return axis == "x" ||
78  axis == "X" ||
79  axis == "y" ||
80  axis == "Y";
81 }
82 
83 double
86 {
87  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
88 
89  return getPosOnValue ();
90 }
91 
92 Range
95 {
96  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
97 
98  if ( axis == Axes::X ) {
99  return m_binner->getRange ( axis );
100  }
101  if ( axis == Axes::Y ) {
102  return m_binner->getRange ( axis );
103  }
104 
105  return dataRangeOnValue ();
106 }
107 
108 const string & StHist2DProjector::getXLabel() const
109 {
110  return m_x_label;
111 }
112 
113 const string & StHist2DProjector::getYLabel ( bool ) const
114 {
115  return m_y_label;
116 }
117 
118 const string & StHist2DProjector::getZLabel ( bool ) const
119 {
120  return m_z_label;
121 }
122 
123 namespace dp = hippodraw::DataPoint3DTuple;
124 
125 double
128 {
129  StHist2DProjector * p = const_cast < StHist2DProjector * > ( this );
130  p -> prepareValues ();
131 
132  unsigned int col = 3; // bad value
133  switch ( axis ) {
134 
135  case Axes::X:
136  col = dp::X;
137  break;
138 
139  case Axes::Y:
140  col = dp::Y;
141  break;
142 
143  case Axes::Z:
144  col = dp::Z;
145  break;
146 
147  default:
148  break;
149  }
150  assert ( col < 3 );
151 
152  double result = 0.0;
153  const DataSource * ntuple = getProjectedValues ();
154  const vector < double > & value = ntuple -> getColumn ( dp::Z );
155 
156  if ( col < 2 ) {
157  const vector < double > & data = ntuple -> getColumn ( col );
158 
159  double sumXV = 0.0;
160  // Doxygen 1.5.0 needs the std::
161  sumXV = std::inner_product ( data.begin(), data.end(),
162  value.begin(), sumXV );
163 
164  double sumV = 0.0;
165  sumV = accumulate ( value.begin(), value.end(), sumV );
166 
167  result = sumXV / sumV;
168  }
169  else {
170  double sumV = 0.0;
171  sumV = accumulate ( value.begin(), value.end (), sumV );
172  result = ( sumV / value.size () ) * m_z_axis -> getScaleFactor ();
173  }
174  p -> setDirty ( true );
175 
176  return result;
177 }
178 
179 /* virtual */
180 const std::string & StHist2DProjector::getTitle () const
181 {
182  return m_title;
183 }
184 
185 int
188 {
189  double sum = m_binner->getNumberOfEntries ();
190 
191  return static_cast < int > ( sum );
192 }
193 
194 int
196 getUnderflow () const
197 {
198  return m_binner->getUnderflow ();
199 }
200 
201 int
203 getOverflow () const
204 {
205  return m_binner->getOverflow ();
206 }
207 
208 void
210 addValues ( const std::vector < double > & v )
211 {
212  double x = v[0];
213  double y = v[1];
214  double w = v.size() == 3 ? v[2] : 1.0;
215 
216  m_binner -> accumulate ( x, y, w );
217  setDirty ();
218 
219  notifyObservers ();
220 }
221 
222 bool
224 isEmpty () const
225 {
226  return false;
227 }
228 
229 void
232  const Range & range,
233  bool const_width )
234 {
235  if ( m_binner -> isEmpty () ) {
236  m_binner -> setRange ( axis, range, const_width );
237  checkScaling ();
238  }
239  setDirty ( true );
240 }
virtual Range dataRangeOn(hippodraw::Axes::Type axis) const
Returns the range of the data on a specified axis.
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 bool isAxisBinned(const std::string &axis) const
Returns true if the intended axis is &quot;X&quot;, otherwise returns false.
virtual void notifyObservers() const
Notifies Observer objects of a change.
Definition: Observable.cxx:93
virtual const std::string & getTitle() const
Finds the title of the plot.
virtual int getUnderflow() const
Returns the number of underflow.
std::string m_x_label
The label of the x axis.
virtual int getOverflow() const =0
Returns the overflow.
StHist2DProjector()
The default constructor.
void * data(numeric::array arr)
Definition: num_util.cpp:389
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
virtual double getAverage(hippodraw::Axes::Type axis) const
Get the Average of all projected values on the specified axis.
virtual int getUnderflow() const =0
Returns the underflow.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
const DataSource * getProjectedValues() const
Returns DataSource representation of projected values.
AxisModelBase * m_z_axis
The AxisModel along the Z axis.
Definition: ProjectorBase.h:96
hippodraw::DataSource class interface.
const std::string & getXLabel() const
Returns the label (title) of the X axis.
hippodraw::BinsBase class interface
BinsBase * m_binner
The binner object.
ViewBase * v
Definition: PlotTable.cxx:104
virtual int getOverflow() const
Returns the number of overflow.
virtual int getNumberOfEntries() const =0
Returns the true number of entries.
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
bool isEmpty() const
Returns false as this class&#39; data source is never empty even if no filling has occurred yet...
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.
std::string m_y_label
The label of the y axis.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
virtual void checkScaling()
Checks the axis scaling.
hippodraw::AxisModelBase class interface
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
A derived class of BinningProjector projects to a two dimensional histogram.
Definition: Hist2DProjImp.h:33
std::string m_z_label
The label of the y axis.
virtual void addValues(const std::vector< double > &v)
Add the values to the histogram.
Expresses a range of values.
Definition: Range.h:33
hippodraw::DataPointTuple namespace interface
A derived class of ProjectorBase that projects data accumulated by calls to its addValues function in...
double getPosOnValue() const
Returns the smallest positive value on the Y axis.
const std::string & getZLabel() const
Returns the label (title) of the z axis.
Type
Axes constants.
Definition: AxesType.h:31
StHist2DProjector class interface.
const std::string & getYLabel(bool flag=false) const
Returns the label (title) of the Y axis.
std::string m_title
The title of the histogram.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen