32 #include "fastjet/tools/GridMedianBackgroundEstimator.hh"
35 FASTJET_BEGIN_NAMESPACE
43 void GridMedianBackgroundEstimator::set_particles(
const vector<PseudoJet> & particles) {
44 vector<double> scalar_pt(n_tiles(), 0.0);
46 #ifdef FASTJET_GMBGE_USEFJGRID
47 assert(all_tiles_equal_area());
56 vector<double> scalar_dt(n_tiles(), 0.0);
58 for (
unsigned i = 0; i < particles.size(); i++) {
59 int j = tile_index(particles[i]);
61 pt = particles[i].pt();
62 dt = particles[i].mt() - pt;
63 if (_rescaling_class == 0){
67 double r = (*_rescaling_class)(particles[i]);
74 sort(scalar_dt.begin(), scalar_dt.end());
78 double p50 = _percentile(scalar_dt, 0.5);
79 _rho_m = p50 / mean_tile_area();
80 _sigma_m = (p50-_percentile(scalar_dt, (1.0-0.6827)/2.0))/sqrt(mean_tile_area());
84 for (
unsigned i = 0; i < particles.size(); i++) {
85 int j = tile_index(particles[i]);
87 if (_rescaling_class == 0){
88 scalar_pt[j] += particles[i].pt();
90 scalar_pt[j] += particles[i].pt()/(*_rescaling_class)(particles[i]);
102 if (n_good_tiles() != n_tiles()) {
104 for (
unsigned i = 0; i < scalar_pt.size(); i++) {
105 if (tile_is_good(i)) {
108 std::swap(scalar_pt[i],scalar_pt[newn]);
112 scalar_pt.resize(newn);
118 sort(scalar_pt.begin(), scalar_pt.end());
124 double p50 = _percentile(scalar_pt, 0.5);
125 _rho = p50 / mean_tile_area();
126 _sigma = (p50-_percentile(scalar_pt, (1.0-0.6827)/2.0))/sqrt(mean_tile_area());
128 _has_particles =
true;
136 double GridMedianBackgroundEstimator::rho()
const {
137 verify_particles_set();
146 double GridMedianBackgroundEstimator::sigma()
const{
147 verify_particles_set();
157 double GridMedianBackgroundEstimator::rho(
const PseudoJet & jet) {
159 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
160 return rescaling*rho();
167 double GridMedianBackgroundEstimator::sigma(
const PseudoJet & jet){
169 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
170 return rescaling*
sigma();
175 double GridMedianBackgroundEstimator::rho_m()
const {
176 if (! _enable_rho_m){
177 throw Error(
"GridMediamBackgroundEstimator: rho_m requested but rho_m calculation has been disabled.");
179 verify_particles_set();
188 double GridMedianBackgroundEstimator::sigma_m()
const{
189 if (! _enable_rho_m){
190 throw Error(
"GridMediamBackgroundEstimator: sigma_m requested but rho_m/sigma_m calculation has been disabled.");
192 verify_particles_set();
199 double GridMedianBackgroundEstimator::rho_m(
const PseudoJet & jet) {
201 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
202 return rescaling*rho_m();
209 double GridMedianBackgroundEstimator::sigma_m(
const PseudoJet & jet){
211 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
212 return rescaling*sigma_m();
217 void GridMedianBackgroundEstimator::verify_particles_set()
const {
218 if (!_has_particles)
throw Error(
"GridMedianBackgroundEstimator::rho() or sigma() called without particles having been set");
225 string GridMedianBackgroundEstimator::description()
const {
227 #ifdef FASTJET_GMBGE_USEFJGRID
228 desc <<
"GridMedianBackgroundEstimator, with " << RectangularGrid::description();
230 desc <<
"GridMedianBackgroundEstimator, with grid extension |y| < " << _ymax
231 <<
", and grid cells of size dy x dphi = " << _dy <<
" x " << _dphi
232 <<
" (requested size = " << _requested_grid_spacing <<
")";
258 _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.");
260 BackgroundEstimatorBase::set_rescaling_class(rescaling_class_in);
264 #ifndef FASTJET_GMBGE_USEFJGRID
269 void GridMedianBackgroundEstimator::setup_grid() {
274 assert(_ymax>0 && _ymax - _ymin >= _requested_grid_spacing);
278 double ny_double = (_ymax-_ymin) / _requested_grid_spacing;
279 _ny = int(ny_double+0.5);
280 _dy = (_ymax-_ymin) / _ny;
282 _nphi = int (twopi / _requested_grid_spacing + 0.5);
283 _dphi = twopi / _nphi;
286 assert(_ny >= 1 && _nphi >= 1);
288 _ntotal = _nphi * _ny;
290 _tile_area = _dy * _dphi;
296 int GridMedianBackgroundEstimator::tile_index(
const PseudoJet & p)
const {
307 int iy = int(floor( (p.rap() - _ymin) / _dy ));
308 if (iy < 0 || iy >= _ny)
return -1;
310 int iphi = int( p.phi()/_dphi );
311 assert(iphi >= 0 && iphi <= _nphi);
312 if (iphi == _nphi) iphi = 0;
314 int index_res = iy*_nphi + iphi;
315 assert (index_res >= 0 && index_res < _ny*_nphi);
318 #endif // FASTJET_GMBGE_USEFJGRID
322 FASTJET_END_NAMESPACE
base class corresponding to errors that can be thrown by FastJet
Class to contain pseudojets, including minimal information of use to jet-clustering routines...