CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/PatUtils/interface/DuplicatedElectronRemover.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PatUtils_DuplicatedElectronRemover_h
00002 #define PhysicsTools_PatUtils_DuplicatedElectronRemover_h
00003 
00004 #include "PhysicsTools/PatUtils/interface/GenericDuplicateRemover.h"
00005 
00006 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00007 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00008 #include "DataFormats/Common/interface/View.h"
00009 
00010 #include <memory>
00011 #include <vector>
00012 
00013 
00014 namespace pat { 
00015     
00016     /* --- Original comment from TQAF follows ----
00017      * it is possible that there are multiple electron objects in the collection that correspond to the same
00018      * real physics object - a supercluster with two tracks reconstructed to it, or a track that points to two different SC
00019      *  (i would guess the latter doesn't actually happen).
00020      * NB triplicates also appear in the electron collection provided by egamma group, it is necessary to handle those correctly   
00021      */
00022     class DuplicatedElectronRemover {
00023         public:
00024             struct SameSuperclusterOrTrack {
00025                 template<typename T1, typename T2>
00026                 bool operator()(const T1 &t1, const T2 &t2) const { 
00027                     return ((t1.superCluster() == t2.superCluster()) ||
00028                             (t1.gsfTrack()     == t2.gsfTrack())); 
00029                 }
00030             }; // struct
00031 
00032             struct BestEoverP {
00033                 template<typename T1, typename T2>
00034                 bool operator()(const T1 &t1, const T2 &t2) const { 
00035                     float diff1 = fabs(t1.eSuperClusterOverP()-1);
00036                     float diff2 = fabs(t2.eSuperClusterOverP()-1);
00037                     return diff1 <= diff2;
00038                 }
00039             }; //struct
00040 
00041             // List of duplicate electrons to remove 
00042             // Among those that share the same cluster or track, the one with E/P nearer to 1 is kept
00043             std::auto_ptr< std::vector<size_t> > duplicatesToRemove(const std::vector<reco::GsfElectron> &electrons) const ;
00044 
00045             // List of duplicate electrons to remove 
00046             // Among those that share the same cluster or track, the one with E/P nearer to 1 is kept
00047             std::auto_ptr< std::vector<size_t> > duplicatesToRemove(const edm::View<reco::GsfElectron>   &electrons) const ;
00048 
00049             // Generic method. Collection can be vector, view or whatever you like
00050             template<typename Collection>
00051             std::auto_ptr< std::vector<size_t> > duplicatesToRemove(const Collection &electrons) const ;
00052             
00053         private:
00054     }; // class
00055 } // namespace
00056 
00057 // implemented here because is templated
00058 template<typename Collection>
00059 std::auto_ptr< std::vector<size_t> >
00060 pat::DuplicatedElectronRemover::duplicatesToRemove(const Collection &electrons) const {
00061     pat::GenericDuplicateRemover<SameSuperclusterOrTrack,BestEoverP> dups;
00062     return dups.duplicates(electrons);
00063 }
00064 #endif