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

Namespaces

 SFINAE
 

Classes

class  AnalysisObject
 AnalysisObject is the base class for histograms and scatters. More...
 
class  AnnotationError
 Error for unfound or broken AnalysisObject annotations. More...
 
class  Axis1D
 1D bin container More...
 
class  Axis2D
 2D bin container More...
 
class  Bin
 Base class for bins in 1D and 2D histograms. More...
 
class  Bin1D
 A generic 1D bin type. More...
 
class  Bin2D
 A generic 2D bin type. More...
 
class  Binned1D
 1D binned container of T objects, without outflows More...
 
class  BinningError
 Error for general binning problems. More...
 
struct  CIterable
 
struct  CmpFloats
 Functor to compare two floating point numbers and return whether they are fuzzily equivalent. More...
 
class  Counter
 A weighted counter. More...
 
class  Dbn0D
 A 0D distribution. More...
 
class  Dbn1D
 A 1D distribution. More...
 
class  Dbn2D
 A 2D distribution. More...
 
class  Dbn3D
 A 2D distribution. More...
 
struct  Derefable
 SFINAE definition of dereferenceability trait, cf. Boost has_dereference. More...
 
struct  Derefable< T, SFINAE::void_t< decltype(*std::declval< T >())> >
 
struct  DerefableToAO
 SFINAE struct to check for dereferencing to an AnalysisObject (reference) at compile time. More...
 
struct  DerefableToAO< T, typename std::conditional< std::is_base_of< AnalysisObject, typename std::decay< decltype(*std::declval< T >()) >::type >::value, AnalysisObject, void >::type >
 
class  Error
 An N-dimensional error to be contained in a Point<N> More...
 
class  Exception
 Generic unspecialised YODA runtime error. More...
 
class  GridError
 Error to throw when a slicing is requested on a non-slicable state of an object. More...
 
class  Histo1D
 A one-dimensional histogram. More...
 
class  Histo2D
 A two-dimensional histogram. More...
 
class  HistoBin1D
 A Bin1D specialised for handling histogram-type information. More...
 
class  HistoBin2D
 A Bin2D specialised for handling histogram-type information. More...
 
struct  Iterable
 
class  LockError
 Error for modification of a data object where filling has already begun. More...
 
class  LogicError
 Error for places where it should not have been possible to get to! More...
 
class  LowStatsError
 Errors relating to insufficient (effective) statistics. More...
 
class  Point
 Base class for all Point*Ds, providing generic access to their numerical properties. More...
 
class  Point1D
 A 1D data point to be contained in a Scatter1D. More...
 
class  Point2D
 A 2D data point to be contained in a Scatter2D. More...
 
class  Point3D
 A 3D data point to be contained in a Scatter3D. More...
 
class  Profile1D
 A one-dimensional profile histogram. More...
 
class  Profile2D
 A two-dimensional profile histogram. More...
 
class  ProfileBin1D
 A Bin1D specialised for handling profile-type information. More...
 
class  ProfileBin2D
 A Bin1D specialised for handling profile-type information. More...
 
struct  Pushable
 
class  RangeError
 Error for e.g. use of invalid bin ranges. More...
 
class  Reader
 Pure virtual base class for various output writers. More...
 
class  ReaderAIDA
 Persistency reader for AIDA XML format. More...
 
class  ReaderFLAT
 Persistency reader from YODA flat text data format. More...
 
class  ReadError
 Error for file reading errors. More...
 
class  ReaderYODA
 Persistency reader from YODA text data format. More...
 
class  Scatter
 Abstract base class for all Scatter*Ds. More...
 
class  Scatter1D
 A very generic data type which is just a collection of 1D data points with errors. More...
 
class  Scatter2D
 A very generic data type which is just a collection of 2D data points with errors. More...
 
class  Scatter3D
 A very generic data type which is just a collection of 3D data points with errors. More...
 
class  UserError
 Error for problems introduced outside YODA, to put it nicely. More...
 
class  WeightError
 Errors relating to event/bin weights. More...
 
class  Weights
 A named, vectorised generalisation of an event weight. More...
 
class  WriteError
 Error for file writing errors. More...
 
class  Writer
 Pure virtual base class for various output writers. More...
 
class  WriterAIDA
 Persistency writer for AIDA XML format. More...
 
class  WriterFLAT
 Persistency writer for flat text format. More...
 
class  WriterYODA
 Persistency writer for YODA flat text format. More...
 

Typedefs

using AO = AnalysisObject
 
typedef Axis1D< HistoBin1D, Dbn1DHisto1DAxis
 Convenience typedef. More...
 
typedef Histo1D H1D
 Convenience typedef. More...
 
typedef Axis2D< HistoBin2D, Dbn2DHisto2DAxis
 Convenience typedef. More...
 
typedef Histo2D H2D
 Convenience typedef. More...
 
typedef Axis1D< ProfileBin1D, Dbn2DProfile1DAxis
 Convenience typedef. More...
 
typedef Profile1D P1D
 Convenience typedef. More...
 
typedef Axis2D< ProfileBin2D, Dbn3DProfile2DAxis
 Convenience typedef. More...
 
typedef Profile2D P2D
 Convenience typedef. More...
 
typedef Scatter1D S1D
 Convenience typedef. More...
 
typedef Scatter2D S2D
 Convenience typedef. More...
 
typedef Scatter3D S3D
 Convenience typedef. More...
 

Enumerations

enum  Sign { MINUS = -1, ZERO = 0, PLUS = 1 }
 Enum for signs of numbers. More...
 

Functions

template<typename BIN1D , typename DBN >
Axis1D< BIN1D, DBN > operator+ (const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
 Add the statistics on two axes. More...
 
template<typename BIN1D , typename DBN >
Axis1D< BIN1D, DBN > operator- (const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
 Subtract the statistics on two axis. More...
 
template<class DBN >
Bin1D< DBN > operator+ (const Bin1D< DBN > &a, const Bin1D< DBN > &b)
 
template<class DBN >
Bin1D< DBN > operator- (const Bin1D< DBN > &a, const Bin1D< DBN > &b)
 
template<class DBN >
bool operator< (const Bin1D< DBN > &a, const Bin1D< DBN > &b)
 Bin1Ds are compared for axis sorting by lower edge position. More...
 
template<class DBN >
Bin2D< DBN > operator+ (const Bin2D< DBN > &a, const Bin2D< DBN > &b)
 
template<class DBN >
Bin2D< DBN > operator- (const Bin2D< DBN > &a, const Bin2D< DBN > &b)
 
template<class DBN >
bool operator< (const Bin2D< DBN > &a, const Bin2D< DBN > &b)
 Bin2Ds are compared for axis sorting by lower edge position in first x and then y directions. More...
 
std::string version ()
 Namespaced version string function. More...
 
Dbn0D operator+ (const Dbn0D &a, const Dbn0D &b)
 Add two dbns. More...
 
Dbn0D operator- (const Dbn0D &a, const Dbn0D &b)
 Subtract one dbn from another. More...
 
Dbn1D operator+ (const Dbn1D &a, const Dbn1D &b)
 Add two dbns. More...
 
Dbn1D operator- (const Dbn1D &a, const Dbn1D &b)
 Subtract one dbn from another. More...
 
Dbn2D operator+ (const Dbn2D &a, const Dbn2D &b)
 Add two dbns. More...
 
Dbn2D operator- (const Dbn2D &a, const Dbn2D &b)
 Subtract one dbn from another. More...
 
Dbn3D operator+ (const Dbn3D &a, const Dbn3D &b)
 Add two dbns. More...
 
Dbn3D operator- (const Dbn3D &a, const Dbn3D &b)
 Subtract one dbn from another. More...
 
HistoBin1D operator+ (const HistoBin1D &a, const HistoBin1D &b)
 Add two bins. More...
 
HistoBin1D operator- (const HistoBin1D &a, const HistoBin1D &b)
 Subtract two bins. More...
 
HistoBin2D operator+ (const HistoBin2D &a, const HistoBin2D &b)
 Bin addition operator. More...
 
HistoBin2D operator- (const HistoBin2D &a, const HistoBin2D &b)
 Bin subtraction operator. More...
 
ProfileBin1D operator+ (const ProfileBin1D &a, const ProfileBin1D &b)
 
ProfileBin1D operator- (const ProfileBin1D &a, const ProfileBin1D &b)
 
ProfileBin2D operator+ (const ProfileBin2D &a, const ProfileBin2D &b)
 Bin addition operator. More...
 
ProfileBin2D operator- (const ProfileBin2D &a, const ProfileBin2D &b)
 Bin subtraction operator. More...
 
ReadermkReader (const std::string &format_name)
 Factory function to make a writer object by format name or a filename. More...
 
double chi2 (const HistoBin1D &b1, const HistoBin1D &b2)
 
double chi2 (const Histo1D &h1, const Histo1D &h2)
 
double chi2 (const ProfileBin1D &b1, const ProfileBin1D &b2)
 
double chi2 (const Profile1D &h1, const Profile1D &h2)
 
double chi2 (const Point2D &p1, const Point2D &p2)
 
double chi2 (const Scatter2D &s1, const Scatter2D &s2)
 
std::ostream & operator<< (std::ostream &out, const Weights &w)
 Standard text representaion. More...
 
WritermkWriter (const std::string &format_name)
 Factory function to make a writer object by format name or a filename. More...
 
Combining counters: global operators
Counter add (const Counter &first, const Counter &second)
 Add two counters. More...
 
Counter operator+ (const Counter &first, const Counter &second)
 Add two counters. More...
 
Counter subtract (const Counter &first, const Counter &second)
 Subtract two counters. More...
 
Counter operator- (const Counter &first, const Counter &second)
 Subtract two counters. More...
 
Scatter1D divide (const Counter &numer, const Counter &denom)
 
Scatter1D operator/ (const Counter &numer, const Counter &denom)
 
Scatter1D efficiency (const Counter &accepted, const Counter &total)
 Calculate an efficiency ratio of two counters. More...
 
Comparison operators
template<int N>
bool operator== (const Error< N > &a, const Error< N > &b)
 Equality test. More...
 
template<int N>
bool operator!= (const Error< N > &a, const Error< N > &b)
 Inequality test. More...
 
template<int N>
bool operator< (const Error< N > &a, const Error< N > &b)
 Less-than operator used to sort errors. More...
 
template<int N>
bool operator<= (const Error< N > &a, const Error< N > &b)
 Less-than-or-equals operator used to sort errors. More...
 
template<int N>
bool operator> (const Error< N > &a, const Error< N > &b)
 Greater-than operator used to sort errors. More...
 
template<int N>
bool operator>= (const Error< N > &a, const Error< N > &b)
 Greater-than-or-equals operator used to sort errors. More...
 
bool operator== (const YODA::Point1D &a, const YODA::Point1D &b)
 Equality test of x characteristics only. More...
 
bool operator!= (const YODA::Point1D &a, const YODA::Point1D &b)
 Equality test of x characteristics only. More...
 
bool operator< (const YODA::Point1D &a, const YODA::Point1D &b)
 Less-than operator used to sort bins by x-ordering. More...
 
bool operator<= (const YODA::Point1D &a, const YODA::Point1D &b)
 Less-than-or-equals operator used to sort bins by x-ordering. More...
 
bool operator> (const YODA::Point1D &a, const YODA::Point1D &b)
 Greater-than operator used to sort bins by x-ordering. More...
 
bool operator>= (const YODA::Point1D &a, const YODA::Point1D &b)
 Greater-than-or-equals operator used to sort bins by x-ordering. More...
 
bool operator== (const YODA::Point2D &a, const YODA::Point2D &b)
 
bool operator!= (const YODA::Point2D &a, const YODA::Point2D &b)
 Equality test of x characteristics only. More...
 
bool operator< (const YODA::Point2D &a, const YODA::Point2D &b)
 Less-than operator used to sort bins by x-ordering. More...
 
bool operator<= (const YODA::Point2D &a, const YODA::Point2D &b)
 Less-than-or-equals operator used to sort bins by x-ordering. More...
 
bool operator> (const YODA::Point2D &a, const YODA::Point2D &b)
 Greater-than operator used to sort bins by x-ordering. More...
 
bool operator>= (const YODA::Point2D &a, const YODA::Point2D &b)
 Greater-than-or-equals operator used to sort bins by x-ordering. More...
 
bool operator== (const Point3D &a, const YODA::Point3D &b)
 Equality operator. More...
 
bool operator!= (const Point3D &a, const YODA::Point3D &b)
 Inequality operator. More...
 
bool operator< (const Point3D &a, const YODA::Point3D &b)
 Less-than operator used to sort bins by x-first ordering. More...
 
bool operator<= (const Point3D &a, const YODA::Point3D &b)
 Less-than-or-equals operator. More...
 
bool operator> (const Point3D &a, const YODA::Point3D &b)
 Greater-than operator. More...
 
bool operator>= (const Point3D &a, const YODA::Point3D &b)
 Greater-than-or-equals operator. More...
 
template<int N>
bool operator== (const Point< N > &a, const Point< N > &b)
 Equality test. More...
 
template<int N>
bool operator!= (const Point< N > &a, const Point< N > &b)
 Inequality test. More...
 
template<int N>
bool operator< (const Point< N > &a, const Point< N > &b)
 Less-than operator used to sort points. More...
 
template<int N>
bool operator<= (const Point< N > &a, const Point< N > &b)
 Less-than-or-equals operator used to sort points. More...
 
template<int N>
bool operator> (const Point< N > &a, const Point< N > &b)
 Greater-than operator used to sort points. More...
 
template<int N>
bool operator>= (const Point< N > &a, const Point< N > &b)
 Greater-than-or-equals operator used to sort points. More...
 
Combining histos: global operators
Histo1D add (const Histo1D &first, const Histo1D &second)
 Add two histograms. More...
 
Histo1D operator+ (const Histo1D &first, const Histo1D &second)
 Add two histograms. More...
 
Histo1D subtract (const Histo1D &first, const Histo1D &second)
 Subtract two histograms. More...
 
Histo1D operator- (const Histo1D &first, const Histo1D &second)
 Subtract two histograms. More...
 
Scatter2D divide (const Histo1D &numer, const Histo1D &denom)
 
Scatter2D operator/ (const Histo1D &numer, const Histo1D &denom)
 
Scatter2D add (const Histo1D &histo, const Scatter2D &scatt)
 Add histogram and scatter. More...
 
Scatter2D add (const Scatter2D &scatt, const Histo1D &histo)
 
Scatter2D subtract (const Histo1D &histo, const Scatter2D &scatt)
 Subtract scatter from histogram. More...
 
Scatter2D subtract (const Scatter2D &scatt, const Histo1D &histo)
 Subtract histogram from scatter. More...
 
Scatter2D multiply (const Histo1D &histo, const Scatter2D &scatt)
 Multiply histogram with scatter. More...
 
Scatter2D multiply (const Scatter2D &scatt, const Histo1D &histo)
 Multiply scatter with histogram. More...
 
Scatter2D divide (const Histo1D &numer, const Scatter2D &denom)
 Divide histogram by scatter. More...
 
Scatter2D divide (const Scatter2D &numer, const Histo1D &denom)
 Divide scatter by histogram. More...
 
Scatter2D efficiency (const Histo1D &accepted, const Histo1D &total)
 Calculate a histogrammed efficiency ratio of two histograms. More...
 
Scatter2D asymm (const Histo1D &a, const Histo1D &b)
 Calculate the asymmetry (a-b)/(a+b) of two histograms. More...
 
Scatter2D toIntegralHisto (const Histo1D &h, bool includeunderflow=true)
 Convert a Histo1D to a Scatter2D representing the integral of the histogram. More...
 
Scatter2D toIntegralEfficiencyHisto (const Histo1D &h, bool includeunderflow=true, bool includeoverflow=true)
 Convert a Histo1D to a Scatter2D where each bin is a fraction of the total. More...
 
Histo2D add (const Histo2D &first, const Histo2D &second)
 Add two histograms. More...
 
Histo2D operator+ (const Histo2D &first, const Histo2D &second)
 Add two histograms. More...
 
Histo2D subtract (const Histo2D &first, const Histo2D &second)
 Subtract two histograms. More...
 
Histo2D operator- (const Histo2D &first, const Histo2D &second)
 Subtract two histograms. More...
 
Scatter3D divide (const Histo2D &numer, const Histo2D &denom)
 Divide two histograms, with an uncorrelated error treatment. More...
 
Scatter3D operator/ (const Histo2D &numer, const Histo2D &denom)
 
Scatter3D efficiency (const Histo2D &accepted, const Histo2D &total)
 Calculate a histogrammed efficiency ratio of two histograms. More...
 
Scatter3D asymm (const Histo2D &a, const Histo2D &b)
 Calculate the asymmetry (a-b)/(a+b) of two histograms. More...
 
Writer functions to files (with automatic format detection)
void write (const std::string &filename, const AnalysisObject &ao)
 Write out object ao to file filename. More...
 
template<typename RANGE >
void write (const std::string &filename, const RANGE &aos)
 Write out a collection of objects objs to file filename. More...
 
template<typename AOITER >
void write (const std::string &filename, const AOITER &begin, const AOITER &end)
 
Writer functions to streams (with explicit format specification)
void write (std::ostream &os, const AnalysisObject &ao, const std::string &fmt)
 Write out object ao to stream os with format fmt. More...
 
template<typename RANGE >
void write (std::ostream &os, const RANGE &aos, const std::string &fmt)
 Write out a collection of objects objs to file filename. More...
 
template<typename AOITER >
void write (std::ostream &os, const AOITER &begin, const AOITER &end, const std::string &fmt)
 
Reader functions from files (with automatic format detection)
void read (const std::string &filename, std::vector< AnalysisObject *> &aos)
 Read in a collection of objects objs from file filename. More...
 
std::vector< AnalysisObject * > read (const std::string &filename)
 Read in a collection of objects from file filename. More...
 
Reader functions from streams (with explicit format specification)
void read (std::istream &is, std::vector< AnalysisObject *> &aos, const std::string &fmt)
 Read in a collection of objects objs from stream is, expecting format fmt. More...
 
std::vector< AnalysisObject * > read (std::istream &is, const std::string &fmt)
 Read in a collection of objects from stream is, expecting format fmt. More...
 
Combining profile histos: global operators
Profile1D add (const Profile1D &first, const Profile1D &second)
 Add two profile histograms. More...
 
Profile1D operator+ (const Profile1D &first, const Profile1D &second)
 Add two profile histograms. More...
 
Profile1D subtract (const Profile1D &first, const Profile1D &second)
 Subtract two profile histograms. More...
 
Profile1D operator- (const Profile1D &first, const Profile1D &second)
 Subtract two profile histograms. More...
 
Scatter2D divide (const Profile1D &numer, const Profile1D &denom)
 Divide two profile histograms. More...
 
Scatter2D operator/ (const Profile1D &numer, const Profile1D &denom)
 Divide two profile histograms. More...
 
Profile2D add (const Profile2D &first, const Profile2D &second)
 Add two profile histograms. More...
 
Profile2D operator+ (const Profile2D &first, const Profile2D &second)
 Add two profile histograms. More...
 
Profile2D subtract (const Profile2D &first, const Profile2D &second)
 Subtract two profile histograms. More...
 
Profile2D operator- (const Profile2D &first, const Profile2D &second)
 Subtract two profile histograms. More...
 
Scatter3D divide (const Profile2D &numer, const Profile2D &denom)
 Divide two profile histograms. More...
 
Scatter3D operator/ (const Profile2D &numer, const Profile2D &denom)
 Divide two profile histograms. More...
 
Conversion functions from ROOT to YODA data types
Scatter2D toScatter2D (const TH1 &th1, bool scalebywidth=true)
 
Scatter2D toScatter2D (const TH1 *th1, bool scalebywidth=true)
 Convert a ROOT 1D histogram (excluding TProfile) to a YODA Scatter2D. More...
 
Scatter2DtoNewScatter2D (const TH1 &th1, bool scalebywidth=true)
 Convert a ROOT 1D histogram (excluding TProfile) to a new'd YODA Scatter2D. More...
 
Scatter2DtoNewScatter2D (const TH1 *th1, bool scalebywidth=true)
 Convert a ROOT 1D histogram (excluding TProfile) to a new'd YODA Scatter2D. More...
 
Scatter2D toScatter2D (const TProfile &tp1)
 Convert a ROOT TProfile to a YODA Scatter2D. More...
 
Scatter2D toScatter2D (const TProfile *tp1)
 Convert a ROOT TProfile to a YODA Scatter2D. More...
 
Scatter2DtoNewScatter2D (const TProfile &tp1)
 Convert a ROOT TProfile to a new'd YODA Scatter2D. More...
 
Scatter2DtoNewScatter2D (const TProfile *tp1)
 Convert a ROOT TProfile to a new'd YODA Scatter2D. More...
 
Scatter3D toScatter3D (const TH2 &th2, bool scalebyarea=true)
 
Scatter3D toScatter3D (const TH2 *th2, bool scalebyarea=true)
 Convert a ROOT 2D histogram to a YODA Scatter3D. More...
 
Scatter3DtoNewScatter3D (const TH2 &th2, bool scalebyarea=true)
 Convert a ROOT 2D histogram to a new'd YODA Scatter3D. More...
 
Scatter3DtoNewScatter3D (const TH2 *th2, bool scalebyarea=true)
 Convert a ROOT 2D histogram to a new'd YODA Scatter3D. More...
 
Conversion functions from YODA to ROOT data types
Todo:
Add toScatter2D(TGraph&/*) and toScatter3D(TGraph2D&/*)
TH1D toTH1D (const Histo1D &h)
 Convert a YODA Histo1D to a ROOT 1D histogram. More...
 
TH1D * toNewTH1D (const Histo1D &h, const std::string &rootname)
 Convert a YODA Histo1D to a ROOT 1D histogram as new'd pointer. More...
 
TH2D toTH2D (const Histo2D &h)
 Convert a YODA Histo2D to a ROOT 2D histogram. More...
 
TH2D * toNewTH2D (const Histo2D &h, const std::string &rootname)
 Convert a YODA Histo2D to a ROOT 2D histogram as new'd pointer. More...
 
TProfile toTProfile (const Profile1D &p)
 Convert a YODA Scatter2D to a ROOT TH1D. More...
 
TH1D toTH1D (const Profile1D &p)
 Convert a YODA Profile1D to a ROOT TH1D. More...
 
TProfile * toNewTProfile (const Profile1D &p, const std::string &rootname)
 Convert a YODA Profile1D to a ROOT TProfile as new'd pointer. More...
 
TGraphAsymmErrors toTGraph (const Scatter2D &s)
 Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors. More...
 
TGraphAsymmErrors * toNewTGraph (const Scatter2D &s, const std::string &rootname)
 Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors as new'd pointer. More...
 
TGraphAsymmErrors toTGraph (const Histo1D &h)
 Convert a YODA Histo1D to a ROOT TGraphAsymmErrors. More...
 
TGraphAsymmErrors * toNewTGraph (const Histo1D &h, const std::string &rootname)
 Convert a YODA Histo1D to a ROOT TGraphAsymmErrors as new'd pointer. More...
 
TGraphAsymmErrors toTGraph (const Profile1D &p)
 Convert a YODA Profile1D to a ROOT TGraphAsymmErrors. More...
 
TGraphAsymmErrors * toNewTGraph (const Profile1D &p, const std::string &rootname)
 Convert a YODA Profile1D to a ROOT TGraphAsymmErrors as new'd pointer. More...
 
Combining scatters by merging sets of points
Scatter1D combine (const Scatter1D &a, const Scatter1D &b)
 
Scatter1D combine (const std::vector< Scatter1D > &scatters)
 
Scatter2D combine (const Scatter2D &a, const Scatter2D &b)
 
Scatter2D combine (const std::vector< Scatter2D > &scatters)
 
Scatter3D combine (const Scatter3D &a, const Scatter3D &b)
 
Scatter3D combine (const std::vector< Scatter3D > &scatters)
 
template<int N>
Scatter< N > combine (const Scatter< N > &a, const Scatter< N > &b)
 
template<int N>
Scatter< N > combine (const std::vector< Scatter< N > > &scatters)
 
Conversion functions from other data types
Scatter1D mkScatter (const Counter &c)
 Make a Scatter1D representation of a Histo1D. More...
 
Scatter1D mkScatter (const Scatter1D &s)
 
Scatter2D mkScatter (const Histo1D &h, bool usefocus)
 Make a Scatter2D representation of a Histo1D. More...
 
Scatter2D mkScatter (const Profile1D &p, bool usefocus, bool usestddev)
 Make a Scatter2D representation of a Profile1D. More...
 
Scatter2D mkScatter (const Scatter2D &s)
 
Scatter3D mkScatter (const Histo2D &h, bool usefocus=false)
 
Scatter3D mkScatter (const Profile2D &p, bool usefocus=false, bool usestddev=false)
 
Scatter3D mkScatter (const Scatter3D &s)
 
Transforming operations on Scatter1D
template<typename FNX >
void transformX (Scatter1D &s, FNX fx)
 Apply transformation fx(x) to all values and error positions (operates in-place on s) More...
 
Transforming operations on Scatter2D
template<typename FNX >
void transformX (Scatter2D &s, FNX fx)
 Apply transformation fx(x) to all values and error positions (operates in-place on s) More...
 
template<typename FNY >
void transformY (Scatter2D &s, FNY fy)
 Apply transformation fy(y) to all values and error positions (operates in-place on s) More...
 
void flip (Scatter2D &s)
 Exchange the x and y axes (operates in-place on s) More...
 
Transforming operations on Scatter3D
template<typename FNX >
void transformX (Scatter3D &s, FNX fx)
 Apply transformation fx(x) to all values and error positions (operates in-place on s) More...
 
template<typename FNY >
void transformY (Scatter3D &s, FNY fy)
 Apply transformation fy(y) to all values and error positions (operates in-place on s) More...
 
template<typename FNZ >
void transformZ (Scatter3D &s, FNZ fz)
 Apply transformation fz(z) to all values and error positions (operates in-place on s) More...
 
Comparison functions for safe floating point equality tests
bool isZero (double val, double tolerance=1E-8)
 
bool isZero (long val, double=1E-8)
 
bool fuzzyEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for equality with a degree of fuzziness. More...
 
bool fuzzyEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for equality with a degree of fuzziness. More...
 
bool fuzzyGtrEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for >= with a degree of fuzziness. More...
 
bool fuzzyGtrEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for >= with a degree of fuzziness. More...
 
bool fuzzyLessEquals (double a, double b, double tolerance=1E-5)
 Compare two floating point numbers for <= with a degree of fuzziness. More...
 
bool fuzzyLessEquals (long a, long b, double=1E-5)
 Compare two integral-type numbers for <= with a degree of fuzziness. More...
 
double approx (double a, int n=5)
 Returns a number floored at the nth decimal place. More...
 
Miscellaneous numerical helpers
template<typename NUM >
NUM sqr (NUM a)
 Named number-type squaring operation. More...
 
template<typename Num >
Num add_quad (Num a, Num b)
 Named number-type addition in quadrature operation. More...
 
template<typename Num >
Num add_quad (Num a, Num b, Num c)
 Named number-type addition in quadrature operation. More...
 
int sign (double val)
 Find the sign of a number. More...
 
int sign (int val)
 Find the sign of a number. More...
 
int sign (long val)
 Find the sign of a number. More...
 
Binning helper functions
std::vector< double > linspace (size_t nbins, double start, double end, bool include_end=true)
 Make a list of nbins + 1 values equally spaced between start and end inclusive. More...
 
std::vector< double > logspace (size_t nbins, double start, double end, bool include_end=true)
 Make a list of nbins + 1 values exponentially spaced between start and end inclusive. More...
 
template<typename NUM >
int index_between (const NUM &val, const std::vector< NUM > &binedges)
 Return the bin index of the given value, val, given a vector of bin edges. More...
 
Statistics functions
double mean (const std::vector< int > &sample)
 Calculate the mean of a sample. More...
 
double covariance (const std::vector< int > &sample1, const std::vector< int > &sample2)
 Calculate the covariance (variance) between two samples. More...
 
double correlation (const std::vector< int > &sample1, const std::vector< int > &sample2)
 Calculate the correlation strength between two samples. More...
 
Combining weights: global operators
Weights operator+ (const Weights &first, const Weights &second)
 Add two weights. More...
 
Weights operator- (const Weights &first, const Weights &second)
 Subtract two weights. More...
 
Weights operator* (const Weights &first, const Weights &second)
 Multiply two weights. More...
 
Weights operator/ (const Weights &numer, const Weights &denom)
 Divide two weights. More...
 
Weights operator* (double a, const Weights &w)
 Multiply by a double. More...
 
Weights operator* (const Weights &w, double a)
 Multiply by a double. More...
 
Weights operator/ (const Weights &w, double a)
 Divide by a double. More...
 
Weights operator/ (double a, const Weights &w)
 

Variables

static const double MAXDOUBLE = DBL_MAX
 
static const double MAXINT = INT_MAX
 
static const double PI = M_PI
 A pre-defined value of $ \pi $. More...
 
static const double TWOPI = 2*M_PI
 A pre-defined value of $ 2\pi $. More...
 
static const double HALFPI = M_PI_2
 A pre-defined value of $ \pi/2 $. More...
 
static const int YODA_FORMAT_VERSION = 2
 

Ranges and intervals

enum  RangeBoundary { OPEN =0, SOFT =0, CLOSED =1, HARD =1 }
 
template<typename NUM >
bool inRange (NUM value, NUM low, NUM high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Determine if value is in the range low to high, for floating point numbers. More...
 
template<typename NUM >
bool inRange (NUM value, std::pair< NUM, NUM > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for doubles, which accepts a pair for the range arguments. More...
 
bool inRange (int value, int low, int high, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=CLOSED)
 Determine if value is in the range low to high, for integer types. More...
 
bool inRange (int value, std::pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
 Alternative version of inRange for ints, which accepts a pair for the range arguments. More...
 

Detailed Description

Todo:
Add SFINAE math type stuff (see Rivet) and add inrange() and inrange_closed_closed() etc. aliases cf. MCUtils

Typedef Documentation

◆ AO

using YODA::AO = typedef AnalysisObject

Definition at line 296 of file AnalysisObject.h.

◆ H1D

typedef Histo1D YODA::H1D

Convenience typedef.

Definition at line 417 of file Histo1D.h.

◆ H2D

typedef Histo2D YODA::H2D

Convenience typedef.

Definition at line 454 of file Histo2D.h.

◆ Histo1DAxis

Convenience typedef.

Definition at line 23 of file Histo1D.h.

◆ Histo2DAxis

Convenience typedef.

Definition at line 24 of file Histo2D.h.

◆ P1D

Convenience typedef.

Definition at line 363 of file Profile1D.h.

◆ P2D

Convenience typedef.

Definition at line 404 of file Profile2D.h.

◆ Profile1DAxis

Convenience typedef.

Definition at line 25 of file Profile1D.h.

◆ Profile2DAxis

Convenience typedef.

Definition at line 24 of file Profile2D.h.

◆ S1D

Convenience typedef.

Definition at line 260 of file Scatter1D.h.

◆ S2D

Convenience typedef.

Definition at line 293 of file Scatter2D.h.

◆ S3D

Convenience typedef.

Definition at line 307 of file Scatter3D.h.

Enumeration Type Documentation

◆ RangeBoundary

Represents whether an interval is open (non-inclusive) or closed (inclusive).

For example, the interval $ [0, \pi) $ is closed (an inclusive boundary) at 0, and open (a non-inclusive boundary) at $ \pi $.

Enumerator
OPEN 
SOFT 
CLOSED 
HARD 

Definition at line 147 of file MathUtils.h.

◆ Sign

enum YODA::Sign

Enum for signs of numbers.

Enumerator
MINUS 
ZERO 
PLUS 

Definition at line 47 of file MathUtils.h.

47 { MINUS = -1, ZERO = 0, PLUS = 1 };

Function Documentation

◆ add() [1/7]

Counter YODA::add ( const Counter first,
const Counter second 
)
inline

Add two counters.

Definition at line 236 of file Counter.h.

Referenced by add(), operator+(), and operator/().

236  {
237  Counter tmp = first;
238  tmp += second;
239  return tmp;
240  }

◆ add() [2/7]

Profile1D YODA::add ( const Profile1D first,
const Profile1D second 
)
inline

Add two profile histograms.

Definition at line 371 of file Profile1D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

371  {
372  Profile1D tmp = first;
373  if (first.path() != second.path()) tmp.setPath("");
374  tmp += second;
375  return tmp;
376  }

◆ add() [3/7]

Profile2D YODA::add ( const Profile2D first,
const Profile2D second 
)
inline

Add two profile histograms.

Definition at line 411 of file Profile2D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

411  {
412  Profile2D tmp = first;
413  if (first.path() != second.path()) tmp.setPath("");
414  tmp += second;
415  return tmp;
416  }

◆ add() [4/7]

Histo1D YODA::add ( const Histo1D first,
const Histo1D second 
)
inline

Add two histograms.

Definition at line 424 of file Histo1D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

424  {
425  Histo1D tmp = first;
426  if (first.path() != second.path()) tmp.setPath("");
427  tmp += second;
428  return tmp;
429  }

◆ add() [5/7]

Histo2D YODA::add ( const Histo2D first,
const Histo2D second 
)
inline

Add two histograms.

Definition at line 461 of file Histo2D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

461  {
462  Histo2D tmp = first;
463  if (first.path() != second.path()) tmp.setPath("");
464  tmp += second;
465  return tmp;
466  }

◆ add() [6/7]

Scatter2D YODA::add ( const Histo1D histo,
const Scatter2D scatt 
)

Add histogram and scatter.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

Definition at line 200 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

200  {
201  if (histo.numBins() != scatt.numPoints()) throw BinningError("Histogram binning incompatible with number of scatter points");
202 
203  Scatter2D rtn = scatt.clone();
204  if (histo.path() != scatt.path()) rtn.setPath("");
205  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
206 
207  for (size_t i = 0; i < rtn.numPoints(); ++i) {
208  const HistoBin1D& b = histo.bin(i);
209  const Point2D& s = scatt.point(i);
210 
212  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
213  throw BinningError("x binnings are not equivalent in " + histo.path() + " + " + scatt.path());
214 
215 
216  // convert bin to scatter point
217  double biny;
218  try {
219  biny = b.height();
220  } catch (const Exception&) { // LowStatsError or WeightError
221  biny = 0;
222  }
223  double biney;
224  try {
225  biney = b.heightErr();
226  } catch (const Exception&) { // LowStatsError or WeightError
227  biney = 0;
228  }
229  // combine with scatter values
230  double newy = biny + s.y();
231  double newey_p = sqrt(sqr(biney) + sqr(s.yErrPlus()));
232  double newey_m = sqrt(sqr(biney) + sqr(s.yErrMinus()));
233  // set new values
234  Point2D& t = rtn.point(i);
235  t.setY(newy);
236  t.setYErrMinus(newey_p);
237  t.setYErrPlus(newey_m);
238  }
239 
240  assert(rtn.numPoints() == histo.numBins());
241  return rtn;
242  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ add() [7/7]

Scatter2D YODA::add ( const Scatter2D scatt,
const Histo1D histo 
)
inline

Definition at line 475 of file Histo1D.h.

References add(), multiply(), and subtract().

475  {
476  return add(histo, scatt);
477  }
Scatter2D add(const Scatter2D &scatt, const Histo1D &histo)
Definition: Histo1D.h:475

◆ add_quad() [1/2]

template<typename Num >
Num YODA::add_quad ( Num  a,
Num  b 
)
inline

Named number-type addition in quadrature operation.

Definition at line 213 of file MathUtils.h.

Referenced by chi2(), and divide().

213  {
214  return sqrt(a*a + b*b);
215  }

◆ add_quad() [2/2]

template<typename Num >
Num YODA::add_quad ( Num  a,
Num  b,
Num  c 
)
inline

Named number-type addition in quadrature operation.

Definition at line 219 of file MathUtils.h.

219  {
220  return sqrt(a*a + b*b + c*c);
221  }

◆ approx()

double YODA::approx ( double  a,
int  n = 5 
)
inline

Returns a number floored at the nth decimal place.

Definition at line 131 of file MathUtils.h.

131  {
132  double roundTo = pow(10.0,n);
133  a *= roundTo;
134  a = floor(a);
135  return a/roundTo;
136  }

◆ asymm() [1/2]

Scatter2D YODA::asymm ( const Histo1D a,
const Histo1D b 
)
inline

Calculate the asymmetry (a-b)/(a+b) of two histograms.

Note
The two histos must have exactly the same binning.

Definition at line 515 of file Histo1D.h.

References toIntegralEfficiencyHisto(), and toIntegralHisto().

515  {
516  return (a-b) / (a+b);
517  }

◆ asymm() [2/2]

Scatter3D YODA::asymm ( const Histo2D a,
const Histo2D b 
)
inline

Calculate the asymmetry (a-b)/(a+b) of two histograms.

Note
The two histos must have exactly the same binning.

Definition at line 521 of file Histo2D.h.

521  {
522  return (a-b) / (a+b);
523  }

◆ chi2() [1/6]

double YODA::chi2 ( const HistoBin1D b1,
const HistoBin1D b2 
)
Todo:
Optional arg for additional (fractional/abs?) "syst" error?
Todo:
Check that binnings are compatible

Definition at line 8 of file Stats.h.

References add_quad(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), and sqr().

Referenced by chi2().

8  {
10  const double diff = b1.height() - b2.height();
11  return sqr(diff) / add_quad(b1.heightErr(), b2.heightErr()); //< Histo errs are symmetric
12  }
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:213

◆ chi2() [2/6]

double YODA::chi2 ( const Histo1D h1,
const Histo1D h2 
)
Todo:
Optional arg for additional (fractional/abs?) "syst" error?
Todo:
Check that binnings are compatible

Definition at line 15 of file Stats.h.

References YODA::Histo1D::bin(), chi2(), and YODA::Histo1D::numBins().

15  {
17  double hist_chi2 = 0;
18  BOOST_FOREACH (size_t i = 0; i < h1.numBins(); ++i) {
19  hist_chi2 += chi2(h1.bin(i), h2.bin(i));
20  }
21  return hist_chi2;
22  }
double chi2(const Scatter2D &s1, const Scatter2D &s2)
Definition: Stats.h:56

◆ chi2() [3/6]

double YODA::chi2 ( const ProfileBin1D b1,
const ProfileBin1D b2 
)
Todo:
Optional arg for additional (fractional/abs?) "syst" error?
Todo:
Check that binnings are compatible

Definition at line 27 of file Stats.h.

References add_quad(), YODA::ProfileBin1D::mean(), sqr(), and YODA::ProfileBin1D::stdErr().

27  {
29  const double diff = b1.mean() - b2.mean();
30  return sqr(diff) / add_quad(b1.stdErr(), b2.stdErr()); //< Profile histo errs are symmetric
31  }
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:213

◆ chi2() [4/6]

double YODA::chi2 ( const Profile1D h1,
const Profile1D h2 
)
Todo:
Optional arg for additional (fractional/abs?) "syst" error?
Todo:
Check that binnings are compatible

Definition at line 34 of file Stats.h.

References YODA::Profile1D::bin(), chi2(), and YODA::Profile1D::numBins().

34  {
36  double hist_chi2 = 0;
37  BOOST_FOREACH (size_t i = 0; i < h1.numBins(); ++i) {
38  hist_chi2 += chi2(h1.bin(i), h2.bin(i));
39  }
40  return hist_chi2;
41  }
double chi2(const Scatter2D &s1, const Scatter2D &s2)
Definition: Stats.h:56

◆ chi2() [5/6]

double YODA::chi2 ( const Point2D p1,
const Point2D p2 
)
Todo:

This assumes that y is the value... probably true, but ugly. Comparison axis spec arg?

Optional arg for additional (fractional/abs?) "syst" error?

Todo:
Check that "binnings" are compatible

Definition at line 47 of file Stats.h.

References add_quad(), sqr(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

47  {
49  const double diff = p1.y() - p2.y();
50  const double err1 = (diff > 0) ? p1.yErrMinus() : p1.yErrPlus(); //< Scatter errs are asymmetric
51  const double err2 = (diff > 0) ? p2.yErrPlus() : p2.yErrMinus(); //< Scatter errs are asymmetric
52  return sqr(diff) / add_quad(err1, err2);
53  }
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:213

◆ chi2() [6/6]

double YODA::chi2 ( const Scatter2D s1,
const Scatter2D s2 
)
Todo:
Optional arg for additional (fractional/abs?) "syst" error?
Todo:
Check that binnings are compatible

Definition at line 56 of file Stats.h.

References chi2(), YODA::Scatter2D::numPoints(), and YODA::Scatter2D::point().

56  {
58  double hist_chi2 = 0;
59  BOOST_FOREACH (size_t i = 0; i < s1.numPoints(); ++i) {
60  hist_chi2 += chi2(s1.point(i), s2.point(i));
61  }
62  return hist_chi2;
63  }
double chi2(const Scatter2D &s1, const Scatter2D &s2)
Definition: Stats.h:56

◆ combine() [1/8]

template<int N>
Scatter<N> YODA::combine ( const Scatter< N > &  a,
const Scatter< N > &  b 
)
inline

Definition at line 230 of file ScatterND.h.

230  {
231  Scatter<N> rtn = a;
232  rtn.combineWith(b);
233  return rtn;
234  }

◆ combine() [2/8]

template<int N>
Scatter<N> YODA::combine ( const std::vector< Scatter< N > > &  scatters)
inline

Definition at line 237 of file ScatterND.h.

237  {
238  Scatter<N> rtn;
239  rtn.combineWith(scatters);
240  return rtn;
241  }

◆ combine() [3/8]

Scatter1D YODA::combine ( const Scatter1D a,
const Scatter1D b 
)
inline

Definition at line 266 of file Scatter1D.h.

References YODA::Scatter1D::combineWith().

266  {
267  Scatter1D rtn = a;
268  rtn.combineWith(b);
269  return rtn;
270  }

◆ combine() [4/8]

Scatter1D YODA::combine ( const std::vector< Scatter1D > &  scatters)
inline

Definition at line 272 of file Scatter1D.h.

References YODA::Scatter1D::combineWith(), and mkScatter().

272  {
273  Scatter1D rtn;
274  rtn.combineWith(scatters);
275  return rtn;
276  }

◆ combine() [5/8]

Scatter2D YODA::combine ( const Scatter2D a,
const Scatter2D b 
)
inline

Definition at line 299 of file Scatter2D.h.

References YODA::Scatter2D::combineWith().

299  {
300  Scatter2D rtn = a;
301  rtn.combineWith(b);
302  return rtn;
303  }

◆ combine() [6/8]

Scatter2D YODA::combine ( const std::vector< Scatter2D > &  scatters)
inline

Definition at line 305 of file Scatter2D.h.

References YODA::Scatter2D::combineWith(), and mkScatter().

305  {
306  Scatter2D rtn;
307  rtn.combineWith(scatters);
308  return rtn;
309  }

◆ combine() [7/8]

Scatter3D YODA::combine ( const Scatter3D a,
const Scatter3D b 
)
inline

Definition at line 313 of file Scatter3D.h.

References YODA::Scatter3D::combineWith().

313  {
314  Scatter3D rtn = a;
315  rtn.combineWith(b);
316  return rtn;
317  }

◆ combine() [8/8]

Scatter3D YODA::combine ( const std::vector< Scatter3D > &  scatters)
inline

Definition at line 319 of file Scatter3D.h.

References YODA::Scatter3D::combineWith(), and mkScatter().

319  {
320  Scatter3D rtn;
321  rtn.combineWith(scatters);
322  return rtn;
323  }

◆ correlation()

double YODA::correlation ( const std::vector< int > &  sample1,
const std::vector< int > &  sample2 
)
inline

Calculate the correlation strength between two samples.

Definition at line 339 of file MathUtils.h.

References covariance().

339  {
340  const double cov = covariance(sample1, sample2);
341  const double var1 = covariance(sample1, sample1);
342  const double var2 = covariance(sample2, sample2);
343  const double correlation = cov/sqrt(var1*var2);
344  const double corr_strength = correlation*sqrt(var2/var1);
345  return corr_strength;
346  }
double covariance(const std::vector< int > &sample1, const std::vector< int > &sample2)
Calculate the covariance (variance) between two samples.
Definition: MathUtils.h:324
double correlation(const std::vector< int > &sample1, const std::vector< int > &sample2)
Calculate the correlation strength between two samples.
Definition: MathUtils.h:339

◆ covariance()

double YODA::covariance ( const std::vector< int > &  sample1,
const std::vector< int > &  sample2 
)
inline

Calculate the covariance (variance) between two samples.

Definition at line 324 of file MathUtils.h.

References mean().

Referenced by correlation().

324  {
325  const double mean1 = mean(sample1);
326  const double mean2 = mean(sample2);
327  const size_t N = sample1.size();
328  double cov = 0.0;
329  for (size_t i = 0; i < N; i++) {
330  const double cov_i = (sample1[i] - mean1)*(sample2[i] - mean2);
331  cov += cov_i;
332  }
333  if (N > 1) return cov/(N-1);
334  else return 0.0;
335  }
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition: MathUtils.h:314

◆ divide() [1/7]

Scatter1D YODA::divide ( const Counter numer,
const Counter denom 
)

Divide two counters, with an uncorrelated error treatment

Todo:
Or just return a Point1D?
Todo:
Add skipnullpts extra optional arg

Definition at line 25 of file Counter.cc.

References add_quad(), YODA::Scatter1D::addPoint(), YODA::Counter::err(), YODA::Counter::relErr(), and YODA::Counter::val().

Referenced by efficiency(), multiply(), operator-(), and operator/().

25  {
26  Scatter1D rtn;
27  if (denom.val() != 0) {
28  const double val = numer.val() / denom.val();
29  const double err = val * add_quad(numer.relErr(), denom.relErr());
30  rtn.addPoint(val, err);
31  } else {
32  rtn.addPoint(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
33  }
34  return rtn;
35  }
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:213

◆ divide() [2/7]

Scatter2D YODA::divide ( const Profile1D numer,
const Profile1D denom 
)

Divide two profile histograms.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.

Definition at line 155 of file Profile1D.cc.

References YODA::Scatter2D::addPoint(), YODA::Profile1D::bin(), fuzzyEquals(), YODA::ProfileBin1D::mean(), YODA::Profile1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), sqr(), YODA::ProfileBin1D::stdErr(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMid(), and YODA::Bin1D< DBN >::xMin().

155  {
156  Scatter2D rtn;
157 
158  for (size_t i = 0; i < numer.numBins(); ++i) {
159  const ProfileBin1D& b1 = numer.bin(i);
160  const ProfileBin1D& b2 = denom.bin(i);
161 
163  if (!fuzzyEquals(b1.xMin(), b2.xMin()) || !fuzzyEquals(b1.xMax(), b2.xMax()))
164  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
165 
166  // Assemble the x value and error
167  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
168  const double x = b1.xMid();
169  const double exminus = x - b1.xMin();
170  const double explus = b1.xMax() - x;
171 
172  // Assemble the y value and error
173  double y = std::numeric_limits<double>::quiet_NaN();
174  double ey = std::numeric_limits<double>::quiet_NaN();
175  try {
176  if (b2.mean() == 0 || (b1.mean() == 0 && b1.stdErr() != 0)) {
177  // y = std::numeric_limits<double>::quiet_NaN();
178  // ey = std::numeric_limits<double>::quiet_NaN();
179  // throw LowStatsError("Requested division of empty bin");
180  } else {
181  y = b1.mean() / b2.mean();
183  const double relerr_1 = b1.stdErr() != 0 ? b1.stdErr()/b1.mean() : 0;
184  const double relerr_2 = b2.stdErr() != 0 ? b2.stdErr()/b2.mean() : 0;
185  ey = y * sqrt(sqr(relerr_1) + sqr(relerr_2));
186  }
187  } catch (const LowStatsError& e) {
188  // y = std::numeric_limits<double>::quiet_NaN();
189  // ey = std::numeric_limits<double>::quiet_NaN();
190  }
191 
194  //const double eyplus = y * sqrt( sqr(p1.yErrPlus()/p1.y()) + sqr(p2.yErrMinus()/p2.y()) );
195  //const double eyminus = y * sqrt( sqr(p1.yErrMinus()/p1.y()) + sqr(p2.yErrPlus()/p2.y()) );
196  rtn.addPoint(x, y, exminus, explus, ey, ey);
197  }
198 
199  assert(rtn.numPoints() == numer.numBins());
200  return rtn;
201  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ divide() [3/7]

Scatter3D YODA::divide ( const Profile2D numer,
const Profile2D denom 
)

Divide two profile histograms.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.

Definition at line 189 of file Profile2D.cc.

References YODA::Scatter3D::addPoint(), YODA::Profile2D::bin(), fuzzyEquals(), YODA::ProfileBin2D::mean(), YODA::Profile2D::numBins(), YODA::Scatter3D::numPoints(), YODA::AnalysisObject::path(), sqr(), YODA::ProfileBin2D::stdErr(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMid(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yMax(), YODA::Bin2D< DBN >::yMid(), and YODA::Bin2D< DBN >::yMin().

189  {
190  Scatter3D rtn;
191 
192  for (size_t i = 0; i < numer.numBins(); ++i) {
193  const ProfileBin2D& b1 = numer.bin(i);
194  const ProfileBin2D& b2 = denom.bin(i);
195 
197  if (!fuzzyEquals(b1.xMin(), b2.xMin()) || !fuzzyEquals(b1.xMax(), b2.xMax()))
198  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
199  if (!fuzzyEquals(b1.yMin(), b2.yMin()) || !fuzzyEquals(b1.yMax(), b2.yMax()))
200  throw BinningError("y binnings are not equivalent in " + numer.path() + " / " + denom.path());
201 
202  // Assemble the x value and error
203  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
204  const double x = b1.xMid();
205  const double exminus = x - b1.xMin();
206  const double explus = b1.xMax() - x;
207 
208  // Assemble the y value and error
209  // Use the midpoint of the "bin" for the new central y value, in the absence of better information
210  const double y = b1.yMid();
211  const double eyminus = y - b1.yMin();
212  const double eyplus = b1.yMax() - y;
213 
214  // Assemble the z value and error
215  double z = std::numeric_limits<double>::quiet_NaN();
216  double ez = std::numeric_limits<double>::quiet_NaN();
217  try {
218  if (b2.mean() == 0 || (b1.mean() == 0 && b1.stdErr() != 0)) {
219  // z = std::numeric_limits<double>::quiet_NaN();
220  // ez = std::numeric_limits<double>::quiet_NaN();
221  // throw LowStatsError("Requested division of empty bin");
222  } else {
223  z = b1.mean() / b2.mean();
225  const double relerr_1 = b1.stdErr() != 0 ? b1.stdErr()/b1.mean() : 0;
226  const double relerr_2 = b2.stdErr() != 0 ? b2.stdErr()/b2.mean() : 0;
227  ez = z * sqrt(sqr(relerr_1) + sqr(relerr_2));
228  }
229  } catch (const LowStatsError& e) {
230  // z = std::numeric_limits<double>::quiet_NaN();
231  // ez = std::numeric_limits<double>::quiet_NaN();
232  }
233 
236  //const double eyplus = y * sqrt( sqr(p1.yErrPlus()/p1.y()) + sqr(p2.yErrMinus()/p2.y()) );
237  //const double eyminus = y * sqrt( sqr(p1.yErrMinus()/p1.y()) + sqr(p2.yErrPlus()/p2.y()) );
238  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
239  }
240 
241  assert(rtn.numPoints() == numer.numBins());
242  return rtn;
243  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ divide() [4/7]

Scatter2D YODA::divide ( const Histo1D numer,
const Histo1D denom 
)
Todo:
Add multiply(H1, H1) -> Scatter2D?

Divide two histograms, with an uncorrelated error treatment

Todo:
Wouldn't it be nice to be able to supply a correlation matrix or function as optional arg?
Note
The two histos must have exactly the same binning.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Provide optional alt behaviours to fill with NaN or remove the invalid point or throw

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Provide optional alt behaviours to fill with NaN or remove the invalid point or throw

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.

Definition at line 153 of file Histo1D.cc.

References YODA::Scatter2D::addPoint(), YODA::Histo1D::bin(), fuzzyEquals(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::HistoBin1D::relErr(), sqr(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMid(), and YODA::Bin1D< DBN >::xMin().

153  {
154  Scatter2D rtn;
155 
156  for (size_t i = 0; i < numer.numBins(); ++i) {
157  const HistoBin1D& b1 = numer.bin(i);
158  const HistoBin1D& b2 = denom.bin(i);
159 
161  if (!fuzzyEquals(b1.xMin(), b2.xMin()) || !fuzzyEquals(b1.xMax(), b2.xMax()))
162  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
163 
164  // Assemble the x value and error
165  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
166  const double x = b1.xMid();
167  const double exminus = x - b1.xMin();
168  const double explus = b1.xMax() - x;
169 
170  // Assemble the y value and error
172  double y, ey;
173  if (b2.height() == 0 || (b1.height() == 0 && b1.heightErr() != 0)) {
174  y = std::numeric_limits<double>::quiet_NaN();
175  ey = std::numeric_limits<double>::quiet_NaN();
176  // throw LowStatsError("Requested division of empty bin");
177  } else {
178  y = b1.height() / b2.height();
180  const double relerr_1 = b1.heightErr() != 0 ? b1.relErr() : 0;
181  const double relerr_2 = b2.heightErr() != 0 ? b2.relErr() : 0;
182  ey = y * sqrt(sqr(relerr_1) + sqr(relerr_2));
183  }
184 
187  //const double eyplus = y * sqrt( sqr(p1.yErrPlus()/p1.y()) + sqr(p2.yErrMinus()/p2.y()) );
188  //const double eyminus = y * sqrt( sqr(p1.yErrMinus()/p1.y()) + sqr(p2.yErrPlus()/p2.y()) );
189  rtn.addPoint(x, y, exminus, explus, ey, ey);
190  }
191 
192  assert(rtn.numPoints() == numer.numBins());
193  return rtn;
194  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ divide() [5/7]

Scatter2D YODA::divide ( const Histo1D numer,
const Scatter2D denom 
)

Divide histogram by scatter.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?

Definition at line 392 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::HistoBin1D::relErr(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

392  {
393  if (numer.numBins() != denom.numPoints()) throw BinningError("Histogram binning incompatible with number of scatter points");
394 
395  Scatter2D rtn = denom.clone();
396  if (numer.path() != denom.path()) rtn.setPath("");
397  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
398 
399  for (size_t i = 0; i < rtn.numPoints(); ++i) {
400  const HistoBin1D& b = numer.bin(i);
401  const Point2D& s = denom.point(i);
402 
404  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
405  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
406 
407 
408  // convert bin to scatter point
409  double biny;
410  try {
411  biny = b.height();
412  } catch (const Exception&) { // LowStatsError or WeightError
413  biny = 0;
414  }
415  double biney;
416  try {
417  biney = b.relErr();
418  } catch (const Exception&) { // LowStatsError or WeightError
419  biney = 0;
420  }
421  // combine with scatter values
422  double newy, newey_p, newey_m;
423  if (s.y() == 0 || (b.height() == 0 && b.heightErr() != 0)) {
424  newy = std::numeric_limits<double>::quiet_NaN();
425  newey_m = newey_p = std::numeric_limits<double>::quiet_NaN();
426  // throw LowStatsError("Requested division of empty bin");
427  } else {
428  newy = biny / s.y();
429  newey_p = newy * sqrt(sqr(biney) + sqr(s.yErrPlus() / s.y()));
430  newey_m = newy * sqrt(sqr(biney) + sqr(s.yErrMinus() / s.y()));
431  }
432  // set new values
433  Point2D& t = rtn.point(i);
434  t.setY(newy);
435  t.setYErrMinus(newey_p);
436  t.setYErrPlus(newey_m);
437  }
438 
439  assert(rtn.numPoints() == numer.numBins());
440  return rtn;
441  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ divide() [6/7]

Scatter2D YODA::divide ( const Scatter2D numer,
const Histo1D denom 
)

Divide scatter by histogram.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?

Definition at line 447 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::HistoBin1D::relErr(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrAvg(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

447  {
448  if (numer.numPoints() != denom.numBins()) throw BinningError("Histogram binning incompatible with number of scatter points");
449 
450  Scatter2D rtn = numer.clone();
451  if (numer.path() != denom.path()) rtn.setPath("");
452  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
453 
454  for (size_t i = 0; i < rtn.numPoints(); ++i) {
455  const Point2D& s = numer.point(i);
456  const HistoBin1D& b = denom.bin(i);
457 
459  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
460  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
461 
462 
463  // convert bin to scatter point
464  double biny;
465  try {
466  biny = b.height();
467  } catch (const Exception&) { // LowStatsError or WeightError
468  biny = 0;
469  }
470  double biney;
471  try {
472  biney = b.relErr();
473  } catch (const Exception&) { // LowStatsError or WeightError
474  biney = 0;
475  }
476  // combine with scatter values
477  double newy, newey_p, newey_m;
478  if (b.height() == 0 || (s.y() == 0 && s.yErrAvg() != 0)) {
479  newy = std::numeric_limits<double>::quiet_NaN();
480  newey_m = newey_p = std::numeric_limits<double>::quiet_NaN();
481  // throw LowStatsError("Requested division of empty bin");
482  } else {
483  newy = s.y() / biny;
484  newey_p = newy * sqrt(sqr(biney) + sqr(s.yErrPlus() / s.y()));
485  newey_m = newy * sqrt(sqr(biney) + sqr(s.yErrMinus() / s.y()));
486  }
487  // set new values
488  Point2D& t = rtn.point(i);
489  t.setY(newy);
490  t.setYErrMinus(newey_p);
491  t.setYErrPlus(newey_m);
492  }
493 
494  assert(rtn.numPoints() == denom.numBins());
495  return rtn;
496  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ divide() [7/7]

Scatter3D YODA::divide ( const Histo2D numer,
const Histo2D denom 
)

Divide two histograms, with an uncorrelated error treatment.

Todo:
Add multiply(H2, H2) -> Scatter3D?
Todo:
Wouldn't it be nice to be able to supply a correlation matrix or function as optional arg?
Note
The two histos must have exactly the same binning.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

<

Todo:
Ok?
Todo:
Is this the exact error treatment for all (uncorrelated) cases? Behaviour around 0? +1 and -1 fills?

Deal with +/- errors separately, inverted for the denominator contributions:

Todo:
check correctness with different signed numerator and denominator.

Definition at line 316 of file Histo2D.cc.

References YODA::Scatter3D::addPoint(), YODA::Histo2D::bin(), fuzzyEquals(), YODA::HistoBin2D::height(), YODA::HistoBin2D::heightErr(), YODA::Histo2D::numBins(), YODA::Scatter3D::numPoints(), YODA::AnalysisObject::path(), YODA::HistoBin2D::relErr(), sqr(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMid(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yMax(), YODA::Bin2D< DBN >::yMid(), and YODA::Bin2D< DBN >::yMin().

316  {
317  Scatter3D rtn;
318 
319  for (size_t i = 0; i < numer.numBins(); ++i) {
320  const HistoBin2D& b1 = numer.bin(i);
321  const HistoBin2D& b2 = denom.bin(i);
322 
324  if (!fuzzyEquals(b1.xMin(), b2.xMin()) || !fuzzyEquals(b1.xMax(), b2.xMax()))
325  throw BinningError("x binnings are not equivalent in " + numer.path() + " / " + denom.path());
326  if (!fuzzyEquals(b1.yMin(), b2.yMin()) || !fuzzyEquals(b1.yMax(), b2.yMax()))
327  throw BinningError("y binnings are not equivalent in " + numer.path() + " / " + denom.path());
328 
329  // Assemble the x value and error
330  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
331  const double x = b1.xMid();
332  const double exminus = x - b1.xMin();
333  const double explus = b1.xMax() - x;
334 
335  // Assemble the y value and error
336  // Use the midpoint of the "bin" for the new central y value, in the absence of better information
337  const double y = b1.yMid();
338  const double eyminus = y - b1.yMin();
339  const double eyplus = b1.yMax() - y;
340 
341  // Assemble the z value and error
342  double z = std::numeric_limits<double>::quiet_NaN();
343  double ez = std::numeric_limits<double>::quiet_NaN();
344  if (b2.height() == 0 || (b1.height() == 0 && b1.heightErr() != 0)) {
345  // z = std::numeric_limits<double>::quiet_NaN();
346  // ez = std::numeric_limits<double>::quiet_NaN();
347  // throw LowStatsError("Requested division of empty bin");
348  } else {
349  z = b1.height() / b2.height();
351  const double relerr_1 = b1.heightErr() != 0 ? b1.relErr() : 0;
352  const double relerr_2 = b2.heightErr() != 0 ? b2.relErr() : 0;
353  ez = z * sqrt(sqr(relerr_1) + sqr(relerr_2));
354  }
357  //const double eyplus = y * sqrt( sqr(p1.yErrPlus()/p1.y()) + sqr(p2.yErrMinus()/p2.y()) );
358  //const double eyminus = y * sqrt( sqr(p1.yErrMinus()/p1.y()) + sqr(p2.yErrPlus()/p2.y()) );
359  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
360  }
361 
362  assert(rtn.numPoints() == numer.numBins());
363  return rtn;
364  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ efficiency() [1/3]

Scatter1D YODA::efficiency ( const Counter accepted,
const Counter total 
)

Calculate an efficiency ratio of two counters.

Todo:
Add divide functions/operators on pointers

Note that an efficiency is not the same thing as a standard division of two histograms: the errors must be treated as correlated

Todo:
Or just return a Point1D?
Todo:
Add skipnullpts extra optional arg

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Todo:
Provide optional alt behaviours to fill with NaN or remove the invalid point, or...
Todo:
Or throw a LowStatsError exception if h.effNumEntries() (or sumW()?) == 0?

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Todo:
Provide optional alt behaviours to fill with NaN or remove the invalid point, or...
Todo:
Or throw a LowStatsError exception if h.effNumEntries() (or sumW()?) == 0?

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Definition at line 40 of file Counter.cc.

References divide(), YODA::Counter::err(), YODA::Counter::numEntries(), YODA::Scatter1D::numPoints(), YODA::Scatter1D::point(), YODA::Point1D::setX(), sqr(), YODA::Counter::sumW(), and YODA::Counter::sumW2().

Referenced by multiply(), and operator/().

40  {
41  Scatter1D tmp = divide(accepted, total);
42  assert(tmp.numPoints() == 1);
43 
45 
46  // Check that the numerator is consistent with being a subset of the denominator (NOT effNumEntries here!)
47  if (accepted.numEntries() > total.numEntries() || accepted.sumW() > total.sumW())
48  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator");
49 
50  // If no entries on the denominator, set eff = err = 0 and move to the next bin
53  double eff = std::numeric_limits<double>::quiet_NaN();
54  double err = std::numeric_limits<double>::quiet_NaN();
55  if (total.sumW() != 0) {
56  eff = accepted.sumW() / total.sumW(); //< Actually this is already calculated by the division...
57  err = sqrt(abs( ((1-2*eff)*accepted.sumW2() + sqr(eff)*total.sumW2()) / sqr(total.sumW()) ));
58  }
59 
61 
62  tmp.point(0).setX(eff, err);
63  return tmp;
64  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ efficiency() [2/3]

Scatter2D YODA::efficiency ( const Histo1D accepted,
const Histo1D total 
)

Calculate a histogrammed efficiency ratio of two histograms.

Todo:
Add functions/operators on pointers
Note
The two histos must have exactly the same binning.
An efficiency is not the same thing as a standard division of two histograms: the errors are treated as correlated via binomial statistics.
Todo:
Add functions/operators on pointers

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

Note
Neither effNumEntries nor sumW are guaranteed to satisfy num <= den for general weights!

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

Note
Neither effNumEntries nor sumW are guaranteed to satisfy num <= den for general weights!

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

Definition at line 503 of file Histo1D.cc.

References YODA::Histo1D::bin(), divide(), YODA::Histo1D::numBins(), YODA::Bin1D< DBN >::numEntries(), and YODA::Scatter2D::point().

503  {
504  Scatter2D tmp = divide(accepted, total);
505  for (size_t i = 0; i < accepted.numBins(); ++i) {
506  const HistoBin1D& b_acc = accepted.bin(i);
507  const HistoBin1D& b_tot = total.bin(i);
508  Point2D& point = tmp.point(i);
509 
511 
512  // Check that the numerator is consistent with being a subset of the denominator
514  if (b_acc.numEntries() > b_tot.numEntries())
515  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator: "
516  + Utils::toStr(b_acc.numEntries()) + " entries / " + Utils::toStr(b_tot.numEntries()) + " entries");
517 
518  // If no entries on the denominator, set eff = err = 0 and move to the next bin
519  double eff = std::numeric_limits<double>::quiet_NaN();
520  double err = std::numeric_limits<double>::quiet_NaN();
521  try {
522  if (b_tot.sumW() != 0) {
523  eff = b_acc.sumW() / b_tot.sumW(); //< Actually this is already calculated by the division...
524  err = sqrt(abs( ((1-2*eff)*b_acc.sumW2() + sqr(eff)*b_tot.sumW2()) / sqr(b_tot.sumW()) ));
525  }
526  } catch (const LowStatsError& e) {
527  //
528  }
529 
531 
532  point.setY(eff, err);
533  }
534  return tmp;
535  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ efficiency() [3/3]

Scatter3D YODA::efficiency ( const Histo2D accepted,
const Histo2D total 
)

Calculate a histogrammed efficiency ratio of two histograms.

Note
The two histos must have exactly the same binning.
An efficiency is not the same thing as a standard division of two histograms: the errors are treated as correlated via binomial statistics.

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Note
Neither effNumEntries nor sumW are guaranteed to satisfy num <= den for general weights!

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Note
Neither effNumEntries nor sumW are guaranteed to satisfy num <= den for general weights!

END DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H1

Definition at line 367 of file Histo2D.cc.

References YODA::Histo2D::bin(), divide(), YODA::Histo2D::numBins(), YODA::Bin2D< DBN >::numEntries(), and YODA::Scatter3D::point().

367  {
368  Scatter3D tmp = divide(accepted, total);
369  for (size_t i = 0; i < accepted.numBins(); ++i) {
370  const HistoBin2D& b_acc = accepted.bin(i);
371  const HistoBin2D& b_tot = total.bin(i);
372  Point3D& point = tmp.point(i);
373 
375 
376  // Check that the numerator is consistent with being a subset of the denominator
378  if (b_acc.numEntries() > b_tot.numEntries())
379  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator: "
380  + Utils::toStr(b_acc.numEntries()) + " entries / " + Utils::toStr(b_tot.numEntries()) + " entries");
381 
382  // If no entries on the denominator, set eff = err = 0 and move to the next bin
383  double eff = std::numeric_limits<double>::quiet_NaN();
384  double err = std::numeric_limits<double>::quiet_NaN();
385  try {
386  if (b_tot.sumW() != 0) {
387  eff = b_acc.sumW() / b_tot.sumW(); //< Actually this is already calculated by the division...
388  err = sqrt(abs( ((1-2*eff)*b_acc.sumW2() + sqr(eff)*b_tot.sumW2()) / sqr(b_tot.sumW()) ));
389  }
390  } catch (const LowStatsError& e) {
391  //
392  }
393 
395 
396  point.setZ(eff, err);
397  }
398  return tmp;
399 
400  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ flip()

void YODA::flip ( Scatter2D s)
inline

Exchange the x and y axes (operates in-place on s)

Todo:
Add external scale, scaleX, scaleY functions
Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 397 of file Scatter2D.h.

References YODA::Scatter2D::numPoints(), YODA::Scatter2D::point(), YODA::Point2D::setX(), YODA::Point2D::setXErrMinus(), YODA::Point2D::setXErrPlus(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), YODA::Point2D::x(), YODA::Point2D::xMax(), YODA::Point2D::xMin(), YODA::Point2D::y(), YODA::Point2D::yMax(), and YODA::Point2D::yMin().

397  {
398  for (size_t i = 0; i < s.numPoints(); ++i) {
399  Point2D& p = s.point(i);
400  const double newx = p.y();
401  const double newy = p.x();
402  const double newxmin = p.yMin();
403  const double newxmax = p.yMax();
404  const double newymin = p.xMin();
405  const double newymax = p.xMax();
406  p.setX(newx);
407  p.setY(newy);
409  p.setXErrMinus(newx - newxmin);
410  p.setXErrPlus(newxmax - newx);
411  p.setYErrMinus(newy - newymin);
412  p.setYErrPlus(newymax - newy);
413  }
414  }

◆ fuzzyEquals() [1/2]

bool YODA::fuzzyEquals ( double  a,
double  b,
double  tolerance = 1E-5 
)
inline

Compare two floating point numbers for equality with a degree of fuzziness.

The tolerance parameter is fractional, based on absolute values of the args.

Definition at line 72 of file MathUtils.h.

References isZero().

Referenced by YODA::Bin1D< Dbn2D >::add(), add(), YODA::Bin2D< Dbn3D >::adjacentTo(), divide(), fuzzyGtrEquals(), fuzzyLessEquals(), YODA::Bin1D< Dbn2D >::merge(), multiply(), operator<(), operator==(), YODA::Axis2D< BIN2D, DBN >::operator==(), YODA::Axis1D< BIN1D, DBN >::rebinTo(), YODA::Binned1D< T >::sameBinning(), YODA::Bin1D< Dbn2D >::subtract(), subtract(), toTH1D(), and toTProfile().

72  {
73  const double absavg = (fabs(a) + fabs(b))/2.0;
74  const double absdiff = fabs(a - b);
75  const bool rtn = (isZero(a) && isZero(b)) || absdiff < tolerance*absavg;
76  // cout << a << " == " << b << "? " << rtn << endl;
77  return rtn;
78  }
bool isZero(long val, double=1E-8)
Definition: MathUtils.h:64

◆ fuzzyEquals() [2/2]

bool YODA::fuzzyEquals ( long  a,
long  b,
double  = 1E-5 
)
inline

Compare two integral-type numbers for equality with a degree of fuzziness.

Since there is no risk of floating point error with integral types, this function just exists in case fuzzyEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.

Definition at line 88 of file MathUtils.h.

88  {
89  return a == b;
90  }

◆ fuzzyGtrEquals() [1/2]

bool YODA::fuzzyGtrEquals ( double  a,
double  b,
double  tolerance = 1E-5 
)
inline

Compare two floating point numbers for >= with a degree of fuzziness.

The tolerance parameter on the equality test is as for fuzzyEquals.

Definition at line 96 of file MathUtils.h.

References fuzzyEquals().

96  {
97  return a > b || fuzzyEquals(a, b, tolerance);
98  }
bool fuzzyEquals(long a, long b, double=1E-5)
Compare two integral-type numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:88

◆ fuzzyGtrEquals() [2/2]

bool YODA::fuzzyGtrEquals ( long  a,
long  b,
double  = 1E-5 
)
inline

Compare two integral-type numbers for >= with a degree of fuzziness.

Since there is no risk of floating point error with integral types, this function just exists in case fuzzyGtrEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.

Definition at line 107 of file MathUtils.h.

107  {
108  return a >= b;
109  }

◆ fuzzyLessEquals() [1/2]

bool YODA::fuzzyLessEquals ( double  a,
double  b,
double  tolerance = 1E-5 
)
inline

Compare two floating point numbers for <= with a degree of fuzziness.

The tolerance parameter on the equality test is as for fuzzyEquals.

Definition at line 115 of file MathUtils.h.

References fuzzyEquals().

Referenced by YODA::Dbn1D::xVariance().

115  {
116  return a < b || fuzzyEquals(a, b, tolerance);
117  }
bool fuzzyEquals(long a, long b, double=1E-5)
Compare two integral-type numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:88

◆ fuzzyLessEquals() [2/2]

bool YODA::fuzzyLessEquals ( long  a,
long  b,
double  = 1E-5 
)
inline

Compare two integral-type numbers for <= with a degree of fuzziness.

Since there is no risk of floating point error with integral types, this function just exists in case fuzzyLessEquals is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored, even if it would have an absolute magnitude greater than 1.

Definition at line 126 of file MathUtils.h.

126  {
127  return a <= b;
128  }

◆ index_between()

template<typename NUM >
int YODA::index_between ( const NUM &  val,
const std::vector< NUM > &  binedges 
)
inline

Return the bin index of the given value, val, given a vector of bin edges.

NB. The binedges vector must be sorted

Definition at line 294 of file MathUtils.h.

References inRange().

294  {
295  if (!inRange(val, binedges.front(), binedges.back())) return -1; //< Out of histo range
296  int index = -1;
297  for (size_t i = 1; i < binedges.size(); ++i) {
298  if (val < binedges[i]) {
299  index = i-1;
300  break;
301  }
302  }
303  assert(inRange(index, -1, binedges.size()-1));
304  return index;
305  }
bool inRange(int value, std::pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
Alternative version of inRange for ints, which accepts a pair for the range arguments.
Definition: MathUtils.h:194

◆ inRange() [1/4]

template<typename NUM >
bool YODA::inRange ( NUM  value,
NUM  low,
NUM  high,
RangeBoundary  lowbound = CLOSED,
RangeBoundary  highbound = OPEN 
)
inline

Determine if value is in the range low to high, for floating point numbers.

Interval boundary types are defined by lowbound and highbound.

Todo:
Optimise to one-line at compile time?

Definition at line 155 of file MathUtils.h.

References CLOSED, and OPEN.

Referenced by YODA::Profile1D::fill(), YODA::Histo2D::fill(), YODA::Profile2D::fill(), YODA::Histo1D::fill(), index_between(), and inRange().

156  {
157  if (lowbound == OPEN && highbound == OPEN) {
158  return (value > low && value < high);
159  } else if (lowbound == OPEN && highbound == CLOSED) {
160  return (value > low && value <= high);
161  } else if (lowbound == CLOSED && highbound == OPEN) {
162  return (value >= low && value < high);
163  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
164  return (value >= low && value <= high);
165  }
166  }

◆ inRange() [2/4]

template<typename NUM >
bool YODA::inRange ( NUM  value,
std::pair< NUM, NUM >  lowhigh,
RangeBoundary  lowbound = CLOSED,
RangeBoundary  highbound = OPEN 
)
inline

Alternative version of inRange for doubles, which accepts a pair for the range arguments.

Definition at line 170 of file MathUtils.h.

References inRange().

171  {
172  return inRange(value, lowhigh.first, lowhigh.second, lowbound, highbound);
173  }
bool inRange(int value, std::pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
Alternative version of inRange for ints, which accepts a pair for the range arguments.
Definition: MathUtils.h:194

◆ inRange() [3/4]

bool YODA::inRange ( int  value,
int  low,
int  high,
RangeBoundary  lowbound = CLOSED,
RangeBoundary  highbound = CLOSED 
)
inline

Determine if value is in the range low to high, for integer types.

Interval boundary types are defined by lowbound and highbound.

Todo:
Optimise to one-line at compile time?

Definition at line 180 of file MathUtils.h.

References CLOSED, and OPEN.

181  {
182  if (lowbound == OPEN && highbound == OPEN) {
183  return (value > low && value < high);
184  } else if (lowbound == OPEN && highbound == CLOSED) {
185  return (value > low && value <= high);
186  } else if (lowbound == CLOSED && highbound == OPEN) {
187  return (value >= low && value < high);
188  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
189  return (value >= low && value <= high);
190  }
191  }

◆ inRange() [4/4]

bool YODA::inRange ( int  value,
std::pair< int, int >  lowhigh,
RangeBoundary  lowbound = CLOSED,
RangeBoundary  highbound = OPEN 
)
inline

Alternative version of inRange for ints, which accepts a pair for the range arguments.

Definition at line 194 of file MathUtils.h.

References inRange().

195  {
196  return inRange(value, lowhigh.first, lowhigh.second, lowbound, highbound);
197  }
bool inRange(int value, std::pair< int, int > lowhigh, RangeBoundary lowbound=CLOSED, RangeBoundary highbound=OPEN)
Alternative version of inRange for ints, which accepts a pair for the range arguments.
Definition: MathUtils.h:194

◆ isZero() [1/2]

bool YODA::isZero ( double  val,
double  tolerance = 1E-8 
)
inline

Compare a floating point number to zero with a degree of fuzziness expressed by the absolute tolerance parameter.

Definition at line 55 of file MathUtils.h.

Referenced by fuzzyEquals(), sign(), YODA::Bin1D< Dbn2D >::xFocus(), YODA::Bin2D< Dbn3D >::xFocus(), and YODA::Bin2D< Dbn3D >::yFocus().

55  {
56  return (fabs(val) < tolerance);
57  }

◆ isZero() [2/2]

bool YODA::isZero ( long  val,
double  = 1E-8 
)
inline

Compare an integral-type number to zero.

Since there is no risk of floating point error, this function just exists in case isZero is accidentally used on an integer type, to avoid implicit type conversion. The tolerance parameter is ignored.

Definition at line 64 of file MathUtils.h.

64  {
65  return val == 0;
66  }

◆ linspace()

std::vector<double> YODA::linspace ( size_t  nbins,
double  start,
double  end,
bool  include_end = true 
)
inline

Make a list of nbins + 1 values equally spaced between start and end inclusive.

NB. The arg ordering and the meaning of the nbins variable is "histogram-like", as opposed to the Numpy/Matlab version.

Definition at line 252 of file MathUtils.h.

Referenced by YODA::Axis1D< BIN1D, DBN >::Axis1D(), YODA::Axis2D< BIN2D, DBN >::Axis2D(), YODA::Binned1D< T >::Binned1D(), and logspace().

252  {
253  assert(end >= start);
254  assert(nbins > 0);
255  std::vector<double> rtn;
256  const double interval = (end-start)/static_cast<double>(nbins);
257  for (size_t i = 0; i < nbins; ++i) {
258  rtn.push_back(start + i*interval);
259  }
260  assert(rtn.size() == nbins);
261  if (include_end) rtn.push_back(end); // exact end, not result of n * interval
262  return rtn;
263  }

◆ logspace()

std::vector<double> YODA::logspace ( size_t  nbins,
double  start,
double  end,
bool  include_end = true 
)
inline

Make a list of nbins + 1 values exponentially spaced between start and end inclusive.

NB. The arg ordering and the meaning of the nbins variable is "histogram-like", as opposed to the Numpy/Matlab version, and the start and end arguments are expressed in "normal" space, rather than as the logarithms of the start/end values as in Numpy/Matlab.

Definition at line 271 of file MathUtils.h.

References linspace().

271  {
272  assert(end >= start);
273  assert(start > 0);
274  assert(nbins > 0);
275  const double logstart = std::log(start);
276  const double logend = std::log(end);
277  const std::vector<double> logvals = linspace(nbins, logstart, logend);
278  assert(logvals.size() == nbins+1);
279  std::vector<double> rtn; rtn.reserve(logvals.size());
280  rtn.push_back(start);
281  for (size_t i = 1; i < logvals.size()-1; ++i) {
282  rtn.push_back(std::exp(logvals[i]));
283  }
284  assert(rtn.size() == nbins);
285  if (include_end) rtn.push_back(end);
286  return rtn;
287  }
std::vector< double > linspace(size_t nbins, double start, double end, bool include_end=true)
Make a list of nbins + 1 values equally spaced between start and end inclusive.
Definition: MathUtils.h:252

◆ mean()

double YODA::mean ( const std::vector< int > &  sample)
inline

Calculate the mean of a sample.

Definition at line 314 of file MathUtils.h.

Referenced by covariance().

314  {
315  double mean = 0.0;
316  for (size_t i=0; i<sample.size(); ++i) {
317  mean += sample[i];
318  }
319  return mean/sample.size();
320  }
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition: MathUtils.h:314

◆ mkReader()

Reader & YODA::mkReader ( const std::string &  format_name)

Factory function to make a writer object by format name or a filename.

<

Todo:
Improve/remove... .ydat?

<

Todo:
Improve/remove... .ydat?

Definition at line 17 of file Reader.cc.

Referenced by read(), and YODA::Reader::read().

17  {
18  // Determine the format from the string (a file or file extension)
19  const size_t lastdot = name.find_last_of(".");
20  string fmt = Utils::toLower(lastdot == string::npos ? name : name.substr(lastdot+1));
21  if (fmt == "gz") {
22  #ifndef HAVE_LIBZ
23  throw UserError("YODA was compiled without zlib support: can't read " + name);
24  #endif
25  const size_t lastbutonedot = (lastdot == string::npos) ? string::npos : name.find_last_of(".", lastdot-1);
26  fmt = Utils::toLower(lastbutonedot == string::npos ? name : name.substr(lastbutonedot+1));
27  }
28  // Create the appropriate Reader
29  if (Utils::startswith(fmt, "yoda")) return ReaderYODA::create();
30  if (Utils::startswith(fmt, "aida")) return ReaderAIDA::create();
31  if (Utils::startswith(fmt, "dat" )) return ReaderFLAT::create();
32  if (Utils::startswith(fmt, "flat")) return ReaderFLAT::create();
33  throw UserError("Format cannot be identified from string '" + name + "'");
34  }

◆ mkScatter() [1/8]

Scatter1D YODA::mkScatter ( const Counter c)

Make a Scatter1D representation of a Histo1D.

Definition at line 9 of file Scatter1D.cc.

References YODA::Scatter1D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Counter::err(), YODA::AnalysisObject::setAnnotation(), YODA::AnalysisObject::type(), and YODA::Counter::val().

Referenced by combine(), toIntegralHisto(), toTGraph(), YODA::WriterFLAT::writeHisto1D(), YODA::WriterAIDA::writeHisto1D(), YODA::WriterFLAT::writeHisto2D(), YODA::WriterFLAT::writeProfile1D(), YODA::WriterAIDA::writeProfile1D(), and YODA::WriterFLAT::writeProfile2D().

9  {
10  Scatter1D rtn;
11  for (const std::string& a : c.annotations())
12  rtn.setAnnotation(a, c.annotation(a));
13  rtn.setAnnotation("Type", c.type()); // might override the copied ones
14  rtn.addPoint(c.val(), c.err());
15  return rtn;
16  }

◆ mkScatter() [2/8]

Scatter1D YODA::mkScatter ( const Scatter1D s)
inline

Make a Scatter1D representation of... erm, a Scatter1D!

Note
Mainly exists to allow mkScatter to be called on any AnalysisObject type

Definition at line 291 of file Scatter1D.h.

References YODA::Scatter1D::Scatter1D().

291  {
292  return Scatter1D(s);
293  }

◆ mkScatter() [3/8]

Scatter2D YODA::mkScatter ( const Histo1D h,
bool  usefocus = false 
)

Make a Scatter2D representation of a Histo1D.

Make a Scatter2D representation of a Histo1D

Optional usefocus argument can be used to position the point at the bin focus rather than geometric midpoint.

Definition at line 10 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Histo1D::bins(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::setAnnotation(), and YODA::AnalysisObject::type().

10  {
11  Scatter2D rtn;
12  for (const std::string& a : h.annotations())
13  rtn.setAnnotation(a, h.annotation(a));
14  rtn.setAnnotation("Type", h.type()); // might override the copied ones
15  for (const HistoBin1D& b : h.bins()) {
16  const double x = usefocus ? b.xFocus() : b.xMid();
17  const double ex_m = x - b.xMin();
18  const double ex_p = b.xMax() - x;
19 
20  double y;
21  try {
22  y = b.height();
23  } catch (const Exception&) { // LowStatsError or WeightError
24  y = std::numeric_limits<double>::quiet_NaN();
25  }
26  double ey;
27  try {
28  ey = b.heightErr();
29  } catch (const Exception&) { // LowStatsError or WeightError
30  ey = std::numeric_limits<double>::quiet_NaN();
31  }
32 
33  const Point2D pt(x, y, ex_m, ex_p, ey, ey);
34  rtn.addPoint(pt);
35  }
36  assert(h.numBins() == rtn.numPoints());
37  return rtn;
38  }

◆ mkScatter() [4/8]

Scatter2D YODA::mkScatter ( const Profile1D p,
bool  usefocus = false,
bool  usestddev = false 
)

Make a Scatter2D representation of a Profile1D.

Make a Scatter2D representation of a Profile1D

Optional usefocus argument can be used to position the point at the bin focus rather than geometric midpoint. Optional usestddev argument can be used to draw the y-distribution sigma rather than the standard error on the mean as the y-error bar size.

< Control y-error scheme via usestddev arg

< Control y-error scheme via usestddev arg

Definition at line 42 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Profile1D::bins(), YODA::Profile1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::setAnnotation(), and YODA::AnalysisObject::type().

42  {
43  Scatter2D rtn;
44  for (const std::string& a : p.annotations())
45  rtn.setAnnotation(a, p.annotation(a));
46  rtn.setAnnotation("Type", p.type());
47  for (const ProfileBin1D& b : p.bins()) {
48  const double x = usefocus ? b.xFocus() : b.xMid();
49  const double ex_m = x - b.xMin();
50  const double ex_p = b.xMax() - x;
51 
52  double y;
53  try {
54  y = b.mean();
55  } catch (const Exception&) { // LowStatsError or WeightError
56  y = std::numeric_limits<double>::quiet_NaN();
57  }
58  double ey;
59  try {
60  ey = usestddev ? b.stdDev() : b.stdErr();
61  } catch (const Exception&) { // LowStatsError or WeightError
62  ey = std::numeric_limits<double>::quiet_NaN();
63  }
64 
65  const Point2D pt(x, y, ex_m, ex_p, ey, ey);
66  rtn.addPoint(pt);
67  }
68  assert(p.numBins() == rtn.numPoints());
69  return rtn;
70  }

◆ mkScatter() [5/8]

Scatter2D YODA::mkScatter ( const Scatter2D s)
inline

Make a Scatter2D representation of... erm, a Scatter2D!

Note
Mainly exists to allow mkScatter to be called on any AnalysisObject type

Definition at line 336 of file Scatter2D.h.

References YODA::Scatter2D::Scatter2D().

336 { return Scatter2D(s); }

◆ mkScatter() [6/8]

Scatter3D YODA::mkScatter ( const Histo2D h,
bool  usefocus = false 
)

Make a Scatter3D representation of a Histo2D

Optional usefocus argument can be used to position the point at the bin focus rather than geometric midpoint.

SAME FOR ALL 2D BINS

END SAME FOR ALL 2D BINS

SAME FOR ALL 2D BINS

END SAME FOR ALL 2D BINS

Definition at line 10 of file Scatter3D.cc.

References YODA::Scatter3D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Histo2D::bin(), YODA::HistoBin2D::height(), YODA::HistoBin2D::heightErr(), YODA::Histo2D::numBins(), YODA::AnalysisObject::setAnnotation(), YODA::AnalysisObject::type(), YODA::Bin2D< DBN >::xFocus(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMid(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yFocus(), YODA::Bin2D< DBN >::yMax(), YODA::Bin2D< DBN >::yMid(), and YODA::Bin2D< DBN >::yMin().

10  {
11  Scatter3D rtn;
12  for (const std::string& a : h.annotations())
13  rtn.setAnnotation(a, h.annotation(a));
14  rtn.setAnnotation("Type", h.type());
15  for (size_t i = 0; i < h.numBins(); ++i) {
16  const HistoBin2D& b = h.bin(i);
17 
19 
20  double x = b.xMid();
21  if (usefocus) {
22  try {
23  x = b.xFocus();
24  } catch (const LowStatsError& lse) {
25  x = b.xMid();
26  }
27  }
28  const double exminus = x - b.xMin();
29  const double explus = b.xMax() - x;
30 
31  double y = b.yMid();
32  if (usefocus) {
33  try {
34  y = b.yFocus();
35  } catch (const LowStatsError& lse) {
36  y = b.yMid();
37  }
38  }
39  const double eyminus = y - b.yMin();
40  const double eyplus = b.yMax() - y;
41 
43 
44  const double z = b.height();
45  const double ez = b.heightErr();
46 
47  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
48  }
49 
50  return rtn;
51  }

◆ mkScatter() [7/8]

Scatter3D YODA::mkScatter ( const Profile2D p,
bool  usefocus = false,
bool  usestddev = false 
)

Make a Scatter3D representation of a Profile2D

Optional usefocus argument can be used to position the point at the bin focus rather than geometric midpoint. Optional usestddev argument can be used to draw the distribution sigma rather than the standard error on the mean as the z-error bar size.

SAME FOR ALL 2D BINS

END SAME FOR ALL 2D BINS

< Control z-error scheme via usestddev arg

SAME FOR ALL 2D BINS

END SAME FOR ALL 2D BINS

< Control z-error scheme via usestddev arg

Definition at line 54 of file Scatter3D.cc.

References YODA::Scatter3D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Profile2D::bin(), YODA::ProfileBin2D::mean(), YODA::Profile2D::numBins(), YODA::AnalysisObject::setAnnotation(), YODA::ProfileBin2D::stdDev(), YODA::ProfileBin2D::stdErr(), YODA::AnalysisObject::type(), YODA::Bin2D< DBN >::xFocus(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMid(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yFocus(), YODA::Bin2D< DBN >::yMax(), YODA::Bin2D< DBN >::yMid(), and YODA::Bin2D< DBN >::yMin().

54  {
55  Scatter3D rtn;
56  for (const std::string& a : h.annotations())
57  rtn.setAnnotation(a, h.annotation(a));
58  rtn.setAnnotation("Type", h.type());
59  for (size_t i = 0; i < h.numBins(); ++i) {
60  const ProfileBin2D& b = h.bin(i);
61 
63 
64  double x = b.xMid();
65  if (usefocus) {
66  try {
67  x = b.xFocus();
68  } catch (const LowStatsError& lse) {
69  x = b.xMid();
70  }
71  }
72  const double exminus = x - b.xMin();
73  const double explus = b.xMax() - x;
74 
75  double y = b.yMid();
76  if (usefocus) {
77  try {
78  y = b.yFocus();
79  } catch (const LowStatsError& lse) {
80  y = b.yMid();
81  }
82  }
83  const double eyminus = y - b.yMin();
84  const double eyplus = b.yMax() - y;
85 
87 
88 
89  double z;
90  try {
91  z = b.mean();
92  } catch (const LowStatsError& lse) {
93  z = std::numeric_limits<double>::quiet_NaN();
94  }
95  double ez;
96  try {
97  ez = usestddev ? b.stdDev() : b.stdErr();
98  } catch (const LowStatsError& lse) {
99  ez = std::numeric_limits<double>::quiet_NaN();
100  }
101 
102  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
103  }
104 
105  return rtn;
106  }

◆ mkScatter() [8/8]

Scatter3D YODA::mkScatter ( const Scatter3D s)
inline

Make a Scatter3D representation of... erm, a Scatter3D!

Note
Mainly exists to allow mkScatter to be called on any AnalysisObject type

Definition at line 350 of file Scatter3D.h.

References YODA::Scatter3D::Scatter3D().

350 { return Scatter3D(s); }

◆ mkWriter()

Writer & YODA::mkWriter ( const std::string &  format_name)

Factory function to make a writer object by format name or a filename.

<

Todo:
Improve/remove... .ydat?

<

Todo:
Improve/remove... .ydat?

Definition at line 25 of file Writer.cc.

Referenced by write(), and YODA::Writer::writeFoot().

25  {
26  // Determine the format from the string (a file or file extension)
27  const size_t lastdot = name.find_last_of(".");
28  string fmt = Utils::toLower(lastdot == string::npos ? name : name.substr(lastdot+1));
29  const bool compress = (fmt == "gz");
30  //cout << "***" << compress << endl;
31  if (compress) {
32  #ifndef HAVE_LIBZ
33  throw UserError("YODA was compiled without zlib support: can't write " + name);
34  #endif
35  const size_t lastbutonedot = (lastdot == string::npos) ? string::npos : name.find_last_of(".", lastdot-1);
36  fmt = Utils::toLower(lastbutonedot == string::npos ? name : name.substr(lastbutonedot+1));
37  }
38  // Create the appropriate Writer
39  Writer* w = nullptr;
40  if (Utils::startswith(fmt, "yoda")) w = &WriterYODA::create();
41  if (Utils::startswith(fmt, "aida")) w = &WriterAIDA::create();
42  if (Utils::startswith(fmt, "dat" )) w = &WriterFLAT::create();
43  if (Utils::startswith(fmt, "flat")) w = &WriterFLAT::create();
44  if (!w) throw UserError("Format cannot be identified from string '" + name + "'");
45  w->useCompression(compress);
46  return *w;
47  }

◆ multiply() [1/2]

Scatter2D YODA::multiply ( const Histo1D histo,
const Scatter2D scatt 
)

Multiply histogram with scatter.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

Definition at line 344 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::HistoBin1D::relErr(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

Referenced by add(), and multiply().

344  {
345  if (histo.numBins() != scatt.numPoints()) throw BinningError("Histogram binning incompatible with number of scatter points");
346 
347  Scatter2D rtn = scatt.clone();
348  if (histo.path() != scatt.path()) rtn.setPath("");
349  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
350 
351  for (size_t i = 0; i < rtn.numPoints(); ++i) {
352  const HistoBin1D& b = histo.bin(i);
353  const Point2D& s = scatt.point(i);
354 
356  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
357  throw BinningError("x binnings are not equivalent in " + histo.path() + " * " + scatt.path());
358 
359 
360  // convert bin to scatter point
361  double biny;
362  try {
363  biny = b.height();
364  } catch (const Exception&) { // LowStatsError or WeightError
365  biny = 0;
366  }
367  double biney;
368  try {
369  biney = b.relErr();
370  } catch (const Exception&) { // LowStatsError or WeightError
371  biney = 0;
372  }
373  // combine with scatter values
374  double newy = biny * s.y();
375  double newey_p = newy * sqrt(sqr(biney) + sqr(s.yErrPlus() / s.y()));
376  double newey_m = newy * sqrt(sqr(biney) + sqr(s.yErrMinus() / s.y()));
377  // set new values
378  Point2D& t = rtn.point(i);
379  t.setY(newy);
380  t.setYErrMinus(newey_p);
381  t.setYErrPlus(newey_m);
382  }
383 
384  assert(rtn.numPoints() == histo.numBins());
385  return rtn;
386  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ multiply() [2/2]

Scatter2D YODA::multiply ( const Scatter2D scatt,
const Histo1D histo 
)
inline

Multiply scatter with histogram.

Definition at line 489 of file Histo1D.h.

References divide(), efficiency(), and multiply().

489  {
490  return multiply(histo, scatt);
491  }
Scatter2D multiply(const Scatter2D &scatt, const Histo1D &histo)
Multiply scatter with histogram.
Definition: Histo1D.h:489

◆ operator!=() [1/5]

template<int N>
bool YODA::operator!= ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Inequality test.

Definition at line 180 of file ErrorND.h.

180  {
181  return !(a == b);
182  }

◆ operator!=() [2/5]

template<int N>
bool YODA::operator!= ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Inequality test.

Definition at line 188 of file PointND.h.

188  {
189  return !(a == b);
190  }

◆ operator!=() [3/5]

bool YODA::operator!= ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Equality test of x characteristics only.

Definition at line 316 of file Point1D.h.

316  {
317  return !(a == b);
318  }

◆ operator!=() [4/5]

bool YODA::operator!= ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Equality test of x characteristics only.

Definition at line 519 of file Point2D.h.

519  {
520  return !(a == b);
521  }

◆ operator!=() [5/5]

bool YODA::operator!= ( const Point3D a,
const YODA::Point3D b 
)
inline

Inequality operator.

Definition at line 618 of file Point3D.h.

618  {
619  return !(a == b);
620  }

◆ operator*() [1/3]

Weights YODA::operator* ( const Weights first,
const Weights second 
)
inline

Multiply two weights.

Definition at line 268 of file Weights.h.

268  {
269  Weights tmp = first;
270  tmp *= second;
271  return tmp;
272  }

◆ operator*() [2/3]

Weights YODA::operator* ( double  a,
const Weights w 
)
inline

Multiply by a double.

Definition at line 283 of file Weights.h.

283  {
284  Weights tmp = w;
285  tmp *= a;
286  return tmp;
287  }

◆ operator*() [3/3]

Weights YODA::operator* ( const Weights w,
double  a 
)
inline

Multiply by a double.

Definition at line 290 of file Weights.h.

290  {
291  return a * w;
292  }

◆ operator+() [1/17]

HistoBin2D YODA::operator+ ( const HistoBin2D a,
const HistoBin2D b 
)
inline

Bin addition operator.

Definition at line 148 of file HistoBin2D.h.

148  {
149  HistoBin2D rtn(a);
150  rtn += b;
151  return rtn;
152  }

◆ operator+() [2/17]

HistoBin1D YODA::operator+ ( const HistoBin1D a,
const HistoBin1D b 
)
inline

Add two bins.

Definition at line 160 of file HistoBin1D.h.

160  {
161  HistoBin1D rtn(a);
162  rtn += b;
163  return rtn;
164  }

◆ operator+() [3/17]

Dbn0D YODA::operator+ ( const Dbn0D a,
const Dbn0D b 
)
inline

Add two dbns.

Definition at line 187 of file Dbn0D.h.

187  {
188  Dbn0D rtn = a;
189  rtn += b;
190  return rtn;
191  }

◆ operator+() [4/17]

ProfileBin1D YODA::operator+ ( const ProfileBin1D a,
const ProfileBin1D b 
)
inline

Definition at line 189 of file ProfileBin1D.h.

189  {
190  ProfileBin1D rtn(a);
191  rtn += b;
192  return rtn;
193  }

◆ operator+() [5/17]

ProfileBin2D YODA::operator+ ( const ProfileBin2D a,
const ProfileBin2D b 
)
inline

Bin addition operator.

Definition at line 194 of file ProfileBin2D.h.

194  {
195  ProfileBin2D rtn(a);
196  rtn += b;
197  return rtn;
198  }

◆ operator+() [6/17]

Dbn1D YODA::operator+ ( const Dbn1D a,
const Dbn1D b 
)
inline

Add two dbns.

Definition at line 219 of file Dbn1D.h.

219  {
220  Dbn1D rtn = a;
221  rtn += b;
222  return rtn;
223  }

◆ operator+() [7/17]

Counter YODA::operator+ ( const Counter first,
const Counter second 
)
inline

Add two counters.

Definition at line 243 of file Counter.h.

References add().

243  {
244  return add(first, second);
245  }
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:236

◆ operator+() [8/17]

Weights YODA::operator+ ( const Weights first,
const Weights second 
)
inline

Add two weights.

Definition at line 254 of file Weights.h.

254  {
255  Weights tmp = first;
256  tmp += second;
257  return tmp;
258  }

◆ operator+() [9/17]

Dbn2D YODA::operator+ ( const Dbn2D a,
const Dbn2D b 
)
inline

Add two dbns.

Definition at line 292 of file Dbn2D.h.

292  {
293  Dbn2D rtn = a;
294  rtn += b;
295  return rtn;
296  }

◆ operator+() [10/17]

template<class DBN >
Bin1D<DBN> YODA::operator+ ( const Bin1D< DBN > &  a,
const Bin1D< DBN > &  b 
)
inline

Add two bins

This "add" operator is defined for adding two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 326 of file Bin1D.h.

326  {
327  Bin1D<DBN> rtn = a;
328  rtn += b;
329  return rtn;
330  }

◆ operator+() [11/17]

Profile1D YODA::operator+ ( const Profile1D first,
const Profile1D second 
)
inline

Add two profile histograms.

Definition at line 380 of file Profile1D.h.

References add().

380  {
381  return add(first, second);
382  }
Profile1D add(const Profile1D &first, const Profile1D &second)
Add two profile histograms.
Definition: Profile1D.h:371

◆ operator+() [12/17]

Dbn3D YODA::operator+ ( const Dbn3D a,
const Dbn3D b 
)
inline

Add two dbns.

Definition at line 416 of file Dbn3D.h.

416  {
417  Dbn3D rtn = a;
418  rtn += b;
419  return rtn;
420  }

◆ operator+() [13/17]

Profile2D YODA::operator+ ( const Profile2D first,
const Profile2D second 
)
inline

Add two profile histograms.

Definition at line 419 of file Profile2D.h.

References add().

419  {
420  return add(first,second);
421  }
Profile2D add(const Profile2D &first, const Profile2D &second)
Add two profile histograms.
Definition: Profile2D.h:411

◆ operator+() [14/17]

Histo1D YODA::operator+ ( const Histo1D first,
const Histo1D second 
)
inline

Add two histograms.

Definition at line 433 of file Histo1D.h.

References add().

433  {
434  return add(first, second);
435  }
Scatter2D add(const Scatter2D &scatt, const Histo1D &histo)
Definition: Histo1D.h:475

◆ operator+() [15/17]

Histo2D YODA::operator+ ( const Histo2D first,
const Histo2D second 
)
inline

Add two histograms.

Definition at line 470 of file Histo2D.h.

References add().

470  {
471  return add(first, second);
472  }
Histo2D add(const Histo2D &first, const Histo2D &second)
Add two histograms.
Definition: Histo2D.h:461

◆ operator+() [16/17]

template<class DBN >
Bin2D<DBN> YODA::operator+ ( const Bin2D< DBN > &  a,
const Bin2D< DBN > &  b 
)
inline

Add two bins

This "add" operator is defined for adding two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 495 of file Bin2D.h.

495  {
496  Bin2D<DBN> rtn = a;
497  rtn += b;
498  return rtn;
499  }

◆ operator+() [17/17]

template<typename BIN1D , typename DBN >
Axis1D<BIN1D,DBN> YODA::operator+ ( const Axis1D< BIN1D, DBN > &  first,
const Axis1D< BIN1D, DBN > &  second 
)
inline

Add the statistics on two axes.

Definition at line 589 of file Axis1D.h.

589  {
590  Axis1D<BIN1D,DBN> tmp = first;
591  tmp += second;
592  return tmp;
593  }

◆ operator-() [1/17]

HistoBin2D YODA::operator- ( const HistoBin2D a,
const HistoBin2D b 
)
inline

Bin subtraction operator.

Definition at line 156 of file HistoBin2D.h.

156  {
157  HistoBin2D rtn(a);
158  rtn -= b;
159  return rtn;
160  }

◆ operator-() [2/17]

HistoBin1D YODA::operator- ( const HistoBin1D a,
const HistoBin1D b 
)
inline

Subtract two bins.

Definition at line 167 of file HistoBin1D.h.

167  {
168  HistoBin1D rtn(a);
169  rtn -= b;
170  return rtn;
171  }

◆ operator-() [3/17]

Dbn0D YODA::operator- ( const Dbn0D a,
const Dbn0D b 
)
inline

Subtract one dbn from another.

Definition at line 194 of file Dbn0D.h.

194  {
195  Dbn0D rtn = a;
196  rtn -= b;
197  return rtn;
198  }

◆ operator-() [4/17]

ProfileBin1D YODA::operator- ( const ProfileBin1D a,
const ProfileBin1D b 
)
inline

Definition at line 195 of file ProfileBin1D.h.

195  {
196  ProfileBin1D rtn(a);
197  rtn -= b;
198  return rtn;
199  }

◆ operator-() [5/17]

ProfileBin2D YODA::operator- ( const ProfileBin2D a,
const ProfileBin2D b 
)
inline

Bin subtraction operator.

Definition at line 202 of file ProfileBin2D.h.

202  {
203  ProfileBin2D rtn(a);
204  rtn -= b;
205  return rtn;
206  }

◆ operator-() [6/17]

Dbn1D YODA::operator- ( const Dbn1D a,
const Dbn1D b 
)
inline

Subtract one dbn from another.

Definition at line 226 of file Dbn1D.h.

226  {
227  Dbn1D rtn = a;
228  rtn -= b;
229  return rtn;
230  }

◆ operator-() [7/17]

Counter YODA::operator- ( const Counter first,
const Counter second 
)
inline

Subtract two counters.

Definition at line 256 of file Counter.h.

References divide(), and subtract().

256  {
257  return subtract(first, second);
258  }
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:249

◆ operator-() [8/17]

Weights YODA::operator- ( const Weights first,
const Weights second 
)
inline

Subtract two weights.

Definition at line 261 of file Weights.h.

261  {
262  Weights tmp = first;
263  tmp -= second;
264  return tmp;
265  }

◆ operator-() [9/17]

Dbn2D YODA::operator- ( const Dbn2D a,
const Dbn2D b 
)
inline

Subtract one dbn from another.

Definition at line 299 of file Dbn2D.h.

299  {
300  Dbn2D rtn = a;
301  rtn -= b;
302  return rtn;
303  }

◆ operator-() [10/17]

template<class DBN >
Bin1D<DBN> YODA::operator- ( const Bin1D< DBN > &  a,
const Bin1D< DBN > &  b 
)
inline

Subtract one bin from another

This "subtraction" operator is defined for subtracting two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 338 of file Bin1D.h.

338  {
339  Bin1D<DBN> rtn = a;
340  rtn -= b;
341  return rtn;
342  }

◆ operator-() [11/17]

Profile1D YODA::operator- ( const Profile1D first,
const Profile1D second 
)
inline

Subtract two profile histograms.

Definition at line 395 of file Profile1D.h.

References divide(), and subtract().

395  {
396  return subtract(first, second);
397  }
Profile1D subtract(const Profile1D &first, const Profile1D &second)
Subtract two profile histograms.
Definition: Profile1D.h:386

◆ operator-() [12/17]

Dbn3D YODA::operator- ( const Dbn3D a,
const Dbn3D b 
)
inline

Subtract one dbn from another.

Definition at line 423 of file Dbn3D.h.

423  {
424  Dbn3D rtn = a;
425  rtn -= b;
426  return rtn;
427  }

◆ operator-() [13/17]

Profile2D YODA::operator- ( const Profile2D first,
const Profile2D second 
)
inline

Subtract two profile histograms.

Definition at line 432 of file Profile2D.h.

References divide(), and subtract().

432  {
433  return subtract(first,second);
434  }
Profile2D subtract(const Profile2D &first, const Profile2D &second)
Subtract two profile histograms.
Definition: Profile2D.h:424

◆ operator-() [14/17]

Histo1D YODA::operator- ( const Histo1D first,
const Histo1D second 
)
inline

Subtract two histograms.

Definition at line 448 of file Histo1D.h.

References divide(), and subtract().

448  {
449  return subtract(first, second);
450  }
Scatter2D subtract(const Scatter2D &scatt, const Histo1D &histo)
Subtract histogram from scatter.
Definition: Histo1D.cc:296

◆ operator-() [15/17]

Histo2D YODA::operator- ( const Histo2D first,
const Histo2D second 
)
inline

Subtract two histograms.

Definition at line 485 of file Histo2D.h.

References divide(), and subtract().

485  {
486  return subtract(first, second);
487  }
Histo2D subtract(const Histo2D &first, const Histo2D &second)
Subtract two histograms.
Definition: Histo2D.h:476

◆ operator-() [16/17]

template<class DBN >
Bin2D<DBN> YODA::operator- ( const Bin2D< DBN > &  a,
const Bin2D< DBN > &  b 
)
inline

Subtract one bin from another

This "subtraction" operator is defined for subtracting two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 507 of file Bin2D.h.

507  {
508  Bin2D<DBN> rtn = a;
509  rtn -= b;
510  return rtn;
511  }

◆ operator-() [17/17]

template<typename BIN1D , typename DBN >
Axis1D<BIN1D,DBN> YODA::operator- ( const Axis1D< BIN1D, DBN > &  first,
const Axis1D< BIN1D, DBN > &  second 
)
inline

Subtract the statistics on two axis.

Definition at line 597 of file Axis1D.h.

597  {
598  Axis1D<BIN1D,DBN> tmp = first;
599  tmp -= second;
600  return tmp;
601  }

◆ operator/() [1/8]

Scatter1D YODA::operator/ ( const Counter numer,
const Counter denom 
)
inline

Divide two counters, with an uncorrelated error treatment

Todo:
Or just return a Point1D?

Definition at line 267 of file Counter.h.

References divide(), and efficiency().

267  {
268  return divide(numer, denom);
269  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:25

◆ operator/() [2/8]

Weights YODA::operator/ ( const Weights numer,
const Weights denom 
)
inline

Divide two weights.

Definition at line 275 of file Weights.h.

275  {
276  Weights tmp = numer;
277  tmp /= denom;
278  return tmp;
279  }

◆ operator/() [3/8]

Weights YODA::operator/ ( const Weights w,
double  a 
)
inline

Divide by a double.

Definition at line 295 of file Weights.h.

295  {
296  Weights tmp = w;
297  tmp /= a;
298  return tmp;
299  }

◆ operator/() [4/8]

Weights YODA::operator/ ( double  a,
const Weights w 
)
inline

Divide a double by a Weights

Todo:
Is this really needed?

Definition at line 303 of file Weights.h.

References YODA::Weights::keys().

303  {
304  Weights tmp(w.keys(), a);
305  tmp /= w;
306  return tmp;
307  }

◆ operator/() [5/8]

Scatter2D YODA::operator/ ( const Profile1D numer,
const Profile1D denom 
)
inline

Divide two profile histograms.

Definition at line 405 of file Profile1D.h.

References divide().

405  {
406  return divide(numer, denom);
407  }
Scatter2D divide(const Profile1D &numer, const Profile1D &denom)
Divide two profile histograms.
Definition: Profile1D.cc:155

◆ operator/() [6/8]

Scatter3D YODA::operator/ ( const Profile2D numer,
const Profile2D denom 
)
inline

Divide two profile histograms.

Definition at line 440 of file Profile2D.h.

References divide().

440  {
441  return divide(numer, denom);
442  }
Scatter3D divide(const Profile2D &numer, const Profile2D &denom)
Divide two profile histograms.
Definition: Profile2D.cc:189

◆ operator/() [7/8]

Scatter2D YODA::operator/ ( const Histo1D numer,
const Histo1D denom 
)
inline

Divide two histograms, with an uncorrelated error treatment

Note
The two histos must have exactly the same binning.

Definition at line 467 of file Histo1D.h.

References add(), and divide().

467  {
468  return divide(numer, denom);
469  }
Scatter2D divide(const Scatter2D &numer, const Histo1D &denom)
Divide scatter by histogram.
Definition: Histo1D.cc:447

◆ operator/() [8/8]

Scatter3D YODA::operator/ ( const Histo2D numer,
const Histo2D denom 
)
inline

Divide two histograms, with an uncorrelated error treatment

Note
The two histos must have exactly the same binning.

Definition at line 504 of file Histo2D.h.

References divide(), and efficiency().

504  {
505  return divide(numer, denom);
506  }
Scatter3D divide(const Histo2D &numer, const Histo2D &denom)
Divide two histograms, with an uncorrelated error treatment.
Definition: Histo2D.cc:316

◆ operator<() [1/7]

template<int N>
bool YODA::operator< ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Less-than operator used to sort errors.

Definition at line 187 of file ErrorND.h.

References LT_IF_NOT_EQ.

187  {
188  #define LT_IF_NOT_EQ(a,b) { if (!fuzzyEquals(a, b)) return a < b; }
189  for (size_t i = 0; i < N; ++i) {
190  LT_IF_NOT_EQ(a.err(i).first, b.err(i).first);
191  LT_IF_NOT_EQ(a.err(i).second, b.err(i).second);
192  }
193  #undef LT_IF_NOT_EQ
194  return a.name() < b.name();
195  }
#define LT_IF_NOT_EQ(a, b)

◆ operator<() [2/7]

template<int N>
bool YODA::operator< ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Less-than operator used to sort points.

Definition at line 195 of file PointND.h.

References LT_IF_NOT_EQ.

195  {
196  #define LT_IF_NOT_EQ(a,b) { if (!fuzzyEquals(a, b)) return a < b; }
197  for (size_t i = 0; i < N; ++i) LT_IF_NOT_EQ(a.pos()[i], b.pos()[i]);
198  if (a.errs().size() != b.errs().size()) return a.errs().size() < b.errs().size();
199  for (size_t i = 0; i < a.errs().size(); ++i) {
200  if (a.errs()[i] != b.errs()[i]) return a.errs()[i] < b.errs()[i];
201  }
202  #undef LT_IF_NOT_EQ
203  return false;
204  }
#define LT_IF_NOT_EQ(a, b)

◆ operator<() [3/7]

bool YODA::operator< ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Less-than operator used to sort bins by x-ordering.

Definition at line 321 of file Point1D.h.

References fuzzyEquals(), YODA::Point1D::x(), YODA::Point1D::xErrMinus(), and YODA::Point1D::xErrPlus().

321  {
322  if (!YODA::fuzzyEquals(a.x(), b.x())) {
323  return a.x() < b.x();
324  }
325  if (!YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
326  return a.xErrMinus() < b.xErrMinus();
327  }
328  if (!YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
329  return a.xErrPlus() < b.xErrPlus();
330  }
331  return false;
332  }
double x() const
Get x value.
Definition: Point1D.h:78
double xErrMinus(std::string source="") const
Get negative x-error value.
Definition: Point1D.h:98
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double xErrPlus(std::string source="") const
Get positive x-error value.
Definition: Point1D.h:104

◆ operator<() [4/7]

template<class DBN >
bool YODA::operator< ( const Bin1D< DBN > &  a,
const Bin1D< DBN > &  b 
)
inline

Bin1Ds are compared for axis sorting by lower edge position.

Definition at line 347 of file Bin1D.h.

References YODA::Bin1D< DBN >::xEdges().

Referenced by YODA_YAML::Node::Tag().

347  {
348  return b.xEdges().first > a.xEdges().first;
349  }

◆ operator<() [5/7]

template<class DBN >
bool YODA::operator< ( const Bin2D< DBN > &  a,
const Bin2D< DBN > &  b 
)
inline

Bin2Ds are compared for axis sorting by lower edge position in first x and then y directions.

Definition at line 516 of file Bin2D.h.

References fuzzyEquals(), and YODA::Bin2D< DBN >::xMin().

516  {
517  if (!fuzzyEquals(a.xMin(), b.xMin())) return b.xMin() > a.xMin();
518  return b.yMin() > a.yMin();
519  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ operator<() [6/7]

bool YODA::operator< ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Less-than operator used to sort bins by x-ordering.

Definition at line 524 of file Point2D.h.

References fuzzyEquals(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), and YODA::Point2D::xErrPlus().

524  {
525  if (!YODA::fuzzyEquals(a.x(), b.x())) {
526  return a.x() < b.x();
527  }
528  if (!YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
529  return a.xErrMinus() < b.xErrMinus();
530  }
531  if (!YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
532  return a.xErrPlus() < b.xErrPlus();
533  }
534  return false;
535  }
double x() const
Get x value.
Definition: Point2D.h:106
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double xErrMinus() const
Get negative x-error value.
Definition: Point2D.h:141
double xErrPlus() const
Get positive x-error value.
Definition: Point2D.h:146

◆ operator<() [7/7]

bool YODA::operator< ( const Point3D a,
const YODA::Point3D b 
)
inline

Less-than operator used to sort bins by x-first ordering.

Definition at line 623 of file Point3D.h.

References fuzzyEquals(), YODA::Point3D::x(), YODA::Point3D::xErrMinus(), YODA::Point3D::xErrPlus(), YODA::Point3D::y(), YODA::Point3D::yErrMinus(), and YODA::Point3D::yErrPlus().

623  {
624  if (! fuzzyEquals(a.x(), b.x())) {
625  return a.x() < b.x();
626  }
627  if (!fuzzyEquals(a.y(), b.y())) {
628  return a.y() < b.y();
629  }
630  if (! fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
631  return a.xErrMinus() < b.xErrMinus();
632  }
633  if (!fuzzyEquals(a.yErrMinus(), b.yErrMinus())) {
634  return a.yErrMinus() < b.yErrMinus();
635  }
636  if (! fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
637  return a.xErrPlus() < b.xErrPlus();
638  }
639  if (!fuzzyEquals(a.yErrPlus(), b.yErrPlus())) {
640  return a.yErrPlus() < b.yErrPlus();
641  }
642  return false;
643  }
double xErrPlus() const
Get positive x-error value.
Definition: Point3D.h:142
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double y() const
Get y value.
Definition: Point3D.h:103
double yErrMinus() const
Get negative y-error value.
Definition: Point3D.h:205
double xErrMinus() const
Get negative x-error value.
Definition: Point3D.h:137
double yErrPlus() const
Get positive y-error value.
Definition: Point3D.h:210
double x() const
Get x value.
Definition: Point3D.h:97

◆ operator<<()

std::ostream& YODA::operator<< ( std::ostream &  out,
const Weights w 
)
inline

Standard text representaion.

Definition at line 313 of file Weights.h.

References YODA::Weights::begin(), and YODA::Weights::end().

313  {
314  out << "{ ";
315  for (Weights::const_iterator i = w.begin(); i != w.end(); ++i) {
316  if (i != w.begin()) out << ", ";
317  out << i->first << ": " << i->second;
318  }
319  out << "}";
320  return out;
321  }

◆ operator<=() [1/5]

template<int N>
bool YODA::operator<= ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Less-than-or-equals operator used to sort errors.

Definition at line 199 of file ErrorND.h.

199  {
200  if (a == b) return true;
201  return a < b;
202  }

◆ operator<=() [2/5]

template<int N>
bool YODA::operator<= ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Less-than-or-equals operator used to sort points.

Definition at line 208 of file PointND.h.

208  {
209  if (a == b) return true;
210  return a < b;
211  }

◆ operator<=() [3/5]

bool YODA::operator<= ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Less-than-or-equals operator used to sort bins by x-ordering.

Definition at line 335 of file Point1D.h.

335  {
336  if (a == b) return true;
337  return a < b;
338  }

◆ operator<=() [4/5]

bool YODA::operator<= ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Less-than-or-equals operator used to sort bins by x-ordering.

Definition at line 538 of file Point2D.h.

538  {
539  if (a == b) return true;
540  return a < b;
541  }

◆ operator<=() [5/5]

bool YODA::operator<= ( const Point3D a,
const YODA::Point3D b 
)
inline

Less-than-or-equals operator.

Definition at line 646 of file Point3D.h.

646  {
647  if (a == b) return true;
648  return a < b;
649  }

◆ operator==() [1/5]

template<int N>
bool YODA::operator== ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Equality test.

Definition at line 169 of file ErrorND.h.

References YODA::Error< N >::errMinus(), YODA::Error< N >::errPlus(), fuzzyEquals(), and YODA::Error< N >::name().

169  {
170  if (a.name() != b.name()) return false;
171  for (size_t i = 0; i < N; ++i) {
172  if (!fuzzyEquals(a.errMinus(i), b.errMinus(i))) return false;
173  if (!fuzzyEquals(a.errPlus(i), b.errPlus(i))) return false;
174  }
175  return true;
176  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ operator==() [2/5]

template<int N>
bool YODA::operator== ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Equality test.

Definition at line 173 of file PointND.h.

References fuzzyEquals().

173  {
174  // Compare positions
175  for (size_t i = 0; i < N; ++i) {
176  if ( !fuzzyEquals(a.pos()[i], b.pos()[i]) ) return false;
177  }
178  // Compare number of errors and then (sorted) error equality
179  if (a.errs().size() != b.errs().size()) return false;
180  for (size_t i = 0; i < a.errs().size(); ++i) {
181  if (a.errs()[i] != b.errs()[i]) return false;
182  }
183  return true;
184  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ operator==() [3/5]

bool YODA::operator== ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Equality test of x characteristics only.

Definition at line 308 of file Point1D.h.

References fuzzyEquals(), YODA::Point1D::x(), YODA::Point1D::xErrMinus(), and YODA::Point1D::xErrPlus().

308  {
309  const bool same_val = YODA::fuzzyEquals(a.x(), b.x());
310  const bool same_eminus = YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus());
311  const bool same_eplus = YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus());
312  return same_val && same_eminus && same_eplus;
313  }
double x() const
Get x value.
Definition: Point1D.h:78
double xErrMinus(std::string source="") const
Get negative x-error value.
Definition: Point1D.h:98
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double xErrPlus(std::string source="") const
Get positive x-error value.
Definition: Point1D.h:104

◆ operator==() [4/5]

bool YODA::operator== ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Equality test of x characteristics only

Todo:
Need to add y comparisons, too

Definition at line 511 of file Point2D.h.

References fuzzyEquals(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), and YODA::Point2D::xErrPlus().

511  {
512  const bool same_val = YODA::fuzzyEquals(a.x(), b.x());
513  const bool same_eminus = YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus());
514  const bool same_eplus = YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus());
515  return same_val && same_eminus && same_eplus;
516  }
double x() const
Get x value.
Definition: Point2D.h:106
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double xErrMinus() const
Get negative x-error value.
Definition: Point2D.h:141
double xErrPlus() const
Get positive x-error value.
Definition: Point2D.h:146

◆ operator==() [5/5]

bool YODA::operator== ( const Point3D a,
const YODA::Point3D b 
)
inline

Equality operator.

Definition at line 608 of file Point3D.h.

References fuzzyEquals(), YODA::Point3D::x(), YODA::Point3D::xErrMinus(), YODA::Point3D::xErrPlus(), YODA::Point3D::y(), YODA::Point3D::yErrMinus(), and YODA::Point3D::yErrPlus().

608  {
609  const bool same_val = fuzzyEquals(a.x(), b.x()) && fuzzyEquals(a.y(), b.y());
610  const bool same_eminus = fuzzyEquals(a.xErrMinus(), b.xErrMinus()) &&
611  fuzzyEquals(a.yErrMinus(), b.yErrMinus());
612  const bool same_eplus = fuzzyEquals(a.xErrPlus(), b.xErrPlus()) &&
613  fuzzyEquals(a.yErrPlus(), b.yErrPlus());
614  return same_val && same_eminus && same_eplus;
615  }
double xErrPlus() const
Get positive x-error value.
Definition: Point3D.h:142
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
double y() const
Get y value.
Definition: Point3D.h:103
double yErrMinus() const
Get negative y-error value.
Definition: Point3D.h:205
double xErrMinus() const
Get negative x-error value.
Definition: Point3D.h:137
double yErrPlus() const
Get positive y-error value.
Definition: Point3D.h:210
double x() const
Get x value.
Definition: Point3D.h:97

◆ operator>() [1/5]

template<int N>
bool YODA::operator> ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Greater-than operator used to sort errors.

Definition at line 206 of file ErrorND.h.

206  {
207  return !(a <= b);
208  }

◆ operator>() [2/5]

template<int N>
bool YODA::operator> ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Greater-than operator used to sort points.

Definition at line 215 of file PointND.h.

215  {
216  return !(a <= b);
217  }

◆ operator>() [3/5]

bool YODA::operator> ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Greater-than operator used to sort bins by x-ordering.

Definition at line 341 of file Point1D.h.

341  {
342  return !(a <= b);
343  }

◆ operator>() [4/5]

bool YODA::operator> ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Greater-than operator used to sort bins by x-ordering.

Definition at line 544 of file Point2D.h.

544  {
545  return !(a <= b);
546  }

◆ operator>() [5/5]

bool YODA::operator> ( const Point3D a,
const YODA::Point3D b 
)
inline

Greater-than operator.

Definition at line 652 of file Point3D.h.

652  {
653  return !(a <= b);
654  }

◆ operator>=() [1/5]

template<int N>
bool YODA::operator>= ( const Error< N > &  a,
const Error< N > &  b 
)
inline

Greater-than-or-equals operator used to sort errors.

Definition at line 212 of file ErrorND.h.

212  {
213  return !(a < b);
214  }

◆ operator>=() [2/5]

template<int N>
bool YODA::operator>= ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Greater-than-or-equals operator used to sort points.

Definition at line 221 of file PointND.h.

221  {
222  return !(a < b);
223  }

◆ operator>=() [3/5]

bool YODA::operator>= ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Greater-than-or-equals operator used to sort bins by x-ordering.

Definition at line 346 of file Point1D.h.

346  {
347  return !(a < b);
348  }

◆ operator>=() [4/5]

bool YODA::operator>= ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Greater-than-or-equals operator used to sort bins by x-ordering.

Definition at line 549 of file Point2D.h.

549  {
550  return !(a < b);
551  }

◆ operator>=() [5/5]

bool YODA::operator>= ( const Point3D a,
const YODA::Point3D b 
)
inline

Greater-than-or-equals operator.

Definition at line 657 of file Point3D.h.

657  {
658  return !(a < b);
659  }

◆ read() [1/4]

void YODA::read ( const std::string &  filename,
std::vector< AnalysisObject *> &  aos 
)

Read in a collection of objects objs from file filename.

This version fills (actually, appends to) a supplied vector, avoiding copying, and is hence CPU efficient. The appropriate format reader will be determined from the filename.

Todo:
Use SFINAE magic to allow ~arbitrary collection<AnalysisObject*> (with push_back()?) to be passed

Definition at line 79 of file IO.h.

References mkReader(), and YODA::Reader::read().

Referenced by read().

79  {
80  Reader& r = mkReader(filename);
81  r.read(filename, aos);
82  }
Reader & mkReader(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Reader.cc:17

◆ read() [2/4]

std::vector<AnalysisObject*> YODA::read ( const std::string &  filename)

Read in a collection of objects from file filename.

This version returns a vector by value, involving copying, and is hence less CPU efficient than the alternative version where a vector is filled by reference. The appropriate format reader will be determined from the filename.

Definition at line 90 of file IO.h.

References read().

90  {
91  std::vector<AnalysisObject*> rtn;
92  read(filename, rtn);
93  return rtn;
94  }
std::vector< AnalysisObject * > read(std::istream &is, const std::string &fmt)
Read in a collection of objects from stream is, expecting format fmt.
Definition: IO.h:118

◆ read() [3/4]

void YODA::read ( std::istream &  is,
std::vector< AnalysisObject *> &  aos,
const std::string &  fmt 
)

Read in a collection of objects objs from stream is, expecting format fmt.

This version fills (actually, appends to) a supplied vector, avoiding copying, and is hence CPU efficient.

Todo:
Use SFINAE magic to allow ~arbitrary collection<AnalysisObject*> (with push_back()?) to be passed

Definition at line 108 of file IO.h.

References mkReader(), and YODA::Reader::read().

108  {
109  Reader& r = mkReader(fmt);
110  r.read(is, aos);
111  }
Reader & mkReader(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Reader.cc:17

◆ read() [4/4]

std::vector<AnalysisObject*> YODA::read ( std::istream &  is,
const std::string &  fmt 
)

Read in a collection of objects from stream is, expecting format fmt.

This version returns a vector by value, involving copying, and is hence less CPU efficient than the alternative version where a vector is filled by reference.

Definition at line 118 of file IO.h.

References read().

118  {
119  std::vector<AnalysisObject*> rtn;
120  read(is, rtn, fmt);
121  return rtn;
122  }
std::vector< AnalysisObject * > read(std::istream &is, const std::string &fmt)
Read in a collection of objects from stream is, expecting format fmt.
Definition: IO.h:118

◆ sign() [1/3]

int YODA::sign ( double  val)
inline

Find the sign of a number.

Definition at line 224 of file MathUtils.h.

References isZero(), MINUS, PLUS, and ZERO.

224  {
225  if (isZero(val)) return ZERO;
226  const int valsign = (val > 0) ? PLUS : MINUS;
227  return valsign;
228  }
bool isZero(long val, double=1E-8)
Definition: MathUtils.h:64

◆ sign() [2/3]

int YODA::sign ( int  val)
inline

Find the sign of a number.

Definition at line 231 of file MathUtils.h.

References MINUS, PLUS, and ZERO.

231  {
232  if (val == 0) return ZERO;
233  return (val > 0) ? PLUS : MINUS;
234  }

◆ sign() [3/3]

int YODA::sign ( long  val)
inline

Find the sign of a number.

Definition at line 237 of file MathUtils.h.

References MINUS, PLUS, and ZERO.

237  {
238  if (val == 0) return ZERO;
239  return (val > 0) ? PLUS : MINUS;
240  }

◆ sqr()

template<typename NUM >
NUM YODA::sqr ( NUM  a)
inline

Named number-type squaring operation.

Definition at line 207 of file MathUtils.h.

Referenced by add(), chi2(), divide(), efficiency(), multiply(), subtract(), toIntegralEfficiencyHisto(), and YODA::Dbn1D::xVariance().

207  {
208  return a*a;
209  }

◆ subtract() [1/7]

Counter YODA::subtract ( const Counter first,
const Counter second 
)
inline

Subtract two counters.

Definition at line 249 of file Counter.h.

Referenced by add(), and operator-().

249  {
250  Counter tmp = first;
251  tmp -= second;
252  return tmp;
253  }

◆ subtract() [2/7]

Profile1D YODA::subtract ( const Profile1D first,
const Profile1D second 
)
inline

Subtract two profile histograms.

Definition at line 386 of file Profile1D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

386  {
387  Profile1D tmp = first;
388  if (first.path() != second.path()) tmp.setPath("");
389  tmp -= second;
390  return tmp;
391  }

◆ subtract() [3/7]

Profile2D YODA::subtract ( const Profile2D first,
const Profile2D second 
)
inline

Subtract two profile histograms.

Definition at line 424 of file Profile2D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

424  {
425  Profile2D tmp = first;
426  if (first.path() != second.path()) tmp.setPath("");
427  tmp -= second;
428  return tmp;
429  }

◆ subtract() [4/7]

Histo1D YODA::subtract ( const Histo1D first,
const Histo1D second 
)
inline

Subtract two histograms.

Definition at line 439 of file Histo1D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

439  {
440  Histo1D tmp = first;
441  if (first.path() != second.path()) tmp.setPath("");
442  tmp -= second;
443  return tmp;
444  }

◆ subtract() [5/7]

Histo2D YODA::subtract ( const Histo2D first,
const Histo2D second 
)
inline

Subtract two histograms.

Definition at line 476 of file Histo2D.h.

References YODA::AnalysisObject::path(), and YODA::AnalysisObject::setPath().

476  {
477  Histo2D tmp = first;
478  if (first.path() != second.path()) tmp.setPath("");
479  tmp -= second;
480  return tmp;
481  }

◆ subtract() [6/7]

Scatter2D YODA::subtract ( const Histo1D histo,
const Scatter2D scatt 
)

Subtract scatter from histogram.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

Definition at line 248 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

248  {
249  if (histo.numBins() != scatt.numPoints()) throw BinningError("Histogram binning incompatible with number of scatter points");
250 
251  Scatter2D rtn = scatt.clone();
252  if (histo.path() != scatt.path()) rtn.setPath("");
253  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
254 
255  for (size_t i = 0; i < rtn.numPoints(); ++i) {
256  const HistoBin1D& b = histo.bin(i);
257  const Point2D& s = scatt.point(i);
258 
260  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
261  throw BinningError("x binnings are not equivalent in " + histo.path() + " - " + scatt.path());
262 
263 
264  // convert bin to scatter point
265  double biny;
266  try {
267  biny = b.height();
268  } catch (const Exception&) { // LowStatsError or WeightError
269  biny = 0;
270  }
271  double biney;
272  try {
273  biney = b.heightErr();
274  } catch (const Exception&) { // LowStatsError or WeightError
275  biney = 0;
276  }
277  // combine with scatter values
278  double newy = biny - s.y();
279  double newey_p = sqrt(sqr(biney) + sqr(s.yErrPlus()));
280  double newey_m = sqrt(sqr(biney) + sqr(s.yErrMinus()));
281  // set new values
282  Point2D& t = rtn.point(i);
283  t.setY(newy);
284  t.setYErrMinus(newey_p);
285  t.setYErrPlus(newey_m);
286  }
287 
288  assert(rtn.numPoints() == histo.numBins());
289  return rtn;
290  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ subtract() [7/7]

Scatter2D YODA::subtract ( const Scatter2D scatt,
const Histo1D histo 
)

Subtract histogram from scatter.

Todo:
Create a compatibleBinning function? Or just compare vectors of edges().
Todo:
Create a compatibleBinning function? Or just compare vectors of edges().

Definition at line 296 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Scatter2D::clone(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::AnalysisObject::rmAnnotation(), YODA::AnalysisObject::setPath(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), sqr(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

296  {
297  if (histo.numBins() != scatt.numPoints()) throw BinningError("Histogram binning incompatible with number of scatter points");
298 
299  Scatter2D rtn = scatt.clone();
300  if (histo.path() != scatt.path()) rtn.setPath("");
301  if (rtn.hasAnnotation("ScaledBy")) rtn.rmAnnotation("ScaledBy");
302 
303  for (size_t i = 0; i < rtn.numPoints(); ++i) {
304  const HistoBin1D& b = histo.bin(i);
305  const Point2D& s = scatt.point(i);
306 
308  if (!fuzzyEquals(b.xMin(), s.x() - s.xErrMinus()) || !fuzzyEquals(b.xMax(), s.x() + s.xErrPlus()))
309  throw BinningError("x binnings are not equivalent in " + scatt.path() + " - " + histo.path());
310 
311 
312  // convert bin to scatter point
313  double biny;
314  try {
315  biny = b.height();
316  } catch (const Exception&) { // LowStatsError or WeightError
317  biny = 0;
318  }
319  double biney;
320  try {
321  biney = b.heightErr();
322  } catch (const Exception&) { // LowStatsError or WeightError
323  biney = 0;
324  }
325  // combine with scatter values
326  double newy = s.y() - biny;
327  double newey_p = sqrt(sqr(biney) + sqr(s.yErrPlus()));
328  double newey_m = sqrt(sqr(biney) + sqr(s.yErrMinus()));
329  // set new values
330  Point2D& t = rtn.point(i);
331  t.setY(newy);
332  t.setYErrMinus(newey_p);
333  t.setYErrPlus(newey_m);
334  }
335 
336  assert(rtn.numPoints() == histo.numBins());
337  return rtn;
338  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ toIntegralEfficiencyHisto()

Scatter2D YODA::toIntegralEfficiencyHisto ( const Histo1D h,
bool  includeunderflow = true,
bool  includeoverflow = true 
)

Convert a Histo1D to a Scatter2D where each bin is a fraction of the total.

Note
This sounds weird: let's explain a bit more! Sometimes we want to take a histo h, make an integral histogram H from it, and then divide H by the total integral of h, such that every bin in H represents the cumulative efficiency of that bin as a fraction of the total. I.e. an integral histo, scaled by 1/total_integral and with binomial errors.

The includeunderflow param behaves as for toIntegral, and applies to both the initial integration and the integral used for the scaling. The includeoverflow param applies only to obtaining the scaling factor.

Todo:
Rename/alias as mkIntegralEff
Todo:
Or throw a LowStatsError exception if h.effNumEntries() == 0?
Todo:
Provide optional alt behaviours
Todo:
Need to check that bins are all positive? Integral could be zero due to large +ve/-ve in different bins :O
Todo:
Should the total integral error be sqrt(sumW2)? Or more complex, cf. Simon etc.?
Todo:
Or throw a LowStatsError exception if h.effNumEntries() == 0?
Todo:
Provide optional alt behaviours
Todo:
Need to check that bins are all positive? Integral could be zero due to large +ve/-ve in different bins :O
Todo:
Should the total integral error be sqrt(sumW2)? Or more complex, cf. Simon etc.?

Definition at line 553 of file Histo1D.cc.

References YODA::Histo1D::integral(), YODA::Histo1D::overflow(), YODA::Scatter2D::points(), sqr(), YODA::Dbn1D::sumW(), and toIntegralHisto().

Referenced by asymm().

553  {
554  Scatter2D rtn = toIntegralHisto(h, includeunderflow);
555  const double integral = h.integral() - (includeoverflow ? 0 : h.overflow().sumW());
556 
557  // If the integral is empty, the (integrated) efficiency values may as well all be zero, so return here
561  if (integral == 0) return rtn;
562 
564  const double integral_err = sqrt(integral);
565 
566  // Normalize and compute binomial errors
567  for (Point2D& p : rtn.points()) {
568  const double eff = p.y() / integral;
569  const double ey = sqrt(abs( ((1-2*eff)*sqr(p.y()/p.yErrAvg()) + sqr(eff)*sqr(integral_err)) / sqr(integral) ));
570  p.setY(eff, ey);
571  }
572 
573  return rtn;
574  }
Scatter2D toIntegralHisto(const Histo1D &h, bool includeunderflow=true)
Convert a Histo1D to a Scatter2D representing the integral of the histogram.
Definition: Histo1D.cc:539
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:207

◆ toIntegralHisto()

Scatter2D YODA::toIntegralHisto ( const Histo1D h,
bool  includeunderflow = true 
)

Convert a Histo1D to a Scatter2D representing the integral of the histogram.

Note
The integral histo errors are calculated as sqrt(binvalue), as if they are uncorrelated. This is not in general true for integral histograms, so if you need accurate errors you should explicitly monitor bin-to-bin correlations.

The includeunderflow param chooses whether the underflow bin is included in the integral numbers as an offset.

Todo:
Rename/alias as mkIntegral
Todo:
Check that the histogram binning has no gaps, otherwise throw a BinningError
Todo:
Check that the histogram binning has no gaps, otherwise throw a BinningError

Definition at line 539 of file Histo1D.cc.

References YODA::Histo1D::bin(), YODA::Histo1D::integral(), mkScatter(), YODA::Histo1D::numBins(), YODA::Scatter2D::point(), YODA::Point2D::setY(), YODA::Dbn1D::sumW(), YODA::Bin1D< DBN >::sumW(), and YODA::Histo1D::underflow().

Referenced by asymm(), and toIntegralEfficiencyHisto().

539  {
541  Scatter2D tmp = mkScatter(h);
542  double integral = includeunderflow ? h.underflow().sumW() : 0.0;
543  for (size_t i = 0; i < h.numBins(); ++i) {
544  Point2D& point = tmp.point(i);
545  integral += h.bin(i).sumW();
546  const double err = sqrt(integral); //< @todo Should be sqrt(sumW2)? Or more complex, cf. Simon etc.?
547  point.setY(integral, err);
548  }
549  return tmp;
550  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9

◆ toNewScatter2D() [1/4]

Scatter2D* YODA::toNewScatter2D ( const TH1 &  th1,
bool  scalebywidth = true 
)
inline

Convert a ROOT 1D histogram (excluding TProfile) to a new'd YODA Scatter2D.

Definition at line 106 of file ROOTCnv.h.

References YODA::Scatter2D::newclone(), and toScatter2D().

106  {
107  return toScatter2D(th1, scalebywidth).newclone();
108  }
Scatter2D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter2D.h:127
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toNewScatter2D() [2/4]

Scatter2D* YODA::toNewScatter2D ( const TH1 *  th1,
bool  scalebywidth = true 
)
inline

Convert a ROOT 1D histogram (excluding TProfile) to a new'd YODA Scatter2D.

Definition at line 110 of file ROOTCnv.h.

References YODA::Scatter2D::newclone(), and toScatter2D().

110  {
111  return toScatter2D(th1, scalebywidth).newclone();
112  }
Scatter2D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter2D.h:127
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toNewScatter2D() [3/4]

Scatter2D* YODA::toNewScatter2D ( const TProfile &  tp1)
inline

Convert a ROOT TProfile to a new'd YODA Scatter2D.

Definition at line 131 of file ROOTCnv.h.

References YODA::Scatter2D::newclone(), and toScatter2D().

131  {
132  return toScatter2D(tp1).newclone();
133  }
Scatter2D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter2D.h:127
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toNewScatter2D() [4/4]

Scatter2D* YODA::toNewScatter2D ( const TProfile *  tp1)
inline

Convert a ROOT TProfile to a new'd YODA Scatter2D.

Definition at line 135 of file ROOTCnv.h.

References YODA::Scatter2D::newclone(), and toScatter2D().

135  {
136  return toScatter2D(tp1).newclone();
137  }
Scatter2D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter2D.h:127
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toNewScatter3D() [1/2]

Scatter3D* YODA::toNewScatter3D ( const TH2 &  th2,
bool  scalebyarea = true 
)
inline

Convert a ROOT 2D histogram to a new'd YODA Scatter3D.

Definition at line 190 of file ROOTCnv.h.

References YODA::Scatter3D::newclone(), and toScatter3D().

190  {
191  return toScatter3D(th2, scalebyarea).newclone();
192  }
Scatter3D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter3D.h:139
Scatter3D toScatter3D(const TH2 *th2, bool scalebyarea=true)
Convert a ROOT 2D histogram to a YODA Scatter3D.
Definition: ROOTCnv.h:183

◆ toNewScatter3D() [2/2]

Scatter3D* YODA::toNewScatter3D ( const TH2 *  th2,
bool  scalebyarea = true 
)
inline

Convert a ROOT 2D histogram to a new'd YODA Scatter3D.

Definition at line 194 of file ROOTCnv.h.

References YODA::Scatter3D::newclone(), and toScatter3D().

194  {
195  return toScatter3D(th2, scalebyarea).newclone();
196  }
Scatter3D * newclone() const
Make a copy on the heap, via &#39;new&#39;.
Definition: Scatter3D.h:139
Scatter3D toScatter3D(const TH2 *th2, bool scalebyarea=true)
Convert a ROOT 2D histogram to a YODA Scatter3D.
Definition: ROOTCnv.h:183

◆ toNewTGraph() [1/3]

TGraphAsymmErrors* YODA::toNewTGraph ( const Scatter2D s,
const std::string &  rootname 
)
inline

Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors as new'd pointer.

Definition at line 441 of file ROOTCnv.h.

References toTGraph().

441  {
442  return (TGraphAsymmErrors*) toTGraph(s).Clone(rootname.c_str());
443  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:460

◆ toNewTGraph() [2/3]

TGraphAsymmErrors* YODA::toNewTGraph ( const Histo1D h,
const std::string &  rootname 
)
inline

Convert a YODA Histo1D to a ROOT TGraphAsymmErrors as new'd pointer.

Definition at line 453 of file ROOTCnv.h.

References toTGraph().

453  {
454  return (TGraphAsymmErrors*) toTGraph(h).Clone(rootname.c_str());
455  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:460

◆ toNewTGraph() [3/3]

TGraphAsymmErrors* YODA::toNewTGraph ( const Profile1D p,
const std::string &  rootname 
)
inline

Convert a YODA Profile1D to a ROOT TGraphAsymmErrors as new'd pointer.

Definition at line 465 of file ROOTCnv.h.

References toTGraph().

465  {
466  return (TGraphAsymmErrors*) toTGraph(p).Clone(rootname.c_str());
467  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:460

◆ toNewTH1D()

TH1D* YODA::toNewTH1D ( const Histo1D h,
const std::string &  rootname 
)
inline

Convert a YODA Histo1D to a ROOT 1D histogram as new'd pointer.

Definition at line 252 of file ROOTCnv.h.

References toTH1D().

252  {
253  return (TH1D*) toTH1D(h).Clone(rootname.c_str());
254  }
TH1D toTH1D(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TH1D.
Definition: ROOTCnv.h:373

◆ toNewTH2D()

TH2D* YODA::toNewTH2D ( const Histo2D h,
const std::string &  rootname 
)
inline

Convert a YODA Histo2D to a ROOT 2D histogram as new'd pointer.

Definition at line 312 of file ROOTCnv.h.

References toTH2D().

312  {
313  return (TH2D*) toTH2D(h).Clone(rootname.c_str());
314  }
TH2D toTH2D(const Histo2D &h)
Convert a YODA Histo2D to a ROOT 2D histogram.
Definition: ROOTCnv.h:261

◆ toNewTProfile()

TProfile* YODA::toNewTProfile ( const Profile1D p,
const std::string &  rootname 
)
inline

Convert a YODA Profile1D to a ROOT TProfile as new'd pointer.

Definition at line 404 of file ROOTCnv.h.

References toTProfile().

404  {
405  return (TProfile*) toTProfile(p).Clone(rootname.c_str());
406  }
TProfile toTProfile(const Profile1D &p)
Convert a YODA Scatter2D to a ROOT TH1D.
Definition: ROOTCnv.h:327

◆ toScatter2D() [1/4]

Scatter2D YODA::toScatter2D ( const TH1 &  th1,
bool  scalebywidth = true 
)
inline
Todo:
Check that direct Scatter filling gives the same result at mkScatter(h) for ROOT -> YODA
Todo:
toProfile1D: TProfile -> Profile1D
Todo:
toScatter2D: TGraph(AsymmErrs) -> Scatter2D

Convert a ROOT 1D histogram (excluding TProfile) to a YODA Scatter2D

The optional bool arg specifies whether or not to divide y vals/errs by bin width.

Definition at line 74 of file ROOTCnv.h.

References YODA::AnalysisObject::addAnnotation(), YODA::Scatter2D::addPoint(), YODA::AnalysisObject::setPath(), and YODA::AnalysisObject::setTitle().

Referenced by toNewScatter2D(), and toScatter2D().

74  {
75  Scatter2D rtn;
76  for (int ix = 1; ix <= th1.GetNbinsX(); ++ix) {
77  const TAxis& axx = *th1.GetXaxis();
78  const double x = axx.GetBinCenter(ix);
79  const double exminus = x - axx.GetBinLowEdge(ix);
80  const double explus = axx.GetBinUpEdge(ix) - x;
81  const double xwidth = axx.GetBinWidth(ix);
82  //
83  const double val = th1.GetBinContent(ix) / (scalebywidth ? xwidth : 1);
84  const double evalminus = th1.GetBinErrorLow(ix) / (scalebywidth ? xwidth : 1);
85  const double evalplus = th1.GetBinErrorUp(ix) / (scalebywidth ? xwidth : 1);
86  rtn.addPoint(x, val,
87  exminus, explus,
88  evalminus, evalplus);
89  }
90  rtn.setPath(th1.GetName());
91  rtn.setTitle(th1.GetTitle());
92  rtn.addAnnotation("XLabel", th1.GetXaxis()->GetTitle());
93  rtn.addAnnotation("YLabel", th1.GetYaxis()->GetTitle());
94  return rtn;
95  }

◆ toScatter2D() [2/4]

Scatter2D YODA::toScatter2D ( const TH1 *  th1,
bool  scalebywidth = true 
)
inline

Convert a ROOT 1D histogram (excluding TProfile) to a YODA Scatter2D.

Definition at line 99 of file ROOTCnv.h.

References toScatter2D().

99  {
100  if (th1 == NULL) throw UserError("Null TH1 pointer passed as argument");
101  return toScatter2D(*th1, scalebywidth);
102  }
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toScatter2D() [3/4]

Scatter2D YODA::toScatter2D ( const TProfile &  tp1)
inline

Convert a ROOT TProfile to a YODA Scatter2D.

Definition at line 119 of file ROOTCnv.h.

References toScatter2D().

119  {
120  return toScatter2D((TH1&)tp1, false);
121  }
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toScatter2D() [4/4]

Scatter2D YODA::toScatter2D ( const TProfile *  tp1)
inline

Convert a ROOT TProfile to a YODA Scatter2D.

Definition at line 124 of file ROOTCnv.h.

References toScatter2D().

124  {
125  if (tp1 == NULL) throw UserError("Null TProfile pointer passed as argument");
126  return toScatter2D(*tp1); //< TProfile inherits from TH1, so this just uses the function above
127  }
Scatter2D toScatter2D(const TProfile *tp1)
Convert a ROOT TProfile to a YODA Scatter2D.
Definition: ROOTCnv.h:124

◆ toScatter3D() [1/2]

Scatter3D YODA::toScatter3D ( const TH2 &  th2,
bool  scalebyarea = true 
)
inline

Convert a ROOT 2D histogram to a YODA Scatter3D

The optional bool arg specifies whether or not to divide y vals/errs by bin area.

Definition at line 146 of file ROOTCnv.h.

References YODA::AnalysisObject::addAnnotation(), YODA::Scatter3D::addPoint(), YODA::AnalysisObject::setPath(), and YODA::AnalysisObject::setTitle().

Referenced by toNewScatter3D(), and toScatter3D().

146  {
147  Scatter3D rtn;
148  for (int ix = 1; ix <= th2.GetNbinsX(); ++ix) {
149  for (int iy = 1; iy <= th2.GetNbinsY(); ++iy) {
150  const TAxis& axx = *th2.GetXaxis();
151  const double x = axx.GetBinCenter(ix);
152  const double exminus = x - axx.GetBinLowEdge(ix);
153  const double explus = axx.GetBinUpEdge(ix) - x;
154  const double xwidth = axx.GetBinWidth(ix);
155  //
156  const TAxis& axy = *th2.GetYaxis();
157  const double y = axy.GetBinCenter(iy);
158  const double eyminus = y - axy.GetBinLowEdge(iy);
159  const double eyplus = axy.GetBinUpEdge(iy) - y;
160  const double ywidth = axy.GetBinWidth(iy);
161  //
162  const int ixy = th2.GetBin(ix, iy);
163  const double area = xwidth*ywidth;
164  const double val = th2.GetBinContent(ixy) / (scalebyarea ? area : 1);
165  const double evalminus = th2.GetBinErrorLow(ixy) / (scalebyarea ? area : 1);
166  const double evalplus = th2.GetBinErrorUp(ixy) / (scalebyarea ? area : 1);
167  rtn.addPoint(x, y, val,
168  exminus, explus,
169  eyminus, eyplus,
170  evalminus, evalplus);
171  }
172  }
173  rtn.setPath(th2.GetName());
174  rtn.setTitle(th2.GetTitle());
175  rtn.addAnnotation("XLabel", th2.GetXaxis()->GetTitle());
176  rtn.addAnnotation("YLabel", th2.GetYaxis()->GetTitle());
177  rtn.addAnnotation("ZLabel", th2.GetZaxis()->GetTitle());
178  return rtn;
179  }

◆ toScatter3D() [2/2]

Scatter3D YODA::toScatter3D ( const TH2 *  th2,
bool  scalebyarea = true 
)
inline

Convert a ROOT 2D histogram to a YODA Scatter3D.

Definition at line 183 of file ROOTCnv.h.

References toScatter3D().

183  {
184  if (th2 == NULL) throw UserError("Null TH2 pointer passed as argument");
185  return toScatter3D(*th2, scalebyarea);
186  }
Scatter3D toScatter3D(const TH2 *th2, bool scalebyarea=true)
Convert a ROOT 2D histogram to a YODA Scatter3D.
Definition: ROOTCnv.h:183

◆ toTGraph() [1/3]

TGraphAsymmErrors YODA::toTGraph ( const Scatter2D s)
inline

Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors.

Todo:
Convert a YODA Profile2D to a ROOT TProfile2D
Todo:
Check/improve/extend.

Definition at line 417 of file ROOTCnv.h.

References YODA::AnalysisObject::annotation(), YODA::AnalysisObject::hasAnnotation(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), YODA::AnalysisObject::title(), YODA::Point2D::x(), YODA::Point2D::xErrMinus(), YODA::Point2D::xErrPlus(), YODA::Point2D::y(), YODA::Point2D::yErrMinus(), and YODA::Point2D::yErrPlus().

Referenced by toNewTGraph(), and toTGraph().

417  {
418  TVectorF xs(s.numPoints()), ys(s.numPoints());
419  TVectorF exls(s.numPoints()), exhs(s.numPoints());
420  TVectorF eyls(s.numPoints()), eyhs(s.numPoints());
421  for (size_t i = 0; i < s.numPoints(); ++i) {
422  const Point2D& p = s.point(i);
423  xs[i] = p.x();
424  ys[i] = p.y();
425  exls[i] = p.xErrMinus();
426  exhs[i] = p.xErrPlus();
427  eyls[i] = p.yErrMinus();
428  eyhs[i] = p.yErrPlus();
429  }
430  // Make the ROOT object... mm, the constructors don't take name+title, unlike all this histos!
431  TGraphAsymmErrors rtn(xs, ys, exls, exhs, eyls, eyhs);
432  rtn.SetName(s.path().c_str());
433  rtn.SetTitle(s.title().c_str());
434  // Labels
435  if (s.hasAnnotation("XLabel")) rtn.GetXaxis()->SetTitle(s.annotation("XLabel").c_str());
436  if (s.hasAnnotation("YLabel")) rtn.GetYaxis()->SetTitle(s.annotation("YLabel").c_str());
437  return rtn;
438  }

◆ toTGraph() [2/3]

TGraphAsymmErrors YODA::toTGraph ( const Histo1D h)
inline

Convert a YODA Histo1D to a ROOT TGraphAsymmErrors.

Definition at line 448 of file ROOTCnv.h.

References mkScatter(), and toTGraph().

448  {
449  return toTGraph(mkScatter(h));
450  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:460
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9

◆ toTGraph() [3/3]

TGraphAsymmErrors YODA::toTGraph ( const Profile1D p)
inline

Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.

Definition at line 460 of file ROOTCnv.h.

References mkScatter(), and toTGraph().

460  {
461  return toTGraph(mkScatter(p));
462  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:460
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:9

◆ toTH1D() [1/2]

TH1D YODA::toTH1D ( const Histo1D h)
inline

Convert a YODA Histo1D to a ROOT 1D histogram.

Todo:
Check/improve/extend – needs SetBinError or not?

Definition at line 219 of file ROOTCnv.h.

References YODA::AnalysisObject::annotation(), YODA::Histo1D::bin(), YODA::Histo1D::binAt(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::Histo1D::numBins(), YODA::Histo1D::overflow(), YODA::AnalysisObject::path(), YODA::Dbn1D::sumW(), YODA::Bin1D< DBN >::sumW(), YODA::Dbn1D::sumW2(), YODA::Bin1D< DBN >::sumW2(), YODA::AnalysisObject::title(), YODA::Histo1D::underflow(), YODA::Bin1D< DBN >::xMax(), and YODA::Bin1D< DBN >::xMin().

Referenced by toNewTH1D().

219  {
220  // Work out bin edges first
221  std::vector<double> edges;
222  edges.reserve(h.numBins()+1);
223  edges.push_back(h.bin(0).xMin());
224  for (size_t i = 0; i < h.numBins(); ++i) {
225  const HistoBin1D& b = h.bin(i);
226  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
227  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
228  }
229  // Book ROOT histogram
230  TH1D rtn(h.path().c_str(), h.title().c_str(), edges.size()-1, &edges[0]);
231  rtn.Sumw2();
232  TArrayD& sumw2s = *rtn.GetSumw2();
233  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
234  try {
235  const HistoBin1D& b = h.binAt(rtn.GetBinCenter(i)); // throws if in a gap
236  rtn.SetBinContent(i, b.sumW());
237  sumw2s[i] = b.sumW2();
238  } catch (const Exception& e) { }
239  }
240  // Overflows
241  rtn.SetBinContent(0, h.underflow().sumW());
242  rtn.SetBinContent(rtn.GetNbinsX()+1, h.overflow().sumW());
243  sumw2s[0] = h.underflow().sumW2();
244  sumw2s[rtn.GetNbinsX()+1] = h.overflow().sumW2();
245  // Labels
246  if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel").c_str());
247  if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel").c_str());
248  return rtn;
249  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ toTH1D() [2/2]

TH1D YODA::toTH1D ( const Profile1D p)
inline

Convert a YODA Profile1D to a ROOT TH1D.

Definition at line 373 of file ROOTCnv.h.

References YODA::AnalysisObject::annotation(), YODA::Profile1D::bin(), YODA::Profile1D::binAt(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::ProfileBin1D::mean(), YODA::Profile1D::numBins(), YODA::Profile1D::overflow(), YODA::AnalysisObject::path(), YODA::ProfileBin1D::stdErr(), YODA::AnalysisObject::title(), YODA::Profile1D::underflow(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMin(), YODA::Dbn2D::yMean(), and YODA::Dbn2D::yStdErr().

373  {
374  // Work out bin edges first
375  std::vector<double> edges;
376  edges.reserve(p.numBins()+1);
377  edges.push_back(p.bin(0).xMin());
378  for (size_t i = 0; i < p.numBins(); ++i) {
379  const ProfileBin1D& b = p.bin(i);
380  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
381  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
382  }
383  // Book ROOT histogram
384  TH1D rtn(p.path().c_str(), p.title().c_str(), edges.size()-1, &edges[0]);
385  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
386  try {
387  const ProfileBin1D& b = p.binAt(rtn.GetBinCenter(i)); // throws if in a gap
388  rtn.SetBinContent(i, b.mean());
389  rtn.SetBinError(i, b.stdErr());
390  } catch (const Exception& e) { }
391  }
392  // Overflows
393  rtn.SetBinContent(0, p.underflow().yMean());
394  rtn.SetBinContent(rtn.GetNbinsX()+1, p.overflow().yMean());
395  rtn.SetBinError(0, p.underflow().yStdErr());
396  rtn.SetBinError(rtn.GetNbinsX()+1, p.overflow().yStdErr());
397  // Labels
398  if (p.hasAnnotation("XLabel")) rtn.SetXTitle(p.annotation("XLabel").c_str());
399  if (p.hasAnnotation("YLabel")) rtn.SetYTitle(p.annotation("YLabel").c_str());
400  return rtn;
401  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ toTH2D()

TH2D YODA::toTH2D ( const Histo2D h)
inline

Convert a YODA Histo2D to a ROOT 2D histogram.

Todo:
Check/improve/extend – needs SetBinError or not?
Todo:
Connect up when supported in YODA... if 2D overflows are possible in ROOT?!

Definition at line 261 of file ROOTCnv.h.

References YODA::AnalysisObject::annotation(), YODA::Histo2D::bin(), YODA::Histo2D::binAt(), YODA::AnalysisObject::hasAnnotation(), YODA::Histo2D::numBins(), YODA::AnalysisObject::path(), YODA::Bin2D< DBN >::sumW(), YODA::Bin2D< DBN >::sumW2(), YODA::AnalysisObject::title(), YODA::Bin2D< DBN >::xMax(), YODA::Bin2D< DBN >::xMin(), YODA::Bin2D< DBN >::yMax(), and YODA::Bin2D< DBN >::yMin().

Referenced by toNewTH2D().

261  {
262  // Work out bin edges first
263  std::vector<double> xedges, yedges;
264  xedges.reserve(h.numBins()+1);
265  yedges.reserve(h.numBins()+1);
266  xedges.push_back(h.bin(0).xMin());
267  yedges.push_back(h.bin(0).yMin());
268  for (size_t i = 0; i < h.numBins(); ++i) {
269  const HistoBin2D& b = h.bin(i);
270  xedges.push_back(b.xMin());
271  xedges.push_back(b.xMax());
272  yedges.push_back(b.yMin());
273  yedges.push_back(b.yMax());
274  }
275  // Sort and remove (fuzzy) duplicate edges
276  std::sort(xedges.begin(), xedges.end());
277  std::sort(yedges.begin(), yedges.end());
278  const std::vector<double>::iterator xlast = std::unique(xedges.begin(), xedges.end());
279  const std::vector<double>::iterator ylast = std::unique(yedges.begin(), yedges.end());
280  xedges.erase(xlast, xedges.end());
281  yedges.erase(ylast, yedges.end());
282 
283  // Book ROOT histogram
284  TH2D rtn(h.path().c_str(), h.title().c_str(), xedges.size()-1, &xedges[0], yedges.size()-1, &yedges[0]);
285  rtn.Sumw2();
286  TArrayD& sumw2s = *rtn.GetSumw2();
287  for (int ix = 1; ix <= rtn.GetNbinsX(); ++ix) {
288  for (int iy = 1; iy <= rtn.GetNbinsY(); ++iy) {
289  const int i = rtn.GetBin(ix, iy);
290  try {
291  //const HistoBin2D& b = h.binAt(rtn.GetBinCenter(ix), rtn.GetBinCenter(iy)); // throws if in a gap
292  const HistoBin2D& b = h.binAt(rtn.GetXaxis()->GetBinCenter(ix), rtn.GetYaxis()->GetBinCenter(iy)); // throws if in a gap
293  rtn.SetBinContent(i, b.sumW());
294  sumw2s[i] = b.sumW2();
295  } catch (const Exception& e) { }
296  }
297  }
298  // Overflows
300  // rtn.SetBinContent(0, h.underflow().sumW());
301  // rtn.SetBinContent(rtn.GetNbinsX()+1, h.overflow().sumW());
302  // sumw2s[0] = h.underflow().sumW2();
303  // sumw2s[rtn.GetNbinsX()+1] = h.overflow().sumW2();
304  // Labels
305  if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel").c_str());
306  if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel").c_str());
307  if (h.hasAnnotation("ZLabel")) rtn.SetZTitle(h.annotation("ZLabel").c_str());
308  return rtn;
309  }

◆ toTProfile()

TProfile YODA::toTProfile ( const Profile1D p)
inline

Convert a YODA Scatter2D to a ROOT TH1D.

Convert a YODA Profile1D to a ROOT TProfile

Warning
Reported not to work, and maybe not to be possible at all...
Todo:
Check/improve/extend. How to set all the y-weights in ROOT profiles?
Todo:
Need to set the following, according to Roman Lysak:

Definition at line 327 of file ROOTCnv.h.

References YODA::AnalysisObject::annotation(), YODA::Profile1D::bin(), YODA::Profile1D::binAt(), fuzzyEquals(), YODA::AnalysisObject::hasAnnotation(), YODA::Profile1D::numBins(), YODA::Profile1D::overflow(), YODA::AnalysisObject::path(), YODA::Dbn2D::sumW(), YODA::Bin1D< DBN >::sumW(), YODA::ProfileBin1D::sumWY(), YODA::Dbn2D::sumWY(), YODA::ProfileBin1D::sumWY2(), YODA::Dbn2D::sumWY2(), YODA::AnalysisObject::title(), YODA::Profile1D::underflow(), YODA::Bin1D< DBN >::xMax(), and YODA::Bin1D< DBN >::xMin().

Referenced by toNewTProfile().

327  {
328  // Work out bin edges first
329  std::vector<double> edges;
330  edges.reserve(p.numBins()+1);
331  edges.push_back(p.bin(0).xMin());
332  for (size_t i = 0; i < p.numBins(); ++i) {
333  const ProfileBin1D& b = p.bin(i);
334  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
335  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
336  }
337  // Book ROOT histogram
338  TProfile rtn(p.path().c_str(), p.title().c_str(), edges.size()-1, &edges[0]);
339  rtn.Sumw2();
340  Double_t* sumwys = rtn.GetArray(); //< YUCK!!!
341  TArrayD& sumwy2s = *rtn.GetSumw2(); //< YUCK!!!
342  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
343  try {
344  const ProfileBin1D& b = p.binAt(rtn.GetBinCenter(i)); // throws if in a gap
345  // rtn.SetBinContent(i, b.mean());
346  // rtn.SetBinError(i, b.stdErr());
348  // - for sum(y*y): TProfile::GetSumw2()
349  // - for sum(y): TProfile::GetArray()
350  // - for sum(w): TProfile::SetBinEntries(bin, w)
351  // Clearly, the names of accessors/methods are confusing...
352  rtn.SetBinEntries(i, b.sumW());
353  sumwys[i] = b.sumWY();
354  sumwy2s[i] = b.sumWY2();
355  } catch (const Exception& e) { }
356  }
357  // Overflows
358  rtn.SetBinEntries(0, p.underflow().sumW());
359  rtn.SetBinEntries(rtn.GetNbinsX()+1, p.overflow().sumW());
360  sumwys[0] = p.underflow().sumWY();
361  sumwys[0] = p.underflow().sumWY();
362  sumwy2s[rtn.GetNbinsX()+1] = p.overflow().sumWY2();
363  sumwy2s[rtn.GetNbinsX()+1] = p.overflow().sumWY2();
364  // Labels
365  if (p.hasAnnotation("XLabel")) rtn.SetXTitle(p.annotation("XLabel").c_str());
366  if (p.hasAnnotation("YLabel")) rtn.SetYTitle(p.annotation("YLabel").c_str());
367  return rtn;
368  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:72

◆ transformX() [1/3]

template<typename FNX >
void YODA::transformX ( Scatter1D s,
FNX  fx 
)
inline

Apply transformation fx(x) to all values and error positions (operates in-place on s)

fx should be a function which takes double x -> double newx

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 308 of file Scatter1D.h.

References YODA::Scatter1D::numPoints(), YODA::Scatter1D::point(), YODA::Point1D::setX(), YODA::Point1D::setXErrMinus(), YODA::Point1D::setXErrPlus(), YODA::Point1D::x(), YODA::Point1D::xMax(), and YODA::Point1D::xMin().

308  {
309  for (size_t i = 0; i < s.numPoints(); ++i) {
310  Point1D& p = s.point(i);
311  const double newx = fx(p.x());
312  const double fx_xmin = fx(p.xMin());
313  const double fx_xmax = fx(p.xMax());
314  // Deal with possible inversions of min/max ordering under the transformation
315  const double newxmin = std::min(fx_xmin, fx_xmax);
316  const double newxmax = std::max(fx_xmin, fx_xmax);
317  // Set new point x values
318  p.setX(newx);
320  p.setXErrMinus(newx - newxmin);
321  p.setXErrPlus(newxmax - newx);
322  }
323  }

◆ transformX() [2/3]

template<typename FNX >
void YODA::transformX ( Scatter2D s,
FNX  fx 
)
inline

Apply transformation fx(x) to all values and error positions (operates in-place on s)

fx should be a function which takes double x -> double newx

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 353 of file Scatter2D.h.

References YODA::Scatter2D::numPoints(), YODA::Scatter2D::point(), YODA::Point2D::setX(), YODA::Point2D::setXErrMinus(), YODA::Point2D::setXErrPlus(), YODA::Point2D::x(), YODA::Point2D::xMax(), and YODA::Point2D::xMin().

353  {
354  for (size_t i = 0; i < s.numPoints(); ++i) {
355  Point2D& p = s.point(i);
356  const double newx = fx(p.x());
357  const double fx_xmin = fx(p.xMin());
358  const double fx_xmax = fx(p.xMax());
359  // Deal with possible inversions of min/max ordering under the transformation
360  const double newxmin = std::min(fx_xmin, fx_xmax);
361  const double newxmax = std::max(fx_xmin, fx_xmax);
362  // Set new point x values
363  p.setX(newx);
365  p.setXErrMinus(newx - newxmin);
366  p.setXErrPlus(newxmax - newx);
367  }
368  }

◆ transformX() [3/3]

template<typename FNX >
void YODA::transformX ( Scatter3D s,
FNX  fx 
)
inline

Apply transformation fx(x) to all values and error positions (operates in-place on s)

fx should be a function which takes double x -> double newx

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 367 of file Scatter3D.h.

References YODA::Scatter3D::numPoints(), YODA::Scatter3D::point(), YODA::Point3D::setX(), YODA::Point3D::setXErrMinus(), YODA::Point3D::setXErrPlus(), YODA::Point3D::x(), YODA::Point3D::xMax(), and YODA::Point3D::xMin().

367  {
368  for (size_t i = 0; i < s.numPoints(); ++i) {
369  Point3D& p = s.point(i);
370  const double newx = fx(p.x());
371  const double fx_xmin = fx(p.xMin());
372  const double fx_xmax = fx(p.xMax());
373  // Deal with possible inversions of min/max ordering under the transformation
374  const double newxmin = std::min(fx_xmin, fx_xmax);
375  const double newxmax = std::max(fx_xmin, fx_xmax);
376  // Set new point x values
377  p.setX(newx);
379  p.setXErrMinus(newx - newxmin);
380  p.setXErrPlus(newxmax - newx);
381  }
382  }

◆ transformY() [1/2]

template<typename FNY >
void YODA::transformY ( Scatter2D s,
FNY  fy 
)
inline

Apply transformation fy(y) to all values and error positions (operates in-place on s)

fy should be a function which takes double y -> double newy

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 375 of file Scatter2D.h.

References YODA::Scatter2D::numPoints(), YODA::Scatter2D::point(), YODA::Point2D::setY(), YODA::Point2D::setYErrMinus(), YODA::Point2D::setYErrPlus(), YODA::Point2D::y(), YODA::Point2D::yMax(), and YODA::Point2D::yMin().

375  {
376  for (size_t i = 0; i < s.numPoints(); ++i) {
377  Point2D& p = s.point(i);
378  const double newy = fy(p.y());
379  const double fy_ymin = fy(p.yMin());
380  const double fy_ymax = fy(p.yMax());
381  // Deal with possible inversions of min/max ordering under the transformation
382  const double newymin = std::min(fy_ymin, fy_ymax);
383  const double newymax = std::max(fy_ymin, fy_ymax);
384  // Set new point y values
385  p.setY(newy);
387  p.setYErrMinus(newy - newymin);
388  p.setYErrPlus(newymax - newy);
389  }
390  }

◆ transformY() [2/2]

template<typename FNY >
void YODA::transformY ( Scatter3D s,
FNY  fy 
)
inline

Apply transformation fy(y) to all values and error positions (operates in-place on s)

fy should be a function which takes double y -> double newy

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 389 of file Scatter3D.h.

References YODA::Scatter3D::numPoints(), YODA::Scatter3D::point(), YODA::Point3D::setY(), YODA::Point3D::setYErrMinus(), YODA::Point3D::setYErrPlus(), YODA::Point3D::y(), YODA::Point3D::yMax(), and YODA::Point3D::yMin().

389  {
390  for (size_t i = 0; i < s.numPoints(); ++i) {
391  Point3D& p = s.point(i);
392  const double newy = fy(p.y());
393  const double fy_ymin = fy(p.yMin());
394  const double fy_ymax = fy(p.yMax());
395  // Deal with possible inversions of min/max ordering under the transformation
396  const double newymin = std::min(fy_ymin, fy_ymax);
397  const double newymax = std::max(fy_ymin, fy_ymax);
398  // Set new point y values
399  p.setY(newy);
401  p.setYErrMinus(newy - newymin);
402  p.setYErrPlus(newymax - newy);
403  }
404  }

◆ transformZ()

template<typename FNZ >
void YODA::transformZ ( Scatter3D s,
FNZ  fz 
)
inline

Apply transformation fz(z) to all values and error positions (operates in-place on s)

fz should be a function which takes double z -> double newz

Todo:
Be careful about transforms which could switch around min and max errors, or send both in the same direction!

Definition at line 411 of file Scatter3D.h.

References YODA::Scatter3D::numPoints(), YODA::Scatter3D::point(), YODA::Point3D::setZ(), YODA::Point3D::setZErrMinus(), YODA::Point3D::setZErrPlus(), YODA::Point3D::z(), YODA::Point3D::zMax(), and YODA::Point3D::zMin().

411  {
412  for (size_t i = 0; i < s.numPoints(); ++i) {
413  Point3D& p = s.point(i);
414  const double newz = fz(p.z());
415  const double fz_zmin = fz(p.zMin());
416  const double fz_zmax = fz(p.zMax());
417  // Deal with possible inversions of min/max ordering under the transformation
418  const double newzmin = std::min(fz_zmin, fz_zmax);
419  const double newzmax = std::max(fz_zmin, fz_zmax);
420  // Set new point z values
421  p.setZ(newz);
423  p.setZErrMinus(newz - newzmin);
424  p.setZErrPlus(newzmax - newz);
425  }
426  }

◆ version()

std::string YODA::version ( )
inline

Namespaced version string function.

Definition at line 25 of file YodaConfig.h.

References YODA_VERSION.

25  {
26  return YODA_VERSION;
27  }
#define YODA_VERSION
Definition: YodaConfig.h:19

◆ write() [1/6]

void YODA::write ( const std::string &  filename,
const AnalysisObject ao 
)

Write out object ao to file filename.

Definition at line 19 of file IO.h.

References mkWriter(), and YODA::Writer::write().

Referenced by YODA::Writer::write().

19  {
20  Writer& w = mkWriter(filename);
21  w.write(filename, ao);
22  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

◆ write() [2/6]

template<typename RANGE >
void YODA::write ( const std::string &  filename,
const RANGE &  aos 
)

Write out a collection of objects objs to file filename.

Definition at line 26 of file IO.h.

References mkWriter(), and YODA::Writer::write().

26  {
27  Writer& w = mkWriter(filename);
28  w.write(filename, aos);
29  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

◆ write() [3/6]

template<typename AOITER >
void YODA::write ( const std::string &  filename,
const AOITER &  begin,
const AOITER &  end 
)

Write out the objects specified by start iterator begin and end iterator end to file filename.

Definition at line 34 of file IO.h.

References mkWriter(), and YODA::Writer::write().

34  {
35  Writer& w = mkWriter(filename);
36  w.write(filename, begin, end);
37  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

◆ write() [4/6]

void YODA::write ( std::ostream &  os,
const AnalysisObject ao,
const std::string &  fmt 
)

Write out object ao to stream os with format fmt.

Definition at line 46 of file IO.h.

References mkWriter(), and YODA::Writer::write().

46  {
47  Writer& w = mkWriter(fmt);
48  w.write(os, ao);
49  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

◆ write() [5/6]

template<typename RANGE >
void YODA::write ( std::ostream &  os,
const RANGE &  aos,
const std::string &  fmt 
)

Write out a collection of objects objs to file filename.

Definition at line 53 of file IO.h.

References mkWriter(), and YODA::Writer::write().

53  {
54  Writer& w = mkWriter(fmt);
55  w.write(os, aos);
56  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

◆ write() [6/6]

template<typename AOITER >
void YODA::write ( std::ostream &  os,
const AOITER &  begin,
const AOITER &  end,
const std::string &  fmt 
)

Write out the objects specified by start iterator begin and end iterator end to file filename.

Definition at line 61 of file IO.h.

References mkWriter(), and YODA::Writer::write().

61  {
62  Writer& w = mkWriter(fmt);
63  w.write(os, begin, end);
64  }
Writer & mkWriter(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Writer.cc:25

Variable Documentation

◆ HALFPI

const double YODA::HALFPI = M_PI_2
static

A pre-defined value of $ \pi/2 $.

Definition at line 44 of file MathUtils.h.

◆ MAXDOUBLE

const double YODA::MAXDOUBLE = DBL_MAX
static

Pre-defined numeric type limits

Deprecated:
Prefer the standard DBL/INT_MAX

Definition at line 34 of file MathUtils.h.

◆ MAXINT

const double YODA::MAXINT = INT_MAX
static

Definition at line 35 of file MathUtils.h.

◆ PI

const double YODA::PI = M_PI
static

A pre-defined value of $ \pi $.

Definition at line 38 of file MathUtils.h.

◆ TWOPI

const double YODA::TWOPI = 2*M_PI
static

A pre-defined value of $ 2\pi $.

Definition at line 41 of file MathUtils.h.

◆ YODA_FORMAT_VERSION

const int YODA::YODA_FORMAT_VERSION = 2
static

Definition at line 30 of file WriterYODA.cc.