10 const size_t& currentiteration,
12 const float& convergencelimit,
18 auto const& med =
Median(v);
19 auto const& rms =
RMS(v);
22 if (v.size() < lmin)
return mean;
25 if (currentiteration >= nmax)
return mean;
28 float fracdiff = fabs(med - oldmed) / oldmed;
29 if ((currentiteration >= nmin) && (fracdiff < convergencelimit))
return mean;
36 v.erase(std::remove_if(v.begin(),
38 [med, nsigma, rms](
const float&
x) {
39 return ((
x < (med - nsigma * rms)) || (
x > (med + nsigma * rms)));
44 v, nmin, nmax, lmin, currentiteration + 1, convergencelimit, nsigma, med);
48 const std::vector<float>& dq_v,
49 std::vector<float>& dq_trunc_v,
54 int Nneighbor = (int)(
_rad * 3 * 2);
57 dq_trunc_v.reserve(rr_v.size());
59 int Nmax = dq_v.size() - 1;
61 for (
size_t n = 0;
n < dq_v.size();
n++) {
64 float rr = rr_v.at(
n);
66 int nmin =
n - Nneighbor;
67 int nmax =
n + Nneighbor;
69 if (nmin < 0) nmin = 0;
70 if (nmax > Nmax) nmax = Nmax;
73 std::vector<float> dq_local_v;
75 for (
int i = nmin; i < nmax; i++) {
77 float dr = rr - rr_v[i];
80 if (dr >
_rad)
continue;
82 dq_local_v.push_back(dq_v[i]);
86 if (dq_local_v.size() == 0) {
87 dq_trunc_v.push_back(dq_v.at(
n));
92 float median =
Median(dq_local_v);
93 float rms =
RMS(dq_local_v);
95 float truncated_dq = 0.;
97 for (
auto const& dq : dq_local_v) {
98 if ((dq < (median + rms * nsigma)) && (dq > (median - rms * nsigma))) {
104 dq_trunc_v.push_back(truncated_dq / npts);
114 for (
auto const&
n : v)
124 if (v.size() == 1)
return v[0];
126 std::vector<float> vcpy = v;
128 std::sort(vcpy.begin(), vcpy.end());
130 float median = vcpy[vcpy.size() / 2];
139 for (
auto const& val : v)
143 for (
auto const& val : v)
144 rms += (val - avg) * (val - avg);
145 rms = sqrt(rms / (v.size() - 1));
Class def header for a class TruncMean.
float Median(const std::vector< float > &v)
float RMS(const std::vector< float > &v)
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
float CalcIterativeTruncMean(std::vector< float > v, const size_t &nmin, const size_t &nmax, const size_t ¤titeration, 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 ...
float Mean(const std::vector< float > &v)
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 ...