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.15/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
 
LabelsAndBins fAxis
 

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), fAxis(num.GetLabels(), num.GetBinnings())
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
void Scale(double s)
Definition: Hist.cxx:296
void Divide(const Hist &rhs)
Definition: Hist.cxx:531
Hist fHist
Definition: Ratio.h:56
int num
Definition: f2_nu.C:119
LabelsAndBins fAxis
Definition: Ratio.h:57
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))), fAxis(labels, bins)
24  {
25  }
const Binning bins
Definition: NumuCC_CPiBin.h:8
Hist fHist
Definition: Ratio.h:56
LabelsAndBins fAxis
Definition: Ratio.h:57
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)), fAxis(std::move(l), std::move(b))
53  {
54  }
Hist fHist
Definition: Ratio.h:56
const hit & b
Definition: hits.cxx:21
LabelsAndBins fAxis
Definition: Ratio.h:57

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:46
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:44
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

Definition at line 67 of file Ratio.cxx.

References fAxis, fHist, ana::LabelsAndBins::GetBins1D(), ana::LabelsAndBins::GetLabel1D(), runNovaSAM::ret, and ana::Hist::ToTH1().

Referenced by ana::DataMCRatio(), demo::DrawUpDownRatioCanvas(), ana::MichelDecomp::GetNCMCContent(), ana::MichelDecomp::GetNCScale(), ana::MichelDecomp::GetNueScale(), ana::MichelDecomp::GetNumuMCContent(), ana::MichelDecomp::GetNumuScale(), make_xs(), make_xs_1D(), ana::CrossSectionAnalysis::PlotEfficiency(), ana::NumuCCIncAnalysis::PlotEfficiency(), Plotting_Data2DataComp(), Plotting_Data2DataComp_SingleCanvas(), Plotting_DataAndPrediction(), PredRatioToNom(), Ratio(), ana::RatioPlot(), test_nuwro(), ana::NDOscCurve::ToTH1(), ana::OscCurve::ToTH1(), ToTH2(), ana::ToTH2(), ana::ToTH3(), Unfold1D(), and Unfold3D().

68  {
69  TH1D* ret = fHist.ToTH1(fAxis.GetBins1D());
70  ret->SetLineColor(col);
71  ret->SetLineStyle(style);
72  ret->GetXaxis()->SetTitle(fAxis.GetLabel1D().c_str());
73  ret->GetYaxis()->SetTitle("Ratio");
74  return ret;
75  }
TH1D * ToTH1(const Binning &bins) const
Definition: Hist.cxx:207
const std::string & GetLabel1D() const
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
Int_t col[ntarg]
Definition: Style.C:29
Hist fHist
Definition: Ratio.h:56
LabelsAndBins fAxis
Definition: Ratio.h:57
TH2 * ana::Ratio::ToTH2 ( ) const

Definition at line 78 of file Ratio.cxx.

References om::cout, allTimeWatchdog::endl, fAxis, ana::LabelsAndBins::GetBinnings(), ana::LabelsAndBins::GetLabels(), ana::LabelsAndBins::NDimensions(), runNovaSAM::ret, ToTH1(), and ana::ToTH2Helper().

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

79  {
80  if(fAxis.NDimensions() != 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()),
86  fAxis.GetBinnings()[0],
87  fAxis.GetBinnings()[1]);
88 
89  ret->GetXaxis()->SetTitle(fAxis.GetLabels()[0].c_str());
90  ret->GetYaxis()->SetTitle(fAxis.GetLabels()[1].c_str());
91 
92  // Allow GetMean() and friends to work even if this histogram never had any
93  // explicit Fill() calls made.
94  if(ret->GetEntries() == 0) ret->SetEntries(1);
95 
96  return ret;
97  }
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:67
OStream cout
Definition: OStream.cxx:6
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
unsigned int NDimensions() const
Definition: LabelsAndBins.h:66
LabelsAndBins fAxis
Definition: Ratio.h:57
TH2 * ToTH2Helper(std::unique_ptr< TH1 > h1, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
Helper for ana::ToTH2.
Definition: UtilsExt.cxx:135
const std::vector< std::string > & GetLabels() const
Definition: LabelsAndBins.h:68

Friends And Related Function Documentation

friend class Spectrum
friend

Definition at line 11 of file Ratio.h.

Member Data Documentation

LabelsAndBins ana::Ratio::fAxis
protected

Definition at line 57 of file Ratio.h.

Referenced by ToTH1(), and ToTH2().

Hist ana::Ratio::fHist
protected

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