CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/DataFormats/PatCandidates/src/Muon.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Muon.cc,v 1.32.2.3 2013/01/24 13:17:36 bellan Exp $
00003 //
00004 
00005 #include "DataFormats/PatCandidates/interface/Muon.h"
00006 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00007 #include "DataFormats/VertexReco/interface/Vertex.h"
00008 #include "FWCore/Utilities/interface/Exception.h"
00009 #include "DataFormats/MuonReco/interface/MuonCocktails.h"
00010 
00011 #include <limits>
00012 
00013 using namespace pat;
00014 
00015 
00017 Muon::Muon() :
00018     Lepton<reco::Muon>(),
00019     embeddedMuonBestTrack_(false),
00020     embeddedImprovedMuonBestTrack_(false),
00021     improvedMuonBestTrackType_(reco::Muon::None),
00022     embeddedTrack_(false),
00023     embeddedStandAloneMuon_(false),
00024     embeddedCombinedMuon_(false),
00025     embeddedTCMETMuonCorrs_(false),
00026     embeddedCaloMETMuonCorrs_(false),
00027     embeddedPickyMuon_(false),
00028     embeddedTpfmsMuon_(false),
00029     embeddedDytMuon_(false),
00030     embeddedPFCandidate_(false),
00031     pfCandidateRef_(),
00032     cachedNormChi2_(false),
00033     cachedDB_(false),
00034     cachedNumberOfValidHits_(0),
00035     normChi2_(0.0),
00036     dB_(0.0),
00037     edB_(0.0),
00038     numberOfValidHits_(0)
00039 {
00040   initImpactParameters();
00041 }
00042 
00044 Muon::Muon(const reco::Muon & aMuon) :
00045     Lepton<reco::Muon>(aMuon),
00046     embeddedMuonBestTrack_(false),
00047     embeddedImprovedMuonBestTrack_(false),
00048     improvedMuonBestTrackType_(reco::Muon::None),
00049     embeddedTrack_(false),
00050     embeddedStandAloneMuon_(false),
00051     embeddedCombinedMuon_(false),
00052     embeddedTCMETMuonCorrs_(false),
00053     embeddedCaloMETMuonCorrs_(false),
00054     embeddedPickyMuon_(false),
00055     embeddedTpfmsMuon_(false),
00056     embeddedDytMuon_(false),
00057     embeddedPFCandidate_(false),
00058     pfCandidateRef_(),
00059     cachedNormChi2_(false),
00060     cachedDB_(false),
00061     cachedNumberOfValidHits_(0),
00062     normChi2_(0.0),
00063     dB_(0.0),
00064     edB_(0.0),
00065     numberOfValidHits_(0)
00066 {
00067   initImpactParameters();
00068 }
00069 
00071 Muon::Muon(const edm::RefToBase<reco::Muon> & aMuonRef) :
00072     Lepton<reco::Muon>(aMuonRef),
00073     embeddedMuonBestTrack_(false),
00074     embeddedImprovedMuonBestTrack_(false),
00075     improvedMuonBestTrackType_(reco::Muon::None),
00076     embeddedTrack_(false),
00077     embeddedStandAloneMuon_(false),
00078     embeddedCombinedMuon_(false),
00079     embeddedTCMETMuonCorrs_(false),
00080     embeddedCaloMETMuonCorrs_(false),
00081     embeddedPickyMuon_(false),
00082     embeddedTpfmsMuon_(false),
00083     embeddedDytMuon_(false),
00084     embeddedPFCandidate_(false),
00085     pfCandidateRef_(),
00086     cachedNormChi2_(false),
00087     cachedDB_(false),
00088     cachedNumberOfValidHits_(0),
00089     normChi2_(0.0),
00090     dB_(0.0),
00091     edB_(0.0),
00092     numberOfValidHits_(0)
00093 {
00094   initImpactParameters();
00095 }
00096 
00098 Muon::Muon(const edm::Ptr<reco::Muon> & aMuonRef) :
00099     Lepton<reco::Muon>(aMuonRef),
00100     embeddedMuonBestTrack_(false),
00101     embeddedImprovedMuonBestTrack_(false),
00102     improvedMuonBestTrackType_(reco::Muon::None),
00103     embeddedTrack_(false),
00104     embeddedStandAloneMuon_(false),
00105     embeddedCombinedMuon_(false),
00106     embeddedTCMETMuonCorrs_(false),
00107     embeddedCaloMETMuonCorrs_(false),
00108     embeddedPickyMuon_(false),
00109     embeddedTpfmsMuon_(false),
00110     embeddedDytMuon_(false),
00111     embeddedPFCandidate_(false),
00112     pfCandidateRef_(),
00113     cachedNormChi2_(false),
00114     cachedDB_(false),
00115     cachedNumberOfValidHits_(0),
00116     normChi2_(0.0),
00117     dB_(0.0),
00118     edB_(0.0),
00119     numberOfValidHits_(0)
00120 {
00121   initImpactParameters();
00122 }
00123 
00125 Muon::~Muon() {
00126 }
00127 
00128 std::ostream&
00129 reco::operator<<(std::ostream& out, const pat::Muon& obj)
00130 {
00131   if(!out) return out;
00132 
00133   out << "\tpat::Muon: ";
00134   out << std::setiosflags(std::ios::right);
00135   out << std::setiosflags(std::ios::fixed);
00136   out << std::setprecision(3);
00137   out << " E/pT/eta/phi "
00138       << obj.energy()<<"/"
00139       << obj.pt()<<"/"
00140       << obj.eta()<<"/"
00141       << obj.phi();
00142   return out;
00143 }
00144 
00145 // initialize impact parameter container vars
00146 void Muon::initImpactParameters() {
00147   for (int i_ = 0; i_<5; ++i_){
00148     ip_.push_back(0.0);
00149     eip_.push_back(0.0);
00150     cachedIP_.push_back(false);
00151   }
00152 }
00153 
00154 
00156 reco::TrackRef Muon::track() const {
00157   if (embeddedTrack_) {
00158     return reco::TrackRef(&track_, 0);
00159   } else {
00160     return reco::Muon::innerTrack();
00161   }
00162 }
00163 
00164 
00166 reco::TrackRef Muon::standAloneMuon() const {
00167   if (embeddedStandAloneMuon_) {
00168     return reco::TrackRef(&standAloneMuon_, 0);
00169   } else {
00170     return reco::Muon::outerTrack();
00171   }
00172 }
00173 
00174 
00176 reco::TrackRef Muon::combinedMuon() const {
00177   if (embeddedCombinedMuon_) {
00178     return reco::TrackRef(&combinedMuon_, 0);
00179   } else {
00180     return reco::Muon::globalTrack();
00181   }
00182 }
00183 
00185 reco::TrackRef Muon::pickyTrack() const {
00186   if (embeddedPickyMuon_) {
00187     return reco::TrackRef(&pickyMuon_, 0);
00188   } else {
00189     return reco::Muon::pickyTrack();
00190   }
00191 }
00192 
00194 reco::TrackRef Muon::tpfmsTrack() const {
00195   if (embeddedTpfmsMuon_) {
00196     return reco::TrackRef(&tpfmsMuon_, 0);
00197   } else {
00198     return reco::Muon::tpfmsTrack();
00199   }
00200 }
00201 
00203 reco::TrackRef Muon::dytTrack() const {
00204   if (embeddedDytMuon_) {
00205     return reco::TrackRef(&dytMuon_, 0);
00206   } else {
00207     return reco::Muon::dytTrack();
00208   }
00209 }
00210 
00211 reco::TrackRef Muon::muonBestTrack() const {
00212   if (embeddedMuonBestTrack_) {
00213     return reco::TrackRef(&muonBestTrack_,0);
00214   } else {
00215     reco::Muon::MuonTrackTypePair newBestTrack = muon::muonBestTrack(*this, reco::defaultTuneP);
00216     return newBestTrack.first;
00217   }
00218 }
00219 
00220 
00221 reco::TrackRef Muon::improvedMuonBestTrack() const {
00222   if (embeddedImprovedMuonBestTrack_) {
00223     return reco::TrackRef(&improvedMuonBestTrack_,0);
00224   } else {
00225     reco::Muon::MuonTrackTypePair newBestTrack = muon::muonBestTrack(*this, reco::improvedTuneP);
00226     return newBestTrack.first;
00227   }
00228 }
00229 
00230 
00232 reco::PFCandidateRef Muon::pfCandidateRef() const {
00233   if (embeddedPFCandidate_) {
00234     return reco::PFCandidateRef(&pfCandidate_, 0);
00235   } else {
00236     return pfCandidateRef_;
00237   }
00238 }
00239 
00241 reco::CandidatePtr Muon::sourceCandidatePtr( size_type i ) const {
00242   if (embeddedPFCandidate_) {
00243     return reco::CandidatePtr( pfCandidateRef_.id(), pfCandidateRef_.get(), pfCandidateRef_.key() );
00244   } else {
00245     return reco::CandidatePtr();
00246   }
00247 }
00248 
00250 void Muon::embedMuonBestTrack() {
00251   muonBestTrack_.clear();  embeddedMuonBestTrack_ = false;
00252   if (reco::Muon::muonBestTrack().isNonnull()) {
00253       muonBestTrack_.push_back(*reco::Muon::muonBestTrack());
00254       embeddedMuonBestTrack_ = true;
00255   }
00256 }
00257 
00259 void Muon::embedImprovedMuonBestTrack() {
00260   improvedMuonBestTrack_.clear(); embeddedImprovedMuonBestTrack_ = false;
00261 
00262   if(improvedMuonBestTrack().isNonnull()){
00263     improvedMuonBestTrack_.push_back(*improvedMuonBestTrack());
00264     embeddedImprovedMuonBestTrack_ = true;
00265   }
00266   else
00267     edm::LogError("PATMuon|embedImprovedMuonBestTrack") << "Orphan best track this must not happend!";
00268 }
00269 
00270 
00272 void Muon::embedTrack() {
00273   track_.clear();
00274   if (reco::Muon::innerTrack().isNonnull()) {
00275       track_.push_back(*reco::Muon::innerTrack());
00276       embeddedTrack_ = true;
00277   }
00278 }
00279 
00280 
00282 void Muon::embedStandAloneMuon() {
00283   standAloneMuon_.clear();
00284   if (reco::Muon::outerTrack().isNonnull()) {
00285       standAloneMuon_.push_back(*reco::Muon::outerTrack());
00286       embeddedStandAloneMuon_ = true;
00287   }
00288 }
00289 
00290 
00292 void Muon::embedCombinedMuon() {
00293   combinedMuon_.clear();
00294   if (reco::Muon::globalTrack().isNonnull()) {
00295       combinedMuon_.push_back(*reco::Muon::globalTrack());
00296       embeddedCombinedMuon_ = true;
00297   }
00298 }
00299 
00301 void Muon::embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
00302   caloMETMuonCorrs_.clear();
00303   caloMETMuonCorrs_.push_back(t);
00304   embeddedCaloMETMuonCorrs_ = true;
00305 }
00306 
00308 void Muon::embedTcMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
00309   tcMETMuonCorrs_.clear();
00310   tcMETMuonCorrs_.push_back(t);
00311   embeddedTCMETMuonCorrs_ = true;
00312 }
00313 
00315 void Muon::embedPickyMuon() {
00316   pickyMuon_.clear();
00317   reco::TrackRef tk = reco::Muon::pickyTrack();
00318   if (tk.isNonnull()) {
00319     pickyMuon_.push_back(*tk);
00320     embeddedPickyMuon_ = true;
00321   }
00322 }
00323 
00325 void Muon::embedTpfmsMuon() {
00326   tpfmsMuon_.clear();
00327   reco::TrackRef tk = reco::Muon::tpfmsTrack();
00328   if (tk.isNonnull()) {
00329     tpfmsMuon_.push_back(*tk);
00330     embeddedTpfmsMuon_ = true;
00331   }
00332 }
00333 
00335 void Muon::embedDytMuon() {
00336   dytMuon_.clear();
00337   reco::TrackRef tk = reco::Muon::dytTrack();
00338   if (tk.isNonnull()) {
00339     dytMuon_.push_back(*tk);
00340     embeddedDytMuon_ = true;
00341   }
00342 }
00343 
00345 void Muon::embedPFCandidate() {
00346   pfCandidate_.clear();
00347   if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
00348     pfCandidate_.push_back( *pfCandidateRef_ );
00349     embeddedPFCandidate_ = true;
00350   }
00351 }
00352 
00353 bool Muon::muonID(const std::string& name) const {
00354   muon::SelectionType st = muon::selectionTypeFromString(name);
00355   return muon::isGoodMuon(*this, st);
00356 }
00357 
00358 
00363 double Muon::normChi2() const {
00364   if ( cachedNormChi2_ ) {
00365     return normChi2_;
00366   } else {
00367     reco::TrackRef t = globalTrack();
00368     return t->chi2() / t->ndof();
00369   }
00370 }
00371 
00376 unsigned int Muon::numberOfValidHits() const {
00377   if ( cachedNumberOfValidHits_ ) {
00378     return numberOfValidHits_;
00379   } else {
00380     reco::TrackRef t = innerTrack();
00381     return t->numberOfValidHits();
00382   }
00383 }
00384 
00385 // embed various impact parameters with errors
00386 // IpType defines the type of the impact parameter
00387 // None is default and reverts to old behavior controlled by
00388 // patMuons.usePV = True/False
00389 double Muon::dB(IpType type_) const {
00390 
00391   // preserve old functionality exactly
00392   if (type_ == None){
00393     if ( cachedDB_ ) {
00394       return dB_;
00395     }
00396     else {
00397       return std::numeric_limits<double>::max();
00398     }
00399   }
00400 
00401   // more IP types (new)
00402   else if ( cachedIP_[type_] ) {
00403     return ip_[type_];
00404   } else {
00405     return std::numeric_limits<double>::max();
00406   }
00407 }
00408 
00409 
00410 // embed various impact parameters with errors
00411 // IpType defines the type of the impact parameter
00412 // None is default and reverts to old behavior controlled by
00413 // patMuons.usePV = True/False
00414 double Muon::edB(IpType type_) const {
00415 
00416   // preserve old functionality exactly
00417   if (type_ == None){
00418     if ( cachedDB_ ) {
00419       return edB_;
00420     }
00421     else {
00422       return std::numeric_limits<double>::max();
00423     }
00424   }
00425 
00426   // more IP types (new)
00427   else if ( cachedIP_[type_] ) {
00428     return eip_[type_];
00429   } else {
00430     return std::numeric_limits<double>::max();
00431   }
00432 }
00433 
00434 
00435 double Muon::segmentCompatibility(reco::Muon::ArbitrationType arbitrationType) const {
00436    return muon::segmentCompatibility(*this, arbitrationType);
00437 }
00438 
00439 
00440 
00441 // Selectors
00442 bool Muon::isTightMuon(const reco::Vertex&vtx) const {
00443   return muon::isTightMuon(*this, vtx);
00444 }
00445 
00446 bool Muon::isLooseMuon() const {
00447   return muon::isLooseMuon(*this);
00448 
00449 }
00450 
00451 bool Muon::isSoftMuon(const reco::Vertex& vtx) const {
00452   return muon::isSoftMuon(*this, vtx);
00453 }
00454 
00455 
00456 bool Muon::isHighPtMuon(const reco::Vertex& vtx, reco::TunePType type) const{
00457   return muon::isHighPtMuon(*this, vtx, type);
00458 }
00459