test
CMS 3D CMS Logo

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