32 #include "fastjet/tools/BackgroundEstimatorBase.hh"
36 FASTJET_BEGIN_NAMESPACE
38 LimitedWarning BackgroundEstimatorBase::_warnings_empty_area;
48 void BackgroundEstimatorBase::_median_and_stddev(
const vector<double> & quantity_vector,
51 double & stand_dev_if_gaussian,
52 bool do_fj2_calculation)
const {
57 if (quantity_vector.size() == 0) {
59 stand_dev_if_gaussian = 0;
63 vector<double> sorted_quantity_vector = quantity_vector;
64 sort(sorted_quantity_vector.begin(), sorted_quantity_vector.end());
68 int n_jets_used = sorted_quantity_vector.size();
69 if (n_empty_jets < -n_jets_used/4.0)
70 _warnings_empty_area.warn(
"BackgroundEstimatorBase::_median_and_stddev(...): the estimated empty area is suspiciously large and negative and may lead to an over-estimation of rho. This may be due to (i) a rare statistical fluctuation or (ii) too small a range used to estimate the background properties.");
74 double posn[2] = {0.5, (1.0-0.6827)/2.0};
76 for (
int i = 0; i < 2; i++) {
77 res[i] = _percentile(sorted_quantity_vector, posn[i], n_empty_jets,
82 stand_dev_if_gaussian = res[0] - res[1];
95 double BackgroundEstimatorBase::_percentile(
const vector<double> & sorted_quantities,
96 const double percentile,
98 const bool do_fj2_calculation
100 assert(percentile >= 0.0 && percentile <= 1.0);
102 int quantities_size = sorted_quantities.size();
103 if (quantities_size == 0)
return 0;
105 double total_njets = quantities_size + nempty;
106 double percentile_pos;
107 if (do_fj2_calculation) {
108 percentile_pos = (total_njets-1)*percentile - nempty;
110 percentile_pos = (total_njets)*percentile - nempty - 0.5;
114 if (percentile_pos >= 0 && quantities_size > 1) {
115 int int_percentile_pos = int(percentile_pos);
118 if (int_percentile_pos+1 > quantities_size-1){
119 int_percentile_pos = quantities_size-2;
120 percentile_pos = quantities_size-1;
124 sorted_quantities[int_percentile_pos] * (int_percentile_pos+1-percentile_pos)
125 + sorted_quantities[int_percentile_pos+1] * (percentile_pos - int_percentile_pos);
128 }
else if (percentile_pos > -0.5 && quantities_size >= 1
129 && !do_fj2_calculation) {
133 result = sorted_quantities[0];
143 FASTJET_END_NAMESPACE