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 }

Generated for HippoDraw Class Library by doxygen