Fork me on GitHub

Ignore:
Timestamp:
Sep 3, 2014, 3:18:54 PM (10 years ago)
Author:
Pavel Demin <demin@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
be2222c
Parents:
5b5a56b
Message:

upgrade FastJet to version 3.1.0-beta.1, upgrade Nsubjettiness to version 2.1.0, add SoftKiller version 1.0.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/tools/GridMedianBackgroundEstimator.cc

    r5b5a56b r35cdc46  
    1 //STARTHEADER
    2 // $Id$
    3 //
    4 // Copyright (c) 2005-2011, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     1//FJSTARTHEADER
     2// $Id: GridMedianBackgroundEstimator.cc 3555 2014-08-11 09:56:35Z salam $
     3//
     4// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
    55//
    66//----------------------------------------------------------------------
     
    1313//
    1414//  The algorithms that underlie FastJet have required considerable
    15 //  development and are described in hep-ph/0512210. If you use
     15//  development. They are described in the original FastJet paper,
     16//  hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
    1617//  FastJet as part of work towards a scientific publication, please
    17 //  include a citation to the FastJet paper.
     18//  quote the version you use and include a citation to the manual and
     19//  optionally also to hep-ph/0512210.
    1820//
    1921//  FastJet is distributed in the hope that it will be useful,
     
    2527//  along with FastJet. If not, see <http://www.gnu.org/licenses/>.
    2628//----------------------------------------------------------------------
    27 //ENDHEADER
     29//FJENDHEADER
    2830
    2931
     
    3234
    3335FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
     36
    3437
    3538//----------------------------------------------------------------------
     
    3942// of the specified particles.
    4043void GridMedianBackgroundEstimator::set_particles(const vector<PseudoJet> & particles) {
    41   fill(_scalar_pt.begin(), _scalar_pt.end(), 0.0);
    42   for (unsigned i = 0; i < particles.size(); i++) {
    43     int j = igrid(particles[i]);
    44     if (j >= 0){
    45       if (_rescaling_class == 0)
    46         _scalar_pt[j] += particles[i].perp();
    47       else
    48         _scalar_pt[j] += particles[i].perp()/(*_rescaling_class)(particles[i]);
     44  vector<double> scalar_pt(n_tiles(), 0.0);
     45
     46#ifdef FASTJET_GMBGE_USEFJGRID
     47  assert(all_tiles_equal_area());
     48  //assert(n_good_tiles() == n_tiles()); // not needed now that we have an implementation
     49#endif
     50
     51  // check if we need to compute only rho or both rho and rho_m
     52  if (_enable_rho_m){
     53    // both rho and rho_m
     54    //
     55    // this requires a few other variables
     56    vector<double> scalar_dt(n_tiles(), 0.0);
     57    double pt, dt;
     58    for (unsigned i = 0; i < particles.size(); i++) {
     59      int j = tile_index(particles[i]);
     60      if (j >= 0){
     61        pt = particles[i].pt();
     62        dt = particles[i].mt() - pt;
     63        if (_rescaling_class == 0){
     64          scalar_pt[j] += pt;
     65          scalar_dt[j] += dt;
     66        } else {
     67          double r = (*_rescaling_class)(particles[i]);
     68          scalar_pt[j] += pt/r;
     69          scalar_dt[j] += dt/r;
     70        }
     71      }
     72    }
     73    // sort things for _percentile
     74    sort(scalar_dt.begin(), scalar_dt.end());
     75
     76    // compute rho_m and sigma_m (see comment below for the
     77    // normaliosation of sigma)
     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());
     81  } else {
     82    // only rho
     83    //fill(_scalar_pt.begin(), _scalar_pt.end(), 0.0);
     84    for (unsigned i = 0; i < particles.size(); i++) {
     85      int j = tile_index(particles[i]);
     86      if (j >= 0){
     87        if (_rescaling_class == 0){
     88          scalar_pt[j] += particles[i].pt();
     89        } else {
     90          scalar_pt[j] += particles[i].pt()/(*_rescaling_class)(particles[i]);
     91        }
     92      }
    4993    }
    5094  }
    51   sort(_scalar_pt.begin(), _scalar_pt.end());
     95
     96  // if there are some "bad" tiles, then we need to exclude them from
     97  // the calculation of the median. We'll do this by condensing the
     98  // scalar_pt vector down to just the values for the tiles that are
     99  // good.
     100  //
     101  // tested answers look right in "issue" 2014-08-08-testing-rect-grid
     102  if (n_good_tiles() != n_tiles()) {
     103    int newn = 0;
     104    for (unsigned i = 0; i < scalar_pt.size(); i++) {
     105      if (tile_is_good(i)) {
     106        // clang gets confused with the SharedPtr swap if we don't
     107        // have std:: here
     108        std::swap(scalar_pt[i],scalar_pt[newn]);
     109        newn++;
     110      }
     111    }
     112    scalar_pt.resize(newn);
     113  }
     114
     115  // in all cases, carry on with the computation of rho
     116  //
     117  // first sort
     118  sort(scalar_pt.begin(), scalar_pt.end());
     119
     120  // then compute rho
     121  //
     122  // watch out: by definition, our sigma is the standard deviation of
     123  // the pt density multiplied by the square root of the cell area
     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());
    52127
    53128  _has_particles = true;
     
    61136double GridMedianBackgroundEstimator::rho() const {
    62137  verify_particles_set();
    63   return _percentile(_scalar_pt, 0.5) / _cell_area;
     138  return _rho;
    64139}
    65140
     
    71146double GridMedianBackgroundEstimator::sigma() const{
    72147  verify_particles_set();
    73   // watch out: by definition, our sigma is the standard deviation of
    74   // the pt density multiplied by the square root of the cell area
    75   return (_percentile(_scalar_pt, 0.5) -
    76           _percentile(_scalar_pt, (1.0-0.6827)/2.0)
    77           )/sqrt(_cell_area);
     148  return _sigma;
    78149}
    79150
     
    85156// determination.
    86157double GridMedianBackgroundEstimator::rho(const PseudoJet & jet)  {
    87   verify_particles_set();
     158  //verify_particles_set();
    88159  double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
    89160  return rescaling*rho();
     
    95166// the position of a given jet. As for rho(jet), it is non-const.
    96167double GridMedianBackgroundEstimator::sigma(const PseudoJet & jet){
    97   verify_particles_set();
     168  //verify_particles_set();
    98169  double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
    99170  return rescaling*sigma();
     171}
     172
     173//----------------------------------------------------------------------
     174// returns rho_m (particle-masses contribution to the 4-vector density)
     175double GridMedianBackgroundEstimator::rho_m() const {
     176  if (! _enable_rho_m){
     177    throw Error("GridMediamBackgroundEstimator: rho_m requested but rho_m calculation has been disabled.");
     178  }
     179  verify_particles_set();
     180  return _rho_m;
     181}
     182
     183
     184//----------------------------------------------------------------------
     185// returns sigma_m (particle-masses contribution to the 4-vector
     186// density); must be multipled by sqrt(area) to get fluctuations
     187// for a region of a given area.
     188double 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.");
     191  }
     192  verify_particles_set();
     193  return _sigma_m;
     194}
     195
     196//----------------------------------------------------------------------
     197// returns rho_m locally at the position of a given jet. As for
     198// rho(jet), it is non-const.
     199double GridMedianBackgroundEstimator::rho_m(const PseudoJet & jet)  {
     200  //verify_particles_set();
     201  double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
     202  return rescaling*rho_m();
     203}
     204
     205
     206//----------------------------------------------------------------------
     207// returns sigma_m locally at the position of a given jet. As for
     208// rho(jet), it is non-const.
     209double GridMedianBackgroundEstimator::sigma_m(const PseudoJet & jet){
     210  //verify_particles_set();
     211  double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet);
     212  return rescaling*sigma_m();
    100213}
    101214
     
    112225string GridMedianBackgroundEstimator::description() const {
    113226  ostringstream desc;
     227#ifdef FASTJET_GMBGE_USEFJGRID
     228  desc << "GridMedianBackgroundEstimator, with " << RectangularGrid::description();
     229#else
    114230  desc << "GridMedianBackgroundEstimator, with grid extension |y| < " << _ymax
    115        << " and requested grid spacing = " << _requested_grid_spacing;
     231       << ", and grid cells of size dy x dphi = " << _dy << " x " << _dphi
     232       << " (requested size = " << _requested_grid_spacing << ")";
     233#endif
    116234  return desc.str();
    117235}       
     
    144262
    145263
     264#ifndef FASTJET_GMBGE_USEFJGRID
    146265//----------------------------------------------------------------------
    147266// protected material
     
    168287
    169288  _ntotal = _nphi * _ny;
    170   _scalar_pt.resize(_ntotal);
    171   _cell_area = _dy * _dphi;
    172 }
    173 
    174 
    175 //----------------------------------------------------------------------
    176 // retrieve the grid cell index for a given PseudoJet
    177 int GridMedianBackgroundEstimator::igrid(const PseudoJet & p) const {
     289  //_scalar_pt.resize(_ntotal);
     290  _tile_area = _dy * _dphi;
     291}
     292
     293
     294//----------------------------------------------------------------------
     295// retrieve the grid tile index for a given PseudoJet
     296int GridMedianBackgroundEstimator::tile_index(const PseudoJet & p) const {
    178297  // directly taking int does not work for values between -1 and 0
    179298  // so use floor instead
     
    193312  if (iphi == _nphi) iphi = 0; // just in case of rounding errors
    194313
    195   int igrid_res = iy*_nphi + iphi;
    196   assert (igrid_res >= 0 && igrid_res < _ny*_nphi);
    197   return igrid_res;
    198 }
     314  int index_res = iy*_nphi + iphi;
     315  assert (index_res >= 0 && index_res < _ny*_nphi);
     316  return index_res;
     317}
     318#endif // FASTJET_GMBGE_USEFJGRID
     319
    199320
    200321
Note: See TracChangeset for help on using the changeset viewer.