Fork me on GitHub

source: git/external/fastjet/contribs/Nsubjettiness/MeasureFunction.hh@ be2222c

ImprovedOutputFile Timing dual_readout llp
Last change on this file since be2222c was 35cdc46, checked in by Pavel Demin <demin@…>, 10 years ago

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

  • Property mode set to 100644
File size: 11.9 KB
Line 
1// Nsubjettiness Package
2// Questions/Comments? jthaler@jthaler.net
3//
4// Copyright (c) 2011-14
5// Jesse Thaler, Ken Van Tilburg, Christopher K. Vermilion, and TJ Wilkason
6//
7// $Id: MeasureFunction.hh 678 2014-06-12 20:43:03Z jthaler $
8//----------------------------------------------------------------------
9// This file is part of FastJet contrib.
10//
11// It is free software; you can redistribute it and/or modify it under
12// the terms of the GNU General Public License as published by the
13// Free Software Foundation; either version 2 of the License, or (at
14// your option) any later version.
15//
16// It is distributed in the hope that it will be useful, but WITHOUT
17// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19// License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this code. If not, see <http://www.gnu.org/licenses/>.
23//----------------------------------------------------------------------
24
25#ifndef __FASTJET_CONTRIB_MEASUREFUNCTION_HH__
26#define __FASTJET_CONTRIB_MEASUREFUNCTION_HH__
27
28#include "fastjet/PseudoJet.hh"
29#include <cmath>
30#include <vector>
31#include <list>
32#include <limits>
33
34
35FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
36
37namespace contrib{
38
39///////
40//
41// TauComponents
42// (eventually we might want to put this in a separate header file)
43//
44///////
45
46/// \class TauComponents
47// This class creates a wrapper for the various tau/subtau values calculated in Njettiness. This class allows Njettiness access to these variables
48// without ever having to do the calculation itself. It takes in subtau numerators and tau denominator from MeasureFunction
49// and outputs tau numerator, and normalized tau and subtau.
50class TauComponents {
51
52public:
53 // empty constructor necessary to initialize tau_components in Njettiness
54 // later set correctly in Njettiness::getTau function
55 TauComponents() {
56 _jet_pieces_numerator.resize(1, 0.0);
57 _beam_piece_numerator = 0.0;
58 _denominator = 0;
59 _numerator = 0;
60 _jet_pieces.resize(1, 0.0);
61 _beam_piece = 0.0;
62 _tau = 0;
63 _has_denominator = false;
64 _has_beam = false;
65 }
66
67 // This constructor takes input vector and double and calculates all necessary tau components
68 TauComponents(std::vector<double> jet_pieces_numerator, double beam_piece_numerator, double denominator, bool has_denominator, bool has_beam)
69 : _jet_pieces_numerator(jet_pieces_numerator),
70 _beam_piece_numerator(beam_piece_numerator),
71 _denominator(denominator),
72 _has_denominator(has_denominator),
73 _has_beam(has_beam) {
74
75 if (!_has_denominator) assert(_denominator == 1.0); //make sure no effect from _denominator if _has_denominator is false
76 if (!_has_beam) assert (_beam_piece_numerator == 0.0); //make sure no effect from _beam_piece_numerator if _has_beam is false
77
78 _numerator = _beam_piece_numerator;
79 _jet_pieces.resize(_jet_pieces_numerator.size(),0.0);
80 for (unsigned j = 0; j < _jet_pieces_numerator.size(); j++) {
81 _jet_pieces[j] = _jet_pieces_numerator[j]/_denominator;
82 _numerator += _jet_pieces_numerator[j];
83 }
84
85 _beam_piece = _beam_piece_numerator/_denominator;
86 _tau = _numerator/_denominator;
87 }
88
89
90 // return values
91 std::vector<double> jet_pieces_numerator() const { return _jet_pieces_numerator; }
92 double beam_piece_numerator() const { return _beam_piece_numerator; }
93 double denominator() const { return _denominator; }
94 double numerator() const { return _numerator; }
95
96 bool has_denominator() const { return _has_denominator; }
97 bool has_beam() const { return _has_beam; }
98
99 std::vector<double> jet_pieces() const { return _jet_pieces; }
100 double beam_piece() const { return _beam_piece; }
101 double tau() const { return _tau; }
102
103private:
104
105 // these values are input in the constructor
106 std::vector<double> _jet_pieces_numerator;
107 double _beam_piece_numerator;
108 double _denominator;
109 bool _has_denominator; //added so that TauComponents knows if denominator is used or not
110 bool _has_beam; //added so that TauComponents knows if beam regions is used or not
111
112 // these values are derived from above values
113 std::vector<double> _jet_pieces;
114 double _beam_piece;
115 double _numerator;
116 double _tau;
117
118};
119
120///////
121//
122// Measure Function
123//
124///////
125
126
127//------------------------------------------------------------------------
128/// \class MeasureFunction
129// This class calculates the tau_N of a jet given a specific measure.
130// It serves as a base class for calculating tau_N according to different measures that are implemented
131// in further derived classes, but does not define a particular measure itself.
132class MeasureFunction {
133
134public:
135 //These functions define the measure by which tau_N is calculated,
136 //and are overloaded by the various measures below
137
138 // Distanes to axes. These are called many times, so need to be as fast as possible
139 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const = 0;
140 virtual double beam_distance_squared(const fastjet::PseudoJet& particle) const = 0;
141
142 // The actual measures used in N-(sub)jettiness
143 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const = 0;
144 virtual double beam_numerator(const fastjet::PseudoJet& particle) const = 0;
145
146 // a possible normalization factor
147 virtual double denominator(const fastjet::PseudoJet& particle) const = 0;
148
149 //------
150 // The functions below call the above functions and are not virtual
151 //------
152
153 // Return all of the necessary TauComponents for specific input particles and axes
154 // Also have optional pointers to get out information about partitioning
155 TauComponents result(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const;
156
157 // Just getting tau value if that is all that is needed
158 double tau(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const {
159 return result(particles,axes).tau();
160 }
161
162 // Create the partitioning and stores internally
163 std::vector<fastjet::PseudoJet> get_partition(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes, PseudoJet * beamPartitionStorage = NULL) const;
164
165 // Essentially same as get_partition, but in the form needed for the jet algorithm
166 std::vector<std::list<int> > get_partition_list(const std::vector<fastjet::PseudoJet>& particles, const std::vector<fastjet::PseudoJet>& axes) const;
167
168 // calculates the tau result using an existing partition
169 TauComponents result_from_partition(const std::vector<fastjet::PseudoJet>& jet_partitioning, const std::vector<fastjet::PseudoJet>& axes, PseudoJet * beamPartitionStorage = NULL) const;
170
171 // shorthand for squaring
172 static inline double sq(double x) {return x*x;}
173
174 //virtual destructor
175 virtual ~MeasureFunction(){}
176
177protected:
178 //bool set by derived classes to choose whether or not to use the denominator
179 bool _has_denominator;
180 bool _has_beam;
181
182 // This constructor allows _has_denominator to be set by derived classes
183 MeasureFunction(bool has_denominator = true, bool has_beam = true) : _has_denominator(has_denominator), _has_beam(has_beam) {}
184
185};
186
187
188/// \class DefaultNormalizedMeasureFunction
189// This class is the default measure, inheriting from the class above. This class will calculate tau_N
190// of a jet according to this measure. This measure is defined as the pT of the particle multiplied by deltaR
191// to the power of beta. This class includes the normalization factor determined by R0
192class DefaultNormalizedMeasureFunction : public MeasureFunction {
193
194public:
195
196 DefaultNormalizedMeasureFunction(double beta, double R0, double Rcutoff, bool normalized = true)
197 : MeasureFunction(normalized), _beta(beta), _R0(R0), _Rcutoff(Rcutoff) {}
198
199 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
200 return particle.squared_distance(axis);
201 }
202
203 virtual double beam_distance_squared(const fastjet::PseudoJet& /*particle*/) const {
204 return sq(_Rcutoff);
205 }
206
207 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const{
208 return particle.perp() * std::pow(jet_distance_squared(particle,axis),_beta/2.0);
209 }
210
211 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
212 return particle.perp() * std::pow(_Rcutoff,_beta);
213 }
214
215 virtual double denominator(const fastjet::PseudoJet& particle) const {
216 return particle.perp() * std::pow(_R0,_beta);
217 }
218
219private:
220 double _beta;
221 double _R0;
222 double _Rcutoff;
223
224
225};
226
227//------------------------------------------------------------------------
228/// \class DefaultUnnormalizedMeasureFunction
229// This class is the unnormalized default measure, inheriting from the class above. The only difference from above
230// is that the denominator is defined to be 1.0 by setting _has_denominator to false.
231class DefaultUnnormalizedMeasureFunction : public DefaultNormalizedMeasureFunction {
232
233public:
234 // Since all methods are identical, UnnormalizedMeasure inherits directly
235 // from NormalizedMeasure. R0 is a dummy value since the value of R0 is unecessary for this class,
236 // and the "false" flag sets _has_denominator in MeasureFunction to false so no denominator is used.
237 DefaultUnnormalizedMeasureFunction(double beta, double Rcutoff)
238 : DefaultNormalizedMeasureFunction(beta, std::numeric_limits<double>::quiet_NaN(), Rcutoff, false) {}
239};
240
241//------------------------------------------------------------------------
242/// \class GeometricMeasureFunction
243// This class is the geometic measure, inheriting from the class above. This class will calculate tau_N
244// of a jet according to this measure. This measure is defined by the Lorentz dot product between
245// the particle and the axis. This class includes normalization of tau_N.
246class GeometricMeasureFunction : public MeasureFunction {
247
248public:
249 // Right now, we are hard coded for beam_beta = 1.0, but that will need to change
250 GeometricMeasureFunction(double jet_beta, double Rcutoff) :
251 MeasureFunction(false), // doesn't have denominator
252 _jet_beta(jet_beta), _beam_beta(1.0), _Rcutoff(Rcutoff) {}
253
254 virtual double jet_distance_squared(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
255 fastjet::PseudoJet lightAxis = lightFrom(axis);
256 double pseudoRsquared = 2.0*dot_product(lightFrom(axis),particle)/(lightAxis.pt()*particle.pt());
257 return pseudoRsquared;
258 }
259
260 virtual double beam_distance_squared(const fastjet::PseudoJet& /*particle*/) const {
261 return sq(_Rcutoff);
262 }
263
264 virtual double jet_numerator(const fastjet::PseudoJet& particle, const fastjet::PseudoJet& axis) const {
265 fastjet::PseudoJet lightAxis = lightFrom(axis);
266 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(lightAxis.pt(),_beam_beta - 1.0);
267 return particle.pt() * weight * std::pow(jet_distance_squared(particle,axis),_jet_beta/2.0);
268 }
269
270 virtual double beam_numerator(const fastjet::PseudoJet& particle) const {
271 double weight = (_beam_beta == 1.0) ? 1.0 : std::pow(particle.pt()/particle.e(),_beam_beta - 1.0);
272 return particle.pt() * weight * std::pow(_Rcutoff,_jet_beta);
273 }
274
275 virtual double denominator(const fastjet::PseudoJet& /*particle*/) const {
276 return std::numeric_limits<double>::quiet_NaN();
277 }
278
279
280private:
281 double _jet_beta;
282 double _beam_beta;
283 double _Rcutoff;
284
285 // create light-like axis
286 fastjet::PseudoJet lightFrom(const fastjet::PseudoJet& input) const {
287 double length = sqrt(pow(input.px(),2) + pow(input.py(),2) + pow(input.pz(),2));
288 return fastjet::PseudoJet(input.px()/length,input.py()/length,input.pz()/length,1.0);
289 }
290
291};
292
293
294} //namespace contrib
295
296FASTJET_END_NAMESPACE
297
298#endif // __FASTJET_CONTRIB_MEASUREFUNCTION_HH__
Note: See TracBrowser for help on using the repository browser.