CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
53  reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon& muon, const double nSigma, const double ptThreshold) {
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  virtual void beginJob() override {}
73  virtual void produce(edm::Event&, const edm::EventSetup&) override;
74  virtual void endJob() override {}
75 
76  // Store the track-to-track map(s) used when using TeV refit tracks.
77  bool storeMatchMaps(const edm::Event& event);
78 
79  // Take the muon passed in, clone it (so that we save all the muon
80  // id information such as isolation, calo energy, etc.) and replace
81  // its combined muon track with the passed in track.
83  const reco::Muon::MuonTrackTypePair& newTrack) const;
84 
85  // The input muons -- i.e. the merged collection of reco::Muons.
87 
88  // Allow building the muon from just the tracker track. This
89  // functionality should go away after understanding the difference
90  // between the output of option 1 of GlobalMuonProducer and just
91  // looking at the tracker tracks of these muons.
93 
94  // Allow building the muon from just the global track. This option
95  // is introduced since starting from CMSSW 3_1_0, the MuonIdProducer
96  // makes the p4() of the reco::Muon object be what we call the sigma
97  // switch above.
99 
100  // If tevMuonTracks below is not "none", use the TeV refit track as
101  // the combined track of the muon.
103 
104  // Optionally switch out the combined muon track for one of the TeV
105  // muon refit tracks, specified by the input tag here
106  // (e.g. "tevMuons:firstHit").
108 
109  // Whether to make a cocktail muon instead of using just the one
110  // type in tevMuonTracks, where "cocktail" means use the result of
111  // Piotr's tevOptimized().
113 
114  // Whether to use the TMR version of the cocktail function, defined
115  // above. If true, overrides fromCocktail.
116  bool fromTMR;
117 
118  // The cut value for TMR, read from the config file.
119  double TMRcut;
120 
121  // Whether to use Adam Everett's sigma-switch method, choosing
122  // between the global track and the tracker track.
124 
125  // The number of sigma to switch on in the above method.
126  double nSigmaSwitch;
127 
128  // The pT threshold to switch at in the above method.
129  double ptThreshold;
130 
131  // If we're not making cocktail muons, trackMap is the map that maps
132  // global tracks to the desired TeV refit (e.g. from globalMuons to
133  // tevMuons:picky).
135 
136  // All the track maps used in making cocktail muons.
140 
141 
142 
143  // All the tokens
149 
150 
151 
152 };
153 
155  : src(cfg.getParameter<edm::InputTag>("src")),
156  fromTrackerTrack(cfg.getParameter<bool>("fromTrackerTrack")),
157  fromGlobalTrack(cfg.getParameter<bool>("fromGlobalTrack")),
158  tevMuonTracks(cfg.getParameter<std::string>("tevMuonTracks")),
159  fromCocktail(cfg.getParameter<bool>("fromCocktail")),
160  fromTMR(cfg.getParameter<bool>("fromTMR")),
161  TMRcut(cfg.getParameter<double>("TMRcut")),
162  fromSigmaSwitch(cfg.getParameter<bool>("fromSigmaSwitch")),
163  nSigmaSwitch(cfg.getParameter<double>("nSigmaSwitch")),
164  ptThreshold(cfg.getParameter<double>("ptThreshold"))
165 {
166  fromTeVRefit = tevMuonTracks != "none";
167 
168 
169  srcToken_ = consumes<edm::View<reco::Muon> >(src) ;
170  trackMapToken_ = consumes<reco::TrackToTrackMap> (edm::InputTag(tevMuonTracks, "default"));
171  trackMapDefaultToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks)) ;
172  trackMapFirstHitToken_ = consumes<reco::TrackToTrackMap>(edm::InputTag(tevMuonTracks, "firstHit"));
173  trackMapPickyToken_ = consumes<reco::TrackToTrackMap> (edm::InputTag(tevMuonTracks, "picky"));
174 
175 
176 
177 
178  produces<reco::MuonCollection>();
179 }
180 
182  if (fromCocktail || fromTMR) {
183  event.getByToken(trackMapDefaultToken_,trackMapDefault);
184  event.getByToken(trackMapFirstHitToken_, trackMapFirstHit);
185  event.getByToken(trackMapPickyToken_, trackMapPicky);
186  return !trackMapDefault.failedToGet() &&
188  }
189  else {
190  event.getByToken(trackMapToken_, trackMap);
191  return !trackMap.failedToGet();
192  }
193 }
194 
196  const reco::Muon::MuonTrackTypePair& newTrack) const {
197  // Muon mass to make a four-vector out of the new track.
198  static const double muMass = 0.10566;
199 
200  reco::TrackRef tkTrack = muon.innerTrack();
201  reco::TrackRef muTrack = muon.outerTrack();
202 
203  // Make up a real Muon from the tracker track.
204  reco::Particle::Point vtx(newTrack.first->vx(), newTrack.first->vy(), newTrack.first->vz());
206  double p = newTrack.first->p();
207  p4.SetXYZT(newTrack.first->px(), newTrack.first->py(), newTrack.first->pz(),
208  sqrt(p*p + muMass*muMass));
209 
210  reco::Muon* mu = muon.clone();
211  mu->setCharge(newTrack.first->charge());
212  mu->setP4(p4);
213  mu->setVertex(vtx);
214  mu->setGlobalTrack(newTrack.first);
215  mu->setInnerTrack(tkTrack);
216  mu->setOuterTrack(muTrack);
217  mu->setBestTrack(newTrack.second);
218  return mu;
219 }
220 
222  // Get the global muons from the event.
224  event.getByToken(srcToken_, muons);
225 
226  // If we can't get the global muon collection, or below the
227  // track-to-track maps needed, still produce an empty collection of
228  // muons so consumers don't throw an exception.
229  bool ok = !muons.failedToGet();
230 
231  // If we're instructed to use the TeV refit tracks in some way, we
232  // need the track-to-track maps. If we're making a cocktail muon,
233  // get all three track maps (the cocktail ingredients); else just
234  // get the map which takes the above global tracks to the desired
235  // TeV-muon refitted tracks (firstHit or picky).
236  if (ok && fromTeVRefit)
237  ok = storeMatchMaps(event);
238 
239  // Make the output collection.
240  std::auto_ptr<reco::MuonCollection> cands(new reco::MuonCollection);
241 
242  if (ok) {
244  for (muon = muons->begin(); muon != muons->end(); muon++) {
245  // Filter out the so-called trackerMuons and stand-alone muons
246  // (and caloMuons, if they were ever to get into the input muons
247  // collection).
248  if (!muon->isGlobalMuon()) continue;
249 
250  if (fromTeVRefit || fromSigmaSwitch) {
251  // Start out with a null TrackRef.
253 
254  // If making a cocktail muon, use tevOptimized() to get the track
255  // desired. Otherwise, get the refit track from the desired track
256  // map.
257  if (fromTMR)
258  tevTk = tevOptimizedTMR(*muon, *trackMapFirstHit, TMRcut);
259  else if (fromCocktail)
260  tevTk = muon::tevOptimized(*muon);
261  else if (fromSigmaSwitch)
262  tevTk = sigmaSwitch(*muon, nSigmaSwitch, ptThreshold);
263  else {
265  trackMap->find(muon->combinedMuon());
266  if (tevTkRef != trackMap->end())
267  tevTk = make_pair(tevTkRef->val,reco::Muon::CombinedTrack);
268  }
269 
270  // If the TrackRef is valid, make a new Muon that has the same
271  // tracker and stand-alone tracks, but has the refit track as
272  // its global track.
273  if (tevTk.first.isNonnull())
274  cands->push_back(*cloneAndSwitchTrack(*muon, tevTk));
275  }
276  else if (fromTrackerTrack)
277  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->innerTrack(),reco::Muon::InnerTrack)));
278  else if (fromGlobalTrack)
279  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->globalTrack(),reco::Muon::CombinedTrack)));
280  else {
281  cands->push_back(*muon->clone());
282 
283  // Just cloning does not work in the case of the source being
284  // a pat::Muon with embedded track references -- these do not
285  // get copied. Explicitly set them.
286  reco::Muon& last = cands->at(cands->size()-1);
287  if (muon->globalTrack().isTransient())
288  last.setGlobalTrack(muon->globalTrack());
289  if (muon->innerTrack().isTransient())
290  last.setInnerTrack(muon->innerTrack());
291  if (muon->outerTrack().isTransient())
292  last.setOuterTrack(muon->outerTrack());
293  }
294  }
295  }
296  else
297  edm::LogWarning("MuonsFromRefitTracksProducer")
298  << "either " << src << " or the track map(s) " << tevMuonTracks
299  << " not present in the event; producing empty collection";
300 
301  event.put(cands);
302 }
303 
dbl * delta
Definition: mlp_gen.cc:36
bool isAvailable() const
Definition: Ref.h:614
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon &muon, const double nSigma, const double ptThreshold)
tuple cfg
Definition: looper.py:237
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapPickyToken_
const_iterator end() const
last iterator over the map (read only)
virtual TrackRef innerTrack() const
Definition: Muon.h:48
virtual void setCharge(Charge q)
set electric charge
#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
virtual void setP4(const LorentzVector &p4)
set 4-momentum
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapToken_
edm::Handle< reco::TrackToTrackMap > trackMapDefault
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapDefaultToken_
edm::Handle< reco::TrackToTrackMap > trackMap
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
virtual void produce(edm::Event &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
edm::Handle< reco::TrackToTrackMap > trackMapFirstHit
math::XYZPoint Point
point in the space
Definition: Particle.h:31
reco::Muon::MuonTrackTypePair tevOptimizedTMR(const reco::Muon &muon, const reco::TrackToTrackMap &fmsMap, const double cut)
const int mu
Definition: Constants.h:22
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void setVertex(const Point &vertex)
set vertex
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
bool failedToGet() const
Definition: HandleBase.h:80
MuonsFromRefitTracksProducer(const edm::ParameterSet &)
edm::Handle< reco::TrackToTrackMap > trackMapPicky
ViewBase * clone() const
Definition: View.cc:13
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
tuple muons
Definition: patZpeak.py:38
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:40
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:27
Muon * clone() const
create a clone
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
edm::EDGetTokenT< reco::TrackToTrackMap > trackMapFirstHitToken_
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54