FastJet  3.1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
PxConePlugin.cc
1 //FJSTARTHEADER
2 // $Id: PxConePlugin.cc 3433 2014-07-23 08:17:03Z salam $
3 //
4 // Copyright (c) 2005-2014, 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 
40 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
41 
42 using namespace std;
43 
44 bool PxConePlugin::_first_time = true;
45 
46 string 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  << " (NB: non-standard version of PxCone, containing small bug fixes by Gavin Salam)";
55 
56  return desc.str();
57 }
58 
59 
60 void PxConePlugin::run_clustering(ClusterSequence & clust_seq) const {
61  // print a banner if we run this for the first time
62  //_print_banner(clust_seq.fastjet_banner_stream());
63 
64  // only have hh mode
65  int mode = 2;
66 
67  int ntrak = clust_seq.jets().size(), itkdm = 4;
68  double *ptrak = new double[ntrak*4+1];
69  for (int i = 0; i < ntrak; i++) {
70  ptrak[4*i+0] = clust_seq.jets()[i].px();
71  ptrak[4*i+1] = clust_seq.jets()[i].py();
72  ptrak[4*i+2] = clust_seq.jets()[i].pz();
73  ptrak[4*i+3] = clust_seq.jets()[i].E();
74  }
75 
76  // max number of allowed jets
77  int mxjet = ntrak;
78  int njet;
79  double *pjet = new double[mxjet*5+1];
80  int *ipass = new int[ntrak+1];
81  int *ijmul = new int[mxjet+1];
82  int ierr;
83 
84  // run pxcone
85  pxcone(
86  mode , // 1=>e+e-, 2=>hadron-hadron
87  ntrak , // Number of particles
88  itkdm , // First dimension of PTRAK array:
89  ptrak , // Array of particle 4-momenta (Px,Py,Pz,E)
90  cone_radius() , // Cone size (half angle) in radians
91  min_jet_energy() , // Minimum Jet energy (GeV)
92  overlap_threshold() , // Maximum fraction of overlap energy in a jet
93  mxjet , // Maximum possible number of jets
94  njet , // Number of jets found
95  pjet , // 5-vectors of jets
96  ipass, // Particle k belongs to jet number IPASS(k)-1
97  // IPASS = -1 if not assosciated to a jet
98  ijmul, // Jet i contains IJMUL[i] particles
99  ierr // = 0 if all is OK ; = -1 otherwise
100  );
101 
102  if (ierr != 0) throw Error("An error occurred while running PXCONE");
103 
104  // now transfer information back
105  valarray<int> last_index_created(njet);
106 
107  vector<vector<int> > jet_particle_content(njet);
108 
109  // get a list of particles in each jet
110  for (int itrak = 0; itrak < ntrak; itrak++) {
111  int jet_i = ipass[itrak] - 1;
112  if (jet_i >= 0) jet_particle_content[jet_i].push_back(itrak);
113  }
114 
115  // now transfer the jets back into our own structure -- we will
116  // mimic the cone code with a sequential recombination sequence in
117  // which the jets are built up by adding one particle at a time
118  for(int ipxjet = njet-1; ipxjet >= 0; ipxjet--) {
119  const vector<int> & jet_trak_list = jet_particle_content[ipxjet];
120  int jet_k = jet_trak_list[0];
121 
122  for (unsigned ilist = 1; ilist < jet_trak_list.size(); ilist++) {
123  int jet_i = jet_k;
124  // retrieve our misappropriated index for the jet
125  int jet_j = jet_trak_list[ilist];
126  // do a fake recombination step with dij=0
127  double dij = 0.0;
128  //clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
129  if (ilist != jet_trak_list.size()-1 || E_scheme_jets()) {
130  // our E-scheme recombination in cases where it doesn't matter
131  clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
132  } else {
133  // put in pxcone's momentum for the last recombination so that the
134  // final inclusive jet corresponds exactly to PXCONE's
135  clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij,
136  PseudoJet(pjet[5*ipxjet+0],pjet[5*ipxjet+1],
137  pjet[5*ipxjet+2],pjet[5*ipxjet+3]),
138  jet_k);
139  }
140  }
141 
142  // NB: put a sensible looking d_iB just to be nice...
143  double d_iB = clust_seq.jets()[jet_k].perp2();
144  clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
145  }
146 
147 
148  //// following code is for testing only
149  //cout << endl;
150  //for (int ijet = 0; ijet < njet; ijet++) {
151  // PseudoJet jet(pjet[ijet][0],pjet[ijet][1],pjet[ijet][2],pjet[ijet][3]);
152  // cout << jet.perp() << " " << jet.rap() << endl;
153  //}
154  //cout << "-----------------------------------------------------\n";
155  //vector<PseudoJet> ourjets(clust_seq.inclusive_jets());
156  //for (vector<PseudoJet>::const_iterator ourjet = ourjets.begin();
157  // ourjet != ourjets.end(); ourjet++) {
158  // cout << ourjet->perp() << " " << ourjet->rap() << endl;
159  //}
160  ////cout << endl;
161 
162  delete[] ptrak;
163  delete[] ipass;
164  delete[] ijmul;
165  delete[] pjet;
166 }
167 
168 // print a banner for reference to the 3rd-party code
169 void PxConePlugin::_print_banner(ostream *ostr) const{
170  if (! _first_time) return;
171  _first_time=false;
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 
188 FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
const std::vector< PseudoJet > & jets() const
allow the user to access the internally stored _jets() array, which contains both the initial particl...
deals with clustering
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], with the specified dij, and return the index (newjet_k) allocated to the new jet, whose momentum is assumed to be the 4-vector sum of that of jet_i and jet_j
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...
base class corresponding to errors that can be thrown by FastJet
Definition: Error.hh:47
Class to contain pseudojets, including minimal information of use to jet-clustering routines...
Definition: PseudoJet.hh:67