ra4_draw  4bd0201e3d922d42bd545d4b045ed44db33454a4
gamma_params.cpp
Go to the documentation of this file.
1 
29 #include "core/gamma_params.hpp"
30 
31 #include <cmath>
32 
36  n_effective_(0.),
37  weight_(0.){
38 }
39 
47 GammaParams::GammaParams(double n_effective, double weight):
48  n_effective_(n_effective),
49  weight_(weight){
50  }
51 
63 void GammaParams::SetYieldAndUncertainty(double yield, double uncertainty){
64  if(yield > 0.){
65  n_effective_ = (yield*yield)/(uncertainty*uncertainty);
66  weight_ = uncertainty*uncertainty/yield;
67  }else{
68  n_effective_ = 0.;
69  weight_ = hypot(yield, uncertainty);
70  }
71 }
72 
82 void GammaParams::SetNEffectiveAndWeight(double n_effective, double weight){
83  n_effective_ = n_effective;
84  weight_ = weight;
85 }
86 
91 double GammaParams::Yield() const{
92  return n_effective_*weight_;
93 }
94 
99 void GammaParams::Yield(double yield){
101 }
102 
110  return sqrt(n_effective_)*weight_;
111 }
112 
119 void GammaParams::Uncertainty(double uncertainty){
120  SetYieldAndUncertainty(Yield(), uncertainty);
121 }
122 
127 double GammaParams::NEffective() const{
128  return n_effective_;
129 }
130 
135 void GammaParams::NEffective(double n_effective){
136  SetNEffectiveAndWeight(n_effective, Weight());
137 }
138 
143 double GammaParams::Weight() const{
144  return weight_;
145 }
146 
151 void GammaParams::Weight(double weight){
153 }
154 
162  return sqrt(n_effective_+1.)*weight_;
163 }
164 
177  if(NEffective() == 0. && gp.NEffective() == 0.){
178  SetNEffectiveAndWeight(0., hypot(Weight(), gp.Weight()));
179  }else{
181  }
182  return *this;
183 }
184 
195  return *this;
196 }
197 
209  return (gp1 += gp2);
210 }
211 
223  return (gp*=scale);
224 }
225 
237  return (gp*=scale);
238 }
239 
248 std::ostream & operator<<(std::ostream &stream, const GammaParams &gp){
249  stream << gp.Yield() << "+-" << gp.CorrectedUncertainty()
250  << " (N=" << gp.NEffective() << ", w=" << gp.Weight() << ")";
251  return stream;
252 }
double Weight() const
Get the effective weight for the sample.
double weight_
double CorrectedUncertainty() const
Get the "sqrt(N+1)"-like uncertainty on the yield/rate.
Represents a yield and uncertainty obtained by counting weighted events.
Definition: gamma_params.hpp:6
GammaParams & operator+=(const GammaParams &gp)
Adds another GammaParams to *this.
void SetYieldAndUncertainty(double yield, double uncertainty)
Sets GammaParams by yield and uncertainty.
GammaParams & operator*=(double scale)
Scale/multiply *this by a constant.
GammaParams()
Standard constructor initializing to unweighted count = 0, weight = 0.
double Yield() const
Get the yield/rate.
std::ostream & operator<<(std::ostream &stream, const GammaParams &gp)
Print GammaParams to output stream.
double n_effective_
double Uncertainty() const
Get the "sqrt(N)"-like uncertainty on the yield/rate.
double NEffective() const
Get the effective number of unweighted events.
GammaParams operator+(GammaParams gp1, GammaParams gp2)
Add two GammaParams.
GammaParams operator*(double scale, GammaParams gp)
Scale/multiply a GammaParams by a constant on the left.
void SetNEffectiveAndWeight(double n_effective, double weight)
Sets GammaParams by unweighted event count and weight.