LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
opdet::FlashUtilities Class Reference

#include "FlashUtilities.h"

Public Member Functions

 FlashUtilities ()
 
float CompareByError (const FlashHypothesis &, const std::vector< float > &, std::vector< float > &)
 
float CompareByFraction (const FlashHypothesis &, const std::vector< float > &, std::vector< float > &)
 
float CompareByFraction (const std::vector< float > &, const std::vector< float > &, std::vector< float > &)
 
void GetPosition (const std::vector< float > &, const std::vector< float > &, float &, float &)
 
void GetPosition (const std::vector< float > &, const std::vector< float > &, double &, double &)
 

Detailed Description

Definition at line 22 of file FlashUtilities.h.

Constructor & Destructor Documentation

opdet::FlashUtilities::FlashUtilities ( )
inline

Definition at line 25 of file FlashUtilities.h.

References CompareByError(), CompareByFraction(), and GetPosition().

25 {}

Member Function Documentation

float opdet::FlashUtilities::CompareByError ( const FlashHypothesis fh,
const std::vector< float > &  compare_vector,
std::vector< float > &  result_vector 
)

Title: FlashUtilities Class Author: Wes Ketchum (wketc.nosp@m.hum@.nosp@m.lanl..nosp@m.gov)

Description: Class that contains utility functions for flash and flash hypotheses: — compare a flash hypothesis to a truth or reco vector — get an extent of a flash (central point, width) These classes should operate using simple objects, and will need other classes/functions to fill those vectors properly.

Definition at line 21 of file FlashUtilities.cxx.

References util::abs(), opdet::FlashHypothesis::GetHypothesisErrorVector(), opdet::FlashHypothesis::GetHypothesisVector(), opdet::FlashHypothesis::GetTotalPEs(), opdet::FlashHypothesis::GetTotalPEsError(), and opdet::FlashHypothesis::GetVectorSize().

Referenced by opdet::FlashHypothesisComparison::FillComparisonInfo(), and FlashUtilities().

24 {
25  if (compare_vector.size() != fh.GetVectorSize())
26  throw std::runtime_error("ERROR in FlashUtilities Compare: Mismatching vector sizes.");
27 
28  result_vector.resize(fh.GetVectorSize());
29 
30  float result_total = 0;
31 
32  std::vector<float> const& NPEs_Vector(fh.GetHypothesisVector());
33  std::vector<float> const& NPEs_ErrorVector(fh.GetHypothesisErrorVector());
34 
35  for (size_t i = 0; i < fh.GetVectorSize(); i++) {
36  result_total += compare_vector[i];
37  float diff = NPEs_Vector[i] - compare_vector[i];
38  if (std::abs(diff) < std::numeric_limits<float>::epsilon())
39  result_vector[i] = 0;
40  else if (NPEs_ErrorVector[i] < std::numeric_limits<float>::epsilon())
41  result_vector[i] = diff / std::numeric_limits<float>::epsilon();
42  else
43  result_vector[i] = diff / NPEs_ErrorVector[i];
44  }
45 
46  float total_error = fh.GetTotalPEsError();
47  float total_diff = fh.GetTotalPEs() - result_total;
48  if (std::abs(total_diff) < std::numeric_limits<float>::epsilon())
49  result_total = 0;
50  else if (total_error < std::numeric_limits<float>::epsilon())
51  result_total = total_diff / std::numeric_limits<float>::epsilon();
52  else
53  result_total = total_diff / total_error;
54 
55  return result_total;
56 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
float opdet::FlashUtilities::CompareByFraction ( const FlashHypothesis fh,
const std::vector< float > &  compare_vector,
std::vector< float > &  result_vector 
)

Definition at line 58 of file FlashUtilities.cxx.

References opdet::FlashHypothesis::GetHypothesisVector().

Referenced by FlashUtilities().

61 {
62  return CompareByFraction(fh.GetHypothesisVector(), compare_vector, result_vector);
63 }
float CompareByFraction(const FlashHypothesis &, const std::vector< float > &, std::vector< float > &)
float opdet::FlashUtilities::CompareByFraction ( const std::vector< float > &  NPEs_Vector,
const std::vector< float > &  compare_vector,
std::vector< float > &  result_vector 
)

Definition at line 65 of file FlashUtilities.cxx.

References util::abs().

68 {
69  if (compare_vector.size() != NPEs_Vector.size())
70  throw std::runtime_error("ERROR in FlashUtilities Compare: Mismatching vector sizes.");
71 
72  result_vector.resize(NPEs_Vector.size());
73 
74  float total_comp = 0;
75  float total_hyp = 0;
76  for (size_t i = 0; i < NPEs_Vector.size(); i++) {
77  total_comp += compare_vector[i];
78  total_hyp += NPEs_Vector[i];
79  float diff = NPEs_Vector[i] - compare_vector[i];
80  if (std::abs(diff) < std::numeric_limits<float>::epsilon())
81  result_vector[i] = 0;
82  else if (compare_vector[i] < std::numeric_limits<float>::epsilon())
83  result_vector[i] = diff / std::numeric_limits<float>::epsilon();
84  else
85  result_vector[i] = diff / compare_vector[i];
86  }
87 
88  float result_total = 0.0;
89  float total_diff = total_hyp - total_comp;
90  if (std::abs(total_diff) < std::numeric_limits<float>::epsilon())
91  result_total = 0;
92  else if (total_comp < std::numeric_limits<float>::epsilon())
93  result_total = total_diff / std::numeric_limits<float>::epsilon();
94  else
95  result_total = total_diff / total_comp;
96 
97  return result_total;
98 }
constexpr auto abs(T v)
Returns the absolute value of the argument.
void opdet::FlashUtilities::GetPosition ( const std::vector< float > &  pe_vector,
const std::vector< float > &  pos_vector,
float &  mean,
float &  rms 
)

Definition at line 100 of file FlashUtilities.cxx.

References pmtana::mean(), and sum.

Referenced by opdet::FlashHypothesisComparison::FillFlashHypothesisInfo(), opdet::FlashHypothesisComparison::FillSimPhotonCounterInfo(), FlashUtilities(), and GetPosition().

104 {
105  if (pe_vector.size() != pos_vector.size())
106  throw std::runtime_error("ERROR in FlashUtilities GetPosition: Mismatchin vector sizes.");
107 
108  float sum = std::accumulate(pe_vector.begin(), pe_vector.end(), 0.0);
109 
110  if (sum < std::numeric_limits<float>::epsilon()) {
111  mean = 0;
112  rms = 0;
113  return;
114  }
115 
116  mean = std::inner_product(pe_vector.begin(), pe_vector.end(), pos_vector.begin(), 0.0) / sum;
117 
118  rms = 0;
119  for (size_t i = 0; i < pe_vector.size(); i++)
120  rms += pe_vector[i] * (pos_vector[i] - mean) * (pos_vector[i] - mean);
121 
122  rms = std::sqrt(rms) / sum;
123 }
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
Double_t sum
Definition: plot.C:31
void opdet::FlashUtilities::GetPosition ( const std::vector< float > &  pe_vector,
const std::vector< float > &  pos_vector,
double &  mean,
double &  rms 
)

Definition at line 125 of file FlashUtilities.cxx.

References GetPosition().

129 {
130  float fmean, frms;
131  GetPosition(pe_vector, pos_vector, fmean, frms);
132  mean = double(fmean);
133  rms = double(frms);
134 }
void GetPosition(const std::vector< float > &, const std::vector< float > &, float &, float &)
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13

The documentation for this class was generated from the following files: