yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
YODA::Scatter1D Class Reference

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

#include <Scatter1D.h>

Inheritance diagram for YODA::Scatter1D:
YODA::AnalysisObject

Public Types

typedef Point1D Point
 Type of the native Point1D collection. More...
 
typedef Utils::sortedvector< Point1DPoints
 
typedef std::shared_ptr< Scatter1DPtr
 
- 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 Scatter1D &other)
 Equality operator. More...
 
bool operator!= (const Scatter1D &other)
 Non-equality operator. More...
 
Constructors
 Scatter1D (const std::string &path="", const std::string &title="")
 Empty constructor. More...
 
 Scatter1D (const Points &points, const std::string &path="", const std::string &title="")
 Constructor from a set of points. More...
 
 Scatter1D (const std::vector< double > &x, const std::string &path="", const std::string &title="")
 Constructor from a vector of x values with no errors. More...
 
 Scatter1D (const std::vector< double > &x, const std::vector< double > &ex, const std::string &path="", const std::string &title="")
 Constructor from vectors of x values with symmetric errors. More...
 
 Scatter1D (const std::vector< double > &x, const std::vector< std::pair< double, double > > &ex, const std::string &path="", const std::string &title="")
 Constructor from x values with asymmetric errors. More...
 
 Scatter1D (const std::vector< double > &x, const std::vector< double > &exminus, const std::vector< double > &explus, const std::string &path="", const std::string &title="")
 Constructor from values with completely explicit asymmetric errors. More...
 
 Scatter1D (const Scatter1D &s1, const std::string &path="")
 
Scatter1Doperator= (const Scatter1D &s1)
 Assignment operator. More...
 
Scatter1D clone () const
 Make a copy on the stack. More...
 
Scatter1Dnewclone () 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...
 
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...
 
Point1Dpoint (size_t index)
 Get a reference to the point with index index (non-const) More...
 
const Point1Dpoint (size_t index) const
 Get a reference to the point with index index (const) More...
 
Point inserters
void addPoint (const Point1D &pt)
 Insert a new point. More...
 
void addPoint (double x)
 Insert a new point, defined as the x value and no errors. More...
 
void addPoint (double x, double ex)
 Insert a new point, defined as the x value and symmetric errors. More...
 
void addPoint (double x, const std::pair< double, double > &ex)
 Insert a new point, defined as the x value and an asymmetric error pair. More...
 
void addPoint (double x, double exminus, double explus)
 Insert a new point, defined as the x value and explicit asymmetric errors. More...
 
void addPoints (const Points &pts)
 Insert a collection of new points. More...
 
Combining sets of scatter points
void combineWith (const Scatter1D &other)
 
void combineWith (const std::vector< Scatter1D > &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 1D data points with errors.

Definition at line 23 of file Scatter1D.h.

Member Typedef Documentation

◆ Point

Type of the native Point1D collection.

Definition at line 27 of file Scatter1D.h.

◆ Points

typedef Utils::sortedvector<Point1D> YODA::Scatter1D::Points

Definition at line 28 of file Scatter1D.h.

◆ Ptr

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

Definition at line 29 of file Scatter1D.h.

Constructor & Destructor Documentation

◆ Scatter1D() [1/7]

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

Empty constructor.

Definition at line 36 of file Scatter1D.h.

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

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

◆ Scatter1D() [2/7]

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

Constructor from a set of points.

Definition at line 42 of file Scatter1D.h.

44  : AnalysisObject("Scatter1D", path, title),
45  _points(points)
46  { }
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: Scatter1D.h:157

◆ Scatter1D() [3/7]

YODA::Scatter1D::Scatter1D ( const std::vector< double > &  x,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from a vector of x values with no errors.

Definition at line 50 of file Scatter1D.h.

References addPoint().

52  : AnalysisObject("Scatter1D", path, title)
53  {
54  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i]);
55  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:188
const std::string title() const
Get the AO title.

◆ Scatter1D() [4/7]

YODA::Scatter1D::Scatter1D ( const std::vector< double > &  x,
const std::vector< double > &  ex,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from vectors of x values with symmetric errors.

Definition at line 59 of file Scatter1D.h.

References addPoint().

61  : AnalysisObject("Scatter1D", path, title)
62  {
63  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
64  for (size_t i = 0; i < x.size(); ++i) addPoint(x[i], ex[i]);
65  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:188
const std::string title() const
Get the AO title.

◆ Scatter1D() [5/7]

YODA::Scatter1D::Scatter1D ( const std::vector< double > &  x,
const std::vector< std::pair< double, double > > &  ex,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from x values with asymmetric errors.

Definition at line 68 of file Scatter1D.h.

References addPoint().

70  : AnalysisObject("Scatter1D", path, title)
71  {
72  if (x.size() != ex.size()) throw UserError("x and ex vectors must have same length");
73  for (size_t i = 0; i < x.size(); ++i) addPoint(Point1D(x[i], ex[i]));
74  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:188
const std::string title() const
Get the AO title.

◆ Scatter1D() [6/7]

YODA::Scatter1D::Scatter1D ( const std::vector< double > &  x,
const std::vector< double > &  exminus,
const std::vector< double > &  explus,
const std::string &  path = "",
const std::string &  title = "" 
)
inline

Constructor from values with completely explicit asymmetric errors.

Definition at line 78 of file Scatter1D.h.

References addPoint().

82  : AnalysisObject("Scatter1D", path, title)
83  {
84  if (x.size() != exminus.size()) throw UserError("x and ex vectors must have same length");
85  if (exminus.size() != explus.size()) throw UserError("ex plus and minus vectors must have same length");
86  for (size_t i = 0; i < x.size(); ++i) addPoint(Point1D(x[i], exminus[i], explus[i]));
87  }
AnalysisObject()
Default constructor.
const std::string path() const
Get the AO path.
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:188
const std::string title() const
Get the AO title.

◆ Scatter1D() [7/7]

YODA::Scatter1D::Scatter1D ( const Scatter1D s1,
const std::string &  path = "" 
)
inline

Copy constructor with optional new path

Todo:
Also allow title setting from the constructor?

Definition at line 92 of file Scatter1D.h.

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

93  : AnalysisObject("Scatter1D", (path.size() == 0) ? s1.path() : path, s1, s1.title()),
94  _points(s1._points)
95  {
96  for ( auto &ann : annotations()){
97  setAnnotation(ann, annotation(ann));
98  }
99  }
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::Scatter1D::addPoint ( const Point1D pt)
inline

Insert a new point.

Definition at line 188 of file Scatter1D.h.

Referenced by addPoints(), YODA::divide(), YODA::mkScatter(), and Scatter1D().

188  {
189  _points.insert(pt);
190  }

◆ addPoint() [2/5]

void YODA::Scatter1D::addPoint ( double  x)
inline

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

Definition at line 193 of file Scatter1D.h.

193  {
194  _points.insert(Point1D(x));
195  }

◆ addPoint() [3/5]

void YODA::Scatter1D::addPoint ( double  x,
double  ex 
)
inline

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

Definition at line 198 of file Scatter1D.h.

198  {
199  _points.insert(Point1D(x, ex));
200  }

◆ addPoint() [4/5]

void YODA::Scatter1D::addPoint ( double  x,
const std::pair< double, double > &  ex 
)
inline

Insert a new point, defined as the x value and an asymmetric error pair.

Definition at line 203 of file Scatter1D.h.

203  {
204  _points.insert(Point1D(x, ex));
205  }

◆ addPoint() [5/5]

void YODA::Scatter1D::addPoint ( double  x,
double  exminus,
double  explus 
)
inline

Insert a new point, defined as the x value and explicit asymmetric errors.

Definition at line 208 of file Scatter1D.h.

208  {
209  _points.insert(Point1D(x, exminus, explus));
210  }

◆ addPoints()

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

Insert a collection of new points.

Definition at line 213 of file Scatter1D.h.

References addPoint().

Referenced by combineWith().

213  {
214  for (const Point1D& pt : pts) addPoint(pt);
215  }
void addPoint(const Point1D &pt)
Insert a new point.
Definition: Scatter1D.h:188

◆ clone()

Scatter1D YODA::Scatter1D::clone ( ) const
inline

Make a copy on the stack.

Definition at line 110 of file Scatter1D.h.

References Scatter1D().

110  {
111  return Scatter1D(*this);
112  }
Scatter1D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter1D.h:36

◆ combineWith() [1/2]

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

Definition at line 224 of file Scatter1D.h.

References addPoints(), and points().

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

224  {
225  addPoints(other.points());
226  }
void addPoints(const Points &pts)
Insert a collection of new points.
Definition: Scatter1D.h:213

◆ combineWith() [2/2]

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

Better name? Make this the add operation?

Convert/extend to accept a Range or generic

Definition at line 230 of file Scatter1D.h.

References combineWith().

230  {
231  for (const Scatter1D& s : others) combineWith(s);
232  }
Scatter1D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter1D.h:36
void combineWith(const Scatter1D &other)
Definition: Scatter1D.h:224

◆ dim()

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

Dimension of this data object.

Implements YODA::AnalysisObject.

Definition at line 123 of file Scatter1D.h.

123 { return 1; }

◆ newclone()

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

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

Implements YODA::AnalysisObject.

Definition at line 115 of file Scatter1D.h.

References Scatter1D().

115  {
116  return new Scatter1D(*this);
117  }
Scatter1D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter1D.h:36

◆ numPoints()

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

Number of points in the scatter.

Definition at line 151 of file Scatter1D.h.

Referenced by YODA::efficiency(), point(), and YODA::transformX().

151  {
152  return _points.size();
153  }

◆ operator!=()

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

Non-equality operator.

Definition at line 243 of file Scatter1D.h.

References operator==().

243  {
244  return ! operator == (other);
245  }
bool operator==(const Scatter1D &other)
Equality operator.
Definition: Scatter1D.h:238

◆ operator=()

Scatter1D& YODA::Scatter1D::operator= ( const Scatter1D s1)
inline

Assignment operator.

Definition at line 103 of file Scatter1D.h.

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

103  {
104  AnalysisObject::operator = (s1); //< AO treatment of paths etc.
105  _points = s1._points;
106  return *this;
107  }
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.

◆ operator==()

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

Equality operator.

Definition at line 238 of file Scatter1D.h.

Referenced by operator!=().

238  {
239  return _points == other._points;
240  }

◆ point() [1/2]

Point1D& YODA::Scatter1D::point ( size_t  index)
inline

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

Definition at line 169 of file Scatter1D.h.

References numPoints().

Referenced by YODA::efficiency(), YODA::transformX(), and variations().

169  {
170  if (index >= numPoints()) throw RangeError("There is no point with this index");
171  return _points.at(index);
172  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter1D.h:151

◆ point() [2/2]

const Point1D& YODA::Scatter1D::point ( size_t  index) const
inline

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

Definition at line 176 of file Scatter1D.h.

References numPoints().

176  {
177  if (index >= numPoints()) throw RangeError("There is no point with this index");
178  return _points.at(index);
179  }
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter1D.h:151

◆ points() [1/2]

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

Get the collection of points (non-const)

Definition at line 157 of file Scatter1D.h.

Referenced by combineWith(), and YODA::WriterFLAT::writeScatter1D().

157  {
158  return _points;
159  }

◆ points() [2/2]

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

Get the collection of points (const)

Definition at line 163 of file Scatter1D.h.

163  {
164  return _points;
165  }

◆ reset()

void YODA::Scatter1D::reset ( )
inlinevirtual

Clear all points.

Implements YODA::AnalysisObject.

Definition at line 130 of file Scatter1D.h.

130  {
131  _points.clear();
132  }

◆ scaleX()

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

Scaling of x axis.

Definition at line 135 of file Scatter1D.h.

References variations().

135  {
136  for (Point1D& p : _points) p.scaleX(scalex);
137  }

◆ variations()

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

Get the list of variations stored in the points.

Definition at line 18 of file Scatter1D.cc.

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

Referenced by scaleX().

18  {
19  std::vector<std::string> vecvariations;
20  for (auto &point : this->_points){
21  for (auto &it : point.errMap()){
22  //if the variation is not already in the vector, add it !
23  if (std::find(vecvariations.begin(), vecvariations.end(), it.first) == vecvariations.end()){
24  vecvariations.push_back(it.first);
25  }
26  }
27  }
28  return vecvariations;
29  }
Point1D & point(size_t index)
Get a reference to the point with index index (non-const)
Definition: Scatter1D.h:169
const std::map< std::string, std::pair< double, double > > & errMap() const
Get error map for direction i.
Definition: Point1D.h:217

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