ProfileProjector.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 "ProfileProjector.h"
18 
19 #include "axes/AxisModelBase.h"
20 
21 #include "binners/BinsBase.h"
22 #include "binners/BinsFactory.h"
23 #include "binners/BinnerAxis.h"
25 
27 #include "datasrcs/NTuple.h"
28 
29 #include <algorithm>
30 
31 #include <climits>
32 #include <cassert>
33 
34 using namespace hippodraw;
35 
36 #include <stdio.h>
37 
38 #ifdef ITERATOR_MEMBER_DEFECT
39 using namespace std;
40 #else
41 using std::list;
42 using std::max;
43 using std::string;
44 using std::vector;
45 #endif
46 
48  : BinningProjector ( 1 ),
49  NTupleProjector ( 3 )
50 {
51  m_binding_options.push_back ( "X" );
52  m_binding_options.push_back ( "Y" );
53  m_binding_options.push_back ( "Weight (optional)" );
54  m_min_bindings = 2;
55 
56  BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
57  BinnerAxis * binner = binner_factory -> create ( "BinnerLinear" );
58 
59  BinsFactory * factory = BinsFactory::instance();
60  m_binner = factory -> create ( "Bins1DProfile" );
61 
62  m_binner->setBinnerOn ( binner, Axes::X );
63  addPointReps();
64 }
65 
71 ProfileProjector ( const ProfileProjector & projector )
72  : ProjectorBase ( projector ),
73  BinningProjector ( projector ),
74  NTupleProjector ( projector )
75 {
76  addPointReps();
77 }
78 
80 {
81  return new ProfileProjector( *this );
82 }
83 
86 {
87  unsigned int cols = m_ntuple->columns () - 1;
88  if ( m_columns[0] > cols ) m_columns[0] = cols;
89  if ( m_columns[1] > cols ) m_columns[1] = cols;
90  if ( m_columns[2] > cols ) m_columns[2] = cols;
91 
92  m_binner->setDirty ( );
93 }
94 
96 {
97  if ( m_ntuple->isNull () ) return;
98 
99  // Get the data and the optional weight column.
100  unsigned int & x_col = m_columns[0];
101  unsigned int & y_col = m_columns[1];
102  unsigned int & w_col = m_columns[2];
103  unsigned int size = m_ntuple -> rows ();
104 
105  bool have_weight = w_col < UINT_MAX;
106 
107  // Use integer indexing to ensure that it will take everything from the
108  // same row, including the cut values.
109 
110  m_binner->reset ();
111 
112  for ( unsigned int i = 0; i < size; i++ )
113  {
114  if ( acceptRow ( i, m_cut_list ) == false ) continue;
115 
116  double x = m_ntuple -> valueAt ( i, x_col );
117  double y = m_ntuple -> valueAt ( i, y_col );
118  double w = 1.0;
119  if ( have_weight) {
120  w = m_ntuple -> valueAt ( i, w_col );
121  }
122  m_binner->accumulate( x, y, w );
123  }
124 }
125 
127 {
128  return dataRangeOn ( Axes::Y );
129 }
130 
131 namespace dp = hippodraw::DataPoint2DTuple;
132 
133 Range
136 {
137  assert ( axis == Axes::X || axis == Axes::Y );
138 
139  if ( axis == Axes::X ) {
140  return dataRange ( m_columns[0] );
141  }
142 
143  ProfileProjector * p = const_cast<ProfileProjector *> ( this );
144  p->prepareValues ();
145 
146  // If no points are left due to cuts, then returns zero range.
147  if ( m_proj_values -> empty () ) {
148  return Range ( 0.0, 0.0 );
149  }
150  double max = DBL_MIN;
151  double min = DBL_MAX;
152 
153  const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
154  const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
155  for ( unsigned int i = 0; i < values.size(); i++ ) {
156  double hi = values[i] + errors[i];
157  double lo = values[i] - errors[i];
158  max = std::max ( max, hi );
159  min = std::min ( min, lo );
160  }
161 
162  return Range ( min, max );
163 }
164 
165 double
168 {
169  assert ( axis == Axes::X || axis == Axes::Y );
170 
171  if ( axis == Axes::X ) {
172  return getPos ( m_columns[0] );
173  }
174 
175  // If no points are left due to cuts, then returns DBL_MAX.
176  if ( m_proj_values -> empty() ) {
177  return DBL_MAX;
178  }
179 
180  double pos = DBL_MAX;
181 
182  const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
183  const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
184  for ( unsigned int i = 0; i < values.size (); i++ ) {
185  double lo = values[i] - errors[i];
186  if ( lo > 0.0 &&
187  lo < pos ) pos = lo;
188  }
189 
190  return pos;
191 }
192 
193 /* virtual */
194 bool ProfileProjector::isAxisBinned ( const std::string & axis ) const
195 {
196  if ( axis == m_binding_options[0] ) {
197  return true;
198  }
199  return false;
200 }
201 
203 {
204  m_pointreps.push_back ( "Symbol" );
205 }
206 
207 void
209 setRange ( hippodraw::Axes::Type axis, bool const_width )
210 {
211  assert ( m_binner );
212  assert ( axis == Axes::X || axis == Axes::Y );
213 
214  if ( axis == Axes::X ) {
215  const Range & range = m_x_axis->getRange( false );
216  if( m_x_axis->isLog() ) {
217  if( range.low() < 0.0 ) return;
218  m_x_axis->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
219  const Range & range2 = m_x_axis->getRange( false );
220  setBinnerRange ( axis, range2, const_width );
221  }
222  else {
223  setBinnerRange ( axis, range, const_width );
224 
225  }
226  }
227 }
228 
229 void
232  const Range & range,
233  bool const_width )
234 {
235  m_binner -> setRange ( axis, range, const_width );
236  checkScaling ();
237 
238  setDirty ( true );
239 }
240 
241 void
243 update ( const Observable * object )
244 {
245  const DataSource * datasource
246  = dynamic_cast < const DataSource * > ( object );
247 
248  if ( datasource != 0 ) {
249  NTupleProjector::update ( object );
250  }
251  else {
252  BinningProjector::update ( object );
253  }
254 }
255 
256 void
258 willDelete ( const Observable * object )
259 {
260  const DataSource * datasource
261  = dynamic_cast < const DataSource * > ( object );
262 
263  if ( datasource != 0 ) {
264  NTupleProjector::willDelete ( object );
265  }
266  else {
267  BinningProjector::willDelete ( object );
268  }
269 }
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
virtual bool isAxisBinned(const std::string &axis) const
Returns true if specified axis is binned.
A namespace to set the standard for indexing into 2 dimension data point tuple.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
bool acceptRow(unsigned int i, const CutList_t &cut_list) const
For row i of the column in the DataSource, returns true if all the cuts accept the row...
unsigned int m_min_bindings
The minimum number of columns that must be bound.
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
Definition: Observable.h:39
virtual void update(const Observable *object)
Implements Observer pattern.
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
hippodraw::AxisModelBase class interface
virtual void checkScaling()
Checks and sets if an AxisModelBase object on an axis should be scaled.
virtual void willDelete(const Observable *object)
If object is the target of normalization, removes the target and sets normalization off...
std::vector< std::string > m_binding_options
The list of binding options for the Projector.
Type
Axes constants.
Definition: AxesType.h:31
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
ProfileProjector class interface.
BinsBase * m_binner
The binner object.
A Factory singleton class for creating objects whose class derives from BinnerAxis.
virtual void willDelete(const Observable *)
Responds to willDelete message from the observed data source.
std::vector< std::string > m_pointreps
Vector of acceptable PointReps.
virtual void willDelete(const Observable *object)
Implements Observer pattern.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
Definition: DataSource.h:458
Namespace for HippoDraw.
Definition: AxesType.cxx:21
const DataSource * m_ntuple
The pointer to the data source being projected.
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
double getPos(int column) const
Returns the minimum positive value on the specified column.
virtual void execute()
Provides the all the data to the binner.
virtual void accumulate(double x, double w_or_y=1.0, double z=1.0, double w=1.0)=0
Accumulates the data point with weight w.
hippodraw::NTuple class interface.
Base class for DataSource.
Definition: DataSource.h:55
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
A Factory singleton class for creating objects whose class derives from BinsBase. ...
Definition: BinsFactory.h:31
virtual void update(const Observable *)
Responds to update message from the data source.
intp size(numeric::array arr)
Definition: num_util.cpp:296
virtual void addPointReps()
Function to add the acceptable point reps.
virtual void changedNTuple()
This function is called when the DataSource has been changed to a new one.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
STL namespace.
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
ProfileProjector()
The default constructor.
bool isNull() const
Returns true if the receiving objects is a null object.
Definition: DataSource.cxx:125
Expresses a range of values.
Definition: Range.h:33
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
An NTupleProjector is a projector that projects data from an DataSource object.
virtual void reset()=0
Resets the accumulation to zero.
CutList_t m_cut_list
A list of cuts that filter the projection.
hippodraw::DataPointTuple namespace interface
virtual void update(const Observable *object)
Updates the receiving projector.
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
virtual Range dataRangeOn(hippodraw::Axes::Type) const
Returns the range of the data on the specified axis.
Range dataRange(int column) const
Returns the range of data on the specified column.
void setDirty()
Sets a flag to indicate that re-binning needs to be done.
Definition: BinsBase.cxx:64
virtual Range valueRange() const
Finds the range of the projected values.
hippodraw::BinnerAxis class interface
virtual void setRange(hippodraw::Axes::Type axis, bool const_width)
Sets the range of the selected axis.
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)
Sets the Range of the binner.
A derived class of BinningProjector which projects to a profile display.
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
hippodraw::BinsBase class interface
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
std::vector< unsigned int > m_columns
A vector containing indexes to the columns of the DataSource.

Generated for HippoDraw Class Library by doxygen