ProjectorHelper.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 #include "msdevstudio/MSconfig.h"
14 #endif
15 
16 #include "ProjectorHelper.h"
18 #include "datasrcs/DataSource.h"
19 
20 #include <algorithm>
21 #include <numeric>
22 #include <iterator>
23 
24 #include <cmath>
25 
26 using std::sqrt;
27 using std::vector;
28 
29 namespace dp = hippodraw::DataPoint2DTuple;
30 
31 namespace hippodraw {
32 
34 ProjectorHelper ( const DataSource *ntuple )
35  : m_ntuple ( ntuple )
36 {
37 }
38 
39 int
41 size () const
42 {
43  return m_ntuple -> rows ();
44 }
45 
46 double
48 getTotal () const
49 {
50  return m_ntuple -> sum ( dp::Y );
51 }
52 
53 double
55 minCoord () const
56 {
57  const vector< double >& colCoord = m_ntuple -> getColumn( dp::X );
58 
59  return *std::min_element( colCoord.begin(), colCoord.end() );
60 }
61 
62 double
64 maxCoord () const
65 {
66  const vector< double >& colCoord = m_ntuple -> getColumn( dp::X );
67 
68  return *std::max_element( colCoord.begin(), colCoord.end() );
69 }
70 
71 double
73 minValue () const
74 {
75  const vector< double >& colValue = m_ntuple -> getColumn( dp::Y );
76 
77  return *std::min_element( colValue.begin(), colValue.end() );
78 }
79 
80 double
82 maxValue () const
83 {
84  const vector< double >& colValue = m_ntuple -> getColumn( dp::Y );
85 
86  return *std::max_element( colValue.begin(), colValue.end() );
87 }
88 
89 double
91 meanValue () const
92 {
93  const vector< double >& colValue = m_ntuple -> getColumn( dp::Y );
94  double sum = 0.0;
95  sum = std::accumulate( colValue.begin(), colValue.end(), sum );
96 
97  return sum / colValue.size();
98 }
99 
100 
101 double
103 meanCoord () const
104 {
105  const vector<double>& colCoord = m_ntuple -> getColumn( dp::X );
106  const vector<double>& colValue = m_ntuple -> getColumn( dp::Y );
107 
108  double sumXY = 0.0;
109  sumXY = std::inner_product( colCoord.begin(), colCoord.end(),
110  colValue.begin(), sumXY );
111  double sumY = 0.0;
112  sumY = std::accumulate( colValue.begin(), colValue.end(), sumY );
113 
114  return sumXY / sumY;
115 }
116 
117 double
119 stdCoord () const
120 {
121  const vector<double>& x = m_ntuple -> getColumn( dp::X );
122  const vector<double>& y = m_ntuple -> getColumn( dp::Y );
123 
124  double sumY = getTotal();
125  double mean = meanCoord();
126  double sumXXY = 0.0;
127 
128  for( unsigned int i = 0; i < x.size(); i++)
129  sumXXY += ( x[i] * x[i] * y[i] );
130 
131  return sqrt ( sumXXY / sumY - mean * mean );
132 }
133 
134 double
136 valueAt( double x ) const
137 {
138  const vector<double>& colValue = m_ntuple -> getColumn( dp::Y );
139  const vector<double>& colCoord = m_ntuple -> getColumn( dp::X );
140 
141  double value = 0.0;
142  bool is_set = false;
143 
144  for ( unsigned int i = 1; i < colValue.size(); i++) {
145  if ( colCoord[i-1] <= x && x <= colCoord[i] ) {
146  value = colValue[i-1]; // Eschew linear interpolation in favor of
147  is_set = true; // returning a valid value, which is more robust.
148  }
149  }
150  if ( is_set == false ) {
151  throw std::string("valueAt: x lies outside valid range.");
152  }
153 
154  return value;
155 }
156 
157 } // namespace hippodraw
158 
unsigned int i
virtual double meanValue() const
Returns the mean of the values in the data set.
const DataSource * m_ntuple
The pointer to the ntuple (of the appropriate data set) for which it is called to help...
virtual int size() const
Returns the number of points in the data set.
virtual double stdCoord() const
Returns the standard deviation of the coordinates along the X axis in the data set.
virtual double meanCoord() const
Returns the mean of the coordinates along the X axis in the data set.
hippodraw::DataSource class interface.
virtual double minCoord() const
Returns the smallest coordinate value along the X axis in the data set.
virtual double maxValue() const
Returns the largest value in the data set.
virtual double minValue() const
Returns the smallest value in the data set.
hippodraw::DataPointTuple namespace interface
virtual double maxCoord() const
Returns the largest coordinate value along the X axis in the data set.
ProjectorHelper class interface.
virtual double getTotal() const
Returns the sum of the values of the data set.
ProjectorHelper(const DataSource *ntuple)
The constructor taking ntuple pointer as arguments.
virtual double valueAt(double x) const
Returns the value at a given coordinate.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen