CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/PatCandidates/src/Muon.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Muon.cc,v 1.29 2011/06/08 20:40:19 rwolf Exp $
00003 //
00004 
00005 #include "DataFormats/PatCandidates/interface/Muon.h"
00006 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 
00009 #include <limits>
00010 
00011 using namespace pat;
00012 
00013 
00015 Muon::Muon() :
00016     Lepton<reco::Muon>(),
00017     embeddedTrack_(false),
00018     embeddedStandAloneMuon_(false),
00019     embeddedCombinedMuon_(false),
00020     embeddedTCMETMuonCorrs_(false),
00021     embeddedCaloMETMuonCorrs_(false),
00022     embeddedPickyMuon_(false),
00023     embeddedTpfmsMuon_(false),
00024     pickyMuonRef_(),
00025     tpfmsMuonRef_(),
00026     embeddedPFCandidate_(false),
00027     pfCandidateRef_(),
00028     cachedNormChi2_(false),
00029     cachedDB_(false),
00030     cachedNumberOfValidHits_(0),
00031     normChi2_(0.0),
00032     dB_(0.0),
00033     edB_(0.0),
00034     numberOfValidHits_(0)
00035 {
00036   initImpactParameters();
00037 }
00038 
00040 Muon::Muon(const reco::Muon & aMuon) :
00041     Lepton<reco::Muon>(aMuon),
00042     embeddedTrack_(false),
00043     embeddedStandAloneMuon_(false),
00044     embeddedCombinedMuon_(false),
00045     embeddedTCMETMuonCorrs_(false),
00046     embeddedCaloMETMuonCorrs_(false),
00047     embeddedPickyMuon_(false),
00048     embeddedTpfmsMuon_(false),
00049     pickyMuonRef_(),
00050     tpfmsMuonRef_(),
00051     embeddedPFCandidate_(false),
00052     pfCandidateRef_(),
00053     cachedNormChi2_(false),
00054     cachedDB_(false),
00055     cachedNumberOfValidHits_(0),
00056     normChi2_(0.0),
00057     dB_(0.0),
00058     edB_(0.0),
00059     numberOfValidHits_(0)
00060 {
00061   initImpactParameters();
00062 }
00063 
00065 Muon::Muon(const edm::RefToBase<reco::Muon> & aMuonRef) :
00066     Lepton<reco::Muon>(aMuonRef),
00067     embeddedTrack_(false),
00068     embeddedStandAloneMuon_(false),
00069     embeddedCombinedMuon_(false),
00070     embeddedTCMETMuonCorrs_(false),
00071     embeddedCaloMETMuonCorrs_(false),
00072     embeddedPickyMuon_(false),
00073     embeddedTpfmsMuon_(false),
00074     pickyMuonRef_(),
00075     tpfmsMuonRef_(),
00076     embeddedPFCandidate_(false),
00077     pfCandidateRef_(),
00078     cachedNormChi2_(false),
00079     cachedDB_(false),
00080     cachedNumberOfValidHits_(0),
00081     normChi2_(0.0),
00082     dB_(0.0),
00083     edB_(0.0),
00084     numberOfValidHits_(0)
00085 {
00086   initImpactParameters();
00087 }
00088 
00090 Muon::Muon(const edm::Ptr<reco::Muon> & aMuonRef) :
00091     Lepton<reco::Muon>(aMuonRef),
00092     embeddedTrack_(false),
00093     embeddedStandAloneMuon_(false),
00094     embeddedCombinedMuon_(false),
00095     embeddedTCMETMuonCorrs_(false),
00096     embeddedCaloMETMuonCorrs_(false),
00097     embeddedPickyMuon_(false),
00098     embeddedTpfmsMuon_(false),
00099     pickyMuonRef_(),
00100     tpfmsMuonRef_(),
00101     embeddedPFCandidate_(false),
00102     pfCandidateRef_(),
00103     cachedNormChi2_(false),
00104     cachedDB_(false),
00105     cachedNumberOfValidHits_(0),
00106     normChi2_(0.0),
00107     dB_(0.0),
00108     edB_(0.0),
00109     numberOfValidHits_(0)
00110 {
00111   initImpactParameters();
00112 }
00113 
00115 Muon::~Muon() {
00116 }
00117 
00118 std::ostream& 
00119 reco::operator<<(std::ostream& out, const pat::Muon& obj) 
00120 {
00121   if(!out) return out;
00122   
00123   out << "\tpat::Muon: ";
00124   out << std::setiosflags(std::ios::right);
00125   out << std::setiosflags(std::ios::fixed);
00126   out << std::setprecision(3);
00127   out << " E/pT/eta/phi " 
00128       << obj.energy()<<"/"
00129       << obj.pt()<<"/"
00130       << obj.eta()<<"/"
00131       << obj.phi();
00132   return out; 
00133 }
00134 
00135 // initialize impact parameter container vars
00136 void Muon::initImpactParameters() {
00137   for (int i_ = 0; i_<5; ++i_){
00138     ip_.push_back(0.0);
00139     eip_.push_back(0.0);
00140     cachedIP_.push_back(false);
00141   }
00142 }
00143 
00144 
00146 reco::TrackRef Muon::track() const {
00147   if (embeddedTrack_) {
00148     return reco::TrackRef(&track_, 0);
00149   } else {
00150     return reco::Muon::innerTrack();
00151   }
00152 }
00153 
00154 
00156 reco::TrackRef Muon::standAloneMuon() const {
00157   if (embeddedStandAloneMuon_) {
00158     return reco::TrackRef(&standAloneMuon_, 0);
00159   } else {
00160     return reco::Muon::outerTrack();
00161   }
00162 }
00163 
00164 
00166 reco::TrackRef Muon::combinedMuon() const {
00167   if (embeddedCombinedMuon_) {
00168     return reco::TrackRef(&combinedMuon_, 0);
00169   } else {
00170     return reco::Muon::globalTrack();
00171   }
00172 }
00173 
00175 reco::TrackRef Muon::pickyMuon() const {
00176   if (embeddedPickyMuon_) {
00177     return reco::TrackRef(&pickyMuon_, 0);
00178   } else {
00179     return pickyMuonRef_;
00180   }
00181 }
00182 
00184 reco::TrackRef Muon::tpfmsMuon() const {
00185   if (embeddedTpfmsMuon_) {
00186     return reco::TrackRef(&tpfmsMuon_, 0);
00187   } else {
00188     return tpfmsMuonRef_;
00189   }
00190 }
00191 
00193 reco::PFCandidateRef Muon::pfCandidateRef() const {
00194   if (embeddedPFCandidate_) {
00195     return reco::PFCandidateRef(&pfCandidate_, 0);
00196   } else {
00197     return pfCandidateRef_;
00198   }
00199 }
00200 
00202 reco::CandidatePtr Muon::sourceCandidatePtr( size_type i ) const {
00203   if (embeddedPFCandidate_) {
00204     return reco::CandidatePtr( pfCandidateRef_.id(), pfCandidateRef_.get(), pfCandidateRef_.key() ); 
00205   } else {
00206     return reco::CandidatePtr();
00207   }
00208 }
00209 
00211 void Muon::embedTrack() {
00212   track_.clear();
00213   if (reco::Muon::innerTrack().isNonnull()) {
00214       track_.push_back(*reco::Muon::innerTrack());
00215       embeddedTrack_ = true;
00216   }
00217 }
00218 
00219 
00221 void Muon::embedStandAloneMuon() {
00222   standAloneMuon_.clear();
00223   if (reco::Muon::outerTrack().isNonnull()) {
00224       standAloneMuon_.push_back(*reco::Muon::outerTrack());
00225       embeddedStandAloneMuon_ = true;
00226   }
00227 }
00228 
00229 
00231 void Muon::embedCombinedMuon() {
00232   combinedMuon_.clear();
00233   if (reco::Muon::globalTrack().isNonnull()) {
00234       combinedMuon_.push_back(*reco::Muon::globalTrack());
00235       embeddedCombinedMuon_ = true;
00236   }
00237 }
00238 
00240 void Muon::embedCaloMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
00241   caloMETMuonCorrs_.clear();
00242   caloMETMuonCorrs_.push_back(t);
00243   embeddedCaloMETMuonCorrs_ = true;
00244 }
00245 
00247 void Muon::embedTcMETMuonCorrs(const reco::MuonMETCorrectionData& t) {
00248   tcMETMuonCorrs_.clear();
00249   tcMETMuonCorrs_.push_back(t);
00250   embeddedTCMETMuonCorrs_ = true;
00251 }
00252 
00254 void Muon::embedPickyMuon() {
00255   pickyMuon_.clear();
00256   if (pickyMuonRef_.isNonnull()) {
00257       pickyMuon_.push_back(*pickyMuonRef_);
00258       embeddedPickyMuon_ = true;
00259   }
00260 }
00261 
00263 void Muon::embedTpfmsMuon() {
00264   tpfmsMuon_.clear();
00265   if (tpfmsMuonRef_.isNonnull()) {
00266       tpfmsMuon_.push_back(*tpfmsMuonRef_);
00267       embeddedTpfmsMuon_ = true;
00268   }
00269 }
00270 
00272 void Muon::embedPFCandidate() {
00273   pfCandidate_.clear();
00274   if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
00275     pfCandidate_.push_back( *pfCandidateRef_ );
00276     embeddedPFCandidate_ = true;
00277   }
00278 }
00279 
00280 bool Muon::muonID(const std::string& name) const {
00281   muon::SelectionType st = muon::selectionTypeFromString(name);
00282   return muon::isGoodMuon(*this, st);
00283 }
00284 
00285 
00290 double Muon::normChi2() const {
00291   if ( cachedNormChi2_ ) {
00292     return normChi2_;
00293   } else {
00294     reco::TrackRef t = globalTrack();
00295     return t->chi2() / t->ndof();
00296   }
00297 }
00298 
00303 unsigned int Muon::numberOfValidHits() const {
00304   if ( cachedNumberOfValidHits_ ) {
00305     return numberOfValidHits_;
00306   } else {
00307     reco::TrackRef t = innerTrack();
00308     return t->numberOfValidHits();
00309   }
00310 }
00311 
00312 // embed various impact parameters with errors
00313 // IpType defines the type of the impact parameter
00314 // None is default and reverts to old behavior controlled by 
00315 // patMuons.usePV = True/False
00316 double Muon::dB(IpType type_) const {
00317   
00318   // preserve old functionality exactly
00319   if (type_ == None){
00320     if ( cachedDB_ ) {
00321       return dB_;
00322     }
00323     else {
00324       return std::numeric_limits<double>::max();
00325     }
00326   }
00327   
00328   // more IP types (new)
00329   else if ( cachedIP_[type_] ) {
00330     return ip_[type_];
00331   } else {
00332     return std::numeric_limits<double>::max();
00333   }
00334 }
00335 
00336 
00337 // embed various impact parameters with errors
00338 // IpType defines the type of the impact parameter
00339 // None is default and reverts to old behavior controlled by 
00340 // patMuons.usePV = True/False
00341 double Muon::edB(IpType type_) const {
00342 
00343   // preserve old functionality exactly
00344   if (type_ == None){
00345     if ( cachedDB_ ) {
00346       return edB_;
00347     }
00348     else {
00349       return std::numeric_limits<double>::max();
00350     }
00351   }
00352 
00353   // more IP types (new)
00354   else if ( cachedIP_[type_] ) {
00355     return eip_[type_];
00356   } else {
00357     return std::numeric_limits<double>::max();
00358   }
00359 }
00360 
00361 
00362 double Muon::segmentCompatibility(reco::Muon::ArbitrationType arbitrationType) const {
00363    return muon::segmentCompatibility(*this, arbitrationType);
00364 }
00365 
00366