3 namespace single_photon
7 const size_t& nmax,
const size_t& currentiteration,
9 const double& convergencelimit,
10 const double& nsigma,
const double& oldmed)
14 auto const& med =
Median(v);
15 auto const& rms =
RMS(v);
22 if (currentiteration >= nmax)
26 double fracdiff = fabs(med-oldmed) / oldmed;
27 if ( (currentiteration >= nmin) && (fracdiff < convergencelimit) )
35 v.erase( std::remove_if( v.begin(), v.end(),
36 [med,nsigma,rms](
const double&
x) {
return ( (
x < (med-nsigma*rms)) || (
x > (med+nsigma*rms)) ); }),
43 std::vector<double>& dq_trunc_v,
const double& nsigma)
47 int Nneighbor = (int)(
_rad * 3 * 2);
50 dq_trunc_v.reserve( rr_v.size() );
52 int Nmax = dq_v.size()-1;
54 for (
size_t n=0;
n < dq_v.size();
n++) {
57 double rr = rr_v.at(
n);
59 int nmin =
n - Nneighbor;
60 int nmax =
n + Nneighbor;
62 if (nmin < 0) nmin = 0;
63 if (nmax > Nmax) nmax = Nmax;
66 std::vector<double> dq_local_v;
68 for (
int i=nmin; i < nmax; i++) {
70 double dr = rr - rr_v[i];
73 if (dr >
_rad)
continue;
75 dq_local_v.push_back( dq_v[i] );
79 if (dq_local_v.size() == 0 ) {
80 dq_trunc_v.push_back( dq_v.at(
n) );
85 double median =
Median(dq_local_v);
86 double rms =
RMS(dq_local_v);
88 double truncated_dq = 0.;
90 for (
auto const& dq : dq_local_v) {
91 if ( ( dq < (median+rms * nsigma) ) && ( dq > (median-rms * nsigma) ) ){
97 dq_trunc_v.push_back( truncated_dq / npts );
99 if(dq_trunc_v.back() != dq_trunc_v.back()){
100 std::cout<<
"ERROR::TruncMean.cxx || NAN "<<dq_trunc_v.back()<<std::endl;
101 std::cout<<
"truncated_dq: "<<truncated_dq<<std::endl;
103 std::cout<<
"median: "<<median<<std::endl;
116 for (
auto const&
n : v) mean +=
n;
125 if (v.size() == 1)
return v[0];
127 std::vector<double> vcpy = v;
129 std::sort(vcpy.begin(), vcpy.end());
131 double median = vcpy[ vcpy.size() / 2 ];
139 if(v.size()==1)
return v.front();
142 for (
auto const& val : v) avg += val;
145 for (
auto const& val : v) rms += (val-avg)*(val-avg);
146 rms = sqrt( rms / ( v.size() - 1 ) );
150 std::cout<<
"ERROR || TruncMean::RMS || is returning nan."<<std::endl;
151 std::cout<<
"ERROR || TruncMean::RMS || "<<rms<<std::endl;
152 std::cout<<
"ERROR || TruncMean::RMS || Input is of size "<<v.size()<<std::endl;
153 for(
auto const &val : v){
154 std::cout<<
"ERROR || TruncMean::RMS || "<<val<<std::endl;
156 std::cout<<
"ERROR || TruncMean::RMS || Most likely because your radius is too small! "<<v.size()<<std::endl;
process_name opflash particleana ie x
void CalcTruncMeanProfile(const std::vector< double > &rr_v, const std::vector< double > &dq_v, std::vector< double > &dq_trunc_v, const double &nsigma=1)
Given residual range and dq vectors return truncated local dq. Input vectors are assumed to be match ...
double Mean(const std::vector< double > &v)
double CalcIterativeTruncMean(std::vector< double > v, const size_t &nmin, const size_t &nmax, const size_t ¤titeration, const size_t &lmin, const double &convergencelimit, const double &nsigma, const double &oldmed=kINVALID_FLOAT)
Iteratively calculate the truncated mean of a distribution.
double Median(const std::vector< double > &v)
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
double RMS(const std::vector< double > &v)
BEGIN_PROLOG could also be cout