FlashHypothesis.h
Go to the documentation of this file.
1 #ifndef FLASHHYPOTHESIS_H
2 #define FLASHHYPOTHESIS_H
3 
4 /*!
5  * Title: FlashHypothesis Class
6  * Author: Wes Ketchum (wketchum@lanl.gov)
7  *
8  * Description: Class that represents a flash hypothesis (PEs per opdet) and its error
9 */
10 
11 #include <cmath>
12 #include <numeric>
13 #include <stdexcept>
14 #include <vector>
15 
16 namespace opdet{
17 
19 
20  public:
23  { _NPEs_Vector = std::vector<float>(s,0.0); _NPEs_ErrorVector = std::vector<float>(s,0.0); }
24  FlashHypothesis(std::vector<float> const& vector,
25  std::vector<float> const& vector_error=std::vector<float>())
26  { SetHypothesisVectorAndErrorVector(vector,vector_error); }
27 
28  std::vector<float> const& GetHypothesisVector() const { return _NPEs_Vector; }
29  std::vector<float> const& GetHypothesisErrorVector() const { return _NPEs_ErrorVector; }
30  void SetHypothesisVector( std::vector<float> v ) { _NPEs_Vector=v; _NPEs_ErrorVector.resize(v.size()); }
31  void SetHypothesisErrorVector( std::vector<float> v ) { _NPEs_ErrorVector = v; _NPEs_Vector.resize(v.size()); }
32  void SetHypothesisVectorAndErrorVector( std::vector<float> v , std::vector<float> err=std::vector<float>(0));
33 
34  float const& GetHypothesis(size_t i_opdet) const { return _NPEs_Vector.at(i_opdet); }
35  float const& GetHypothesisError(size_t i_opdet) const { return _NPEs_ErrorVector.at(i_opdet); }
36  void SetHypothesis( size_t i_opdet, float pe ) { _NPEs_Vector.at(i_opdet)=pe; }
37  void SetHypothesisError( size_t i_opdet, float err ) { _NPEs_ErrorVector.at(i_opdet) = err; }
38 
39  void SetHypothesisAndError( size_t i_opdet, float pe , float err=-999 );
40 
41  float GetTotalPEs() const
42  { return std::accumulate(_NPEs_Vector.begin(),_NPEs_Vector.end(),0.0); }
43  float GetTotalPEsError() const
44  { return std::sqrt( std::inner_product(_NPEs_ErrorVector.begin(),_NPEs_ErrorVector.end(),_NPEs_ErrorVector.begin(),0.0) ); }
45 
46  size_t GetVectorSize() const { return _NPEs_Vector.size(); }
47 
48  void Normalize(float const& totalPE_target);
49 
50  void Print();
51 
53 
54  if( _NPEs_Vector.size() != fh.GetVectorSize() )
55  throw std::runtime_error("ERROR in FlashHypothesisAddition: Cannot add hypothesis of different size");
56 
57  FlashHypothesis flashhyp(_NPEs_Vector.size());
58  for(size_t i=0; i<_NPEs_Vector.size(); i++){
59  flashhyp._NPEs_Vector[i] = _NPEs_Vector[i] + fh._NPEs_Vector[i];
60  flashhyp._NPEs_ErrorVector[i] =
61  std::sqrt(this->_NPEs_ErrorVector[i]*this->_NPEs_ErrorVector[i] +
63  }
64  return flashhyp;
65  }
66 
67  private:
68  std::vector<float> _NPEs_Vector;
69  std::vector<float> _NPEs_ErrorVector;
70  };
71 
72 
74 
75  public:
76 
79  { _prompt_hyp=FlashHypothesis(s); _late_hyp=FlashHypothesis(s); UpdateTotalHyp(); }
81  { SetPromptAndLateHyp(prompt,late); }
82 
83  void SetPromptAndLateHyp(const FlashHypothesis& prompt, const FlashHypothesis& late)
84  { _prompt_hyp=prompt; _late_hyp=late; UpdateTotalHyp(); }
85  void SetTotalHypAndPromptFraction(const FlashHypothesis& total,float frac);
86  void SetPromptHypAndPromptFraction(const FlashHypothesis& prompt, float frac);
87 
88  size_t GetVectorSize() const { return _prompt_hyp.GetVectorSize(); }
89 
90  float GetPromptFraction() const { return _prompt_frac; }
91  float GetLateFraction() const { return 1.-_prompt_frac; }
92 
93  const FlashHypothesis& GetPromptHypothesis() const { return _prompt_hyp; }
94  const FlashHypothesis& GetLateHypothesis() const { return _late_hyp; }
95  const FlashHypothesis& GetTotalHypothesis() const { return _total_hyp; }
96 
97  void Normalize(float totalPEs);
98 
99  void Print();
100 
102 
103  if( this->GetVectorSize() != fhc.GetVectorSize() )
104  throw std::runtime_error("ERROR in FlashHypothesisCollectionAddition: Cannot add hypothesis of different size");
105 
106  FlashHypothesis ph = this->GetPromptHypothesis();
107  ph = ph + fhc.GetPromptHypothesis();
108  FlashHypothesis lh = this->GetLateHypothesis();
109  lh = lh + fhc.GetLateHypothesis();
110 
111  return (FlashHypothesisCollection(ph,lh));
112  }
113 
114  private:
119 
120  void CheckFrac(float f);
121  void UpdateTotalHyp();
122 
123  };
124 
125 }
126 
127 #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 >())
struct vector vector
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)
FlashHypothesisCollection operator+(const FlashHypothesisCollection &fhc)
float GetTotalPEs() const
float const & GetHypothesisError(size_t i_opdet) const
void SetHypothesisError(size_t i_opdet, float err)
const FlashHypothesis & GetPromptHypothesis() const
void err(const char *fmt,...)
Definition: message.cpp:226
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)
static QCString * s
Definition: config.cpp:1042