All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | Friends | List of all members
ana::Ratio Class Reference

Represent the ratio between two spectra. More...

#include <Ratio.h>

Public Member Functions

 Ratio (const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
 
 Ratio (TH1 *h, std::string varName="")
 Don't use this constructor unless you REALLY KNOW what you're doing. More...
 
virtual ~Ratio ()
 
 Ratio (const Ratio &rhs)
 
Ratiooperator= (const Ratio &rhs)
 
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
 

Protected Attributes

TH1D * fHist
 

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 13 of file Ratio.cxx.

15  {
16  // Scale to same arbitrary POT
17  fHist = num.ToTH1(1e20);
18  TH1D* temp = denom.ToTH1(1e20);
19  if(purOrEffErrs){
20  fHist->Divide(fHist, temp, 1, 1, "B");
21  }
22  else{
23  fHist->Divide(temp);
24  }
25  HistCache::Delete(temp);
26 
27  fHist->GetYaxis()->SetTitle("Ratio");
28 
29  // TODO: set error bars smartly
30  }
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
TH1D * fHist
Definition: Ratio.h:36
ana::Ratio::Ratio ( TH1 *  h,
std::string  varName = "" 
)

Don't use this constructor unless you REALLY KNOW what you're doing.

Definition at line 33 of file Ratio.cxx.

34  {
35  if(!h){
36  fHist = 0;
37  return;
38  }
39 
40  DontAddDirectory guard;
41 
42  const TString className = h->ClassName();
43 
44  if(className == "TH1D"){
45  // Shortcut if types match
46  fHist = HistCache::Copy((TH1D*)h);
47  }
48  else{
49  fHist = HistCache::New(UniqueName(), h->GetXaxis());
50  fHist->GetXaxis()->SetTitle(h->GetXaxis()->GetTitle());
51  fHist->Add(h);
52  }
53 
54  if(!varName.empty()) fHist->GetXaxis()->SetTitle(varName.c_str());
55  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
while getopts h
TH1D * fHist
Definition: Ratio.h:36
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:21
std::string UniqueName()
Return a different string each time, for creating histograms.
ana::Ratio::~Ratio ( )
virtual

Definition at line 58 of file Ratio.cxx.

59  {
61  }
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
TH1D * fHist
Definition: Ratio.h:36
ana::Ratio::Ratio ( const Ratio rhs)

Definition at line 64 of file Ratio.cxx.

65  {
66  DontAddDirectory guard;
67 
68  assert(rhs.fHist);
69  fHist = HistCache::Copy(rhs.fHist);
70  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
TH1D * fHist
Definition: Ratio.h:36

Member Function Documentation

Ratio ana::Ratio::operator* ( const Ratio rhs) const

Definition at line 93 of file Ratio.cxx.

94  {
95  Ratio ret = *this;
96  ret *= rhs;
97  return ret;
98  }
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:13
Ratio & ana::Ratio::operator*= ( const Ratio rhs)

Definition at line 86 of file Ratio.cxx.

87  {
88  fHist->Multiply(rhs.fHist);
89  return *this;
90  }
TH1D * fHist
Definition: Ratio.h:36
Ratio ana::Ratio::operator/ ( const Ratio rhs) const

Definition at line 108 of file Ratio.cxx.

109  {
110  Ratio ret = *this;
111  ret /= rhs;
112  return ret;
113  }
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:13
Ratio & ana::Ratio::operator/= ( const Ratio rhs)

Definition at line 101 of file Ratio.cxx.

102  {
103  fHist->Divide(rhs.fHist);
104  return *this;
105  }
TH1D * fHist
Definition: Ratio.h:36
Ratio & ana::Ratio::operator= ( const Ratio rhs)

Definition at line 73 of file Ratio.cxx.

74  {
75  if(this == &rhs) return *this;
76 
77  DontAddDirectory guard;
78 
80  assert(rhs.fHist);
81  fHist = HistCache::Copy(rhs.fHist);
82  return *this;
83  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
TH1D * fHist
Definition: Ratio.h:36
TH1D * ana::Ratio::ToTH1 ( Color_t  col = kBlack,
Style_t  style = kSolid 
) const

Definition at line 116 of file Ratio.cxx.

117  {
118  // Could have a file temporarily open
119  DontAddDirectory guard;
120 
121  TH1D* ret = HistCache::Copy(fHist);
122  ret->SetLineColor(col);
123  ret->SetLineStyle(style);
124  return ret;
125  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
def style
Definition: util.py:237
TH1D * fHist
Definition: Ratio.h:36

Friends And Related Function Documentation

friend class Spectrum
friend

Definition at line 11 of file Ratio.h.

Member Data Documentation

TH1D* ana::Ratio::fHist
protected

Definition at line 36 of file Ratio.h.


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