ProfileProjector.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
16 
17 #include "ProfileProjector.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 <algorithm>
30 #include <climits>
31 
32 #include <cassert>
33 
34 using namespace hippodraw;
35 
36 #include <stdio.h>
37 
38 #ifdef ITERATOR_MEMBER_DEFECT
39 using namespace std;
40 #else
41 using std::list;
42 using std::max;
43 using std::string;
44 using std::vector;
45 #endif
46 
48  : BinningProjector ( 1 ),
49  NTupleProjector ( 3 )
50 {
51  m_binding_options.push_back ( "X" );
52  m_binding_options.push_back ( "Y" );
53  m_binding_options.push_back ( "Weight (optional)" );
54  m_min_bindings = 2;
55 
56  BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
57  BinnerAxis * binner = binner_factory -> create ( "BinnerLinear" );
58 
59  BinsFactory * factory = BinsFactory::instance();
60  m_binner = factory -> create ( "Bins1DProfile" );
61 
62  m_binner->setBinnerOn ( binner, Axes::X );
63  addPointReps();
64 }
65 
71 ProfileProjector ( const ProfileProjector & projector )
72  : ProjectorBase ( projector ),
73  BinningProjector ( projector ),
74  NTupleProjector ( projector )
75 {
76  addPointReps();
77 }
78 
80 {
81  return new ProfileProjector( *this );
82 }
83 
86 {
87  unsigned int cols = m_ntuple->columns () - 1;
88  if ( m_columns[0] > cols ) m_columns[0] = cols;
89  if ( m_columns[1] > cols ) m_columns[1] = cols;
90  if ( m_columns[2] > cols ) m_columns[2] = cols;
91 
92  m_binner->setDirty ( );
93 }
94 
96 {
97  if ( m_ntuple->isNull () ) return;
98 
99  // Get the data and the optional weight column.
100  unsigned int & x_col = m_columns[0];
101  unsigned int & y_col = m_columns[1];
102  unsigned int & w_col = m_columns[2];
103  unsigned int size = m_ntuple -> rows ();
104 
105  bool have_weight = w_col < UINT_MAX;
106 
107  // Use integer indexing to ensure that it will take everything from the
108  // same row, including the cut values.
109 
110  m_binner->reset ();
111 
112  for ( unsigned int i = 0; i < size; i++ )
113  {
114  if ( acceptRow ( i, m_cut_list ) == false ) continue;
115 
116  double x = m_ntuple -> valueAt ( i, x_col );
117  double y = m_ntuple -> valueAt ( i, y_col );
118  double w = 1.0;
119  if ( have_weight) {
120  w = m_ntuple -> valueAt ( i, w_col );
121  }
122  m_binner->accumulate( x, y, w );
123  }
124 }
125 
127 {
128  return dataRangeOn ( Axes::Y );
129 }
130 
131 namespace dp = hippodraw::DataPoint2DTuple;
132 
133 Range
136 {
137  assert ( axis == Axes::X || axis == Axes::Y );
138 
139  if ( axis == Axes::X ) {
140  return dataRange ( m_columns[0] );
141  }
142 
143  ProfileProjector * p = const_cast<ProfileProjector *> ( this );
144  p->prepareValues ();
145 
146  // If no points are left due to cuts, then returns zero range.
147  if ( m_proj_values -> empty () ) {
148  return Range ( 0.0, 0.0 );
149  }
150  double max = DBL_MIN;
151  double min = DBL_MAX;
152 
153  const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
154  const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
155  for ( unsigned int i = 0; i < values.size(); i++ ) {
156  double hi = values[i] + errors[i];
157  double lo = values[i] - errors[i];
158  max = std::max ( max, hi );
159  min = std::min ( min, lo );
160  }
161 
162  return Range ( min, max );
163 }
164 
165 double
168 {
169  assert ( axis == Axes::X || axis == Axes::Y );
170 
171  if ( axis == Axes::X ) {
172  return getPos ( m_columns[0] );
173  }
174 
175  // If no points are left due to cuts, then returns DBL_MAX.
176  if ( m_proj_values -> empty() ) {
177  return DBL_MAX;
178  }
179 
180  double pos = DBL_MAX;
181 
182  const vector < double > & values = m_proj_values -> getColumn ( dp::Y );
183  const vector < double > & errors = m_proj_values -> getColumn ( dp::YERR );
184  for ( unsigned int i = 0; i < values.size (); i++ ) {
185  double lo = values[i] - errors[i];
186  if ( lo > 0.0 &&
187  lo < pos ) pos = lo;
188  }
189 
190  return pos;
191 }
192 
193 /* virtual */
194 bool ProfileProjector::isAxisBinned ( const std::string & axis ) const
195 {
196  if ( axis == m_binding_options[0] ) {
197  return true;
198  }
199  return false;
200 }
201 
203 {
204  m_pointreps.push_back ( "Symbol" );
205 }
206 
207 void
209 setRange ( hippodraw::Axes::Type axis, bool const_width )
210 {
211  assert ( m_binner );
212  assert ( axis == Axes::X || axis == Axes::Y );
213 
214  if ( axis == Axes::X ) {
215  const Range & range = m_x_axis->getRange( false );
216  if( m_x_axis->isLog() ) {
217  if( range.low() < 0.0 ) return;
218  m_x_axis->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
219  const Range & range2 = m_x_axis->getRange( false );
220  setBinnerRange ( axis, range2, const_width );
221  }
222  else {
223  setBinnerRange ( axis, range, const_width );
224 
225  }
226  }
227 }
228 
229 void
232  const Range & range,
233  bool const_width )
234 {
235  m_binner -> setRange ( axis, range, const_width );
236  checkScaling ();
237 
238  setDirty ( true );
239 }
240 
241 void
243 update ( const Observable * object )
244 {
245  const DataSource * datasource
246  = dynamic_cast < const DataSource * > ( object );
247 
248  if ( datasource != 0 ) {
249  NTupleProjector::update ( object );
250  }
251  else {
252  BinningProjector::update ( object );
253  }
254 }
255 
256 void
258 willDelete ( const Observable * object )
259 {
260  const DataSource * datasource
261  = dynamic_cast < const DataSource * > ( object );
262 
263  if ( datasource != 0 ) {
264  NTupleProjector::willDelete ( object );
265  }
266  else {
267  BinningProjector::willDelete ( object );
268  }
269 }

Generated for HippoDraw Class Library by doxygen