CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  template<typename T>
18  static inline T sqr(const T & val) { return val * val; }
19 
20  template<typename T1, typename T2, typename R>
21  struct JetDistance : public std::binary_function<T1, T2, R> {
22  JetDistance(double sigmaDeltaR, double sigmaDeltaE) :
23  sigmaDeltaR2(sqr(sigmaDeltaR)),
24  sigmaDeltaE2(sqr(sigmaDeltaE)) {}
25 
26  double operator () (const T1 &v1, const T2 &v2) const
27  {
28  using namespace ROOT::Math;
29 // return VectorUtil::DeltaR2(v1, v2) / sigmaDeltaR2 +
30 // sqr(2. * (v1.R() - v2.R()) /
31 // (v1.R() + v2.R())) / sigmaDeltaE2;
32  double x = VectorUtil::DeltaR2(v1, v2) / sigmaDeltaR2 +
33  sqr(2. * (v1.R() - v2.R()) /
34  (v1.R() + v2.R())) / sigmaDeltaE2;
35 // std::cout << "xxx " << VectorUtil::DeltaPhi(v1, v2) << " " << (v1.Eta() - v2.Eta()) << " " << (v1.R() - v2.R()) / (v1.R() + v2.R()) << " " << x << std::endl;
36  return x;
37  }
38 
39  double sigmaDeltaR2, sigmaDeltaE2;
40  };
41 }
42 
44  maxChi2(pSet.getParameter<double>("maxChi2")),
45  sigmaDeltaR(pSet.getParameter<double>("sigmaDeltaR")),
46  sigmaDeltaE(pSet.getParameter<double>("sigmaDeltaE")),
47  threshold(1.0)
48 {
49 }
50 
52  const edm::RefToBaseVector<reco::Jet> & refJets_,
53  const edm::RefToBaseVector<reco::Jet> & recJets_,
55  )
56 {
57  refJetCorrector.setCorrector(corrector);
58  recJetCorrector.setCorrector(corrector);
59 
60  typedef ROOT::Math::Cartesian3D<double> Vector;
61 
62  std::vector<Vector> corrRefJets;
63  refJets.clear();
65  iter != refJets_.end(); ++iter) {
66  edm::RefToBase<reco::Jet> jetRef = *iter;
67  reco::Jet jet = refJetCorrector(*jetRef);
68  if (jet.energy() < threshold)
69  continue;
70 
71  corrRefJets.push_back(Vector(jet.px(), jet.py(), jet.pz()));
72  refJets.push_back(jetRef);
73  }
74 
75  std::vector<Vector> corrRecJets;
76  recJets.clear();
78  iter != recJets_.end(); ++iter) {
79  edm::RefToBase<reco::Jet> jetRec = *iter;
80  reco::Jet jet = recJetCorrector(*jetRec);
81  if (jet.energy() < threshold)
82  continue;
83 
84  corrRecJets.push_back(Vector(jet.px(), jet.py(), jet.pz()));
85  recJets.push_back(jetRec);
86  }
87 
88  this->refJets = refJets;
89  refToRec.clear();
90  refToRec.resize(refJets.size(), -1);
91 
92  this->recJets = recJets;
93  recToRef.clear();
94  recToRef.resize(recJets.size(), -1);
95 
96  Matching<double> matching(corrRefJets, corrRecJets,
100 
101  const std::vector<Match>& matches =
102  matching.match(std::less<double>(),
103  std::bind2nd(std::less<double>(), maxChi2));
104  for(std::vector<Match>::const_iterator iter = matches.begin();
105  iter != matches.end(); ++iter) {
106  refToRec[iter->index1] = iter->index2;
107  recToRef[iter->index2] = iter->index1;
108  }
109 }
110 
113 {
115  if (recJet.id() != recJets.id())
116  return result;
117 
118  for(unsigned int i = 0; i != recJets.size(); ++i) {
119  if (recJets[i] == recJet) {
120  int match = recToRef[i];
121  if (match >= 0)
122  result = refJets[match];
123  break;
124  }
125  }
126 
127  return result;
128 }
int i
Definition: DBlmapReader.cc:9
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:39
const_iterator end() const
std::vector< int > recToRef
Definition: MatchJet.h:38
edm::RefToBaseVector< reco::Jet > recJets
Definition: MatchJet.h:40
ProductID id() const
Definition: RefToBase.h:233
double sigmaDeltaE
Definition: MatchJet.h:47
void matchCollections(const edm::RefToBaseVector< reco::Jet > &refJets, const edm::RefToBaseVector< reco::Jet > &recJets, const reco::JetCorrector *corrector)
match the collections
Definition: MatchJet.cc:51
double sigmaDeltaR
Definition: MatchJet.h:46
T x() const
Cartesian x coordinate.
virtual double energy() const
energy
std::vector< int > refToRec
Definition: MatchJet.h:38
double maxChi2
Definition: MatchJet.h:45
tuple corrector
Definition: mvaPFMET_cff.py:86
tuple result
Definition: query.py:137
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:112
tuple btag
Definition: BTagSF.py:15
CorrectJet refJetCorrector
Definition: MatchJet.h:42
CorrectJet recJetCorrector
Definition: MatchJet.h:43
virtual double px() const
x coordinate of momentum vector
void setCorrector(const reco::JetCorrector *corrector)
Returns the corrected jet.
Definition: CorrectJet.h:22
virtual double pz() const
z coordinate of momentum vector
const_iterator begin() const
std::vector< Match > match(SortComparator sortComparator=SortComparator(), CutCriterion cutCriterion=CutCriterion())
Definition: Matching.h:72
Square< F >::type sqr(const F &f)
Definition: Square.h:13
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:48
MatchJet()
Definition: MatchJet.h:22
long double T
ProductID id() const
virtual double py() const
y coordinate of momentum vector