Profile2DProjector.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 "Profile2DProjector.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 <cassert>
30 
31 using namespace hippodraw;
32 
33 using std::list;
34 using std::max;
35 using std::string;
36 using std::vector;
37 
39  : BinningProjector ( 2 ),
40  NTupleProjector ( 4 )
41 {
42  m_binding_options.push_back ( "X" );
43  m_binding_options.push_back ( "Y" );
44  m_binding_options.push_back ( "Z" );
45  m_min_bindings = 3;
46 
48  BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
49  BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
50 
51  BinsFactory * factory = BinsFactory::instance();
52  m_binner = factory->create ( "Bins2DProfile" );
53 
56  addPointReps();
57 }
58 
65  : ProjectorBase ( projector ),
66  BinningProjector ( projector ),
67  NTupleProjector ( projector ),
68  m_value_range( projector.m_value_range )
69 {
70  addPointReps();
71 }
72 
74 {
75  return new Profile2DProjector( *this );
76 }
77 
79 {
80  unsigned int cols = m_ntuple->columns () - 1;
81  if ( m_columns[0] > cols ) m_columns[0] = cols;
82  if ( m_columns[1] > cols ) m_columns[1] = cols;
83  if ( m_columns[2] > cols ) m_columns[2] = cols;
84 
85  m_binner->setDirty();
86 }
87 
90 {
91  if ( m_ntuple->isNull () ) return;
92  unsigned int ix = m_columns[0];
93  unsigned int iy = m_columns[1];
94  unsigned int iz = m_columns[2];
95  unsigned int iw = m_columns[3];
96  bool have_weight = false;
97 // bool iw = m_weight >= 0;
98 // if ( have_weight ) {
99 // weight = &(m_ntuple->operator [] ( m_weight ) );
100 // }
101 
102  // Use integer indexing to ensure that it will take everything from the
103  // same row, including the cut values.
104 
105  m_binner->reset();
106  unsigned int size = m_ntuple -> rows ();
107  for ( unsigned int i = 0; i < size; i++ )
108  {
109  if ( acceptRow ( i, m_cut_list ) == false ) continue;
110 
111  double x = m_ntuple -> valueAt ( i, ix );
112  double y = m_ntuple -> valueAt ( i, iy );
113  double z = m_ntuple -> valueAt ( i, iz );
114 
115  double w = 1.0;
116  if ( have_weight ) {
117  w = m_ntuple -> valueAt ( i, iw );
118  }
119  m_binner->accumulate( x, y, z, w );
120  }
121 }
122 
123 /* virtual */
124 bool Profile2DProjector::isAxisBinned ( const std::string & axis ) const
125 {
126  if ( axis == m_binding_options[0]
127  || axis == m_binding_options[1] ) return true;
128  return false;
129 }
130 
132 {
133  if ( isDirty () ) {
134  // Work around const.
135  Profile2DProjector * p = const_cast <Profile2DProjector *> ( this );
136  p->prepareValues ();
137  }
138 
139  return dataRangeOn ( Axes::Z );
140 }
141 
142 namespace dp = hippodraw::DataPoint3DTuple;
143 
144 Range
147 {
148  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
149  if ( axis == Axes::X ) {
150  return dataRange ( m_columns[0] );
151  }
152  if ( axis == Axes::Y ) {
153  return dataRange ( m_columns[1] );
154  }
155  // else axis == Z )
156  if ( isDirty () ) {
157  Profile2DProjector * p = const_cast < Profile2DProjector * > ( this );
158  p ->prepareValues ();
159  p -> setDirty ( false );
160  }
161  const vector < double > & values = m_proj_values -> getColumn ( dp::Z );
162 
163  return Range ( values );
164 }
165 
168 double
171 {
172  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
173  if ( axis == Axes::X ) {
174  return getPos ( m_columns[0] );
175  }
176  if ( axis == Axes::Y ) {
177  return getPos ( m_columns[1] );
178  }
179  if ( axis == Axes::Z ) {
180  return getPos ( m_columns[2] );
181  }
182  return DBL_MAX;
183 }
184 
186 void
188 setRange ( hippodraw::Axes::Type axis, bool const_width )
189 {
190  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
191 
192  AxisModelBase * model = 0;
193  if ( axis == Axes::X ) {
194  model = m_x_axis;
195  } else if ( axis == Axes::Y ) {
196  model = m_y_axis;
197  }
198 
199  if ( axis != Axes::Z ) {
200  const Range & range = model->getRange (false);
201  if( model->isLog() ) {
202  if ( range.low() < 0.0 ) return;
203  model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
204  const Range & range2 = model->getRange ( false );
205  setBinnerRange ( axis, range2, const_width );
206  } else {
207  setBinnerRange ( axis, range, const_width );
208  }
209  }
210 
211  setDirty ( true );
212 }
213 
215 const Range &
217 setBinWidth ( hippodraw::Axes::Type axis, double width )
218 {
219  assert ( axis == Axes::X || axis == Axes::Y );
220 
221  const Range & range = m_binner->setBinWidth ( axis, width );
222 
223  setDirty ( true );
224 
225  return range;
226 }
227 
231 // void
232 const Range &
235  int parm,
236  bool dragging )
237 {
238  double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
239 
240  return setBinWidth ( axis, new_width );
241 }
242 
247 void Profile2DProjector::setOffset ( const std::string & axis,
248  int parm,
249  bool dragging )
250 {
251  if ( ( axis == "X" || axis == "Y" ) == false ) return;
252 
253  double new_offset = m_binner->calcOffset ( axis, parm, dragging );
254 
255  Axes::Type at;
256  if ( axis == "X" ) {
257  at = Axes::X;
258  }
259  else { // "Y"
260  at = Axes::Y;
261  }
262 
263  if( new_offset == 0.0 ) return; // no one cares
264  if( !dragging ) // reset
265  setOffset( at, 0.0 );
266  else
267  setOffset( at, new_offset );
268 
269  setDirty ( true );
270 }
271 
272 /* virtual */
273 void
275 setOffset ( hippodraw::Axes::Type axis, double offset )
276 {
277  if( axis == Axes::Z ) return;
278  assert ( axis == Axes::X || axis == Axes::Y );
279 
280  m_binner->setOffset ( axis, offset );
281  if( axis == Axes::X )
282  m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
283  else
284  m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
285 
286  setDirty ( true );
287 }
288 
289 const string & Profile2DProjector::getZLabel() const
290 {
291  return m_ntuple->getLabelAt( m_columns[2] );
292 }
293 
295 {
296  m_pointreps.push_back ( "ColorBox" );
297  m_pointreps.push_back ( "Contour" );
298 }
299 
300 void
303  const Range & range, bool const_width )
304 {
305  m_binner -> setRange ( axis, range, const_width );
306  checkScaling ();
307 
308  setDirty ( true );
309 }
310 
311 void
313 update ( const Observable * object )
314 {
315  const DataSource * datasource
316  = dynamic_cast < const DataSource * > ( object );
317 
318  if ( datasource != 0 ) {
319  NTupleProjector::update ( object );
320  }
321  else {
322  BinningProjector::update ( object );
323  }
324 }
325 
326 void
328 willDelete ( const Observable * object )
329 {
330  const DataSource * datasource
331  = dynamic_cast < const DataSource * > ( object );
332 
333  if ( datasource != 0 ) {
334  NTupleProjector::willDelete ( object );
335  }
336  else {
337  BinningProjector::willDelete ( object );
338  }
339 }
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
Range m_value_range
The range of the accumulated values.
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
Profile2DProjector()
The default constructor.
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...
void execute()
Projects the data source into bins.
unsigned int m_min_bindings
The minimum number of columns that must be bound.
A derived class of BinningProjector that reads three columns of data and projects them to a two dimen...
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
Definition: Observable.h:39
virtual const std::string & getLabelAt(unsigned int index) const
Returns the label for the column at index index.
Definition: DataSource.cxx:179
virtual Range valueRange() const
Finds the range of the projected values.
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
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
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.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
virtual void setRange(hippodraw::Axes::Type axis, bool)
const std::string & getZLabel() const
Returns the label (title) of the z axis.
unsigned int columns() const
Returns the number of columns or data arrays available from this DataSource.
Definition: DataSource.h:458
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
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.
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.
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
hippodraw::NTuple class interface.
Base class for DataSource.
Definition: DataSource.h:55
virtual bool isAxisBinned(const std::string &axis) const
Returns true if the destined axis is "X" or "Y", otherwise returns false.
static BinnerAxisFactory * instance()
Returns a pointer to the singleton instance.
virtual void setOffset(const std::string &axis, int parm, bool dragging)
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
Profile2DProjector class interface.
virtual void setOffset(hippodraw::Axes::Type axis, double value)=0
Sets the offset parameter on the specified axis.
virtual void changedNTuple()
This function is called when the ntuple has been changed to a new one.
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
virtual Range dataRangeOn(hippodraw::Axes::Type) const
Returns the range of data on the specified axis.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
virtual double getPosOn(hippodraw::Axes::Type axis) const
Returns the minimum positive value of the data on a specified axis.
virtual void setBinnerRange(hippodraw::Axes::Type axis, const Range &range, bool const_width)
Sets the Range of the binner.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double value)=0
Sets the bin width parameter on the specified axis.
virtual void addPointReps()
Function to add the acceptable point reps.
static BinsFactory * instance()
Returns a pointer to the singleton instance.
Definition: BinsFactory.cxx:33
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)
Implements Observer pattern.
bool isDirty() const
Returns true if the projector has been marked dirty.
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.
A namespace to set the standard for indexing into 3 dimension data point tuple.
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
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
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.
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.
virtual void willDelete(const Observable *object)
Implements Observer pattern.

Generated for HippoDraw Class Library by doxygen