CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
MatcherByPullsAlgorithm Class Reference

#include <MuonAnalysis/MuonAssociators/interface/MatcherByPullsAlgorithm.cc>

Public Member Functions

void fillInvCov (const reco::Track &tk, AlgebraicSymMatrix55 &invCov) const
 Fill the inverse covariance matrix for the match(track, candidate, invCov) method. More...
 
std::pair< bool, float > match (const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
 
std::pair< int, float > match (const reco::RecoCandidate &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good) const
 
std::pair< int, float > match (const reco::Track &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good) const
 
 MatcherByPullsAlgorithm (const edm::ParameterSet &)
 
void matchMany (const reco::RecoCandidate &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good, std::vector< std::pair< double, int > > &matchesToFill) const
 
void matchMany (const reco::Track &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good, std::vector< std::pair< double, int > > &matchesToFill) const
 
 ~MatcherByPullsAlgorithm ()
 

Private Types

enum  TrackChoice { StaTrack, TrkTrack, GlbTrack }
 Enum to define which track to use. More...
 

Private Member Functions

const reco::Tracktrack (const reco::RecoCandidate &src) const
 Get track out of Candidate, NULL if missing. More...
 

Private Attributes

double cut_
 Cut on the pull. More...
 
bool diagOnly_
 Use only the diagonal terms of the covariance matrix. More...
 
double dr2_
 DeltaR of the matching cone. More...
 
TrackChoice track_
 Track to be used in matching. More...
 
bool useVertex_
 Use also dxy / dsz in the matching. More...
 

Detailed Description

Description: Matches a RecoCandidate to a GenParticle (or any other Candidate) using the pulls of the helix parameters

Implementation: <Notes on="" implementation>="">

Definition at line 34 of file MatcherByPullsAlgorithm.h.

Member Enumeration Documentation

Enum to define which track to use.

Enumerator
StaTrack 
TrkTrack 
GlbTrack 

Definition at line 83 of file MatcherByPullsAlgorithm.h.

Constructor & Destructor Documentation

MatcherByPullsAlgorithm::MatcherByPullsAlgorithm ( const edm::ParameterSet iConfig)
explicit

Definition at line 13 of file MatcherByPullsAlgorithm.cc.

References Exception, edm::ParameterSet::getParameter(), GlbTrack, StaTrack, AlCaHLTBitMon_QueryRunRegistry::string, track(), track_, and TrkTrack.

13  :
14  dr2_(std::pow(iConfig.getParameter<double>("maxDeltaR"),2)),
15  cut_(iConfig.getParameter<double>("maxPull")),
16  diagOnly_(iConfig.getParameter<bool>("diagonalElementsOnly")),
17  useVertex_(iConfig.getParameter<bool>("useVertexVariables"))
18 {
19  std::string track = iConfig.getParameter<std::string>("track");
20  if (track == "standAloneMuon") track_ = StaTrack;
21  else if (track == "combinedMuon") track_ = GlbTrack;
22  else if (track == "track") track_ = TrkTrack;
23  else throw cms::Exception("Configuration") << "MatcherByPullsAlgorithm: track '"<<track<<"' is not known\n" <<
24  "Allowed values are: 'track', 'combinedMuon', 'standAloneMuon' (as per reco::RecoCandidate object)\n";
25 }
T getParameter(std::string const &) const
bool diagOnly_
Use only the diagonal terms of the covariance matrix.
double dr2_
DeltaR of the matching cone.
bool useVertex_
Use also dxy / dsz in the matching.
double cut_
Cut on the pull.
TrackChoice track_
Track to be used in matching.
const reco::Track * track(const reco::RecoCandidate &src) const
Get track out of Candidate, NULL if missing.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
MatcherByPullsAlgorithm::~MatcherByPullsAlgorithm ( )

Definition at line 27 of file MatcherByPullsAlgorithm.cc.

28 {
29 }

Member Function Documentation

void MatcherByPullsAlgorithm::fillInvCov ( const reco::Track tk,
AlgebraicSymMatrix55 invCov 
) const

Fill the inverse covariance matrix for the match(track, candidate, invCov) method.

Definition at line 147 of file MatcherByPullsAlgorithm.cc.

References reco::TrackBase::covariance(), diagOnly_, i, j, and useVertex_.

Referenced by match(), and matchMany().

148 {
149  if (useVertex_) {
150  invCov = tk.covariance();
151  if (diagOnly_) {
152  for (size_t i = 0; i < 5; ++i) { for (size_t j = i+1; j < 5; ++j) {
153  invCov(i,j) = 0;
154  } }
155  }
156  invCov.Invert();
157  } else {
158  AlgebraicSymMatrix33 momCov = tk.covariance().Sub<AlgebraicSymMatrix33>(0,0); // get 3x3 matrix
159  if (diagOnly_) { momCov(0,1) = 0; momCov(0,2) = 0; momCov(1,2) = 0; }
160  momCov.Invert();
161  invCov.Place_at(momCov,0,0);
162  }
163 }
int i
Definition: DBlmapReader.cc:9
bool diagOnly_
Use only the diagonal terms of the covariance matrix.
bool useVertex_
Use also dxy / dsz in the matching.
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:726
int j
Definition: DBlmapReader.cc:9
std::pair< bool, float > MatcherByPullsAlgorithm::match ( const reco::Track tk,
const reco::Candidate mc,
const AlgebraicSymMatrix55 invertedCovariance 
) const

Match Track to MC Candidate, using already inverted covariance matrix Return status of match and pull, or (-1,9e9)

Definition at line 39 of file MatcherByPullsAlgorithm.cc.

References reco::Candidate::charge(), reco::TrackBase::charge(), gather_cfg::cout, cut_, SiPixelRawToDigiRegional_cfi::deltaPhi, reco::deltaR2(), mps_update::diff, dr2_, reco::TrackBase::dsz(), reco::TrackBase::dxy(), reco::Candidate::eta(), reco::TrackBase::eta(), i, reco::Candidate::p(), reco::Candidate::phi(), reco::TrackBase::phi(), reco::Candidate::pt(), reco::TrackBase::pt(), reco::TrackBase::qoverp(), mathSSE::sqrt(), reco::Candidate::theta(), reco::TrackBase::theta(), reco::Candidate::vertex(), reco::Candidate::vx(), reco::TrackBase::vx(), reco::Candidate::vy(), reco::TrackBase::vy(), reco::Candidate::vz(), and reco::TrackBase::vz().

Referenced by match(), and matchMany().

39  {
40  if (::deltaR2(tk,c) <= dr2_) {
41  AlgebraicVector5 diff(tk.qoverp() - c.charge()/c.p(),
42  tk.theta() - c.theta(),
43  ::deltaPhi(tk.phi(), c.phi()),
44  tk.dxy(c.vertex()),
45  tk.dsz(c.vertex()));
46  double pull = ROOT::Math::Similarity(diff, invCov);
47 #if 0
48  std::cout << "Tk charge/pt/eta/phi/vx/vy/vz " << tk.charge() << "\t" << tk.pt() << "\t" << tk.eta() << "\t" << tk.phi() << "\t" << tk.vx() << "\t" << tk.vy() << "\t" << tk.vz() << std::endl;
49  std::cout << "MC charge/pt/eta/phi/vx/vy/vz " << c.charge() << "\t" << c.pt() << "\t" << c.eta() << "\t" << c.phi() << "\t" << c.vx() << "\t" << c.vy() << "\t" << c.vz() << std::endl;
50  std::cout << "Delta: " << diff << std::endl;
51  std::cout << "Sigmas: ";
52  for (size_t i = 0; i < 5; ++i) {
53  if (invCov(i,i) == 0) std::cout << "---\t";
54  else std::cout << std::sqrt(1.0/invCov(i,i)) << "\t";
55  }
56  std::cout << std::endl;
57  std::cout << "Items: ";
58  for (size_t i = 0; i < 5; ++i) {
59  if (invCov(i,i) == 0) std::cout << "---\t";
60  else std::cout << diff(i)*std::sqrt(invCov(i,i)) << "\t";
61  }
62  std::cout << std::endl;
63  std::cout << "Pull: " << pull << std::endl;
64 #endif
65  return std::pair<bool,float>(pull < cut_, pull);
66  }
67  return std::pair<bool,float>(false,9e9);
68 }
double qoverp() const
q / p
Definition: TrackBase.h:568
int i
Definition: DBlmapReader.cc:9
double theta() const
polar angle
Definition: TrackBase.h:574
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:640
double dsz() const
dsz parameter (THIS IS NOT the SZ impact parameter to (0,0,0) if refPoint is far from (0...
Definition: TrackBase.h:598
list diff
Definition: mps_update.py:85
double dr2_
DeltaR of the matching cone.
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:646
T sqrt(T t)
Definition: SSEVec.h:18
double pt() const
track transverse momentum
Definition: TrackBase.h:616
double cut_
Cut on the pull.
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:664
ROOT::Math::SVector< double, 5 > AlgebraicVector5
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
tuple cout
Definition: gather_cfg.py:145
int charge() const
track electric charge
Definition: TrackBase.h:562
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:586
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:652
std::pair< int, float > MatcherByPullsAlgorithm::match ( const reco::RecoCandidate src,
const std::vector< reco::GenParticle > &  cands,
const std::vector< uint8_t > &  good 
) const

Match Reco Candidate to MC Candidates, skipping the ones which are not good Return index of matchin and pull, or (-1,9e9)

Definition at line 73 of file MatcherByPullsAlgorithm.cc.

References match(), and track().

76 {
77  const reco::Track * tk = track(src);
78  return (tk == 0 ?
79  std::pair<int,float>(-1,9e9) :
80  match(*tk, cands, good));
81 }
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
const reco::Track * track(const reco::RecoCandidate &src) const
Get track out of Candidate, NULL if missing.
std::pair< int, float > MatcherByPullsAlgorithm::match ( const reco::Track src,
const std::vector< reco::GenParticle > &  cands,
const std::vector< uint8_t > &  good 
) const

Match Reco Track to MC Tracks, skipping the ones which are not good Return index of matchin and pull, or (-1,9e9)

Definition at line 84 of file MatcherByPullsAlgorithm.cc.

References fillInvCov(), i, visualization-live-secondInstance_cfg::m, match(), and gen::n.

87 {
88  std::pair<int,float> best(-1,9e9);
89 
90  AlgebraicSymMatrix55 invCov; fillInvCov(tk, invCov);
91  for (int i = 0, n = cands.size(); i < n; ++i) {
92  if (!good[i]) continue;
93  std::pair<bool,float> m = match(tk, cands[i], invCov);
94  if (m.first && (m.second < best.second)) {
95  best.first = i;
96  best.second = m.second;
97  }
98  }
99  return best;
100 }
int i
Definition: DBlmapReader.cc:9
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void fillInvCov(const reco::Track &tk, AlgebraicSymMatrix55 &invCov) const
Fill the inverse covariance matrix for the match(track, candidate, invCov) method.
void MatcherByPullsAlgorithm::matchMany ( const reco::RecoCandidate src,
const std::vector< reco::GenParticle > &  cands,
const std::vector< uint8_t > &  good,
std::vector< std::pair< double, int > > &  matchesToFill 
) const

Match Reco Candidate to MC Candidates, allowing multiple matches and skipping the ones which are not good It will fill in the vector of <double,int> with pull and index for all matching candidates, already sorted by pulls. This method assumes that matchesToFill is empty when the method is called

Definition at line 103 of file MatcherByPullsAlgorithm.cc.

References track().

107 {
108  const reco::Track * tk = track(src);
109  if (tk != 0) matchMany(*tk, cands, good, matchesToFill);
110 }
const reco::Track * track(const reco::RecoCandidate &src) const
Get track out of Candidate, NULL if missing.
void matchMany(const reco::RecoCandidate &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good, std::vector< std::pair< double, int > > &matchesToFill) const
void MatcherByPullsAlgorithm::matchMany ( const reco::Track src,
const std::vector< reco::GenParticle > &  cands,
const std::vector< uint8_t > &  good,
std::vector< std::pair< double, int > > &  matchesToFill 
) const

Match Reco Track to MC Tracks, allowing multiple matches and skipping the ones which are not good It will fill in the vector of <double,int> with pull and index for all matching candidates, already sorted by pulls. This method assumes that matchesToFill is empty when the method is called

Definition at line 113 of file MatcherByPullsAlgorithm.cc.

References fillInvCov(), i, visualization-live-secondInstance_cfg::m, match(), and gen::n.

117 {
118 
119  AlgebraicSymMatrix55 invCov; fillInvCov(tk, invCov);
120  for (int i = 0, n = cands.size(); i < n; ++i) {
121  if (!good[i]) continue;
122  std::pair<bool,double> m = match(tk, cands[i], invCov);
123  if (m.first) matchesToFill.push_back(std::make_pair(m.second,i));
124  }
125  std::sort(matchesToFill.begin(),matchesToFill.end());
126 }
int i
Definition: DBlmapReader.cc:9
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void fillInvCov(const reco::Track &tk, AlgebraicSymMatrix55 &invCov) const
Fill the inverse covariance matrix for the match(track, candidate, invCov) method.
const reco::Track * MatcherByPullsAlgorithm::track ( const reco::RecoCandidate src) const
private

Get track out of Candidate, NULL if missing.

Definition at line 136 of file MatcherByPullsAlgorithm.cc.

References assert(), reco::RecoCandidate::combinedMuon(), edm::Ref< C, T, F >::get(), GlbTrack, edm::Ref< C, T, F >::isNonnull(), reco::RecoCandidate::standAloneMuon(), StaTrack, reco::RecoCandidate::track(), track_, and TrkTrack.

Referenced by match(), MatcherByPullsAlgorithm(), and matchMany().

136  {
137  switch (track_) {
138  case StaTrack : return muon.standAloneMuon().isNonnull() ? muon.standAloneMuon().get() : 0;
139  case GlbTrack : return muon.combinedMuon().isNonnull() ? muon.combinedMuon().get() : 0;
140  case TrkTrack : return muon.track().isNonnull() ? muon.track().get() : 0;
141  }
142  assert(false);
143 }
assert(m_qm.get())
TrackChoice track_
Track to be used in matching.

Member Data Documentation

double MatcherByPullsAlgorithm::cut_
private

Cut on the pull.

Definition at line 92 of file MatcherByPullsAlgorithm.h.

Referenced by match().

bool MatcherByPullsAlgorithm::diagOnly_
private

Use only the diagonal terms of the covariance matrix.

Definition at line 95 of file MatcherByPullsAlgorithm.h.

Referenced by fillInvCov().

double MatcherByPullsAlgorithm::dr2_
private

DeltaR of the matching cone.

Definition at line 89 of file MatcherByPullsAlgorithm.h.

Referenced by match().

TrackChoice MatcherByPullsAlgorithm::track_
private

Track to be used in matching.

Definition at line 86 of file MatcherByPullsAlgorithm.h.

Referenced by MatcherByPullsAlgorithm(), and track().

bool MatcherByPullsAlgorithm::useVertex_
private

Use also dxy / dsz in the matching.

Definition at line 98 of file MatcherByPullsAlgorithm.h.

Referenced by fillInvCov().