Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PhysicsTools_PatUtils_DuplicatedElectronRemover_h
0002 #define PhysicsTools_PatUtils_DuplicatedElectronRemover_h
0003 
0004 #include "PhysicsTools/PatUtils/interface/GenericDuplicateRemover.h"
0005 
0006 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0007 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0008 #include "DataFormats/Common/interface/View.h"
0009 
0010 #include <memory>
0011 #include <vector>
0012 
0013 namespace pat {
0014 
0015   /* --- Original comment from TQAF follows ----
0016      * it is possible that there are multiple electron objects in the collection that correspond to the same
0017      * real physics object - a supercluster with two tracks reconstructed to it, or a track that points to two different SC
0018      *  (i would guess the latter doesn't actually happen).
0019      * NB triplicates also appear in the electron collection provided by egamma group, it is necessary to handle those correctly   
0020      */
0021   class DuplicatedElectronRemover {
0022   public:
0023     struct SameSuperclusterOrTrack {
0024       template <typename T1, typename T2>
0025       bool operator()(const T1 &t1, const T2 &t2) const {
0026         return ((t1.superCluster() == t2.superCluster()) || (t1.gsfTrack() == t2.gsfTrack()));
0027       }
0028     };  // struct
0029 
0030     struct BestEoverP {
0031       template <typename T1, typename T2>
0032       bool operator()(const T1 &t1, const T2 &t2) const {
0033         float diff1 = fabs(t1.eSuperClusterOverP() - 1);
0034         float diff2 = fabs(t2.eSuperClusterOverP() - 1);
0035         return diff1 <= diff2;
0036       }
0037     };  //struct
0038 
0039     // List of duplicate electrons to remove
0040     // Among those that share the same cluster or track, the one with E/P nearer to 1 is kept
0041     std::unique_ptr<std::vector<size_t> > duplicatesToRemove(const std::vector<reco::GsfElectron> &electrons) const;
0042 
0043     // List of duplicate electrons to remove
0044     // Among those that share the same cluster or track, the one with E/P nearer to 1 is kept
0045     std::unique_ptr<std::vector<size_t> > duplicatesToRemove(const edm::View<reco::GsfElectron> &electrons) const;
0046 
0047     // Generic method. Collection can be vector, view or whatever you like
0048     template <typename Collection>
0049     std::unique_ptr<std::vector<size_t> > duplicatesToRemove(const Collection &electrons) const;
0050 
0051   private:
0052   };  // class
0053 }  // namespace pat
0054 
0055 // implemented here because is templated
0056 template <typename Collection>
0057 std::unique_ptr<std::vector<size_t> > pat::DuplicatedElectronRemover::duplicatesToRemove(
0058     const Collection &electrons) const {
0059   pat::GenericDuplicateRemover<SameSuperclusterOrTrack, BestEoverP> dups;
0060   return dups.duplicates(electrons);
0061 }
0062 #endif