CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonCocktails.cc
Go to the documentation of this file.
1 #include "TMath.h"
4 
5 //
6 // Return the TeV-optimized refit track (aka the cocktail or Tune P) or
7 // the tracker track if either the optimized pT or tracker pT is below the pT threshold
8 //
10  const reco::TrackRef& trackerTrack,
11  const reco::TrackRef& tpfmsTrack,
12  const reco::TrackRef& pickyTrack,
13  const double ptThreshold,
14  const double tune1,
15  const double tune2,
16  double dptcut) {
17 
18  // Array for convenience below.
19  const reco::Muon::MuonTrackTypePair refit[4] = {
20  make_pair(trackerTrack, reco::Muon::InnerTrack),
21  make_pair(combinedTrack,reco::Muon::CombinedTrack),
22  make_pair(tpfmsTrack, reco::Muon::TPFMS),
23  make_pair(pickyTrack, reco::Muon::Picky)
24  };
25 
26  // Calculate the log(tail probabilities). If there's a problem,
27  // signify this with prob == 0. The current problems recognized are:
28  // the track being not available, whether the (re)fit failed or it's
29  // just not in the event, or if the (re)fit ended up with no valid
30  // hits.
31  double prob[4] = {0.,0.,0.,0.};
32  bool valid[4] = {0,0,0,0};
33 
34  double dptmin = 1.;
35 
36  if (dptcut>0) {
37  for (unsigned int i = 0; i < 4; ++i)
38  if (refit[i].first.isNonnull())
39  if (refit[i].first->ptError()/refit[i].first->pt()<dptmin) dptmin = refit[i].first->ptError()/refit[i].first->pt();
40 
41  if (dptmin>dptcut) dptcut = dptmin+0.15;
42  }
43 
44  for (unsigned int i = 0; i < 4; ++i)
45  if (refit[i].first.isNonnull()){
46  valid[i] = true;
47  if (refit[i].first->numberOfValidHits() && (refit[i].first->ptError()/refit[i].first->pt()<dptcut || dptcut<0))
48  prob[i] = muon::trackProbability(refit[i].first);
49  }
50 
51 
52  // Start with picky.
53  int chosen = 3;
54 
55  // If there's a problem with picky, make the default one of the
56  // other tracks. Try TPFMS first, then global, then tracker-only.
57  if (prob[3] == 0.) {
58 
59  // split so that passing dptcut<0 recreates EXACTLY the old tuneP behavior
60  if (dptcut>0) {
61  if (prob[0] > 0.) chosen = 0;
62  else if (prob[2] > 0.) chosen = 2;
63  else if (prob[1] > 0.) chosen = 1;
64  } else {
65  if (prob[2] > 0.) chosen = 2;
66  else if (prob[1] > 0.) chosen = 1;
67  else if (prob[0] > 0.) chosen = 0;
68  }
69  }
70 
71  // Now the algorithm: switch from picky to tracker-only if the
72  // difference, log(tail prob(picky)) - log(tail prob(tracker-only))
73  // is greater than a tuned value. Then compare the
74  // so-picked track to TPFMS in the same manner using another tuned
75  // value.
76  if (prob[0] > 0. && prob[3] > 0. && (prob[3] - prob[0]) > tune1)
77  chosen = 0;
78  if (prob[2] > 0. && (prob[chosen] - prob[2]) > tune2)
79  chosen = 2;
80 
81  // Sanity checks
82  if (chosen == 3 && !valid[3] ) chosen = 2;
83  if (chosen == 2 && !valid[2] ) chosen = 1;
84  if (chosen == 1 && !valid[1] ) chosen = 0;
85 
86  // Done. If pT of the chosen track (or pT of the tracker track) is below the threshold value, return the tracker track.
87  if (valid[chosen] && refit[chosen].first->pt() < ptThreshold && prob[0] > 0.) return make_pair(trackerTrack,reco::Muon::InnerTrack);
88  if (trackerTrack->pt() < ptThreshold && prob[0] > 0.) return make_pair(trackerTrack,reco::Muon::InnerTrack);
89 
90  // Return the chosen track (which can be the global track in
91  // very rare cases).
92  return refit[chosen];
93 }
94 
95 //
96 // calculate the tail probability (-ln(P)) of a fit
97 //
99 
100  int nDOF = (int)track->ndof();
101  if ( nDOF > 0 && track->chi2()> 0) {
102  return -log(TMath::Prob(track->chi2(), nDOF));
103  } else {
104  return 0.0;
105  }
106 
107 }
108 
110  const reco::TrackToTrackMap& map) {
111  reco::TrackToTrackMap::const_iterator it = map.find(combinedTrack);
112  return it == map.end() ? reco::TrackRef() : it->val;
113 }
114 
115 
116 //
117 // Get the sigma-switch decision (tracker-only versus global).
118 //
120  const reco::TrackRef& trackerTrack,
121  const double nSigma,
122  const double ptThreshold) {
123  // If either the global or tracker-only fits have pT below threshold
124  // (default 200 GeV), return the tracker-only fit.
125  if (combinedTrack->pt() < ptThreshold || trackerTrack->pt() < ptThreshold)
126  return make_pair(trackerTrack,reco::Muon::InnerTrack);
127 
128  // If both are above the pT threshold, compare the difference in
129  // q/p: if less than two sigma of the tracker-only track, switch to
130  // global. Otherwise, use tracker-only.
131  const double delta = fabs(trackerTrack->qoverp() - combinedTrack->qoverp());
132  const double threshold = nSigma * trackerTrack->qoverpError();
133  return delta > threshold ? make_pair(trackerTrack,reco::Muon::InnerTrack) : make_pair(combinedTrack,reco::Muon::CombinedTrack);
134 }
135 
136 //
137 // Get the TMR decision (tracker-only versus TPFMS).
138 //
140  const reco::TrackRef& fmsTrack,
141  const double tune) {
142  double probTK = 0;
143  double probFMS = 0;
144 
145  if (trackerTrack.isNonnull() && trackerTrack->numberOfValidHits())
146  probTK = muon::trackProbability(trackerTrack);
147  if (fmsTrack.isNonnull() && fmsTrack->numberOfValidHits())
148  probFMS = muon::trackProbability(fmsTrack);
149 
150  bool TKok = probTK > 0;
151  bool FMSok = probFMS > 0;
152 
153  if (TKok && FMSok) {
154  if (probFMS - probTK > tune)
155  return make_pair(trackerTrack,reco::Muon::InnerTrack);
156  else
157  return make_pair(fmsTrack,reco::Muon::TPFMS);
158  }
159  else if (FMSok)
160  return make_pair(fmsTrack,reco::Muon::TPFMS);
161  else if (TKok)
162  return make_pair(trackerTrack,reco::Muon::InnerTrack);
163  else
164  return make_pair(reco::TrackRef(),reco::Muon::None);
165 }
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
const_iterator end() const
last iterator over the map (read only)
const_iterator find(const key_type &k) const
find element with specified reference key
dictionary map
Definition: Association.py:205
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
reco::Muon::MuonTrackTypePair tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackRef &tpfmsTrack, const reco::TrackRef &pickyTrack, const double ptThreshold=200., const double tune1=17., const double tune2=40., const double dptcut=0.25)
Definition: MuonCocktails.cc:9
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const double nSigma=2., const double ptThreshold=200.)
reco::Muon::MuonTrackTypePair TMR(const reco::TrackRef &trackerTrack, const reco::TrackRef &fmsTrack, const double tune=4.)
bool first
Definition: L1TdeRCT.cc:94
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
reco::TrackRef getTevRefitTrack(const reco::TrackRef &combinedTrack, const reco::TrackToTrackMap &map)
double trackProbability(const reco::TrackRef track)
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:41