Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:53

0001 //
0002 //
0003 
0004 #ifndef DataFormats_PatCandidates_Electron_h
0005 #define DataFormats_PatCandidates_Electron_h
0006 
0007 /**
0008   \class    pat::Electron Electron.h "DataFormats/PatCandidates/interface/Electron.h"
0009   \brief    Analysis-level electron class
0010 
0011    pat::Electron implements the analysis-level electron class within the
0012    'pat' namespace.
0013 
0014    Please post comments and questions to the Physics Tools hypernews:
0015    https://hypernews.cern.ch/HyperNews/CMS/get/physTools.html
0016 
0017   \author   Steven Lowette, Giovanni Petrucciani, Frederic Ronga
0018 */
0019 
0020 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0021 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0022 #include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
0023 #include "DataFormats/EgammaCandidates/interface/GsfElectronCoreFwd.h"
0024 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
0025 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0026 #include "DataFormats/PatCandidates/interface/Lepton.h"
0027 
0028 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0029 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
0030 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
0031 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0032 #include "DataFormats/Common/interface/AtomicPtrCache.h"
0033 
0034 // Define typedefs for convenience
0035 namespace pat {
0036   class Electron;
0037   typedef std::vector<Electron> ElectronCollection;
0038   typedef edm::Ref<ElectronCollection> ElectronRef;
0039   typedef edm::RefVector<ElectronCollection> ElectronRefVector;
0040 }  // namespace pat
0041 
0042 namespace reco {
0043   /// pipe operator (introduced to use pat::Electron with PFTopProjectors)
0044   std::ostream& operator<<(std::ostream& out, const pat::Electron& obj);
0045 }  // namespace reco
0046 
0047 // Class definition
0048 namespace pat {
0049   class PATElectronSlimmer;
0050 
0051   class Electron : public Lepton<reco::GsfElectron> {
0052   public:
0053     typedef std::pair<std::string, float> IdPair;
0054 
0055     /// default constructor
0056     Electron();
0057     /// constructor from reco::GsfElectron
0058     Electron(const reco::GsfElectron& anElectron);
0059     /// constructor from a RefToBase to a reco::GsfElectron (to be superseded by Ptr counterpart)
0060     Electron(const edm::RefToBase<reco::GsfElectron>& anElectronRef);
0061     /// constructor from a Ptr to a reco::GsfElectron
0062     Electron(const edm::Ptr<reco::GsfElectron>& anElectronRef);
0063     /// destructor
0064     ~Electron() override;
0065 
0066     /// required reimplementation of the Candidate's clone method
0067     Electron* clone() const override { return new Electron(*this); }
0068 
0069     // ---- methods for content embedding ----
0070     /// override the virtual reco::GsfElectron::core method, so that the embedded core can be used by GsfElectron client methods
0071     reco::GsfElectronCoreRef core() const override;
0072     /// override the reco::GsfElectron::gsfTrack method, to access the internal storage of the supercluster
0073     reco::GsfTrackRef gsfTrack() const override;
0074     /// override the reco::GsfElectron::superCluster method, to access the internal storage of the supercluster
0075     reco::SuperClusterRef superCluster() const override;
0076     /// override the reco::GsfElectron::pflowSuperCluster method, to access the internal storage of the pflowSuperCluster
0077     reco::SuperClusterRef parentSuperCluster() const override;
0078     /// returns nothing. Use either gsfTrack or closestCtfTrack
0079     reco::TrackRef track() const override;
0080     /// override the reco::GsfElectron::closestCtfTrackRef method, to access the internal storage of the track
0081     reco::TrackRef closestCtfTrackRef() const override;
0082     /// direct access to the seed cluster
0083     reco::CaloClusterPtr seed() const;
0084 
0085     //method to access the basic clusters
0086     const std::vector<reco::CaloCluster>& basicClusters() const { return basicClusters_; }
0087     //method to access the preshower clusters
0088     const std::vector<reco::CaloCluster>& preshowerClusters() const { return preshowerClusters_; }
0089     //method to access the pflow basic clusters
0090     const std::vector<reco::CaloCluster>& pflowBasicClusters() const { return pflowBasicClusters_; }
0091     //method to access the pflow preshower clusters
0092     const std::vector<reco::CaloCluster>& pflowPreshowerClusters() const { return pflowPreshowerClusters_; }
0093 
0094     using reco::RecoCandidate::track;  // avoid hiding the base implementation
0095     /// method to store the electron's core internally
0096     void embedGsfElectronCore();
0097     /// method to store the electron's GsfTrack internally
0098     void embedGsfTrack();
0099     /// method to store the electron's SuperCluster internally
0100     void embedSuperCluster();
0101     /// method to store the electron's PflowSuperCluster internally
0102     void embedPflowSuperCluster();
0103     /// method to store the electron's seedcluster internally
0104     void embedSeedCluster();
0105     /// method to store the electron's basic clusters
0106     void embedBasicClusters();
0107     /// method to store the electron's preshower clusters
0108     void embedPreshowerClusters();
0109     /// method to store the electron's pflow basic clusters
0110     void embedPflowBasicClusters();
0111     /// method to store the electron's pflow preshower clusters
0112     void embedPflowPreshowerClusters();
0113     /// method to store the electron's Track internally
0114     void embedTrack();
0115     /// method to store the RecHits internally - can be called from the PATElectronProducer
0116     void embedRecHits(const EcalRecHitCollection* rechits);
0117 
0118     // ---- methods for electron ID ----
0119     /// Returns a specific electron ID associated to the pat::Electron given its name
0120     // For cut-based IDs, the value map has the following meaning:
0121     // 0: fails,
0122     // 1: passes electron ID only,
0123     // 2: passes electron Isolation only,
0124     // 3: passes electron ID and Isolation only,
0125     // 4: passes conversion rejection,
0126     // 5: passes conversion rejection and ID,
0127     // 6: passes conversion rejection and Isolation,
0128     // 7: passes the whole selection.
0129     // For more details have a look at:
0130     // https://twiki.cern.ch/twiki/bin/view/CMS/SimpleCutBasedEleID
0131     // https://twiki.cern.ch/twiki/bin/view/CMS/SWGuideCategoryBasedElectronID
0132     // Note: an exception is thrown if the specified ID is not available
0133     float electronID(const std::string& name) const;
0134     float electronID(const char* name) const { return electronID(std::string(name)); }
0135     /// Returns true if a specific ID is available in this pat::Electron
0136     bool isElectronIDAvailable(const std::string& name) const;
0137     bool isElectronIDAvailable(const char* name) const { return isElectronIDAvailable(std::string(name)); }
0138     /// Returns all the electron IDs in the form of <name,value> pairs. The 'default' ID is the first in the list
0139     const std::vector<IdPair>& electronIDs() const { return electronIDs_; }
0140     /// Store multiple electron ID values, discarding existing ones. The first one in the list becomes the 'default' electron id
0141     void setElectronIDs(const std::vector<IdPair>& ids) { electronIDs_ = ids; }
0142 
0143     // ---- overload of isolation functions ----
0144     /// Overload of pat::Lepton::trackIso(); returns the value of the summed track pt in a cone of deltaR<0.4
0145     float trackIso() const { return dr04TkSumPt(); }
0146     /// Overload of pat::Lepton::ecalIso(); returns the value of the summed Et of all recHits in the ecal in a cone of deltaR<0.4
0147     float ecalIso() const { return dr04EcalRecHitSumEt(); }
0148     /// Overload of pat::Lepton::hcalIso(); returns the value of the summed Et of all caloTowers in the hcal in a cone of deltaR<0.4
0149     float hcalIso() const { return dr04HcalTowerSumEt(); }
0150     /// Overload of pat::Lepton::caloIso(); returns the sum of ecalIso() and hcalIso
0151     float caloIso() const { return ecalIso() + hcalIso(); }
0152     /// returns PUPPI isolations
0153     float puppiChargedHadronIso() const { return puppiChargedHadronIso_; }
0154     float puppiNeutralHadronIso() const { return puppiNeutralHadronIso_; }
0155     float puppiPhotonIso() const { return puppiPhotonIso_; }
0156     /// returns PUPPINoLeptons isolations
0157     float puppiNoLeptonsChargedHadronIso() const { return puppiNoLeptonsChargedHadronIso_; }
0158     float puppiNoLeptonsNeutralHadronIso() const { return puppiNoLeptonsNeutralHadronIso_; }
0159     float puppiNoLeptonsPhotonIso() const { return puppiNoLeptonsPhotonIso_; }
0160     /// sets PUPPI isolations
0161     void setIsolationPUPPI(float chargedhadrons_, float neutralhadrons_, float photons_) {
0162       puppiChargedHadronIso_ = chargedhadrons_;
0163       puppiNeutralHadronIso_ = neutralhadrons_;
0164       puppiPhotonIso_ = photons_;
0165     }
0166     /// sets PUPPINoLeptons isolations
0167     void setIsolationPUPPINoLeptons(float chargedhadrons_, float neutralhadrons_, float photons_) {
0168       puppiNoLeptonsChargedHadronIso_ = chargedhadrons_;
0169       puppiNoLeptonsNeutralHadronIso_ = neutralhadrons_;
0170       puppiNoLeptonsPhotonIso_ = photons_;
0171     }
0172     // ---- PF specific methods ----
0173     bool isPF() const { return isPF_; }
0174     void setIsPF(bool hasPFCandidate) { isPF_ = hasPFCandidate; }
0175 
0176     /// reference to the source PFCandidates; null if this has been built from a standard electron
0177     reco::PFCandidateRef pfCandidateRef() const;
0178     /// add a reference to the source IsolatedPFCandidate
0179     void setPFCandidateRef(const reco::PFCandidateRef& ref) { pfCandidateRef_ = ref; }
0180     /// embed the PFCandidate pointed to by pfCandidateRef_
0181     void embedPFCandidate();
0182     /// get the number of non-null PFCandidates
0183     size_t numberOfSourceCandidatePtrs() const override {
0184       return (pfCandidateRef_.isNonnull() ? 1 : 0) + associatedPackedFCandidateIndices_.size();
0185     }
0186     /// get the source candidate pointer with index i
0187     reco::CandidatePtr sourceCandidatePtr(size_type i) const override;
0188 
0189     // ---- embed various impact parameters with errors ----
0190     typedef enum IPTYPE { PV2D = 0, PV3D = 1, BS2D = 2, BS3D = 3, PVDZ = 4, IpTypeSize = 5 } IpType;
0191     /// Impact parameter wrt primary vertex or beamspot
0192     double dB(IPTYPE type) const;
0193     /// Uncertainty on the corresponding impact parameter
0194     double edB(IPTYPE type) const;
0195     /// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
0196     double dB() const { return std::abs(dB(PV2D)); }
0197     /// the version without arguments returns PD2D, but with an absolute value (for backwards compatibility)
0198     double edB() const { return std::abs(edB(PV2D)); }
0199     /// Set impact parameter of a certain type and its uncertainty
0200     void setDB(double dB, double edB, IPTYPE type);
0201 
0202     // ---- Momentum estimate specific methods ----
0203     const LorentzVector& ecalDrivenMomentum() const { return ecalDrivenMomentum_; }
0204     void setEcalDrivenMomentum(const Candidate::LorentzVector& mom) { ecalDrivenMomentum_ = mom; }
0205 
0206     /// pipe operator (introduced to use pat::Electron with PFTopProjectors)
0207     friend std::ostream& reco::operator<<(std::ostream& out, const pat::Electron& obj);
0208 
0209     /// additional mva input variables
0210     /// sigmaIEtaIPhi
0211     float sigmaIetaIphi() const { return sigmaIetaIphi_; }
0212     /// sigmaIEtaIPhi (from full 5x5 non-ZS clusters without fractions, a la 5.3.X)
0213     float full5x5_sigmaIetaIphi() const { return full5x5_sigmaIetaIphi_; }
0214     /// ip3d
0215     double ip3d() const { return ip3d_; }
0216     /// set missing mva input variables
0217     void setMvaVariables(double sigmaIetaIphi, double ip3d);
0218     void full5x5_setSigmaIetaIphi(float sigmaIetaIphi) { full5x5_sigmaIetaIphi_ = sigmaIetaIphi; }
0219 
0220     const EcalRecHitCollection* recHits() const { return &recHits_; }
0221 
0222     /// additional regression variables
0223     /// regression1
0224     double ecalRegressionEnergy() const { return ecalRegressionEnergy_; }
0225     double ecalRegressionError() const { return ecalRegressionError_; }
0226     /// regression2
0227     double ecalTrackRegressionEnergy() const { return ecalTrackRegressionEnergy_; }
0228     double ecalTrackRegressionError() const { return ecalTrackRegressionError_; }
0229     /// set regression1
0230     void setEcalRegressionEnergy(double val, double err) {
0231       ecalRegressionEnergy_ = val;
0232       ecalRegressionError_ = err;
0233     }
0234     /// set regression2
0235     void setEcalTrackRegressionEnergy(double val, double err) {
0236       ecalTrackRegressionEnergy_ = val;
0237       ecalTrackRegressionError_ = err;
0238     }
0239 
0240     /// set scale corrections / smearings
0241     void setEcalScale(double val) { ecalScale_ = val; }
0242     void setEcalSmear(double val) { ecalSmear_ = val; }
0243     void setEcalRegressionScale(double val) { ecalRegressionScale_ = val; }
0244     void setEcalRegressionSmear(double val) { ecalRegressionSmear_ = val; }
0245     void setEcalTrackRegressionScale(double val) { ecalTrackRegressionScale_ = val; }
0246     void setEcalTrackRegressionSmear(double val) { ecalTrackRegressionSmear_ = val; }
0247 
0248     /// get scale corrections /smearings
0249     double ecalScale() const { return ecalScale_; }
0250     double ecalSmear() const { return ecalSmear_; }
0251     double ecalRegressionScale() const { return ecalRegressionScale_; }
0252     double ecalRegressionSmear() const { return ecalRegressionSmear_; }
0253     double ecalTrackRegressionScale() const { return ecalTrackRegressionScale_; }
0254     double ecalTrackRegressionSmear() const { return ecalTrackRegressionSmear_; }
0255     /// vertex fit combined with missing number of hits method
0256     bool passConversionVeto() const { return passConversionVeto_; }
0257     void setPassConversionVeto(bool flag) { passConversionVeto_ = flag; }
0258 
0259     /// References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet reclustering)
0260     edm::RefVector<pat::PackedCandidateCollection> associatedPackedPFCandidates() const;
0261     /// References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet reclustering)
0262     template <typename T>
0263     void setAssociatedPackedPFCandidates(const edm::RefProd<pat::PackedCandidateCollection>& refprod,
0264                                          T beginIndexItr,
0265                                          T endIndexItr) {
0266       packedPFCandidates_ = refprod;
0267       associatedPackedFCandidateIndices_.clear();
0268       associatedPackedFCandidateIndices_.insert(associatedPackedFCandidateIndices_.end(), beginIndexItr, endIndexItr);
0269     }
0270 
0271     friend class PATElectronSlimmer;
0272 
0273   protected:
0274     /// init impact parameter defaults (for use in a constructor)
0275     void initImpactParameters();
0276 
0277     // ---- for content embedding ----
0278     /// True if electron's gsfElectronCore is stored internally
0279     bool embeddedGsfElectronCore_;
0280     /// Place to store electron's gsfElectronCore internally
0281     std::vector<reco::GsfElectronCore> gsfElectronCore_;
0282     /// True if electron's gsfTrack is stored internally
0283     bool embeddedGsfTrack_;
0284     /// Place to store electron's gsfTrack internally
0285     std::vector<reco::GsfTrack> gsfTrack_;
0286     /// True if electron's supercluster is stored internally
0287     bool embeddedSuperCluster_;
0288     /// True if electron's pflowsupercluster is stored internally
0289     bool embeddedPflowSuperCluster_;
0290     /// Place to store electron's supercluster internally
0291     std::vector<reco::SuperCluster> superCluster_;
0292     /// Place to temporarily store the electron's supercluster after relinking the seed to it
0293     edm::AtomicPtrCache<std::vector<reco::SuperCluster> > superClusterRelinked_;
0294     /// Place to store electron's basic clusters internally
0295     std::vector<reco::CaloCluster> basicClusters_;
0296     /// Place to store electron's preshower clusters internally
0297     std::vector<reco::CaloCluster> preshowerClusters_;
0298     /// Place to store electron's pflow basic clusters internally
0299     std::vector<reco::CaloCluster> pflowBasicClusters_;
0300     /// Place to store electron's pflow preshower clusters internally
0301     std::vector<reco::CaloCluster> pflowPreshowerClusters_;
0302     /// Place to store electron's pflow supercluster internally
0303     std::vector<reco::SuperCluster> pflowSuperCluster_;
0304     /// True if electron's track is stored internally
0305     bool embeddedTrack_;
0306     /// Place to store electron's track internally
0307     std::vector<reco::Track> track_;
0308     /// True if seed cluster is stored internally
0309     bool embeddedSeedCluster_;
0310     /// Place to store electron's seed cluster internally
0311     std::vector<reco::CaloCluster> seedCluster_;
0312     /// True if RecHits stored internally
0313     bool embeddedRecHits_;
0314     /// Place to store electron's RecHits internally (5x5 around seed+ all RecHits)
0315     EcalRecHitCollection recHits_;
0316 
0317     // ---- electron ID's holder ----
0318     /// Electron IDs
0319     std::vector<IdPair> electronIDs_;
0320 
0321     // ---- PF specific members ----
0322     bool isPF_;
0323     /// true if the IsolatedPFCandidate is embedded
0324     bool embeddedPFCandidate_;
0325     /// A copy of the source IsolatedPFCandidate is stored in this vector if embeddedPFCandidate_ if True
0326     reco::PFCandidateCollection pfCandidate_;
0327     /// reference to the IsolatedPFCandidate this has been built from; null if this has been built from a standard electron
0328     reco::PFCandidateRef pfCandidateRef_;
0329 
0330     // ---- specific members : Momentum estimates ----
0331     /// ECAL-driven momentum
0332     LorentzVector ecalDrivenMomentum_;
0333 
0334     /// additional missing mva variables : 14/04/2012
0335     float sigmaIetaIphi_, full5x5_sigmaIetaIphi_;
0336     double ip3d_;
0337 
0338     /// output of regression
0339     double ecalRegressionEnergy_;
0340     double ecalTrackRegressionEnergy_;
0341     double ecalRegressionError_;
0342     double ecalTrackRegressionError_;
0343 
0344     /// scale corrections and smearing applied or to be be applied. Initialized to -99999.
0345     double ecalScale_;
0346     double ecalSmear_;
0347 
0348     double ecalRegressionScale_;
0349     double ecalRegressionSmear_;
0350 
0351     double ecalTrackRegressionScale_;
0352     double ecalTrackRegressionSmear_;
0353 
0354     /// PUPPI isolations
0355     float puppiChargedHadronIso_;
0356     float puppiNeutralHadronIso_;
0357     float puppiPhotonIso_;
0358 
0359     /// PUPPINoLeptons isolations
0360     float puppiNoLeptonsChargedHadronIso_;
0361     float puppiNoLeptonsNeutralHadronIso_;
0362     float puppiNoLeptonsPhotonIso_;
0363 
0364     /// conversion veto
0365     bool passConversionVeto_;
0366 
0367     // ---- cached impact parameters ----
0368     /// True if the IP (former dB) has been cached
0369     uint8_t cachedIP_;
0370     /// Impact parameter at the primary vertex,
0371     float ip_[IpTypeSize];
0372     /// Impact parameter uncertainty as recommended by the tracking group
0373     float eip_[IpTypeSize];
0374 
0375     // ---- link to PackedPFCandidates
0376     edm::RefProd<pat::PackedCandidateCollection> packedPFCandidates_;
0377     std::vector<uint16_t> associatedPackedFCandidateIndices_;
0378   };
0379 }  // namespace pat
0380 
0381 #endif