CMS 3D CMS Logo

MatcherByPullsAlgorithm.cc
Go to the documentation of this file.
2 
3 // user include files
5 
6 /* ____ _ _
7  * / ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
8  * | | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
9  * | |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
10  * \____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
11  *
12  */
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 }
30 
32 
33 /* __ __ _ _
34  * | \/ | __ _| |_ ___| |__ ___ _ __ ___
35  * | |\/| |/ _` | __/ __| '_ \ / _ \ '__/ __|
36  * | | | | (_| | || (__| | | | __/ | \__ \
37  * |_| |_|\__,_|\__\___|_| |_|\___|_| |___/
38  *
39  */
40 std::pair<bool, float> MatcherByPullsAlgorithm::match(const reco::Track &tk,
41  const reco::Candidate &c,
42  const AlgebraicSymMatrix55 &invCov) const {
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 }
72 
74  const std::vector<reco::GenParticle> &cands,
75  const std::vector<uint8_t> &good) const {
76  const reco::Track *tk = track(src);
77  return (tk == nullptr ? std::pair<int, float>(-1, 9e9) : match(*tk, cands, good));
78 }
79 
80 std::pair<int, float> MatcherByPullsAlgorithm::match(const reco::Track &tk,
81  const std::vector<reco::GenParticle> &cands,
82  const std::vector<uint8_t> &good) const {
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 }
98 
100  const std::vector<reco::GenParticle> &cands,
101  const std::vector<uint8_t> &good,
102  std::vector<std::pair<double, int> > &matchesToFill) const {
103  const reco::Track *tk = track(src);
104  if (tk != nullptr)
105  matchMany(*tk, cands, good, matchesToFill);
106 }
107 
109  const std::vector<reco::GenParticle> &cands,
110  const std::vector<uint8_t> &good,
111  std::vector<std::pair<double, int> > &matchesToFill) const {
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 }
123 
124 /* _ _ _ _ _ _ _ _
125  * | | | | |_(_) (_) |_(_) ___ ___
126  * | | | | __| | | | __| |/ _ \/ __|
127  * | |_| | |_| | | | |_| | __/\__ \
128  * \___/ \__|_|_|_|\__|_|\___||___/
129  *
130  */
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 }
142 
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 }
change_name.diff
diff
Definition: change_name.py:13
MatcherByPullsAlgorithm::~MatcherByPullsAlgorithm
~MatcherByPullsAlgorithm()
Definition: MatcherByPullsAlgorithm.cc:31
MatcherByPullsAlgorithm.h
AlgebraicSymMatrix33
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
Definition: AlgebraicROOTObjects.h:21
electrons_cff.bool
bool
Definition: electrons_cff.py:366
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
MatcherByPullsAlgorithm::MatcherByPullsAlgorithm
MatcherByPullsAlgorithm(const edm::ParameterSet &)
Definition: MatcherByPullsAlgorithm.cc:13
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:72
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
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15146
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
deltaR.h
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
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
reco::RecoCandidate
Definition: RecoCandidate.h:20
AlgebraicVector5
ROOT::Math::SVector< double, 5 > AlgebraicVector5
Definition: AlgebraicROOTObjects.h:14
reco::Candidate
Definition: Candidate.h:27
MatcherByPullsAlgorithm::match
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
Definition: MatcherByPullsAlgorithm.cc:40
std
Definition: JetResolutionObject.h:76
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:46
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