LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
FlashHypothesis.cxx
Go to the documentation of this file.
1 #include "FlashHypothesis.h"
2 #include <limits>
3 
4 void opdet::FlashHypothesis::SetHypothesisVectorAndErrorVector( std::vector<float> v , std::vector<float> err)
5 {
6  if(err.size()!=0 && err.size()!=v.size())
7  throw std::runtime_error("ERROR in FlashHypothesisVectorSetter: Vector sizes not equal");
8 
9  _NPEs_Vector = v;
10  if(err.size()==0){
11  _NPEs_Vector = v;
12  _NPEs_ErrorVector.resize(v.size());
13  for(size_t i=0; i<_NPEs_Vector.size(); i++)
14  _NPEs_ErrorVector[i] = std::sqrt(_NPEs_Vector[i]);
15  }
16  else
17  _NPEs_ErrorVector = err;
18 
19 }
20 
21 void opdet::FlashHypothesis::SetHypothesisAndError( size_t i_opdet, float pe , float err)
22 {
23  SetHypothesis(i_opdet,pe);
24  if(err>0) SetHypothesisError(i_opdet,err);
25  else SetHypothesisError(i_opdet,std::sqrt(pe));
26 }
27 
28 void opdet::FlashHypothesis::Normalize(float const& totalPE_target){
29 
30  if( GetTotalPEs() < std::numeric_limits<float>::epsilon() ) return;
31 
32  const float PE_ratio = totalPE_target/GetTotalPEs();
33  for(size_t i_opdet=0; i_opdet<_NPEs_Vector.size(); i_opdet++){
34  _NPEs_Vector[i_opdet] *= PE_ratio;
35  _NPEs_ErrorVector[i_opdet] = std::sqrt(_NPEs_Vector[i_opdet]);
36  }
37 
38 }
39 
41 {
42  std::cout << "TotalPEs: " << GetTotalPEs() << " +/- " << GetTotalPEsError() << std::endl;
43  std::cout << "Vector size: " << GetVectorSize() << std::endl;
44  for(size_t i=0; i<GetVectorSize(); i++)
45  std::cout << "\t" << i << ": " << GetHypothesis(i) << " +/- " << GetHypothesisError(i) << std::endl;
46 }
47 
49 {
50  CheckFrac(frac);
51  _total_hyp = total;
52  _prompt_frac = frac;
53  _prompt_hyp = total; _prompt_hyp.Normalize( frac*total.GetTotalPEs() );
54  _late_hyp = total; _late_hyp.Normalize( (1.-frac)*total.GetTotalPEs() );
55 }
56 
58 {
59  CheckFrac(frac);
60  _prompt_hyp = prompt;
61  _prompt_frac = frac;
62  _late_hyp = prompt; _late_hyp.Normalize( (1/frac - 1.)*prompt.GetTotalPEs() );
63  _total_hyp = _prompt_hyp + _late_hyp;
64 }
65 
66 void opdet::FlashHypothesisCollection::Normalize(float totalPE_target){
67  _prompt_hyp.Normalize(totalPE_target*_prompt_frac);
68  _late_hyp.Normalize(totalPE_target*(1.-_prompt_frac));
69  UpdateTotalHyp();
70 }
71 
73 {
74  if ( std::abs(f-0.0) < std::numeric_limits<float>::epsilon() ||
75  std::abs(f-1.0) < std::numeric_limits<float>::epsilon() ||
76  (f>0.0 && f<1.0) )
77  return;
78 
79  throw std::runtime_error("ERROR in FlashHypothesisCollection: Input fraction is not in valid range.");
80 }
81 
83 {
84  _total_hyp = _prompt_hyp + _late_hyp;
85  const float total_pe = _total_hyp.GetTotalPEs();
86  if(total_pe > std::numeric_limits<float>::epsilon())
87  _prompt_frac = _prompt_hyp.GetTotalPEs() / total_pe;
88  else
89  _prompt_frac = 1.;
90 }
91 
93 {
94  std::cout << "PromptHyp:" << std::endl;
95  _prompt_hyp.Print();
96  std::cout << "LateHyp:" << std::endl;
97  _late_hyp.Print();
98  std::cout << "TotalHyp:" << std::endl;
99  _total_hyp.Print();
100  std::cout << "PromptFraction: " << _prompt_frac << std::endl;
101 
102 }
void SetHypothesisVectorAndErrorVector(std::vector< float > v, std::vector< float > err=std::vector< float >(0))
size_t GetVectorSize() const
float GetTotalPEsError() const
std::vector< float > _NPEs_ErrorVector
void SetHypothesisAndError(size_t i_opdet, float pe, float err=-999)
TFile f
Definition: plotHisto.C:6
float GetTotalPEs() const
float const & GetHypothesisError(size_t i_opdet) const
void SetTotalHypAndPromptFraction(const FlashHypothesis &total, float frac)
void SetHypothesisError(size_t i_opdet, float err)
std::vector< float > _NPEs_Vector
void SetPromptHypAndPromptFraction(const FlashHypothesis &prompt, float frac)
float const & GetHypothesis(size_t i_opdet) const
void Normalize(float const &totalPE_target)
void SetHypothesis(size_t i_opdet, float pe)