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 

Generated for HippoDraw Class Library by doxygen