FastJet 3.5.0
Loading...
Searching...
No Matches
TrackJetPlugin.cc
1//FJSTARTHEADER
2// $Id$
3//
4// Copyright (c) 2007-2025, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
5//
6//----------------------------------------------------------------------
7// This file is part of FastJet.
8//
9// FastJet is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 2 of the License, or
12// (at your option) any later version.
13//
14// The algorithms that underlie FastJet have required considerable
15// development. They are described in the original FastJet paper,
16// hep-ph/0512210 and in the manual, arXiv:1111.6097. If you use
17// FastJet as part of work towards a scientific publication, please
18// quote the version you use and include a citation to the manual and
19// optionally also to hep-ph/0512210.
20//
21// FastJet is distributed in the hope that it will be useful,
22// but WITHOUT ANY WARRANTY; without even the implied warranty of
23// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24// GNU General Public License for more details.
25//
26// You should have received a copy of the GNU General Public License
27// along with FastJet. If not, see <http://www.gnu.org/licenses/>.
28//----------------------------------------------------------------------
29//FJENDHEADER
30
31// History of changes from the original TrackJet.cc file in Rivet <=1.1.2
32//
33// 2011-01-28 Gregory Soyez <soyez@fastjet.fr>
34//
35// * Replaced the use of sort by stable_sort (see BUGS in the top
36// FastJet dir)
37//
38//
39// 2009-01-17 Gregory Soyez <soyez@fastjet.fr>
40//
41// * Aligned the var names with the previous conventions
42//
43// * Put the plugin in the fastjet::trackjet namespace
44//
45//
46// 2009-01-06 Gregory Soyez <soyez@fastjet.fr>
47//
48// * Adapted the original code in a FastJet plugin class.
49//
50// * Allowed for arbitrary recombination schemes (one for the
51// recomstruction of the 'jet' --- i.e. summing the particles
52// into a jet --- and one for the accumulation of particles in
53// a 'track' --- i.e. the dynamics of the clustering)
54
55
56// fastjet stuff
57#include "fastjet/ClusterSequence.hh"
58#include "fastjet/TrackJetPlugin.hh"
59
60// other stuff
61#include <algorithm>
62#include <list>
63#include <memory>
64#include <cmath>
65#include <vector>
66#include <sstream>
67
68FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
69
70using namespace std;
71
72//------------------------------------------------------------------
73// helper class to sort the particles in pt
74//------------------------------------------------------------------
75class TrackJetParticlePtr{
76public:
77 TrackJetParticlePtr(int i_index, double i_perp2)
78 : index(i_index), perp2(i_perp2){}
79
80 int index;
81 double perp2;
82
83 bool operator <(const TrackJetParticlePtr &other) const {
84 return perp2>other.perp2;
85 }
86};
87
88//------------------------------------------------------------------
89// implementation of the TrackJet plugin
90//------------------------------------------------------------------
91
92thread_safety_helpers::FirstTimeTrue TrackJetPlugin::_first_time;
93
94string TrackJetPlugin::description () const {
95 ostringstream desc;
96 desc << "TrackJet algorithm with R = " << R();
97 return desc.str();
98}
99
100void TrackJetPlugin::run_clustering(ClusterSequence & clust_seq) const {
101 // print a banner if we run this for the first time
102 _print_banner(clust_seq.fastjet_banner_stream());
103
104 // we first need to sort the particles in pt
105 vector<TrackJetParticlePtr> particle_list;
106
107 const vector<PseudoJet> & jets = clust_seq.jets();
108 int index=0;
109 for (vector<PseudoJet>::const_iterator mom_it = jets.begin(); mom_it != jets.end(); mom_it++){
110 particle_list.push_back(TrackJetParticlePtr(index, mom_it->perp2()));
111 index++;
112 }
113
114 // sort the particles into decreasing pt
115 stable_sort(particle_list.begin(), particle_list.end());
116
117
118 // if we're using a recombination scheme different from the E scheme,
119 // we first need to update the particles' energy so that they
120 // are massless (and rapidity = pseudorapidity)
121 vector<PseudoJet> tuned_particles = clust_seq.jets();
122 vector<PseudoJet> tuned_tracks = clust_seq.jets();
123 for (vector<PseudoJet>::iterator pit = tuned_particles.begin();
124 pit != tuned_particles.end(); pit++)
125 _jet_recombiner.preprocess(*pit);
126 for (vector<PseudoJet>::iterator pit = tuned_tracks.begin();
127 pit != tuned_tracks.end(); pit++)
128 _track_recombiner.preprocess(*pit);
129
130
131 // we'll just need the particle indices for what follows
132 list<int> sorted_pt_index;
133 for (vector<TrackJetParticlePtr>::iterator mom_it = particle_list.begin();
134 mom_it != particle_list.end(); mom_it++)
135 sorted_pt_index.push_back(mom_it->index);
136
137 // now start building the jets
138 while (sorted_pt_index.size()){
139 // note that here 'track' refers to the direction we're using to test if a particle belongs to the jet
140 // 'jet' refers to the momentum of the jet
141 // the difference between the two is in the recombination scheme used to compute the sum of 4-vectors
142 int current_jet_index = sorted_pt_index.front();
143 PseudoJet current_jet = tuned_particles[current_jet_index];
144 PseudoJet current_track = tuned_tracks[current_jet_index];
145
146 // remove the first particle from the available ones
147 list<int>::iterator index_it = sorted_pt_index.begin();
148 sorted_pt_index.erase(index_it);
149
150 // start browsing the remaining ones
151 index_it = sorted_pt_index.begin();
152 while (index_it != sorted_pt_index.end()){
153 const PseudoJet & current_particle = tuned_particles[*index_it];
154 const PseudoJet & current_particle_track = tuned_tracks[*index_it];
155
156 // check if the particle is within a distance R of the jet
157 double distance2 = current_track.plain_distance(current_particle_track);
158 if (distance2 <= _radius2){
159 // add the particle to the jet
160 PseudoJet new_track;
161 PseudoJet new_jet;
162 _jet_recombiner.recombine(current_jet, current_particle, new_jet);
163 _track_recombiner.recombine(current_track, current_particle_track, new_track);
164
165 int new_jet_index;
166 clust_seq.plugin_record_ij_recombination(current_jet_index, *index_it, distance2, new_jet, new_jet_index);
167
168 current_jet = new_jet;
169 current_track = new_track;
170 current_jet_index = new_jet_index;
171
172 // particle has been clustered so remove it from the list
173 sorted_pt_index.erase(index_it);
174
175 // and don't forget to start again from the beginning
176 // as the jet axis may have changed
177 index_it = sorted_pt_index.begin();
178 } else {
179 index_it++;
180 }
181 }
182
183 // now we have a final jet, so cluster it with the beam
184 clust_seq.plugin_record_iB_recombination(current_jet_index, _radius2);
185 }
186
187}
188
189// print a banner for reference to the 3rd-party code
190void TrackJetPlugin::_print_banner(ostream *ostr) const{
191 if (! _first_time()) return;
192
193 // make sure the user has not set the banner stream to NULL
194 if (!ostr) return;
195
196 (*ostr) << "#-------------------------------------------------------------------------" << endl;
197 (*ostr) << "# You are running the TrackJet plugin for FastJet. It is based on " << endl;
198 (*ostr) << "# the implementation by Andy Buckley and Manuel Bahr that is to be " << endl;
199 (*ostr) << "# found in Rivet 1.1.2. See http://www.hepforge.org/downloads/rivet. " << endl;
200 (*ostr) << "#-------------------------------------------------------------------------" << endl;
201
202 // make sure we really have the output done.
203 ostr->flush();
204}
205
206FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
deals with clustering
void plugin_record_iB_recombination(int jet_i, double diB)
record the fact that there has been a recombination between jets()[jet_i] and the beam,...
const std::vector< PseudoJet > & jets() const
allow the user to access the internally stored _jets() array, which contains both the initial particl...
static std::ostream * fastjet_banner_stream()
returns a pointer to the stream to be used to print banners (cout by default).
void plugin_record_ij_recombination(int jet_i, int jet_j, double dij, int &newjet_k)
record the fact that there has been a recombination between jets()[jet_i] and jets()[jet_k],...
Class to contain pseudojets, including minimal information of use to jet-clustering routines.
Definition PseudoJet.hh:68
double plain_distance(const PseudoJet &other) const
returns squared cylinder (rap-phi) distance between this jet and another
Definition PseudoJet.cc:488