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