CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastPrunePlugin.cc
Go to the documentation of this file.
1 // $Id: FastPrunePlugin.cc,v 1.1 2011/04/25 04:19:54 srappocc Exp $
3 //
4 // Implements the FastPrunePlugin class. See FastPrunePlugin.hh for a
5 // description.
6 //
8 
9 #include "RecoJets/JetAlgorithms/interface/FastPrunePlugin.hh"
10 
11 #include <sstream>
12 #include <cmath>
13 #include <vector>
14 #include <algorithm>
15 using namespace std;
16 
17 using namespace fastjet;
18 
19 FastPrunePlugin::FastPrunePlugin (const JetDefinition & find_definition,
20  const JetDefinition & prune_definition,
21  const double & zcut,
22  const double & Rcut_factor) :
23  _find_definition(find_definition),
24  _prune_definition(prune_definition),
25  _minpT(20.),
26  _unpruned_seq(NULL),
27  _pruned_recombiner(0),
28  _cut_setter(new DefaultCutSetter(zcut, Rcut_factor))
29 {
30  // If the passed prune_definition (copied into _prune_def) has an external
31  // recombiner, use it. Otherwise, create our own DefaultRecombiner. We
32  // could just point to _prune_definition's DefaultRecombiner, but FastJet
33  // actually sets this to use external_scheme later when we set
34  // _prune_definition's Recombiner to be a PrunedRecombiner. (Calling
35  // JetDefinition::set_recombiner() also calls jetdef._default_recombiner =
36  // DefaultRecombiner(external_scheme) as a sanity check to keep you from
37  // using it.)
38  RecombinationScheme scheme = _prune_definition.recombination_scheme();
39  if (scheme == external_scheme)
40  _pruned_recombiner = new PrunedRecombiner(_prune_definition.recombiner(), zcut, 0.0);
41  else
42  _pruned_recombiner = new PrunedRecombiner(scheme, zcut, 0.0);
43 }
44 
45 FastPrunePlugin::FastPrunePlugin (const JetDefinition & find_definition,
46  const JetDefinition & prune_definition,
47  const JetDefinition::Recombiner* recomb,
48  const double & zcut,
49  const double & Rcut_factor) :
50  _find_definition(find_definition),
51  _prune_definition(prune_definition),
52  _minpT(20.),
53  _unpruned_seq(NULL),
54  _pruned_recombiner(new PrunedRecombiner(recomb, zcut, 0.0)),
55  _cut_setter(new DefaultCutSetter(zcut, Rcut_factor))
56 {}
57 
58 FastPrunePlugin::FastPrunePlugin (const JetDefinition & find_definition,
59  const JetDefinition & prune_definition,
60  CutSetter* const cut_setter) :
61  _find_definition(find_definition),
62  _prune_definition(prune_definition),
63  _minpT(20.),
64  _unpruned_seq(NULL),
65  _pruned_recombiner(0),
66  _cut_setter(cut_setter)
67 {
68  // See comments in first constructor
69  RecombinationScheme scheme = _prune_definition.recombination_scheme();
70  if (scheme == external_scheme)
71  _pruned_recombiner = new PrunedRecombiner(_prune_definition.recombiner());
72  else
73  _pruned_recombiner = new PrunedRecombiner(scheme);
74 }
75 
76 FastPrunePlugin::FastPrunePlugin (const JetDefinition & find_definition,
77  const JetDefinition & prune_definition,
78  CutSetter* const cut_setter,
79  const JetDefinition::Recombiner* recomb) :
80  _find_definition(find_definition),
81  _prune_definition(prune_definition),
82  _minpT(20.),
83  _unpruned_seq(NULL),
84  _pruned_recombiner(new PrunedRecombiner(recomb)),
85  _cut_setter(cut_setter)
86 {}
87 
88 string FastPrunePlugin::description () const {
89  ostringstream desc;
90 
91  desc << "Pruned jet algorithm \n"
92  << "----------------------- \n"
93  << "Jet finder: " << _find_definition.description()
94  << "\n----------------------- \n"
95  << "Prune jets with: " << _prune_definition.description()
96  << "\n----------------------- \n"
97  << "Pruning parameters: "
98  << "zcut = " << _cut_setter->zcut << ", "
99  << "Rcut_factor = ";
100  if (DefaultCutSetter *cs = dynamic_cast<DefaultCutSetter*>(_cut_setter))
101  desc << cs->Rcut_factor;
102  else
103  desc << "[dynamic]";
104  desc << "\n"
105  << "----------------------- \n" ;
106 
107  return desc.str();
108 }
109 
110 // Meat of the plugin. This function takes the input particles from input_seq
111 // and calls plugin_record_{ij, iB}_recombination repeatedly such that
112 // input_seq holds a cluster sequence corresponding to pruned jets
113 // This function first creates unpruned jets using _find_definition, then uses
114 // the prune_definition, along with the PrunedRecombiner, on each jet to
115 // produce a pruned jet. For each of these jets, output_mergings() is called,
116 // which reads the history of the pruned sequence and calls the
117 // plugin_record functions of input_seq to match this history.
118 // Branches that are pruned appear in the history as PseudoJets with no
119 // children. For this reason, only inclusive_jets() is sensible to use with
120 // the final ClusterSequence. The substructure, e.g., constituents() of a
121 // pruned jet will not include the pruned away branchings.
122 void FastPrunePlugin::run_clustering(ClusterSequence & input_seq) const {
123 
124  // this will be filled in the output_mergings() step
125  _pruned_subjets.clear();
126 
127  vector<PseudoJet> inputs = input_seq.jets();
128  // Record user_index's so we can match PJ's in pruned jets to PJ's in
129  // input_seq.
130  // Use i+1 to distinguish from the default, which in some places appears to
131  // be 0.
132  // Note that we're working with a local copy of the input jets, so we don't
133  // change the indices in input_seq.
134  for (unsigned int i = 0; i < inputs.size(); i++)
135  inputs[i].set_user_index(i+1);
136 
137  // ClusterSequence for initial (unpruned) jet finding
138  if(_unpruned_seq) delete _unpruned_seq;
139  _unpruned_seq = new ClusterSequence(inputs, _find_definition);
140 
141  // now, for each jet, construct a pruned version:
142  vector<PseudoJet> unpruned_jets =
143  sorted_by_pt(_unpruned_seq->inclusive_jets(_minpT));
144 
145  for (unsigned int i = 0; i < unpruned_jets.size(); i++) {
146  _cut_setter->SetCuts(unpruned_jets[i], *_unpruned_seq);
147  _pruned_recombiner->reset(_cut_setter->zcut, _cut_setter->Rcut);
148  _prune_definition.set_recombiner(_pruned_recombiner);
149 
150  // temp way to get constituents, to compare to new version
151  vector<PseudoJet> constituents;
152  for (size_t j = 0; j < inputs.size(); ++j)
153  if (_unpruned_seq->object_in_jet(inputs[j], unpruned_jets[i])) {
154  constituents.push_back(inputs[j]);
155  }
156  ClusterSequence pruned_seq(constituents, _prune_definition);
157 
158  vector<int> pruned_PJs = _pruned_recombiner->pruned_pseudojets();
159  _output_mergings(pruned_seq, pruned_PJs, input_seq);
160  }
161 }
162 
163 
164 // Takes the merging structure of "in_seq" and feeds this into "out_seq" using
165 // _plugin_record_{ij,iB}_recombination().
166 // PJ's in the input CS should have user_index's that are their (index+1) in
167 // _jets() in the output CS (the output CS should be the input CS to
168 // run_clustering()).
169 // This allows us to build up the same jet in out_seq as already exists in
170 // in_seq.
171 void FastPrunePlugin::_output_mergings(ClusterSequence & in_seq,
172  vector<int> & pruned_pseudojets,
173  ClusterSequence & out_seq) const {
174  // vector to store the pruned subjets for this jet
175  vector<PseudoJet> temp_pruned_subjets;
176 
177  vector<PseudoJet> p = in_seq.jets();
178 
179  // sort this vector so we can binary search it
180  sort(pruned_pseudojets.begin(), pruned_pseudojets.end());
181 
182  // get the history from in_seq
183  const vector<ClusterSequence::history_element> & hist = in_seq.history();
184  vector<ClusterSequence::history_element>::const_iterator
185  iter = hist.begin();
186 
187  // skip particle input elements
188  while (iter->parent1 == ClusterSequence::InexistentParent)
189  iter++;
190 
191  // Walk through history. PseudoJets in in_seq should have a user_index
192  // corresponding to their index in out_seq. Note that when we create a
193  // new PJ via record_ij we need to set the user_index of our local copy.
194  for (; iter != hist.end(); iter++) {
195  int new_jet_index = -1;
196  int jet_index = iter->jetp_index;
197  int parent1 = iter->parent1;
198  int parent2 = iter->parent2;
199  int parent1_index = p[hist[iter->parent1].jetp_index].user_index() - 1;
200 
201  if (parent2 == ClusterSequence::BeamJet) {
202  out_seq.plugin_record_iB_recombination(parent1_index, iter->dij);
203  } else {
204  int parent2_index = p[hist[parent2].jetp_index].user_index() - 1;
205 
206  // Check if either parent is stored in pruned_pseudojets
207  // Note that it is the history index that is stored
208  if (binary_search(pruned_pseudojets.begin(), pruned_pseudojets.end(),
209  parent2)) {
210  // pruned away parent2 -- just give child parent1's index
211  p[jet_index].set_user_index(p[hist[parent1].jetp_index].user_index());
212  temp_pruned_subjets.push_back(out_seq.jets()[parent2_index]);
213  } else if (binary_search(pruned_pseudojets.begin(), pruned_pseudojets.end(),
214  parent1)) {
215  // pruned away parent1 -- just give child parent2's index
216  p[jet_index].set_user_index(p[hist[parent2].jetp_index].user_index());
217  temp_pruned_subjets.push_back(out_seq.jets()[parent1_index]);
218  } else {
219  // no pruning -- record combination and index for child
220  out_seq.plugin_record_ij_recombination(parent1_index, parent2_index,
221  iter->dij, new_jet_index);
222  p[jet_index].set_user_index(new_jet_index + 1);
223  }
224  }
225  }
226 
227  _pruned_subjets.push_back(temp_pruned_subjets);
228 }
229 
230 
int i
Definition: DBlmapReader.cc:9
auto_ptr< ClusterSequence > cs
#define NULL
Definition: scimark2.h:8
int j
Definition: DBlmapReader.cc:9
tuple description
Definition: idDealer.py:66