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 
14 
21 
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  }
46  else if (FMSok)
47  return make_pair(fmsTrack->val,reco::Muon::TPFMS);
48  else if (TKok)
49  return make_pair(trackerTrack,reco::Muon::InnerTrack);
50 
51  return make_pair(combinedTrack,reco::Muon::CombinedTrack);
52 }
53 
54  reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon& muon, const double nSigma, const double ptThreshold) {
55  const reco::TrackRef& combinedTrack = muon.globalTrack();
56  const reco::TrackRef& trackerTrack = muon.innerTrack();
57 
58  if (combinedTrack->pt() < ptThreshold || trackerTrack->pt() < ptThreshold)
59  return make_pair(trackerTrack,reco::Muon::InnerTrack);
60 
61  double delta = fabs(trackerTrack->qoverp() - combinedTrack->qoverp());
62  double threshold = nSigma * trackerTrack->qoverpError();
63 
64  return delta > threshold ? make_pair(trackerTrack,reco::Muon::InnerTrack) : make_pair(combinedTrack,reco::Muon::CombinedTrack);
65 }
66 
68 public:
71 
72 private:
73  virtual void beginJob() {}
74  virtual void produce(edm::Event&, const edm::EventSetup&);
75  virtual void endJob() {}
76 
77  // Store the track-to-track map(s) used when using TeV refit tracks.
78  bool storeMatchMaps(const edm::Event& event);
79 
80  // Take the muon passed in, clone it (so that we save all the muon
81  // id information such as isolation, calo energy, etc.) and replace
82  // its combined muon track with the passed in track.
84  const reco::Muon::MuonTrackTypePair& newTrack) const;
85 
86  // The input muons -- i.e. the merged collection of reco::Muons.
88 
89  // Allow building the muon from just the tracker track. This
90  // functionality should go away after understanding the difference
91  // between the output of option 1 of GlobalMuonProducer and just
92  // looking at the tracker tracks of these muons.
94 
95  // Allow building the muon from just the global track. This option
96  // is introduced since starting from CMSSW 3_1_0, the MuonIdProducer
97  // makes the p4() of the reco::Muon object be what we call the sigma
98  // switch above.
100 
101  // If tevMuonTracks below is not "none", use the TeV refit track as
102  // the combined track of the muon.
104 
105  // Optionally switch out the combined muon track for one of the TeV
106  // muon refit tracks, specified by the input tag here
107  // (e.g. "tevMuons:firstHit").
108  std::string tevMuonTracks;
109 
110  // Whether to make a cocktail muon instead of using just the one
111  // type in tevMuonTracks, where "cocktail" means use the result of
112  // Piotr's tevOptimized().
114 
115  // Whether to use the TMR version of the cocktail function, defined
116  // above. If true, overrides fromCocktail.
117  bool fromTMR;
118 
119  // The cut value for TMR, read from the config file.
120  double TMRcut;
121 
122  // Whether to use Adam Everett's sigma-switch method, choosing
123  // between the global track and the tracker track.
125 
126  // The number of sigma to switch on in the above method.
127  double nSigmaSwitch;
128 
129  // The pT threshold to switch at in the above method.
130  double ptThreshold;
131 
132  // If we're not making cocktail muons, trackMap is the map that maps
133  // global tracks to the desired TeV refit (e.g. from globalMuons to
134  // tevMuons:picky).
136 
137  // All the track maps used in making cocktail muons.
141 };
142 
144  : src(cfg.getParameter<edm::InputTag>("src")),
145  fromTrackerTrack(cfg.getParameter<bool>("fromTrackerTrack")),
146  fromGlobalTrack(cfg.getParameter<bool>("fromGlobalTrack")),
147  tevMuonTracks(cfg.getParameter<std::string>("tevMuonTracks")),
148  fromCocktail(cfg.getParameter<bool>("fromCocktail")),
149  fromTMR(cfg.getParameter<bool>("fromTMR")),
150  TMRcut(cfg.getParameter<double>("TMRcut")),
151  fromSigmaSwitch(cfg.getParameter<bool>("fromSigmaSwitch")),
152  nSigmaSwitch(cfg.getParameter<double>("nSigmaSwitch")),
153  ptThreshold(cfg.getParameter<double>("ptThreshold"))
154 {
155  fromTeVRefit = tevMuonTracks != "none";
156  produces<reco::MuonCollection>();
157 }
158 
160  if (fromCocktail || fromTMR) {
161  event.getByLabel(tevMuonTracks, "default", trackMapDefault);
162  event.getByLabel(tevMuonTracks, "firstHit", trackMapFirstHit);
163  event.getByLabel(tevMuonTracks, "picky", trackMapPicky);
164  return !trackMapDefault.failedToGet() &&
166  }
167  else {
168  event.getByLabel(edm::InputTag(tevMuonTracks), trackMap);
169  return !trackMap.failedToGet();
170  }
171 }
172 
174  const reco::Muon::MuonTrackTypePair& newTrack) const {
175  // Muon mass to make a four-vector out of the new track.
176  static const double muMass = 0.10566;
177 
178  reco::TrackRef tkTrack = muon.innerTrack();
179  reco::TrackRef muTrack = muon.outerTrack();
180 
181  // Make up a real Muon from the tracker track.
182  reco::Particle::Point vtx(newTrack.first->vx(), newTrack.first->vy(), newTrack.first->vz());
184  double p = newTrack.first->p();
185  p4.SetXYZT(newTrack.first->px(), newTrack.first->py(), newTrack.first->pz(),
186  sqrt(p*p + muMass*muMass));
187 
188  reco::Muon* mu = muon.clone();
189  mu->setCharge(newTrack.first->charge());
190  mu->setP4(p4);
191  mu->setVertex(vtx);
192  mu->setGlobalTrack(newTrack.first);
193  mu->setInnerTrack(tkTrack);
194  mu->setOuterTrack(muTrack);
195  mu->setBestTrack(newTrack.second);
196  return mu;
197 }
198 
200  // Get the global muons from the event.
202  event.getByLabel(src, muons);
203 
204  // If we can't get the global muon collection, or below the
205  // track-to-track maps needed, still produce an empty collection of
206  // muons so consumers don't throw an exception.
207  bool ok = !muons.failedToGet();
208 
209  // If we're instructed to use the TeV refit tracks in some way, we
210  // need the track-to-track maps. If we're making a cocktail muon,
211  // get all three track maps (the cocktail ingredients); else just
212  // get the map which takes the above global tracks to the desired
213  // TeV-muon refitted tracks (firstHit or picky).
214  if (ok && fromTeVRefit)
215  ok = storeMatchMaps(event);
216 
217  // Make the output collection.
218  std::auto_ptr<reco::MuonCollection> cands(new reco::MuonCollection);
219 
220  if (ok) {
222  for (muon = muons->begin(); muon != muons->end(); muon++) {
223  // Filter out the so-called trackerMuons and stand-alone muons
224  // (and caloMuons, if they were ever to get into the input muons
225  // collection).
226  if (!muon->isGlobalMuon()) continue;
227 
228  if (fromTeVRefit || fromSigmaSwitch) {
229  // Start out with a null TrackRef.
231 
232  // If making a cocktail muon, use tevOptimized() to get the track
233  // desired. Otherwise, get the refit track from the desired track
234  // map.
235  if (fromTMR)
236  tevTk = tevOptimizedTMR(*muon, *trackMapFirstHit, TMRcut);
237  else if (fromCocktail)
239  *trackMapPicky);
240  else if (fromSigmaSwitch)
241  tevTk = sigmaSwitch(*muon, nSigmaSwitch, ptThreshold);
242  else {
244  trackMap->find(muon->combinedMuon());
245  if (tevTkRef != trackMap->end())
246  tevTk = make_pair(tevTkRef->val,reco::Muon::CombinedTrack);
247  }
248 
249  // If the TrackRef is valid, make a new Muon that has the same
250  // tracker and stand-alone tracks, but has the refit track as
251  // its global track.
252  if (tevTk.first.isNonnull())
253  cands->push_back(*cloneAndSwitchTrack(*muon, tevTk));
254  }
255  else if (fromTrackerTrack)
256  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->innerTrack(),reco::Muon::InnerTrack)));
257  else if (fromGlobalTrack)
258  cands->push_back(*cloneAndSwitchTrack(*muon, make_pair(muon->globalTrack(),reco::Muon::CombinedTrack)));
259  else {
260  cands->push_back(*muon->clone());
261 
262  // Just cloning does not work in the case of the source being
263  // a pat::Muon with embedded track references -- these do not
264  // get copied. Explicitly set them.
265  reco::Muon& last = cands->at(cands->size()-1);
266  if (muon->globalTrack().isTransient())
267  last.setGlobalTrack(muon->globalTrack());
268  if (muon->innerTrack().isTransient())
269  last.setInnerTrack(muon->innerTrack());
270  if (muon->outerTrack().isTransient())
271  last.setOuterTrack(muon->outerTrack());
272  }
273  }
274  }
275  else
276  edm::LogWarning("MuonsFromRefitTracksProducer")
277  << "either " << src << " or the track map(s) " << tevMuonTracks
278  << " not present in the event; producing empty collection";
279 
280  event.put(cands);
281 }
282 
dbl * delta
Definition: mlp_gen.cc:36
reco::Muon::MuonTrackTypePair sigmaSwitch(const reco::Muon &muon, const double nSigma, const double ptThreshold)
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void setOuterTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:752
const_iterator end() const
last iterator over the map (read only)
virtual TrackRef innerTrack() const
Definition: Muon.h:49
virtual void setCharge(Charge q)
set electric charge
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:753
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
bool isAvailable() const
Definition: Ref.h:276
edm::Handle< reco::TrackToTrackMap > trackMapDefault
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
edm::Handle< reco::TrackToTrackMap > trackMap
bool storeMatchMaps(const edm::Event &event)
T sqrt(T t)
Definition: SSEVec.h:46
double p4[4]
Definition: TauolaWrapper.h:92
edm::Handle< reco::TrackToTrackMap > trackMapFirstHit
math::XYZPoint Point
point in the space
Definition: Particle.h:29
reco::Muon::MuonTrackTypePair tevOptimizedTMR(const reco::Muon &muon, const reco::TrackToTrackMap &fmsMap, const double cut)
const int mu
Definition: Constants.h:23
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:52
Muon * clone() const
create a clone
Definition: Muon.cc:40
bool failedToGet() const
Definition: HandleBase.h:80
MuonsFromRefitTracksProducer(const edm::ParameterSet &)
edm::Handle< reco::TrackToTrackMap > trackMapPicky
ViewBase * clone() const
Definition: View.cc:13
double trackProbability(const reco::TrackRef track)
virtual void setBestTrack(MuonTrackType muonType)
Definition: Muon.h:94
tuple muons
Definition: patZpeak.py:38
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=4., const double tune2=6., const double dptcut=-1.)
Definition: MuonCocktails.cc:9
std::pair< TrackRef, Muon::MuonTrackType > MuonTrackTypePair
Definition: Muon.h:41
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:756
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:55