EqualEntriesHist1DProjector.cxx
Go to the documentation of this file.
1 
13 #ifdef _MSC_VER
14 // Include max() and min() missing from MicroSoft Visual C++.
15 #include "msdevstudio/MSconfig.h"
16 #endif
17 
19 
20 #include "axes/AxisModelBase.h"
22 #include "datasrcs/NTuple.h"
23 #include "datasrcs/NTupleSorter.h"
24 
25 #include <algorithm>
26 #include <numeric>
27 
28 #include <cfloat>
29 #include <climits>
30 
31 #include <cassert>
32 
33 using namespace hippodraw;
34 
35 #ifdef ITERATOR_MEMBER_DEFECT
36 using namespace std;
37 #else
38 using std::accumulate;
39 using std::find;
40 using std::max;
41 using std::min;
42 using std::list;
43 using std::string;
44 using std::vector;
45 #endif
46 
48  : NTupleProjector ( 2 ),
49  m_y_label ( "Density" ),
50  m_bin_num (100),
51  m_start_num (100)
52 {
53  m_binding_options.push_back ( "X" );
54  m_binding_options.push_back ( "Weight (optional)" );
55  m_min_bindings = 1;
56  addPointReps();
57 }
58 
65  : NTupleProjector ( projector ),
66  m_y_label ( projector.m_y_label ),
67  m_bin_num ( projector.m_bin_num ),
68  m_start_num ( projector.m_start_num )
69 {
70  addPointReps();
71 }
72 
74 {
75  return new EqualEntriesHist1DProjector( *this );
76 }
77 
79 {
80  unsigned int cols = m_ntuple->columns () - 1;
81  if ( m_columns[0] > cols ) {
82  m_columns[0] = cols;
83  }
84  if ( m_columns[1] > cols ) m_columns[1] = UINT_MAX;
85 }
86 
87 
88 double
91 {
92  assert ( axis == Axes::X || axis == Axes::Y );
93 
94  if ( axis == Axes::X ) {
95  return getPos ( m_columns[0] );
96  }
97  // Y
98 
99  return 0;
100  //return getPosOnValue ();
101 }
102 
103 
104 Range
107 {
108  assert ( axis == Axes::X || axis == Axes::Y );
109 
110  if ( axis == Axes::X ) {
111  return dataRange ( m_columns[0] );
112  }
113  // Y
114  return dataRangeOnValue ();
115 }
116 
117 
118 const string & EqualEntriesHist1DProjector::getYLabel ( bool density ) const
119 {
120  return m_y_label;
121 }
122 
123 
124 namespace dp = hippodraw::DataPoint2DTuple;
125 
126 
127 // ToDo:: need implementation to get all information.
128 double
131 {
132  return 0;
133 }
134 
135 
136 int
138 getUnderflow () const
139 {
140  return 0;
141 }
142 
143 int
145 getOverflow () const
146 {
147  return 0;
148 }
149 
150 
151 DataSource *
153 createNTuple () const
154 {
155  unsigned int columns = 4;
156  NTuple * ntuple = new NTuple ( columns );
157 
158  vector < string > labels;
159  labels.push_back ( "X" );
160  labels.push_back ( "Value" );
161  labels.push_back ( dp::WIDTH );
162  labels.push_back ( dp::ERROR );
163 
164  ntuple->setLabels ( labels );
165 
166  fillProjectedValues ( ntuple );
167 
168  return ntuple;
169 }
170 
171 void
173 fillProjectedValues ( DataSource * ntuple, bool ) const
174 {
175  ntuple -> clear();
176 
177  vector < double > row ( dp::SIZE );
178 
179  unsigned int x_col = m_columns[0];
180  unsigned int size = m_ntuple -> rows ();
181 
182  // Sort a column of data source.
183  vector < double > col = m_ntuple -> getColumn ( x_col );
184  std::sort(col.begin(), col.end());
185 
186  // Index of the vector
187  unsigned int k=0;
188  for ( unsigned int i = 0; i < m_bin_num; i++ ) {
189 
190  // For comm_bin_numing bins with too small width
191  unsigned int j=1;
192  row [dp::XERR] = col[k+size/m_bin_num]- col[k];
193 
194  // Last bin can't exceed data range
195  if (i==m_bin_num-1) row[dp::XERR] = col[size-1]-col[k];
196 
197  // Bin width is 0, combine with the following ones.
198  while ((row[dp::XERR]==0) && (i!=m_bin_num-1)) {
199  j++;
200  i++;
201  row[dp::XERR]=col[k+j*size/m_bin_num]-col[k];
202  if ( i==m_bin_num-1 ) row[dp::XERR] = col[size-1]-col[k];
203  }
204 
205  // Bin width is 0 and it's last bin, ignore the last bin
206  if ( row[dp::XERR]==0 ) return;
207 
208  // Cooridinate of the middle of the bin.
209  row [dp::X] = col[k] + 0.5*row[dp::XERR];
210 
211  // Density is number of entries in a bin divided by bin width.
212  row [dp::Y] = size*j/m_bin_num/row[dp::XERR];
213 
214  // Use half width
215  row [dp::XERR] /= 2.0;
216  row [dp::YERR] = 0;
217 
218  ntuple -> addRow (row);
219 
220  // next bin
221  k+=j*size/m_bin_num;
222  }
223 
224 }
225 
226 void
229 {
231  m_range = dataRange ( m_columns[0] );
232 
233  if ( m_proj_values == 0 ) {
235  } else {
237  }
238 
239  setDirty ( false );
240 }
241 
242 
243 void
246 {
247  m_pointreps.push_back ( "Column" );
248  m_pointreps.push_back ( "FilledColumn" );
249  m_pointreps.push_back ( "Symbol" );
250  m_pointreps.push_back ( "Line" );
251 }
252 
254 isAxisBinned ( const std::string & axis ) const
255 {
256  if ( axis == m_binding_options[0] ) {
257  return true;
258  }
259  return false;
260 }
261 
262 Range
264 valueRange () const
265 {
266  return dataRangeOn ( Axes::Y );
267 }
268 
269 Range
272 {
273  EqualEntriesHist1DProjector * p = const_cast < EqualEntriesHist1DProjector * > ( this );
274  p->prepareValues ();
275  if ( m_proj_values -> empty () ) {
276  return Range ( 0.0, 1.0, 0.5 );
277  }
278 
279  const vector < double > & values = m_proj_values -> getColumn( dp::Y );
280  return Range ( values );
281 }
282 
283 const Range &
285 setBinWidth( Axes::Type axis, int parm, bool dragging )
286 {
287  m_bin_num=m_start_num+parm-50;
289  setDirty(true);
290 
291  if ( !dragging ) m_start_num = m_bin_num;
292  //m_range = dataRange ( m_columns[0] );
293  return m_range;
294 }
295 
296 const Range &
298 setBinWidth( Axes::Type axis, double number )
299 {
300  m_bin_num=(unsigned int) number;
302  setDirty(true);
303  //m_range = dataRange ( m_columns[0] );
304  return m_range;
305 }
306 
307 double
309 getBinWidth ( Axes::Type axis ) const
310 {
311  return (double)m_bin_num;
312 }
313 
314 void
317 {
318  unsigned int size = m_ntuple -> rows ();
319  if ( size-1 < m_bin_num ) m_start_num = m_bin_num = size-1;
320  if (m_bin_num < 1) m_bin_num = 1;
321 }
virtual bool isAxisBinned(const std::string &axis) const
Returns true if specified axis is binned.
unsigned int i
double getPos(int column) const
Returns the minimum positive value on the specified column.
void adjustNumberOfBins()
Make sure the number of bins between 1 and number of rows.
unsigned int m_bin_num
The number of bins.
std::string ERROR
YERR column label.
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
virtual void fillProjectedValues(DataSource *ntuple, bool in_range=false) const
std::vector< unsigned int > m_columns
A vector containing indexes to the columns of the DataSource.
Range m_range
The range of the data source.
Range dataRange(int column) const
Returns the range of data on the specified column.
virtual void addPointReps()
Function to add the acceptable point reps.
unsigned int m_start_num
The number of bins when dragging starts.
void setLabels(const std::vector< std::string > &v)
Assigns the label to each column from the vector of strings.
Definition: NTuple.cxx:471
An NTupleProjector is a projector that projects data from an DataSource object.
virtual const Range & setBinWidth(Axes::Type axis, int parm, bool dragging)
Sets the number of bins in this class.
NTupleSorter class interface.
virtual void prepareValues()
Informs the projector to prepare its projected values for plotting.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
virtual double getBinWidth(Axes::Type axis) const
Get the number of bins in this class.
hippodraw::NTuple class interface.
virtual int getOverflow() const
Returns overflow.
error on X or half bin width
intp size(numeric::array arr)
Definition: num_util.cpp:296
const DataSource * m_ntuple
The pointer to the data source being projected.
std::vector< std::string > m_binding_options
The list of binding options for the Projector.
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
A derived class of NTupleProjector that projects a column of data into a one dimensional histogram...
virtual Range valueRange() const
Finds the range of the projected values.
A DataSource class implemented with std::vector&lt;double&gt; to store the column data. ...
Definition: NTuple.h:33
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
hippodraw;:EqualEntriesHist1Projector class interface
virtual Range dataRangeOn(hippodraw::Axes::Type axis) const
Returns the range of the data on a specified axis.
hippodraw::AxisModelBase class interface
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
Definition: DataSource.h:458
virtual int getUnderflow() const
Returns underflow.
virtual double getAverage(hippodraw::Axes::Type axis) const
Get the Average of all projected values on the specified axis.
virtual void changedNTuple()
This function is called when the NTuple has been changed to a new one.
Expresses a range of values.
Definition: Range.h:33
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
hippodraw::DataPointTuple namespace interface
std::string m_y_label
The label for the y axis.
unsigned int m_min_bindings
The minimum number of columns that must be bound.
std::string WIDTH
XERR column label.
virtual DataSource * createNTuple() const
Creates an NTuple representation of the projected values.
Type
Axes constants.
Definition: AxesType.h:31
virtual const std::string & getYLabel(bool density=false) const
Returns the label of the axis.
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen