CMS 3D CMS Logo

Muon.cc
Go to the documentation of this file.
1 //
2 //
3 
8 #include <limits>
9 
10 using namespace pat;
11 
12 
14 Muon::Muon() :
15  Lepton<reco::Muon>(),
16  embeddedMuonBestTrack_(false),
17  embeddedTunePMuonBestTrack_(false),
18  embeddedTrack_(false),
19  embeddedStandAloneMuon_(false),
20  embeddedCombinedMuon_(false),
21  embeddedTCMETMuonCorrs_(false),
22  embeddedCaloMETMuonCorrs_(false),
23  embeddedPickyMuon_(false),
24  embeddedTpfmsMuon_(false),
25  embeddedDytMuon_(false),
26  embeddedPFCandidate_(false),
27  pfCandidateRef_(),
28  cachedNormChi2_(false),
29  normChi2_(0.0),
30  cachedNumberOfValidHits_(false),
31  numberOfValidHits_(0),
32  pfEcalEnergy_(0)
33 {
34  initImpactParameters();
35 }
36 
38 Muon::Muon(const reco::Muon & aMuon) :
39  Lepton<reco::Muon>(aMuon),
40  embeddedMuonBestTrack_(false),
41  embeddedTunePMuonBestTrack_(false),
42  embeddedTrack_(false),
43  embeddedStandAloneMuon_(false),
44  embeddedCombinedMuon_(false),
45  embeddedTCMETMuonCorrs_(false),
46  embeddedCaloMETMuonCorrs_(false),
47  embeddedPickyMuon_(false),
48  embeddedTpfmsMuon_(false),
49  embeddedDytMuon_(false),
50  embeddedPFCandidate_(false),
51  pfCandidateRef_(),
52  cachedNormChi2_(false),
53  normChi2_(0.0),
54  cachedNumberOfValidHits_(false),
55  numberOfValidHits_(0),
56  pfEcalEnergy_(0)
57 {
58  initImpactParameters();
59 }
60 
62 Muon::Muon(const edm::RefToBase<reco::Muon> & aMuonRef) :
63  Lepton<reco::Muon>(aMuonRef),
64  embeddedMuonBestTrack_(false),
65  embeddedTunePMuonBestTrack_(false),
66  embeddedTrack_(false),
67  embeddedStandAloneMuon_(false),
68  embeddedCombinedMuon_(false),
69  embeddedTCMETMuonCorrs_(false),
70  embeddedCaloMETMuonCorrs_(false),
71  embeddedPickyMuon_(false),
72  embeddedTpfmsMuon_(false),
73  embeddedDytMuon_(false),
74  embeddedPFCandidate_(false),
75  pfCandidateRef_(),
76  cachedNormChi2_(false),
77  normChi2_(0.0),
78  cachedNumberOfValidHits_(0),
79  numberOfValidHits_(0),
80  pfEcalEnergy_(0)
81 {
82  initImpactParameters();
83 }
84 
86 Muon::Muon(const edm::Ptr<reco::Muon> & aMuonRef) :
87  Lepton<reco::Muon>(aMuonRef),
88  embeddedMuonBestTrack_(false),
89  embeddedTunePMuonBestTrack_(false),
90  embeddedTrack_(false),
91  embeddedStandAloneMuon_(false),
92  embeddedCombinedMuon_(false),
93  embeddedTCMETMuonCorrs_(false),
94  embeddedCaloMETMuonCorrs_(false),
95  embeddedPickyMuon_(false),
96  embeddedTpfmsMuon_(false),
97  embeddedDytMuon_(false),
98  embeddedPFCandidate_(false),
99  pfCandidateRef_(),
100  cachedNormChi2_(false),
101  normChi2_(0.0),
102  cachedNumberOfValidHits_(0),
103  numberOfValidHits_(0),
104  pfEcalEnergy_(0)
105 {
106  initImpactParameters();
107 }
108 
110 Muon::~Muon() {
111 }
112 
113 std::ostream&
114 reco::operator<<(std::ostream& out, const pat::Muon& obj)
115 {
116  if(!out) return out;
117 
118  out << "\tpat::Muon: ";
119  out << std::setiosflags(std::ios::right);
120  out << std::setiosflags(std::ios::fixed);
121  out << std::setprecision(3);
122  out << " E/pT/eta/phi "
123  << obj.energy()<<"/"
124  << obj.pt()<<"/"
125  << obj.eta()<<"/"
126  << obj.phi();
127  return out;
128 }
129 
130 // initialize impact parameter container vars
131 void Muon::initImpactParameters() {
132  std::fill(ip_, ip_+IpTypeSize, 0.0f);
133  std::fill(eip_, eip_+IpTypeSize, 0.0f);
134  cachedIP_ = 0;
135 }
136 
137 
139 reco::TrackRef Muon::track() const {
140  if (embeddedTrack_) {
141  return reco::TrackRef(&track_, 0);
142  } else {
143  return reco::Muon::innerTrack();
144  }
145 }
146 
147 
150  if (embeddedStandAloneMuon_) {
151  return reco::TrackRef(&standAloneMuon_, 0);
152  } else {
153  return reco::Muon::outerTrack();
154  }
155 }
156 
157 
159 reco::TrackRef Muon::combinedMuon() const {
160  if (embeddedCombinedMuon_) {
161  return reco::TrackRef(&combinedMuon_, 0);
162  } else {
163  return reco::Muon::globalTrack();
164  }
165 }
166 
168 reco::TrackRef Muon::pickyTrack() const {
169  if (embeddedPickyMuon_) {
170  return reco::TrackRef(&pickyMuon_, 0);
171  } else {
172  return reco::Muon::pickyTrack();
173  }
174 }
175 
177 reco::TrackRef Muon::tpfmsTrack() const {
178  if (embeddedTpfmsMuon_) {
179  return reco::TrackRef(&tpfmsMuon_, 0);
180  } else {
181  return reco::Muon::tpfmsTrack();
182  }
183 }
184 
186 reco::TrackRef Muon::dytTrack() const {
187  if (embeddedDytMuon_) {
188  return reco::TrackRef(&dytMuon_, 0);
189  } else {
190  return reco::Muon::dytTrack();
191  }
192 }
193 
195 reco::TrackRef Muon::muonBestTrack() const {
196  if (!muonBestTrack_.empty()) {
197  return reco::TrackRef(&muonBestTrack_, 0);
198  } else {
199  return reco::Muon::muonBestTrack();
200  }
201 }
202 
204 reco::TrackRef Muon::tunePMuonBestTrack() const {
205  if (!tunePMuonBestTrack_.empty()) {
206  return reco::TrackRef(&tunePMuonBestTrack_, 0);
207  } else if (muonBestTrackType() == tunePMuonBestTrackType()) {
208  return muonBestTrack();
209  } else {
211  }
212 }
213 
214 
215 
216 
218 reco::PFCandidateRef Muon::pfCandidateRef() const {
219  if (embeddedPFCandidate_) {
221  } else {
222  return pfCandidateRef_;
223  }
224 }
225 
228  if(pfCandidateRef_.isNonnull() && i==0 ) return reco::CandidatePtr(edm::refToPtr(pfCandidateRef_) );
229  if(refToOrig_.isNonnull() && pfCandidateRef_.isNonnull() && i==1 ) return refToOrig_;
230  if(refToOrig_.isNonnull() && ! pfCandidateRef_.isNonnull() && i==0 ) return refToOrig_;
231  return reco::CandidatePtr();
232 }
233 
235 void Muon::embedMuonBestTrack(bool force) {
236  muonBestTrack_.clear();
237  embeddedMuonBestTrack_ = false;
238  bool alreadyEmbedded = false;
239  if (!force) {
240  switch (muonBestTrackType()) {
241  case None: alreadyEmbedded = true; break;
242  case InnerTrack: if (embeddedTrack_) alreadyEmbedded = true; break;
243  case OuterTrack: if (embeddedStandAloneMuon_) alreadyEmbedded = true; break;
244  case CombinedTrack: if (embeddedCombinedMuon_) alreadyEmbedded = true; break;
245  case TPFMS: if (embeddedTpfmsMuon_) alreadyEmbedded = true; break;
246  case Picky: if (embeddedPickyMuon_) alreadyEmbedded = true; break;
247  case DYT: if (embeddedDytMuon_) alreadyEmbedded = true; break;
248  }
249  }
250  if (force || !alreadyEmbedded) {
251  muonBestTrack_.push_back(*reco::Muon::muonBestTrack());
252  embeddedMuonBestTrack_ = true;
253  }
254 }
255 
258  tunePMuonBestTrack_.clear();
259  bool alreadyEmbedded = false;
260  embeddedTunePMuonBestTrack_ = false;
261  if (!force) {
262  switch (tunePMuonBestTrackType()) {
263  case None: alreadyEmbedded = true; break;
264  case InnerTrack: if (embeddedTrack_) alreadyEmbedded = true; break;
265  case OuterTrack: if (embeddedStandAloneMuon_) alreadyEmbedded = true; break;
266  case CombinedTrack: if (embeddedCombinedMuon_) alreadyEmbedded = true; break;
267  case TPFMS: if (embeddedTpfmsMuon_) alreadyEmbedded = true; break;
268  case Picky: if (embeddedPickyMuon_) alreadyEmbedded = true; break;
269  case DYT: if (embeddedDytMuon_) alreadyEmbedded = true; break;
270  }
271  if (muonBestTrackType() == tunePMuonBestTrackType()) {
272  if (embeddedMuonBestTrack_) alreadyEmbedded = true;
273  }
274  }
275  if (force || !alreadyEmbedded) {
276  tunePMuonBestTrack_.push_back(*reco::Muon::tunePMuonBestTrack());
277  embeddedTunePMuonBestTrack_ = true;
278  }
279 }
280 
281 
283 void Muon::embedTrack() {
284  track_.clear();
285  if (reco::Muon::innerTrack().isNonnull()) {
286  track_.push_back(*reco::Muon::innerTrack());
287  embeddedTrack_ = true;
288  }
289 }
290 
291 
294  standAloneMuon_.clear();
295  if (reco::Muon::outerTrack().isNonnull()) {
296  standAloneMuon_.push_back(*reco::Muon::outerTrack());
297  embeddedStandAloneMuon_ = true;
298  }
299 }
300 
301 
304  combinedMuon_.clear();
305  if (reco::Muon::globalTrack().isNonnull()) {
306  combinedMuon_.push_back(*reco::Muon::globalTrack());
307  embeddedCombinedMuon_ = true;
308  }
309 }
310 
313  caloMETMuonCorrs_.clear();
314  caloMETMuonCorrs_.push_back(t);
315  embeddedCaloMETMuonCorrs_ = true;
316 }
317 
320  tcMETMuonCorrs_.clear();
321  tcMETMuonCorrs_.push_back(t);
322  embeddedTCMETMuonCorrs_ = true;
323 }
324 
326 void Muon::embedPickyMuon() {
327  pickyMuon_.clear();
329  if (tk.isNonnull()) {
330  pickyMuon_.push_back(*tk);
331  embeddedPickyMuon_ = true;
332  }
333 }
334 
336 void Muon::embedTpfmsMuon() {
337  tpfmsMuon_.clear();
339  if (tk.isNonnull()) {
340  tpfmsMuon_.push_back(*tk);
341  embeddedTpfmsMuon_ = true;
342  }
343 }
344 
346 void Muon::embedDytMuon() {
347  dytMuon_.clear();
349  if (tk.isNonnull()) {
350  dytMuon_.push_back(*tk);
351  embeddedDytMuon_ = true;
352  }
353 }
354 
356 void Muon::embedPFCandidate() {
357  pfCandidate_.clear();
358  if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
359  pfCandidate_.push_back( *pfCandidateRef_ );
360  embeddedPFCandidate_ = true;
361  }
362 }
363 
364 bool Muon::muonID(const std::string& name) const {
366  return muon::isGoodMuon(*this, st);
367 }
368 
369 
374 double Muon::normChi2() const {
375  if ( cachedNormChi2_ ) {
376  return normChi2_;
377  } else {
379  return t->chi2() / t->ndof();
380  }
381 }
382 
387 unsigned int Muon::numberOfValidHits() const {
388  if ( cachedNumberOfValidHits_ ) {
389  return numberOfValidHits_;
390  } else {
392  return t->numberOfValidHits();
393  }
394 }
395 
396 // embed various impact parameters with errors
397 // IpType defines the type of the impact parameter
398 double Muon::dB(IpType type_) const {
399  // more IP types (new)
400  if ( cachedIP_ & (1 << int(type_))) {
401  return ip_[type_];
402  } else {
404  }
405 }
406 
407 
408 // embed various impact parameters with errors
409 // IpType defines the type of the impact parameter
410 double Muon::edB(IpType type_) const {
411  // more IP types (new)
412  if ( cachedIP_ & (1 << int(type_))) {
413  return eip_[type_];
414  } else {
416  }
417 }
418 
419 
420 double Muon::segmentCompatibility(reco::Muon::ArbitrationType arbitrationType) const {
421  return muon::segmentCompatibility(*this, arbitrationType);
422 }
423 
424 // Selectors
425 bool Muon::isTightMuon(const reco::Vertex&vtx) const {
426  return muon::isTightMuon(*this, vtx);
427 }
428 
429 bool Muon::isLooseMuon() const {
430  return muon::isLooseMuon(*this);
431 
432 }
433 
434 bool Muon::isMediumMuon() const {
435  return muon::isMediumMuon(*this);
436 
437 }
438 
439 bool Muon::isSoftMuon(const reco::Vertex& vtx) const {
440  return muon::isSoftMuon(*this, vtx);
441 }
442 
443 
444 bool Muon::isHighPtMuon(const reco::Vertex& vtx) const{
445  return muon::isHighPtMuon(*this, vtx);
446 }
447 
virtual double pt() const final
transverse momentum
embedCombinedMuon
whether to embed in AOD externally stored standalone muon track
embedPFCandidate
embed in AOD externally stored the electron&#39;s pflow preshower clusters
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
size_t size_type
Definition: Candidate.h:30
virtual double eta() const final
momentum pseudorapidity
virtual TrackRef innerTrack() const
Definition: Muon.h:48
embedDytMuon
embed in AOD externally stored TeV-refit TPFMS muon track
~Muon()
Definition: Muon.cc:96
reco::PFCandidatePtr pfCandidate_
bool isMediumMuon(const reco::Muon &)
virtual TrackRef tpfmsTrack() const
Definition: Muon.h:57
bool isLooseMuon(const reco::Muon &)
SelectionType
Selector type.
Definition: MuonSelectors.h:17
Definition: HeavyIon.h:7
bool isSoftMuon(const reco::Muon &, const reco::Vertex &)
embedPickyMuon
embed in AOD externally stored standalone muon track
virtual double phi() const final
momentum azimuthal angle
virtual TrackRef muonBestTrack() const
Definition: Muon.h:63
Muon()
default constructor
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:71
embedTrack
embed in AOD externally stored particle flow candidate
Definition: Muon.py:1
ArbitrationType
define arbitration schemes
Definition: Muon.h:182
virtual double energy() const final
energy
virtual CandidatePtr sourceCandidatePtr(size_type i) const
Definition: LeafCandidate.h:86
virtual TrackRef pickyTrack() const
Definition: Muon.h:58
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
double f[11][100]
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
static const int muonID
Definition: TopGenEvent.h:20
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
embedTpfmsMuon
embed in AOD externally stored TeV-refit picky muon track
SelectionType selectionTypeFromString(const std::string &label)
Definition: MuonSelectors.cc:9
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:20
virtual TrackRef dytTrack() const
Definition: Muon.h:59
fixed size matrix
embedStandAloneMuon
whether to embed in AOD externally stored gsf track
embedTunePMuonBestTrack
embed in AOD externally stored muon best track from global pflow
virtual TrackRef tunePMuonBestTrack() const
Definition: Muon.h:65
Definition: Lepton.py:1
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Analysis-level muon class.
Definition: Muon.h:49
Muon()
Definition: Muon.cc:3
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54