Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ana::Ratio Class Reference

Represent the ratio between two spectra. More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.10/src/CAFAna/Core/Ratio.h"

Inheritance diagram for ana::Ratio:
ana::NDOscCurve ana::OscCurve

Public Member Functions

 Ratio (const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
 
 Ratio (Eigen::ArrayXd &&arr, const std::vector< std::string > &labels, const std::vector< Binning > &bins)
 
virtual ~Ratio ()
 
 Ratio (const Ratio &rhs)=default
 
Ratiooperator= (const Ratio &rhs)=default
 
Ratiooperator*= (const Ratio &rhs)
 
Ratio operator* (const Ratio &rhs) const
 
Ratiooperator/= (const Ratio &rhs)
 
Ratio operator/ (const Ratio &rhs) const
 
TH1D * ToTH1 (Color_t col=kBlack, Style_t style=kSolid) const
 
TH2 * ToTH2 () const
 
bool HasStan () const
 
const Eigen::ArrayXd & GetEigen () const
 
const Eigen::ArrayXstanGetEigenStan () const
 

Protected Member Functions

 Ratio (Hist &&h, std::vector< Binning > &&b, std::vector< std::string > &&l)
 

Protected Attributes

Hist fHist
 
std::vector< BinningfBins
 
std::vector< std::stringfLabels
 

Friends

class Spectrum
 

Detailed Description

Represent the ratio between two spectra.

Definition at line 8 of file Ratio.h.

Constructor & Destructor Documentation

ana::Ratio::Ratio ( const Spectrum num,
const Spectrum denom,
bool  purOrEffErrs = false 
)
Parameters
numNumerator of the ratio
denomDenominator of the ratio
purOrEffErrsDoes this ratio represent a purity or efficiency plot? If so, error bars are calculated differently.

Definition at line 11 of file Ratio.cxx.

References ana::Hist::Divide(), fHist, ana::Spectrum::fHist, ana::Hist::GetBinContent(), ana::Hist::GetNbinsX(), MECModelEnuComparisons::i, ana::Spectrum::POT(), ana::Hist::Scale(), and ana::Hist::SetBinContent().

Referenced by ana::operator/(), and Ratio().

13  : fHist(num.fHist), fBins(num.GetBinnings()), fLabels(num.GetLabels())
14  {
15  fHist.Divide(denom.fHist);
16  fHist.Scale(denom.POT()/num.POT());
17 
18  // This is clumsy, but the old histogram operation considered 0/0 = 0,
19  // which is actually pretty useful (at least PredictionInterp relies on
20  // this).
21  for(int i = 0; i < fHist.GetNbinsX()+2; ++i){
22  if(num.fHist.GetBinContent(i) == 0 &&
23  denom.fHist.GetBinContent(i) == 0){
24  fHist.SetBinContent(i, 0);
25  }
26  }
27 
28  // TODO do something with purOrEffErrs
29  }
void SetBinContent(int i, double x)
Definition: Hist.cxx:363
int GetNbinsX() const
Definition: Hist.cxx:228
std::vector< std::string > fLabels
Definition: Ratio.h:58
void Scale(double s)
Definition: Hist.cxx:296
std::vector< Binning > fBins
Definition: Ratio.h:57
void Divide(const Hist &rhs)
Definition: Hist.cxx:531
Hist fHist
Definition: Ratio.h:56
int num
Definition: f2_nu.C:119
ana::Ratio::Ratio ( Eigen::ArrayXd &&  arr,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins 
)
inline

Definition at line 20 of file Ratio.h.

References col, operator*(), operator*=(), operator/(), operator/=(), operator=(), Ratio(), ToTH1(), ToTH2(), and ~Ratio().

23  : fHist(Hist::Adopt(std::move(arr))), fBins(bins), fLabels(labels)
24  {
25  }
std::vector< std::string > fLabels
Definition: Ratio.h:58
std::vector< Binning > fBins
Definition: Ratio.h:57
const Binning bins
Definition: NumuCC_CPiBin.h:8
Hist fHist
Definition: Ratio.h:56
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149
ana::Ratio::~Ratio ( )
virtual

Definition at line 32 of file Ratio.cxx.

Referenced by Ratio().

33  {
34  }
ana::Ratio::Ratio ( const Ratio rhs)
default
ana::Ratio::Ratio ( Hist &&  h,
std::vector< Binning > &&  b,
std::vector< std::string > &&  l 
)
inlineprotected

Definition at line 49 of file Ratio.h.

52  : fHist(std::move(h)), fBins(std::move(b)), fLabels(std::move(l))
53  {
54  }
std::vector< std::string > fLabels
Definition: Ratio.h:58
std::vector< Binning > fBins
Definition: Ratio.h:57
Hist fHist
Definition: Ratio.h:56
const hit & b
Definition: hits.cxx:21

Member Function Documentation

const Eigen::ArrayXd& ana::Ratio::GetEigen ( ) const
inline
const Eigen::ArrayXstan& ana::Ratio::GetEigenStan ( ) const
inline

Definition at line 45 of file Ratio.h.

References fHist, and ana::Hist::GetEigenStan().

Referenced by ana::ReweightableSpectrum::WeightedBy().

45 {return fHist.GetEigenStan();}
Hist fHist
Definition: Ratio.h:56
const Eigen::ArrayXstan & GetEigenStan() const
Definition: Hist.h:54
bool ana::Ratio::HasStan ( ) const
inline

Definition at line 43 of file Ratio.h.

References fHist, and ana::Hist::HasStan().

Referenced by ana::ReweightableSpectrum::WeightedBy().

43 {return fHist.HasStan();}
Hist fHist
Definition: Ratio.h:56
bool HasStan() const
Definition: Hist.h:52
Ratio ana::Ratio::operator* ( const Ratio rhs) const

Definition at line 44 of file Ratio.cxx.

References runNovaSAM::ret.

Referenced by Ratio().

45  {
46  Ratio ret = *this;
47  ret *= rhs;
48  return ret;
49  }
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:11
Ratio & ana::Ratio::operator*= ( const Ratio rhs)

Definition at line 37 of file Ratio.cxx.

References fHist, and ana::Hist::Multiply().

Referenced by Ratio().

38  {
39  fHist.Multiply(rhs.fHist);
40  return *this;
41  }
Hist fHist
Definition: Ratio.h:56
void Multiply(const Hist &rhs)
Definition: Hist.cxx:479
Ratio ana::Ratio::operator/ ( const Ratio rhs) const

Definition at line 59 of file Ratio.cxx.

References runNovaSAM::ret.

Referenced by Ratio().

60  {
61  Ratio ret = *this;
62  ret /= rhs;
63  return ret;
64  }
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:11
Ratio & ana::Ratio::operator/= ( const Ratio rhs)

Definition at line 52 of file Ratio.cxx.

References ana::Hist::Divide(), and fHist.

Referenced by Ratio().

53  {
54  fHist.Divide(rhs.fHist);
55  return *this;
56  }
void Divide(const Hist &rhs)
Definition: Hist.cxx:531
Hist fHist
Definition: Ratio.h:56
Ratio& ana::Ratio::operator= ( const Ratio rhs)
default

Referenced by Ratio().

TH1D * ana::Ratio::ToTH1 ( Color_t  col = kBlack,
Style_t  style = kSolid 
) const
TH2 * ana::Ratio::ToTH2 ( ) const

Definition at line 78 of file Ratio.cxx.

References om::cout, allTimeWatchdog::endl, fBins, fLabels, runNovaSAM::ret, ToTH1(), and ana::ToTH2Helper().

Referenced by ana::SingleNucAnalysis::PlotEfficiency2D(), ana::NumuCC2p2hAnalysis::PlotEfficiency2D(), and Ratio().

79  {
80  if(fBins.size() != 2){
81  std::cout << "Error: This Ratio does not appear to be 2D." << std::endl;
82  abort();
83  }
84 
85  TH2* ret = ana::ToTH2Helper(std::unique_ptr<TH1>(ToTH1()), fBins[0], fBins[1]);
86 
87  ret->GetXaxis()->SetTitle(fLabels[0].c_str());
88  ret->GetYaxis()->SetTitle(fLabels[1].c_str());
89 
90  // Allow GetMean() and friends to work even if this histogram never had any
91  // explicit Fill() calls made.
92  if(ret->GetEntries() == 0) ret->SetEntries(1);
93 
94  return ret;
95  }
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:67
std::vector< std::string > fLabels
Definition: Ratio.h:58
std::vector< Binning > fBins
Definition: Ratio.h:57
OStream cout
Definition: OStream.cxx:6
TH2 * ToTH2Helper(std::unique_ptr< TH1 > h1, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
Helper for ana::ToTH2.
Definition: UtilsExt.cxx:135

Friends And Related Function Documentation

friend class Spectrum
friend

Definition at line 11 of file Ratio.h.

Member Data Documentation

std::vector<Binning> ana::Ratio::fBins
protected

Definition at line 57 of file Ratio.h.

Referenced by ToTH1(), and ToTH2().

Hist ana::Ratio::fHist
protected
std::vector<std::string> ana::Ratio::fLabels
protected

Definition at line 58 of file Ratio.h.

Referenced by ToTH1(), and ToTH2().


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