LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FlashHypothesis.h
Go to the documentation of this file.
1 #ifndef FLASHHYPOTHESIS_H
2 #define FLASHHYPOTHESIS_H
3 
11 #include <cmath>
12 #include <numeric>
13 #include <stdexcept>
14 #include <vector>
15 
16 namespace opdet {
17 
19 
20  public:
22  FlashHypothesis(size_t s)
23  {
24  _NPEs_Vector = std::vector<float>(s, 0.0);
25  _NPEs_ErrorVector = std::vector<float>(s, 0.0);
26  }
27  FlashHypothesis(std::vector<float> const& vector,
28  std::vector<float> const& vector_error = std::vector<float>())
29  {
30  SetHypothesisVectorAndErrorVector(vector, vector_error);
31  }
32 
33  std::vector<float> const& GetHypothesisVector() const { return _NPEs_Vector; }
34  std::vector<float> const& GetHypothesisErrorVector() const { return _NPEs_ErrorVector; }
35  void SetHypothesisVector(std::vector<float> v)
36  {
37  _NPEs_Vector = v;
38  _NPEs_ErrorVector.resize(v.size());
39  }
40  void SetHypothesisErrorVector(std::vector<float> v)
41  {
43  _NPEs_Vector.resize(v.size());
44  }
45  void SetHypothesisVectorAndErrorVector(std::vector<float> v,
46  std::vector<float> err = std::vector<float>(0));
47 
48  float const& GetHypothesis(size_t i_opdet) const { return _NPEs_Vector.at(i_opdet); }
49  float const& GetHypothesisError(size_t i_opdet) const { return _NPEs_ErrorVector.at(i_opdet); }
50  void SetHypothesis(size_t i_opdet, float pe) { _NPEs_Vector.at(i_opdet) = pe; }
51  void SetHypothesisError(size_t i_opdet, float err) { _NPEs_ErrorVector.at(i_opdet) = err; }
52 
53  void SetHypothesisAndError(size_t i_opdet, float pe, float err = -999);
54 
55  float GetTotalPEs() const
56  {
57  return std::accumulate(_NPEs_Vector.begin(), _NPEs_Vector.end(), 0.0);
58  }
59  float GetTotalPEsError() const
60  {
61  return std::sqrt(std::inner_product(
62  _NPEs_ErrorVector.begin(), _NPEs_ErrorVector.end(), _NPEs_ErrorVector.begin(), 0.0));
63  }
64 
65  size_t GetVectorSize() const { return _NPEs_Vector.size(); }
66 
67  void Normalize(float const& totalPE_target);
68 
69  void Print();
70 
72  {
73 
74  if (_NPEs_Vector.size() != fh.GetVectorSize())
75  throw std::runtime_error(
76  "ERROR in FlashHypothesisAddition: Cannot add hypothesis of different size");
77 
78  FlashHypothesis flashhyp(_NPEs_Vector.size());
79  for (size_t i = 0; i < _NPEs_Vector.size(); i++) {
80  flashhyp._NPEs_Vector[i] = _NPEs_Vector[i] + fh._NPEs_Vector[i];
81  flashhyp._NPEs_ErrorVector[i] =
82  std::sqrt(this->_NPEs_ErrorVector[i] * this->_NPEs_ErrorVector[i] +
83  fh._NPEs_ErrorVector[i] * fh._NPEs_ErrorVector[i]);
84  }
85  return flashhyp;
86  }
87 
88  private:
89  std::vector<float> _NPEs_Vector;
90  std::vector<float> _NPEs_ErrorVector;
91  };
92 
94 
95  public:
98  {
99  _prompt_hyp = FlashHypothesis(s);
100  _late_hyp = FlashHypothesis(s);
101  UpdateTotalHyp();
102  }
104  {
105  SetPromptAndLateHyp(prompt, late);
106  }
107 
108  void SetPromptAndLateHyp(const FlashHypothesis& prompt, const FlashHypothesis& late)
109  {
110  _prompt_hyp = prompt;
111  _late_hyp = late;
112  UpdateTotalHyp();
113  }
114  void SetTotalHypAndPromptFraction(const FlashHypothesis& total, float frac);
115  void SetPromptHypAndPromptFraction(const FlashHypothesis& prompt, float frac);
116 
117  size_t GetVectorSize() const { return _prompt_hyp.GetVectorSize(); }
118 
119  float GetPromptFraction() const { return _prompt_frac; }
120  float GetLateFraction() const { return 1. - _prompt_frac; }
121 
122  const FlashHypothesis& GetPromptHypothesis() const { return _prompt_hyp; }
123  const FlashHypothesis& GetLateHypothesis() const { return _late_hyp; }
124  const FlashHypothesis& GetTotalHypothesis() const { return _total_hyp; }
125 
126  void Normalize(float totalPEs);
127 
128  void Print();
129 
131  {
132 
133  if (this->GetVectorSize() != fhc.GetVectorSize())
134  throw std::runtime_error(
135  "ERROR in FlashHypothesisCollectionAddition: Cannot add hypothesis of different size");
136 
137  FlashHypothesis ph = this->GetPromptHypothesis();
138  ph = ph + fhc.GetPromptHypothesis();
139  FlashHypothesis lh = this->GetLateHypothesis();
140  lh = lh + fhc.GetLateHypothesis();
141 
142  return (FlashHypothesisCollection(ph, lh));
143  }
144 
145  private:
150 
151  void CheckFrac(float f);
152  void UpdateTotalHyp();
153  };
154 
155 }
156 
157 #endif
void SetHypothesisVectorAndErrorVector(std::vector< float > v, std::vector< float > err=std::vector< float >(0))
size_t GetVectorSize() const
void SetPromptAndLateHyp(const FlashHypothesis &prompt, const FlashHypothesis &late)
FlashHypothesis(std::vector< float > const &vector, std::vector< float > const &vector_error=std::vector< float >())
float GetTotalPEsError() const
std::vector< float > _NPEs_ErrorVector
std::vector< float > const & GetHypothesisErrorVector() const
const FlashHypothesis & GetLateHypothesis() const
void SetHypothesisAndError(size_t i_opdet, float pe, float err=-999)
TFile f
Definition: plotHisto.C:6
FlashHypothesisCollection operator+(const FlashHypothesisCollection &fhc)
float GetTotalPEs() const
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
float const & GetHypothesisError(size_t i_opdet) const
void SetHypothesisError(size_t i_opdet, float err)
const FlashHypothesis & GetPromptHypothesis() const
std::vector< float > _NPEs_Vector
FlashHypothesis operator+(const FlashHypothesis &fh)
FlashHypothesisCollection(const FlashHypothesis &prompt, const FlashHypothesis &late)
float const & GetHypothesis(size_t i_opdet) const
void Normalize(float const &totalPE_target)
void SetHypothesis(size_t i_opdet, float pe)
const FlashHypothesis & GetTotalHypothesis() const
void SetHypothesisErrorVector(std::vector< float > v)
std::vector< float > const & GetHypothesisVector() const
void SetHypothesisVector(std::vector< float > v)