yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
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< Point2DPoints
 
typedef std::shared_ptr< Scatter2DPtr
 
- 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

size_t dim () const
 Dimension of this data object. More...
 
const std::vector< std::string > variations () const
 Get the list of variations stored in the points. More...
 
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...
 
std::vector< std::string > annotations () const
 
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...
 
void setAnnotation (const std::string &name, const std::string &value)
 Add or set a string-valued annotation by name. More...
 
void setAnnotation (const std::string &name, double value)
 Add or set a double-valued annotation by name. More...
 
void setAnnotation (const std::string &name, float value)
 Add or set a float-valued annotation by name. More...
 
void setAnnotation (const std::string &name, long double value)
 Add or set a long-double-valued annotation by name. More...
 
template<typename T >
void setAnnotation (const std::string &name, const T &value)
 Add or set an annotation by name (templated for remaining types) 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
 Get the AO title. More...
 
void setTitle (const std::string &title)
 Set the AO title. More...
 
const std::string path () const
 Get the AO path. More...
 
void setPath (const std::string &path)
 
const std::string name () const
 
virtual std::string type () const
 Get name of the analysis object type. More...
 

Detailed Description

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

Definition at line 24 of file Scatter2D.h.

Member Typedef Documentation

◆ Point

Type of the native Point2D collection.

Definition at line 28 of file Scatter2D.h.

◆ Points

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

Definition at line 29 of file Scatter2D.h.

◆ Ptr

typedef std::shared_ptr<Scatter2D> YODA::Scatter2D::Ptr

Definition at line 30 of file Scatter2D.h.

Constructor & Destructor Documentation

◆ Scatter2D() [1/7]

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

Empty constructor.

Definition at line 37 of file Scatter2D.h.

Referenced by clone(), YODA::mkScatter(), and newclone().

38  : AnalysisObject("Scatter2D", path, title)
39  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.

◆ Scatter2D() [2/7]

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

Constructor from a set of points.

Definition at line 43 of file Scatter2D.h.

45  : AnalysisObject("Scatter2D", path, title),
46  _points(points)
47  { }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string title() const
Get the AO title.
Points & points()
Get the collection of points (non-const)
Definition: Scatter2D.h:185

◆ Scatter2D() [3/7]

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 51 of file Scatter2D.h.

References addPoint().

53  : AnalysisObject("Scatter2D", path, title)
54  {
55  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
56  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i], y[i]);
57  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:216
const std::string title() const
Get the AO title.

◆ Scatter2D() [4/7]

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 61 of file Scatter2D.h.

References addPoint().

64  : AnalysisObject("Scatter2D", path, title)
65  {
66  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
67  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
68  if (y.size() != ey.size()) throw UserError("y and ey vectors must have same length");
69  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i], y[i], ex[i], ey[i]);
70  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:216
const std::string title() const
Get the AO title.

◆ Scatter2D() [5/7]

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 74 of file Scatter2D.h.

References addPoint().

77  : AnalysisObject("Scatter2D", path, title)
78  {
79  if (x.size() != y.size()) throw UserError("x and y vectors must have same length");
80  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
81  if (y.size() != ey.size()) throw UserError("y and ey vectors must have same length");
82  for (size_t i = 0; i < x.size(); ++i) addPoint(Point2D(x[i], y[i], ex[i], ey[i]));
83  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:216
const std::string title() const
Get the AO title.

◆ Scatter2D() [6/7]

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 87 of file Scatter2D.h.

References addPoint().

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

◆ Scatter2D() [7/7]

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 104 of file Scatter2D.h.

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), and YODA::AnalysisObject::setAnnotation().

105  : AnalysisObject("Scatter2D", (path.size() == 0) ? s2.path() : path, s2, s2.title()),
106  _points(s2._points)
107  {
108  for ( auto &ann : annotations()){
109  setAnnotation(ann, annotation(ann));
110  }
111  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
void setAnnotation(const std::string &name, const std::string &value)
Add or set a string-valued annotation by name.
std::vector< std::string > annotations() const

Member Function Documentation

◆ addPoint() [1/5]

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

Insert a new point.

Definition at line 216 of file Scatter2D.h.

Referenced by addPoints(), YODA::ReaderAIDA::create(), YODA::divide(), YODA::mkScatter(), Scatter2D(), and YODA::toScatter2D().

216  {
217  _points.insert(pt);
218  }

◆ addPoint() [2/5]

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 221 of file Scatter2D.h.

221  {
222  _points.insert(Point2D(x, y));
223  }

◆ addPoint() [3/5]

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 226 of file Scatter2D.h.

227  {
228  _points.insert(Point2D(x, y, ex, ey));
229  }

◆ addPoint() [4/5]

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 232 of file Scatter2D.h.

233  {
234  _points.insert(Point2D(x, y, ex, ey));
235  }

◆ addPoint() [5/5]

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 238 of file Scatter2D.h.

240  {
241  _points.insert(Point2D(x, y, exminus, explus, eyminus, eyplus));
242  }

◆ addPoints()

void YODA::Scatter2D::addPoints ( const Points pts)
inline

Insert a collection of new points.

Definition at line 245 of file Scatter2D.h.

References addPoint().

Referenced by combineWith().

245  {
246  for (const Point2D& pt : pts) addPoint(pt);
247  }
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:216

◆ clone()

Scatter2D YODA::Scatter2D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 122 of file Scatter2D.h.

References Scatter2D().

Referenced by YODA::add(), YODA::divide(), YODA::multiply(), and YODA::subtract().

122  {
123  return Scatter2D(*this);
124  }
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:37

◆ combineWith() [1/2]

void YODA::Scatter2D::combineWith ( const Scatter2D other)
inline
Todo:
Better name? Make this the add operation?

Definition at line 256 of file Scatter2D.h.

References addPoints(), and points().

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

256  {
257  addPoints(other.points());
258  //return *this;
259  }
void addPoints(const Points &pts)
Insert a collection of new points.
Definition: Scatter2D.h:245

◆ combineWith() [2/2]

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 263 of file Scatter2D.h.

References combineWith().

263  {
264  for (const Scatter2D& s : others) combineWith(s);
265  //return *this;
266  }
void combineWith(const Scatter2D &other)
Definition: Scatter2D.h:256
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:37

◆ dim()

size_t YODA::Scatter2D::dim ( ) const
inlinevirtual

Dimension of this data object.

Implements YODA::AnalysisObject.

Definition at line 135 of file Scatter2D.h.

135 { return 2; }

◆ newclone()

Scatter2D* YODA::Scatter2D::newclone ( ) const
inlinevirtual

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

Implements YODA::AnalysisObject.

Definition at line 127 of file Scatter2D.h.

References Scatter2D().

Referenced by YODA::toNewScatter2D().

127  {
128  return new Scatter2D(*this);
129  }
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:37

◆ numPoints()

size_t YODA::Scatter2D::numPoints ( ) const
inline

Number of points in the scatter.

Definition at line 179 of file Scatter2D.h.

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

179  {
180  return _points.size();
181  }

◆ operator!=()

bool YODA::Scatter2D::operator!= ( const Scatter2D other)
inline

Non-equality operator.

Definition at line 277 of file Scatter2D.h.

References operator==().

277  {
278  return ! operator == (other);
279  }
bool operator==(const Scatter2D &other)
Equality operator.
Definition: Scatter2D.h:272

◆ operator=()

Scatter2D& YODA::Scatter2D::operator= ( const Scatter2D s2)
inline

Assignment operator.

Definition at line 115 of file Scatter2D.h.

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

115  {
116  AnalysisObject::operator = (s2); //< AO treatment of paths etc.
117  _points = s2._points;
118  return *this;
119  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.

◆ operator==()

bool YODA::Scatter2D::operator== ( const Scatter2D other)
inline

Equality operator.

Definition at line 272 of file Scatter2D.h.

Referenced by operator!=().

272  {
273  return _points == other._points;
274  }

◆ point() [1/2]

Point2D& YODA::Scatter2D::point ( size_t  index)
inline

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

Definition at line 197 of file Scatter2D.h.

References numPoints().

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

197  {
198  if (index >= numPoints()) throw RangeError("There is no point with this index");
199  return _points.at(index);
200  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:179

◆ point() [2/2]

const Point2D& YODA::Scatter2D::point ( size_t  index) const
inline

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

Definition at line 204 of file Scatter2D.h.

References numPoints().

204  {
205  if (index >= numPoints()) throw RangeError("There is no point with this index");
206  return _points.at(index);
207  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:179

◆ points() [1/2]

Points& YODA::Scatter2D::points ( )
inline

Get the collection of points (non-const)

Definition at line 185 of file Scatter2D.h.

Referenced by combineWith(), YODA::Histo1D::Histo1D(), YODA::Profile1D::Profile1D(), YODA::toIntegralEfficiencyHisto(), and YODA::WriterFLAT::writeScatter2D().

185  {
186  return _points;
187  }

◆ points() [2/2]

const Points& YODA::Scatter2D::points ( ) const
inline

Get the collection of points (const)

Definition at line 191 of file Scatter2D.h.

191  {
192  return _points;
193  }

◆ reset()

void YODA::Scatter2D::reset ( )
inlinevirtual

Clear all points.

Implements YODA::AnalysisObject.

Definition at line 142 of file Scatter2D.h.

142  {
143  _points.clear();
144  }

◆ scale()

void YODA::Scatter2D::scale ( double  scalex,
double  scaley 
)
inline

Scaling of both axes

Deprecated:
Use scaleXY

Definition at line 163 of file Scatter2D.h.

References scaleXY(), and variations().

163  {
164  scaleXY(scalex, scaley);
165  }
void scaleXY(double scalex, double scaley)
Scaling of both axes.
Definition: Scatter2D.h:157

◆ scaleX()

void YODA::Scatter2D::scaleX ( double  scalex)
inline

Scaling of x axis.

Definition at line 147 of file Scatter2D.h.

147  {
148  for (Point2D& p : _points) p.scaleX(scalex);
149  }

◆ scaleXY()

void YODA::Scatter2D::scaleXY ( double  scalex,
double  scaley 
)
inline

Scaling of both axes.

Definition at line 157 of file Scatter2D.h.

Referenced by scale().

157  {
158  for (Point2D& p : _points) p.scaleXY(scalex, scaley);
159  }

◆ scaleY()

void YODA::Scatter2D::scaleY ( double  scaley)
inline

Scaling of y axis.

Definition at line 152 of file Scatter2D.h.

152  {
153  for (Point2D& p : _points) p.scaleY(scaley);
154  }

◆ variations()

const std::vector< std::string > YODA::Scatter2D::variations ( ) const

Get the list of variations stored in the points.

Definition at line 72 of file Scatter2D.cc.

References YODA::Point2D::errMap(), and point().

Referenced by scale().

72  {
73  std::vector<std::string> vecvariations;
74  for (auto &point : this->_points){
75  for (auto &it : point.errMap()){
76  //if the variation is not already in the vector, add it !
77  if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
78  vecvariations.push_back(it.first);
79  }
80  }
81  }
82  return vecvariations;
83  }
Point2D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter2D.h:197
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point2D.h:381

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