FastJet  3.1.0-beta.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SISConeSphericalPlugin.cc
1 
2 // fastjet stuff
3 #include "fastjet/ClusterSequence.hh"
4 #include "fastjet/SISConeSphericalPlugin.hh"
5 
6 //// siscone stuff
7 #include "siscone/spherical/momentum.h"
8 #include "siscone/spherical/siscone.h"
9 
10 // other stuff
11 #include<sstream>
12 
13 FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
14 
15 using namespace std;
16 using namespace siscone_spherical;
17 
18 /// shortcut for converting siscone CSphmomentum into PseudoJet
19 template<> PseudoJet::PseudoJet(const siscone_spherical::CSphmomentum & four_vector) {
20  (*this) = PseudoJet(four_vector.px,four_vector.py,four_vector.pz,
21  four_vector.E);
22 }
23 
24 /////////////////////////////////////////////
25 // static members declaration //
26 /////////////////////////////////////////////
27 std::auto_ptr<SISConeSphericalPlugin> SISConeSphericalPlugin::stored_plugin;
28 std::auto_ptr<std::vector<PseudoJet> > SISConeSphericalPlugin::stored_particles;
29 std::auto_ptr<CSphsiscone> SISConeSphericalPlugin::stored_siscone;
30 
31 
32 /////////////////////////////////////////////
33 // now comes the implementation itself //
34 /////////////////////////////////////////////
35 string SISConeSphericalPlugin::description () const {
36  ostringstream desc;
37 
38  const string on = "on";
39  const string off = "off";
40 
41  string sm_scale_string = "split-merge uses " +
42  split_merge_scale_name(Esplit_merge_scale(split_merge_scale()));
43 
44  desc << "Spherical SISCone jet algorithm with " ;
45  desc << "cone_radius = " << cone_radius () << ", ";
46  desc << "overlap_threshold = " << overlap_threshold () << ", ";
47  desc << "n_pass_max = " << n_pass_max () << ", ";
48  desc << "protojet_Emin = " << protojet_Emin() << ", ";
49  desc << sm_scale_string << ", ";
50  desc << "caching turned " << (caching() ? on : off);
51  desc << ", SM stop scale = " << _split_merge_stopping_scale;
52 
53  // add a note to the description if we use the pt-weighted splitting
54  if (_use_E_weighted_splitting){
55  desc << ", using E-weighted splitting";
56  }
57 
58  if (_use_jet_def_recombiner){
59  desc << ", using jet-definition's own recombiner";
60  }
61 
62  // create a fake siscone object so that we can find out more about it
63  CSphsiscone siscone;
64  if (siscone.merge_identical_protocones) {
65  desc << ", and (IR unsafe) merge_indentical_protocones=true" ;
66  }
67 
68  desc << ", SISCone code v" << siscone_version();
69 
70  return desc.str();
71 }
72 
73 
74 // overloading the base class implementation
75 void SISConeSphericalPlugin::run_clustering(ClusterSequence & clust_seq) const {
76 
77  CSphsiscone::set_banner_stream(clust_seq.fastjet_banner_stream());
78 
79  CSphsiscone local_siscone;
80  CSphsiscone * siscone;
81 
82  unsigned n = clust_seq.jets().size();
83 
84  bool new_siscone = true; // by default we'll be running it
85 
86  if (caching()) {
87 
88  // Establish if we have a cached run with the same R, npass and
89  // particles. If not then do any tidying up / reallocation that's
90  // necessary for the next round of caching, otherwise just set
91  // relevant pointers so that we can reuse and old run.
92  if (stored_siscone.get() != 0) {
93  new_siscone = !(stored_plugin->cone_radius() == cone_radius()
94  && stored_plugin->n_pass_max() == n_pass_max()
95  && stored_particles->size() == n);
96  if (!new_siscone) {
97  for(unsigned i = 0; i < n; i++) {
98  // only check momentum because indices will be correctly dealt
99  // with anyway when extracting the clustering order.
100  new_siscone |= !have_same_momentum(clust_seq.jets()[i],
101  (*stored_particles)[i]);
102  }
103  }
104  }
105 
106  // allocate the new siscone, etc., if need be
107  if (new_siscone) {
108  stored_siscone .reset( new CSphsiscone );
109  stored_particles.reset( new std::vector<PseudoJet>(clust_seq.jets()));
110  reset_stored_plugin();
111  }
112 
113  siscone = stored_siscone.get();
114  } else {
115  siscone = &local_siscone;
116  }
117 
118  // make sure stopping scale is set in siscone
119  siscone->SM_var2_hardest_cut_off = _split_merge_stopping_scale*_split_merge_stopping_scale;
120 
121  // set the specific parameters
122  // when running with ghosts for passive areas, do not put the
123  // ghosts into the stable-cone search (not relevant)
124  siscone->stable_cone_soft_E2_cutoff = ghost_separation_scale()
125  * ghost_separation_scale();
126  // set the type of splitting we want (default=std one, true->pt-weighted split)
127  siscone->set_E_weighted_splitting(_use_E_weighted_splitting);
128 
129 
130  if (new_siscone) {
131  // transfer fastjet initial particles into the siscone type
132  std::vector<CSphmomentum> siscone_momenta(n);
133  for(unsigned i = 0; i < n; i++) {
134  const PseudoJet & p = clust_seq.jets()[i]; // shorthand
135  siscone_momenta[i] = CSphmomentum(p.px(), p.py(), p.pz(), p.E());
136  }
137 
138  // run the jet finding
139  //cout << "plg sms: " << split_merge_scale() << endl;
140  siscone->compute_jets(siscone_momenta, cone_radius(), overlap_threshold(),
141  n_pass_max(), protojet_or_ghost_Emin(),
142  Esplit_merge_scale(split_merge_scale()));
143  } else {
144  // rerun the jet finding
145  // just run the overlap part of the jets.
146  //cout << "plg rcmp sms: " << split_merge_scale() << endl;
147  siscone->recompute_jets(overlap_threshold(), protojet_or_ghost_Emin(),
148  Esplit_merge_scale(split_merge_scale()));
149  }
150 
151  // extract the jets [in reverse order -- to get nice ordering in pt at end]
152  int njet = siscone->jets.size();
153 
154  // allocate space for the extras object
156 
157  for (int ijet = njet-1; ijet >= 0; ijet--) {
158  const CSphjet & jet = siscone->jets[ijet]; // shorthand
159 
160  // Successively merge the particles that make up the cone jet
161  // until we have all particles in it. Start off with the zeroth
162  // particle.
163  int jet_k = jet.contents[0];
164  for (unsigned ipart = 1; ipart < jet.contents.size(); ipart++) {
165  // take the last result of the merge
166  int jet_i = jet_k;
167  // and the next element of the jet
168  int jet_j = jet.contents[ipart];
169  // and merge them (with a fake dij)
170  double dij = 0.0;
171 
172  if (_use_jet_def_recombiner) {
173  clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, jet_k);
174  } else {
175  // create the new jet by hand so that we can adjust its user index
176  PseudoJet newjet = clust_seq.jets()[jet_i] + clust_seq.jets()[jet_j];
177  // set the user index to be the pass in which the jet was discovered
178  // *** The following line was commented for 3.0.1 ***
179  //newjet.set_user_index(jet.pass);
180  clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, newjet, jet_k);
181  }
182 
183  }
184 
185  // we have merged all the jet's particles into a single object, so now
186  // "declare" it to be a beam (inclusive) jet.
187  // [NB: put a sensible looking d_iB just to be nice...]
188  double d_iB = clust_seq.jets()[jet_k].perp2();
189  clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
190 
191  // now record the pass of the jet in the extras object
192  extras->_pass[clust_seq.jets()[jet_k].cluster_hist_index()] = jet.pass;
193  }
194 
195  // now copy the list of protocones into an "extras" objects
196  for (unsigned ipass = 0; ipass < siscone->protocones_list.size(); ipass++) {
197  for (unsigned ipc = 0; ipc < siscone->protocones_list[ipass].size(); ipc++) {
198  PseudoJet protocone(siscone->protocones_list[ipass][ipc]);
199  protocone.set_user_index(ipass);
200  extras->_protocones.push_back(protocone);
201  }
202  }
203  extras->_most_ambiguous_split = siscone->most_ambiguous_split;
204 
205  // tell it what the jet definition was
206  extras->_jet_def_plugin = this;
207 
208  // give the extras object to the cluster sequence.
209  //
210  // As of v3.1 of FastJet, extras are automatically owned (as
211  // SharedPtr) by the ClusterSequence and auto_ptr is deprecated. So
212  // we can use a simple pointer here
213  clust_seq.plugin_associate_extras(extras);
214 }
215 
216 void SISConeSphericalPlugin::reset_stored_plugin() const{
217  stored_plugin.reset( new SISConeSphericalPlugin(*this));
218 }
219 
220 
221 FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh