LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
util::NormalDistribution Class Reference

#include "PIDAAlg.h"

Public Member Functions

 NormalDistribution ()
 
 NormalDistribution (float, float)
 
float getValue (float)
 

Private Attributes

float fStepSize
 
float fMaxSigma
 
std::vector< float > fValues
 

Detailed Description

Definition at line 30 of file PIDAAlg.h.

Constructor & Destructor Documentation

util::NormalDistribution::NormalDistribution ( )
inline

Definition at line 33 of file PIDAAlg.h.

33 {}
util::NormalDistribution::NormalDistribution ( float  max_sigma,
float  step_size 
)

Definition at line 352 of file PIDAAlg.cxx.

353 {
354 
355  if (step_size == 0) throw "util::NormalDistribution --- Cannot have zero step size!";
356 
357  const size_t vector_size = (size_t)(max_sigma / step_size);
358  fValues.resize(vector_size);
359 
360  const float AMPLITUDE = 1. / std::sqrt(2 * M_PI);
361 
362  float integral = 0;
363  for (size_t i_step = 0; i_step < vector_size; i_step++) {
364  float diff = i_step * step_size;
365  fValues[i_step] = AMPLITUDE * std::exp(-0.5 * diff * diff);
366  integral += fValues[i_step];
367  }
368 
369  for (size_t i_step = 0; i_step < vector_size; i_step++)
370  fValues[i_step] /= (integral * 2);
371 
372  fStepSize = step_size;
373  fMaxSigma = fStepSize * vector_size;
374 }
std::vector< float > fValues
Definition: PIDAAlg.h:41

Member Function Documentation

float util::NormalDistribution::getValue ( float  x)

Definition at line 376 of file PIDAAlg.cxx.

References util::abs().

Referenced by pid::PIDAAlg::createKDE().

377 {
378 
379  x = std::abs(x);
380  if (x > fMaxSigma) return 0;
381 
382  size_t bin_low = x / fStepSize;
383  float remainder = (x - (bin_low * fStepSize)) / fStepSize;
384 
385  return fValues[bin_low] * (1 - remainder) + remainder * fValues[bin_low + 1];
386 }
Float_t x
Definition: compare.C:6
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::vector< float > fValues
Definition: PIDAAlg.h:41

Member Data Documentation

float util::NormalDistribution::fMaxSigma
private

Definition at line 40 of file PIDAAlg.h.

float util::NormalDistribution::fStepSize
private

Definition at line 39 of file PIDAAlg.h.

std::vector<float> util::NormalDistribution::fValues
private

Definition at line 41 of file PIDAAlg.h.


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