DyHist2DProjector.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 //_MSC_VER
16 
17 #include "DyHist2DProjector.h"
18 
19 #include "axes/AxisModelBase.h"
20 
21 #include "binners/BinsBase.h"
22 #include "binners/BinsFactory.h"
23 #include "binners/BinnerAxis.h"
25 
26 #include "datasrcs/NTuple.h"
27 
28 #include <climits>
29 #include <cassert>
30 
31 
32 using namespace hippodraw;
33 
34 using std::list;
35 using std::max;
36 using std::string;
37 using std::vector;
38 
40  : Hist2DProjImp (),
41  NTupleProjector ( 3 )
42 {
43  m_binding_options.push_back ( "X" );
44  m_binding_options.push_back ( "Y" );
45  m_binding_options.push_back ( "Weight (optional)" );
46  m_min_bindings = 2;
47 }
48 
54 DyHist2DProjector ( const DyHist2DProjector & projector )
55  : ProjectorBase ( projector ),
56  Hist2DProjImp ( projector ),
57  NTupleProjector ( projector ),
60  m_value_range( projector.m_value_range )
61 {
62 }
63 
65 {
66  return new DyHist2DProjector( *this );
67 }
68 
70 {
71  unsigned int cols = m_ntuple->columns () - 1;
72  if ( m_columns[0] > cols ) m_columns[0] = cols;
73  if ( m_columns[1] > cols ) m_columns[1] = cols;
74 
75  m_binner->setDirty();
76 }
77 
79 {
80  unsigned int x_col = m_columns[0];
81  unsigned int y_col = m_columns[1];
82  unsigned int w_col = m_columns[2];
83 
84  bool have_weight = w_col < UINT_MAX;
85 
86  // Use integer indexing to ensure that it will take everything from the
87  // same row, including the cut values.
88 
89  m_binner->reset();
90  unsigned int size = m_ntuple -> rows ();
91  for ( unsigned int i = 0; i < size; i++ )
92  {
93  if ( acceptRow ( i, m_cut_list ) == false ) continue;
94 
95  double x = m_ntuple -> valueAt ( i, x_col );
96  double y = m_ntuple -> valueAt ( i, y_col );
97  double w = 1.0;
98  if ( have_weight ) {
99  w = m_ntuple -> valueAt ( i, w_col );
100  }
101  m_binner->accumulate( x, y, w );
102  }
103 }
104 
105 /* virtual */
106 bool DyHist2DProjector::isAxisBinned ( const std::string & axis ) const
107 {
108  if ( axis == m_binding_options[0]
109  || axis == m_binding_options[1] ) return true;
110  return false;
111 }
112 
113 Range
116 {
117  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
118  if ( axis == Axes::X ) {
119  return dataRange ( m_columns[0] );
120  } else if ( axis == Axes::Y ) {
121  return dataRange ( m_columns[1] );
122  } else {
123  return dataRangeOnValue ();
124  }
125 }
126 
127 double
130 {
131  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
132  if ( axis == Axes::X ) {
133  return getPos ( m_columns[0] );
134  } else if( axis == Axes::Y ) {
135  return getPos ( m_columns[1] );
136  } else {
137  return valueRange().pos();
138  }
139 }
140 
141 const Range &
144  int parm,
145  bool dragging )
146 {
147  double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
148 
149  return Hist2DProjImp::setBinWidth ( axis, new_width );
150 }
151 
152 void DyHist2DProjector::setOffset ( const std::string & axis,
153  int parm,
154  bool dragging )
155 {
156  Axes::Type at = Axes::convert ( axis );
157  if ( at != Axes::X && at != Axes::Y ) return;
158 
159  double new_offset = m_binner->calcOffset ( axis, parm, dragging );
160 
161  if( new_offset == 0.0 ) return; // no one cares
162  if( !dragging ) // reset
163  Hist2DProjImp::setOffset( at, 0.0 );
164  else
165  Hist2DProjImp::setOffset( at, new_offset );
166 
167  setDirty ( true );
168 }
169 
170 void
173  const Range & range,
174  bool const_width )
175 {
176  m_binner -> setRange ( axis, range, const_width );
177  checkScaling ();
178 
179  setDirty ( true );
180 }
181 
182 void
184 update ( const Observable * object )
185 {
186  const DataSource * datasource
187  = dynamic_cast < const DataSource * > ( object );
188 
189  if ( datasource != 0 ) {
190  NTupleProjector::update ( object );
191  }
192  else {
193  BinningProjector::update ( object );
194  }
195 }
196 
197 void
199 willDelete ( const Observable * object )
200 {
201  const DataSource * datasource
202  = dynamic_cast < const DataSource * > ( object );
203 
204  if ( datasource != 0 ) {
205  NTupleProjector::willDelete ( object );
206  }
207  else {
208  BinningProjector::willDelete ( object );
209  }
210 }
virtual void checkScaling()
Checks the axis scaling.
Range dataRangeOnValue() const
Returns the data range on the Z axis.
std::string m_z_label_density
The label of the z axis when displaying density.
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 willDelete(const Observable *object)
Implements Observer pattern.
hippodraw::AxisModelBase class interface
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.
virtual void setOffset(hippodraw::Axes::Type axis, double v)
Sets the bin offset.
Type
Axes constants.
Definition: AxesType.h:31
BinsBase * m_binner
The binner object.
virtual void willDelete(const Observable *)
Responds to willDelete message from the observed data source.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
Definition: DataSource.h:458
std::string m_z_label_entries
The label of the z axis when displaying number of entries per bin.
virtual double calcBinWidth(hippodraw::Axes::Type axis, int parm, bool dragging) const =0
Calculates a new bin width base on dragging slider value.
Namespace for HippoDraw.
Definition: AxesType.cxx:21
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)
Sets the Range of the binner.
const DataSource * m_ntuple
The pointer to the data source being projected.
double getPos(int column) const
Returns the minimum positive value on the specified column.
ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
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
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, int parm, bool dragging)
Sets the bin width.
DyHist2DProjector()
The default constructor.
A derived class of BinningProjector projects to a two dimensional histogram.
Definition: Hist2DProjImp.h:33
virtual void update(const Observable *)
Responds to update message from the data source.
intp size(numeric::array arr)
Definition: num_util.cpp:296
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
Range m_value_range
The range of the accumulated values.
Type convert(const std::string &axis)
Converts from string representation ot Axes::Type representation.
Definition: AxesType.cxx:32
DyHist2DProjector class implementation.
Expresses a range of values.
Definition: Range.h:33
virtual bool isAxisBinned(const std::string &axis) const
Returns true if the destined axis is "X" or "Y", otherwise returns false.
virtual Range dataRangeOn(hippodraw::Axes::Type) const
Returns the range of data on the specified axis.
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
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.
virtual Range valueRange() const
Finds the range of the projected values.
A derived class of Hist2DProjImp and NTupleProjector that reads two columns of data and projects them...
virtual void update(const Observable *object)
Updates the receiving projector.
virtual void changedNTuple()
This function is called when the ntuple has been changed to a new one.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double v)
This function sets the binWidth.
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
hippodraw::BinnerAxis class interface
void execute()
Projects the data source into bins.
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
virtual void setOffset(const std::string &axis, int parm, bool dragging)
Sets the bin offset.
virtual void update(const Observable *object)
Implements Observer pattern.
virtual void setRange(hippodraw::Axes::Type axis, bool)
Sets the range of the selected axis.
hippodraw::BinsBase class interface
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
virtual double calcOffset(const std::string &, int parm, bool dragging) const =0
Calculates and returns a new range from dragging slider.
std::vector< unsigned int > m_columns
A vector containing indexes to the columns of the DataSource.

Generated for HippoDraw Class Library by doxygen