All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Ratio.cxx
Go to the documentation of this file.
2 
5 
6 #include "TH1.h"
7 
8 #include <cassert>
9 
10 namespace ana
11 {
12  //----------------------------------------------------------------------
13  Ratio::Ratio(const Spectrum& num, const Spectrum& denom,
14  bool purOrEffErrs)
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  }
31 
32  //----------------------------------------------------------------------
33  Ratio::Ratio(TH1* h, std::string varName)
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  }
56 
57  //----------------------------------------------------------------------
59  {
61  }
62 
63  //----------------------------------------------------------------------
64  Ratio::Ratio(const Ratio& rhs)
65  {
66  DontAddDirectory guard;
67 
68  assert(rhs.fHist);
70  }
71 
72  //----------------------------------------------------------------------
74  {
75  if(this == &rhs) return *this;
76 
77  DontAddDirectory guard;
78 
80  assert(rhs.fHist);
82  return *this;
83  }
84 
85  //----------------------------------------------------------------------
87  {
88  fHist->Multiply(rhs.fHist);
89  return *this;
90  }
91 
92  //----------------------------------------------------------------------
93  Ratio Ratio::operator*(const Ratio& rhs) const
94  {
95  Ratio ret = *this;
96  ret *= rhs;
97  return ret;
98  }
99 
100  //----------------------------------------------------------------------
102  {
103  fHist->Divide(rhs.fHist);
104  return *this;
105  }
106 
107  //----------------------------------------------------------------------
108  Ratio Ratio::operator/(const Ratio& rhs) const
109  {
110  Ratio ret = *this;
111  ret /= rhs;
112  return ret;
113  }
114 
115  //----------------------------------------------------------------------
116  TH1D* Ratio::ToTH1(Color_t col, Style_t style) const
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  }
126 } // namespace
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
Definition: Ratio.cxx:116
Ratio & operator=(const Ratio &rhs)
Definition: Ratio.cxx:73
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
Ratio & operator*=(const Ratio &rhs)
Definition: Ratio.cxx:86
def style
Definition: util.py:237
process_name opflashCryoW ana
Ratio & operator/=(const Ratio &rhs)
Definition: Ratio.cxx:101
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:30
Ratio operator*(const Ratio &rhs) const
Definition: Ratio.cxx:93
while getopts h
Ratio(const Spectrum &num, const Spectrum &denom, bool purOrEffErrs=false)
Definition: Ratio.cxx:13
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
TH1D * fHist
Definition: Ratio.h:36
Ratio operator/(const Ratio &rhs) const
Definition: Ratio.cxx:108
Represent the ratio between two spectra.
Definition: Ratio.h:8
virtual ~Ratio()
Definition: Ratio.cxx:58
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:21
Prevent histograms being added to the current directory.
std::string UniqueName()
Return a different string each time, for creating histograms.