yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
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 YODA::Scatter< N > 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 Types inherited from YODA::Scatter< N >
typedef Utils::ndarray< double, N > NdVal
 
typedef Utils::ndarray< std::pair< double, double >, N > NdValPair
 
typedef Utils::sortedvector< Point< N > > Points
 
typedef std::shared_ptr< ScatterPtr
 

Public Member Functions

size_t dim () const
 Dimension of this data object. More...
 
void parseVariations ()
 
std::vector< std::string > variations () const
 Get the list of variations stored in the points. More...
 
std::vector< std::vector< double > > covarianceMatrix (bool ignoreOffDiagonalTerms=false)
 
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 (size_t i, double scale)
 Scaling along direction i. More...
 
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...
 
Point removers
void rmPoint (size_t index)
 Remove the point with index index. 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...
 
void parseVariations ()
 
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...
 
- Public Member Functions inherited from YODA::Scatter< N >
virtual ~Scatter ()
 Virtual destructor for inheritance. More...
 
void reset ()
 Clear all points. More...
 
void scale (const NdVal &scales)
 Scaling. More...
 
virtual void rmPoints (std::vector< size_t > indices)
 Safely remove the points with indices indices. More...
 
 Scatter (const std::string &path="", const std::string &title="")
 Empty constructor. More...
 
 Scatter (const Points &points, const std::string &path="", const std::string &title="")
 Constructor from a set of points. More...
 
 Scatter (const std::vector< NdVal > &positions, const std::string &path="", const std::string &title="")
 Constructor from a vector of position values with no errors. More...
 
 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. More...
 
 Scatter (const Scatter< N > &s, const std::string &path="")
 Copy constructor with optional new path. More...
 
Scatter< N > & operator= (const Scatter< N > &s)
 Assignment operator. More...
 
Scatter< N > clone () const
 Make a copy on the stack. More...
 
Scatter< N > * newclone () const
 Make a copy on the heap, via 'new'. More...
 
size_t numPoints () const
 Number of points in the scatter. More...
 
Pointspoints ()
 Get the collection of points. More...
 
const Pointspoints () const
 Get the collection of points (const version) More...
 
Point< N > & point (size_t index)
 Get a reference to the point with index index. More...
 
const Point< N > & point (size_t index) const
 Get the point with index index (const version) More...
 
Scatter< N > & addPoint (const Point< N > &pt)
 Insert a new point. More...
 
Scatter< N > & addPoint (const NdVal &pos)
 Insert a new point, from a position array. More...
 
Scatter< N > & addPoints (Points pts)
 Insert a collection of new points. More...
 
Scatter< N > & combineWith (const Scatter< N > &other)
 
Scatter< N > & combineWith (const std::vector< Scatter< N > > &others)
 

Detailed Description

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

Definition at line 25 of file Scatter2D.h.

Member Typedef Documentation

◆ Point

Type of the native Point2D collection.

Definition at line 29 of file Scatter2D.h.

◆ Points

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

Definition at line 30 of file Scatter2D.h.

◆ Ptr

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

Definition at line 31 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 38 of file Scatter2D.h.

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

39  : AnalysisObject("Scatter2D", path, title)
40  { }
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 44 of file Scatter2D.h.

46  : AnalysisObject("Scatter2D", path, title),
47  _points(points)
48  { }
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:194

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

References addPoint().

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

References addPoint().

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

References addPoint().

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

References addPoint().

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

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

106  : AnalysisObject("Scatter2D", (path.size() == 0) ? s2.path() : path, s2, s2.title()),
107  _points(s2._points)
108  {
109  for ( auto &ann : annotations()){
110  setAnnotation(ann, annotation(ann));
111  }
112  }
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 225 of file Scatter2D.h.

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

225  {
226  _points.insert(pt);
227  }

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

References YODA::Point< N >::setParent().

230  {
231  Point2D thisPoint = Point2D(x, y);
232  thisPoint.setParent(this);
233  _points.insert(thisPoint);
234  }

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

References YODA::Point< N >::setParent().

238  {
239  Point2D thisPoint = Point2D(x, y, ex, ey);
240  thisPoint.setParent(this);
241  _points.insert(thisPoint);
242  }

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

References YODA::Point< N >::setParent().

246  {
247  Point2D thisPoint = Point2D(x, y, ex, ey);
248  thisPoint.setParent(this);
249  _points.insert(thisPoint);
250  }

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

References YODA::Point< N >::setParent().

255  {
256  Point2D thisPoint = Point2D(x, y, exminus, explus, eyminus, eyplus);
257  thisPoint.setParent(this);
258  _points.insert(thisPoint);
259  }

◆ addPoints()

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

Insert a collection of new points.

Definition at line 262 of file Scatter2D.h.

References addPoint().

Referenced by combineWith().

262  {
263  for (const Point2D& pt : pts) addPoint(pt);
264  }
void addPoint(const Point2D &pt)
Insert a new point.
Definition: Scatter2D.h:225

◆ clone()

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

Make a copy on the stack.

Definition at line 123 of file Scatter2D.h.

References Scatter2D().

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

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

◆ combineWith() [1/2]

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

Definition at line 292 of file Scatter2D.h.

References addPoints(), and points().

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

292  {
293  addPoints(other.points());
294  //return *this;
295  }
void addPoints(const Points &pts)
Insert a collection of new points.
Definition: Scatter2D.h:262

◆ combineWith() [2/2]

void YODA::Scatter2D::combineWith ( const std::vector< Scatter2D > &  others)
inline
Todo:

Better name?

Convert/extend to accept a Range or generic

Definition at line 299 of file Scatter2D.h.

References combineWith().

299  {
300  for (const Scatter2D& s : others) combineWith(s);
301  //return *this;
302  }
void combineWith(const Scatter2D &other)
Definition: Scatter2D.h:292
Scatter2D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter2D.h:38

◆ covarianceMatrix()

std::vector< std::vector< double > > YODA::Scatter2D::covarianceMatrix ( bool  ignoreOffDiagonalTerms = false)

Definition at line 116 of file Scatter2D.cc.

References YODA::Point2D::errMap(), numPoints(), point(), YODA::sqr(), and variations().

Referenced by scale().

116  {
117  int nPoints = this->numPoints();
118  //double covM[nPoints][nPoints] = {};
119  std::vector<std::vector<double> > covM;
120 
121 
122  // initialise cov matrix to be the right shape
123  for (int i = 0; i < nPoints; i++) {
124  std::vector<double> row;
125  row.resize(nPoints);
126  covM.push_back(row);
127  }
128 
129  // case where only have nominal, ie total uncertainty, labelled "" (empty string)
130  if (this->variations().size() == 1) {
131  for (int i = 0; i < nPoints; i++) {
132  covM[i][i] = sqr(((this->_points[i].yErrs().first+this->_points[i].yErrs().second)/2));
133  if (covM[i][i] == 0 ) covM[i][i] = 1;
134  }
135  return covM;
136  }
137  // more interesting case where we actually have some uncertainty breakdown!
138  auto systList= this->variations();
139  for (auto sname : systList){
140  if (sname.length() == 0) continue;
141  std::vector<double> systErrs;
142  systErrs.resize(nPoints);
143  for (int i = 0; i < nPoints; i++) {
144  auto point = this->_points[i];
145  try {
146  auto variations = point.errMap().at(sname);
147  // up/dn are symmetrized since this method can't handle asymmetric errors
148  systErrs[i] = (fabs(variations.first)+fabs(variations.second))*0.5;
149  } catch (const std::exception& e) { // missing bin
150  systErrs[i] = 0.0;
151  }
152  }
153  if (ignoreOffDiagonalTerms || sname.find("stat") != std::string::npos || sname.find("uncor") != std::string::npos) {
154  for (int i = 0; i < nPoints; i++) {
155  covM[i][i] += systErrs[i]*systErrs[i]; // just the diagonal; bins are considered uncorrelated
156  }
157  } else {
158  for (int i = 0; i < nPoints; i++) {
159  for (int j = 0; j < nPoints; j++) {
160  covM[i][j] += systErrs[i]*systErrs[j];
161  }
162  }
163  }
164  }
165  return covM;
166  }
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point2D.cc:8
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:208
Point2D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter2D.h:206
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:188
std::vector< std::string > variations() const
Get the list of variations stored in the points.
Definition: Scatter2D.cc:102

◆ dim()

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

Dimension of this data object.

Implements YODA::AnalysisObject.

Definition at line 136 of file Scatter2D.h.

136 { return 2; }

◆ newclone()

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

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

Implements YODA::AnalysisObject.

Definition at line 128 of file Scatter2D.h.

References Scatter2D().

Referenced by YODA::toNewScatter2D().

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

◆ numPoints()

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

Number of points in the scatter.

Implements YODA::Scatter< N >.

Definition at line 188 of file Scatter2D.h.

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

188  {
189  return _points.size();
190  }

◆ operator!=()

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

Non-equality operator.

Definition at line 313 of file Scatter2D.h.

References operator==().

313  {
314  return ! operator == (other);
315  }
bool operator==(const Scatter2D &other)
Equality operator.
Definition: Scatter2D.h:308

◆ operator=()

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

Assignment operator.

Definition at line 116 of file Scatter2D.h.

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

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

◆ operator==()

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

Equality operator.

Definition at line 308 of file Scatter2D.h.

Referenced by operator!=().

308  {
309  return _points == other._points;
310  }

◆ parseVariations()

void YODA::Scatter2D::parseVariations ( )

Definition at line 79 of file Scatter2D.cc.

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::hasAnnotation(), numPoints(), YODA::Point2D::setYErrs(), and variations().

Referenced by scale().

79  {
80  if (this->_variationsParsed) { return; }
81  if (!(this->hasAnnotation("ErrorBreakdown"))) { return; }
82  YAML::Node errorBreakdown;
83  errorBreakdown = YAML::Load(this->annotation("ErrorBreakdown"));
84 
85  if (errorBreakdown.size()) {
86  for (size_t thisPointIndex = 0; thisPointIndex < this->numPoints(); ++thisPointIndex) {
87  Point2D& thispoint = this->_points[thisPointIndex];
88  YAML::Node variations = errorBreakdown[thisPointIndex];
89  for (const auto& variation : variations) {
90  const std::string variationName = variation.first.as<std::string>();
91  double eyp = variation.second["up"].as<double>();
92  double eym = variation.second["dn"].as<double>();
93  thispoint.setYErrs(eym,eyp,variationName);
94  }
95  }
96  this-> _variationsParsed =true;
97  }
98  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:188
const std::string & annotation(const std::string &name) const
Get an annotation by name (as a string)
bool hasAnnotation(const std::string &name) const
Check if an annotation is defined.
std::vector< std::string > variations() const
Get the list of variations stored in the points.
Definition: Scatter2D.cc:102

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

References numPoints().

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

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

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

References numPoints().

213  {
214  if (index >= numPoints()) throw RangeError("There is no point with this index");
215  return _points.at(index);
216  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter2D.h:188

◆ points() [1/2]

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

Get the collection of points (non-const)

Definition at line 194 of file Scatter2D.h.

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

194  {
195  return _points;
196  }

◆ points() [2/2]

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

Get the collection of points (const)

Definition at line 200 of file Scatter2D.h.

200  {
201  return _points;
202  }

◆ reset()

void YODA::Scatter2D::reset ( )
inlinevirtual

Clear all points.

Implements YODA::AnalysisObject.

Definition at line 143 of file Scatter2D.h.

143  {
144  _points.clear();
145  }

◆ rmPoint()

void YODA::Scatter2D::rmPoint ( size_t  index)
inlinevirtual

Remove the point with index index.

Implements YODA::Scatter< N >.

Definition at line 273 of file Scatter2D.h.

273  {
274  _points.erase(_points.begin()+index);
275  }

◆ scale()

void YODA::Scatter2D::scale ( size_t  i,
double  scale 
)
inlinevirtual

Scaling along direction i.

Implements YODA::Scatter< N >.

Definition at line 163 of file Scatter2D.h.

References covarianceMatrix(), parseVariations(), scaleX(), scaleY(), and variations().

163  {
164  switch (i) {
165  case 1: scaleX(scale); break;
166  case 2: scaleY(scale); break;
167  default: throw RangeError("Invalid axis int, must be in range 1..dim");
168  }
169  }
void scale(size_t i, double scale)
Scaling along direction i.
Definition: Scatter2D.h:163
void scaleX(double scalex)
Scaling of x axis.
Definition: Scatter2D.h:148
void scaleY(double scaley)
Scaling of y axis.
Definition: Scatter2D.h:153

◆ scaleX()

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

Scaling of x axis.

Definition at line 148 of file Scatter2D.h.

Referenced by scale().

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

◆ scaleXY()

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

Scaling of both axes.

Definition at line 158 of file Scatter2D.h.

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

◆ scaleY()

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

Scaling of y axis.

Definition at line 153 of file Scatter2D.h.

Referenced by scale().

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

◆ variations()

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

Get the list of variations stored in the points.

Todo:
Reduce duplication between Scatter types

Implements YODA::Scatter< N >.

Definition at line 102 of file Scatter2D.cc.

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

Referenced by covarianceMatrix(), parseVariations(), and scale().

102  {
103  std::vector<std::string> vecVariations;
104  for (auto& point : this->_points) {
105  for (auto& it : point.errMap()) {
106  // if the variation is not already in the vector, add it!
107  if (std::find(vecVariations.begin(), vecVariations.end(), it.first) == vecVariations.end()) {
108  vecVariations.push_back(it.first);
109  }
110  }
111  }
112  return vecVariations;
113  }
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point2D.cc:8
Point2D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter2D.h:206

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