CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Muon.cc
Go to the documentation of this file.
1 //
2 //
3 
8 #include <limits>
9 
10 using namespace pat;
11 
12 
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  cachedDB_(false),
30  cachedNumberOfValidHits_(0),
31  normChi2_(0.0),
32  dB_(0.0),
33  edB_(0.0),
34  numberOfValidHits_(0)
35 {
37 }
38 
40 Muon::Muon(const reco::Muon & aMuon) :
41  Lepton<reco::Muon>(aMuon),
42  embeddedMuonBestTrack_(false),
43  embeddedTunePMuonBestTrack_(false),
44  embeddedTrack_(false),
45  embeddedStandAloneMuon_(false),
46  embeddedCombinedMuon_(false),
47  embeddedTCMETMuonCorrs_(false),
48  embeddedCaloMETMuonCorrs_(false),
49  embeddedPickyMuon_(false),
50  embeddedTpfmsMuon_(false),
51  embeddedDytMuon_(false),
52  embeddedPFCandidate_(false),
53  pfCandidateRef_(),
54  cachedNormChi2_(false),
55  cachedDB_(false),
56  cachedNumberOfValidHits_(0),
57  normChi2_(0.0),
58  dB_(0.0),
59  edB_(0.0),
60  numberOfValidHits_(0)
61 {
63 }
64 
67  Lepton<reco::Muon>(aMuonRef),
68  embeddedMuonBestTrack_(false),
69  embeddedTunePMuonBestTrack_(false),
70  embeddedTrack_(false),
71  embeddedStandAloneMuon_(false),
72  embeddedCombinedMuon_(false),
73  embeddedTCMETMuonCorrs_(false),
74  embeddedCaloMETMuonCorrs_(false),
75  embeddedPickyMuon_(false),
76  embeddedTpfmsMuon_(false),
77  embeddedDytMuon_(false),
78  embeddedPFCandidate_(false),
79  pfCandidateRef_(),
80  cachedNormChi2_(false),
81  cachedDB_(false),
82  cachedNumberOfValidHits_(0),
83  normChi2_(0.0),
84  dB_(0.0),
85  edB_(0.0),
86  numberOfValidHits_(0)
87 {
89 }
90 
92 Muon::Muon(const edm::Ptr<reco::Muon> & aMuonRef) :
93  Lepton<reco::Muon>(aMuonRef),
94  embeddedMuonBestTrack_(false),
95  embeddedTunePMuonBestTrack_(false),
96  embeddedTrack_(false),
97  embeddedStandAloneMuon_(false),
98  embeddedCombinedMuon_(false),
99  embeddedTCMETMuonCorrs_(false),
100  embeddedCaloMETMuonCorrs_(false),
101  embeddedPickyMuon_(false),
102  embeddedTpfmsMuon_(false),
103  embeddedDytMuon_(false),
104  embeddedPFCandidate_(false),
105  pfCandidateRef_(),
106  cachedNormChi2_(false),
107  cachedDB_(false),
108  cachedNumberOfValidHits_(0),
109  normChi2_(0.0),
110  dB_(0.0),
111  edB_(0.0),
112  numberOfValidHits_(0)
113 {
115 }
116 
119 }
120 
121 std::ostream&
122 reco::operator<<(std::ostream& out, const pat::Muon& obj)
123 {
124  if(!out) return out;
125 
126  out << "\tpat::Muon: ";
127  out << std::setiosflags(std::ios::right);
128  out << std::setiosflags(std::ios::fixed);
129  out << std::setprecision(3);
130  out << " E/pT/eta/phi "
131  << obj.energy()<<"/"
132  << obj.pt()<<"/"
133  << obj.eta()<<"/"
134  << obj.phi();
135  return out;
136 }
137 
138 // initialize impact parameter container vars
140  for (int i_ = 0; i_<5; ++i_){
141  ip_.push_back(0.0);
142  eip_.push_back(0.0);
143  cachedIP_.push_back(false);
144  }
145 }
146 
147 
150  if (embeddedTrack_) {
151  return reco::TrackRef(&track_, 0);
152  } else {
153  return reco::Muon::innerTrack();
154  }
155 }
156 
157 
161  return reco::TrackRef(&standAloneMuon_, 0);
162  } else {
163  return reco::Muon::outerTrack();
164  }
165 }
166 
167 
170  if (embeddedCombinedMuon_) {
171  return reco::TrackRef(&combinedMuon_, 0);
172  } else {
173  return reco::Muon::globalTrack();
174  }
175 }
176 
179  if (embeddedPickyMuon_) {
180  return reco::TrackRef(&pickyMuon_, 0);
181  } else {
182  return reco::Muon::pickyTrack();
183  }
184 }
185 
188  if (embeddedTpfmsMuon_) {
189  return reco::TrackRef(&tpfmsMuon_, 0);
190  } else {
191  return reco::Muon::tpfmsTrack();
192  }
193 }
194 
197  if (embeddedDytMuon_) {
198  return reco::TrackRef(&dytMuon_, 0);
199  } else {
200  return reco::Muon::dytTrack();
201  }
202 }
203 
206  if (!muonBestTrack_.empty()) {
207  return reco::TrackRef(&muonBestTrack_, 0);
208  } else {
209  return reco::Muon::muonBestTrack();
210  }
211 }
212 
215  if (!tunePMuonBestTrack_.empty()) {
217  } else if (muonBestTrackType() == tunePMuonBestTrackType()) {
218  return muonBestTrack();
219  } else {
221  }
222 }
223 
224 
225 
226 
229  if (embeddedPFCandidate_) {
231  } else {
232  return pfCandidateRef_;
233  }
234 }
235 
239  if(refToOrig_.isNonnull() && pfCandidateRef_.isNonnull() && i==1 ) return refToOrig_;
240  if(refToOrig_.isNonnull() && ! pfCandidateRef_.isNonnull() && i==0 ) return refToOrig_;
241  return reco::CandidatePtr();
242 }
243 
245 void Muon::embedMuonBestTrack(bool force) {
246  muonBestTrack_.clear();
247  embeddedMuonBestTrack_ = false;
248  bool alreadyEmbedded = force;
249  if (!force) {
250  switch (muonBestTrackType()) {
251  case None: alreadyEmbedded = true; break;
252  case InnerTrack: if (embeddedTrack_) alreadyEmbedded = true; break;
253  case OuterTrack: if (embeddedStandAloneMuon_) alreadyEmbedded = true; break;
254  case CombinedTrack: if (embeddedCombinedMuon_) alreadyEmbedded = true; break;
255  case TPFMS: if (embeddedTpfmsMuon_) alreadyEmbedded = true; break;
256  case Picky: if (embeddedPickyMuon_) alreadyEmbedded = true; break;
257  case DYT: if (embeddedDytMuon_) alreadyEmbedded = true; break;
258  }
259  }
260  if (!alreadyEmbedded) {
262  embeddedMuonBestTrack_ = true;
263  }
264 }
265 
268  tunePMuonBestTrack_.clear();
269  bool alreadyEmbedded = force;
271  if (!force) {
272  switch (muonBestTrackType()) {
273  case None: alreadyEmbedded = true; break;
274  case InnerTrack: if (embeddedTrack_) alreadyEmbedded = true; break;
275  case OuterTrack: if (embeddedStandAloneMuon_) alreadyEmbedded = true; break;
276  case CombinedTrack: if (embeddedCombinedMuon_) alreadyEmbedded = true; break;
277  case TPFMS: if (embeddedTpfmsMuon_) alreadyEmbedded = true; break;
278  case Picky: if (embeddedPickyMuon_) alreadyEmbedded = true; break;
279  case DYT: if (embeddedDytMuon_) alreadyEmbedded = true; break;
280  }
282  if (embeddedMuonBestTrack_) alreadyEmbedded = true;
283  }
284  }
285  if (!alreadyEmbedded) {
288  }
289 }
290 
291 
294  track_.clear();
295  if (reco::Muon::innerTrack().isNonnull()) {
296  track_.push_back(*reco::Muon::innerTrack());
297  embeddedTrack_ = true;
298  }
299 }
300 
301 
304  standAloneMuon_.clear();
305  if (reco::Muon::outerTrack().isNonnull()) {
308  }
309 }
310 
311 
314  combinedMuon_.clear();
315  if (reco::Muon::globalTrack().isNonnull()) {
317  embeddedCombinedMuon_ = true;
318  }
319 }
320 
323  caloMETMuonCorrs_.clear();
324  caloMETMuonCorrs_.push_back(t);
326 }
327 
330  tcMETMuonCorrs_.clear();
331  tcMETMuonCorrs_.push_back(t);
333 }
334 
337  pickyMuon_.clear();
339  if (tk.isNonnull()) {
340  pickyMuon_.push_back(*tk);
341  embeddedPickyMuon_ = true;
342  }
343 }
344 
347  tpfmsMuon_.clear();
349  if (tk.isNonnull()) {
350  tpfmsMuon_.push_back(*tk);
351  embeddedTpfmsMuon_ = true;
352  }
353 }
354 
357  dytMuon_.clear();
359  if (tk.isNonnull()) {
360  dytMuon_.push_back(*tk);
361  embeddedDytMuon_ = true;
362  }
363 }
364 
367  pfCandidate_.clear();
369  pfCandidate_.push_back( *pfCandidateRef_ );
370  embeddedPFCandidate_ = true;
371  }
372 }
373 
374 bool Muon::muonID(const std::string& name) const {
376  return muon::isGoodMuon(*this, st);
377 }
378 
379 
384 double Muon::normChi2() const {
385  if ( cachedNormChi2_ ) {
386  return normChi2_;
387  } else {
389  return t->chi2() / t->ndof();
390  }
391 }
392 
397 unsigned int Muon::numberOfValidHits() const {
398  if ( cachedNumberOfValidHits_ ) {
399  return numberOfValidHits_;
400  } else {
402  return t->numberOfValidHits();
403  }
404 }
405 
406 // embed various impact parameters with errors
407 // IpType defines the type of the impact parameter
408 // None is default and reverts to old behavior controlled by
409 // patMuons.usePV = True/False
410 double Muon::dB(IpType type_) const {
411 
412  // preserve old functionality exactly
413  if (type_ == None){
414  if ( cachedDB_ ) {
415  return dB_;
416  }
417  else {
419  }
420  }
421 
422  // more IP types (new)
423  else if ( cachedIP_[type_] ) {
424  return ip_[type_];
425  } else {
427  }
428 }
429 
430 
431 // embed various impact parameters with errors
432 // IpType defines the type of the impact parameter
433 // None is default and reverts to old behavior controlled by
434 // patMuons.usePV = True/False
435 double Muon::edB(IpType type_) const {
436 
437  // preserve old functionality exactly
438  if (type_ == None){
439  if ( cachedDB_ ) {
440  return edB_;
441  }
442  else {
444  }
445  }
446 
447  // more IP types (new)
448  else if ( cachedIP_[type_] ) {
449  return eip_[type_];
450  } else {
452  }
453 }
454 
455 
457  return muon::segmentCompatibility(*this, arbitrationType);
458 }
459 
460 // Selectors
461 bool Muon::isTightMuon(const reco::Vertex&vtx) const {
462  return muon::isTightMuon(*this, vtx);
463 }
464 
465 bool Muon::isLooseMuon() const {
466  return muon::isLooseMuon(*this);
467 
468 }
469 
470 bool Muon::isSoftMuon(const reco::Vertex& vtx) const {
471  return muon::isSoftMuon(*this, vtx);
472 }
473 
474 
475 bool Muon::isHighPtMuon(const reco::Vertex& vtx) const{
476  return muon::isHighPtMuon(*this, vtx);
477 }
478 
double normChi2() const
Norm chi2 gives the normalized chi2 of the global track.
Definition: Muon.cc:384
int i
Definition: DBlmapReader.cc:9
void embedStandAloneMuon()
set reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.cc:303
reco::PFCandidateRef pfCandidateRef_
Definition: Muon.h:285
unsigned int numberOfValidHits() const
numberOfValidHits returns the number of valid hits on the global track.
Definition: Muon.cc:397
reco::TrackRef innerTrack() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
bool embeddedTCMETMuonCorrs_
muon MET corrections for tcMET
Definition: Muon.h:263
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
virtual MuonTrackType muonBestTrackType() const
Definition: Muon.h:64
virtual float pt() const
transverse momentum
void embedPFCandidate()
embed the IsolatedPFCandidate pointed to by pfCandidateRef_
Definition: Muon.cc:366
size_t size_type
Definition: Candidate.h:34
bool muonID(const std::string &name) const
Definition: Muon.cc:374
unsigned int numberOfValidHits_
Definition: Muon.h:301
virtual TrackRef innerTrack() const
Definition: Muon.h:48
void embedMuonBestTrack(bool force=false)
embed the Track selected to be the best measurement of the muon parameters
Definition: Muon.cc:245
unsigned int type_
muon type mask
Definition: Muon.h:269
virtual float phi() const
momentum azimuthal angle
bool embeddedTrack_
track of inner track detector
Definition: Muon.h:253
std::vector< reco::MuonMETCorrectionData > tcMETMuonCorrs_
Definition: Muon.h:264
bool cachedNumberOfValidHits_
has the dB been cached?
Definition: Muon.h:291
double segmentCompatibility(reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration) const
Returns the segment compatibility, using muon::segmentCompatibility (DataFormats/MuonReco/interface/M...
Definition: Muon.cc:456
bool embeddedStandAloneMuon_
track of muon system
Definition: Muon.h:256
std::vector< reco::Track > tunePMuonBestTrack_
Definition: Muon.h:251
bool isAvailable() const
Definition: Ref.h:276
bool embeddedPickyMuon_
Definition: Muon.h:270
virtual TrackRef tpfmsTrack() const
Definition: Muon.h:57
Muon()
default constructor
Definition: Muon.cc:14
void embedPickyMuon()
embed reference to the above picky Track
Definition: Muon.cc:336
bool isLooseMuon(const reco::Muon &)
void embedCombinedMuon()
set reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon...
Definition: Muon.cc:313
SelectionType
Selector type.
Definition: MuonSelectors.h:17
bool isSoftMuon(const reco::Muon &, const reco::Vertex &)
std::vector< reco::Track > pickyMuon_
Definition: Muon.h:273
void embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData &t)
embed the MuonMETCorrectionData for muon corrected caloMET
Definition: Muon.cc:322
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
reco::CandidatePtr sourceCandidatePtr(size_type i) const
get the candidate pointer with index i
Definition: Muon.cc:237
virtual double energy() const
energy
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:152
bool embeddedTpfmsMuon_
Definition: Muon.h:271
bool cachedNormChi2_
Definition: Muon.h:288
reco::PFCandidateRef pfCandidateRef() const
reference to the source IsolatedPFCandidates
Definition: Muon.cc:228
std::vector< reco::MuonMETCorrectionData > caloMETMuonCorrs_
Definition: Muon.h:267
reco::PFCandidateCollection pfCandidate_
Definition: Muon.h:282
virtual reco::TrackRef tunePMuonBestTrack() const
Track selected to be the best measurement of the muon parameters (from muon information alone) ...
Definition: Muon.cc:214
virtual TrackRef muonBestTrack() const
Definition: Muon.h:63
std::ostream & operator<<(std::ostream &, BeamSpot beam)
Definition: BeamSpot.cc:71
std::vector< reco::Track > dytMuon_
Definition: Muon.h:275
double normChi2_
has the numberOfValidHits been cached?
Definition: Muon.h:292
bool isLooseMuon() const
Definition: Muon.cc:465
enum pat::Muon::IPTYPE IpType
void embedTrack()
set reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.cc:293
virtual float eta() const
momentum pseudorapidity
ArbitrationType
define arbitration schemes
Definition: Muon.h:178
bool embeddedTunePMuonBestTrack_
best muon track (muon only)
Definition: Muon.h:250
void embedTcMETMuonCorrs(const reco::MuonMETCorrectionData &t)
embed the MuonMETCorrectionData for tcMET
Definition: Muon.cc:329
Analysis-level lepton class.
Definition: Lepton.h:30
bool embeddedDytMuon_
Definition: Muon.h:272
virtual TrackRef pickyTrack() const
Definition: Muon.h:58
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
std::vector< bool > cachedIP_
Definition: Muon.h:297
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
bool embeddedPFCandidate_
true if the IsolatedPFCandidate is embedded
Definition: Muon.h:279
double dB(IpType type=None) const
Definition: Muon.cc:410
reco::TrackRef tpfmsTrack() const
reference to Track reconstructed using hits in the tracker + info from the first muon station that ha...
Definition: Muon.cc:187
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:51
reco::TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
bool embeddedCaloMETMuonCorrs_
muon MET corrections for caloMET
Definition: Muon.h:266
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
reco::TrackRef combinedMuon() const
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.cc:169
tuple out
Definition: dbtoconf.py:99
bool isHighPtMuon(const reco::Vertex &) const
Definition: Muon.cc:475
reco::TrackRef standAloneMuon() const
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.cc:159
bool isTightMuon(const reco::Vertex &) const
Definition: Muon.cc:461
void embedTpfmsMuon()
embed reference to the above tpfms Track
Definition: Muon.cc:346
std::vector< double > ip_
Definition: Muon.h:298
reco::TrackRef muonBestTrack() const
Track selected to be the best measurement of the muon parameters (including PFlow global information)...
Definition: Muon.cc:205
bool isHighPtMuon(const reco::Muon &, const reco::Vertex &)
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
bool embeddedCombinedMuon_
track of combined fit
Definition: Muon.h:259
bool isSoftMuon(const reco::Vertex &) const
Definition: Muon.cc:470
void embedDytMuon()
embed reference to the above dyt Track
Definition: Muon.cc:356
double edB(IpType type=None) const
Definition: Muon.cc:435
std::vector< double > eip_
Definition: Muon.h:299
SelectionType selectionTypeFromString(const std::string &label)
Definition: MuonSelectors.cc:9
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
bool cachedDB_
has the normalized chi2 been cached?
Definition: Muon.h:289
std::vector< reco::Track > muonBestTrack_
Definition: Muon.h:248
void embedTunePMuonBestTrack(bool force=false)
embed the Track selected to be the best measurement of the muon parameters
Definition: Muon.cc:267
reco::TrackRef dytTrack() const
reference to Track reconstructed using DYT algorithm
Definition: Muon.cc:196
virtual TrackRef dytTrack() const
Definition: Muon.h:59
std::vector< reco::Track > track_
Definition: Muon.h:254
virtual MuonTrackType tunePMuonBestTrackType() const
Definition: Muon.h:66
std::vector< reco::Track > combinedMuon_
Definition: Muon.h:260
std::vector< reco::Track > standAloneMuon_
Definition: Muon.h:257
virtual ~Muon()
destructor
Definition: Muon.cc:118
double edB_
dB and edB are the impact parameter at the primary vertex,
Definition: Muon.h:294
reco::TrackRef pickyTrack() const
reference to Track reconstructed using hits in the tracker + &quot;good&quot; muon hits (reimplemented from rec...
Definition: Muon.cc:178
virtual TrackRef tunePMuonBestTrack() const
Definition: Muon.h:65
double dB_
globalTrack-&gt;chi2() / globalTrack-&gt;ndof()
Definition: Muon.h:293
volatile std::atomic< bool > shutdown_flag false
bool isTightMuon(const reco::Muon &, const reco::Vertex &)
Analysis-level muon class.
Definition: Muon.h:50
edm::Ptr< reco::Candidate > refToOrig_
Definition: PATObject.h:407
bool embeddedMuonBestTrack_
best muon track (global pflow)
Definition: Muon.h:247
reco::TrackRef track() const
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.cc:149
std::vector< reco::Track > tpfmsMuon_
Definition: Muon.h:274
virtual TrackRef globalTrack() const
reference to Track reconstructed in both tracked and muon detector
Definition: Muon.h:54
void initImpactParameters(void)
Definition: Muon.cc:139