LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
FlashHypothesis.cxx
Go to the documentation of this file.
1 #include "FlashHypothesis.h"
2 
3 #include <iostream>
4 #include <limits>
5 
7  std::vector<float> err)
8 {
9  if (err.size() != 0 && err.size() != v.size())
10  throw std::runtime_error("ERROR in FlashHypothesisVectorSetter: Vector sizes not equal");
11 
12  _NPEs_Vector = v;
13  if (err.size() == 0) {
14  _NPEs_Vector = v;
15  _NPEs_ErrorVector.resize(v.size());
16  for (size_t i = 0; i < _NPEs_Vector.size(); i++)
17  _NPEs_ErrorVector[i] = std::sqrt(_NPEs_Vector[i]);
18  }
19  else
20  _NPEs_ErrorVector = err;
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)
27  SetHypothesisError(i_opdet, err);
28  else
29  SetHypothesisError(i_opdet, std::sqrt(pe));
30 }
31 
32 void opdet::FlashHypothesis::Normalize(float const& totalPE_target)
33 {
34 
35  if (GetTotalPEs() < std::numeric_limits<float>::epsilon()) return;
36 
37  const float PE_ratio = totalPE_target / GetTotalPEs();
38  for (size_t i_opdet = 0; i_opdet < _NPEs_Vector.size(); i_opdet++) {
39  _NPEs_Vector[i_opdet] *= PE_ratio;
40  _NPEs_ErrorVector[i_opdet] = std::sqrt(_NPEs_Vector[i_opdet]);
41  }
42 }
43 
45 {
46  std::cout << "TotalPEs: " << GetTotalPEs() << " +/- " << GetTotalPEsError() << std::endl;
47  std::cout << "Vector size: " << GetVectorSize() << std::endl;
48  for (size_t i = 0; i < GetVectorSize(); i++)
49  std::cout << "\t" << i << ": " << GetHypothesis(i) << " +/- " << GetHypothesisError(i)
50  << std::endl;
51 }
52 
54  float frac)
55 {
56  CheckFrac(frac);
57  _total_hyp = total;
58  _prompt_frac = frac;
59  _prompt_hyp = total;
60  _prompt_hyp.Normalize(frac * total.GetTotalPEs());
61  _late_hyp = total;
62  _late_hyp.Normalize((1. - frac) * total.GetTotalPEs());
63 }
64 
66  float frac)
67 {
68  CheckFrac(frac);
69  _prompt_hyp = prompt;
70  _prompt_frac = frac;
71  _late_hyp = prompt;
72  _late_hyp.Normalize((1 / frac - 1.) * prompt.GetTotalPEs());
73  _total_hyp = _prompt_hyp + _late_hyp;
74 }
75 
77 {
78  _prompt_hyp.Normalize(totalPE_target * _prompt_frac);
79  _late_hyp.Normalize(totalPE_target * (1. - _prompt_frac));
80  UpdateTotalHyp();
81 }
82 
84 {
85  if (std::abs(f - 0.0) < std::numeric_limits<float>::epsilon() ||
86  std::abs(f - 1.0) < std::numeric_limits<float>::epsilon() || (f > 0.0 && f < 1.0))
87  return;
88 
89  throw std::runtime_error(
90  "ERROR in FlashHypothesisCollection: Input fraction is not in valid range.");
91 }
92 
94 {
95  _total_hyp = _prompt_hyp + _late_hyp;
96  const float total_pe = _total_hyp.GetTotalPEs();
97  if (total_pe > std::numeric_limits<float>::epsilon())
98  _prompt_frac = _prompt_hyp.GetTotalPEs() / total_pe;
99  else
100  _prompt_frac = 1.;
101 }
102 
104 {
105  std::cout << "PromptHyp:" << std::endl;
106  _prompt_hyp.Print();
107  std::cout << "LateHyp:" << std::endl;
108  _late_hyp.Print();
109  std::cout << "TotalHyp:" << std::endl;
110  _total_hyp.Print();
111  std::cout << "PromptFraction: " << _prompt_frac << std::endl;
112 }
void SetHypothesisVectorAndErrorVector(std::vector< float > v, std::vector< float > err=std::vector< float >(0))
size_t GetVectorSize() const
float GetTotalPEsError() const
constexpr auto abs(T v)
Returns the absolute value of the argument.
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)