FastJet 3.4.1
PxConePlugin.cc
1//FJSTARTHEADER
2// $Id$
3//
4// Copyright (c) 2005-2023, 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#include "fastjet/PxConePlugin.hh"
32
33#include "fastjet/ClusterSequence.hh"
34#include <sstream>
35
36// pxcone stuff
37#include "pxcone.h"
38
39
40FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
41
42using namespace std;
43
44thread_safety_helpers::FirstTimeTrue PxConePlugin::_first_time;
45
46string PxConePlugin::description () const {
47 ostringstream desc;
48
49 desc << "PxCone jet algorithm with "
50 << "cone_radius = " << cone_radius () << ", "
51 << "min_jet_energy = " << min_jet_energy () << ", "
52 << "overlap_threshold = " << overlap_threshold () << ", "
53 << "E_scheme_jets = " << E_scheme_jets () << ", "
54 << "mode (1=e+e-, 2=hh) = " << _mode
55 << " (NB: non-standard version of PxCone, containing small bug fixes by Gavin Salam)";
56
57 return desc.str();
58}
59
60
61void PxConePlugin::run_clustering(ClusterSequence & clust_seq) const {
62 // print a banner if we run this for the first time
63 //_print_banner(clust_seq.fastjet_banner_stream());
64
65 // only have hh mode
66 //int mode = 2;
67
68 int ntrak = clust_seq.jets().size(), itkdm = 4;
69 double *ptrak = new double[ntrak*4+1];
70 for (int i = 0; i < ntrak; i++) {
71 ptrak[4*i+0] = clust_seq.jets()[i].px();
72 ptrak[4*i+1] = clust_seq.jets()[i].py();
73 ptrak[4*i+2] = clust_seq.jets()[i].pz();
74 ptrak[4*i+3] = clust_seq.jets()[i].E();
75 }
76
77 // max number of allowed jets
78 int mxjet = ntrak;
79 int njet;
80 double *pjet = new double[mxjet*5+1];
81 int *ipass = new int[ntrak+1];
82 int *ijmul = new int[mxjet+1];
83 int ierr;
84
85 // run pxcone
86 pxcone(
87 _mode , // 1=>e+e-, 2=>hadron-hadron
88 ntrak , // Number of particles
89 itkdm , // First dimension of PTRAK array:
90 ptrak , // Array of particle 4-momenta (Px,Py,Pz,E)
91 cone_radius() , // Cone size (half angle) in radians
92 min_jet_energy() , // Minimum Jet energy (GeV)
93 overlap_threshold() , // Maximum fraction of overlap energy in a jet
94 mxjet , // Maximum possible number of jets
95 njet , // Number of jets found
96 pjet , // 5-vectors of jets
97 ipass, // Particle k belongs to jet number IPASS(k)-1
98 // IPASS = -1 if not assosciated to a jet
99 ijmul, // Jet i contains IJMUL[i] particles
100 ierr // = 0 if all is OK ; = -1 otherwise
101 );
102
103 if (ierr != 0) throw Error("An error occurred while running PXCONE");
104
105 // now transfer information back
106 valarray<int> last_index_created(njet);
107
108 vector<vector<int> > jet_particle_content(njet);
109
110 // get a list of particles in each jet
111 for (int itrak = 0; itrak < ntrak; itrak++) {
112 int jet_i = ipass[itrak] - 1;
113 if (jet_i >= 0) jet_particle_content[jet_i].push_back(itrak);
114 }
115
116 // now transfer the jets back into our own structure -- we will
117 // mimic the cone code with a sequential recombination sequence in
118 // which the jets are built up by adding one particle at a time
119 for(int ipxjet = njet-1; ipxjet >= 0; ipxjet--) {
120 const vector<int> & jet_trak_list = jet_particle_content[ipxjet];
121 int jet_k = jet_trak_list[0];
122
123 for (unsigned ilist = 1; ilist < jet_trak_list.size(); ilist++) {
124 int jet_i = jet_k;
125 // retrieve our misappropriated index for the jet
126 int jet_j = jet_trak_list[ilist];
127 // do a fake recombination step with dij=0
128 double dij = 0.0;
129 //clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
130 if (ilist != jet_trak_list.size()-1 || E_scheme_jets()) {
131 // our E-scheme recombination in cases where it doesn't matter
132 clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
133 } else {
134 // put in pxcone's momentum for the last recombination so that the
135 // final inclusive jet corresponds exactly to PXCONE's
136 clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij,
137 PseudoJet(pjet[5*ipxjet+0],pjet[5*ipxjet+1],
138 pjet[5*ipxjet+2],pjet[5*ipxjet+3]),
139 jet_k);
140 }
141 }
142
143 // NB: put a sensible looking d_iB just to be nice...
144 double d_iB = clust_seq.jets()[jet_k].perp2();
145 clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
146 }
147
148
149 //// following code is for testing only
150 //cout << endl;
151 //for (int ijet = 0; ijet < njet; ijet++) {
152 // PseudoJet jet(pjet[ijet][0],pjet[ijet][1],pjet[ijet][2],pjet[ijet][3]);
153 // cout << jet.perp() << " " << jet.rap() << endl;
154 //}
155 //cout << "-----------------------------------------------------\n";
156 //vector<PseudoJet> ourjets(clust_seq.inclusive_jets());
157 //for (vector<PseudoJet>::const_iterator ourjet = ourjets.begin();
158 // ourjet != ourjets.end(); ourjet++) {
159 // cout << ourjet->perp() << " " << ourjet->rap() << endl;
160 //}
161 ////cout << endl;
162
163 delete[] ptrak;
164 delete[] ipass;
165 delete[] ijmul;
166 delete[] pjet;
167}
168
169// print a banner for reference to the 3rd-party code
170void PxConePlugin::_print_banner(ostream *ostr) const{
171 if (! _first_time()) return;
172
173 // make sure the user has not set the banner stream to NULL
174 if (!ostr) return;
175
176 (*ostr) << "#-------------------------------------------------------------------------" << endl;
177 (*ostr) << "# You are running the PxCone plugin for FastJet " << endl;
178 (*ostr) << "# Original code by the Luis Del Pozo, David Ward and Michael H. Seymour " << endl;
179 (*ostr) << "# If you use this plugin, please cite " << endl;
180 (*ostr) << "# M. H. Seymour and C. Tevlin, JHEP 0611 (2006) 052 [hep-ph/0609100]. " << endl;
181 (*ostr) << "# in addition to the usual FastJet reference. " << endl;
182 (*ostr) << "#-------------------------------------------------------------------------" << endl;
183
184 // make sure we really have the output done.
185 ostr->flush();
186}
187
188FASTJET_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...
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],...
base class corresponding to errors that can be thrown by FastJet
Definition: Error.hh:52
Class to contain pseudojets, including minimal information of use to jet-clustering routines.
Definition: PseudoJet.hh:68