#include <TruncMean.h>
|
| TruncMean () |
| Default constructor. More...
|
|
| ~TruncMean () |
| Default destructor. More...
|
|
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 pair-wise (nth entry in rr_v corresponds to nth entry in dq_v vector). Input rr_v values are also assumed to be ordered: monotonically increasing or decreasing. For every dq value a truncated linear dq value is calculated as follows: 0) all dq values within a rr range set by the class variable _rad are selected. 1) the median and rms of these values is calculated. 2) the subset of local dq values within the range [median-rms, median+rms] is selected. 3) the resulting local truncated dq is the average of this truncated subset. std::vector<double> rr_v -> vector of x-axis coordinates (i.e. position for track profile) std::vector<double> dq_v -> vector of measured values for which truncated profile is requested (i.e. charge profile of a track) std::vector<double> dq_trunc_v -> passed by reference -> output stored here double nsigma -> optional parameter, number of sigma to keep around RMS for TM calculation. More...
|
|
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. More...
|
|
void | setRadius (const double &rad) |
| Set the smearing radius over which to take hits for truncated mean computaton. More...
|
|
|
double | Mean (const std::vector< double > &v) |
|
double | Median (const std::vector< double > &v) |
|
double | RMS (const std::vector< double > &v) |
|
single_photon::TruncMean::TruncMean |
( |
| ) |
|
|
inline |
single_photon::TruncMean::~TruncMean |
( |
| ) |
|
|
inline |
double TruncMean::CalcIterativeTruncMean |
( |
std::vector< double > |
v, |
|
|
const size_t & |
nmin, |
|
|
const size_t & |
nmax, |
|
|
const size_t & |
currentiteration, |
|
|
const size_t & |
lmin, |
|
|
const double & |
convergencelimit, |
|
|
const double & |
nsigma, |
|
|
const double & |
oldmed = kINVALID_FLOAT |
|
) |
| |
Iteratively calculate the truncated mean of a distribution.
: mean is returned if vecter's size is too small, or reach the max iteration, or median has converged std::vector<double> v -> vector of values for which truncated mean is asked size_t nmin -> minimum number of iterations to converge on truncated mean size_t nmax -> maximum number of iterations to converge on truncated mean size_t lmin -> minimum number of entries in vector before exiting and returning current value size_t currentiteration -> current iteration double convergencelimit -> fractional difference between successive iterations under which the iteration is completed, provided nmin iterations have occurred. nsigma -> number of sigma around the median value to keep when the distribution is trimmed.
Definition at line 6 of file sbncode/sbncode/SinglePhotonAnalysis/Libraries/TruncMean.cxx.
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)) ); }),
process_name opflash particleana ie x
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)
void TruncMean::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 pair-wise (nth entry in rr_v corresponds to nth entry in dq_v vector). Input rr_v values are also assumed to be ordered: monotonically increasing or decreasing. For every dq value a truncated linear dq value is calculated as follows: 0) all dq values within a rr range set by the class variable _rad are selected. 1) the median and rms of these values is calculated. 2) the subset of local dq values within the range [median-rms, median+rms] is selected. 3) the resulting local truncated dq is the average of this truncated subset. std::vector<double> rr_v -> vector of x-axis coordinates (i.e. position for track profile) std::vector<double> dq_v -> vector of measured values for which truncated profile is requested (i.e. charge profile of a track) std::vector<double> dq_trunc_v -> passed by reference -> output stored here double nsigma -> optional parameter, number of sigma to keep around RMS for TM calculation.
Definition at line 42 of file sbncode/sbncode/SinglePhotonAnalysis/Libraries/TruncMean.cxx.
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;
double Median(const std::vector< double > &v)
double RMS(const std::vector< double > &v)
BEGIN_PROLOG could also be cout
double TruncMean::Mean |
( |
const std::vector< double > & |
v | ) |
|
|
private |
double TruncMean::Median |
( |
const std::vector< double > & |
v | ) |
|
|
private |
double TruncMean::RMS |
( |
const std::vector< double > & |
v | ) |
|
|
private |
Definition at line 136 of file sbncode/sbncode/SinglePhotonAnalysis/Libraries/TruncMean.cxx.
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;
BEGIN_PROLOG could also be cout
void single_photon::TruncMean::setRadius |
( |
const double & |
rad | ) |
|
|
inline |
double single_photon::TruncMean::_rad |
|
private |
The documentation for this class was generated from the following files: