All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlashHypothesis.cxx
Go to the documentation of this file.
1 #include "FlashHypothesis.h"
2 
3 #include <limits>
4 #include <iostream>
5 
6 void opdet::FlashHypothesis::SetHypothesisVectorAndErrorVector( std::vector<float> v , std::vector<float> err)
7 {
8  if(err.size()!=0 && err.size()!=v.size())
9  throw std::runtime_error("ERROR in FlashHypothesisVectorSetter: Vector sizes not equal");
10 
11  _NPEs_Vector = v;
12  if(err.size()==0){
13  _NPEs_Vector = v;
14  _NPEs_ErrorVector.resize(v.size());
15  for(size_t i=0; i<_NPEs_Vector.size(); i++)
16  _NPEs_ErrorVector[i] = std::sqrt(_NPEs_Vector[i]);
17  }
18  else
20 
21 }
22 
23 void opdet::FlashHypothesis::SetHypothesisAndError( size_t i_opdet, float pe , float err)
24 {
25  SetHypothesis(i_opdet,pe);
26  if(err>0) SetHypothesisError(i_opdet,err);
27  else SetHypothesisError(i_opdet,std::sqrt(pe));
28 }
29 
30 void opdet::FlashHypothesis::Normalize(float const& totalPE_target){
31 
32  if( GetTotalPEs() < std::numeric_limits<float>::epsilon() ) return;
33 
34  const float PE_ratio = totalPE_target/GetTotalPEs();
35  for(size_t i_opdet=0; i_opdet<_NPEs_Vector.size(); i_opdet++){
36  _NPEs_Vector[i_opdet] *= PE_ratio;
37  _NPEs_ErrorVector[i_opdet] = std::sqrt(_NPEs_Vector[i_opdet]);
38  }
39 
40 }
41 
43 {
44  std::cout << "TotalPEs: " << GetTotalPEs() << " +/- " << GetTotalPEsError() << std::endl;
45  std::cout << "Vector size: " << GetVectorSize() << std::endl;
46  for(size_t i=0; i<GetVectorSize(); i++)
47  std::cout << "\t" << i << ": " << GetHypothesis(i) << " +/- " << GetHypothesisError(i) << std::endl;
48 }
49 
51 {
52  CheckFrac(frac);
53  _total_hyp = total;
54  _prompt_frac = frac;
55  _prompt_hyp = total; _prompt_hyp.Normalize( frac*total.GetTotalPEs() );
56  _late_hyp = total; _late_hyp.Normalize( (1.-frac)*total.GetTotalPEs() );
57 }
58 
60 {
61  CheckFrac(frac);
62  _prompt_hyp = prompt;
63  _prompt_frac = frac;
64  _late_hyp = prompt; _late_hyp.Normalize( (1/frac - 1.)*prompt.GetTotalPEs() );
65  _total_hyp = _prompt_hyp + _late_hyp;
66 }
67 
69  _prompt_hyp.Normalize(totalPE_target*_prompt_frac);
70  _late_hyp.Normalize(totalPE_target*(1.-_prompt_frac));
71  UpdateTotalHyp();
72 }
73 
75 {
76  if ( std::abs(f-0.0) < std::numeric_limits<float>::epsilon() ||
77  std::abs(f-1.0) < std::numeric_limits<float>::epsilon() ||
78  (f>0.0 && f<1.0) )
79  return;
80 
81  throw std::runtime_error("ERROR in FlashHypothesisCollection: Input fraction is not in valid range.");
82 }
83 
85 {
86  _total_hyp = _prompt_hyp + _late_hyp;
87  const float total_pe = _total_hyp.GetTotalPEs();
88  if(total_pe > std::numeric_limits<float>::epsilon())
89  _prompt_frac = _prompt_hyp.GetTotalPEs() / total_pe;
90  else
91  _prompt_frac = 1.;
92 }
93 
95 {
96  std::cout << "PromptHyp:" << std::endl;
97  _prompt_hyp.Print();
98  std::cout << "LateHyp:" << std::endl;
99  _late_hyp.Print();
100  std::cout << "TotalHyp:" << std::endl;
101  _total_hyp.Print();
102  std::cout << "PromptFraction: " << _prompt_frac << std::endl;
103 
104 }
Class def header for a class FlashHypothesis.
EResult err(const char *call)
std::vector< float > _NPEs_ErrorVector
float GetTotalPEs() const
T abs(T value)
void SetTotalHypAndPromptFraction(const FlashHypothesis &total, float frac)
std::vector< float > _NPEs_Vector
void SetHypothesisVectorAndErrorVector(std::vector< float > v, std::vector< float > err=std::vector< float >(0))
void SetPromptHypAndPromptFraction(const FlashHypothesis &prompt, float frac)
void Normalize(float const &totalPE_target)
void SetHypothesisAndError(size_t i_opdet, float pe, float err=-999)
BEGIN_PROLOG could also be cout