Hist2DProjImp.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // for max() and min() missing from Microsoft Visual C++.
14 #include "msdevstudio/MSconfig.h"
15 #endif //_MSC_VER
16 
17 #include "Hist2DProjImp.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 std::list;
32 using std::max;
33 using std::string;
34 using std::vector;
35 
36 namespace hippodraw {
37 
39  : BinningProjector ( 2 )
40 {
41  BinnerAxisFactory * binner_factory = BinnerAxisFactory::instance ();
42  BinnerAxis * x = binner_factory -> create ( "BinnerLinear" );
43  BinnerAxis * y = binner_factory -> create ( "BinnerLinear" );
44 
45  BinsFactory * factory = BinsFactory::instance ();
46  m_binner = factory->create ( "Bins2DHist" );
47 
50 
51  m_z_label_entries = "Entries / bin";
52  m_z_label_density = "Density";
53 
54  addPointReps();
55 }
56 
62 Hist2DProjImp ( const Hist2DProjImp & projector )
63  : ProjectorBase ( projector ),
64  BinningProjector ( projector ),
65  m_z_label_entries ( projector.m_z_label_entries ),
66  m_z_label_density ( projector.m_z_label_density ),
67  m_value_range( projector.m_value_range )
68 {
69  addPointReps();
70 }
71 
76 {
77 }
78 
80 {
81  return true;
82 }
83 
84 double
86 getPosOnValue () const
87 {
88  Range range = dataRangeOnValue ();
89 
90  return range.pos ();
91 }
92 
93 
94 Range
97 {
98  Range range = dataRangeOn ( axis );
99  if ( axis == Axes::Z ) {
100  range.setLow ( 0.0 );
101  }
102 
103  return range;
104 }
105 
106 namespace dp = hippodraw::DataPoint3DTuple;
107 
108 Range
111 {
112  Hist2DProjImp * p = const_cast < Hist2DProjImp * > ( this );
113  p->prepareValues ();
114  if ( m_proj_values -> empty () ) {
115  return Range ( 0.0, 1.0, 0.5 );
116  }
117 
118  const vector < double > & values = m_proj_values -> getColumn( dp::Z );
119  return Range ( values );
120 }
121 
123 {
124  return dataRangeOn ( Axes::Z );
125 }
126 
128 void
130 setRange ( hippodraw::Axes::Type axis, bool const_width )
131 {
132  assert ( axis == Axes::X || axis == Axes::Y || axis == Axes::Z );
133 
134  AxisModelBase * model = 0;
135  if ( axis == Axes::X ) {
136  model = m_x_axis;
137  } else if ( axis == Axes::Y ) {
138  model = m_y_axis;
139  }
140  if ( axis != Axes::Z ) {
141  const Range & range = model->getRange (false);
142  if( model->isLog() ) {
143  if( range.low() < 0.0 ) return;
144  model->setRange ( range.low(), range.high(), getPosOn ( Axes::X ) );
145  const Range & range2 = model->getRange ( false );
146  setBinnerRange ( axis, range2, const_width );
147  } else {
148  setBinnerRange ( axis, range, const_width );
149  }
150  }
151 }
152 
153 const Range &
155 setBinWidth ( hippodraw::Axes::Type axis, double width )
156 {
157  assert ( axis == Axes::X || axis == Axes::Y );
158 
159  const Range & range = m_binner->setBinWidth ( axis, width );
160  checkScaling ();
161 
162  setDirty ( true );
163 
164  return range;
165 }
166 
167 void
169 setOffset ( hippodraw::Axes::Type axis, double offset )
170 {
171  if ( axis == Axes::Z ) return;
172  assert ( axis == Axes::X || axis == Axes::Y );
173 
174  m_binner->setOffset ( axis, offset );
175  if( axis == Axes::X )
176  m_x_axis->setRange( m_binner->getRange ( Axes::X ), true );
177  else
178  m_y_axis->setRange( m_binner->getRange ( Axes::Y ), true );
179 
180  setDirty ( true );
181 }
182 
183 
185 {
186  m_z_label_entries = "Entries / bin";
187 }
188 
189 const string & Hist2DProjImp::getZLabel() const
190 {
191  bool scaling = m_z_axis->isScaling ();
192 
193  if ( scaling ) return m_z_label_entries;
194  return m_z_label_density;
195 }
196 
198 {
199  return true;
200 }
201 
203 {
204  if ( m_z_axis == 0 ) return;
205 
206  bool yes = m_binner->hasEqualWidths ();
207 
208  if ( yes ) {
209  double width = m_binner->scaleFactor ();
210  m_z_axis->setScaleFactor ( width );
211  }
212  else {
213  m_z_axis->setScaling ( false );
214  }
215 
216 }
217 
219 {
220  m_pointreps.push_back ( "ColorBox" );
221  m_pointreps.push_back ( "Contour" );
222  //m_pointreps.push_back ( "ColorSymbol" );
223 }
224 
225 bool
227 wantsScaleFactor ( const std::string & axis ) const
228 {
229  return axis == "Z" || axis == "z";
230 }
231 
232 } // namespace hippodraw
233 

Generated for HippoDraw Class Library by doxygen