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

Classes

class  AnalysisObject
 AnalysisObject is the base class for histograms and scatters. 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  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...
 
class  Error
 An N-dimensional error to be contained in a Point<N> More...
 
class  Exception
 Generic unspecialised YODA runtime error. More...
 
class  BinningError
 Error for general binning problems. More...
 
class  RangeError
 Error for e.g. use of invalid bin ranges. More...
 
class  LockError
 Error for modification of a data object where filling has already begun. More...
 
class  GridError
 Error to throw when a slicing is requested on a non-slicable state of an object. More...
 
class  LogicError
 Error for places where it should not have been possible to get to! More...
 
class  WeightError
 Errors relating to event/bin weights. More...
 
class  LowStatsError
 Errors relating to insufficient (effective) statistics. More...
 
class  AnnotationError
 Error for unfound or broken AnalysisObject annotations. More...
 
class  ReadError
 Error for file reading errors. More...
 
class  UserError
 Error for problems introduced outside YODA, to put it nicely. 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...
 
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  Point
 An N-dimensional data point to be contained in a Scatter<N> 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...
 
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  ReaderYODA
 Persistency reader from YODA flat text data format. 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  Scatter
 A very generic data type which is just a collection of ND data points with errors. More...
 
struct  CmpFloats
 Functor to compare two floating point numbers and return whether they are fuzzily equivalent. More...
 
class  Weights
 A named, vectorised generalisation of an event weight. 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

typedef Axis1D< HistoBin1D, Dbn1DHisto1DAxis
 Convenience typedef. More...
 
typedef Axis2D< HistoBin2D, Dbn2DHisto2DAxis
 Convenience typedef. More...
 
typedef Axis1D< ProfileBin1D,
Dbn2D
Profile1DAxis
 Convenience typedef. More...
 
typedef Axis2D< ProfileBin2D,
Dbn3D
Profile2DAxis
 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...
 
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)
 
bool operator!= (const YODA::Point1D &a, const YODA::Point1D &b)
 
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)
 Equality test of x characteristics only. More...
 
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)
 Divide two histograms, with an uncorrelated error treatment. More...
 
Scatter2D operator/ (const Histo1D &numer, const Histo1D &denom)
 Divide two histograms, with an uncorrelated error treatment. 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 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)
 
Reader functions 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 output stream stream. 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)
 
Scatter2D toScatter2D (const TH1 *th1)
 Convert a ROOT 1D histogram (including TProfile) to a YODA Scatter2D. More...
 
Conversion functions from YODA to ROOT data types
TH1D toTH1D (const Histo1D &h)
 Convert a YODA Histo1D to a ROOT 1D histogram. More...
 
TH2D toTH2D (const Histo2D &h)
 Convert a YODA Histo2D to a ROOT 2D histogram. 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...
 
TGraphAsymmErrors toTGraph (const Scatter2D &s)
 Convert a YODA Scatter2D to a ROOT TGraphAsymmErrors. More...
 
TGraphAsymmErrors toTGraph (const Histo1D &h)
 Convert a YODA Histo1D to a ROOT TGraphAsymmErrors. More...
 
TGraphAsymmErrors toTGraph (const Profile1D &p)
 Convert a YODA Profile1D to a ROOT TGraphAsymmErrors. 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=false)
 Make a Scatter2D representation of a Histo1D. More...
 
Scatter2D mkScatter (const Profile1D &p, bool usefocus=false)
 Make a Scatter2D representation of a Profile1D. More...
 
Scatter2D mkScatter (const Scatter2D &s)
 
Scatter3D mkScatter (const Histo2D &h, bool usefocus=false)
 Make a Scatter3D representation of a Histo2D. More...
 
Scatter3D mkScatter (const Profile2D &p, bool usefocus=false)
 Make a Scatter3D representation of a Profile2D. More...
 
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...
 
Combining scatters: global operators, assuming aligned points
Todo:
This "1D histo-like behaviour" breaks the x/y/z symmetry... is there another way?
Scatter2D add (const Scatter2D &first, const Scatter2D &second)
 Add two scatters. More...
 
Scatter2D operator+ (const Scatter2D &first, const Scatter2D &second)
 Add two scatters. More...
 
Scatter2D subtract (const Scatter2D &first, const Scatter2D &second)
 Subtract two scatters. More...
 
Scatter2D operator- (const Scatter2D &first, const Scatter2D &second)
 Subtract two scatters. More...
 
Scatter2D divide (const Scatter2D &numer, const Scatter2D &denom)
 Divide two scatters. More...
 
Scatter2D operator/ (const Scatter2D &numer, const Scatter2D &denom)
 Divide two scatters. More...
 
Scatter3D add (const Scatter3D &first, const Scatter3D &second)
 Add two scatters. More...
 
Scatter3D operator+ (const Scatter3D &first, const Scatter3D &second)
 Add two scatters. More...
 
Scatter3D subtract (const Scatter3D &first, const Scatter3D &second)
 Subtract two scatters. More...
 
Scatter3D operator- (const Scatter3D &first, const Scatter3D &second)
 Subtract two scatters. More...
 
Scatter3D divide (const Scatter3D &numer, const Scatter3D &denom)
 Divide two scatters. More...
 
Scatter3D operator/ (const Scatter3D &numer, const Scatter3D &denom)
 Divide two scatters. 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...
 
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 UNUSED(tolerance)=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 UNUSED(tolerance)=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 UNUSED(tolerance)=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 UNUSED(tolerance)=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

const double MAXDOUBLE = std::numeric_limits<double>::max()
 
const double MAXINT = std::numeric_limits<int>::max()
 
const double PI = M_PI
 A pre-defined value of $ \pi $. More...
 
const double TWOPI = 2*M_PI
 A pre-defined value of $ 2\pi $. More...
 
const double HALFPI = M_PI_2
 A pre-defined value of $ \pi/2 $. More...
 

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

Convenience typedef.

Definition at line 23 of file Histo1D.h.

Convenience typedef.

Definition at line 23 of file Histo2D.h.

Convenience typedef.

Definition at line 24 of file Profile1D.h.

Convenience typedef.

Definition at line 23 of file Profile2D.h.

Enumeration Type Documentation

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 143 of file MathUtils.h.

enum YODA::Sign

Enum for signs of numbers.

Enumerator
MINUS 
ZERO 
PLUS 

Definition at line 43 of file MathUtils.h.

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

Function Documentation

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

Add two counters.

Definition at line 205 of file Counter.h.

Referenced by operator+().

205  {
206  Counter tmp = first;
207  tmp += second;
208  return tmp;
209  }
Profile1D YODA::add ( const Profile1D &  first,
const Profile1D &  second 
)
inline

Add two profile histograms.

Definition at line 312 of file Profile1D.h.

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

312  {
313  Profile1D tmp = first;
314  if (first.path() != second.path()) tmp.setPath("");
315  tmp += second;
316  return tmp;
317  }
Scatter2D YODA::add ( const Scatter2D &  first,
const Scatter2D &  second 
)

Add two scatters.

Todo:
Lots of boilerplate shared between these three functions, but I can't think of a C++ way to do it better, since functors for value and error combination are so heavy.
Todo:
Does this even make sense?
Todo:
Deal with +/- errors separately?
Todo:
Deal with +/- errors separately?

Definition at line 81 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), fuzzyEquals(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), sqr(), YODA::Point2D::xMax(), YODA::Point2D::xMin(), YODA::Point2D::y(), and YODA::Point2D::yErrAvg().

81  {
82  Scatter2D tmp;
83  for (size_t i = 0; i < first.numPoints(); ++i) {
84  const Point2D& p1 = first.point(i);
85  const Point2D& p2 = second.point(i);
86  if (!fuzzyEquals(p1.xMin(), p2.xMin()) || !fuzzyEquals(p1.xMax(), p2.xMax()))
87  throw BinningError("Point x binnings are not equivalent for " + first.path() + " + " + second.path());
88  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
89  const double x = (p1.xMin() + p1.xMax()) / 2.0;
90  const double exminus = x - p1.xMin();
91  const double explus = p1.xMax() - x;
92  //
93  const double y = p1.y() + p2.y();
95  const double ey = sqrt( sqr(p1.yErrAvg()) + sqr(p2.yErrAvg()) );
96  tmp.addPoint(x, y, exminus, explus, ey, ey);
97  }
98  assert(tmp.numPoints() == first.numPoints());
99  return tmp;
100  }
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:68
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
Scatter3D YODA::add ( const Scatter3D &  first,
const Scatter3D &  second 
)

Add two scatters.

Todo:
Implement
Todo:
Implement

Definition at line 10 of file Scatter3D.cc.

10  {
12  throw Exception("Implement me!");
13  Scatter3D tmp;
14  return tmp;
15  }
Histo1D YODA::add ( const Histo1D &  first,
const Histo1D &  second 
)
inline

Add two histograms.

Definition at line 375 of file Histo1D.h.

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

375  {
376  Histo1D tmp = first;
377  if (first.path() != second.path()) tmp.setPath("");
378  tmp += second;
379  return tmp;
380  }
Profile2D YODA::add ( const Profile2D &  first,
const Profile2D &  second 
)
inline

Add two profile histograms.

Definition at line 394 of file Profile2D.h.

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

394  {
395  Profile2D tmp = first;
396  if (first.path() != second.path()) tmp.setPath("");
397  tmp += second;
398  return tmp;
399  }
Histo2D YODA::add ( const Histo2D &  first,
const Histo2D &  second 
)
inline

Add two histograms.

Definition at line 432 of file Histo2D.h.

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

432  {
433  Histo2D tmp = first;
434  if (first.path() != second.path()) tmp.setPath("");
435  tmp += second;
436  return tmp;
437  }
template<typename Num >
Num YODA::add_quad ( Num  a,
Num  b 
)
inline

Named number-type addition in quadrature operation.

Definition at line 209 of file MathUtils.h.

Referenced by chi2(), and divide().

209  {
210  return sqrt(a*a + b*b);
211  }
template<typename Num >
Num YODA::add_quad ( Num  a,
Num  b,
Num  c 
)
inline

Named number-type addition in quadrature operation.

Definition at line 215 of file MathUtils.h.

215  {
216  return sqrt(a*a + b*b + c*c);
217  }
double YODA::approx ( double  a,
int  n = 5 
)
inline

Returns a number floored at the nth decimal place.

Definition at line 127 of file MathUtils.h.

127  {
128  double roundTo = pow(10.0,n);
129  a *= roundTo;
130  a = floor(a);
131  return a/roundTo;
132  }
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 432 of file Histo1D.h.

432  {
433  return (a-b) / (a+b);
434  }
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 490 of file Histo2D.h.

490  {
491  return (a-b) / (a+b);
492  }
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:203
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:209
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
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:203
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:209
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
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:203
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:209
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
template<int N>
Scatter<N> YODA::combine ( const Scatter< N > &  a,
const Scatter< N > &  b 
)
inline

Definition at line 234 of file ScatterND.h.

References YODA::Scatter< N >::combineWith().

234  {
235  Scatter<N> rtn = a;
236  rtn.combineWith(b);
237  return rtn;
238  }
template<int N>
Scatter<N> YODA::combine ( const std::vector< Scatter< N > > &  scatters)
inline

Definition at line 241 of file ScatterND.h.

References YODA::Scatter< N >::combineWith().

241  {
242  Scatter<N> rtn;
243  rtn.combineWith(scatters);
244  return rtn;
245  }
Scatter1D YODA::combine ( const Scatter1D &  a,
const Scatter1D &  b 
)
inline

Definition at line 248 of file Scatter1D.h.

References YODA::Scatter1D::combineWith().

248  {
249  Scatter1D rtn = a;
250  rtn.combineWith(b);
251  return rtn;
252  }
Scatter1D YODA::combine ( const std::vector< Scatter1D > &  scatters)
inline

Definition at line 254 of file Scatter1D.h.

References YODA::Scatter1D::combineWith().

254  {
255  Scatter1D rtn;
256  rtn.combineWith(scatters);
257  return rtn;
258  }
Scatter2D YODA::combine ( const Scatter2D &  a,
const Scatter2D &  b 
)
inline

Definition at line 280 of file Scatter2D.h.

References YODA::Scatter2D::combineWith().

280  {
281  Scatter2D rtn = a;
282  rtn.combineWith(b);
283  return rtn;
284  }
Scatter2D YODA::combine ( const std::vector< Scatter2D > &  scatters)
inline

Definition at line 286 of file Scatter2D.h.

References YODA::Scatter2D::combineWith().

286  {
287  Scatter2D rtn;
288  rtn.combineWith(scatters);
289  return rtn;
290  }
Scatter3D YODA::combine ( const Scatter3D &  a,
const Scatter3D &  b 
)
inline

Definition at line 292 of file Scatter3D.h.

References YODA::Scatter3D::combineWith().

292  {
293  Scatter3D rtn = a;
294  rtn.combineWith(b);
295  return rtn;
296  }
Scatter3D YODA::combine ( const std::vector< Scatter3D > &  scatters)
inline

Definition at line 298 of file Scatter3D.h.

References YODA::Scatter3D::combineWith().

298  {
299  Scatter3D rtn;
300  rtn.combineWith(scatters);
301  return rtn;
302  }
double YODA::correlation ( const std::vector< int > &  sample1,
const std::vector< int > &  sample2 
)
inline

Calculate the correlation strength between two samples.

Definition at line 337 of file MathUtils.h.

References covariance().

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

Calculate the covariance (variance) between two samples.

Definition at line 322 of file MathUtils.h.

References mean().

Referenced by correlation().

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

Divide two counters, with an uncorrelated error treatment

Todo:
Or just return a Point1D?

Definition at line 24 of file Counter.cc.

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

Referenced by divide(), efficiency(), and operator/().

24  {
25  Scatter1D rtn;
26  if (denom.val() != 0) {
27  const double val = numer.val() / denom.val();
28  const double err = val * add_quad(numer.relErr(), denom.relErr());
29  rtn.addPoint(val, err);
30  } else {
31  rtn.addPoint(0, 0);
32  }
33  return rtn;
34  }
Num add_quad(Num a, Num b)
Named number-type addition in quadrature operation.
Definition: MathUtils.h:209
Scatter2D YODA::divide ( const Profile1D &  numer,
const Profile1D &  denom 
)

Divide two profile histograms.

Definition at line 106 of file Profile1D.cc.

References divide(), and mkScatter().

106  {
107  return divide(mkScatter(numer), mkScatter(denom));
108  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
Scatter2D YODA::divide ( const Scatter2D &  numer,
const Scatter2D &  denom 
)

Divide two scatters.

Todo:

Need to rework this: should be able to divide matching pairs of points along either axis

In general any pairing of points should be able to have any binary operation applied to it...

Todo:
Provide optional alt behaviours to fill with NaN or remove the invalid point or throw
Todo:
Don't throw here: set a flag and throw after all bins have been handled.
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:
Provide optional alt behaviours to fill with NaN or remove the invalid point or throw
Todo:
Don't throw here: set a flag and throw after all bins have been handled.
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 130 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), fuzzyEquals(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), sqr(), YODA::Point2D::xMax(), YODA::Point2D::xMin(), YODA::Point2D::y(), and YODA::Point2D::yErrAvg().

130  {
131  Scatter2D tmp;
132 
133  // for (size_t i = 0; i < numer.numPoints(); ++i) {
134  // std::cout << numer.point(i).xMin() << " ";
135  // std::cout << numer.point(i).xMax() << " ";
136  // }
137  // std::cout << std::endl;
138  // for (size_t i = 0; i < denom.numPoints(); ++i) {
139  // std::cout << denom.point(i).xMin() << " ";
140  // std::cout << denom.point(i).xMax() << " ";
141  // }
142  // std::cout << std::endl;
143 
144  for (size_t i = 0; i < numer.numPoints(); ++i) {
145  const Point2D& p1 = numer.point(i);
146  const Point2D& p2 = denom.point(i);
147 
148  // Assemble the x value and error
149  // std::cout << p1.xMin() << " vs " << p2.xMin() << " and " << p1.xMax() << " vs " << p2.xMax() << std::endl;
150  if (!fuzzyEquals(p1.xMin(), p2.xMin()) || !fuzzyEquals(p1.xMax(), p2.xMax()))
151  throw BinningError("Point x binnings are not equivalent in " + numer.path() + " / " + denom.path());
152 
153  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
154  const double x = (p1.xMin() + p1.xMax()) / 2.0;
155  const double exminus = x - p1.xMin();
156  const double explus = p1.xMax() - x;
157 
158  // Assemble the y value and error
159  double y = 0;
160  double ey = 0;
161  if (p2.y() == 0 || (p1.y() == 0 && p1.yErrAvg() != 0)) { //< @todo Why only if p1.yErrAvg() != 0, if p1.y == 0?
164  // throw LowStatsError("Requested division of empty bin");
165  } else {
166  y = p1.y() / p2.y();
168  const double relerr_1 = p1.yErrAvg() != 0 ? p1.yErrAvg()/p1.y() : 0;
169  const double relerr_2 = p2.yErrAvg() != 0 ? p2.yErrAvg()/p2.y() : 0;
170  ey = y * sqrt(sqr(relerr_1) + sqr(relerr_2));
171  }
174  //const double eyplus = y * sqrt( sqr(p1.yErrPlus()/p1.y()) + sqr(p2.yErrMinus()/p2.y()) );
175  //const double eyminus = y * sqrt( sqr(p1.yErrMinus()/p1.y()) + sqr(p2.yErrPlus()/p2.y()) );
176  tmp.addPoint(x, y, exminus, explus, ey, ey);
177  }
178  assert(tmp.numPoints() == numer.numPoints());
179  return tmp;
180  }
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:68
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
Scatter3D YODA::divide ( const Scatter3D &  numer,
const Scatter3D &  denom 
)

Divide two scatters.

Todo:
find a nicer solution than setting the bin to zero
Todo:
Generally deal with +/- errors separately
Todo:
find a nicer solution than setting the bin to zero
Todo:
Generally deal with +/- errors separately

Definition at line 93 of file Scatter3D.cc.

References YODA::Scatter3D::addPoint(), fuzzyEquals(), YODA::Scatter3D::numPoints(), YODA::Scatter3D::point(), sqr(), YODA::Point3D::xMax(), YODA::Point3D::xMin(), YODA::Point3D::yErrAvg(), YODA::Point3D::yMax(), YODA::Point3D::yMin(), and YODA::Point3D::z().

93  {
94  Scatter3D tmp;
95  for (size_t i = 0; i < numer.numPoints(); ++i) {
96  const Point3D& p1 = numer.point(i);
97  const Point3D& p2 = denom.point(i);
98 
99  // Assemble the x value and error
100  if (!fuzzyEquals(p1.xMin(), p2.xMin()) || !fuzzyEquals(p1.xMax(), p2.xMax()))
101  throw BinningError("Point x 'bins' are not equivalent");
102  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
103  const double x = (p1.xMin() + p1.xMax()) / 2.0;
104  const double exminus = x - p1.xMin();
105  const double explus = p1.xMax() - x;
106 
107  // Assemble the y value and error
108  if (!fuzzyEquals(p1.yMin(), p2.yMin()) || !fuzzyEquals(p1.yMax(), p2.yMax()))
109  throw BinningError("Point x 'bins' are not equivalent");
110  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
111  const double y = (p1.yMin() + p1.yMax()) / 2.0;
112  const double eyminus = y - p1.yMin();
113  const double eyplus = p1.yMax() - y;
114 
115  double z = 0;
116  double ez = 0;
117  if (p1.z() == 0 || p2.z() == 0) {
119  //throw LowStatsError("Requested division of empty bin");
120  } else {
121  z = p1.z() / p2.z();
123  ez = z * sqrt( sqr(p1.yErrAvg()/p1.z()) + sqr(p2.yErrAvg()/p2.z()) );
124  }
125  tmp.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
126  }
127  assert(tmp.numPoints() == numer.numPoints());
128  return tmp;
129  }
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:68
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
Scatter2D YODA::divide ( const Histo1D &  numer,
const Histo1D &  denom 
)

Divide two histograms, with an uncorrelated error treatment.

Todo:
Add multiply histograms -> Scatter2D
Todo:
Is this really an appropriate definition? Should Scatter/Scatter even exist?!?
Todo:
Is this really an appropriate definition? Should Scatter/Scatter even exist?!?

Definition at line 143 of file Histo1D.cc.

References divide(), and mkScatter().

143  {
145  return divide(mkScatter(numer), mkScatter(denom));
146  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
Scatter3D YODA::divide ( const Profile2D &  numer,
const Profile2D &  denom 
)

Divide two profile histograms.

Definition at line 174 of file Profile2D.cc.

References divide(), and mkScatter().

174  {
175  return divide(mkScatter(numer), mkScatter(denom));
176  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
Scatter3D YODA::divide ( const Histo2D &  numer,
const Histo2D &  denom 
)

Divide two histograms, with an uncorrelated error treatment.

Todo:
Add multiply histograms -> Scatter3D
Note
The two histos must have exactly the same binning.
Todo:
Implement without conversion to scatters; scatter division is a flawed idea
Todo:
Implement without conversion to scatters; scatter division is a flawed idea

Definition at line 298 of file Histo2D.cc.

References divide(), and mkScatter().

298  {
300  return divide(mkScatter(numer), mkScatter(denom));
301  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
Scatter1D YODA::efficiency ( const Counter &  accepted,
const Counter &  total 
)

Calculate an efficiency ratio of two counters.

Todo:
Add mkScatter
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?

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 38 of file Counter.cc.

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

38  {
39  Scatter1D tmp = divide(accepted, total);
40  assert(tmp.numPoints() == 1);
41 
43 
44  // Check that the numerator is consistent with being a subset of the denominator (NOT effNumEntries here!)
45  if (accepted.numEntries() > total.numEntries() || accepted.sumW() > total.sumW())
46  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator");
47 
48  // If no entries on the denominator, set eff = err = 0 and move to the next bin
51  double eff = 0, err = 0;
52  if (total.sumW() != 0) {
53  // Calculate the values and errors
54  // const double eff = b_acc.effNumEntries() / b_tot.effNumEntries();
55  // const double ey = sqrt( b_acc.effNumEntries() * (1 - b_acc.effNumEntries()/b_tot.effNumEntries()) ) / b_tot.effNumEntries();
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  // assert(point.y() == eff); //< @todo Correct? So we don't need to reset the eff on the next line?
59  }
60 
62 
63  tmp.point(0).setX(eff, err);
64  return tmp;
65  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
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.

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

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 H2

BEGIN DIMENSIONALITY-INDEPENDENT BIT TO SHARE WITH H2

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 H2

Definition at line 150 of file Histo1D.cc.

References YODA::Histo1D::bin(), divide(), YODA::Histo1D::numBins(), YODA::Bin1D< DBN >::numEntries(), YODA::Scatter2D::point(), YODA::Point2D::setY(), sqr(), YODA::Bin1D< DBN >::sumW(), and YODA::Bin1D< DBN >::sumW2().

150  {
151  Scatter2D tmp = divide(accepted, total);
152  for (size_t i = 0; i < accepted.numBins(); ++i) {
153  const HistoBin1D& b_acc = accepted.bin(i);
154  const HistoBin1D& b_tot = total.bin(i);
155  Point2D& point = tmp.point(i);
156 
158 
159  // Check that the numerator is consistent with being a subset of the denominator (NOT effNumEntries here!)
160  if (b_acc.numEntries() > b_tot.numEntries() || b_acc.sumW() > b_tot.sumW())
161  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator");
162 
163  // If no entries on the denominator, set eff = err = 0 and move to the next bin
166  double eff = 0, err = 0;
167  if (b_tot.sumW() != 0) {
168  // Calculate the values and errors
169  // const double eff = b_acc.effNumEntries() / b_tot.effNumEntries();
170  // const double ey = sqrt( b_acc.effNumEntries() * (1 - b_acc.effNumEntries()/b_tot.effNumEntries()) ) / b_tot.effNumEntries();
171  eff = b_acc.sumW() / b_tot.sumW(); //< Actually this is already calculated by the division...
172  err = sqrt(abs( ((1-2*eff)*b_acc.sumW2() + sqr(eff)*b_tot.sumW2()) / sqr(b_tot.sumW()) ));
173  // assert(point.y() == eff); //< @todo Correct? So we don't need to reset the eff on the next line?
174  }
175 
177 
178  point.setY(eff, err);
179  }
180  return tmp;
181  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
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

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 304 of file Histo2D.cc.

References YODA::Histo2D::bin(), divide(), YODA::Histo2D::numBins(), YODA::Bin2D< DBN >::numEntries(), YODA::Scatter3D::point(), YODA::Point3D::setZ(), sqr(), YODA::Bin2D< DBN >::sumW(), and YODA::Bin2D< DBN >::sumW2().

304  {
305  Scatter3D tmp = divide(accepted, total);
306  for (size_t i = 0; i < accepted.numBins(); ++i) {
307  const HistoBin2D& b_acc = accepted.bin(i);
308  const HistoBin2D& b_tot = total.bin(i);
309  Point3D& point = tmp.point(i);
310 
312 
313  // Check that the numerator is consistent with being a subset of the denominator (NOT effNumEntries here!)
314  if (b_acc.numEntries() > b_tot.numEntries() || b_acc.sumW() > b_tot.sumW())
315  throw UserError("Attempt to calculate an efficiency when the numerator is not a subset of the denominator");
316 
317  // If no entries on the denominator, set eff = err = 0 and move to the next bin
320  double eff = 0, err = 0;
321  if (b_tot.sumW() != 0) {
322  // Calculate the values and errors
323  // const double eff = b_acc.effNumEntries() / b_tot.effNumEntries();
324  // const double ey = sqrt( b_acc.effNumEntries() * (1 - b_acc.effNumEntries()/b_tot.effNumEntries()) ) / b_tot.effNumEntries();
325  eff = b_acc.sumW() / b_tot.sumW(); //< Actually this is already calculated by the division...
326  err = sqrt(abs( ((1-2*eff)*b_acc.sumW2() + sqr(eff)*b_tot.sumW2()) / sqr(b_tot.sumW()) ));
327  // assert(point.y() == eff); //< @todo Correct? So we don't need to reset the eff on the next line?
328  }
329 
331 
332  point.setZ(eff, err);
333  }
334  return tmp;
335 
336  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
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 406 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().

406  {
407  for (size_t i = 0; i < s.numPoints(); ++i) {
408  Point2D& p = s.point(i);
409  const double newx = p.y();
410  const double newy = p.x();
411  const double newxmin = p.yMin();
412  const double newxmax = p.yMax();
413  const double newymin = p.xMin();
414  const double newymax = p.xMax();
415  p.setX(newx);
416  p.setY(newy);
418  p.setXErrMinus(newx - newxmin);
419  p.setXErrPlus(newxmax - newx);
420  p.setYErrMinus(newy - newymin);
421  p.setYErrPlus(newymax - newy);
422  }
423  }
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 68 of file MathUtils.h.

References isZero().

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

68  {
69  const double absavg = (fabs(a) + fabs(b))/2.0;
70  const double absdiff = fabs(a - b);
71  const bool rtn = (isZero(a) && isZero(b)) || absdiff < tolerance*absavg;
72  // cout << a << " == " << b << "? " << rtn << endl;
73  return rtn;
74  }
bool isZero(long val, double UNUSED(tolerance)=1E-8)
Definition: MathUtils.h:60
bool YODA::fuzzyEquals ( long  a,
long  b,
double   UNUSEDtolerance = 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 84 of file MathUtils.h.

84  {
85  return a == b;
86  }
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 92 of file MathUtils.h.

References fuzzyEquals().

92  {
93  return a > b || fuzzyEquals(a, b, tolerance);
94  }
bool fuzzyEquals(long a, long b, double UNUSED(tolerance)=1E-5)
Compare two integral-type numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:84
bool YODA::fuzzyGtrEquals ( long  a,
long  b,
double   UNUSEDtolerance = 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 103 of file MathUtils.h.

103  {
104  return a >= b;
105  }
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 111 of file MathUtils.h.

References fuzzyEquals().

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

111  {
112  return a < b || fuzzyEquals(a, b, tolerance);
113  }
bool fuzzyEquals(long a, long b, double UNUSED(tolerance)=1E-5)
Compare two integral-type numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:84
bool YODA::fuzzyLessEquals ( long  a,
long  b,
double   UNUSEDtolerance = 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 122 of file MathUtils.h.

122  {
123  return a <= b;
124  }
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 292 of file MathUtils.h.

References inRange().

292  {
293  if (!inRange(val, binedges.front(), binedges.back())) return -1; //< Out of histo range
294  int index = -1;
295  for (size_t i = 1; i < binedges.size(); ++i) {
296  if (val < binedges[i]) {
297  index = i-1;
298  break;
299  }
300  }
301  assert(inRange(index, -1, binedges.size()-1));
302  return index;
303  }
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:190
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 151 of file MathUtils.h.

References CLOSED, and OPEN.

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

152  {
153  if (lowbound == OPEN && highbound == OPEN) {
154  return (value > low && value < high);
155  } else if (lowbound == OPEN && highbound == CLOSED) {
156  return (value > low && value <= high);
157  } else if (lowbound == CLOSED && highbound == OPEN) {
158  return (value >= low && value < high);
159  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
160  return (value >= low && value <= high);
161  }
162  }
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 166 of file MathUtils.h.

References inRange().

167  {
168  return inRange(value, lowhigh.first, lowhigh.second, lowbound, highbound);
169  }
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:190
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 176 of file MathUtils.h.

References CLOSED, and OPEN.

177  {
178  if (lowbound == OPEN && highbound == OPEN) {
179  return (value > low && value < high);
180  } else if (lowbound == OPEN && highbound == CLOSED) {
181  return (value > low && value <= high);
182  } else if (lowbound == CLOSED && highbound == OPEN) {
183  return (value >= low && value < high);
184  } else { // if (lowbound == CLOSED && highbound == CLOSED) {
185  return (value >= low && value <= high);
186  }
187  }
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 190 of file MathUtils.h.

References inRange().

191  {
192  return inRange(value, lowhigh.first, lowhigh.second, lowbound, highbound);
193  }
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:190
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 51 of file MathUtils.h.

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

51  {
52  return (fabs(val) < tolerance);
53  }
bool YODA::isZero ( long  val,
double   UNUSEDtolerance = 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 60 of file MathUtils.h.

60  {
61  return val == 0;
62  }
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 248 of file MathUtils.h.

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

248  {
249  assert(end >= start);
250  assert(nbins > 0);
251  std::vector<double> rtn;
252  const double interval = (end-start)/static_cast<double>(nbins);
253  double edge = start;
254  for (size_t i = 0; i < nbins; ++i) {
255  rtn.push_back(edge);
256  edge += interval;
257  }
258  assert(rtn.size() == nbins);
259  if (include_end) rtn.push_back(end); // exact end, not result of n * interval
260  return rtn;
261  }
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 269 of file MathUtils.h.

References linspace().

269  {
270  assert(end >= start);
271  assert(start > 0);
272  assert(nbins > 0);
273  const double logstart = std::log(start);
274  const double logend = std::log(end);
275  const std::vector<double> logvals = linspace(nbins, logstart, logend);
276  assert(logvals.size() == nbins+1);
277  std::vector<double> rtn; rtn.reserve(logvals.size());
278  rtn.push_back(start);
279  for (size_t i = 1; i < logvals.size()-1; ++i) {
280  rtn.push_back(std::exp(logvals[i]));
281  }
282  assert(rtn.size() == nbins);
283  if (include_end) rtn.push_back(end);
284  return rtn;
285  }
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:248
double YODA::mean ( const std::vector< int > &  sample)
inline

Calculate the mean of a sample.

Definition at line 312 of file MathUtils.h.

Referenced by covariance(), and YODA::Histo1D::xVariance().

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

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

Definition at line 16 of file Reader.cc.

Referenced by read().

16  {
17  const size_t lastdot = name.find_last_of(".");
18  const string fmt = boost::to_lower_copy((lastdot == string::npos) ? name : name.substr(lastdot+1));
19  // cout << "File extension: " << fmt << endl;
20  if (fmt == "yoda") return ReaderYODA::create();
21  if (fmt == "aida") return ReaderAIDA::create();
22  if (fmt == "dat" || fmt == "flat") return ReaderFLAT::create();
23  throw UserError("Format cannot be identified from string '" + name + "'");
24  }
Scatter1D YODA::mkScatter ( const Counter &  c)

Make a Scatter1D representation of a Histo1D.

Definition at line 8 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 divide(), toIntegralHisto(), toTGraph(), YODA::WriterAIDA::writeHisto1D(), YODA::WriterFLAT::writeHisto1D(), YODA::WriterFLAT::writeHisto2D(), YODA::WriterFLAT::writeProfile1D(), YODA::WriterAIDA::writeProfile1D(), and YODA::WriterFLAT::writeProfile2D().

8  {
9  Scatter1D rtn;
10  BOOST_FOREACH (const std::string& a, c.annotations())
11  rtn.setAnnotation(a, c.annotation(a));
12  rtn.setAnnotation("Type", c.type()); // might override the copied ones
13  rtn.addPoint(c.val(), c.err());
14  return rtn;
15  }
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 274 of file Scatter1D.h.

274  {
275  return Scatter1D(s);
276  }
Scatter2D YODA::mkScatter ( const Histo1D &  h,
bool  usefocus = false 
)

Make a Scatter2D representation of a Histo1D.

Definition at line 9 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Histo1D::bins(), YODA::HistoBin1D::height(), YODA::HistoBin1D::heightErr(), YODA::Histo1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::setAnnotation(), YODA::AnalysisObject::type(), YODA::Bin1D< DBN >::xFocus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMid(), and YODA::Bin1D< DBN >::xMin().

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

Make a Scatter2D representation of a Profile1D.

Definition at line 41 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), YODA::AnalysisObject::annotation(), YODA::AnalysisObject::annotations(), YODA::Profile1D::bins(), YODA::ProfileBin1D::mean(), YODA::Profile1D::numBins(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::setAnnotation(), YODA::ProfileBin1D::stdErr(), YODA::Profile1D::type(), YODA::Bin1D< DBN >::xFocus(), YODA::Bin1D< DBN >::xMax(), YODA::Bin1D< DBN >::xMid(), and YODA::Bin1D< DBN >::xMin().

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

309 { return Scatter2D(s); }
Scatter3D YODA::mkScatter ( const Histo2D &  h,
bool  usefocus = false 
)

Make a Scatter3D representation of a Histo2D.

Definition at line 30 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().

30  {
31  Scatter3D rtn;
32  BOOST_FOREACH (const std::string& a, h.annotations())
33  rtn.setAnnotation(a, h.annotation(a));
34  rtn.setAnnotation("Type", h.type());
35  for (size_t i = 0; i < h.numBins(); ++i) {
36  const HistoBin2D& b = h.bin(i);
37 
38  const double x = usefocus ? b.xFocus() : b.xMid();
39  const double exminus = x - b.xMin();
40  const double explus = b.xMax() - x;
41 
42  const double y = usefocus ? b.yFocus() : b.yMid();
43  const double eyminus = y - b.yMin();
44  const double eyplus = b.yMax() - y;
45 
46  const double z = b.height();
47  const double ez = b.heightErr();
48 
49  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
50  }
51 
52  return rtn;
53  }
Scatter3D YODA::mkScatter ( const Profile2D &  p,
bool  usefocus = false 
)

Make a Scatter3D representation of a Profile2D.

Definition at line 56 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::stdErr(), YODA::Profile2D::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().

56  {
57  Scatter3D rtn;
58  BOOST_FOREACH (const std::string& a, h.annotations())
59  rtn.setAnnotation(a, h.annotation(a));
60  rtn.setAnnotation("Type", h.type());
61  for (size_t i = 0; i < h.numBins(); ++i) {
62  const ProfileBin2D& b = h.bin(i);
63 
64  const double x = usefocus ? b.xFocus() : b.xMid();
65  const double exminus = x - b.xMin();
66  const double explus = b.xMax() - x;
67 
68  const double y = usefocus ? b.yFocus() : b.yMid();
69  const double eyminus = y - b.yMin();
70  const double eyplus = b.yMax() - y;
71 
72  double z;
73  try {
74  z = b.mean();
75  } catch (const LowStatsError& lse) {
76  z = 0.0;
77  }
78  double ez;
79  try {
80  ez = b.stdErr();
81  } catch (const LowStatsError& lse) {
82  ez = 0.0;
83  }
84 
85  rtn.addPoint(x, y, z, exminus, explus, eyminus, eyplus, ez, ez);
86  }
87 
88  return rtn;
89  }
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 321 of file Scatter3D.h.

321 { return Scatter3D(s); }
Writer & YODA::mkWriter ( const std::string &  format_name)

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

Definition at line 20 of file Writer.cc.

Referenced by write().

20  {
21  const size_t lastdot = name.find_last_of(".");
22  const string fmt = boost::to_lower_copy((lastdot == std::string::npos) ? name : name.substr(lastdot+1));
23  // cout << "File extension: " << fmt << endl;
24  if (fmt == "yoda") return WriterYODA::create();
25  if (fmt == "aida") return WriterAIDA::create();
26  if (fmt == "dat" || fmt == "flat") return WriterFLAT::create();
27  throw UserError("Format cannot be identified from string '" + name + "'");
28  }
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  }
template<int N>
bool YODA::operator!= ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Inequality test.

Definition at line 194 of file PointND.h.

194  {
195  return !(a == b);
196  }
bool YODA::operator!= ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Equality test of x characteristics only

Todo:
AAARGH! Need to also test y. Maybe need named cmp operators for separate x/y and with/without metadata

Definition at line 230 of file Point1D.h.

230  {
231  return !(a == b);
232  }
bool YODA::operator!= ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Equality test of x characteristics only.

Definition at line 386 of file Point2D.h.

386  {
387  return !(a == b);
388  }
bool YODA::operator!= ( const Point3D &  a,
const YODA::Point3D b 
)
inline

Inequality operator.

Definition at line 444 of file Point3D.h.

444  {
445  return !(a == b);
446  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
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  }
Counter YODA::operator+ ( const Counter &  first,
const Counter &  second 
)
inline

Add two counters.

Definition at line 213 of file Counter.h.

References add().

213  {
214  return add(first, second);
215  }
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:205
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  }
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  }
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  }
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 320 of file Bin1D.h.

320  {
321  Bin1D<DBN> rtn = a;
322  rtn += b;
323  return rtn;
324  }
Profile1D YODA::operator+ ( const Profile1D &  first,
const Profile1D &  second 
)
inline

Add two profile histograms.

Definition at line 321 of file Profile1D.h.

References add().

321  {
322  return add(first, second);
323  }
Profile1D add(const Profile1D &first, const Profile1D &second)
Add two profile histograms.
Definition: Profile1D.h:312
Scatter2D YODA::operator+ ( const Scatter2D &  first,
const Scatter2D &  second 
)
inline

Add two scatters.

Definition at line 328 of file Scatter2D.h.

References add().

328  {
329  return add(first, second);
330  }
Scatter2D add(const Scatter2D &first, const Scatter2D &second)
Add two scatters.
Definition: Scatter2D.cc:81
Scatter3D YODA::operator+ ( const Scatter3D &  first,
const Scatter3D &  second 
)
inline

Add two scatters.

Definition at line 340 of file Scatter3D.h.

References add().

340  {
341  return add(first, second);
342  }
Scatter3D add(const Scatter3D &first, const Scatter3D &second)
Add two scatters.
Definition: Scatter3D.cc:10
Histo1D YODA::operator+ ( const Histo1D &  first,
const Histo1D &  second 
)
inline

Add two histograms.

Definition at line 384 of file Histo1D.h.

References add().

384  {
385  return add(first, second);
386  }
Histo1D add(const Histo1D &first, const Histo1D &second)
Add two histograms.
Definition: Histo1D.h:375
Profile2D YODA::operator+ ( const Profile2D &  first,
const Profile2D &  second 
)
inline

Add two profile histograms.

Definition at line 402 of file Profile2D.h.

References add().

402  {
403  return add(first,second);
404  }
Profile2D add(const Profile2D &first, const Profile2D &second)
Add two profile histograms.
Definition: Profile2D.h:394
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  }
Histo2D YODA::operator+ ( const Histo2D &  first,
const Histo2D &  second 
)
inline

Add two histograms.

Definition at line 441 of file Histo2D.h.

References add().

441  {
442  return add(first, second);
443  }
Histo2D add(const Histo2D &first, const Histo2D &second)
Add two histograms.
Definition: Histo2D.h:432
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 484 of file Bin2D.h.

484  {
485  Bin2D<DBN> rtn = a;
486  rtn += b;
487  return rtn;
488  }
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 486 of file Axis1D.h.

486  {
487  Axis1D<BIN1D,DBN> tmp = first;
488  tmp += second;
489  return tmp;
490  }
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  }
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  }
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  }
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  }
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  }
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  }
Counter YODA::operator- ( const Counter &  first,
const Counter &  second 
)
inline

Subtract two counters.

Definition at line 227 of file Counter.h.

References subtract().

227  {
228  return subtract(first, second);
229  }
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:219
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  }
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  }
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 332 of file Bin1D.h.

332  {
333  Bin1D<DBN> rtn = a;
334  rtn -= b;
335  return rtn;
336  }
Profile1D YODA::operator- ( const Profile1D &  first,
const Profile1D &  second 
)
inline

Subtract two profile histograms.

Definition at line 336 of file Profile1D.h.

References subtract().

336  {
337  return subtract(first, second);
338  }
Profile1D subtract(const Profile1D &first, const Profile1D &second)
Subtract two profile histograms.
Definition: Profile1D.h:327
Scatter2D YODA::operator- ( const Scatter2D &  first,
const Scatter2D &  second 
)
inline

Subtract two scatters.

Definition at line 338 of file Scatter2D.h.

References subtract().

338  {
339  return subtract(first, second);
340  }
Scatter2D subtract(const Scatter2D &first, const Scatter2D &second)
Subtract two scatters.
Definition: Scatter2D.cc:105
Scatter3D YODA::operator- ( const Scatter3D &  first,
const Scatter3D &  second 
)
inline

Subtract two scatters.

Definition at line 350 of file Scatter3D.h.

References subtract().

350  {
351  return subtract(first, second);
352  }
Scatter3D subtract(const Scatter3D &first, const Scatter3D &second)
Subtract two scatters.
Definition: Scatter3D.cc:19
Histo1D YODA::operator- ( const Histo1D &  first,
const Histo1D &  second 
)
inline

Subtract two histograms.

Definition at line 399 of file Histo1D.h.

References subtract().

399  {
400  return subtract(first, second);
401  }
Histo1D subtract(const Histo1D &first, const Histo1D &second)
Subtract two histograms.
Definition: Histo1D.h:390
Profile2D YODA::operator- ( const Profile2D &  first,
const Profile2D &  second 
)
inline

Subtract two profile histograms.

Definition at line 415 of file Profile2D.h.

References subtract().

415  {
416  return subtract(first,second);
417  }
Profile2D subtract(const Profile2D &first, const Profile2D &second)
Subtract two profile histograms.
Definition: Profile2D.h:407
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  }
Histo2D YODA::operator- ( const Histo2D &  first,
const Histo2D &  second 
)
inline

Subtract two histograms.

Definition at line 456 of file Histo2D.h.

References subtract().

456  {
457  return subtract(first, second);
458  }
Histo2D subtract(const Histo2D &first, const Histo2D &second)
Subtract two histograms.
Definition: Histo2D.h:447
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 494 of file Axis1D.h.

494  {
495  Axis1D<BIN1D,DBN> tmp = first;
496  tmp -= second;
497  return tmp;
498  }
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 496 of file Bin2D.h.

496  {
497  Bin2D<DBN> rtn = a;
498  rtn -= b;
499  return rtn;
500  }
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 239 of file Counter.h.

References divide().

239  {
240  return divide(numer, denom);
241  }
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
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  }
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  }
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  }
Scatter2D YODA::operator/ ( const Profile1D &  numer,
const Profile1D &  denom 
)
inline

Divide two profile histograms.

Definition at line 346 of file Profile1D.h.

References divide().

346  {
347  return divide(numer, denom);
348  }
Scatter2D divide(const Profile1D &numer, const Profile1D &denom)
Divide two profile histograms.
Definition: Profile1D.cc:106
Scatter2D YODA::operator/ ( const Scatter2D &  numer,
const Scatter2D &  denom 
)
inline

Divide two scatters.

Definition at line 348 of file Scatter2D.h.

References divide().

348  {
349  return divide(numer, denom);
350  }
Scatter2D divide(const Scatter2D &numer, const Scatter2D &denom)
Divide two scatters.
Definition: Scatter2D.cc:130
Scatter3D YODA::operator/ ( const Scatter3D &  numer,
const Scatter3D &  denom 
)
inline

Divide two scatters.

Definition at line 360 of file Scatter3D.h.

References divide().

360  {
361  return divide(numer, denom);
362  }
Scatter3D divide(const Scatter3D &numer, const Scatter3D &denom)
Divide two scatters.
Definition: Scatter3D.cc:93
Scatter2D YODA::operator/ ( const Histo1D &  numer,
const Histo1D &  denom 
)
inline

Divide two histograms, with an uncorrelated error treatment.

Definition at line 412 of file Histo1D.h.

References divide().

412  {
413  return divide(numer, denom);
414  }
Scatter2D divide(const Histo1D &numer, const Histo1D &denom)
Divide two histograms, with an uncorrelated error treatment.
Definition: Histo1D.cc:143
Scatter3D YODA::operator/ ( const Profile2D &  numer,
const Profile2D &  denom 
)
inline

Divide two profile histograms.

Definition at line 423 of file Profile2D.h.

References divide().

423  {
424  return divide(numer, denom);
425  }
Scatter3D divide(const Profile2D &numer, const Profile2D &denom)
Divide two profile histograms.
Definition: Profile2D.cc:174
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 473 of file Histo2D.h.

References divide().

473  {
474  return divide(numer, denom);
475  }
Scatter3D divide(const Histo2D &numer, const Histo2D &denom)
Divide two histograms, with an uncorrelated error treatment.
Definition: Histo2D.cc:298
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)
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 201 of file PointND.h.

References LT_IF_NOT_EQ.

201  {
202  #define LT_IF_NOT_EQ(a,b) { if (!fuzzyEquals(a, b)) return a < b; }
203  for (size_t i = 0; i < N; ++i) LT_IF_NOT_EQ(a.pos()[i], b.pos()[i]);
204  if (a.errs().size() != b.errs().size()) return a.errs().size() < b.errs().size();
205  for (size_t i = 0; i < a.errs().size(); ++i) {
206  if (a.errs()[i] != b.errs()[i]) return a.errs()[i] < b.errs()[i];
207  }
208  #undef LT_IF_NOT_EQ
209  return false;
210  }
#define LT_IF_NOT_EQ(a, b)
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 235 of file Point1D.h.

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

235  {
236  if (!YODA::fuzzyEquals(a.x(), b.x())) {
237  return a.x() < b.x();
238  }
239  if (!YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
240  return a.xErrMinus() < b.xErrMinus();
241  }
242  if (!YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
243  return a.xErrPlus() < b.xErrPlus();
244  }
245  return false;
246  }
double xErrMinus() const
Get negative x-error value.
Definition: Point1D.h:93
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:68
double xErrPlus() const
Get positive x-error value.
Definition: Point1D.h:98
double x() const
Get x value.
Definition: Point1D.h:74
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 341 of file Bin1D.h.

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

341  {
342  return b.xEdges().first > a.xEdges().first;
343  }
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 391 of file Point2D.h.

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

391  {
392  if (!YODA::fuzzyEquals(a.x(), b.x())) {
393  return a.x() < b.x();
394  }
395  if (!YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
396  return a.xErrMinus() < b.xErrMinus();
397  }
398  if (!YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
399  return a.xErrPlus() < b.xErrPlus();
400  }
401  return false;
402  }
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:68
double xErrPlus() const
Get positive x-error value.
Definition: Point2D.h:138
double x() const
Get x value.
Definition: Point2D.h:99
double xErrMinus() const
Get negative x-error value.
Definition: Point2D.h:133
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 449 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().

449  {
450  if (! fuzzyEquals(a.x(), b.x())) {
451  return a.x() < b.x();
452  }
453  if (!fuzzyEquals(a.y(), b.y())) {
454  return a.y() < b.y();
455  }
456  if (! fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
457  return a.xErrMinus() < b.xErrMinus();
458  }
459  if (!fuzzyEquals(a.yErrMinus(), b.yErrMinus())) {
460  return a.yErrMinus() < b.yErrMinus();
461  }
462  if (! fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
463  return a.xErrPlus() < b.xErrPlus();
464  }
465  if (!fuzzyEquals(a.yErrPlus(), b.yErrPlus())) {
466  return a.yErrPlus() < b.yErrPlus();
467  }
468  return false;
469  }
double xErrPlus() const
Get positive x-error value.
Definition: Point3D.h:138
double x() const
Get x value.
Definition: Point3D.h:93
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:68
double yErrPlus() const
Get positive y-error value.
Definition: Point3D.h:201
double y() const
Get y value.
Definition: Point3D.h:99
double xErrMinus() const
Get negative x-error value.
Definition: Point3D.h:133
double yErrMinus() const
Get negative y-error value.
Definition: Point3D.h:196
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 505 of file Bin2D.h.

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

505  {
506  if (!fuzzyEquals(a.xMin(), b.xMin())) return b.xMin() > a.xMin();
507  return b.yMin() > a.yMin();
508  }
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:68
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  }
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  }
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 214 of file PointND.h.

214  {
215  if (a == b) return true;
216  return a < b;
217  }
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 249 of file Point1D.h.

249  {
250  if (a == b) return true;
251  return a < b;
252  }
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 405 of file Point2D.h.

405  {
406  if (a == b) return true;
407  return a < b;
408  }
bool YODA::operator<= ( const Point3D &  a,
const YODA::Point3D b 
)
inline

Less-than-or-equals operator.

Definition at line 472 of file Point3D.h.

472  {
473  if (a == b) return true;
474  return a < b;
475  }
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:68
template<int N>
bool YODA::operator== ( const Point< N > &  a,
const Point< N > &  b 
)
inline

Equality test.

Definition at line 179 of file PointND.h.

References YODA::Point< N >::errs(), fuzzyEquals(), and YODA::Point< N >::pos().

179  {
180  // Compare positions
181  for (size_t i = 0; i < N; ++i) {
182  if ( !fuzzyEquals(a.pos()[i], b.pos()[i]) ) return false;
183  }
184  // Compare number of errors and then (sorted) error equality
185  if (a.errs().size() != b.errs().size()) return false;
186  for (size_t i = 0; i < a.errs().size(); ++i) {
187  if (a.errs()[i] != b.errs()[i]) return false;
188  }
189  return true;
190  }
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:68
bool YODA::operator== ( const YODA::Point1D a,
const YODA::Point1D b 
)
inline

Equality test of x characteristics only

Todo:
AAARGH! Need to also test y. Maybe need named cmp operators for separate x/y and with/without metadata

Definition at line 221 of file Point1D.h.

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

221  {
222  const bool same_val = YODA::fuzzyEquals(a.x(), b.x());
223  const bool same_eminus = YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus());
224  const bool same_eplus = YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus());
225  return same_val && same_eminus && same_eplus;
226  }
double xErrMinus() const
Get negative x-error value.
Definition: Point1D.h:93
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:68
double xErrPlus() const
Get positive x-error value.
Definition: Point1D.h:98
double x() const
Get x value.
Definition: Point1D.h:74
bool YODA::operator== ( const YODA::Point2D a,
const YODA::Point2D b 
)
inline

Equality test of x characteristics only.

Definition at line 378 of file Point2D.h.

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

378  {
379  const bool same_val = YODA::fuzzyEquals(a.x(), b.x());
380  const bool same_eminus = YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus());
381  const bool same_eplus = YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus());
382  return same_val && same_eminus && same_eplus;
383  }
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:68
double xErrPlus() const
Get positive x-error value.
Definition: Point2D.h:138
double x() const
Get x value.
Definition: Point2D.h:99
double xErrMinus() const
Get negative x-error value.
Definition: Point2D.h:133
bool YODA::operator== ( const Point3D &  a,
const YODA::Point3D b 
)
inline

Equality operator.

Definition at line 434 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().

434  {
435  const bool same_val = fuzzyEquals(a.x(), b.x()) && fuzzyEquals(a.y(), b.y());
436  const bool same_eminus = fuzzyEquals(a.xErrMinus(), b.xErrMinus()) &&
437  fuzzyEquals(a.yErrMinus(), b.yErrMinus());
438  const bool same_eplus = fuzzyEquals(a.xErrPlus(), b.xErrPlus()) &&
439  fuzzyEquals(a.yErrPlus(), b.yErrPlus());
440  return same_val && same_eminus && same_eplus;
441  }
double xErrPlus() const
Get positive x-error value.
Definition: Point3D.h:138
double x() const
Get x value.
Definition: Point3D.h:93
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:68
double yErrPlus() const
Get positive y-error value.
Definition: Point3D.h:201
double y() const
Get y value.
Definition: Point3D.h:99
double xErrMinus() const
Get negative x-error value.
Definition: Point3D.h:133
double yErrMinus() const
Get negative y-error value.
Definition: Point3D.h:196
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  }
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 221 of file PointND.h.

221  {
222  return !(a <= b);
223  }
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 255 of file Point1D.h.

255  {
256  return !(a <= b);
257  }
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 411 of file Point2D.h.

411  {
412  return !(a <= b);
413  }
bool YODA::operator> ( const Point3D &  a,
const YODA::Point3D b 
)
inline

Greater-than operator.

Definition at line 478 of file Point3D.h.

478  {
479  return !(a <= b);
480  }
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  }
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 227 of file PointND.h.

227  {
228  return !(a < b);
229  }
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 260 of file Point1D.h.

260  {
261  return !(a < b);
262  }
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 416 of file Point2D.h.

416  {
417  return !(a < b);
418  }
bool YODA::operator>= ( const Point3D &  a,
const YODA::Point3D b 
)
inline

Greater-than-or-equals operator.

Definition at line 483 of file Point3D.h.

483  {
484  return !(a < b);
485  }
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 52 of file IO.h.

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

Referenced by read().

52  {
53  Reader& r = mkReader(filename);
54  r.read(filename, aos);
55  }
Reader & mkReader(const std::string &format_name)
Factory function to make a writer object by format name or a filename.
Definition: Reader.cc:16
std::vector<AnalysisObject*> YODA::read ( const std::string &  filename)

Read in a collection of objects from output stream stream.

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 63 of file IO.h.

References read().

63  {
64  std::vector<AnalysisObject*> rtn;
65  read(filename, rtn);
66  return rtn;
67  }
std::vector< AnalysisObject * > read(const std::string &filename)
Read in a collection of objects from output stream stream.
Definition: IO.h:63
int YODA::sign ( double  val)
inline

Find the sign of a number.

Definition at line 220 of file MathUtils.h.

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

220  {
221  if (isZero(val)) return ZERO;
222  const int valsign = (val > 0) ? PLUS : MINUS;
223  return valsign;
224  }
bool isZero(long val, double UNUSED(tolerance)=1E-8)
Definition: MathUtils.h:60
int YODA::sign ( int  val)
inline

Find the sign of a number.

Definition at line 227 of file MathUtils.h.

References MINUS, PLUS, and ZERO.

227  {
228  if (val == 0) return ZERO;
229  return (val > 0) ? PLUS : MINUS;
230  }
int YODA::sign ( long  val)
inline

Find the sign of a number.

Definition at line 233 of file MathUtils.h.

References MINUS, PLUS, and ZERO.

233  {
234  if (val == 0) return ZERO;
235  return (val > 0) ? PLUS : MINUS;
236  }
template<typename NUM >
NUM YODA::sqr ( NUM  a)
inline

Named number-type squaring operation.

Definition at line 203 of file MathUtils.h.

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

203  {
204  return a*a;
205  }
Counter YODA::subtract ( const Counter &  first,
const Counter &  second 
)
inline

Subtract two counters.

Definition at line 219 of file Counter.h.

Referenced by operator-().

219  {
220  Counter tmp = first;
221  tmp -= second;
222  return tmp;
223  }
Profile1D YODA::subtract ( const Profile1D &  first,
const Profile1D &  second 
)
inline

Subtract two profile histograms.

Definition at line 327 of file Profile1D.h.

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

327  {
328  Profile1D tmp = first;
329  if (first.path() != second.path()) tmp.setPath("");
330  tmp -= second;
331  return tmp;
332  }
Scatter2D YODA::subtract ( const Scatter2D &  first,
const Scatter2D &  second 
)

Subtract two scatters.

Todo:
Does this even make sense?
Todo:
Deal with +/- errors separately?
Todo:
Deal with +/- errors separately?

Definition at line 105 of file Scatter2D.cc.

References YODA::Scatter2D::addPoint(), fuzzyEquals(), YODA::Scatter2D::numPoints(), YODA::AnalysisObject::path(), YODA::Scatter2D::point(), sqr(), YODA::Point2D::xMax(), YODA::Point2D::xMin(), YODA::Point2D::y(), and YODA::Point2D::yErrAvg().

105  {
106  Scatter2D tmp;
107  for (size_t i = 0; i < first.numPoints(); ++i) {
108  const Point2D& p1 = first.point(i);
109  const Point2D& p2 = second.point(i);
110  if (!fuzzyEquals(p1.xMin(), p2.xMin()) || !fuzzyEquals(p1.xMax(), p2.xMax()))
111  throw BinningError("Point x binnings are not equivalent in " + first.path() + " - " + second.path());
112  // Use the midpoint of the "bin" for the new central x value, in the absence of better information
113  const double x = (p1.xMin() + p1.xMax()) / 2.0;
114  const double exminus = x - p1.xMin();
115  const double explus = p1.xMax() - x;
116  //
117  const double y = p1.y() - p2.y();
119  const double ey = sqrt( sqr(p1.yErrAvg()) + sqr(p2.yErrAvg()) );
120  tmp.addPoint(x, y, exminus, explus, ey, ey);
121  }
122  assert(tmp.numPoints() == first.numPoints());
123  return tmp;
124  }
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:68
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
Scatter3D YODA::subtract ( const Scatter3D &  first,
const Scatter3D &  second 
)

Subtract two scatters.

Todo:
Implement
Todo:
Implement

Definition at line 19 of file Scatter3D.cc.

19  {
21  throw Exception("Implement me!");
22  Scatter3D tmp;
23  return tmp;
24  }
Histo1D YODA::subtract ( const Histo1D &  first,
const Histo1D &  second 
)
inline

Subtract two histograms.

Definition at line 390 of file Histo1D.h.

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

390  {
391  Histo1D tmp = first;
392  if (first.path() != second.path()) tmp.setPath("");
393  tmp -= second;
394  return tmp;
395  }
Profile2D YODA::subtract ( const Profile2D &  first,
const Profile2D &  second 
)
inline

Subtract two profile histograms.

Definition at line 407 of file Profile2D.h.

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

407  {
408  Profile2D tmp = first;
409  if (first.path() != second.path()) tmp.setPath("");
410  tmp -= second;
411  return tmp;
412  }
Histo2D YODA::subtract ( const Histo2D &  first,
const Histo2D &  second 
)
inline

Subtract two histograms.

Definition at line 447 of file Histo2D.h.

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

447  {
448  Histo2D tmp = first;
449  if (first.path() != second.path()) tmp.setPath("");
450  tmp -= second;
451  return tmp;
452  }
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:
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.?
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 199 of file Histo1D.cc.

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

199  {
200  Scatter2D rtn = toIntegralHisto(h, includeunderflow);
201  const double integral = h.integral() - (includeoverflow ? 0 : h.overflow().sumW());
203  const double integral_err = sqrt(integral);
204 
205  // If the integral is empty, the (integrated) efficiency values may as well all be zero, so return here
209  if (integral == 0) return rtn;
210 
211  // Normalize and compute binomial errors
212  BOOST_FOREACH (Point2D& p, rtn.points()) {
213  const double eff = p.y() / integral;
215  const double ey = sqrt(abs( ((1-2*eff)*sqr(p.y()/p.yErrAvg()) + sqr(eff)*sqr(integral_err)) / sqr(integral) ));
216  p.setY(eff, ey);
217  }
218 
219  return rtn;
220  }
Scatter2D toIntegralHisto(const Histo1D &h, bool includeunderflow=true)
Convert a Histo1D to a Scatter2D representing the integral of the histogram.
Definition: Histo1D.cc:185
NUM sqr(NUM a)
Named number-type squaring operation.
Definition: MathUtils.h:203
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:
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 185 of file Histo1D.cc.

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

Referenced by toIntegralEfficiencyHisto().

185  {
187  Scatter2D tmp = mkScatter(h);
188  double integral = includeunderflow ? h.underflow().sumW() : 0.0;
189  for (size_t i = 0; i < h.numBins(); ++i) {
190  Point2D& point = tmp.point(i);
191  integral += h.bin(i).sumW();
192  const double err = sqrt(integral); //< @todo Should be sqrt(sumW2)? Or more complex, cf. Simon etc.?
193  point.setY(integral, err);
194  }
195  return tmp;
196  }
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
Scatter2D YODA::toScatter2D ( const TH1 &  th1)
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 (including TProfile) to a YODA Scatter2D

Todo:
Add a bool flag for whether or not to divide y vals/errs by bin width.

Definition at line 74 of file ROOTCnv.h.

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

Referenced by toScatter2D().

74  {
75  Scatter2D rtn;
76  for (int i = 1; i <= th1.GetNbinsX(); ++i) {
77  const double x = th1.GetBinCenter(i);
78  const double exminus = x - th1.GetBinLowEdge(i);
79  const double explus = th1.GetBinLowEdge(i+1) - x;
80  const double width = exminus + explus;
81  rtn.addPoint(x, th1.GetBinContent(i)/width,
82  exminus, explus,
83  th1.GetBinErrorLow(i)/width, th1.GetBinErrorUp(i)/width);
84  }
85  rtn.addAnnotation("XLabel", th1.GetXaxis()->GetTitle());
86  rtn.addAnnotation("YLabel", th1.GetYaxis()->GetTitle());
87  return rtn;
88  }
Scatter2D YODA::toScatter2D ( const TH1 *  th1)
inline

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

Definition at line 92 of file ROOTCnv.h.

References toScatter2D().

92  {
93  return toScatter2D(*th1);
94  }
Scatter2D toScatter2D(const TH1 *th1)
Convert a ROOT 1D histogram (including TProfile) to a YODA Scatter2D.
Definition: ROOTCnv.h:92
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 289 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 toTGraph().

289  {
290  TVectorF xs(s.numPoints()), ys(s.numPoints());
291  TVectorF exls(s.numPoints()), exhs(s.numPoints());
292  TVectorF eyls(s.numPoints()), eyhs(s.numPoints());
293  for (size_t i = 0; i < s.numPoints(); ++i) {
294  const Point2D& p = s.point(i);
295  xs[i] = p.x();
296  ys[i] = p.y();
297  exls[i] = p.xErrMinus();
298  exhs[i] = p.xErrPlus();
299  eyls[i] = p.yErrMinus();
300  eyhs[i] = p.yErrPlus();
301  }
302  // Make the ROOT object... mm, the constructors don't take name+title, unlike all this histos!
303  TGraphAsymmErrors rtn(xs, ys, exls, exhs, eyls, eyhs);
304  rtn.SetName(s.path().c_str());
305  rtn.SetTitle(s.title().c_str());
306  // Labels
307  if (s.hasAnnotation("XLabel")) rtn.GetXaxis()->SetTitle(s.annotation("XLabel").c_str());
308  if (s.hasAnnotation("YLabel")) rtn.GetYaxis()->SetTitle(s.annotation("YLabel").c_str());
309  return rtn;
310  }
TGraphAsymmErrors YODA::toTGraph ( const Histo1D &  h)
inline

Convert a YODA Histo1D to a ROOT TGraphAsymmErrors.

Definition at line 315 of file ROOTCnv.h.

References mkScatter(), and toTGraph().

315  {
316  return toTGraph(mkScatter(h));
317  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:322
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
TGraphAsymmErrors YODA::toTGraph ( const Profile1D &  p)
inline

Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.

Definition at line 322 of file ROOTCnv.h.

References mkScatter(), and toTGraph().

322  {
323  return toTGraph(mkScatter(p));
324  }
TGraphAsymmErrors toTGraph(const Profile1D &p)
Convert a YODA Profile1D to a ROOT TGraphAsymmErrors.
Definition: ROOTCnv.h:322
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
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 110 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().

110  {
111  // Work out bin edges first
112  std::vector<double> edges;
113  edges.reserve(h.numBins()+1);
114  edges.push_back(h.bin(0).xMin());
115  for (size_t i = 0; i < h.numBins(); ++i) {
116  const HistoBin1D& b = h.bin(i);
117  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
118  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
119  }
120  // Book ROOT histogram
121  TH1D rtn(h.path().c_str(), h.title().c_str(), edges.size()-1, &edges[0]);
122  rtn.Sumw2();
123  TArrayD& sumw2s = *rtn.GetSumw2();
124  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
125  try {
126  const HistoBin1D& b = h.binAt(rtn.GetBinCenter(i)); // throws if in a gap
127  rtn.SetBinContent(i, b.sumW());
128  sumw2s[i] = b.sumW2();
129  } catch (const Exception& e) { }
130  }
131  // Overflows
132  rtn.SetBinContent(0, h.underflow().sumW());
133  rtn.SetBinContent(rtn.GetNbinsX()+1, h.overflow().sumW());
134  sumw2s[0] = h.underflow().sumW2();
135  sumw2s[rtn.GetNbinsX()+1] = h.overflow().sumW2();
136  // Labels
137  if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel").c_str());
138  if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel").c_str());
139  return rtn;
140  }
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:68
TH1D YODA::toTH1D ( const Profile1D &  p)
inline

Convert a YODA Profile1D to a ROOT TH1D.

Definition at line 249 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().

249  {
250  // Work out bin edges first
251  std::vector<double> edges;
252  edges.reserve(p.numBins()+1);
253  edges.push_back(p.bin(0).xMin());
254  for (size_t i = 0; i < p.numBins(); ++i) {
255  const ProfileBin1D& b = p.bin(i);
256  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
257  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
258  }
259  // Book ROOT histogram
260  TH1D rtn(p.path().c_str(), p.title().c_str(), edges.size()-1, &edges[0]);
261  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
262  try {
263  const ProfileBin1D& b = p.binAt(rtn.GetBinCenter(i)); // throws if in a gap
264  rtn.SetBinContent(i, b.mean());
265  rtn.SetBinError(i, b.stdErr());
266  } catch (const Exception& e) { }
267  }
268  // Overflows
269  rtn.SetBinContent(0, p.underflow().yMean());
270  rtn.SetBinContent(rtn.GetNbinsX()+1, p.overflow().yMean());
271  rtn.SetBinError(0, p.underflow().yStdErr());
272  rtn.SetBinError(rtn.GetNbinsX()+1, p.overflow().yStdErr());
273  // Labels
274  if (p.hasAnnotation("XLabel")) rtn.SetXTitle(p.annotation("XLabel").c_str());
275  if (p.hasAnnotation("YLabel")) rtn.SetYTitle(p.annotation("YLabel").c_str());
276  return rtn;
277  }
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:68
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 147 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().

147  {
148  // Work out bin edges first
149  std::vector<double> xedges, yedges;
150  xedges.reserve(h.numBins()+1);
151  yedges.reserve(h.numBins()+1);
152  xedges.push_back(h.bin(0).xMin());
153  yedges.push_back(h.bin(0).yMin());
154  for (size_t i = 0; i < h.numBins(); ++i) {
155  const HistoBin2D& b = h.bin(i);
156  xedges.push_back(b.xMin());
157  xedges.push_back(b.xMax());
158  yedges.push_back(b.yMin());
159  yedges.push_back(b.yMax());
160  }
161  // Sort and remove (fuzzy) duplicate edges
162  std::sort(xedges.begin(), xedges.end());
163  std::sort(yedges.begin(), yedges.end());
164  const std::vector<double>::iterator xlast = std::unique(xedges.begin(), xedges.end());
165  const std::vector<double>::iterator ylast = std::unique(yedges.begin(), yedges.end());
166  xedges.erase(xlast, xedges.end());
167  yedges.erase(ylast, yedges.end());
168 
169  // Book ROOT histogram
170  TH2D rtn(h.path().c_str(), h.title().c_str(), xedges.size()-1, &xedges[0], yedges.size()-1, &yedges[0]);
171  rtn.Sumw2();
172  TArrayD& sumw2s = *rtn.GetSumw2();
173  for (int ix = 1; ix <= rtn.GetNbinsX(); ++ix) {
174  for (int iy = 1; iy <= rtn.GetNbinsY(); ++iy) {
175  const int i = rtn.GetBin(ix, iy);
176  try {
177  const HistoBin2D& b = h.binAt(rtn.GetBinCenter(ix), rtn.GetBinCenter(iy)); // throws if in a gap
178  rtn.SetBinContent(i, b.sumW());
179  sumw2s[i] = b.sumW2();
180  } catch (const Exception& e) { }
181  }
182  }
183  // Overflows
185  // rtn.SetBinContent(0, h.underflow().sumW());
186  // rtn.SetBinContent(rtn.GetNbinsX()+1, h.overflow().sumW());
187  // sumw2s[0] = h.underflow().sumW2();
188  // sumw2s[rtn.GetNbinsX()+1] = h.overflow().sumW2();
189  // Labels
190  if (h.hasAnnotation("XLabel")) rtn.SetXTitle(h.annotation("XLabel").c_str());
191  if (h.hasAnnotation("YLabel")) rtn.SetYTitle(h.annotation("YLabel").c_str());
192  if (h.hasAnnotation("ZLabel")) rtn.SetZTitle(h.annotation("ZLabel").c_str());
193  return rtn;
194  }
TProfile YODA::toTProfile ( const Profile1D &  p)
inline

Convert a YODA Scatter2D to a ROOT TH1D.

Convert a YODA Profile1D to a ROOT TProfile

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 204 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().

204  {
205  // Work out bin edges first
206  std::vector<double> edges;
207  edges.reserve(p.numBins()+1);
208  edges.push_back(p.bin(0).xMin());
209  for (size_t i = 0; i < p.numBins(); ++i) {
210  const ProfileBin1D& b = p.bin(i);
211  if (!fuzzyEquals(edges.back(), b.xMin())) edges.push_back(b.xMin());
212  if (!fuzzyEquals(edges.back(), b.xMax())) edges.push_back(b.xMax());
213  }
214  // Book ROOT histogram
215  TProfile rtn(p.path().c_str(), p.title().c_str(), edges.size()-1, &edges[0]);
216  rtn.Sumw2();
217  Double_t* sumwys = rtn.GetArray(); //< YUCK!!!
218  TArrayD& sumwy2s = *rtn.GetSumw2(); //< YUCK!!!
219  for (int i = 1; i <= rtn.GetNbinsX(); ++i) {
220  try {
221  const ProfileBin1D& b = p.binAt(rtn.GetBinCenter(i)); // throws if in a gap
222  // rtn.SetBinContent(i, b.mean());
223  // rtn.SetBinError(i, b.stdErr());
225  // - for sum(y*y): TProfile::GetSumw2()
226  // - for sum(y): TProfile::GetArray()
227  // - for sum(w): TProfile::SetBinEntries(bin, w)
228  // Clearly, the names of accessors/methods are confusing...
229  rtn.SetBinEntries(i, b.sumW());
230  sumwys[i] = b.sumWY();
231  sumwy2s[i] = b.sumWY2();
232  } catch (const Exception& e) { }
233  }
234  // Overflows
235  rtn.SetBinEntries(0, p.underflow().sumW());
236  rtn.SetBinEntries(rtn.GetNbinsX()+1, p.overflow().sumW());
237  sumwys[0] = p.underflow().sumWY();
238  sumwys[0] = p.underflow().sumWY();
239  sumwy2s[rtn.GetNbinsX()+1] = p.overflow().sumWY2();
240  sumwy2s[rtn.GetNbinsX()+1] = p.overflow().sumWY2();
241  // Labels
242  if (p.hasAnnotation("XLabel")) rtn.SetXTitle(p.annotation("XLabel").c_str());
243  if (p.hasAnnotation("YLabel")) rtn.SetYTitle(p.annotation("YLabel").c_str());
244  return rtn;
245  }
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:68
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 327 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().

327  {
328  for (size_t i = 0; i < s.numPoints(); ++i) {
329  Point1D& p = s.point(i);
330  const double newx = fx(p.x());
331  const double fx_xmin = fx(p.xMin());
332  const double fx_xmax = fx(p.xMax());
333  // Deal with possible inversions of min/max ordering under the transformation
334  const double newxmin = std::min(fx_xmin, fx_xmax);
335  const double newxmax = std::max(fx_xmin, fx_xmax);
336  // Set new point x values
337  p.setX(newx);
339  p.setXErrMinus(newx - newxmin);
340  p.setXErrPlus(newxmax - newx);
341  }
342  }
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 362 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().

362  {
363  for (size_t i = 0; i < s.numPoints(); ++i) {
364  Point2D& p = s.point(i);
365  const double newx = fx(p.x());
366  const double fx_xmin = fx(p.xMin());
367  const double fx_xmax = fx(p.xMax());
368  // Deal with possible inversions of min/max ordering under the transformation
369  const double newxmin = std::min(fx_xmin, fx_xmax);
370  const double newxmax = std::max(fx_xmin, fx_xmax);
371  // Set new point x values
372  p.setX(newx);
374  p.setXErrMinus(newx - newxmin);
375  p.setXErrPlus(newxmax - newx);
376  }
377  }
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 374 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().

374  {
375  for (size_t i = 0; i < s.numPoints(); ++i) {
376  Point3D& p = s.point(i);
377  const double newx = fx(p.x());
378  const double fx_xmin = fx(p.xMin());
379  const double fx_xmax = fx(p.xMax());
380  // Deal with possible inversions of min/max ordering under the transformation
381  const double newxmin = std::min(fx_xmin, fx_xmax);
382  const double newxmax = std::max(fx_xmin, fx_xmax);
383  // Set new point x values
384  p.setX(newx);
386  p.setXErrMinus(newx - newxmin);
387  p.setXErrPlus(newxmax - newx);
388  }
389  }
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 384 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().

384  {
385  for (size_t i = 0; i < s.numPoints(); ++i) {
386  Point2D& p = s.point(i);
387  const double newy = fy(p.y());
388  const double fy_ymin = fy(p.yMin());
389  const double fy_ymax = fy(p.yMax());
390  // Deal with possible inversions of min/max ordering under the transformation
391  const double newymin = std::min(fy_ymin, fy_ymax);
392  const double newymax = std::max(fy_ymin, fy_ymax);
393  // Set new point y values
394  p.setY(newy);
396  p.setYErrMinus(newy - newymin);
397  p.setYErrPlus(newymax - newy);
398  }
399  }
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 396 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().

396  {
397  for (size_t i = 0; i < s.numPoints(); ++i) {
398  Point3D& p = s.point(i);
399  const double newy = fy(p.y());
400  const double fy_ymin = fy(p.yMin());
401  const double fy_ymax = fy(p.yMax());
402  // Deal with possible inversions of min/max ordering under the transformation
403  const double newymin = std::min(fy_ymin, fy_ymax);
404  const double newymax = std::max(fy_ymin, fy_ymax);
405  // Set new point y values
406  p.setY(newy);
408  p.setYErrMinus(newy - newymin);
409  p.setYErrPlus(newymax - newy);
410  }
411  }
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 418 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().

418  {
419  for (size_t i = 0; i < s.numPoints(); ++i) {
420  Point3D& p = s.point(i);
421  const double newz = fz(p.z());
422  const double fz_zmin = fz(p.zMin());
423  const double fz_zmax = fz(p.zMax());
424  // Deal with possible inversions of min/max ordering under the transformation
425  const double newzmin = std::min(fz_zmin, fz_zmax);
426  const double newzmax = std::max(fz_zmin, fz_zmax);
427  // Set new point z values
428  p.setZ(newz);
430  p.setZErrMinus(newz - newzmin);
431  p.setZErrPlus(newzmax - newz);
432  }
433  }
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().

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:20
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:20
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:20

Variable Documentation

const double YODA::HALFPI = M_PI_2

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

Definition at line 40 of file MathUtils.h.

const double YODA::MAXDOUBLE = std::numeric_limits<double>::max()

Definition at line 30 of file MathUtils.h.

const double YODA::MAXINT = std::numeric_limits<int>::max()

Definition at line 31 of file MathUtils.h.

const double YODA::PI = M_PI

A pre-defined value of $ \pi $.

Definition at line 34 of file MathUtils.h.

const double YODA::TWOPI = 2*M_PI

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

Definition at line 37 of file MathUtils.h.