FastJet  3.3.1
D0RunIBaseConePlugin.cc
1 //FJSTARTHEADER
2 // $Id: D0RunIBaseConePlugin.cc 1779 2010-10-25 10:32:59Z soyez $
3 //
4 // Copyright (c) 2009-2018, 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 // D0 stuff
32 // apparently this has to go first to avoid a problem with gcc-4.0.1 builds on Macs
33 #include <list>
34 #include "ConeClusterAlgo.hpp"
35 #include "HepEntityIpre96.h"
36 #include "HepEntityI.h"
37 
38 #include "fastjet/D0RunIBaseConePlugin.hh"
39 #include "fastjet/D0RunIpre96ConePlugin.hh"
40 #include "fastjet/D0RunIConePlugin.hh"
41 #include "fastjet/ClusterSequence.hh"
42 #include "fastjet/Error.hh"
43 #include <sstream>
44 
45 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
46 
47 using namespace std;
48 using namespace d0runi;
49 
50 /////////////////////////////////////////////
51 // //
52 // D0RunIBaseConePlugin implementation //
53 // //
54 /////////////////////////////////////////////
55 
56 const double D0RunIBaseConePlugin::_DEFAULT_SPLifr = 0.5; //shared Et fraction threshold
57 const double D0RunIBaseConePlugin::_DEFAULT_TWOrad = 0.;
58 const bool D0RunIBaseConePlugin::_DEFAULT_D0_Angle = false;
59 const bool D0RunIBaseConePlugin::_DEFAULT_Increase_Delta_R = true;
60 const bool D0RunIBaseConePlugin::_DEFAULT_Kill_Far_Clusters = true;
61 const bool D0RunIBaseConePlugin::_DEFAULT_Jet_Et_Min_On_Iter = true;
62 const double D0RunIBaseConePlugin::_DEFAULT_Far_Ratio = 0.5;
63 const double D0RunIBaseConePlugin::_DEFAULT_Eitem_Negdrop = -1.0;
64 const double D0RunIBaseConePlugin::_DEFAULT_Et_Min_Ratio = 0.5;
65 const double D0RunIBaseConePlugin::_DEFAULT_Thresh_Diff_Et = 0.01;
66 
67 
68 // for the real work, we write a template class that decides which
69 // HepEntity type to use
70 template<typename HepEntityType>
71 void D0RunIBaseConePlugin::run_clustering_worker(ClusterSequence & clust_seq) const{
72  // create the entities needed by the D0 code
73  vector<HepEntityType> entities(clust_seq.jets().size());
74  list<const HepEntityType * > ensemble;
75  for (unsigned i = 0; i < clust_seq.jets().size(); i++) {
76  entities[i].Fill(clust_seq.jets()[i].E(),
77  clust_seq.jets()[i].px(),
78  clust_seq.jets()[i].py(),
79  clust_seq.jets()[i].pz(),
80  i);
81  // use only the particles that do not have infinite rapidity
82  if (abs(entities[i].pz() ) < entities[i].E() ) {
83  ensemble.push_back(& (entities[i]));
84  }
85  }
86 
87  // prepare the D0 algorithm
88  ConeClusterAlgo<HepEntityType>
89  RunIconeAlgo(CONErad(),
90  JETmne(),
91  TWOrad(),
92  SPLifr(),
93  D0_Angle(),
94  Increase_Delta_R(),
95  Kill_Far_Clusters(),
96  Jet_Et_Min_On_Iter(),
97  Far_Ratio(),
98  Eitem_Negdrop(),
99  Et_Min_Ratio(),
100  Thresh_Diff_Et());
101 
102 
103  // run the algorithm
104  float Zvertex = 0.;
105  list<HepEntityType> jets;
106  RunIconeAlgo.makeClusters(jets, ensemble, Zvertex);
107 
108  // now transfer the information about the jets into the
109  // FastJet structure
110  for(int i = RunIconeAlgo.TempColl.size()-1; i >= 0; i--) {
111 
112  std::list<const HepEntityType*> tlist = RunIconeAlgo.TempColl[i].LItems();
113  typename std::list<const HepEntityType*>::iterator tk;
114 
115  // get first particle in list
116  tk = tlist.begin();
117  int jet_k = (*tk)->index;
118 
119  // GS addition: in order to use the proper recombination scheme
120  // used by D0 we need to keep track of the sum as a
121  // "HepEntityType"
122  HepEntityType jet_current_momentum = *(*tk);
123 
124  // now merge with remaining particles in list
125  tk++;
126  for (; tk != tlist.end(); tk++) {
127  int jet_i = jet_k;
128  int jet_j = (*tk)->index;
129  // do a fake recombination step with dij=0
130  double dij = 0.0;
131 
132  // GS addition: find the new momentum and convert that into a
133  // pseudo-jet
134  jet_current_momentum.Add(**tk);
135  PseudoJet new_mom(jet_current_momentum.px(), jet_current_momentum.py(),
136  jet_current_momentum.pz(), jet_current_momentum.E());
137 
138  clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, new_mom, jet_k);
139  }
140 
141  // NB: put a sensible looking d_iB just to be nice...
142  double d_iB = clust_seq.jets()[jet_k].perp2();
143  clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
144  }
145 }
146 
147 
148 /////////////////////////////////////////////
149 // //
150 // D0RunIpre96ConePlugin implementation //
151 // //
152 /////////////////////////////////////////////
153 
154 bool D0RunIpre96ConePlugin::_first_time=true;
155 
156 string D0RunIpre96ConePlugin::description () const {
157  ostringstream desc;
158 
159  desc << "D0 Run I (pre 96) cone jet algorithm, with ";
160  desc << "cone_radius = " << CONErad () << ", "
161  << "min_jet_Et = " << JETmne () << ", "
162  << "split_fraction = " << SPLifr ();
163 
164  return desc.str();
165 }
166 
167 void D0RunIpre96ConePlugin::run_clustering(ClusterSequence & clust_seq) const {
168  // print a banner if we run this for the first time
169  _print_banner(clust_seq.fastjet_banner_stream());
170 
171  run_clustering_worker<HepEntityIpre96>(clust_seq);
172 }
173 
174 // print a banner for reference to the 3rd-party code
175 void D0RunIpre96ConePlugin::_print_banner(ostream *ostr) const{
176  if (! _first_time) return;
177  _first_time=false;
178 
179  // make sure the user has not set the banner stream to NULL
180  if (!ostr) return;
181 
182  (*ostr) << "#--------------------------------------------------------------------------" << endl;
183  (*ostr) << "# You are running the D0 Run I (pre96) Cone plugin for FastJet " << endl;
184  (*ostr) << "# Original code by the D0 collaboration, provided by Lars Sonnenschein; " << endl;
185  (*ostr) << "# interface by FastJet authors " << endl;
186  (*ostr) << "# If you use this plugin, please cite " << endl;
187  (*ostr) << "# B. Abbott et al. [D0 Collaboration], FERMILAB-PUB-97-242-E. " << endl;
188  (*ostr) << "# in addition to the usual FastJet reference. " << endl;
189  (*ostr) << "#--------------------------------------------------------------------------" << endl;
190 
191  // make sure we really have the output done.
192  ostr->flush();
193 }
194 
195 
196 /////////////////////////////////////////////
197 // //
198 // D0RunIConePlugin implementation //
199 // //
200 /////////////////////////////////////////////
201 
202 bool D0RunIConePlugin::_first_time=true;
203 
204 string D0RunIConePlugin::description () const {
205  ostringstream desc;
206 
207  desc << "D0 Run I cone jet algorithm, with ";
208  desc << "cone_radius = " << CONErad () << ", "
209  << "min_jet_Et = " << JETmne () << ", "
210  << "split_fraction = " << SPLifr ();
211 
212  return desc.str();
213 }
214 
215 void D0RunIConePlugin::run_clustering(ClusterSequence & clust_seq) const {
216  // print a banner if we run this for the first time
217  _print_banner(clust_seq.fastjet_banner_stream());
218 
219  run_clustering_worker<HepEntityI>(clust_seq);
220 }
221 
222 // print a banner for reference to the 3rd-party code
223 void D0RunIConePlugin::_print_banner(ostream *ostr) const{
224  if (! _first_time) return;
225  _first_time=false;
226 
227  // make sure the user has not set the banner stream to NULL
228  if (!ostr) return;
229 
230  (*ostr) << "#--------------------------------------------------------------------------" << endl;
231  (*ostr) << "# You are running the D0 Run I Cone plugin for FastJet " << endl;
232  (*ostr) << "# Original code provided by Lars Sonnenschein; interface by FastJet authors" << endl;
233  (*ostr) << "# If you use this plugin, please cite " << endl;
234  (*ostr) << "# B. Abbott et al. [D0 Collaboration], FERMILAB-PUB-97-242-E. " << endl;
235  (*ostr) << "# in addition to the usual FastJet reference. " << endl;
236  (*ostr) << "#--------------------------------------------------------------------------" << endl;
237 
238  // make sure we really have the output done.
239  ostr->flush();
240 }
241 
242 
243 
244 FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
deals with clustering
static std::ostream * fastjet_banner_stream()
returns a pointer to the stream to be used to print banners (cout by default).