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 }

Generated for HippoDraw Class Library by doxygen