yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
ScatterND.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_SCATTERND_H
7 #define YODA_SCATTERND_H
8 
9 #include "YODA/AnalysisObject.h"
10 #include "YODA/PointND.h"
12 #include "YODA/Utils/ndarray.h"
13 #include <vector>
14 #include <set>
15 #include <string>
16 #include <utility>
17 #include <memory>
18 
19 namespace YODA {
20 
21 
23  template <int N>
24  class Scatter : public AnalysisObject {
25  public:
26 
27  // Typedefs
28  typedef Utils::ndarray<double, N> NdVal;
29  typedef Utils::ndarray<std::pair<double,double>, N> NdValPair;
30  typedef Utils::sortedvector< Point<N> > Points;
31  typedef std::shared_ptr<Scatter> Ptr;
32 
33 
35 
36 
38  Scatter(const std::string& path="", const std::string& title="")
39  : AnalysisObject("Scatter", path, title)
40  { }
41 
42 
44  Scatter(const Points& points,
45  const std::string& path="", const std::string& title="")
46  : AnalysisObject("Scatter", path, title),
47  _points(points)
48  { }
49 
50 
52  Scatter(const std::vector<NdVal>& positions,
53  const std::string& path="", const std::string& title="")
54  : AnalysisObject("Scatter", path, title)
55  {
56  for (size_t i = 0; i < positions.size(); ++i) {
57  addPoint(Point<N>(positions[i]));
58  }
59  }
60 
61 
63  Scatter(const std::vector<NdVal>& positions,
64  const std::vector<NdVal>& errors,
65  const std::string& path="", const std::string& title="")
66  : AnalysisObject("Scatter", path, title)
67  {
68  assert(positions.size() == errors.size());
69  for (size_t i = 0; i < positions.size(); ++i) {
70  addPoint(Point<N>(positions[i], errors[i]));
71  }
72  }
73 
74 
75  // /// Constructor from values with completely explicit asymmetric errors
76  // Scatter(const std::vector<double>& x, const std::vector<double>& y,
77  // const std::vector<double>& exminus,
78  // const std::vector<double>& explus,
79  // const std::vector<double>& eyminus,
80  // const std::vector<double>& eyplus,
81  // const std::string& path="", const std::string& title="")
82  // : AnalysisObject("Scatter", path, title)
83  // {
84  // assert(x.size() == y.size() &&
85  // x.size() == exminus.size() && x.size() == explus.size() &&
86  // x.size() == eyminus.size() && x.size() == eyplus.size());
87  // for (size_t i = 0; i < x.size(); ++i) {
88  // addPoint(Point<N>2D(x[i], exminus[i], explus[i], y[i], eyminus[i], eyplus[i]));
89  // }
90  // }
91 
92 
94  Scatter(const Scatter<N>& s, const std::string& path="")
95  : AnalysisObject("Scatter", (path.size() == 0) ? s.path() : path, s, s.title()),
96  _points(s._points)
97  { }
98 
99 
102  setPath(s.path());
103  setTitle(s.title());
104  _points = s._points;
105  return *this;
106  }
107 
109  Scatter<N> clone() const {
110  return Scatter<N>(*this);
111  }
112 
114  Scatter<N>* newclone() const {
115  return new Scatter<N>(*this);
116  }
117 
119 
120 
122 
123 
125  void reset() {
126  _points.clear();
127  }
128 
130  void scale(const NdVal& scales) {
131  for (Point<N>& p : _points) p.scale(scales);
132  }
133 
135 
136 
138 
139 
141 
142 
144  size_t numPoints() const {
145  return _points.size();
146  }
147 
148 
150  Points& points() {
151  return _points;
152  }
153 
154 
156  const Points& points() const {
157  return _points;
158  }
159 
160 
162  Point<N>& point(size_t index) {
163  return _points.at(index);
164  }
165 
166 
168  const Point<N>& point(size_t index) const {
169  return _points.at(index);
170  }
171 
173 
174 
176 
177 
180  _points.insert(pt);
181  return *this;
182  }
183 
185  Scatter<N>& addPoint(const NdVal& pos) {
186  _points.insert(Point<N>(pos));
187  return *this;
188  }
189 
191 
193  Scatter<N>& addPoints(Points pts) {
194  for (const Point<N>& pt : pts) addPoint(pt);
195  return *this;
196  }
197 
199 
200 
202 
203 
206  addPoints(other.points());
207  return *this;
208  }
209 
211  Scatter<N>& combineWith(const std::vector< Scatter<N> >& others) {
212  for (const Scatter<N>& s : others) combineWith(s);
213  return *this;
214  }
215 
217 
218 
219  private:
220 
221  Points _points;
222 
223  };
224 
225 
227 
228 
229  template <int N>
230  inline Scatter<N> combine(const Scatter<N>& a, const Scatter<N>& b) {
231  Scatter<N> rtn = a;
232  rtn.combineWith(b);
233  return rtn;
234  }
235 
236  template <int N>
237  inline Scatter<N> combine(const std::vector< Scatter<N> >& scatters) {
238  Scatter<N> rtn;
239  rtn.combineWith(scatters);
240  return rtn;
241  }
242 
244 
245 
247 
248 
249  // /// @name Combining scatters: global operators, assuming aligned points
250  // //@{
251 
252  // /// Add two scatters
253  // template <int N>
254  // Scatter add(const Scatter& first, const Scatter& second);
255 
256 
257  // /// Add two scatters
258  // template <int N>
259  // inline Scatter operator + (const Scatter& first, const Scatter& second) {
260  // return add(first, second);
261  // }
262 
263 
264  // /// Subtract two scatters
265  // template <int N>
266  // Scatter subtract(const Scatter& first, const Scatter& second);
267 
268 
269  // /// Subtract two scatters
270  // template <int N>
271  // inline Scatter operator - (const Scatter& first, const Scatter& second) {
272  // return subtract(first, second);
273  // }
274 
275 
276  // /// Divide two scatters
277  // template <int N>
278  // Scatter divide(const Scatter& numer, const Scatter& denom);
279 
280 
281  // /// Divide two scatters
282  // template <int N>
283  // inline Scatter operator / (const Scatter& numer, const Scatter& denom) {
284  // return divide(numer, denom);
285  // }
286 
287  // //@}
288 
289 
290 }
291 
292 #endif
Scatter< N > & combineWith(const Scatter< N > &other)
Definition: ScatterND.h:205
Scatter1D combine(const Scatter1D &a, const Scatter1D &b)
Definition: Scatter1D.h:266
Scatter(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: ScatterND.h:38
void scale(const NdVal &scales)
Scaling.
Definition: ScatterND.h:130
Base class for all Point*Ds, providing generic access to their numerical properties.
Definition: Point.h:15
Scatter< N > & addPoint(const NdVal &pos)
Insert a new point, from a position array.
Definition: ScatterND.h:185
Scatter< N > & addPoint(const Point< N > &pt)
Insert a new point.
Definition: ScatterND.h:179
const std::string path() const
Get the AO path.
Point< N > & point(size_t index)
Get a reference to the point with index index.
Definition: ScatterND.h:162
Scatter< N > & addPoints(Points pts)
Insert a collection of new points.
Definition: ScatterND.h:193
void setPath(const std::string &path)
Utils::ndarray< double, N > NdVal
Definition: ScatterND.h:28
Utils::ndarray< std::pair< double, double >, N > NdValPair
Definition: ScatterND.h:29
const Point< N > & point(size_t index) const
Get the point with index index (const version)
Definition: ScatterND.h:168
void reset()
Clear all points.
Definition: ScatterND.h:125
const Points & points() const
Get the collection of points (const version)
Definition: ScatterND.h:156
Scatter(const Scatter< N > &s, const std::string &path="")
Copy constructor with optional new path.
Definition: ScatterND.h:94
size_t numPoints() const
Number of points in the scatter.
Definition: ScatterND.h:144
Scatter< N > & operator=(const Scatter< N > &s)
Assignment operator.
Definition: ScatterND.h:101
Scatter< N > * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: ScatterND.h:114
Scatter< N > clone() const
Make a copy on the stack.
Definition: ScatterND.h:109
std::shared_ptr< Scatter > Ptr
Definition: ScatterND.h:31
const std::string title() const
Get the AO title.
Utils::sortedvector< Point< N > > Points
Definition: ScatterND.h:30
AnalysisObject is the base class for histograms and scatters.
Points & points()
Get the collection of points.
Definition: ScatterND.h:150
Abstract base class for all Scatter*Ds.
Definition: Scatter.h:15
void setTitle(const std::string &title)
Set the AO title.
Scatter(const std::vector< NdVal > &positions, const std::string &path="", const std::string &title="")
Constructor from a vector of position values with no errors.
Definition: ScatterND.h:52
Scatter< N > & combineWith(const std::vector< Scatter< N > > &others)
Definition: ScatterND.h:211
Scatter(const std::vector< NdVal > &positions, const std::vector< NdVal > &errors, const std::string &path="", const std::string &title="")
Constructor from vectors of values for positions and a single set of symmetric errors.
Definition: ScatterND.h:63
Scatter(const Points &points, const std::string &path="", const std::string &title="")
Constructor from a set of points.
Definition: ScatterND.h:44