FastJet  3.1.0-beta.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GridMedianBackgroundEstimator.hh
1 #ifndef __GRID_MEDIAN_BACKGROUND_ESTIMATOR_HH__
2 #define __GRID_MEDIAN_BACKGROUND_ESTIMATOR_HH__
3 
4 //FJSTARTHEADER
5 // $Id: GridMedianBackgroundEstimator.hh 3610 2014-08-13 09:49:28Z salam $
6 //
7 // Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
8 //
9 //----------------------------------------------------------------------
10 // This file is part of FastJet.
11 //
12 // FastJet is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // The algorithms that underlie FastJet have required considerable
18 // development. They are described in the original FastJet paper,
19 // hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
20 // FastJet as part of work towards a scientific publication, please
21 // quote the version you use and include a citation to the manual and
22 // optionally also to hep-ph/0512210.
23 //
24 // FastJet is distributed in the hope that it will be useful,
25 // but WITHOUT ANY WARRANTY; without even the implied warranty of
26 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 // GNU General Public License for more details.
28 //
29 // You should have received a copy of the GNU General Public License
30 // along with FastJet. If not, see <http://www.gnu.org/licenses/>.
31 //----------------------------------------------------------------------
32 //FJENDHEADER
33 
34 
35 #include "fastjet/tools/BackgroundEstimatorBase.hh"
36 
37 // if defined then we'll use the RectangularGrid class
38 //
39 // (For FastJet 3.2, maybe remove the symbol and simply clean up the
40 // code below to use exclusively the RectangularGrid)
41 #define FASTJET_GMBGE_USEFJGRID
42 
43 #ifdef FASTJET_GMBGE_USEFJGRID
44 #include "fastjet/RectangularGrid.hh"
45 #endif
46 
47 
48 
49 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
50 
51 /// @ingroup tools_background
52 /// \class GridMedianBackgroundEstimator
53 ///
54 /// Background Estimator based on the median pt/area of a set of grid
55 /// cells.
56 ///
57 /// Description of the method:
58 /// This background estimator works by projecting the event onto a
59 /// grid in rapidity and azimuth. In each grid cell, the scalar pt
60 /// sum of the particles in the cell is computed. The background
61 /// density is then estimated by the median of (scalar pt sum/cell
62 /// area) for all cells.
63 ///
64 /// Parameters:
65 /// The class takes 2 arguments: the absolute rapidity extent of the
66 /// cells and the size of the grid cells. Note that the size of the cell
67 /// will be adjusted in azimuth to satisfy the 2pi periodicity and
68 /// in rapidity to match the requested rapidity extent.
69 ///
70 /// Rescaling:
71 /// It is possible to use a rescaling profile. In this case, the
72 /// profile needs to be set before setting the particles and it will
73 /// be applied to each particle (i.e. not to each cell).
74 /// Note also that in this case one needs to call rho(jet) instead of
75 /// rho() [Without rescaling, they are identical]
76 ///
78 #ifdef FASTJET_GMBGE_USEFJGRID
80 #endif
81 {
82 
83 public:
84  /// @name constructors and destructors
85  //\{
86 #ifdef FASTJET_GMBGE_USEFJGRID
87  //----------------------------------------------------------------
88  /// \param ymax maximal absolute rapidity extent of the grid
89  /// \param requested_grid_spacing size of the grid cell. The
90  /// "real" cell size could differ due e.g. to the 2pi
91  /// periodicity in azimuthal angle (size, not area)
92  GridMedianBackgroundEstimator(double ymax, double requested_grid_spacing) :
93  RectangularGrid(ymax, requested_grid_spacing),
94  _has_particles(false), _enable_rho_m(true) {}
95 
96  //----------------------------------------------------------------
97  /// Constructor based on a user's fully specified RectangularGrid
99  RectangularGrid(grid),
100  _has_particles(false), _enable_rho_m(true) {
101  if (!RectangularGrid::is_initialised())
102  throw Error("attempt to construct GridMedianBackgroundEstimator with uninitialised RectangularGrid");
103  }
104 
105 #else // alternative in old framework where we didn't have the rectangular grid
106  GridMedianBackgroundEstimator(double ymax, double requested_grid_spacing) :
107  _ymin(-ymax), _ymax(ymax),
108  _requested_grid_spacing(requested_grid_spacing),
109  _has_particles(false), _enable_rho_m(true)
110  {
111  setup_grid();
112  }
113 #endif // FASTJET_GMBGE_USEFJGRID
114 
115  //\}
116 
117 
118  /// @name setting a new event
119  //\{
120  //----------------------------------------------------------------
121 
122  /// tell the background estimator that it has a new event, composed
123  /// of the specified particles.
124  void set_particles(const std::vector<PseudoJet> & particles);
125 
126  /// determine whether the automatic calculation of rho_m and sigma_m
127  /// is enabled (by default true)
128  void set_compute_rho_m(bool enable){ _enable_rho_m = enable;}
129 
130  //\}
131 
132  /// @name retrieving fundamental information
133  //\{
134  //----------------------------------------------------------------
135 
136  /// returns rho, the median background density per unit area
137  double rho() const;
138 
139  /// returns sigma, the background fluctuations per unit area; must be
140  /// multipled by sqrt(area) to get fluctuations for a region of a
141  /// given area.
142  double sigma() const;
143 
144  /// returns rho, the background density per unit area, locally at the
145  /// position of a given jet. Note that this is not const, because a
146  /// user may then wish to query other aspects of the background that
147  /// could depend on the position of the jet last used for a rho(jet)
148  /// determination.
149  double rho(const PseudoJet & jet);
150 
151  /// returns sigma, the background fluctuations per unit area, locally at
152  /// the position of a given jet. As for rho(jet), it is non-const.
153  double sigma(const PseudoJet & jet);
154 
155  /// returns true if this background estimator has support for
156  /// determination of sigma
157  bool has_sigma() {return true;}
158 
159  //-----------------------------------------------------------------
160  /// Returns rho_m, the purely longitudinal, particle-mass-induced
161  /// component of the background density per unit area
162  double rho_m() const;
163 
164  /// returns sigma_m, a measure of the fluctuations in the purely
165  /// longitudinal, particle-mass-induced component of the background
166  /// density per unit area; must be multipled by sqrt(area) to get
167  /// fluctuations for a region of a given area.
168  double sigma_m() const;
169 
170  /// Returns rho_m locally at the jet position. As for rho(jet), it is non-const.
171  double rho_m(const PseudoJet & jet);
172 
173  /// Returns sigma_m locally at the jet position. As for rho(jet), it is non-const.
174  double sigma_m(const PseudoJet & jet);
175 
176  /// Returns true if this background estimator has support for
177  /// determination of rho_m.
178  ///
179  /// Note that support for sigma_m is automatic is one has sigma and
180  /// rho_m support.
181  bool has_rho_m() const {return _enable_rho_m;}
182 
183 
184  /// returns the area of the grid cells (all identical, but
185  /// referred to as "mean" area for uniformity with JetMedianBGE).
186  double mean_area() const {return mean_tile_area();}
187  //\}
188 
189  /// @name configuring the behaviour
190  //\{
191  //----------------------------------------------------------------
192 
193  /// Set a pointer to a class that calculates the rescaling factor as
194  /// a function of the jet (position). Note that the rescaling factor
195  /// is used both in the determination of the "global" rho (the pt/A
196  /// of each jet is divided by this factor) and when asking for a
197  /// local rho (the result is multiplied by this factor).
198  ///
199  /// The BackgroundRescalingYPolynomial class can be used to get a
200  /// rescaling that depends just on rapidity.
201  ///
202  /// Note that this has to be called BEFORE any attempt to do an
203  /// actual computation
204  ///
205  /// The same profile will be used for both pt and mt (this is
206  /// probabaly a good approximation since the particle density
207  /// changes is what dominates the rapidity profile)
208  virtual void set_rescaling_class(const FunctionOfPseudoJet<double> * rescaling_class);
209 
210  //\}
211 
212  /// @name description
213  //\{
214  //----------------------------------------------------------------
215 
216  /// returns a textual description of the background estimator
217  std::string description() const;
218 
219  //\}
220 
221 
222 private:
223 
224 #ifndef FASTJET_GMBGE_USEFJGRID
225 
226  /// configure the grid
227  void setup_grid();
228 
229  /// retrieve the grid cell index for a given PseudoJet
230  int tile_index(const PseudoJet & p) const;
231 
232  // information about the grid
233  double _ymin, _ymax, _dy, _dphi, _requested_grid_spacing, _tile_area;
234  int _ny, _nphi, _ntotal;
235 
236  int n_tiles() const {return _ntotal;}
237  int n_good_tiles() const {return n_tiles();}
238  int tile_is_good(int /* itile */) const {return true;}
239 
240  double mean_tile_area() const {return _tile_area;}
241 #endif // FASTJET_GMBGE_USEFJGRID
242 
243 
244  /// verify that particles have been set and throw an error if not
245  void verify_particles_set() const;
246 
247  // information abotu the event
248  //std::vector<double> _scalar_pt;
249  double _rho, _sigma, _rho_m, _sigma_m;
250  bool _has_particles;
251  bool _enable_rho_m;
252 
253  // various warnings to inform people of potential dangers
254  LimitedWarning _warning_rho_of_jet;
255  LimitedWarning _warning_rescaling;
256 };
257 
258 FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
259 
260 #endif // __GRID_MEDIAN_BACKGROUND_ESTIMATOR_HH__