CMS 3D CMS Logo

ReclusterJets.cc
Go to the documentation of this file.
1 #include <memory>
2 
5 #include "fastjet/tools/Pruner.hh"
6 
7 using namespace std;
8 
9 //using namespace std;
10 using namespace fastjet;
11 
12 namespace heppy {
13 
14  ReclusterJets::ReclusterJets(const std::vector<LorentzVector> &objects, double ktpower, double rparam)
15  : ktpower_(ktpower), rparam_(rparam) {
16  // define jet inputs
17  fjInputs_.clear();
18  int index = 0;
19  for (const LorentzVector &o : objects) {
20  fastjet::PseudoJet j(o.Px(), o.Py(), o.Pz(), o.E());
21  j.set_user_index(index);
22  index++; // in case we want to know which piece ended where
23  fjInputs_.push_back(j);
24  }
25 
26  // choose a jet definition
27  fastjet::JetDefinition jet_def;
28 
29  // prepare jet def
30  if (ktpower_ == 1.0) {
31  jet_def = JetDefinition(kt_algorithm, rparam_);
32  } else if (ktpower_ == 0.0) {
33  jet_def = JetDefinition(cambridge_algorithm, rparam_);
34  } else if (ktpower_ == -1.0) {
35  jet_def = JetDefinition(antikt_algorithm, rparam_);
36  } else {
37  throw cms::Exception("InvalidArgument", "Unsupported ktpower value");
38  }
39 
40  // print out some infos
41  // cout << "Clustering with " << jet_def.description() << endl;
43  // define jet clustering sequence
44  fjClusterSeq_ = std::make_shared<fastjet::ClusterSequence>(fjInputs_, jet_def);
45  }
46 
47  std::vector<math::XYZTLorentzVector> ReclusterJets::makeP4s(const std::vector<fastjet::PseudoJet> &jets) {
48  std::vector<math::XYZTLorentzVector> JetObjectsAll;
49  JetObjectsAll.reserve(jets.size());
50  for (const fastjet::PseudoJet &pj : jets) {
51  JetObjectsAll.push_back(LorentzVector(pj.px(), pj.py(), pj.pz(), pj.e()));
52  }
53  return JetObjectsAll;
54  }
55  std::vector<math::XYZTLorentzVector> ReclusterJets::getGrouping(double ptMin) {
56  // recluster jet
57  inclusiveJets_ = fastjet::sorted_by_pt(fjClusterSeq_->inclusive_jets(ptMin));
58  // return
59  return makeP4s(inclusiveJets_);
60  }
61 
62  std::vector<math::XYZTLorentzVector> ReclusterJets::getGroupingExclusive(double dcut) {
63  // recluster jet
64  exclusiveJets_ = fastjet::sorted_by_pt(fjClusterSeq_->exclusive_jets(dcut));
65  // return
66  return makeP4s(exclusiveJets_);
67  }
68 
69  std::vector<math::XYZTLorentzVector> ReclusterJets::getGroupingExclusive(int njets) {
70  // recluster jet
71  exclusiveJets_ = fastjet::sorted_by_pt(fjClusterSeq_->exclusive_jets(njets));
72  // return
73  return makeP4s(exclusiveJets_);
74  }
75 
77  // cluster everything first
78  exclusiveJets_ = fastjet::sorted_by_pt(fjClusterSeq_->exclusive_jets(1));
79  // get pruned exclusive
80  return getPrunedSubjetExclusive(0, zcut, rcutFactor);
81  }
82 
84  double zcut,
85  double rcutFactor) {
86  if (isubjet >= exclusiveJets_.size()) {
87  throw cms::Exception("InvalidArgument", "getPrunedSubjetExclusive called for non-existing exclusive subjet");
88  }
89  return getPruned(exclusiveJets_[isubjet], zcut, rcutFactor);
90  }
92  double zcut,
93  double rcutFactor) {
94  if (isubjet >= inclusiveJets_.size()) {
95  throw cms::Exception("InvalidArgument", "getPrunedSubjetInclusive called for non-existing inclusive subjet");
96  }
97  return getPruned(inclusiveJets_[isubjet], zcut, rcutFactor);
98  }
99 
100  math::XYZTLorentzVector ReclusterJets::getPruned(const fastjet::PseudoJet &jet, double zcut, double rcutFactor) {
101  // create pruner
102  fastjet::Pruner pruner(fastjet::cambridge_algorithm, zcut, rcutFactor);
103  // Prune the jet
104  fastjet::PseudoJet pruned_jet = pruner(jet);
105  return LorentzVector(pruned_jet.px(), pruned_jet.py(), pruned_jet.pz(), pruned_jet.e());
106  }
107 
108 } // namespace heppy
math::XYZTLorentzVector LorentzVector
Definition: ReclusterJets.h:21
std::vector< fastjet::PseudoJet > fjInputs_
Definition: ReclusterJets.h:51
std::vector< LorentzVector > getGroupingExclusive(int njets)
get grouping (exclusive jets, until n are left)
constexpr float ptMin
LorentzVector getPrunedSubjetInclusive(unsigned int isubjet, double zcut, double rcutFactor)
get pruned 4-vector for a given subject (must be called after getGroupingInclusive) ...
std::vector< LorentzVector > getGrouping(double ptMin=0.0)
get grouping (inclusive jets)
std::vector< fastjet::PseudoJet > exclusiveJets_
Definition: ReclusterJets.h:60
ClusterSequencePtr fjClusterSeq_
Definition: ReclusterJets.h:58
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
TAKEN FROM http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/CMSSW/ElectroWeakAnalysis/Utilities/src/PdfWeig...
Definition: AlphaT.h:16
LorentzVector getPruned(double zcut, double rcutFactor)
get pruned 4-vector
LorentzVector getPrunedSubjetExclusive(unsigned int isubjet, double zcut, double rcutFactor)
get pruned 4-vector for a given subject (must be called after getGroupingExclusive) ...
std::vector< fastjet::PseudoJet > inclusiveJets_
Definition: ReclusterJets.h:59
std::vector< LorentzVector > makeP4s(const std::vector< fastjet::PseudoJet > &jets)