YODA is hosted by Hepforge, IPPP Durham
YODA::Scatter2D Class Reference

A very generic data type which is just a collection of 2D data points with errors. More...

#include <Scatter2D.h>

Inheritance diagram for YODA::Scatter2D:
YODA::AnalysisObject

Public Types

typedef Point2D Point
 Type of the native Point2D collection. More...
 
typedef Utils::sortedvector
< Point2D
Points
 
- Public Types inherited from YODA::AnalysisObject
typedef std::map< std::string,
std::string > 
Annotations
 Collection type for annotations, as a string-string map. More...
 

Public Member Functions

bool operator== (const Scatter2D &other)
 Equality operator. More...
 
bool operator!= (const Scatter2D &other)
 Non-equality operator. More...
 
Constructors
 Scatter2D (const std::string &path="", const std::string &title="")
 Empty constructor. More...
 
 Scatter2D (const Points &points, const std::string &path="", const std::string &title="")
 Constructor from a set of points. More...
 
 Scatter2D (const std::vector< double > &x, const std::vector< double > &y, const std::string &path="", const std::string &title="")
 Constructor from a vector of values with no errors. More...
 
 Scatter2D (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &ex, const std::vector< double > &ey, const std::string &path="", const std::string &title="")
 Constructor from vectors of values with symmetric errors on x and y. More...
 
 Scatter2D (const std::vector< double > &x, const std::vector< double > &y, const std::vector< std::pair< double, double > > &ex, const std::vector< std::pair< double, double > > &ey, const std::string &path="", const std::string &title="")
 Constructor from values with asymmetric errors on both x and y. More...
 
 Scatter2D (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &exminus, const std::vector< double > &explus, const std::vector< double > &eyminus, const std::vector< double > &eyplus, const std::string &path="", const std::string &title="")
 Constructor from values with completely explicit asymmetric errors. More...
 
 Scatter2D (const Scatter2D &s2, const std::string &path="")
 
Scatter2Doperator= (const Scatter2D &s2)
 Assignment operator. More...
 
Scatter2D clone () const
 Make a copy on the stack. More...
 
Scatter2Dnewclone () const
 Make a copy on the heap, via 'new'. More...
 
Modifiers
void reset ()
 Clear all points. More...
 
void scaleX (double scalex)
 Scaling of x axis. More...
 
void scaleY (double scaley)
 Scaling of y axis. More...
 
void scaleXY (double scalex, double scaley)
 Scaling of both axes. More...
 
void scale (double scalex, double scaley)
 
Point accessors
size_t numPoints () const
 Number of points in the scatter. More...
 
Pointspoints ()
 Get the collection of points (non-const) More...
 
const Pointspoints () const
 Get the collection of points (const) More...
 
Point2Dpoint (size_t index)
 Get a reference to the point with index index (non-const) More...
 
const Point2Dpoint (size_t index) const
 Get a reference to the point with index index (const) More...
 
Point inserters
void addPoint (const Point2D &pt)
 Insert a new point. More...
 
void addPoint (double x, double y)
 Insert a new point, defined as the x/y value pair and no errors. More...
 
void addPoint (double x, double y, double ex, double ey)
 Insert a new point, defined as the x/y value pair and symmetric errors. More...
 
void addPoint (double x, double y, const std::pair< double, double > &ex, const std::pair< double, double > &ey)
 Insert a new point, defined as the x/y value pair and asymmetric error pairs. More...
 
void addPoint (double x, double y, double exminus, double explus, double eyminus, double eyplus)
 Insert a new point, defined as the x/y value pair and asymmetric errors. More...
 
void addPoints (const Points &pts)
 Insert a collection of new points. More...
 
Combining sets of scatter points
void combineWith (const Scatter2D &other)
 
void combineWith (const std::vector< Scatter2D > &others)
 
- Public Member Functions inherited from YODA::AnalysisObject
 AnalysisObject ()
 Default constructor. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const std::string &title="")
 Constructor giving a type, a path and an optional title. More...
 
 AnalysisObject (const std::string &type, const std::string &path, const AnalysisObject &ao, const std::string &title="")
 Constructor giving a type, a path, another AO to copy annotation from, and an optional title. More...
 
virtual ~AnalysisObject ()
 Default destructor. More...
 
virtual AnalysisObjectoperator= (const AnalysisObject &ao)
 Default copy assignment operator. More...
 
const std::vector< std::string > annotations () const
 Get all the annotation names. More...
 
bool hasAnnotation (const std::string &name) const
 Check if an annotation is defined. More...
 
const std::string & annotation (const std::string &name) const
 Get an annotation by name (as a string) More...
 
const std::string & annotation (const std::string &name, const std::string &defaultreturn) const
 Get an annotation by name (as a string) with a default in case the annotation is not found. More...
 
template<typename T >
const T annotation (const std::string &name) const
 Get an annotation by name (copied to another type) More...
 
template<typename T >
const T annotation (const std::string &name, const T &defaultreturn) const
 Get an annotation by name (copied to another type) with a default in case the annotation is not found. More...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void setAnnotations (const Annotations &anns)
 Set all annotations at once. More...
 
template<typename T >
void addAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name. More...
 
void rmAnnotation (const std::string &name)
 Delete an annotation by name. More...
 
void clearAnnotations ()
 Delete an annotation by name. More...
 
const std::string title () const
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 
void setPath (const std::string &path)
 Set the AO path. More...
 
virtual std::string type () const
 Get name of the analysis object type, for persistency. More...
 

Detailed Description

A very generic data type which is just a collection of 2D data points with errors.

Definition at line 23 of file Scatter2D.h.

Member Typedef Documentation

Type of the native Point2D collection.

Definition at line 27 of file Scatter2D.h.

typedef Utils::sortedvector<Point2D> YODA::Scatter2D::Points

Definition at line 28 of file Scatter2D.h.

Constructor & Destructor Documentation

YODA::Scatter2D::Scatter2D ( const std::string &  path = "",
const std::string &  title = "" 
)
inline

Empty constructor.

Definition at line 35 of file Scatter2D.h.

Referenced by clone(), and newclone().

36  : AnalysisObject("Scatter2D", path, title)
37  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
YODA::Scatter2D::Scatter2D ( const Points points,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from a set of points.

Definition at line 41 of file Scatter2D.h.

43  : AnalysisObject("Scatter2D", path, title),
44  _points(points)
45  { }
AnalysisObject()
Default constructor.
const std::string path() const
const std::string title() const
Points & points()
Get the collection of points (non-const)
Definition: Scatter2D.h:173
YODA::Scatter2D::Scatter2D ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from a vector of values with no errors.

Definition at line 49 of file Scatter2D.h.

References addPoint().

51  : AnalysisObject("Scatter2D", path, title)
52  {
53  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
54  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i], y[i]);
55  }
AnalysisObject()
Default constructor.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:204
const std::string path() const
const std::string title() const
YODA::Scatter2D::Scatter2D ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< double > &  ex,
const std::vector< double > &  ey,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from vectors of values with symmetric errors on x and y.

Definition at line 59 of file Scatter2D.h.

References addPoint().

62  : AnalysisObject("Scatter2D", path, title)
63  {
64  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
65  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
66  if (y.size() != ey.size()) throw UserError("y and ey vectors must have same length");
67  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i], y[i], ex[i], ey[i]);
68  }
AnalysisObject()
Default constructor.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:204
const std::string path() const
const std::string title() const
YODA::Scatter2D::Scatter2D ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< std::pair< double, double > > &  ex,
const std::vector< std::pair< double, double > > &  ey,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from values with asymmetric errors on both x and y.

Definition at line 72 of file Scatter2D.h.

References addPoint().

75  : AnalysisObject("Scatter2D", path, title)
76  {
77  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
78  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
79  if (y.size() != ey.size()) throw UserError("y and ey vectors must have same length");
80  for (size_t i = 0; i < x.size(); ++i) addPoint(Point2D(x[i], y[i], ex[i], ey[i]));
81  }
AnalysisObject()
Default constructor.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:204
const std::string path() const
const std::string title() const
YODA::Scatter2D::Scatter2D ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< double > &  exminus,
const std::vector< double > &  explus,
const std::vector< double > &  eyminus,
const std::vector< double > &  eyplus,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from values with completely explicit asymmetric errors.

Definition at line 85 of file Scatter2D.h.

References addPoint().

89  : AnalysisObject("Scatter2D", path, title)
90  {
91  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
92  if (x.size() != exminus.size()) throw UserError("x and ex vectors must have same length");
93  if (y.size() != eyminus.size()) throw UserError("y and ey vectors must have same length");
94  if (exminus.size() != explus.size()) throw UserError("ex plus and minus vectors must have same length");
95  if (eyminus.size() != eyplus.size()) throw UserError("ey plus and minus vectors must have same length");
96  for (size_t i = 0; i < x.size(); ++i) addPoint(Point2D(x[i], y[i], exminus[i], explus[i], eyminus[i], eyplus[i]));
97  }
AnalysisObject()
Default constructor.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:204
const std::string path() const
const std::string title() const
YODA::Scatter2D::Scatter2D ( const Scatter2D s2,
const std::string &  path = "" 
)
inline

Copy constructor with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 102 of file Scatter2D.h.

103  : AnalysisObject("Scatter2D", (path.size() == 0) ? s2.path() : path, s2, s2.title()),
104  _points(s2._points)
105  { }
AnalysisObject()
Default constructor.
const std::string path() const

Member Function Documentation

void YODA::Scatter2D::addPoint ( const Point2D pt)
inline

Insert a new point.

Definition at line 204 of file Scatter2D.h.

Referenced by YODA::add(), addPoints(), YODA::divide(), YODA::mkScatter(), Scatter2D(), YODA::subtract(), and YODA::toScatter2D().

204  {
205  _points.insert(pt);
206  }
void YODA::Scatter2D::addPoint ( double  x,
double  y 
)
inline

Insert a new point, defined as the x/y value pair and no errors.

Definition at line 209 of file Scatter2D.h.

209  {
210  _points.insert(Point2D(x, y));
211  }
void YODA::Scatter2D::addPoint ( double  x,
double  y,
double  ex,
double  ey 
)
inline

Insert a new point, defined as the x/y value pair and symmetric errors.

Definition at line 214 of file Scatter2D.h.

215  {
216  _points.insert(Point2D(x, y, ex, ey));
217  }
void YODA::Scatter2D::addPoint ( double  x,
double  y,
const std::pair< double, double > &  ex,
const std::pair< double, double > &  ey 
)
inline

Insert a new point, defined as the x/y value pair and asymmetric error pairs.

Definition at line 220 of file Scatter2D.h.

221  {
222  _points.insert(Point2D(x, y, ex, ey));
223  }
void YODA::Scatter2D::addPoint ( double  x,
double  y,
double  exminus,
double  explus,
double  eyminus,
double  eyplus 
)
inline

Insert a new point, defined as the x/y value pair and asymmetric errors.

Definition at line 226 of file Scatter2D.h.

228  {
229  _points.insert(Point2D(x, y, exminus, explus, eyminus, eyplus));
230  }
void YODA::Scatter2D::addPoints ( const Points pts)
inline

Insert a collection of new points.

Definition at line 233 of file Scatter2D.h.

References addPoint().

Referenced by combineWith().

233  {
234  BOOST_FOREACH (const Point2D& pt, pts) addPoint(pt);
235  }
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:204
Scatter2D YODA::Scatter2D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 116 of file Scatter2D.h.

References Scatter2D().

116  {
117  return Scatter2D(*this);
118  }
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:35
void YODA::Scatter2D::combineWith ( const Scatter2D other)
inline
Todo:
Better name? Make this the add operation?

Definition at line 244 of file Scatter2D.h.

References addPoints(), and points().

Referenced by YODA::combine(), and combineWith().

244  {
245  addPoints(other.points());
246  //return *this;
247  }
void addPoints(const Points &pts)
Insert a collection of new points.
Definition: Scatter2D.h:233
void YODA::Scatter2D::combineWith ( const std::vector< Scatter2D > &  others)
inline
Todo:

Better name? Make this the add operation?

Convert/extend to accept a Range or generic

Definition at line 251 of file Scatter2D.h.

References combineWith().

251  {
252  BOOST_FOREACH (const Scatter2D& s, others) combineWith(s);
253  //return *this;
254  }
void combineWith(const Scatter2D &other)
Definition: Scatter2D.h:244
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:35
Scatter2D* YODA::Scatter2D::newclone ( ) const
inlinevirtual

Make a copy on the heap, via 'new'.

Implements YODA::AnalysisObject.

Definition at line 121 of file Scatter2D.h.

References Scatter2D().

121  {
122  return new Scatter2D(*this);
123  }
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:35
size_t YODA::Scatter2D::numPoints ( ) const
inline

Number of points in the scatter.

Definition at line 167 of file Scatter2D.h.

Referenced by YODA::add(), YODA::chi2(), YODA::divide(), YODA::flip(), YODA::mkScatter(), point(), YODA::subtract(), YODA::toTGraph(), YODA::transformX(), and YODA::transformY().

167  {
168  return _points.size();
169  }
bool YODA::Scatter2D::operator!= ( const Scatter2D other)
inline

Non-equality operator.

Definition at line 265 of file Scatter2D.h.

References operator==().

265  {
266  return ! operator == (other);
267  }
bool operator==(const Scatter2D &other)
Equality operator.
Definition: Scatter2D.h:260
Scatter2D& YODA::Scatter2D::operator= ( const Scatter2D s2)
inline

Assignment operator.

Definition at line 109 of file Scatter2D.h.

References YODA::AnalysisObject::operator=().

109  {
110  AnalysisObject::operator = (s2); //< AO treatment of paths etc.
111  _points = s2._points;
112  return *this;
113  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
bool YODA::Scatter2D::operator== ( const Scatter2D other)
inline

Equality operator.

Definition at line 260 of file Scatter2D.h.

Referenced by operator!=().

260  {
261  return _points == other._points;
262  }
Point2D& YODA::Scatter2D::point ( size_t  index)
inline

Get a reference to the point with index index (non-const)

Definition at line 185 of file Scatter2D.h.

References numPoints().

Referenced by YODA::add(), YODA::chi2(), YODA::divide(), YODA::efficiency(), YODA::flip(), YODA::subtract(), YODA::toIntegralHisto(), YODA::toTGraph(), YODA::transformX(), and YODA::transformY().

185  {
186  if (index >= numPoints()) throw RangeError("There is no point with this index");
187  return _points.at(index);
188  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:167
const Point2D& YODA::Scatter2D::point ( size_t  index) const
inline

Get a reference to the point with index index (const)

Definition at line 192 of file Scatter2D.h.

References numPoints().

192  {
193  if (index >= numPoints()) throw RangeError("There is no point with this index");
194  return _points.at(index);
195  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:167
Points& YODA::Scatter2D::points ( )
inline
const Points& YODA::Scatter2D::points ( ) const
inline

Get the collection of points (const)

Definition at line 179 of file Scatter2D.h.

179  {
180  return _points;
181  }
void YODA::Scatter2D::reset ( )
inlinevirtual

Clear all points.

Implements YODA::AnalysisObject.

Definition at line 132 of file Scatter2D.h.

132  {
133  _points.clear();
134  }
void YODA::Scatter2D::scale ( double  scalex,
double  scaley 
)
inline

Scaling of both axes

Deprecated:
Use scaleXY

Definition at line 153 of file Scatter2D.h.

References scaleXY().

153  {
154  scaleXY(scalex, scaley);
155  }
void scaleXY(double scalex, double scaley)
Scaling of both axes.
Definition: Scatter2D.h:147
void YODA::Scatter2D::scaleX ( double  scalex)
inline

Scaling of x axis.

Definition at line 137 of file Scatter2D.h.

References YODA::Point2D::scaleX().

137  {
138  BOOST_FOREACH (Point2D& p, _points) p.scaleX(scalex);
139  }
void scaleX(double scalex)
Scaling of x axis.
Definition: Scatter2D.h:137
void YODA::Scatter2D::scaleXY ( double  scalex,
double  scaley 
)
inline

Scaling of both axes.

Definition at line 147 of file Scatter2D.h.

References YODA::Point2D::scaleXY().

Referenced by scale().

147  {
148  BOOST_FOREACH (Point2D& p, _points) p.scaleXY(scalex, scaley);
149  }
void scaleXY(double scalex, double scaley)
Scaling of both axes.
Definition: Scatter2D.h:147
void YODA::Scatter2D::scaleY ( double  scaley)
inline

Scaling of y axis.

Definition at line 142 of file Scatter2D.h.

References YODA::Point2D::scaleY().

142  {
143  BOOST_FOREACH (Point2D& p, _points) p.scaleY(scaley);
144  }
void scaleY(double scaley)
Scaling of y axis.
Definition: Scatter2D.h:142

The documentation for this class was generated from the following file: