LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
FlashHypothesis.h
Go to the documentation of this file.
1 #ifndef FLASHHYPOTHESIS_H
2 #define FLASHHYPOTHESIS_H
3 
11 #include <iostream>
12 #include <numeric>
13 #include <vector>
14 #include <cmath>
15 #include <stdexcept>
16 
17 namespace opdet{
18 
20 
21  public:
24  { _NPEs_Vector = std::vector<float>(s,0.0); _NPEs_ErrorVector = std::vector<float>(s,0.0); }
25  FlashHypothesis(std::vector<float> const& vector,
26  std::vector<float> const& vector_error=std::vector<float>())
27  { SetHypothesisVectorAndErrorVector(vector,vector_error); }
28 
29  std::vector<float> const& GetHypothesisVector() const { return _NPEs_Vector; }
30  std::vector<float> const& GetHypothesisErrorVector() const { return _NPEs_ErrorVector; }
31  void SetHypothesisVector( std::vector<float> v ) { _NPEs_Vector=v; _NPEs_ErrorVector.resize(v.size()); }
32  void SetHypothesisErrorVector( std::vector<float> v ) { _NPEs_ErrorVector = v; _NPEs_Vector.resize(v.size()); }
33  void SetHypothesisVectorAndErrorVector( std::vector<float> v , std::vector<float> err=std::vector<float>(0));
34 
35  float const& GetHypothesis(size_t i_opdet) const { return _NPEs_Vector.at(i_opdet); }
36  float const& GetHypothesisError(size_t i_opdet) const { return _NPEs_ErrorVector.at(i_opdet); }
37  void SetHypothesis( size_t i_opdet, float pe ) { _NPEs_Vector.at(i_opdet)=pe; }
38  void SetHypothesisError( size_t i_opdet, float err ) { _NPEs_ErrorVector.at(i_opdet) = err; }
39 
40  void SetHypothesisAndError( size_t i_opdet, float pe , float err=-999 );
41 
42  float GetTotalPEs() const
43  { return std::accumulate(_NPEs_Vector.begin(),_NPEs_Vector.end(),0.0); }
44  float GetTotalPEsError() const
45  { return std::sqrt( std::inner_product(_NPEs_ErrorVector.begin(),_NPEs_ErrorVector.end(),_NPEs_ErrorVector.begin(),0.0) ); }
46 
47  size_t GetVectorSize() const { return _NPEs_Vector.size(); }
48 
49  void Normalize(float const& totalPE_target);
50 
51  void Print();
52 
54 
55  if( _NPEs_Vector.size() != fh.GetVectorSize() )
56  throw std::runtime_error("ERROR in FlashHypothesisAddition: Cannot add hypothesis of different size");
57 
58  FlashHypothesis flashhyp(_NPEs_Vector.size());
59  for(size_t i=0; i<_NPEs_Vector.size(); i++){
60  flashhyp._NPEs_Vector[i] = _NPEs_Vector[i] + fh._NPEs_Vector[i];
61  flashhyp._NPEs_ErrorVector[i] =
62  std::sqrt(this->_NPEs_ErrorVector[i]*this->_NPEs_ErrorVector[i] +
64  }
65  return flashhyp;
66  }
67 
68  private:
69  std::vector<float> _NPEs_Vector;
70  std::vector<float> _NPEs_ErrorVector;
71  };
72 
73 
75 
76  public:
77 
80  { _prompt_hyp=FlashHypothesis(s); _late_hyp=FlashHypothesis(s); UpdateTotalHyp(); }
82  { SetPromptAndLateHyp(prompt,late); }
83 
84  void SetPromptAndLateHyp(const FlashHypothesis& prompt, const FlashHypothesis& late)
85  { _prompt_hyp=prompt; _late_hyp=late; UpdateTotalHyp(); }
86  void SetTotalHypAndPromptFraction(const FlashHypothesis& total,float frac);
87  void SetPromptHypAndPromptFraction(const FlashHypothesis& prompt, float frac);
88 
89  size_t GetVectorSize() const { return _prompt_hyp.GetVectorSize(); }
90 
91  float GetPromptFraction() const { return _prompt_frac; }
92  float GetLateFraction() const { return 1.-_prompt_frac; }
93 
94  const FlashHypothesis& GetPromptHypothesis() const { return _prompt_hyp; }
95  const FlashHypothesis& GetLateHypothesis() const { return _late_hyp; }
96  const FlashHypothesis& GetTotalHypothesis() const { return _total_hyp; }
97 
98  void Normalize(float totalPEs);
99 
100  void Print();
101 
103 
104  if( this->GetVectorSize() != fhc.GetVectorSize() )
105  throw std::runtime_error("ERROR in FlashHypothesisCollectionAddition: Cannot add hypothesis of different size");
106 
107  FlashHypothesis ph = this->GetPromptHypothesis();
108  ph = ph + fhc.GetPromptHypothesis();
109  FlashHypothesis lh = this->GetLateHypothesis();
110  lh = lh + fhc.GetLateHypothesis();
111 
112  return (FlashHypothesisCollection(ph,lh));
113  }
114 
115  private:
120 
121  void CheckFrac(float f);
122  void UpdateTotalHyp();
123 
124  };
125 
126 }
127 
128 #endif
Float_t s
Definition: plot.C:23
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:265
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)