CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DataFormats/PatCandidates/src/Electron.cc

Go to the documentation of this file.
00001 //
00002 // $Id: Electron.cc,v 1.29 2012/04/14 02:06:06 tjkim Exp $
00003 //
00004 
00005 #include "DataFormats/PatCandidates/interface/Electron.h"
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 
00008 #include <limits>
00009 
00010 using namespace pat;
00011 
00013 Electron::Electron() :
00014     Lepton<reco::GsfElectron>(),
00015     embeddedGsfElectronCore_(false),
00016     embeddedGsfTrack_(false),
00017     embeddedSuperCluster_(false),
00018     embeddedTrack_(false),
00019     embeddedPFCandidate_(false),
00020     ecalDrivenMomentum_(Candidate::LorentzVector(0.,0.,0.,0.)),
00021     cachedDB_(false),
00022     dB_(0.0),
00023     edB_(0.0)
00024 {
00025   initImpactParameters();
00026 }
00027 
00029 Electron::Electron(const reco::GsfElectron & anElectron) :
00030     Lepton<reco::GsfElectron>(anElectron),
00031     embeddedGsfElectronCore_(false),
00032     embeddedGsfTrack_(false),
00033     embeddedSuperCluster_(false),
00034     embeddedTrack_(false),
00035     embeddedPFCandidate_(false),
00036     ecalDrivenMomentum_(anElectron.p4()),
00037     cachedDB_(false),
00038     dB_(0.0),
00039     edB_(0.0)
00040 {
00041   initImpactParameters();
00042 }
00043 
00045 Electron::Electron(const edm::RefToBase<reco::GsfElectron> & anElectronRef) :
00046     Lepton<reco::GsfElectron>(anElectronRef),
00047     embeddedGsfElectronCore_(false),
00048     embeddedGsfTrack_(false),
00049     embeddedSuperCluster_(false),
00050     embeddedTrack_(false),
00051     embeddedPFCandidate_(false),
00052     ecalDrivenMomentum_(anElectronRef->p4()),
00053     cachedDB_(false),
00054     dB_(0.0),
00055     edB_(0.0)
00056 {
00057   initImpactParameters();
00058 }
00059 
00061 Electron::Electron(const edm::Ptr<reco::GsfElectron> & anElectronRef) :
00062     Lepton<reco::GsfElectron>(anElectronRef),
00063     embeddedGsfElectronCore_(false),
00064     embeddedGsfTrack_(false),
00065     embeddedSuperCluster_(false),
00066     embeddedTrack_(false),
00067     embeddedPFCandidate_(false),
00068     ecalDrivenMomentum_(anElectronRef->p4()),
00069     cachedDB_(false),
00070     dB_(0.0),
00071     edB_(0.0)
00072 {
00073   initImpactParameters();
00074 }
00075 
00077 Electron::~Electron() {
00078 }
00079 
00081 std::ostream& 
00082 reco::operator<<(std::ostream& out, const pat::Electron& obj) 
00083 {
00084   if(!out) return out;
00085   
00086   out << "\tpat::Electron: ";
00087   out << std::setiosflags(std::ios::right);
00088   out << std::setiosflags(std::ios::fixed);
00089   out << std::setprecision(3);
00090   out << " E/pT/eta/phi " 
00091       << obj.energy()<<"/"
00092       << obj.pt()<<"/"
00093       << obj.eta()<<"/"
00094       << obj.phi();
00095   return out; 
00096 }
00097 
00099 void Electron::initImpactParameters() {
00100   for (int i_ = 0; i_<5; ++i_){
00101     ip_.push_back(0.0);
00102     eip_.push_back(0.0);
00103     cachedIP_.push_back(false);
00104   }
00105 }
00106 
00107 
00109 reco::GsfTrackRef Electron::gsfTrack() const {
00110   if (embeddedGsfTrack_) {
00111     return reco::GsfTrackRef(&gsfTrack_, 0);
00112   } else {
00113     return reco::GsfElectron::gsfTrack();
00114   }
00115 }
00116 
00118 reco::GsfElectronCoreRef Electron::core() const {
00119   if (embeddedGsfElectronCore_) {
00120     return reco::GsfElectronCoreRef(&gsfElectronCore_, 0);
00121   } else {
00122     return reco::GsfElectron::core();
00123   }
00124 }
00125 
00126 
00128 reco::SuperClusterRef Electron::superCluster() const {
00129   if (embeddedSuperCluster_) {
00130     return reco::SuperClusterRef(&superCluster_, 0);
00131   } else {
00132     return reco::GsfElectron::superCluster();
00133   }
00134 }
00135 
00137 reco::TrackRef Electron::closestCtfTrackRef() const {
00138   if (embeddedTrack_) {
00139     return reco::TrackRef(&track_, 0);
00140   } else {
00141     return reco::GsfElectron::closestCtfTrackRef();
00142   }
00143 }
00144 
00145 // the name of the method is misleading, users should use gsfTrack of closestCtfTrack
00146 reco::TrackRef Electron::track() const {
00147   return reco::TrackRef();
00148 }
00149 
00151 void Electron::embedGsfElectronCore() {
00152   gsfElectronCore_.clear();
00153   if (reco::GsfElectron::core().isNonnull()) {
00154       gsfElectronCore_.push_back(*reco::GsfElectron::core());
00155       embeddedGsfElectronCore_ = true;
00156   }
00157 }
00158 
00160 void Electron::embedGsfTrack() {
00161   gsfTrack_.clear();
00162   if (reco::GsfElectron::gsfTrack().isNonnull()) {
00163       gsfTrack_.push_back(*reco::GsfElectron::gsfTrack());
00164       embeddedGsfTrack_ = true;
00165   }
00166 }
00167 
00168 
00170 void Electron::embedSuperCluster() {
00171   superCluster_.clear();
00172   if (reco::GsfElectron::superCluster().isNonnull()) {
00173       superCluster_.push_back(*reco::GsfElectron::superCluster());
00174       embeddedSuperCluster_ = true;
00175   }
00176 }
00177 
00179 void Electron::embedTrack() {
00180   track_.clear();
00181   if (reco::GsfElectron::closestCtfTrackRef().isNonnull()) {
00182       track_.push_back(*reco::GsfElectron::closestCtfTrackRef());
00183       embeddedTrack_ = true;
00184   }
00185 }
00186 
00201 float Electron::electronID(const std::string & name) const {
00202     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00203         if (it->first == name) return it->second;
00204     }
00205     cms::Exception ex("Key not found");
00206     ex << "pat::Electron: the ID " << name << " can't be found in this pat::Electron.\n";
00207     ex << "The available IDs are: ";
00208     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00209         ex << "'" << it->first << "' ";
00210     }
00211     ex << ".\n";
00212     throw ex;
00213 }
00214 
00216 bool Electron::isElectronIDAvailable(const std::string & name) const {
00217     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00218         if (it->first == name) return true;
00219     }
00220     return false;
00221 }
00222 
00223 
00225 reco::PFCandidateRef Electron::pfCandidateRef() const {
00226   if (embeddedPFCandidate_) {
00227     return reco::PFCandidateRef(&pfCandidate_, 0);
00228   } else {
00229     return pfCandidateRef_;
00230   }
00231 }
00232 
00234 void Electron::embedPFCandidate() {
00235   pfCandidate_.clear();
00236   if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
00237     pfCandidate_.push_back( *pfCandidateRef_ );
00238     embeddedPFCandidate_ = true;
00239   }
00240 }
00241 
00244 reco::CandidatePtr Electron::sourceCandidatePtr( size_type i ) const {
00245   if (embeddedPFCandidate_) {
00246     return reco::CandidatePtr( pfCandidateRef_.id(), pfCandidateRef_.get(), pfCandidateRef_.key() );
00247   } else {
00248     return reco::CandidatePtr();
00249   }
00250 }
00251 
00252 
00253 
00264 double Electron::dB(IpType type_) const {
00265   // preserve old functionality exactly
00266   if (type_ == None){
00267     if ( cachedDB_ ) {
00268       return dB_;
00269     } else {
00270       return std::numeric_limits<double>::max();
00271     }
00272   }
00273   // more IP types (new)
00274   else if ( cachedIP_[type_] ) {
00275     return ip_[type_];
00276   } else {
00277     return std::numeric_limits<double>::max();
00278   }
00279 }
00280 
00291 double Electron::edB(IpType type_) const {
00292   // preserve old functionality exactly
00293   if (type_ == None) {
00294     if ( cachedDB_ ) {
00295       return edB_;
00296     } else {
00297       return std::numeric_limits<double>::max();
00298     }
00299   }
00300   // more IP types (new)
00301   else if ( cachedIP_[type_] ) {
00302     return eip_[type_];
00303   } else {
00304     return std::numeric_limits<double>::max();
00305   }
00306 
00307 }
00308 
00310 void Electron::setDB(double dB, double edB, IpType type){
00311   if (type == None) { // Preserve  old functionality exactly
00312     dB_ = dB; edB_ = edB;
00313     cachedDB_ = true;
00314   } else {
00315     ip_[type] = dB; 
00316     eip_[type] = edB; 
00317     cachedIP_[type] = true;
00318   }
00319 }
00320 
00322 void Electron::setMvaVariables( double r9, double sigmaIphiIphi, double sigmaIetaIphi, double ip3d){
00323   r9_ = r9;
00324   sigmaIphiIphi_ = sigmaIphiIphi;
00325   sigmaIetaIphi_ = sigmaIetaIphi;
00326   ip3d_ = ip3d;
00327 }