CMS 3D CMS Logo

MuonsFromRefitTracksProducer.cc
Go to the documentation of this file.
1 
13 
20 
22  const double cut) {
23  const reco::TrackRef& combinedTrack = muon.globalTrack();
24  const reco::TrackRef& trackerTrack = muon.innerTrack();
25 
26  reco::TrackToTrackMap::const_iterator fmsTrack = fmsMap.find(combinedTrack);
27 
28  double probTK = 0;
29  double probFMS = 0;
30 
31  if (trackerTrack.isAvailable() && trackerTrack->numberOfValidHits())
32  probTK = muon::trackProbability(trackerTrack);
33  if (fmsTrack != fmsMap.end() && fmsTrack->val->numberOfValidHits())
34  probFMS = muon::trackProbability(fmsTrack->val);
35 
36  bool TKok = probTK > 0;
37  bool FMSok = probFMS > 0;
38 
39  if (TKok && FMSok) {
40  if (probFMS - probTK > cut)
41  return make_pair(trackerTrack,reco::Muon::InnerTrack);
42  else
43  return make_pair(fmsTrack->val,reco::Muon::TPFMS);
44  }
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) : make_pair(combinedTrack,reco::Muon::CombinedTrack);
64 }
65 
67 public:
70 
71 private:
72  void produce(edm::Event&, const edm::EventSetup&) override;
73 
74  // Store the track-to-track map(s) used when using TeV refit tracks.
75  bool storeMatchMaps(const edm::Event& event);
76 
77  // Take the muon passed in, clone it (so that we save all the muon
78  // id information such as isolation, calo energy, etc.) and replace
79  // its combined muon track with the passed in track.
81  const reco::Muon::MuonTrackTypePair& newTrack) const;
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 
140 
141  // All the tokens
147 
148 
149 
150 };
151 
153  : src(cfg.getParameter<edm::InputTag>("src")),
154  fromTrackerTrack(cfg.getParameter<bool>("fromTrackerTrack")),
155  fromGlobalTrack(cfg.getParameter<bool>("fromGlobalTrack")),
156  tevMuonTracks(cfg.getParameter<std::string>("tevMuonTracks")),
157  fromCocktail(cfg.getParameter<bool>("fromCocktail")),
158  fromTMR(cfg.getParameter<bool>("fromTMR")),
159  TMRcut(cfg.getParameter<double>("TMRcut")),
160  fromSigmaSwitch(cfg.getParameter<bool>("fromSigmaSwitch")),
161  nSigmaSwitch(cfg.getParameter<double>("nSigmaSwitch")),
162  ptThreshold(cfg.getParameter<double>("ptThreshold"))
163 {
164  fromTeVRefit = tevMuonTracks != "none";
165 
166 
167  srcToken_ = consumes<edm::View<reco::Muon> >(src) ;
168  trackMapToken_ = consumes<reco::TrackToTrackMap> (edm::InputTag(tevMuonTracks, "default"));
169  trackMapDefaultToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks)) ;
170  trackMapFirstHitToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks, "firstHit"));
171  trackMapPickyToken_ = consumes<reco::TrackToTrackMap> (edm::InputTag(tevMuonTracks, "picky"));
172 
173 
174 
175 
176  produces<reco::MuonCollection>();
177 }
178 
180  if (fromCocktail || fromTMR) {
181  event.getByToken(trackMapDefaultToken_,trackMapDefault);
182  event.getByToken(trackMapFirstHitToken_, trackMapFirstHit);
183  event.getByToken(trackMapPickyToken_, trackMapPicky);
184  return !trackMapDefault.failedToGet() &&
186  }
187  else {
188  event.getByToken(trackMapToken_, trackMap);
189  return !trackMap.failedToGet();
190  }
191 }
192 
194  const reco::Muon::MuonTrackTypePair& newTrack) const {
195  // Muon mass to make a four-vector out of the new track.
196  static const double muMass = 0.10566;
197 
198  reco::TrackRef tkTrack = muon.innerTrack();
199  reco::TrackRef muTrack = muon.outerTrack();
200 
201  // Make up a real Muon from the tracker track.
202  reco::Particle::Point vtx(newTrack.first->vx(), newTrack.first->vy(), newTrack.first->vz());
204  double p = newTrack.first->p();
205  p4.SetXYZT(newTrack.first->px(), newTrack.first->py(), newTrack.first->pz(),
206  sqrt(p*p + muMass*muMass));
207 
208  reco::Muon* mu = muon.clone();
209  mu->setCharge(newTrack.first->charge());
210  mu->setP4(p4);
211  mu->setVertex(vtx);
212  mu->setGlobalTrack(newTrack.first);
213  mu->setInnerTrack(tkTrack);
214  mu->setOuterTrack(muTrack);
215  mu->setBestTrack(newTrack.second);
216  return mu;
217 }
218 
220  // Get the global muons from the event.
222  event.getByToken(srcToken_, muons);
223 
224  // If we can't get the global muon collection, or below the
225  // track-to-track maps needed, still produce an empty collection of
226  // muons so consumers don't throw an exception.
227  bool ok = !muons.failedToGet();
228 
229  // If we're instructed to use the TeV refit tracks in some way, we
230  // need the track-to-track maps. If we're making a cocktail muon,
231  // get all three track maps (the cocktail ingredients); else just
232  // get the map which takes the above global tracks to the desired
233  // TeV-muon refitted tracks (firstHit or picky).
234  if (ok && fromTeVRefit)
235  ok = storeMatchMaps(event);
236 
237  // Make the output collection.
238  auto cands = std::make_unique<reco::MuonCollection>();
239 
240  if (ok) {
242  for (muon = muons->begin(); muon != muons->end(); muon++) {
243  // Filter out the so-called trackerMuons and stand-alone muons
244  // (and caloMuons, if they were ever to get into the input muons
245  // collection).
246  if (!muon->isGlobalMuon()) continue;
247 
248  if (fromTeVRefit || fromSigmaSwitch) {
249  // Start out with a null TrackRef.
251 
252  // If making a cocktail muon, use tevOptimized() to get the track
253  // desired. Otherwise, get the refit track from the desired track
254  // map.
255  if (fromTMR)
256  tevTk = tevOptimizedTMR(*muon, *trackMapFirstHit, TMRcut);
257  else if (fromCocktail)
258  tevTk = muon::tevOptimized(*muon);
259  else if (fromSigmaSwitch)
260  tevTk = sigmaSwitch(*muon, nSigmaSwitch, ptThreshold);
261  else {
263  trackMap->find(muon->combinedMuon());
264  if (tevTkRef != trackMap->end())
265  tevTk = make_pair(tevTkRef->val,reco::Muon::CombinedTrack);
266  }
267 
268  // If the TrackRef is valid, make a new Muon that has the same
269  // tracker and stand-alone tracks, but has the refit track as
270  // its global track.
271  if (tevTk.first.isNonnull())
272  cands->push_back(*cloneAndSwitchTrack(*muon, tevTk));
273  }
274  else if (fromTrackerTrack)
275  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->innerTrack(),reco::Muon::InnerTrack)));
276  else if (fromGlobalTrack)
277  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->globalTrack(),reco::Muon::CombinedTrack)));
278  else {
279  cands->push_back(*muon->clone());
280 
281  // Just cloning does not work in the case of the source being
282  // a pat::Muon with embedded track references -- these do not
283  // get copied. Explicitly set them.
284  reco::Muon& last = cands->at(cands->size()-1);
285  if (muon->globalTrack().isTransient())
286  last.setGlobalTrack(muon->globalTrack());
287  if (muon->innerTrack().isTransient())
288  last.setInnerTrack(muon->innerTrack());
289  if (muon->outerTrack().isTransient())
290  last.setOuterTrack(muon->outerTrack());
291  }
292  }
293  }
294  else
295  edm::LogWarning("MuonsFromRefitTracksProducer")
296  << "either " << src << " or the track map(s) " << tevMuonTracks
297  << " not present in the event; producing empty collection";
298 
299  event.put(std::move(cands));
300 }
301 
dbl * delta
Definition: mlp_gen.cc:36
bool isAvailable() const
Definition: Ref.h:577
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon &muon, const double nSigma, const double ptThreshold)
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapPickyToken_
const_iterator end() const
last iterator over the map (read only)
virtual TrackRef innerTrack() const
Definition: Muon.h:48
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
reco::Muon * cloneAndSwitchTrack(const reco::Muon &muon, const reco::Muon::MuonTrackTypePair &newTrack) const
const_iterator find(const key_type &k) const
find element with specified reference key
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapToken_
edm::Handle< reco::TrackToTrackMap > trackMapDefault
void setVertex(const Point &vertex) override
set vertex
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapDefaultToken_
edm::Handle< reco::TrackToTrackMap > trackMap
void setCharge(Charge q) final
set electric charge
Definition: LeafCandidate.h:93
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
bool storeMatchMaps(const edm::Event &event)
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
std::unique_ptr< ViewBase > clone() const
Definition: View.cc:14
void produce(edm::Event &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
edm::Handle< reco::TrackToTrackMap > trackMapFirstHit
math::XYZPoint Point
point in the space
Definition: Particle.h:25
reco::Muon::MuonTrackTypePair tevOptimizedTMR(const reco::Muon &muon, const reco::TrackToTrackMap &fmsMap, const double cut)
const int mu
Definition: Constants.h:22
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
bool failedToGet() const
Definition: HandleBase.h:78
MuonsFromRefitTracksProducer(const edm::ParameterSet &)
edm::Handle< reco::TrackToTrackMap > trackMapPicky
edm::EDGetTokenT< edm::View< reco::Muon > > srcToken_
virtual void setOuterTrack(const TrackRef &t)
set reference to Track
double trackProbability(const reco::TrackRef track)
virtual void setBestTrack(MuonTrackType muonType)
Definition: Muon.h:91
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:21
void setP4(const LorentzVector &p4) final
set 4-momentum
Muon * clone() const override
create a clone
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
def move(src, dest)
Definition: eostools.py:510
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapFirstHitToken_
Definition: event.py:1
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54