Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:10

0001 #ifndef PhysicsTools_PatUtils_DuplicatedPhotonRemover_h
0002 #define PhysicsTools_PatUtils_DuplicatedPhotonRemover_h
0003 
0004 #include "PhysicsTools/PatUtils/interface/GenericDuplicateRemover.h"
0005 #include "PhysicsTools/PatUtils/interface/GenericOverlapFinder.h"
0006 
0007 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0008 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0009 #include "DataFormats/EgammaCandidates/interface/PhotonFwd.h"
0010 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0011 
0012 #include "DataFormats/Common/interface/View.h"
0013 
0014 #include "CommonTools/Utils/interface/EtComparator.h"
0015 
0016 namespace pat {
0017 
0018   class DuplicatedPhotonRemover {
0019   public:
0020     // Checks if two objects share the same supercluster seed
0021     struct EqualBySuperClusterSeed {
0022       template <typename T1, typename T2>
0023       bool operator()(const T1 &t1, const T2 &t2) const {
0024         return (t1.superCluster()->seed() == t2.superCluster()->seed());
0025       }
0026     };
0027 
0028     // Checks if two objects share the same supercluster seed
0029     struct EqualBySuperCluster {
0030       template <typename T1, typename T2>
0031       bool operator()(const T1 &t1, const T2 &t2) const {
0032         return (t1.superCluster() == t2.superCluster());
0033       }
0034     };
0035 
0036     /// Indices of duplicated photons (same supercluster) to remove. It keeps the photons with highest energy.
0037     /// PhotonCollection can be anything that has a "begin()" and "end()", and that hold things which have a "superCluster()" method
0038     /// notable examples are std::vector<Photon> and edm::View<Photon> (but GsfElectrons work too)
0039     template <typename PhotonCollection>
0040     std::unique_ptr<std::vector<size_t> > duplicatesBySuperCluster(const PhotonCollection &photons) const;
0041 
0042     /// Indices of duplicated photons (same supercluster) to remove. It keeps the photons with highest energy.
0043     /// PhotonCollection can be anything that has a "begin()" and "end()", and that hold things which have a "superCluster()" method
0044     /// notable examples are std::vector<Photon> and edm::View<Photon> (but GsfElectrons work too)
0045     template <typename PhotonCollection>
0046     std::unique_ptr<std::vector<size_t> > duplicatesBySeed(const PhotonCollection &photons) const;
0047 
0048     /// Indices of photons which happen to be also electrons (that is, they share the same SC seed)
0049     template <typename PhotonCollection, typename ElectronCollection>
0050     std::unique_ptr<pat::OverlapList> electronsBySeed(const PhotonCollection &photons,
0051                                                       const ElectronCollection &electrons) const;
0052 
0053     /// Indices of photons which happen to be also electrons (that is, they share the same SC)
0054     template <typename PhotonCollection, typename ElectronCollection>
0055     std::unique_ptr<pat::OverlapList> electronsBySuperCluster(const PhotonCollection &photons,
0056                                                               const ElectronCollection &electrons) const;
0057 
0058     // ===== Concrete versions for users (and to get it compiled, so I can see if there are errors) ===
0059     std::unique_ptr<std::vector<size_t> > duplicatesBySeed(const reco::PhotonCollection &photons) const;
0060     std::unique_ptr<std::vector<size_t> > duplicatesBySeed(const edm::View<reco::Photon> &photons) const;
0061     std::unique_ptr<std::vector<size_t> > duplicatesBySuperCluster(const edm::View<reco::Photon> &photons) const;
0062     std::unique_ptr<std::vector<size_t> > duplicatesBySuperCluster(const reco::PhotonCollection &photons) const;
0063     std::unique_ptr<pat::OverlapList> electronsBySeed(const reco::PhotonCollection &photons,
0064                                                       const reco::GsfElectronCollection &electrons) const;
0065     std::unique_ptr<pat::OverlapList> electronsBySeed(const edm::View<reco::Photon> &photons,
0066                                                       const reco::GsfElectronCollection &electrons) const;
0067     std::unique_ptr<pat::OverlapList> electronsBySuperCluster(const edm::View<reco::Photon> &photons,
0068                                                               const reco::GsfElectronCollection &electrons) const;
0069     std::unique_ptr<pat::OverlapList> electronsBySuperCluster(const reco::PhotonCollection &photons,
0070                                                               const reco::GsfElectronCollection &electrons) const;
0071     std::unique_ptr<pat::OverlapList> electronsBySeed(const reco::PhotonCollection &photons,
0072                                                       const edm::View<reco::GsfElectron> &electrons) const;
0073     std::unique_ptr<pat::OverlapList> electronsBySeed(const edm::View<reco::Photon> &photons,
0074                                                       const edm::View<reco::GsfElectron> &electrons) const;
0075     std::unique_ptr<pat::OverlapList> electronsBySuperCluster(const edm::View<reco::Photon> &photons,
0076                                                               const edm::View<reco::GsfElectron> &electrons) const;
0077     std::unique_ptr<pat::OverlapList> electronsBySuperCluster(const reco::PhotonCollection &photons,
0078                                                               const edm::View<reco::GsfElectron> &electrons) const;
0079   };
0080 }  // namespace pat
0081 
0082 template <typename PhotonCollection>
0083 std::unique_ptr<std::vector<size_t> > pat::DuplicatedPhotonRemover::duplicatesBySuperCluster(
0084     const PhotonCollection &photons) const {
0085   typedef typename PhotonCollection::value_type PhotonType;
0086   pat::GenericDuplicateRemover<EqualBySuperCluster, GreaterByEt<PhotonType> > dups;
0087   return dups.duplicates(photons);
0088 }
0089 
0090 template <typename PhotonCollection>
0091 std::unique_ptr<std::vector<size_t> > pat::DuplicatedPhotonRemover::duplicatesBySeed(
0092     const PhotonCollection &photons) const {
0093   typedef typename PhotonCollection::value_type PhotonType;
0094   pat::GenericDuplicateRemover<EqualBySuperClusterSeed, GreaterByEt<PhotonType> > dups;
0095   return dups.duplicates(photons);
0096 }
0097 
0098 /// Indices of photons which happen to be also electrons (that is, they share the same SC)
0099 template <typename PhotonCollection, typename ElectronCollection>
0100 std::unique_ptr<pat::OverlapList> pat::DuplicatedPhotonRemover::electronsBySuperCluster(
0101     const PhotonCollection &photons, const ElectronCollection &electrons) const {
0102   pat::GenericOverlapFinder<pat::OverlapDistance<EqualBySuperCluster> > ovl;
0103   return ovl.find(photons, electrons);
0104 }
0105 
0106 /// Indices of photons which happen to be also electrons (that is, they share the same SC)
0107 template <typename PhotonCollection, typename ElectronCollection>
0108 std::unique_ptr<pat::OverlapList> pat::DuplicatedPhotonRemover::electronsBySeed(
0109     const PhotonCollection &photons, const ElectronCollection &electrons) const {
0110   pat::GenericOverlapFinder<pat::OverlapDistance<EqualBySuperClusterSeed> > ovl;
0111   return ovl.find(photons, electrons);
0112 }
0113 
0114 #endif