Ratio.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "CAFAna/Core/Spectrum.h"
4 
5 namespace ana
6 {
7  /// Represent the ratio between two spectra
8  class Ratio
9  {
10  public:
11  friend class Spectrum;
12 
13  /// \param num Numerator of the ratio
14  /// \param denom Denominator of the ratio
15  /// \param purOrEffErrs Does this ratio represent a purity or efficiency
16  /// plot? If so, error bars are calculated differently.
17  Ratio(const Spectrum& num, const Spectrum& denom,
18  bool purOrEffErrs = false);
19 
20  Ratio(Eigen::ArrayXd&& arr,
21  const std::vector<std::string>& labels,
22  const std::vector<Binning>& bins)
23  : fHist(Hist::Adopt(std::move(arr))), fBins(bins), fLabels(labels)
24  {
25  }
26 
27  virtual ~Ratio();
28 
29  Ratio(const Ratio& rhs) = default;
30  Ratio& operator=(const Ratio& rhs) = default;
31 
32  Ratio& operator*=(const Ratio& rhs);
33  Ratio operator*(const Ratio& rhs) const;
34 
35  Ratio& operator/=(const Ratio& rhs);
36  Ratio operator/(const Ratio& rhs) const;
37 
38  TH1D* ToTH1(Color_t col = kBlack,
39  Style_t style = kSolid) const;
40 
41  TH2* ToTH2() const;
42 
43  bool HasStan() const {return fHist.HasStan();}
44  const Eigen::ArrayXd& GetEigen() const {return fHist.GetEigen();}
45  const Eigen::ArrayXstan& GetEigenStan() const {return fHist.GetEigenStan();}
46 
47  protected:
48  // For derived classes
50  std::vector<Binning>&& b,
51  std::vector<std::string>&& l)
52  : fHist(std::move(h)), fBins(std::move(b)), fLabels(std::move(l))
53  {
54  }
55 
57  std::vector<Binning> fBins;
58  std::vector<std::string> fLabels;
59  };
60 
61  inline Ratio operator/(const Spectrum& lhs, const Spectrum& rhs){return Ratio(lhs, rhs);}
62 } // namespace
const Eigen::ArrayXd & GetEigen() const
Definition: Hist.h:53
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TH2 * ToTH2() const
Definition: Ratio.cxx:78
const Eigen::ArrayXd & GetEigen() const
Definition: Ratio.h:44
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:67
Ratio & operator*=(const Ratio &rhs)
Definition: Ratio.cxx:37
Definition: Hist.h:29
Ratio(Hist &&h, std::vector< Binning > &&b, std::vector< std::string > &&l)
Definition: Ratio.h:49
Ratio(Eigen::ArrayXd &&arr, const std::vector< std::string > &labels, const std::vector< Binning > &bins)
Definition: Ratio.h:20
Ratio & operator/=(const Ratio &rhs)
Definition: Ratio.cxx:52
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
Ratio operator*(const Ratio &rhs) const
Definition: Ratio.cxx:44
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:11
Int_t col[ntarg]
Definition: Style.C:29
const Eigen::ArrayXstan & GetEigenStan() const
Definition: Ratio.h:45
std::vector< std::string > fLabels
Definition: Ratio.h:58
Ratio & operator=(const Ratio &rhs)=default
Ratio operator/(const Ratio &rhs) const
Definition: Ratio.cxx:59
std::vector< Binning > fBins
Definition: Ratio.h:57
Represent the ratio between two spectra.
Definition: Ratio.h:8
virtual ~Ratio()
Definition: Ratio.cxx:32
const Binning bins
Definition: NumuCC_CPiBin.h:8
Eigen::Array< stan::math::var, Eigen::Dynamic, 1 > ArrayXstan
Definition: StanUtils.h:7
Hist fHist
Definition: Ratio.h:56
int num
Definition: f2_nu.C:119
const hit & b
Definition: hits.cxx:21
bool HasStan() const
Definition: Ratio.h:43
bool HasStan() const
Definition: Hist.h:52
const Eigen::ArrayXstan & GetEigenStan() const
Definition: Hist.h:54