TruncMean.h
Go to the documentation of this file.
1 /**
2  * \file TruncMean.h
3  *
4  * \ingroup 3DMichel
5  *
6  * \brief Class def header for a class TruncMean
7  *
8  * @author david caratelli [davidc@fnal.gov]
9  * Written 08/02/2018.
10  */
11 
12 #ifndef TRUNCMEAN_H
13 #define TRUNCMEAN_H
14 
15 #include <vector>
16 #include <limits>
17 
18 /**
19  \class TruncMean
20  The truncated mean class allows to compute the following quantities
21  1) the truncated mean profile of an ordered vector of values, such as
22  the charge profile along a particle's track.
23  To create such a profile use the function CalcTruncMeanProfile()
24  2) Get the truncated mean value of a distribution. This function
25  iteratively hones in on the truncated mean of a distribution by
26  updating the mean and cutting the tails after each iteration.
27  For this functionality use CalcIterativeTruncMean()
28  doxygen documentation!
29 */
30 
32 
33 class TruncMean{
34 
35  public:
36 
37  /**
38  @brief Given residual range and dq vectors return truncated local dq.
39  Input vectors are assumed to be match pair-wise (nth entry in rr_v
40  corresponds to nth entry in dq_v vector).
41  Input rr_v values are also assumed to be ordered: monotonically increasing
42  or decreasing.
43  For every dq value a truncated linear dq value is calculated as follows:
44  0) all dq values within a rr range set by the class variable _rad are selected.
45  1) the median and rms of these values is calculated.
46  2) the subset of local dq values within the range [median-rms, median+rms] is selected.
47  3) the resulting local truncated dq is the average of this truncated subset.
48  @input std::vector<float> rr_v -> vector of x-axis coordinates (i.e. position for track profile)
49  @input std::vector<float> dq_v -> vector of measured values for which truncated profile is requested
50  (i.e. charge profile of a track)
51  @input std::vector<float> dq_trunc_v -> passed by reference -> output stored here
52  @input float nsigma -> optional parameter, number of sigma to keep around RMS for TM calculation
53  */
54  void CalcTruncMeanProfile(const std::vector<float>& rr_v, const std::vector<float>& dq_v,
55  std::vector<float>& dq_trunc_v, const float& nsigma = 1);
56 
57  /**
58  @brief Iteratively calculate the truncated mean of a distribution
59  @input std::vector<float> v -> vector of values for which truncated mean is asked
60  @input size_t nmin -> minimum number of iterations to converge on truncated mean
61  @input size_t nmax -> maximum number of iterations to converge on truncated mean
62  @input size_t lmin -> minimum number of entries in vector before exiting and returning current value
63  @input size_t currentiteration -> current iteration
64  @input float convergencelimit -> fractional difference between successive iterations
65  under which the iteration is completed, provided nmin iterations have occurred.
66  @input nsigma -> number of sigma around the median value to keep when the distribution is trimmed.
67  */
68  float CalcIterativeTruncMean(std::vector<float> v, const size_t& nmin,
69  const size_t& nmax, const size_t& currentiteration,
70  const size_t& lmin,
71  const float& convergencelimit,
72  const float& nsigma, const float& oldmed = kINVALID_FLOAT);
73 
74  /**
75  @brief Set the smearing radius over which to take hits for truncated mean computaton.
76  */
77  void setRadius(const float& rad) { _rad = rad; }
78 
79  private:
80 
81  float Mean (const std::vector<float>& v);
82  float Median(const std::vector<float>& v);
83  float RMS (const std::vector<float>& v);
84 
85  /**
86  Smearing radius over which charge from neighboring hits is scanned to calculate local
87  truncated mean
88  */
89  double _rad;
90 
91 };
92 
93 #endif
94 /** @} */ // end of doxygen group
static constexpr double rad
Definition: Units.h:164
static const float kINVALID_FLOAT
Definition: TruncMean.h:31
float Median(const std::vector< float > &v)
Definition: TruncMean.cxx:114
void setRadius(const float &rad)
Set the smearing radius over which to take hits for truncated mean computaton.
Definition: TruncMean.h:77
double _rad
Definition: TruncMean.h:89
float RMS(const std::vector< float > &v)
Definition: TruncMean.cxx:128
static int max(int a, int b)
float CalcIterativeTruncMean(std::vector< float > v, const size_t &nmin, const size_t &nmax, const size_t &currentiteration, const size_t &lmin, const float &convergencelimit, const float &nsigma, const float &oldmed=kINVALID_FLOAT)
Iteratively calculate the truncated mean of a distribution std::vector<float> v -> vector of values ...
Definition: TruncMean.cxx:7
float Mean(const std::vector< float > &v)
Definition: TruncMean.cxx:104
void CalcTruncMeanProfile(const std::vector< float > &rr_v, const std::vector< float > &dq_v, std::vector< float > &dq_trunc_v, const float &nsigma=1)
Given residual range and dq vectors return truncated local dq. Input vectors are assumed to be match ...
Definition: TruncMean.cxx:43