BinningProjector.cxx
Go to the documentation of this file.
1 
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "BinningProjector.h"
18 
19 #include "axes/AxisModelBase.h"
20 #include "binners/BinsBase.h"
21 #include "datasrcs/NTuple.h"
22 
23 #include <cassert>
24 
25 #ifdef ITERATOR_MEMBER_DEFECT
26 using namespace std;
27 #else
28 using std::string;
29 using std::list;
30 using std::vector;
31 #endif
32 
33 using namespace hippodraw;
34 
35 BinningProjector::BinningProjector ( unsigned int axes )
36  : m_binner_dim ( axes ),
37  m_binner ( 0 )
38 {
39 }
40 
42  : ProjectorBase ( projector ),
43  m_binner_dim ( projector.m_binner_dim ),
44  m_binner ( 0 )
45 {
46  if ( projector.m_binner != 0 ) {
47  m_binner = projector.m_binner->clone ();
50  }
51 }
52 
54 {
55  if ( m_binner != 0 ) {
56  delete m_binner;
57  }
58 }
59 
60 void
63 {
64  ProjectorBase::setAxisModel ( axis, model );
65  checkScaling ();
66 }
67 
69 {
70  bool is_dirty = isDirty();
71  if ( is_dirty ) {
72  execute();
74  setDirty ( false );
75  }
76 }
77 
78 const BinsBase *
80 getBinner ( ) const
81 {
82  return m_binner;
83 }
84 
85 void
87 setBinner ( BinsBase * bins )
88 {
89  if ( m_binner != 0 ) delete m_binner;
90  m_binner = bins;
91  if ( m_proj_values != 0 ) delete m_proj_values;
93 }
94 
95 void
99 {
100  string axis;
101  if ( type == Axes::X ) axis = "X";
102  else if ( type == Axes::Y ) axis = "Y";
103  else axis = "Z";
104 
105  bool yes = isAxisBinned ( axis );
106  if ( ! yes ) return;
107 
108  m_binner->setBinnerOn ( binner, type );
109  checkScaling ();
110 
111  setDirty ( true );
112 }
113 
114 int
117 {
118  assert ( m_binner );
119 
120  if ( axis == Axes::X ||
121  ( m_binner_dim == 2 && axis == Axes::Y ) ) {
122  return m_binner->numberOfBins ( axis );
123  }
124 
125  return ProjectorBase::getNumberOfBins ( axis );
126 }
127 
132 const Range &
134 setBinWidth ( hippodraw::Axes::Type axis, double width )
135 {
136  assert ( axis == Axes::X && width > 0. );
137 
138  const Range & range = m_binner->setBinWidth ( Axes::X, width );
139  checkScaling ();
140 
141  setDirty ( true );
142 
143  return range;
144 }
145 
146 const Range &
149  int parm,
150  bool dragging )
151 {
152  double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
153 
154  return setBinWidth ( axis, new_width );
155 }
156 
157 void BinningProjector::setOffset ( const std::string & axis,
158  int parm,
159  bool dragging )
160 {
161  if ( axis != "X" ) return;
162 
163  double new_offset = m_binner->calcOffset ( axis, parm, dragging );
164  setOffset ( Axes::X, new_offset );
165 
166  setDirty ( true );
167 }
168 
169 void
171 setOffset ( hippodraw::Axes::Type axis, double offset )
172 {
173  if ( axis == Axes::Y ) return;
174 
175  m_binner->setOffset ( Axes::X, offset );
176  m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
177 
178  setDirty ( true );
179 }
180 
181 
183 {
184 }
185 
186 double
189 {
190  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
191 
192  if ( axis == Axes::X ||
193  ( axis == Axes::Y && m_binner_dim == 2 ) ) {
194  return m_binner->getOffset ( axis );
195  }
196 
197  // else Z
198  return 0.0;
199 }
200 
201 double
204 {
205  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
206 
207  if ( axis == Axes::X ||
208  ( axis == Axes::Y && m_binner_dim == 2 ) ) {
209  return m_binner->binWidth ( axis );
210  }
211 
212  // else Z
213  return 0.0;
214 }
215 
218 {
219 }
220 
222 {
223  // does nothing
224 }
225 
226 double BinningProjector::getZValue ( double x, double y ) const
227 {
228  return m_binner->getZValue ( x, y );
229 }
230 
231 DataSource *
233 createNTuple () const
234 {
235  return m_binner->createNTuple ();
236 }
237 
238 void
240 fillDataSource ( DataSource * ntuple, bool ) const
241 {
242  m_binner -> fillDataSource ( ntuple );
243 }
244 
245 void
247 normalizeTo ( double number )
248 {
249  m_binner -> scaleNumberOfEntries ( number );
250 }
251 
252 void
254 setNormalizing ( bool on )
255 {
256  m_binner -> setEntriesScaling ( on );
257 }
258 
261 void
263 normalizeTo ( const ProjectorBase * target )
264 {
265  if ( target != 0 ) {
266  if ( target -> isValueBinned ( ) ) {
267  m_target = target;
268  ProjectorBase * t = const_cast < ProjectorBase * > ( target );
269  t -> addObserver ( this );
270  setNormalizing ( true );
271  normalize ();
272  }
273  }
274  else {
275  if ( m_target != 0 ) {
276  ProjectorBase * t = const_cast < ProjectorBase * > ( m_target );
277  t -> removeObserver ( this );
278  setNormalizing ( false );
279  }
280  m_target = 0;
281  }
282 }
283 
284 void
287 {
288  int number = m_target ->getNumberOfEntries ();
289  double norm = number;
290  normalizeTo ( norm );
291 
292  setDirty ( true );
293 }
294 
295 void
297 update ( const Observable * object )
298 {
299  if ( object == m_target ) {
300  normalize ();
301  }
302 
303  else notifyObservers ();
304 }
305 
306 void
308 willDelete ( const Observable * object )
309 {
310  if ( object == m_target ) {
311  m_target = 0;
312  setNormalizing ( false );
313  setDirty ( true );
314  }
315 }
316 
317 void
319 setBinContents ( const DataSource * source )
320 {
321  m_binner -> setBinContents ( source );
322 }
323 
324 void
326 setMinEntries ( int entries )
327 {
328  m_binner -> setMinEntries ( entries );
329  setDirty ( true );
330 }
331 
332 int
335 {
336  return m_binner -> getMinEntries ();
337 }
338 
339 bool
342 {
343  return m_binner_dim == 2 &&
344  m_binner -> hasEqualWidths();
345 }
virtual void reset()
Resets the bins.
virtual double getOffset(hippodraw::Axes::Type axis) const =0
Returns the offset parameter on specific axis.
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
virtual void update(const Observable *object)
Updates the receiving projector.
virtual int getNumberOfEntries() const =0
Returns the total number of entries that went into creating the projected values. ...
The base class for the binner hierarchy.
Definition: BinsBase.h:33
void setBinContents(const DataSource *source)
Sets the contents of the bins from the data source.
virtual void setOffset(hippodraw::Axes::Type axis, double value)=0
Sets the offset parameter on the specified axis.
The base class for the BinnerAxis hierarchy.
Definition: BinnerAxis.h:35
virtual bool isValueBinned() const
Returns true if the projected values are the result of binning.
BinsBase * m_binner
The binner object.
virtual void normalize()
Normalizes the projector to its target.
virtual void normalizeTo(double number)
Sets a scale factor on the output so that the number of entries appears to be number.
The BinningProjector is an abstract class provides most of the functionality for a projector that doe...
virtual double binWidth(hippodraw::Axes::Type axis) const =0
Returns the bin width parameter on the specified axis.
virtual int getNumberOfBins(Axes::Type) const
Returns the number of bins.
hippodraw::AxisModelBase class interface
virtual void setBinnerOn(BinnerAxis *binner, hippodraw::Axes::Type axis)
Sets the bin edge calculator to binner on axis axis.
virtual NTuple * createNTuple() const =0
Creates an NTuple.
virtual void setNormalizing(bool on)
Sets the scaling number of entries on if on is true, otherwise turns if off.
virtual double calcBinWidth(hippodraw::Axes::Type axis, int parm, bool dragging) const =0
Calculates a new bin width base on dragging slider value.
virtual void setAxisModel(hippodraw::Axes::Type, AxisModelBase *)
Sets the AxisModel for axis axis.
virtual void notifyObservers() const
Notifies Observer objects of a change.
Definition: Observable.cxx:93
unsigned int m_binner_dim
The number of AxesType accepted by the binner.
virtual void prepareValues()
Prepares the projector for plotting by executing, if needed, the binning procedure.
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
virtual void setDirty(bool value=true)
Sets the dirty flag to value.
virtual void setOffset(const std::string &axis, int parm, bool dragging)
Sets the bin offset.
virtual void willDelete(const Observable *object)
If object is the target of normalization, removes the target and sets normalization off...
virtual bool isAxisBinned(const std::string &axis) const
Returns true if specified axis is binned.
virtual void setMinEntries(int entries)
Set the minimum entries/bin.
virtual BinsBase * clone() const =0
The virtual function to make copy of concrete derived class.
void removeObserver(Observer *)
Removes an Observer from the Observer list.
Definition: Observable.cxx:66
virtual void fillDataSource(DataSource *ntuple, bool in_range=false) const
void setBinner(BinsBase *bins)
Sets the BinsBase object to be used by this projector.
virtual ~BinningProjector()
The destructor.
virtual int numberOfBins(hippodraw::Axes::Type axis) const =0
Returns the number of bins on specified axis.
hippodraw::NTuple class interface.
virtual void setAxisModel(Axes::Type axis, AxisModelBase *)
Sets the AxisModel for axis axis.
BinningProjector(unsigned int axes)
The following constructor takes the number of axes used by the BinsBase object.
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
Namespace for HippoDraw.
Definition: AxesType.cxx:21
Type
Axes constants.
Definition: AxesType.h:31
hippodraw::BinsBase class interface
virtual int getNumberOfBins(hippodraw::Axes::Type axis) const
Returns the number of bins.
Base class for DataSource.
Definition: DataSource.h:55
Part of an implementation of the Observable-Observer pattern based on the example in the GOF Patterns...
Definition: Observable.h:39
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
double getBinWidth(hippodraw::Axes::Type axis) const
Returns the bin width of the axis.
virtual double getZValue(double x, double y) const
Get the z value at the specified point (x,y).
Definition: BinsBase.cxx:74
virtual const Range & getRange(hippodraw::Axes::Type axis)=0
virtual void execute()
Provides the all the data to the binner.
double getOffset(hippodraw::Axes::Type axis) const
Returns the offset of the axis.
double norm(const std::vector< double > &a)
Computes the two norm of the vector.
Definition: NumLinAlg.cxx:285
virtual bool isImageConvertable() const
Returns true if projected values are convertable to image.
void addObserver(Observer *)
Adds an Observer to the Observer list.
Definition: Observable.cxx:52
hippodraw::BinningProjector class interface
virtual int getMinEntries()
Get the minimum entries/bin.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double value)=0
Sets the bin width parameter on the specified axis.
STL namespace.
virtual const Range & setBinWidth(hippodraw::Axes::Type axis, double width)
virtual double getZValue(double x, double y) const
Get the z value at the specified point (x,y).
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
virtual void checkScaling()
Checks and sets if an AxisModelBase object on an axis should be scaled.
virtual double calcOffset(const std::string &, int parm, bool dragging) const =0
Calculates and returns a new range from dragging slider.
virtual void setBinnerOn(BinnerAxis *, hippodraw::Axes::Type axis)=0
Sets the bin calculator on specified axis.
virtual DataSource * createNTuple() const
Returns an data source representing the binned values.
const BinsBase * getBinner() const
Returns reference to BinsBase object used by this projector.
bool isDirty() const
Returns true if the projector has been marked dirty.
Expresses a range of values.
Definition: Range.h:33
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
const ProjectorBase * m_target
The target projector.

Generated for HippoDraw Class Library by doxygen