CMS 3D CMS Logo

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< 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
 
std::pair< bool, float > match (const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) 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

◆ TrackChoice

Enum to define which track to use.

Enumerator
StaTrack 
TrkTrack 
GlbTrack 

Definition at line 83 of file MatcherByPullsAlgorithm.h.

Constructor & Destructor Documentation

◆ MatcherByPullsAlgorithm()

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

Definition at line 13 of file MatcherByPullsAlgorithm.cc.

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  std::string track = iConfig.getParameter<std::string>("track");
19  if (track == "standAloneMuon")
20  track_ = StaTrack;
21  else if (track == "combinedMuon")
22  track_ = GlbTrack;
23  else if (track == "track")
24  track_ = TrkTrack;
25  else
26  throw cms::Exception("Configuration")
27  << "MatcherByPullsAlgorithm: track '" << track << "' is not known\n"
28  << "Allowed values are: 'track', 'combinedMuon', 'standAloneMuon' (as per reco::RecoCandidate object)\n";
29 }

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

◆ ~MatcherByPullsAlgorithm()

MatcherByPullsAlgorithm::~MatcherByPullsAlgorithm ( )

Definition at line 31 of file MatcherByPullsAlgorithm.cc.

31 {}

Member Function Documentation

◆ fillInvCov()

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 143 of file MatcherByPullsAlgorithm.cc.

143  {
144  if (useVertex_) {
145  invCov = tk.covariance();
146  if (diagOnly_) {
147  for (size_t i = 0; i < 5; ++i) {
148  for (size_t j = i + 1; j < 5; ++j) {
149  invCov(i, j) = 0;
150  }
151  }
152  }
153  invCov.Invert();
154  } else {
155  AlgebraicSymMatrix33 momCov = tk.covariance().Sub<AlgebraicSymMatrix33>(0, 0); // get 3x3 matrix
156  if (diagOnly_) {
157  momCov(0, 1) = 0;
158  momCov(0, 2) = 0;
159  momCov(1, 2) = 0;
160  }
161  momCov.Invert();
162  invCov.Place_at(momCov, 0, 0);
163  }
164 }

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

Referenced by match(), and matchMany().

◆ match() [1/3]

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.

75  {
76  const reco::Track *tk = track(src);
77  return (tk == nullptr ? std::pair<int, float>(-1, 9e9) : match(*tk, cands, good));
78 }

References HLT_FULL_cff::cands, good, match(), TrackRefitter_38T_cff::src, and track().

◆ match() [2/3]

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 80 of file MatcherByPullsAlgorithm.cc.

82  {
83  std::pair<int, float> best(-1, 9e9);
84 
85  AlgebraicSymMatrix55 invCov;
86  fillInvCov(tk, invCov);
87  for (int i = 0, n = cands.size(); i < n; ++i) {
88  if (!good[i])
89  continue;
90  std::pair<bool, float> m = match(tk, cands[i], invCov);
91  if (m.first && (m.second < best.second)) {
92  best.first = i;
93  best.second = m.second;
94  }
95  }
96  return best;
97 }

References HLT_FULL_cff::cands, fillInvCov(), good, mps_fire::i, visualization-live-secondInstance_cfg::m, match(), and dqmiodumpmetadata::n.

◆ match() [3/3]

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 40 of file MatcherByPullsAlgorithm.cc.

42  {
43  if (::deltaR2(tk, c) <= dr2_) {
44  AlgebraicVector5 diff(tk.qoverp() - c.charge() / c.p(),
45  tk.theta() - c.theta(),
46  ::deltaPhi(tk.phi(), c.phi()),
47  tk.dxy(c.vertex()),
48  tk.dsz(c.vertex()));
49  double pull = ROOT::Math::Similarity(diff, invCov);
50 #if 0
51  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;
52  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;
53  std::cout << "Delta: " << diff << std::endl;
54  std::cout << "Sigmas: ";
55  for (size_t i = 0; i < 5; ++i) {
56  if (invCov(i,i) == 0) std::cout << "---\t";
57  else std::cout << std::sqrt(1.0/invCov(i,i)) << "\t";
58  }
59  std::cout << std::endl;
60  std::cout << "Items: ";
61  for (size_t i = 0; i < 5; ++i) {
62  if (invCov(i,i) == 0) std::cout << "---\t";
63  else std::cout << diff(i)*std::sqrt(invCov(i,i)) << "\t";
64  }
65  std::cout << std::endl;
66  std::cout << "Pull: " << pull << std::endl;
67 #endif
68  return std::pair<bool, float>(pull < cut_, pull);
69  }
70  return std::pair<bool, float>(false, 9e9);
71 }

References c, reco::TrackBase::charge(), gather_cfg::cout, cut_, SiPixelRawToDigiRegional_cfi::deltaPhi, HLTMuonOfflineAnalyzer_cfi::deltaR2, change_name::diff, dr2_, reco::TrackBase::dsz(), reco::TrackBase::dxy(), reco::TrackBase::eta(), mps_fire::i, reco::TrackBase::phi(), reco::TrackBase::pt(), reco::TrackBase::qoverp(), mathSSE::sqrt(), reco::TrackBase::theta(), reco::TrackBase::vx(), reco::TrackBase::vy(), and reco::TrackBase::vz().

Referenced by match(), and matchMany().

◆ matchMany() [1/2]

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 99 of file MatcherByPullsAlgorithm.cc.

102  {
103  const reco::Track *tk = track(src);
104  if (tk != nullptr)
105  matchMany(*tk, cands, good, matchesToFill);
106 }

References HLT_FULL_cff::cands, good, TrackRefitter_38T_cff::src, and track().

◆ matchMany() [2/2]

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 108 of file MatcherByPullsAlgorithm.cc.

111  {
112  AlgebraicSymMatrix55 invCov;
113  fillInvCov(tk, invCov);
114  for (int i = 0, n = cands.size(); i < n; ++i) {
115  if (!good[i])
116  continue;
117  std::pair<bool, double> m = match(tk, cands[i], invCov);
118  if (m.first)
119  matchesToFill.push_back(std::make_pair(m.second, i));
120  }
121  std::sort(matchesToFill.begin(), matchesToFill.end());
122 }

References HLT_FULL_cff::cands, fillInvCov(), good, mps_fire::i, visualization-live-secondInstance_cfg::m, match(), dqmiodumpmetadata::n, and jetUpdater_cfi::sort.

◆ track()

const reco::Track * MatcherByPullsAlgorithm::track ( const reco::RecoCandidate src) const
private

Get track out of Candidate, NULL if missing.

Definition at line 131 of file MatcherByPullsAlgorithm.cc.

131  {
132  switch (track_) {
133  case StaTrack:
134  return muon.standAloneMuon().isNonnull() ? muon.standAloneMuon().get() : nullptr;
135  case GlbTrack:
136  return muon.combinedMuon().isNonnull() ? muon.combinedMuon().get() : nullptr;
137  case TrkTrack:
138  return muon.track().isNonnull() ? muon.track().get() : nullptr;
139  }
140  assert(false);
141 }

References cms::cuda::assert(), GlbTrack, StaTrack, track_, and TrkTrack.

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

Member Data Documentation

◆ cut_

double MatcherByPullsAlgorithm::cut_
private

Cut on the pull.

Definition at line 92 of file MatcherByPullsAlgorithm.h.

Referenced by match().

◆ diagOnly_

bool MatcherByPullsAlgorithm::diagOnly_
private

Use only the diagonal terms of the covariance matrix.

Definition at line 95 of file MatcherByPullsAlgorithm.h.

Referenced by fillInvCov().

◆ dr2_

double MatcherByPullsAlgorithm::dr2_
private

DeltaR of the matching cone.

Definition at line 89 of file MatcherByPullsAlgorithm.h.

Referenced by match().

◆ track_

TrackChoice MatcherByPullsAlgorithm::track_
private

Track to be used in matching.

Definition at line 86 of file MatcherByPullsAlgorithm.h.

Referenced by MatcherByPullsAlgorithm(), and track().

◆ useVertex_

bool MatcherByPullsAlgorithm::useVertex_
private

Use also dxy / dsz in the matching.

Definition at line 98 of file MatcherByPullsAlgorithm.h.

Referenced by fillInvCov().

change_name.diff
diff
Definition: change_name.py:13
good
const auto good
min quality of good
Definition: CAHitNtupletGeneratorKernelsImpl.h:760
AlgebraicSymMatrix33
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Definition: AlgebraicROOTObjects.h:21
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
MatcherByPullsAlgorithm::StaTrack
Definition: MatcherByPullsAlgorithm.h:83
MatcherByPullsAlgorithm::TrkTrack
Definition: MatcherByPullsAlgorithm.h:83
muon
Definition: MuonCocktails.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
MatcherByPullsAlgorithm::GlbTrack
Definition: MatcherByPullsAlgorithm.h:83
reco::TrackBase::vx
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:655
reco::TrackBase::dsz
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:614
cms::cuda::assert
assert(be >=bs)
MatcherByPullsAlgorithm::useVertex_
bool useVertex_
Use also dxy / dsz in the matching.
Definition: MatcherByPullsAlgorithm.h:98
MatcherByPullsAlgorithm::cut_
double cut_
Cut on the pull.
Definition: MatcherByPullsAlgorithm.h:92
reco::TrackBase::pt
double pt() const
track transverse momentum
Definition: TrackBase.h:637
MatcherByPullsAlgorithm::fillInvCov
void fillInvCov(const reco::Track &tk, AlgebraicSymMatrix55 &invCov) const
Fill the inverse covariance matrix for the match(track, candidate, invCov) method.
Definition: MatcherByPullsAlgorithm.cc:143
SiPixelRawToDigiRegional_cfi.deltaPhi
deltaPhi
Definition: SiPixelRawToDigiRegional_cfi.py:9
reco::TrackBase::vz
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:661
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:79
MatcherByPullsAlgorithm::track
const reco::Track * track(const reco::RecoCandidate &src) const
Get track out of Candidate, NULL if missing.
Definition: MatcherByPullsAlgorithm.cc:131
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MatcherByPullsAlgorithm::diagOnly_
bool diagOnly_
Use only the diagonal terms of the covariance matrix.
Definition: MatcherByPullsAlgorithm.h:95
reco::Track
Definition: Track.h:27
reco::TrackBase::charge
int charge() const
track electric charge
Definition: TrackBase.h:596
reco::TrackBase::covariance
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:716
reco::TrackBase::phi
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:649
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15161
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
reco::TrackBase::eta
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:652
MatcherByPullsAlgorithm::dr2_
double dr2_
DeltaR of the matching cone.
Definition: MatcherByPullsAlgorithm.h:89
AlgebraicVector5
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Definition: AlgebraicROOTObjects.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MatcherByPullsAlgorithm::match
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
Definition: MatcherByPullsAlgorithm.cc:40
reco::TrackBase::vy
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:658
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
Exception
Definition: hltDiff.cc:245
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
reco::TrackBase::theta
double theta() const
polar angle
Definition: TrackBase.h:602
reco::TrackBase::dxy
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:608
MatcherByPullsAlgorithm::track_
TrackChoice track_
Track to be used in matching.
Definition: MatcherByPullsAlgorithm.h:86
MatcherByPullsAlgorithm::matchMany
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
Definition: MatcherByPullsAlgorithm.cc:99
reco::TrackBase::qoverp
double qoverp() const
q / p
Definition: TrackBase.h:599