8 const size_t& nmax,
const size_t& currentiteration,
10 const float& convergencelimit,
11 const float& nsigma,
const float& oldmed)
15 auto const& med =
Median(v);
16 auto const& rms =
RMS(v);
23 if (currentiteration >= nmax)
27 float fracdiff = fabs(med-oldmed) / oldmed;
28 if ( (currentiteration >= nmin) && (fracdiff < convergencelimit) )
36 v.erase( std::remove_if( v.begin(), v.end(),
37 [med,nsigma,rms](
const float&
x) {
return ( (
x < (med-nsigma*rms)) || (
x > (med+nsigma*rms)) ); }),
44 std::vector<float>& dq_trunc_v,
const float& nsigma)
48 int Nneighbor = (int)(
_rad * 3 * 2);
51 dq_trunc_v.reserve( rr_v.size() );
53 int Nmax = dq_v.size()-1;
55 for (
size_t n=0;
n < dq_v.size();
n++) {
58 float rr = rr_v.at(
n);
60 int nmin =
n - Nneighbor;
61 int nmax =
n + Nneighbor;
63 if (nmin < 0) nmin = 0;
64 if (nmax > Nmax) nmax = Nmax;
67 std::vector<float> dq_local_v;
69 for (
int i=nmin; i < nmax; i++) {
71 float dr = rr - rr_v[i];
74 if (dr >
_rad)
continue;
76 dq_local_v.push_back( dq_v[i] );
80 if (dq_local_v.size() == 0) {
81 dq_trunc_v.push_back( dq_v.at(
n) );
86 float median =
Median(dq_local_v);
87 float rms =
RMS(dq_local_v);
89 float truncated_dq = 0.;
91 for (
auto const& dq : dq_local_v) {
92 if ( ( dq < (median+rms * nsigma) ) && ( dq > (median-rms * nsigma) ) ){
98 dq_trunc_v.push_back( truncated_dq / npts );
108 for (
auto const&
n : v) mean +=
n;
117 if (v.size() == 1)
return v[0];
119 std::vector<float> vcpy = v;
121 std::sort(vcpy.begin(), vcpy.end());
123 float median = vcpy[ vcpy.size() / 2 ];
132 for (
auto const& val : v) avg += val;
135 for (
auto const& val : v) rms += (val-avg)*(val-avg);
136 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 ...