Fork me on GitHub

source: svn/trunk/Utilities/Fastjet/plugins/SISCone/SISConePlugin.cc@ 240

Last change on this file since 240 was 11, checked in by severine ovyn, 16 years ago

Fastjet added; CDFCones directory has been changed

File size: 7.3 KB
RevLine 
[11]1
2// fastjet stuff
3#include "Utilities/Fastjet/include/fastjet/ClusterSequence.hh"
4#include "SISConePlugin.hh"
5
6// scones stuff
7#include "interface/momentum.h"
8#include "interface/siscone.h"
9
10// other stuff
11#include<sstream>
12
13FASTJET_BEGIN_NAMESPACE // defined in fastjet/internal/base.hh
14
15using namespace std;
16using namespace siscone;
17
18// the static objects
19auto_ptr<SISConePlugin > SISConePlugin::stored_plugin ;
20auto_ptr<vector<PseudoJet> > SISConePlugin::stored_particles ;
21auto_ptr<Csiscone > SISConePlugin::stored_siscone ;
22
23string SISConePlugin::description () const {
24 ostringstream desc;
25
26 const string on = "on";
27 const string off = "off";
28
29 string sm_scale_string = "split-merge uses " +
30 split_merge_scale_name(Esplit_merge_scale(split_merge_scale()));
31
32 desc << "SISCone jet algorithm with " ;
33 desc << "cone_radius = " << cone_radius () << ", ";
34 desc << "overlap_threshold = " << overlap_threshold () << ", ";
35 desc << "n_pass_max = " << n_pass_max () << ", ";
36 desc << "protojet_ptmin = " << protojet_ptmin() << ", ";
37 desc << sm_scale_string << ", ";
38 desc << "caching turned " << (caching() ? on : off);
39 desc << ", SM stop scale = " << _split_merge_stopping_scale;
40
41
42 // create a fake siscone object so that we can find out more about it
43 Csiscone siscone;
44 if (siscone.merge_identical_protocones) {
45 desc << ", and (IR unsafe) merge_indentical_protocones=true" ;
46 }
47
48 desc << ", SISCone code v" << siscone_version();
49
50 return desc.str();
51}
52
53
54/// shortcut for converting siscone Cmomentum into PseudoJet
55template<> PseudoJet::PseudoJet(const Cmomentum & four_vector) {
56 (*this) = PseudoJet(four_vector.px,four_vector.py,four_vector.pz,
57 four_vector.E);
58}
59
60
61void SISConePlugin::run_clustering(ClusterSequence & clust_seq) const {
62
63
64 Csiscone * siscone;
65 Csiscone local_siscone;
66
67 unsigned n = clust_seq.jets().size();
68
69 bool new_siscone = true; // by default we'll be running it
70
71 if (caching()) {
72
73 // Establish if we have a cached run with the same R, npass and
74 // particles. If not then do any tidying up / reallocation that's
75 // necessary for the next round of caching, otherwise just set
76 // relevant pointers so that we can reuse and old run.
77 if (stored_siscone.get() != 0) {
78 new_siscone = !(stored_plugin->cone_radius() == cone_radius()
79 && stored_plugin->n_pass_max() == n_pass_max()
80 && stored_particles->size() == n);
81 if (!new_siscone) {
82 for(unsigned i = 0; i < n; i++) {
83 // only check momentum because indices will be correctly dealt
84 // with anyway when extracting the clustering order.
85 new_siscone |= !have_same_momentum(clust_seq.jets()[i],
86 (*stored_particles)[i]);
87 }
88 }
89 }
90
91 // allocate the new siscone, etc., if need be
92 if (new_siscone) {
93 stored_siscone .reset( new Csiscone );
94 stored_particles.reset( new vector<PseudoJet>(clust_seq.jets()));
95 stored_plugin .reset( new SISConePlugin(*this) );
96 }
97
98 siscone = stored_siscone.get();
99 } else {
100 siscone = &local_siscone;
101 }
102
103 // make sure stopping scale is set in siscone
104 siscone->SM_var2_hardest_cut_off = _split_merge_stopping_scale*_split_merge_stopping_scale;
105 // when running with ghosts for passive areas, do not put the
106 // ghosts into the stable-cone search (not relevant)
107 siscone->stable_cone_soft_pt2_cutoff = ghost_separation_scale()
108 * ghost_separation_scale();
109
110 if (new_siscone) {
111 // transfer fastjet initial particles into the siscone type
112 vector<Cmomentum> siscone_momenta(n);
113 for(unsigned i = 0; i < n; i++) {
114 const PseudoJet & p = clust_seq.jets()[i]; // shorthand
115 siscone_momenta[i] = Cmomentum(p.px(), p.py(), p.pz(), p.E());
116 }
117
118 // run the jet finding
119 //cout << "plg sms: " << split_merge_scale() << endl;
120 siscone->compute_jets(siscone_momenta, cone_radius(), overlap_threshold(),
121 n_pass_max(), protojet_or_ghost_ptmin(),
122 Esplit_merge_scale(split_merge_scale()));
123 } else {
124 // just run the overlap part of the jets.
125 //cout << "plg rcmp sms: " << split_merge_scale() << endl;
126 siscone->recompute_jets(overlap_threshold(), protojet_or_ghost_ptmin(),
127 Esplit_merge_scale(split_merge_scale()));
128 }
129
130 // extract the jets [in reverse order -- to get nice ordering in pt at end]
131 int njet = siscone->jets.size();
132
133 for (int ijet = njet-1; ijet >= 0; ijet--) {
134 const Cjet & jet = siscone->jets[ijet]; // shorthand
135
136 // Successively merge the particles that make up the cone jet
137 // until we have all particles in it. Start off with the zeroth
138 // particle.
139 int jet_k = jet.contents[0];
140 for (unsigned ipart = 1; ipart < jet.contents.size(); ipart++) {
141 // take the last result of the merge
142 int jet_i = jet_k;
143 // and the next element of the jet
144 int jet_j = jet.contents[ipart];
145 // and merge them (with a fake dij)
146 double dij = 0.0;
147
148 // create the new jet by hand so that we can adjust its user index
149 PseudoJet newjet = clust_seq.jets()[jet_i] + clust_seq.jets()[jet_j];
150
151 // set the user index to be the pass in which the jet was discovered
152 newjet.set_user_index(jet.pass);
153
154 clust_seq.plugin_record_ij_recombination(jet_i, jet_j, dij, newjet, jet_k);
155 }
156 // we have merged all the jet's particles into a single object, so now
157 // "declare" it to be a beam (inclusive) jet.
158 // [NB: put a sensible looking d_iB just to be nice...]
159 double d_iB = clust_seq.jets()[jet_k].perp2();
160 clust_seq.plugin_record_iB_recombination(jet_k, d_iB);
161 }
162
163 // now copy the list of protocones into an "extras" objects
164 SISConeExtras * extras = new SISConeExtras;
165 for (unsigned ipass = 0; ipass < siscone->protocones_list.size(); ipass++) {
166 for (unsigned ipc = 0; ipc < siscone->protocones_list[ipass].size(); ipc++) {
167 double rap = siscone->protocones_list[ipass][ipc].eta;
168 double phi = siscone->protocones_list[ipass][ipc].phi;
169 PseudoJet protocone(cos(phi),sin(phi),sinh(rap),cosh(rap));
170 //PseudoJet protocone(siscone->protocones_list[ipass][ipc]);
171 protocone.set_user_index(ipass);
172 extras->_protocones.push_back(protocone);
173 }
174 }
175 extras->_most_ambiguous_split = siscone->most_ambiguous_split;
176
177 // tell it what the jet definition was
178 extras->_jet_def_plugin = this;
179
180 // give the extras object to the cluster sequence.
181 clust_seq.plugin_associate_extras(auto_ptr<ClusterSequence::Extras>(extras));
182}
183
184
185///
186string SISConeExtras::description() const {
187 ostringstream ostr;
188 ostr << "This SISCone clustering found " << protocones().size()
189 << " stable protocones";
190 return ostr.str();
191}
192
193// OBSOLETE CODE
194//// temporary, for dealing with warnings...
195//if (siscone.n_warnings > 0) {
196// // print the event (very dirty...)
197// cout.precision(14);
198// cout << "Culprit event is:" << endl;
199// for (int i = 0; i < n; i++) {
200// const PseudoJet & p = clust_seq.jets()[i]; // shorthand
201// cout << p.px() << " " << p.py() << " " << p.pz() << " " << p.E() << endl;
202// }
203//}
204
205
206FASTJET_END_NAMESPACE // defined in fastjet/internal/base.hh
Note: See TracBrowser for help on using the repository browser.