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 trackerTrack;
43  else
44  return fmsTrack->val;
45  }
46  else if (FMSok)
47  return fmsTrack->val;
48  else if (TKok)
49  return trackerTrack;
50 
51  return combinedTrack;
52 }
53 
54 reco::TrackRef 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 trackerTrack;
60 
61  double delta = fabs(trackerTrack->qoverp() - combinedTrack->qoverp());
62  double threshold = nSigma * trackerTrack->qoverpError();
63 
64  return delta > threshold ? trackerTrack : 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::TrackRef& 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::TrackRef& 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->vx(), newTrack->vy(), newTrack->vz());
184  double p = newTrack->p();
185  p4.SetXYZT(newTrack->px(), newTrack->py(), newTrack->pz(),
186  sqrt(p*p + muMass*muMass));
187 
188  reco::Muon* mu = muon.clone();
189  mu->setCharge(newTrack->charge());
190  mu->setP4(p4);
191  mu->setVertex(vtx);
192  mu->setGlobalTrack(newTrack);
193  mu->setInnerTrack(tkTrack);
194  mu->setOuterTrack(muTrack);
195  return mu;
196 }
197 
199  // Get the global muons from the event.
201  event.getByLabel(src, muons);
202 
203  // If we can't get the global muon collection, or below the
204  // track-to-track maps needed, still produce an empty collection of
205  // muons so consumers don't throw an exception.
206  bool ok = !muons.failedToGet();
207 
208  // If we're instructed to use the TeV refit tracks in some way, we
209  // need the track-to-track maps. If we're making a cocktail muon,
210  // get all three track maps (the cocktail ingredients); else just
211  // get the map which takes the above global tracks to the desired
212  // TeV-muon refitted tracks (firstHit or picky).
213  if (ok && fromTeVRefit)
214  ok = storeMatchMaps(event);
215 
216  // Make the output collection.
217  std::auto_ptr<reco::MuonCollection> cands(new reco::MuonCollection);
218 
219  if (ok) {
221  for (muon = muons->begin(); muon != muons->end(); muon++) {
222  // Filter out the so-called trackerMuons and stand-alone muons
223  // (and caloMuons, if they were ever to get into the input muons
224  // collection).
225  if (!muon->isGlobalMuon()) continue;
226 
227  if (fromTeVRefit || fromSigmaSwitch) {
228  // Start out with a null TrackRef.
229  reco::TrackRef tevTk;
230 
231  // If making a cocktail muon, use tevOptimized() to get the track
232  // desired. Otherwise, get the refit track from the desired track
233  // map.
234  if (fromTMR)
235  tevTk = tevOptimizedTMR(*muon, *trackMapFirstHit, TMRcut);
236  else if (fromCocktail)
238  *trackMapPicky);
239  else if (fromSigmaSwitch)
240  tevTk = sigmaSwitch(*muon, nSigmaSwitch, ptThreshold);
241  else {
243  trackMap->find(muon->combinedMuon());
244  if (tevTkRef != trackMap->end())
245  tevTk = tevTkRef->val;
246  }
247 
248  // If the TrackRef is valid, make a new Muon that has the same
249  // tracker and stand-alone tracks, but has the refit track as
250  // its global track.
251  if (tevTk.isNonnull())
252  cands->push_back(*cloneAndSwitchTrack(*muon, tevTk));
253  }
254  else if (fromTrackerTrack)
255  cands->push_back(*cloneAndSwitchTrack(*muon, muon->innerTrack()));
256  else if (fromGlobalTrack)
257  cands->push_back(*cloneAndSwitchTrack(*muon, muon->globalTrack()));
258  else {
259  cands->push_back(*muon->clone());
260 
261  // Just cloning does not work in the case of the source being
262  // a pat::Muon with embedded track references -- these do not
263  // get copied. Explicitly set them.
264  reco::Muon& last = cands->at(cands->size()-1);
265  if (muon->globalTrack().isTransient())
266  last.setGlobalTrack(muon->globalTrack());
267  if (muon->innerTrack().isTransient())
268  last.setInnerTrack(muon->innerTrack());
269  if (muon->outerTrack().isTransient())
270  last.setOuterTrack(muon->outerTrack());
271  }
272  }
273  }
274  else
275  edm::LogWarning("MuonsFromRefitTracksProducer")
276  << "either " << src << " or the track map(s) " << tevMuonTracks
277  << " not present in the event; producing empty collection";
278 
279  event.put(cands);
280 }
281 
dbl * delta
Definition: mlp_gen.cc:36
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
virtual void produce(edm::Event &, const edm::EventSetup &)
virtual void setOuterTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:719
const_iterator end() const
last iterator over the map (read only)
virtual TrackRef innerTrack() const
Definition: Muon.h:38
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:720
const_iterator find(const key_type &k) const
find element with specified reference key
virtual void setP4(const LorentzVector &p4)
set 4-momentum
reco::TrackRef tevOptimized(const reco::TrackRef &combinedTrack, const reco::TrackRef &trackerTrack, const reco::TrackToTrackMap tevMap1, const reco::TrackToTrackMap tevMap2, const reco::TrackToTrackMap tevMap3)
bool isAvailable() const
Definition: Ref.h:275
edm::Handle< reco::TrackToTrackMap > trackMapDefault
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
edm::Handle< reco::TrackToTrackMap > trackMap
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:249
bool storeMatchMaps(const edm::Event &event)
T sqrt(T t)
Definition: SSEVec.h:28
double p4[4]
Definition: TauolaWrapper.h:92
edm::Handle< reco::TrackToTrackMap > trackMapFirstHit
math::XYZPoint Point
point in the space
Definition: Particle.h:30
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
reco::TrackRef tevOptimizedTMR(const reco::Muon &muon, const reco::TrackToTrackMap &fmsMap, const double cut)
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:41
Muon * clone() const
create a clone
Definition: Muon.cc:36
tuple cut
Definition: align_tpl.py:88
reco::Muon * cloneAndSwitchTrack(const reco::Muon &muon, const reco::TrackRef &newTrack) const
bool failedToGet() const
Definition: HandleBase.h:80
MuonsFromRefitTracksProducer(const edm::ParameterSet &)
edm::Handle< reco::TrackToTrackMap > trackMapPicky
ViewBase * clone() const
Definition: View.cc:13
reco::TrackRef sigmaSwitch(const reco::Muon &muon, const double nSigma, const double ptThreshold)
double trackProbability(const reco::TrackRef track)
tuple muons
Definition: patZpeak.py:38
virtual void setGlobalTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:723
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
tuple src
Definition: align_tpl.py:87
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:44