32#include "fastjet/tools/GridMedianBackgroundEstimator.hh"
35FASTJET_BEGIN_NAMESPACE
43void GridMedianBackgroundEstimator::set_particles(
const vector<PseudoJet> & particles) {
44 vector<double> scalar_pt(n_tiles(), 0.0);
46 assert(all_tiles_equal_area());
49 _cached_estimate.reset();
50 _cached_estimate.set_has_sigma(
true);
51 _cached_estimate.set_mean_area(mean_tile_area());
58 vector<double> scalar_dt(n_tiles(), 0.0);
60 for (
unsigned i = 0; i < particles.size(); i++) {
61 int j = tile_index(particles[i]);
63 pt = particles[i].pt();
64 dt = particles[i].mt() - pt;
65 if (_rescaling_class == 0){
69 double r = (*_rescaling_class)(particles[i]);
76 sort(scalar_dt.begin(), scalar_dt.end());
80 double p50 = _percentile(scalar_dt, 0.5);
81 _cached_estimate.set_has_rho_m(
true);
82 _cached_estimate.set_rho_m(p50 / mean_tile_area());
83 _cached_estimate.set_sigma_m((p50-_percentile(scalar_dt, (1.0-0.6827)/2.0))/sqrt(mean_tile_area()));
87 for (
unsigned i = 0; i < particles.size(); i++) {
88 int j = tile_index(particles[i]);
90 if (_rescaling_class == 0){
91 scalar_pt[j] += particles[i].pt();
93 scalar_pt[j] += particles[i].pt()/(*_rescaling_class)(particles[i]);
105 if (n_good_tiles() != n_tiles()) {
107 for (
unsigned i = 0; i < scalar_pt.size(); i++) {
108 if (tile_is_good(i)) {
111 std::swap(scalar_pt[i],scalar_pt[newn]);
115 scalar_pt.resize(newn);
121 sort(scalar_pt.begin(), scalar_pt.end());
127 double p50 = _percentile(scalar_pt, 0.5);
128 _cached_estimate.set_rho(p50 / mean_tile_area());
129 _cached_estimate.set_sigma((p50-_percentile(scalar_pt, (1.0-0.6827)/2.0))/sqrt(mean_tile_area()));
131 _cache_available =
true;
141 verify_particles_set();
142 return _cached_estimate;
147 verify_particles_set();
148 if (_rescaling_class == 0)
149 return _cached_estimate;
153 return local_estimate;
158double GridMedianBackgroundEstimator::rho()
const {
159 verify_particles_set();
160 return _cached_estimate.rho();
168double GridMedianBackgroundEstimator::sigma()
const{
169 verify_particles_set();
170 return _cached_estimate.sigma();
179double GridMedianBackgroundEstimator::rho(
const PseudoJet & jet) {
181 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
182 return rescaling*rho();
189double GridMedianBackgroundEstimator::sigma(
const PseudoJet & jet){
191 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
192 return rescaling*sigma();
197double GridMedianBackgroundEstimator::rho_m()
const {
198 if (! _enable_rho_m){
199 throw Error(
"GridMediamBackgroundEstimator: rho_m requested but rho_m calculation has been disabled.");
201 verify_particles_set();
202 return _cached_estimate.rho_m();
210double GridMedianBackgroundEstimator::sigma_m()
const{
211 if (! _enable_rho_m){
212 throw Error(
"GridMediamBackgroundEstimator: sigma_m requested but rho_m/sigma_m calculation has been disabled.");
214 verify_particles_set();
215 return _cached_estimate.sigma_m();
221double GridMedianBackgroundEstimator::rho_m(
const PseudoJet & jet) {
223 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
224 return rescaling*rho_m();
231double GridMedianBackgroundEstimator::sigma_m(
const PseudoJet & jet){
233 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
234 return rescaling*sigma_m();
239void GridMedianBackgroundEstimator::verify_particles_set()
const {
240 if (!_cache_available)
throw Error(
"GridMedianBackgroundEstimator::rho() or sigma() called without particles having been set");
247string GridMedianBackgroundEstimator::description()
const {
249 desc <<
"GridMedianBackgroundEstimator, with " << RectangularGrid::description();
273 if (_cache_available)
274 _warning_rescaling.warn(
"GridMedianBackgroundEstimator::set_rescaling_class(): trying to set the rescaling class when there are already particles that have been set is dangerous: the rescaling will not affect the already existing particles resulting in mis-estimation of rho. You need to call set_particles() again before proceeding with any background estimation.");
276 BackgroundEstimatorBase::set_rescaling_class(rescaling_class_in);
/// a class that holds the result of the calculation
void apply_rescaling_factor(double rescaling_factor)
apply a rescaling factor (to rho, rho_m, sigma, sigma_m)
base class corresponding to errors that can be thrown by FastJet
Class to contain pseudojets, including minimal information of use to jet-clustering routines.