CMS 3D CMS Logo

SoftMuonMvaRun3Estimator.cc
Go to the documentation of this file.
4 
5 typedef std::pair<const reco::MuonChamberMatch*, const reco::MuonSegmentMatch*> MatchPair;
6 
7 const MatchPair& getBetterMatch(const MatchPair& match1, const MatchPair& match2) {
8  // Prefer DT over CSC simply because it's closer to IP
9  // and will have less multiple scattering (at least for
10  // RB1 vs ME1/3 case). RB1 & ME1/2 overlap is tiny
11  if (match2.first->detector() == MuonSubdetId::DT and match1.first->detector() != MuonSubdetId::DT)
12  return match2;
13 
14  // For the rest compare local x match. We expect that
15  // segments belong to the muon, so the difference in
16  // local x is a reflection on how well we can measure it
17  if (abs(match1.first->x - match1.second->x) > abs(match2.first->x - match2.second->x))
18  return match2;
19 
20  return match1;
21 }
22 
23 float dX(const MatchPair& match) {
24  if (match.first and match.second->hasPhi())
25  return (match.first->x - match.second->x);
26  else
27  return 9999.;
28 }
29 
30 float pullX(const MatchPair& match) {
31  if (match.first and match.second->hasPhi())
32  return dX(match) / sqrt(pow(match.first->xErr, 2) + pow(match.second->xErr, 2));
33  else
34  return 9999.;
35 }
36 
37 float pullDxDz(const MatchPair& match) {
38  if (match.first and match.second->hasPhi())
39  return (match.first->dXdZ - match.second->dXdZ) /
40  sqrt(pow(match.first->dXdZErr, 2) + pow(match.second->dXdZErr, 2));
41  else
42  return 9999.;
43 }
44 
45 float dY(const MatchPair& match) {
46  if (match.first and match.second->hasZed())
47  return (match.first->y - match.second->y);
48  else
49  return 9999.;
50 }
51 
52 float pullY(const MatchPair& match) {
53  if (match.first and match.second->hasZed())
54  return dY(match) / sqrt(pow(match.first->yErr, 2) + pow(match.second->yErr, 2));
55  else
56  return 9999.;
57 }
58 
59 float pullDyDz(const MatchPair& match) {
60  if (match.first and match.second->hasZed())
61  return (match.first->dYdZ - match.second->dYdZ) /
62  sqrt(pow(match.first->dYdZErr, 2) + pow(match.second->dYdZErr, 2));
63  else
64  return 9999.;
65 }
66 
68  booster.set(prefix + "_dX", dX(match));
69  booster.set(prefix + "_pullX", pullX(match));
70  booster.set(prefix + "_pullDxDz", pullDxDz(match));
71  booster.set(prefix + "_dY", dY(match));
72  booster.set(prefix + "_pullY", pullY(match));
73  booster.set(prefix + "_pullDyDz", pullDyDz(match));
74 }
75 
76 void fillMatchInfo(pat::XGBooster& booster, const pat::Muon& muon) {
77  // Initiate containter for results
78  const int n_stations = 2;
79  std::vector<MatchPair> matches;
80  for (unsigned int i = 0; i < n_stations; ++i)
81  matches.push_back(std::pair(nullptr, nullptr));
82 
83  // Find best matches
84  for (auto& chamberMatch : muon.matches()) {
85  unsigned int station = chamberMatch.station() - 1;
86  if (station >= n_stations)
87  continue;
88 
89  // Find best segment match.
90  // We could consider all segments, but we will restrict to segments
91  // that match to this candidate better than to other muon candidates
92  for (auto& segmentMatch : chamberMatch.segmentMatches) {
93  if (not segmentMatch.isMask(reco::MuonSegmentMatch::BestInStationByDR) ||
94  not segmentMatch.isMask(reco::MuonSegmentMatch::BelongsToTrackByDR))
95  continue;
96 
97  // Multiple segment matches are possible in different
98  // chambers that are either overlapping or belong to
99  // different detectors. We need to select one.
100  auto match_pair = MatchPair(&chamberMatch, &segmentMatch);
101 
102  if (matches[station].first)
103  matches[station] = getBetterMatch(matches[station], match_pair);
104  else
105  matches[station] = match_pair;
106  }
107  }
108 
109  // Fill matching information
110  fillMatchInfoForStation("match1", booster, matches[0]);
111  fillMatchInfoForStation("match2", booster, matches[1]);
112 }
113 
115  if (!muon.isTrackerMuon() && !muon.isGlobalMuon())
116  return 0;
117 
118  fillMatchInfo(booster, muon);
119 
120  booster.set("pt", muon.pt());
121  booster.set("eta", muon.eta());
122  booster.set("trkValidFrac", muon.innerTrack()->validFraction());
123  booster.set("glbTrackProbability", muon.combinedQuality().glbTrackProbability);
124  booster.set("nLostHitsInner",
125  muon.innerTrack()->hitPattern().numberOfLostTrackerHits(reco::HitPattern::MISSING_INNER_HITS));
126  booster.set("nLostHitsOuter",
127  muon.innerTrack()->hitPattern().numberOfLostTrackerHits(reco::HitPattern::MISSING_OUTER_HITS));
128  booster.set("trkKink", muon.combinedQuality().trkKink);
129  booster.set("chi2LocalPosition", muon.combinedQuality().chi2LocalPosition);
130  booster.set("nPixels", muon.innerTrack()->hitPattern().numberOfValidPixelHits());
131  booster.set("nValidHits", muon.innerTrack()->hitPattern().numberOfValidTrackerHits());
132  booster.set("nLostHitsOn", muon.innerTrack()->hitPattern().numberOfLostTrackerHits(reco::HitPattern::TRACK_HITS));
133  booster.set("glbNormChi2", muon.isGlobalMuon() ? muon.globalTrack()->normalizedChi2() : 9999.);
134  booster.set("trkLayers", muon.innerTrack()->hitPattern().trackerLayersWithMeasurement());
135  booster.set("highPurity", muon.innerTrack()->quality(reco::Track::highPurity));
136 
137  return booster.predict();
138 }
const MatchPair & getBetterMatch(const MatchPair &match1, const MatchPair &match2)
void fillMatchInfoForStation(std::string prefix, pat::XGBooster &booster, const MatchPair &match)
static const unsigned int BestInStationByDR
float predict(const int iterationEnd=0)
Definition: XGBooster.cc:81
float pullDyDz(const MatchPair &match)
float computeSoftMvaRun3(XGBooster &booster, const Muon &muon)
std::pair< const reco::MuonChamberMatch *, const reco::MuonSegmentMatch * > MatchPair
float pullDxDz(const MatchPair &match)
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float dX(const MatchPair &match)
void fillMatchInfo(pat::XGBooster &booster, const pat::Muon &muon)
static const unsigned int BelongsToTrackByDR
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
static constexpr int DT
Definition: MuonSubdetId.h:11
void set(std::string name, float value)
Definition: XGBooster.cc:79
float pullY(const MatchPair &match)
Analysis-level muon class.
Definition: Muon.h:51
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float pullX(const MatchPair &match)
float dY(const MatchPair &match)