CMS 3D CMS Logo

MuonsFromRefitTracksProducer.cc
Go to the documentation of this file.
1 
13 
20 
22  const reco::TrackToTrackMap& fmsMap,
23  const double cut) {
24  const reco::TrackRef& combinedTrack = muon.globalTrack();
25  const reco::TrackRef& trackerTrack = muon.innerTrack();
26 
27  reco::TrackToTrackMap::const_iterator fmsTrack = fmsMap.find(combinedTrack);
28 
29  double probTK = 0;
30  double probFMS = 0;
31 
32  if (trackerTrack.isAvailable() && trackerTrack->numberOfValidHits())
33  probTK = muon::trackProbability(trackerTrack);
34  if (fmsTrack != fmsMap.end() && fmsTrack->val->numberOfValidHits())
35  probFMS = muon::trackProbability(fmsTrack->val);
36 
37  bool TKok = probTK > 0;
38  bool FMSok = probFMS > 0;
39 
40  if (TKok && FMSok) {
41  if (probFMS - probTK > cut)
42  return make_pair(trackerTrack, reco::Muon::InnerTrack);
43  else
44  return make_pair(fmsTrack->val, reco::Muon::TPFMS);
45  } else if (FMSok)
46  return make_pair(fmsTrack->val, reco::Muon::TPFMS);
47  else if (TKok)
48  return make_pair(trackerTrack, reco::Muon::InnerTrack);
49 
50  return make_pair(combinedTrack, reco::Muon::CombinedTrack);
51 }
52 
54  const reco::TrackRef& combinedTrack = muon.globalTrack();
55  const reco::TrackRef& trackerTrack = muon.innerTrack();
56 
57  if (combinedTrack->pt() < ptThreshold || trackerTrack->pt() < ptThreshold)
58  return make_pair(trackerTrack, reco::Muon::InnerTrack);
59 
60  double delta = fabs(trackerTrack->qoverp() - combinedTrack->qoverp());
61  double threshold = nSigma * trackerTrack->qoverpError();
62 
63  return delta > threshold ? make_pair(trackerTrack, reco::Muon::InnerTrack)
64  : make_pair(combinedTrack, reco::Muon::CombinedTrack);
65 }
66 
68 public:
71 
72 private:
73  void produce(edm::Event&, const edm::EventSetup&) override;
74 
75  // Store the track-to-track map(s) used when using TeV refit tracks.
76  bool storeMatchMaps(const edm::Event& event);
77 
78  // Take the muon passed in, clone it (so that we save all the muon
79  // id information such as isolation, calo energy, etc.) and replace
80  // its combined muon track with the passed in track.
82 
83  // The input muons -- i.e. the merged collection of reco::Muons.
85 
86  // Allow building the muon from just the tracker track. This
87  // functionality should go away after understanding the difference
88  // between the output of option 1 of GlobalMuonProducer and just
89  // looking at the tracker tracks of these muons.
91 
92  // Allow building the muon from just the global track. This option
93  // is introduced since starting from CMSSW 3_1_0, the MuonIdProducer
94  // makes the p4() of the reco::Muon object be what we call the sigma
95  // switch above.
97 
98  // If tevMuonTracks below is not "none", use the TeV refit track as
99  // the combined track of the muon.
101 
102  // Optionally switch out the combined muon track for one of the TeV
103  // muon refit tracks, specified by the input tag here
104  // (e.g. "tevMuons:firstHit").
106 
107  // Whether to make a cocktail muon instead of using just the one
108  // type in tevMuonTracks, where "cocktail" means use the result of
109  // Piotr's tevOptimized().
111 
112  // Whether to use the TMR version of the cocktail function, defined
113  // above. If true, overrides fromCocktail.
114  bool fromTMR;
115 
116  // The cut value for TMR, read from the config file.
117  double TMRcut;
118 
119  // Whether to use Adam Everett's sigma-switch method, choosing
120  // between the global track and the tracker track.
122 
123  // The number of sigma to switch on in the above method.
124  double nSigmaSwitch;
125 
126  // The pT threshold to switch at in the above method.
127  double ptThreshold;
128 
129  // If we're not making cocktail muons, trackMap is the map that maps
130  // global tracks to the desired TeV refit (e.g. from globalMuons to
131  // tevMuons:picky).
133 
134  // All the track maps used in making cocktail muons.
138 
139  // All the tokens
145 };
146 
148  : src(cfg.getParameter<edm::InputTag>("src")),
149  fromTrackerTrack(cfg.getParameter<bool>("fromTrackerTrack")),
150  fromGlobalTrack(cfg.getParameter<bool>("fromGlobalTrack")),
151  tevMuonTracks(cfg.getParameter<std::string>("tevMuonTracks")),
152  fromCocktail(cfg.getParameter<bool>("fromCocktail")),
153  fromTMR(cfg.getParameter<bool>("fromTMR")),
154  TMRcut(cfg.getParameter<double>("TMRcut")),
155  fromSigmaSwitch(cfg.getParameter<bool>("fromSigmaSwitch")),
156  nSigmaSwitch(cfg.getParameter<double>("nSigmaSwitch")),
157  ptThreshold(cfg.getParameter<double>("ptThreshold")) {
158  fromTeVRefit = tevMuonTracks != "none";
159 
160  srcToken_ = consumes<edm::View<reco::Muon> >(src);
161  trackMapToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks, "default"));
162  trackMapDefaultToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks));
163  trackMapFirstHitToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks, "firstHit"));
164  trackMapPickyToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks, "picky"));
165 
166  produces<reco::MuonCollection>();
167 }
168 
170  if (fromCocktail || fromTMR) {
171  event.getByToken(trackMapDefaultToken_, trackMapDefault);
172  event.getByToken(trackMapFirstHitToken_, trackMapFirstHit);
173  event.getByToken(trackMapPickyToken_, trackMapPicky);
174  return !trackMapDefault.failedToGet() && !trackMapFirstHit.failedToGet() && !trackMapPicky.failedToGet();
175  } else {
176  event.getByToken(trackMapToken_, trackMap);
177  return !trackMap.failedToGet();
178  }
179 }
180 
182  const reco::Muon::MuonTrackTypePair& newTrack) const {
183  // Muon mass to make a four-vector out of the new track.
184  static const double muMass = 0.10566;
185 
186  reco::TrackRef tkTrack = muon.innerTrack();
187  reco::TrackRef muTrack = muon.outerTrack();
188 
189  // Make up a real Muon from the tracker track.
190  reco::Particle::Point vtx(newTrack.first->vx(), newTrack.first->vy(), newTrack.first->vz());
192  double p = newTrack.first->p();
193  p4.SetXYZT(newTrack.first->px(), newTrack.first->py(), newTrack.first->pz(), sqrt(p * p + muMass * muMass));
194 
195  reco::Muon* mu = muon.clone();
196  mu->setCharge(newTrack.first->charge());
197  mu->setP4(p4);
198  mu->setVertex(vtx);
199  mu->setGlobalTrack(newTrack.first);
200  mu->setInnerTrack(tkTrack);
201  mu->setOuterTrack(muTrack);
202  mu->setBestTrack(newTrack.second);
203  return mu;
204 }
205 
207  // Get the global muons from the event.
209  event.getByToken(srcToken_, muons);
210 
211  // If we can't get the global muon collection, or below the
212  // track-to-track maps needed, still produce an empty collection of
213  // muons so consumers don't throw an exception.
214  bool ok = !muons.failedToGet();
215 
216  // If we're instructed to use the TeV refit tracks in some way, we
217  // need the track-to-track maps. If we're making a cocktail muon,
218  // get all three track maps (the cocktail ingredients); else just
219  // get the map which takes the above global tracks to the desired
220  // TeV-muon refitted tracks (firstHit or picky).
221  if (ok && fromTeVRefit)
223 
224  // Make the output collection.
225  auto cands = std::make_unique<reco::MuonCollection>();
226 
227  if (ok) {
229  for (muon = muons->begin(); muon != muons->end(); muon++) {
230  // Filter out the so-called trackerMuons and stand-alone muons
231  // (and caloMuons, if they were ever to get into the input muons
232  // collection).
233  if (!muon->isGlobalMuon())
234  continue;
235 
236  if (fromTeVRefit || fromSigmaSwitch) {
237  // Start out with a null TrackRef.
239 
240  // If making a cocktail muon, use tevOptimized() to get the track
241  // desired. Otherwise, get the refit track from the desired track
242  // map.
243  if (fromTMR)
245  else if (fromCocktail)
246  tevTk = muon::tevOptimized(*muon);
247  else if (fromSigmaSwitch)
249  else {
250  reco::TrackToTrackMap::const_iterator tevTkRef = trackMap->find(muon->combinedMuon());
251  if (tevTkRef != trackMap->end())
252  tevTk = make_pair(tevTkRef->val, reco::Muon::CombinedTrack);
253  }
254 
255  // If the TrackRef is valid, make a new Muon that has the same
256  // tracker and stand-alone tracks, but has the refit track as
257  // its global track.
258  if (tevTk.first.isNonnull())
259  cands->push_back(*cloneAndSwitchTrack(*muon, tevTk));
260  } else if (fromTrackerTrack)
261  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->innerTrack(), reco::Muon::InnerTrack)));
262  else if (fromGlobalTrack)
263  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->globalTrack(), reco::Muon::CombinedTrack)));
264  else {
265  cands->push_back(*muon->clone());
266 
267  // Just cloning does not work in the case of the source being
268  // a pat::Muon with embedded track references -- these do not
269  // get copied. Explicitly set them.
270  reco::Muon& last = cands->at(cands->size() - 1);
271  if (muon->globalTrack().isTransient())
272  last.setGlobalTrack(muon->globalTrack());
273  if (muon->innerTrack().isTransient())
274  last.setInnerTrack(muon->innerTrack());
275  if (muon->outerTrack().isTransient())
276  last.setOuterTrack(muon->outerTrack());
277  }
278  }
279  } else
280  edm::LogWarning("MuonsFromRefitTracksProducer") << "either " << src << " or the track map(s) " << tevMuonTracks
281  << " not present in the event; producing empty collection";
282 
283  event.put(std::move(cands));
284 }
285 
ewkMuLumiMonitorDQM_cfi.ptThreshold
ptThreshold
Definition: ewkMuLumiMonitorDQM_cfi.py:13
reco::Muon::CombinedTrack
Definition: Muon.h:36
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
MuonsFromRefitTracksProducer::fromGlobalTrack
bool fromGlobalTrack
Definition: MuonsFromRefitTracksProducer.cc:96
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::AssociationMap::find
const_iterator find(const key_type &k) const
find element with specified reference key
Definition: AssociationMap.h:173
reco::Muon::MuonTrackTypePair
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:38
muon::tevOptimized
reco::Muon::MuonTrackTypePair tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackRef &tpfmsTrack, const reco::TrackRef &pickyTrack, const reco::TrackRef &dytTrack, const double ptThreshold=200., const double tune1=17., const double tune2=40., const double dptcut=0.25)
Definition: MuonCocktails.cc:9
Muon.h
TkAlMuonSelectors_cfi.cut
cut
Definition: TkAlMuonSelectors_cfi.py:5
MuonsFromRefitTracksProducer
Definition: MuonsFromRefitTracksProducer.cc:67
muon
Definition: MuonCocktails.h:17
amptDefaultParameters_cff.mu
mu
Definition: amptDefaultParameters_cff.py:16
MuonsFromRefitTracksProducer::fromSigmaSwitch
bool fromSigmaSwitch
Definition: MuonsFromRefitTracksProducer.cc:121
reco::Muon::TPFMS
Definition: Muon.h:36
edm::Ref::isAvailable
bool isAvailable() const
Definition: Ref.h:537
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
MuonsFromRefitTracksProducer::fromTeVRefit
bool fromTeVRefit
Definition: MuonsFromRefitTracksProducer.cc:100
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MuonsFromRefitTracksProducer::fromTrackerTrack
bool fromTrackerTrack
Definition: MuonsFromRefitTracksProducer.cc:90
refitMuons_cfi.TMRcut
TMRcut
Definition: refitMuons_cfi.py:51
refitMuons_cfi.fromSigmaSwitch
fromSigmaSwitch
Definition: refitMuons_cfi.py:55
EDProducer.h
refitMuons_cfi.fromCocktail
fromCocktail
Definition: refitMuons_cfi.py:31
MuonsFromRefitTracksProducer::fromTMR
bool fromTMR
Definition: MuonsFromRefitTracksProducer.cc:114
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
MuonsFromRefitTracksProducer::trackMapPickyToken_
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapPickyToken_
Definition: MuonsFromRefitTracksProducer.cc:144
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
MuonsFromRefitTracksProducer::~MuonsFromRefitTracksProducer
~MuonsFromRefitTracksProducer() override
Definition: MuonsFromRefitTracksProducer.cc:70
reco::Particle::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
MuonsFromRefitTracksProducer::tevMuonTracks
std::string tevMuonTracks
Definition: MuonsFromRefitTracksProducer.cc:105
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
MuonsFromRefitTracksProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuonsFromRefitTracksProducer.cc:206
MuonsFromRefitTracksProducer::fromCocktail
bool fromCocktail
Definition: MuonsFromRefitTracksProducer.cc:110
refitMuons_cfi.fromGlobalTrack
fromGlobalTrack
Definition: refitMuons_cfi.py:41
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
MakerMacros.h
MuonsFromRefitTracksProducer::trackMapToken_
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapToken_
Definition: MuonsFromRefitTracksProducer.cc:141
dqmdumpme.last
last
Definition: dqmdumpme.py:56
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
muon::trackProbability
double trackProbability(const reco::TrackRef track)
Definition: MuonCocktails.cc:122
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MuonCocktails.h
MuonsFromRefitTracksProducer::trackMapFirstHit
edm::Handle< reco::TrackToTrackMap > trackMapFirstHit
Definition: MuonsFromRefitTracksProducer.cc:136
MuonsFromRefitTracksProducer::src
edm::InputTag src
Definition: MuonsFromRefitTracksProducer.cc:84
MuonsFromRefitTracksProducer::trackMapDefault
edm::Handle< reco::TrackToTrackMap > trackMapDefault
Definition: MuonsFromRefitTracksProducer.cc:135
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MuonsFromRefitTracksProducer::ptThreshold
double ptThreshold
Definition: MuonsFromRefitTracksProducer.cc:127
edm::LogWarning
Definition: MessageLogger.h:141
MuonsFromRefitTracksProducer::trackMapDefaultToken_
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapDefaultToken_
Definition: MuonsFromRefitTracksProducer.cc:142
edm::helpers::KeyVal::val
V val
Definition: AssociationMapHelpers.h:33
refitMuons_cfi.nSigmaSwitch
nSigmaSwitch
Definition: refitMuons_cfi.py:58
MuonsFromRefitTracksProducer::nSigmaSwitch
double nSigmaSwitch
Definition: MuonsFromRefitTracksProducer.cc:124
MuonsFromRefitTracksProducer::trackMap
edm::Handle< reco::TrackToTrackMap > trackMap
Definition: MuonsFromRefitTracksProducer.cc:132
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
edm::AssociationMap
Definition: AssociationMap.h:48
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
MuonsFromRefitTracksProducer::MuonsFromRefitTracksProducer
MuonsFromRefitTracksProducer(const edm::ParameterSet &)
Definition: MuonsFromRefitTracksProducer.cc:147
sigmaSwitch
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon &muon, const double nSigma, const double ptThreshold)
Definition: MuonsFromRefitTracksProducer.cc:53
MuonsFromRefitTracksProducer::storeMatchMaps
bool storeMatchMaps(const edm::Event &event)
Definition: MuonsFromRefitTracksProducer.cc:169
MuonsFromRefitTracksProducer::trackMapPicky
edm::Handle< reco::TrackToTrackMap > trackMapPicky
Definition: MuonsFromRefitTracksProducer.cc:137
p4
double p4[4]
Definition: TauolaWrapper.h:92
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
MuonsFromRefitTracksProducer::TMRcut
double TMRcut
Definition: MuonsFromRefitTracksProducer.cc:117
MuonsFromRefitTracksProducer::cloneAndSwitchTrack
reco::Muon * cloneAndSwitchTrack(const reco::Muon &muon, const reco::Muon::MuonTrackTypePair &newTrack) const
Definition: MuonsFromRefitTracksProducer.cc:181
reco::Muon::InnerTrack
Definition: Muon.h:36
fastsim::Constants::muMass
static constexpr double muMass
Muon mass [GeV].
Definition: Constants.h:14
looper.cfg
cfg
Definition: looper.py:297
refitMuons_cfi.fromTMR
fromTMR
Definition: refitMuons_cfi.py:48
refitMuons_cfi.tevMuonTracks
tevMuonTracks
Definition: refitMuons_cfi.py:24
refitMuons_cfi.fromTrackerTrack
fromTrackerTrack
Definition: refitMuons_cfi.py:36
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
HLT_2018_cff.cands
cands
Definition: HLT_2018_cff.py:13762
MuonsFromRefitTracksProducer::srcToken_
edm::EDGetTokenT< edm::View< reco::Muon > > srcToken_
Definition: MuonsFromRefitTracksProducer.cc:140
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
reco::Particle::Point
math::XYZPoint Point
point in the space
Definition: Particle.h:25
MuonsFromRefitTracksProducer::trackMapFirstHitToken_
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapFirstHitToken_
Definition: MuonsFromRefitTracksProducer.cc:143
ParameterSet.h
tevOptimizedTMR
reco::Muon::MuonTrackTypePair tevOptimizedTMR(const reco::Muon &muon, const reco::TrackToTrackMap &fmsMap, const double cut)
Definition: MuonsFromRefitTracksProducer.cc:21
event
Definition: event.py:1
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:426
edm::Event
Definition: Event.h:73
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
HLTSiStripMonitoring_cff.nSigma
nSigma
Definition: HLTSiStripMonitoring_cff.py:151
edm::InputTag
Definition: InputTag.h:15
TrackToTrackMap.h