CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MatchJet.cc
Go to the documentation of this file.
1 #include <functional>
2 #include <algorithm>
3 #include <vector>
4 #include <memory>
5 #include <string>
6 
7 #include <Math/GenVector/Cartesian3D.h>
8 #include <Math/GenVector/VectorUtil.h>
9 
11 
12 #include "Matching.h"
13 
14 using namespace btag;
15 
16 namespace {
17  inline double sqr(double val) { return val * val; }
18 } // namespace
19 
21  : maxChi2(pSet.getParameter<double>("maxChi2")),
22  sigmaDeltaR2(sqr(pSet.getParameter<double>("sigmaDeltaR"))),
23  sigmaDeltaE2(sqr(pSet.getParameter<double>("sigmaDeltaE"))),
24  threshold(1.0) {}
25 
27  const edm::RefToBaseVector<reco::Jet>& recJets_,
29  refJetCorrector.setCorrector(corrector);
30  recJetCorrector.setCorrector(corrector);
31 
32  typedef ROOT::Math::Cartesian3D<double> Vector;
33 
34  std::vector<Vector> corrRefJets;
35  refJets.clear();
36  for (edm::RefToBaseVector<reco::Jet>::const_iterator iter = refJets.begin(); iter != refJets_.end(); ++iter) {
37  edm::RefToBase<reco::Jet> jetRef = *iter;
38  reco::Jet jet = refJetCorrector(*jetRef);
39  if (jet.energy() < threshold)
40  continue;
41 
42  corrRefJets.push_back(Vector(jet.px(), jet.py(), jet.pz()));
43  refJets.push_back(jetRef);
44  }
45 
46  std::vector<Vector> corrRecJets;
47  recJets.clear();
48  for (edm::RefToBaseVector<reco::Jet>::const_iterator iter = recJets.begin(); iter != recJets_.end(); ++iter) {
49  edm::RefToBase<reco::Jet> jetRec = *iter;
50  reco::Jet jet = recJetCorrector(*jetRec);
51  if (jet.energy() < threshold)
52  continue;
53 
54  corrRecJets.push_back(Vector(jet.px(), jet.py(), jet.pz()));
55  recJets.push_back(jetRec);
56  }
57 
58  refToRec.clear();
59  refToRec.resize(refJets.size(), -1);
60 
61  recToRef.clear();
62  recToRef.resize(recJets.size(), -1);
63 
64  Matching<double> matching(corrRefJets, corrRecJets, [this](auto& v1, auto& v2) {
65  double x = ROOT::Math::VectorUtil::DeltaR2(v1, v2) / this->sigmaDeltaR2 +
66  sqr(2. * (v1.R() - v2.R()) / (v1.R() + v2.R())) / this->sigmaDeltaE2;
67  // Possible debug output
68  // std::cout << "xxx " << ROOT::Math::VectorUtil::DeltaPhi(v1, v2) << " " << (v1.Eta() - v2.Eta())
69  // << " " << (v1.R() - v2.R()) / (v1.R() + v2.R()) << " " << x << std::endl;
70  return x;
71  });
72 
74 
75  const std::vector<Match>& matches = matching.match(std::less<double>(), [&](auto& c) { return c < this->maxChi2; });
76  for (std::vector<Match>::const_iterator iter = matches.begin(); iter != matches.end(); ++iter) {
77  refToRec[iter->index1] = iter->index2;
78  recToRef[iter->index2] = iter->index1;
79  }
80 }
81 
84  if (recJet.id() != recJets.id())
85  return result;
86 
87  for (unsigned int i = 0; i != recJets.size(); ++i) {
88  if (recJets[i] == recJet) {
89  int match = recToRef[i];
90  if (match >= 0)
91  result = refJets[match];
92  break;
93  }
94  }
95 
96  return result;
97 }
double sigmaDeltaE2
Definition: MatchJet.h:44
const edm::EventSetup & c
double pz() const final
z coordinate of momentum vector
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
Base class for all types of Jets.
Definition: Jet.h:20
edm::RefToBaseVector< reco::Jet > refJets
Definition: MatchJet.h:36
const_iterator end() const
std::vector< int > recToRef
Definition: MatchJet.h:35
edm::RefToBaseVector< reco::Jet > recJets
Definition: MatchJet.h:37
int sqr(const T &t)
ProductID id() const
Definition: RefToBase.h:214
void matchCollections(const edm::RefToBaseVector< reco::Jet > &refJets, const edm::RefToBaseVector< reco::Jet > &recJets, const reco::JetCorrector *corrector)
match the collections
Definition: MatchJet.cc:26
tuple result
Definition: mps_fire.py:311
double px() const final
x coordinate of momentum vector
std::vector< int > refToRec
Definition: MatchJet.h:35
double maxChi2
Definition: MatchJet.h:42
double sigmaDeltaR2
Definition: MatchJet.h:43
size_type size() const
edm::RefToBase< reco::Jet > operator()(const edm::RefToBase< reco::Jet > &recJet) const
Returns the matched &quot;reference&quot; jet.
Definition: MatchJet.cc:82
double py() const final
y coordinate of momentum vector
tuple btag
Definition: BTagSF.py:16
CorrectJet refJetCorrector
Definition: MatchJet.h:39
CorrectJet recJetCorrector
Definition: MatchJet.h:40
void setCorrector(const reco::JetCorrector *corrector)
Returns the corrected jet.
Definition: CorrectJet.h:21
const_iterator begin() const
void push_back(const RefToBase< T > &)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
double threshold
Definition: MatchJet.h:45
MatchJet()
Definition: MatchJet.h:21
ProductID id() const
double energy() const final
energy