LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LArDiscreteProbabilityHelper.h
Go to the documentation of this file.
1 
8 #ifndef LAR_DISCRETE_PROBABILITY_HELPER_HELPER_H
9 #define LAR_DISCRETE_PROBABILITY_HELPER_HELPER_H 1
10 
12 
13 #include <algorithm>
14 #include <random>
15 
16 namespace lar_content
17 {
18 
23 {
24 public:
35  template <typename T>
37  const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations);
38 
49  template <typename T>
51  const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit);
52 
61  template <typename T>
62  static float CalculateCorrelationCoefficient(const T &t1, const T &t2);
63 
71  template <typename T>
72  static float CalculateMean(const T &t);
73 
74 private:
83  template <typename T>
84  static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator);
85 
94  template <typename T>
95  static std::vector<T> MakeRandomisedSample(const std::vector<T> &t, std::mt19937 &randomNumberGenerator);
96 
104  template <typename T>
105  static unsigned int GetSize(const T &t);
106 
114  template <typename T>
115  static unsigned int GetSize(const std::vector<T> &t);
116 
125  template <typename T>
126  static float GetElement(const T &t, const unsigned int index);
127 
136  template <typename T>
137  static float GetElement(const std::vector<T> &t, const unsigned int index);
138 };
139 
140 //------------------------------------------------------------------------------------------------------------------------------------------
141 
142 template <typename T>
143 inline std::vector<T> LArDiscreteProbabilityHelper::MakeRandomisedSample(const std::vector<T> &t, std::mt19937 &randomNumberGenerator)
144 {
145  std::vector<T> randomisedVector(t);
146  std::shuffle(randomisedVector.begin(), randomisedVector.end(), randomNumberGenerator);
147 
148  return randomisedVector;
149 }
150 
151 template <>
153 {
154  return DiscreteProbabilityVector(t, randomNumberGenerator);
155 }
156 
157 //------------------------------------------------------------------------------------------------------------------------------------------
158 
159 template <typename T>
160 inline unsigned int LArDiscreteProbabilityHelper::GetSize(const std::vector<T> &t)
161 {
162  return t.size();
163 }
164 
165 template <>
167 {
168  return t.GetSize();
169 }
170 
171 //------------------------------------------------------------------------------------------------------------------------------------------
172 
173 template <typename T>
174 inline float LArDiscreteProbabilityHelper::GetElement(const std::vector<T> &t, const unsigned int index)
175 {
176  return static_cast<float>(t.at(index));
177 }
178 
179 template <>
180 inline float LArDiscreteProbabilityHelper::GetElement(const DiscreteProbabilityVector &t, const unsigned int index)
181 {
182  return static_cast<float>(t.GetProbability(index));
183 }
184 
185 } // namespace lar_content
186 
187 #endif // #ifndef LAR_DISCRETE_PROBABILITY_HELPER_H
TTree * t1
Definition: plottest35.C:26
static float CalculateCorrelationCoefficientPValueFromPermutationTest(const T &t1, const T &t2, std::mt19937 &randomNumberGenerator, const unsigned int nPermutations)
Calculate P value for measured correlation coefficient between two datasets via a permutation test...
static float CalculateCorrelationCoefficientPValueFromStudentTDistribution(const T &t1, const T &t2, const unsigned int nIntegrationSteps, const float upperLimit)
Calculate P value for measured correlation coefficient between two datasets via a integrating the stu...
static float CalculateCorrelationCoefficient(const T &t1, const T &t2)
Calculate the correlation coefficient between two datasets.
float GetProbability(const unsigned int index) const
Get the probability value of the element in the vector.
Header file for the lar discrete probability vector class.
static T MakeRandomisedSample(const T &t, std::mt19937 &randomNumberGenerator)
Make a randomised copy of a dataset.
static unsigned int GetSize(const T &t)
Get the size the size of a dataset.
static float CalculateMean(const T &t)
Calculate the mean of a dataset.
TTree * t2
Definition: plottest35.C:36
static float GetElement(const T &t, const unsigned int index)
Get an element in a dataset.
unsigned int GetSize() const
Get the size of the probability vector.