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 <cassert>
29 #include <climits>
30 
31 using namespace hippodraw;
32 
33 using std::list;
34 using std::max;
35 using std::string;
36 using std::vector;
37 
39  : Hist2DProjImp (),
40  NTupleProjector ( 3 )
41 {
42  m_binding_options.push_back ( "X" );
43  m_binding_options.push_back ( "Y" );
44  m_binding_options.push_back ( "Weight (optional)" );
45  m_min_bindings = 2;
46 }
47 
53 DyHist2DProjector ( const DyHist2DProjector & projector )
54  : ProjectorBase ( projector ),
55  Hist2DProjImp ( projector ),
56  NTupleProjector ( projector ),
57  m_z_label_entries ( projector.m_z_label_entries ),
58  m_z_label_density ( projector.m_z_label_density ),
59  m_value_range( projector.m_value_range )
60 {
61 }
62 
64 {
65  return new DyHist2DProjector( *this );
66 }
67 
69 {
70  unsigned int cols = m_ntuple->columns () - 1;
71  if ( m_columns[0] > cols ) m_columns[0] = cols;
72  if ( m_columns[1] > cols ) m_columns[1] = cols;
73 
74  m_binner->setDirty();
75 }
76 
78 {
79  unsigned int x_col = m_columns[0];
80  unsigned int y_col = m_columns[1];
81  unsigned int w_col = m_columns[2];
82 
83  bool have_weight = w_col < UINT_MAX;
84 
85  // Use integer indexing to ensure that it will take everything from the
86  // same row, including the cut values.
87 
88  m_binner->reset();
89  unsigned int size = m_ntuple -> rows ();
90  for ( unsigned int i = 0; i < size; i++ )
91  {
92  if ( acceptRow ( i, m_cut_list ) == false ) continue;
93 
94  double x = m_ntuple -> valueAt ( i, x_col );
95  double y = m_ntuple -> valueAt ( i, y_col );
96  double w = 1.0;
97  if ( have_weight ) {
98  w = m_ntuple -> valueAt ( i, w_col );
99  }
100  m_binner->accumulate( x, y, w );
101  }
102 }
103 
104 /* virtual */
105 bool DyHist2DProjector::isAxisBinned ( const std::string & axis ) const
106 {
107  if ( axis == m_binding_options[0]
108  || axis == m_binding_options[1] ) return true;
109  return false;
110 }
111 
112 Range
115 {
116  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
117  if ( axis == Axes::X ) {
118  return dataRange ( m_columns[0] );
119  } else if ( axis == Axes::Y ) {
120  return dataRange ( m_columns[1] );
121  } else {
122  return dataRangeOnValue ();
123  }
124 }
125 
126 double
129 {
130  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
131  if ( axis == Axes::X ) {
132  return getPos ( m_columns[0] );
133  } else if( axis == Axes::Y ) {
134  return getPos ( m_columns[1] );
135  } else {
136  return valueRange().pos();
137  }
138 }
139 
140 const Range &
143  int parm,
144  bool dragging )
145 {
146  double new_width = m_binner->calcBinWidth ( axis, parm, dragging );
147 
148  return Hist2DProjImp::setBinWidth ( axis, new_width );
149 }
150 
151 void DyHist2DProjector::setOffset ( const std::string & axis,
152  int parm,
153  bool dragging )
154 {
155  Axes::Type at = Axes::convert ( axis );
156  if ( at != Axes::X && at != Axes::Y ) return;
157 
158  double new_offset = m_binner->calcOffset ( axis, parm, dragging );
159 
160  if( new_offset == 0.0 ) return; // no one cares
161  if( !dragging ) // reset
162  Hist2DProjImp::setOffset( at, 0.0 );
163  else
164  Hist2DProjImp::setOffset( at, new_offset );
165 
166  setDirty ( true );
167 }
168 
169 void
172  const Range & range,
173  bool const_width )
174 {
175  m_binner -> setRange ( axis, range, const_width );
176  checkScaling ();
177 
178  setDirty ( true );
179 }
180 
181 void
183 update ( const Observable * object )
184 {
185  const DataSource * datasource
186  = dynamic_cast < const DataSource * > ( object );
187 
188  if ( datasource != 0 ) {
189  NTupleProjector::update ( object );
190  }
191  else {
192  BinningProjector::update ( object );
193  }
194 }
195 
196 void
198 willDelete ( const Observable * object )
199 {
200  const DataSource * datasource
201  = dynamic_cast < const DataSource * > ( object );
202 
203  if ( datasource != 0 ) {
204  NTupleProjector::willDelete ( object );
205  }
206  else {
207  BinningProjector::willDelete ( object );
208  }
209 }

Generated for HippoDraw Class Library by doxygen