Fork me on GitHub

source: svn/trunk/external/fastjet/contribs/Nsubjettiness/MeasureFunction.hh

Last change on this file was 1368, checked in by Michele Selvaggi, 11 years ago

added nsubjettiness

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