LineProjector.cxx
Go to the documentation of this file.
1 
12 #include "LineProjector.h"
13 
14 #include "axes/AxisModelBase.h"
15 #include "datasrcs/NTuple.h"
16 
17 using namespace hippodraw;
18 
19 using std::string;
20 using std::vector;
21 
23 LineProjector ( hippodraw::Axes::Type axis, double value )
24  : m_value ( value ),
25  m_axis ( axis )
26 {
27 }
28 
30 LineProjector ( const LineProjector & projector )
31  : ProjectorBase ( projector ),
32  m_value ( projector.m_value ),
33  m_axis ( projector.m_axis )
34 {
35 }
36 
38 {
39  // nothing to be done
40 }
41 
43 {
44  return new LineProjector ( *this );
45 }
46 
47 void
50 {
51 }
52 bool
54 isEmpty () const
55 {
56  return false;
57 }
58 
59 Range
62 {
63  Range range;
64  if ( m_axis == Axes::X ) {
65  if ( axis == Axes::X ) {
66  range.setRange ( m_value, m_value, m_value );
67  }
68  else if ( axis == Axes::Y ) {
69  range = m_y_axis -> getRange ( false );
70  }
71  }
72  else if ( m_axis == Axes::Y ) {
73  if ( axis == Axes::X ) {
74  range = m_x_axis -> getRange ( false );
75  }
76  else if ( axis == Axes::Y ) {
77  range.setRange ( m_value, m_value, m_value );
78  }
79  }
80 
81  return range;
82 }
83 
84 const std::string &
86 getTitle() const
87 {
88  return m_title;
89 }
90 
91 Range
93 valueRange () const
94 {
95  Range range;
96  if ( m_axis == Axes::X ) {
97  range = m_y_axis -> getRange ( false );
98  }
99  else {
100  range = m_x_axis -> getRange ( false );
101  }
102 
103  return range;
104 }
105 
106 double
109 {
110  double pos = DBL_MIN;
111  if ( m_axis == Axes::X ) {
112  if ( axis == Axes::X ) {
113  pos = std::max ( pos, m_value );
114  }
115  else if ( axis == Axes::Y ) {
116  const Range & range = m_y_axis -> getRange ( false );
117  pos = range.pos();
118  }
119  }
120  else if ( m_axis == Axes::Y ) {
121  if ( axis == Axes::X ) {
122  const Range & range = m_x_axis -> getRange ( false );
123  pos = range.pos();
124  }
125  else if ( axis == Axes::Y ) {
126  pos = std::max ( pos, m_value );
127  }
128  }
129 
130  return pos;
131 }
132 
133 const std::string &
135 getXLabel() const
136 {
137  return m_title;
138 }
139 
140 const std::string &
142 getYLabel( bool ) const
143 {
144  return m_title;
145 }
146 
147 int
150 {
151  return 1;
152 }
153 
154 int
156 getUnderflow () const
157 {
158  return -1;
159 }
160 
161 int
163 getOverflow () const
164 {
165  return -1;
166 }
167 
168 
170 {
173 
174  setDirty ( false );
175 }
176 
177 namespace dp = hippodraw::DataPoint2DTuple;
178 
179 DataSource *
181 createNTuple () const
182 {
183  unsigned int columns = dp::SIZE;
184  NTuple * ntuple = new NTuple ( columns );
185 
186  const char * values[] = { "X", "Y", "nil", "nil" };
187  vector < string > labels ( values, values + 4 );
188  ntuple -> setLabels ( labels );
189 
190  fillProjectedValues ( ntuple );
191 
192  return ntuple;
193 }
194 
195 void
197 fillProjectedValues ( DataSource * ntuple, bool ) const
198 {
199  ntuple -> clear ();
200 
201  vector < double > row ( dp::SIZE );
202  row[dp::XERR] = 0.;
203  row[dp::YERR] = 0.;
204 
205  if ( m_axis == Axes::X ) { // vertical line
206  const Range & range = m_y_axis -> getRange ( false );
207  row[dp::X] = m_value;
208  row[dp::Y] = range.low ();
209  ntuple -> addRow ( row );
210  row[dp::Y] = range.high ();
211  ntuple -> addRow ( row );
212  }
213  else { // horizontal line
214  const Range & range = m_x_axis -> getRange ( false );
215  row[dp::X] = range.low ();
216  row[dp::Y] = m_value;
217  ntuple -> addRow ( row );
218  row[dp::X] = range.high ();
219  ntuple -> addRow ( row );
220  }
221 }
222 
223 void
225 setValue ( double value )
226 {
227  m_value = value;
228 }
AxisModelBase * m_x_axis
The AxisModel along the X axis.
Definition: ProjectorBase.h:88
A namespace to set the standard for indexing into 2 dimension data point tuple.
virtual const Range & getRange(Axes::Type) const
Returns the Range along the specified axis.
virtual ~LineProjector()
The virtual destructor.
virtual Range valueRange() const
Finds the range of the projected values.
virtual int getNumberOfEntries() const
Returns the total number of entries that went into creating the projected values. ...
virtual bool isEmpty() const
Returns true if the data source used by this projector is empty.
int getUnderflow() const
Returns the number of underflow.
LineProjector(const LineProjector &)
The copy constructor.
virtual double getPosOn(hippodraw::Axes::Type) const
Returns the minimum positive value.
hippodraw::AxisModelBase class interface
Type
Axes constants.
Definition: AxesType.h:31
hippodraw::Axes::Type m_axis
The axis for the value.
Definition: LineProjector.h:38
DataSource * m_proj_values
The NTuple representing the result of the projection.
Definition: ProjectorBase.h:80
virtual void fillProjectedValues(DataSource *ntuple, bool in_range=false) const
int getOverflow() const
Returns the number of overflow.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
Namespace for HippoDraw.
Definition: AxesType.cxx:21
AxisModelBase * m_y_axis
The AxisModel along the Y axis.
Definition: ProjectorBase.h:92
hippodraw::NTuple class interface.
Base class for DataSource.
Definition: DataSource.h:55
double m_value
The value represented.
Definition: LineProjector.h:34
hippodraw::LineProjector class interface
virtual const std::string & getTitle() const
Finds the title of the plot.
virtual const std::string & getXLabel() const
Finds the X axis label of the plot.
virtual ProjectorBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
virtual void prepareValues()
Informs the projector to prepare its projected values for plotting.
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
virtual Range dataRangeOn(hippodraw::Axes::Type) const
Returns the range of the raw data.
A DataSource class implemented with std::vector<double> to store the column data. ...
Definition: NTuple.h:33
void setRange(double low, double high, double pos)
Changes the current Range.
Definition: Range.cxx:126
Expresses a range of values.
Definition: Range.h:33
The base class for the Projector hierarchy.
Definition: ProjectorBase.h:56
virtual const std::string & getYLabel(bool flag=false) const
Finds the Y axis label of the plot.
virtual DataSource * createNTuple() const
Creates an NTuple representation of the projected values.
std::string m_title
A label for the line.
Definition: LineProjector.h:42
error on X or half bin width
void setValue(double value)
Sets the value that will be projected.
virtual void addPointReps()
Function to add the acceptable point reps.
A projector that plots a value as a horizontal or vertical line.
Definition: LineProjector.h:27
double pos() const
Returns the first positive element in range.
Definition: Range.cxx:113
virtual void setDirty(bool value=true)
Sets the dirty flag to value.

Generated for HippoDraw Class Library by doxygen