Changeset 49234af in git for external/fastjet/tools/GridMedianBackgroundEstimator.cc
- Timestamp:
- Dec 9, 2014, 1:27:13 PM (10 years ago)
- Branches:
- ImprovedOutputFile, Timing, dual_readout, llp, master
- Children:
- 37deb3b, 9e991f8
- Parents:
- f6b6ee7 (diff), e7e90df (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
external/fastjet/tools/GridMedianBackgroundEstimator.cc
rf6b6ee7 r49234af 1 // STARTHEADER2 // $Id $3 // 4 // Copyright (c) 2005-201 1, Matteo Cacciari, Gavin P. Salam and Gregory Soyez1 //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 5 5 // 6 6 //---------------------------------------------------------------------- … … 13 13 // 14 14 // 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 16 17 // 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. 18 20 // 19 21 // FastJet is distributed in the hope that it will be useful, … … 25 27 // along with FastJet. If not, see <http://www.gnu.org/licenses/>. 26 28 //---------------------------------------------------------------------- 27 // ENDHEADER29 //FJENDHEADER 28 30 29 31 … … 32 34 33 35 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh 36 34 37 35 38 //---------------------------------------------------------------------- … … 39 42 // of the specified particles. 40 43 void 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 } 49 93 } 50 94 } 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()); 52 127 53 128 _has_particles = true; … … 61 136 double GridMedianBackgroundEstimator::rho() const { 62 137 verify_particles_set(); 63 return _ percentile(_scalar_pt, 0.5) / _cell_area;138 return _rho; 64 139 } 65 140 … … 71 146 double GridMedianBackgroundEstimator::sigma() const{ 72 147 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; 78 149 } 79 150 … … 85 156 // determination. 86 157 double GridMedianBackgroundEstimator::rho(const PseudoJet & jet) { 87 verify_particles_set();158 //verify_particles_set(); 88 159 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet); 89 160 return rescaling*rho(); … … 95 166 // the position of a given jet. As for rho(jet), it is non-const. 96 167 double GridMedianBackgroundEstimator::sigma(const PseudoJet & jet){ 97 verify_particles_set();168 //verify_particles_set(); 98 169 double rescaling = (_rescaling_class == 0) ? 1.0 : (*_rescaling_class)(jet); 99 170 return rescaling*sigma(); 171 } 172 173 //---------------------------------------------------------------------- 174 // returns rho_m (particle-masses contribution to the 4-vector density) 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."); 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. 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."); 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. 199 double 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. 209 double 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(); 100 213 } 101 214 … … 112 225 string GridMedianBackgroundEstimator::description() const { 113 226 ostringstream desc; 227 #ifdef FASTJET_GMBGE_USEFJGRID 228 desc << "GridMedianBackgroundEstimator, with " << RectangularGrid::description(); 229 #else 114 230 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 116 234 return desc.str(); 117 235 } … … 144 262 145 263 264 #ifndef FASTJET_GMBGE_USEFJGRID 146 265 //---------------------------------------------------------------------- 147 266 // protected material … … 168 287 169 288 _ntotal = _nphi * _ny; 170 _scalar_pt.resize(_ntotal);171 _ cell_area = _dy * _dphi;172 } 173 174 175 //---------------------------------------------------------------------- 176 // retrieve the grid cellindex for a given PseudoJet177 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 296 int GridMedianBackgroundEstimator::tile_index(const PseudoJet & p) const { 178 297 // directly taking int does not work for values between -1 and 0 179 298 // so use floor instead … … 193 312 if (iphi == _nphi) iphi = 0; // just in case of rounding errors 194 313 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 199 320 200 321
Note:
See TracChangeset
for help on using the changeset viewer.