CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 //
00002 // $Id: Electron.cc,v 1.26 2011/06/08 20:40:19 rwolf 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 
00080 std::ostream& 
00081 reco::operator<<(std::ostream& out, const pat::Electron& obj) 
00082 {
00083   if(!out) return out;
00084   
00085   out << "\tpat::Electron: ";
00086   out << std::setiosflags(std::ios::right);
00087   out << std::setiosflags(std::ios::fixed);
00088   out << std::setprecision(3);
00089   out << " E/pT/eta/phi " 
00090       << obj.energy()<<"/"
00091       << obj.pt()<<"/"
00092       << obj.eta()<<"/"
00093       << obj.phi();
00094   return out; 
00095 }
00096 
00097 // initialize impact parameter container vars
00098 void Electron::initImpactParameters() {
00099   for (int i_ = 0; i_<5; ++i_){
00100     ip_.push_back(0.0);
00101     eip_.push_back(0.0);
00102     cachedIP_.push_back(false);
00103   }
00104 }
00105 
00106 
00108 reco::GsfTrackRef Electron::gsfTrack() const {
00109   if (embeddedGsfTrack_) {
00110     return reco::GsfTrackRef(&gsfTrack_, 0);
00111   } else {
00112     return reco::GsfElectron::gsfTrack();
00113   }
00114 }
00115 
00117 reco::GsfElectronCoreRef Electron::core() const {
00118   if (embeddedGsfElectronCore_) {
00119     return reco::GsfElectronCoreRef(&gsfElectronCore_, 0);
00120   } else {
00121     return reco::GsfElectron::core();
00122   }
00123 }
00124 
00125 
00127 reco::SuperClusterRef Electron::superCluster() const {
00128   if (embeddedSuperCluster_) {
00129     return reco::SuperClusterRef(&superCluster_, 0);
00130   } else {
00131     return reco::GsfElectron::superCluster();
00132   }
00133 }
00134 
00135 
00137 reco::TrackRef Electron::track() const {
00138   if (embeddedTrack_) {
00139     return reco::TrackRef(&track_, 0);
00140   } else {
00141     return reco::GsfElectron::track();
00142   }
00143 }
00144 
00146 void Electron::embedGsfElectronCore() {
00147   gsfElectronCore_.clear();
00148   if (reco::GsfElectron::core().isNonnull()) {
00149       gsfElectronCore_.push_back(*reco::GsfElectron::core());
00150       embeddedGsfElectronCore_ = true;
00151   }
00152 }
00153 
00155 void Electron::embedGsfTrack() {
00156   gsfTrack_.clear();
00157   if (reco::GsfElectron::gsfTrack().isNonnull()) {
00158       gsfTrack_.push_back(*reco::GsfElectron::gsfTrack());
00159       embeddedGsfTrack_ = true;
00160   }
00161 }
00162 
00163 
00165 void Electron::embedSuperCluster() {
00166   superCluster_.clear();
00167   if (reco::GsfElectron::superCluster().isNonnull()) {
00168       superCluster_.push_back(*reco::GsfElectron::superCluster());
00169       embeddedSuperCluster_ = true;
00170   }
00171 }
00172 
00173 
00175 void Electron::embedTrack() {
00176   track_.clear();
00177   if (reco::GsfElectron::track().isNonnull()) {
00178       track_.push_back(*reco::GsfElectron::track());
00179       embeddedTrack_ = true;
00180   }
00181 }
00182 
00183 // method to retrieve a lepton ID (or throw)
00184 float Electron::electronID(const std::string & name) const {
00185     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00186         if (it->first == name) return it->second;
00187     }
00188     cms::Exception ex("Key not found");
00189     ex << "pat::Electron: the ID " << name << " can't be found in this pat::Electron.\n";
00190     ex << "The available IDs are: ";
00191     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00192         ex << "'" << it->first << "' ";
00193     }
00194     ex << ".\n";
00195     throw ex;
00196 }
00197 // check if an ID is there
00198 bool Electron::isElectronIDAvailable(const std::string & name) const {
00199     for (std::vector<IdPair>::const_iterator it = electronIDs_.begin(), ed = electronIDs_.end(); it != ed; ++it) {
00200         if (it->first == name) return true;
00201     }
00202     return false;
00203 }
00204 
00205 
00207 reco::PFCandidateRef Electron::pfCandidateRef() const {
00208   if (embeddedPFCandidate_) {
00209     return reco::PFCandidateRef(&pfCandidate_, 0);
00210   } else {
00211     return pfCandidateRef_;
00212   }
00213 }
00215 void Electron::embedPFCandidate() {
00216   pfCandidate_.clear();
00217   if ( pfCandidateRef_.isAvailable() && pfCandidateRef_.isNonnull()) {
00218     pfCandidate_.push_back( *pfCandidateRef_ );
00219     embeddedPFCandidate_ = true;
00220   }
00221 }
00222 
00224 reco::CandidatePtr Electron::sourceCandidatePtr( size_type i ) const {
00225   if (embeddedPFCandidate_) {
00226     return reco::CandidatePtr( pfCandidateRef_.id(), pfCandidateRef_.get(), pfCandidateRef_.key() );
00227   } else {
00228     return reco::CandidatePtr();
00229   }
00230 }
00231 
00232 
00233 
00237 double Electron::dB(IpType type_) const {
00238   // preserve old functionality exactly
00239   if (type_ == None){
00240     if ( cachedDB_ ) {
00241       return dB_;
00242     } else {
00243       return std::numeric_limits<double>::max();
00244     }
00245   }
00246   // more IP types (new)
00247   else if ( cachedIP_[type_] ) {
00248     return ip_[type_];
00249   } else {
00250     return std::numeric_limits<double>::max();
00251   }
00252 }
00253 
00257 double Electron::edB(IpType type_) const {
00258   // preserve old functionality exactly
00259   if (type_ == None) {
00260     if ( cachedDB_ ) {
00261       return edB_;
00262     } else {
00263       return std::numeric_limits<double>::max();
00264     }
00265   }
00266   // more IP types (new)
00267   else if ( cachedIP_[type_] ) {
00268     return eip_[type_];
00269   } else {
00270     return std::numeric_limits<double>::max();
00271   }
00272 
00273 }
00274 
00275 void Electron::setDB(double dB, double edB, IpType type){
00276   if (type == None) { // Preserve  old functionality exactly
00277     dB_ = dB; edB_ = edB;
00278     cachedDB_ = true;
00279   } else {
00280     ip_[type] = dB; 
00281     eip_[type] = edB; 
00282     cachedIP_[type] = true;
00283   }
00284 }
00285