Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 //
0003 
0004 #ifndef DataFormats_PatCandidates_Photon_h
0005 #define DataFormats_PatCandidates_Photon_h
0006 
0007 /**
0008   \class    pat::Photon Photon.h "DataFormats/PatCandidates/interface/Photon.h"
0009   \brief    Analysis-level Photon class
0010 
0011    pat::Photon implements the analysis-level photon class within the 'pat'
0012    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/PatCandidates/interface/PATObject.h"
0021 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0022 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
0023 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
0024 #include "DataFormats/PatCandidates/interface/Isolation.h"
0025 #include "DataFormats/PatCandidates/interface/PackedCandidate.h"
0026 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0027 #include "DataFormats/Common/interface/AtomicPtrCache.h"
0028 
0029 // Define typedefs for convenience
0030 namespace pat {
0031   class Photon;
0032   typedef std::vector<Photon> PhotonCollection;
0033   typedef edm::Ref<PhotonCollection> PhotonRef;
0034   typedef edm::RefVector<PhotonCollection> PhotonRefVector;
0035 }  // namespace pat
0036 
0037 namespace reco {
0038   /// pipe operator (introduced to use pat::Photon with PFTopProjectors)
0039   std::ostream& operator<<(std::ostream& out, const pat::Photon& obj);
0040 }  // namespace reco
0041 
0042 // Class definition
0043 namespace pat {
0044   class PATPhotonSlimmer;
0045 
0046   class Photon : public PATObject<reco::Photon> {
0047   public:
0048     typedef std::pair<std::string, Bool_t> IdPair;
0049 
0050     /// default constructor
0051     Photon();
0052     /// constructor from a reco photon
0053     Photon(const reco::Photon& aPhoton);
0054     /// constructor from a RefToBase to a reco photon (to be superseded by Ptr counterpart)
0055     Photon(const edm::RefToBase<reco::Photon>& aPhotonRef);
0056     /// constructor from a Ptr to a reco photon
0057     Photon(const edm::Ptr<reco::Photon>& aPhotonRef);
0058     /// destructor
0059     ~Photon() override;
0060 
0061     /// required reimplementation of the Candidate's clone method
0062     Photon* clone() const override { return new Photon(*this); }
0063 
0064     // ---- methods for content embedding ----
0065     /// override the superCluster method from CaloJet, to access the internal storage of the supercluster
0066     reco::SuperClusterRef superCluster() const override;
0067     /// direct access to the seed cluster
0068     reco::CaloClusterPtr seed() const;
0069 
0070     //method to access the basic clusters
0071     const std::vector<reco::CaloCluster>& basicClusters() const { return basicClusters_; }
0072     //method to access the preshower clusters
0073     const std::vector<reco::CaloCluster>& preshowerClusters() const { return preshowerClusters_; }
0074 
0075     //method to access embedded ecal RecHits
0076     const EcalRecHitCollection* recHits() const { return &recHits_; }
0077 
0078     /// method to store the photon's supercluster internally
0079     void embedSuperCluster();
0080     /// method to store the electron's seedcluster internally
0081     void embedSeedCluster();
0082     /// method to store the electron's basic clusters
0083     void embedBasicClusters();
0084     /// method to store the electron's preshower clusters
0085     void embedPreshowerClusters();
0086     /// method to store the RecHits internally - can be called from the PATElectronProducer
0087     void embedRecHits(const EcalRecHitCollection* rechits);
0088 
0089     // ---- methods for access the generated photon ----
0090     /// return the match to the generated photon
0091     const reco::Candidate* genPhoton() const { return genParticle(); }
0092     /// method to set the generated photon
0093     void setGenPhoton(const reco::GenParticleRef& gp, bool embed = false) { setGenParticleRef(gp, embed); }
0094 
0095     // ---- methods for photon ID ----
0096     /// Returns a specific photon ID associated to the pat::Photon given its name.
0097     /// Note: an exception is thrown if the specified ID is not available
0098     Bool_t photonID(const std::string& name) const;
0099     /// Returns true if a specific ID is available in this pat::Photon
0100     bool isPhotonIDAvailable(const std::string& name) const;
0101     /// Returns all the Photon IDs in the form of <name,value> pairs
0102     /// The 'default' ID is the first in the list
0103     const std::vector<IdPair>& photonIDs() const { return photonIDs_; }
0104     /// Store multiple photon ID values, discarding existing ones
0105     /// The first one in the list becomes the 'default' photon id
0106     void setPhotonIDs(const std::vector<IdPair>& ids) { photonIDs_ = ids; }
0107 
0108     // ---- methods for photon isolation ----
0109     /// Returns the summed track pt in a cone of deltaR<0.4
0110     /// including the region of the reconstructed photon
0111     float trackIso() const { return trkSumPtSolidConeDR04(); }
0112     /// Returns the summed Et in a cone of deltaR<0.4
0113     /// calculated from recHits
0114     float ecalIso() const { return ecalRecHitSumEtConeDR04(); }
0115     /// Returns summed Et in a cone of deltaR<0.4 calculated
0116     /// from caloTowers
0117     float hcalIso() const { return hcalTowerSumEtConeDR04(); }
0118     /// Returns the calorimeter isolation combined from ecal
0119     /// and hcal
0120     float caloIso() const { return ecalIso() + hcalIso(); }
0121 
0122     /// PARTICLE FLOW ISOLATION
0123     /// Returns the isolation calculated with all the PFCandidates
0124     float patParticleIso() const { return userIsolation(pat::PfAllParticleIso); }
0125     /// Returns the isolation calculated with only the charged hadron
0126     /// PFCandidates
0127     float chargedHadronIso() const { return reco::Photon::chargedHadronIso(); }
0128     /// Returns the isolation calculated with only the neutral hadron
0129     /// PFCandidates
0130     float neutralHadronIso() const { return reco::Photon::neutralHadronIso(); }
0131     /// Returns the isolation calculated with only the gamma
0132     /// PFCandidates
0133     float photonIso() const { return reco::Photon::photonIso(); }
0134     /// Returns the isolation calculated with only the pile-up charged hadron
0135     /// PFCandidates
0136     float puChargedHadronIso() const { return userIsolation(pat::PfPUChargedHadronIso); }
0137 
0138     /// Returns a user defined isolation value
0139     float userIso(uint8_t index = 0) const { return userIsolation(IsolationKeys(UserBaseIso + index)); }
0140     /// Returns the isolation variable for a specifc key (or
0141     /// pseudo-key like CaloIso), or -1.0 if not available
0142     float userIsolation(IsolationKeys key) const {
0143       if (key >= 0) {
0144         //if (key >= isolations_.size()) throw cms::Excepton("Missing Data")
0145         //<< "Isolation corresponding to key " << key
0146         //<< " was not stored for this particle.";
0147         if (size_t(key) >= isolations_.size())
0148           return -1.0;
0149         return isolations_[key];
0150       } else
0151         switch (key) {
0152           case pat::CaloIso:
0153             //if (isolations_.size() <= pat::HcalIso) throw cms::Excepton("Missing Data")
0154             //<< "CalIsoo Isolation was not stored for this particle.";
0155             if (isolations_.size() <= pat::HcalIso)
0156               return -1.0;
0157             return isolations_[pat::EcalIso] + isolations_[pat::HcalIso];
0158           default:
0159             return -1.0;
0160             //throw cms::Excepton("Missing Data") << "Isolation corresponding to key "
0161             //<< key << " was not stored for this particle.";
0162         }
0163     }
0164 
0165     float puppiChargedHadronIso() const { return puppiChargedHadronIso_; }
0166     float puppiNeutralHadronIso() const { return puppiNeutralHadronIso_; }
0167     float puppiPhotonIso() const { return puppiPhotonIso_; }
0168 
0169     /// Sets the isolation variable for a specifc key.
0170     /// Note that you can't set isolation for a pseudo-key like CaloIso
0171     void setIsolation(IsolationKeys key, float value) {
0172       if (key >= 0) {
0173         if (size_t(key) >= isolations_.size())
0174           isolations_.resize(key + 1, -1.0);
0175         isolations_[key] = value;
0176       } else {
0177         throw cms::Exception("Illegal Argument")
0178             << "The key for which you're setting isolation does not correspond "
0179             << "to an individual isolation but to the sum of more independent isolations "
0180             << "(e.g. Calo = Ecal + Hcal), so you can't SET the value, just GET it.\n"
0181             << "Please set up each component independly.\n";
0182       }
0183     }
0184     /// Sets tracker isolation variable
0185     void setTrackIso(float trackIso) { setIsolation(TrackIso, trackIso); }
0186     /// Sets ecal isolation variable
0187     void setEcalIso(float caloIso) { setIsolation(EcalIso, caloIso); }
0188     /// Sets hcal isolation variable
0189     void setHcalIso(float caloIso) { setIsolation(HcalIso, caloIso); }
0190     /// Sets user isolation variable #index
0191     void setUserIso(float value, uint8_t index = 0) { setIsolation(IsolationKeys(UserBaseIso + index), value); }
0192     /// Sets PUPPI isolation
0193     void setIsolationPUPPI(float chargedhadrons_, float neutralhadrons_, float photons_) {
0194       puppiChargedHadronIso_ = chargedhadrons_;
0195       puppiNeutralHadronIso_ = neutralhadrons_;
0196       puppiPhotonIso_ = photons_;
0197     }
0198 
0199     // ---- methods for photon isolation deposits ----
0200     /// Returns the IsoDeposit associated with some key, or a null pointer if it is not available
0201     const IsoDeposit* isoDeposit(IsolationKeys key) const {
0202       for (IsoDepositPairs::const_iterator it = isoDeposits_.begin(), ed = isoDeposits_.end(); it != ed; ++it) {
0203         if (it->first == key)
0204           return &it->second;
0205       }
0206       return nullptr;
0207     }
0208     /// Return the tracker IsoDeposit
0209     const IsoDeposit* trackIsoDeposit() const { return isoDeposit(pat::TrackIso); }
0210     /// Return the ecal IsoDeposit
0211     const IsoDeposit* ecalIsoDeposit() const { return isoDeposit(pat::EcalIso); }
0212     /// Return the hcal IsoDeposit
0213     const IsoDeposit* hcalIsoDeposit() const { return isoDeposit(pat::HcalIso); }
0214     /// Return a specified user-level IsoDeposit
0215     const IsoDeposit* userIsoDeposit(uint8_t index = 0) const { return isoDeposit(IsolationKeys(UserBaseIso + index)); }
0216     /// Sets the IsoDeposit associated with some key; if it is already existent, it is overwritten.
0217     void setIsoDeposit(IsolationKeys key, const IsoDeposit& dep) {
0218       IsoDepositPairs::iterator it = isoDeposits_.begin(), ed = isoDeposits_.end();
0219       for (; it != ed; ++it) {
0220         if (it->first == key) {
0221           it->second = dep;
0222           return;
0223         }
0224       }
0225       isoDeposits_.push_back(std::make_pair(key, dep));
0226     }
0227     /// Sets tracker IsoDeposit
0228     void trackIsoDeposit(const IsoDeposit& dep) { setIsoDeposit(pat::TrackIso, dep); }
0229     /// Sets ecal IsoDeposit
0230     void ecalIsoDeposit(const IsoDeposit& dep) { setIsoDeposit(pat::EcalIso, dep); }
0231     /// Sets hcal IsoDeposit
0232     void hcalIsoDeposit(const IsoDeposit& dep) { setIsoDeposit(pat::HcalIso, dep); }
0233     /// Sets user-level IsoDeposit
0234     void userIsoDeposit(const IsoDeposit& dep, uint8_t index = 0) {
0235       setIsoDeposit(IsolationKeys(UserBaseIso + index), dep);
0236     }
0237     /// vertex fit method
0238     bool passElectronVeto() const { return passElectronVeto_; }
0239     void setPassElectronVeto(bool flag) { passElectronVeto_ = flag; }
0240     //pixel seed to veto electron (not recommended by EGM POG but it seems very efficient)
0241     bool hasPixelSeed() const { return hasPixelSeed_; }
0242     void setHasPixelSeed(bool flag) { hasPixelSeed_ = flag; }
0243 
0244     /// input variables for regression energy corrections
0245     float seedEnergy() const { return seedEnergy_; }
0246     void setSeedEnergy(float e) { seedEnergy_ = e; }
0247 
0248     float eMax() const { return eMax_; }
0249     void setEMax(float e) { eMax_ = e; }
0250     float e2nd() const { return e2nd_; }
0251     void setE2nd(float e) { e2nd_ = e; }
0252     float e3x3() const { return e3x3_; }
0253     void setE3x3(float e) { e3x3_ = e; }
0254     float eTop() const { return eTop_; }
0255     void setETop(float e) { eTop_ = e; }
0256     float eBottom() const { return eBottom_; }
0257     void setEBottom(float e) { eBottom_ = e; }
0258     float eLeft() const { return eLeft_; }
0259     void setELeft(float e) { eLeft_ = e; }
0260     float eRight() const { return eRight_; }
0261     void setERight(float e) { eRight_ = e; }
0262 
0263     float see() const { return see_; }
0264     void setSee(float s) { see_ = s; }
0265     float spp() const { return spp_; }
0266     void setSpp(float s) { spp_ = s; }
0267     float sep() const { return sep_; }
0268     void setSep(float s) { sep_ = s; }
0269 
0270     float maxDR() const { return maxDR_; }
0271     void setMaxDR(float m) { maxDR_ = m; }
0272     float maxDRDPhi() const { return maxDRDPhi_; }
0273     void setMaxDRDPhi(float m) { maxDRDPhi_ = m; }
0274     float maxDRDEta() const { return maxDRDEta_; }
0275     void setMaxDRDEta(float m) { maxDRDEta_ = m; }
0276     float maxDRRawEnergy() const { return maxDRRawEnergy_; }
0277     void setMaxDRRawEnergy(float m) { maxDRRawEnergy_ = m; }
0278 
0279     float subClusRawE1() const { return subClusRawE1_; }
0280     void setSubClusRawE1(float s) { subClusRawE1_ = s; }
0281     float subClusRawE2() const { return subClusRawE2_; }
0282     void setSubClusRawE2(float s) { subClusRawE2_ = s; }
0283     float subClusRawE3() const { return subClusRawE3_; }
0284     void setSubClusRawE3(float s) { subClusRawE3_ = s; }
0285 
0286     float subClusDPhi1() const { return subClusDPhi1_; }
0287     void setSubClusDPhi1(float s) { subClusDPhi1_ = s; }
0288     float subClusDPhi2() const { return subClusDPhi2_; }
0289     void setSubClusDPhi2(float s) { subClusDPhi2_ = s; }
0290     float subClusDPhi3() const { return subClusDPhi3_; }
0291     void setSubClusDPhi3(float s) { subClusDPhi3_ = s; }
0292 
0293     float subClusDEta1() const { return subClusDEta1_; }
0294     void setSubClusDEta1(float s) { subClusDEta1_ = s; }
0295     float subClusDEta2() const { return subClusDEta2_; }
0296     void setSubClusDEta2(float s) { subClusDEta2_ = s; }
0297     float subClusDEta3() const { return subClusDEta3_; }
0298     void setSubClusDEta3(float s) { subClusDEta3_ = s; }
0299 
0300     float cryPhi() const { return cryPhi_; }
0301     void setCryPhi(float c) { cryPhi_ = c; }
0302     float cryEta() const { return cryEta_; }
0303     void setCryEta(float c) { cryEta_ = c; }
0304 
0305     float iPhi() const { return iPhi_; }
0306     void setIPhi(float i) { iPhi_ = i; }
0307     float iEta() const { return iEta_; }
0308     void setIEta(float i) { iEta_ = i; }
0309 
0310     /// pipe operator (introduced to use pat::Photon with PFTopProjectors)
0311     friend std::ostream& reco::operator<<(std::ostream& out, const pat::Photon& obj);
0312 
0313     /// References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet reclustering)
0314     edm::RefVector<pat::PackedCandidateCollection> associatedPackedPFCandidates() const;
0315     /// References to PFCandidates linked to this object (e.g. for isolation vetos or masking before jet reclustering)
0316     template <typename T>
0317     void setAssociatedPackedPFCandidates(const edm::RefProd<pat::PackedCandidateCollection>& refprod,
0318                                          T beginIndexItr,
0319                                          T endIndexItr) {
0320       packedPFCandidates_ = refprod;
0321       associatedPackedFCandidateIndices_.clear();
0322       associatedPackedFCandidateIndices_.insert(associatedPackedFCandidateIndices_.begin(), beginIndexItr, endIndexItr);
0323     }
0324 
0325     /// get the number of non-null PFCandidates
0326     size_t numberOfSourceCandidatePtrs() const override { return associatedPackedFCandidateIndices_.size(); }
0327     /// get the source candidate pointer with index i
0328     reco::CandidatePtr sourceCandidatePtr(size_type i) const override;
0329 
0330     friend class PATPhotonSlimmer;
0331 
0332   protected:
0333     // ---- for content embedding ----
0334     bool embeddedSuperCluster_;
0335     std::vector<reco::SuperCluster> superCluster_;
0336     /// Place to temporarily store the electron's supercluster after relinking the seed to it
0337     edm::AtomicPtrCache<std::vector<reco::SuperCluster> > superClusterRelinked_;
0338     /// Place to store electron's basic clusters internally
0339     std::vector<reco::CaloCluster> basicClusters_;
0340     /// Place to store electron's preshower clusters internally
0341     std::vector<reco::CaloCluster> preshowerClusters_;
0342     /// True if seed cluster is stored internally
0343     bool embeddedSeedCluster_;
0344     /// Place to store electron's seed cluster internally
0345     std::vector<reco::CaloCluster> seedCluster_;
0346     /// True if RecHits stored internally
0347     bool embeddedRecHits_;
0348     /// Place to store electron's RecHits internally (5x5 around seed+ all RecHits)
0349     EcalRecHitCollection recHits_;
0350     // ---- photon ID's holder ----
0351     std::vector<IdPair> photonIDs_;
0352     // ---- Isolation and IsoDeposit related datamebers ----
0353     typedef std::vector<std::pair<IsolationKeys, pat::IsoDeposit> > IsoDepositPairs;
0354     IsoDepositPairs isoDeposits_;
0355     std::vector<float> isolations_;
0356 
0357     /// ---- conversion veto ----
0358     bool passElectronVeto_;
0359     bool hasPixelSeed_;
0360 
0361     /// ---- input variables for regression energy corrections ----
0362     float seedEnergy_;
0363     float eMax_;
0364     float e2nd_;
0365     float e3x3_;
0366     float eTop_;
0367     float eBottom_;
0368     float eLeft_;
0369     float eRight_;
0370 
0371     float see_;
0372     float spp_;
0373     float sep_;
0374 
0375     float maxDR_;
0376     float maxDRDPhi_;
0377     float maxDRDEta_;
0378     float maxDRRawEnergy_;
0379 
0380     float subClusRawE1_;
0381     float subClusRawE2_;
0382     float subClusRawE3_;
0383 
0384     float subClusDPhi1_;
0385     float subClusDPhi2_;
0386     float subClusDPhi3_;
0387 
0388     float subClusDEta1_;
0389     float subClusDEta2_;
0390     float subClusDEta3_;
0391 
0392     float cryEta_;
0393     float cryPhi_;
0394     float iEta_;
0395     float iPhi_;
0396 
0397     //PUPPI isolations
0398     float puppiChargedHadronIso_;
0399     float puppiNeutralHadronIso_;
0400     float puppiPhotonIso_;
0401 
0402     // ---- link to PackedPFCandidates
0403     edm::RefProd<pat::PackedCandidateCollection> packedPFCandidates_;
0404     std::vector<uint16_t> associatedPackedFCandidateIndices_;
0405   };
0406 
0407 }  // namespace pat
0408 
0409 #endif