CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CommonTools/RecoAlgos/interface/PhotonSelector.h

Go to the documentation of this file.
00001 #ifndef RecoAlgos_PhotonSelector_h
00002 #define RecoAlgos_PhotonSelector_h
00003 
00016 #include "DataFormats/EgammaCandidates/interface/Photon.h"
00017 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00018 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
00019 
00020 namespace helper {
00021   struct PhotonCollectionStoreManager {
00022     typedef reco::PhotonCollection collection;
00023     PhotonCollectionStoreManager(const edm::Handle<reco::PhotonCollection>&) :
00024       selPhotons_( new reco::PhotonCollection ),
00025       selSuperClusters_( new reco::SuperClusterCollection ) {
00026     }
00027     template<typename I>
00028     void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) {
00029       using namespace reco;
00030       PhotonRefProd rPhotons = evt.template getRefBeforePut<PhotonCollection>();      
00031       SuperClusterRefProd rSuperClusters = evt.template getRefBeforePut<SuperClusterCollection>();      
00032       size_t idx = 0;
00033       for( I i = begin; i != end; ++ i ) {
00034         const Photon & ele = * * i;
00035         selPhotons_->push_back( Photon( ele ) );
00036         selPhotons_->back().setSuperCluster( SuperClusterRef( rSuperClusters, idx ++ ) );
00037         selSuperClusters_->push_back( SuperCluster( * ( ele.superCluster() ) ) );
00038       }
00039     }
00040     edm::OrphanHandle<reco::PhotonCollection> put( edm::Event & evt ) {
00041       edm::OrphanHandle<reco::PhotonCollection> h = evt.put( selPhotons_ );
00042       evt.put( selSuperClusters_ );
00043       return h;
00044     }
00045     size_t size() const { return selPhotons_->size(); }
00046   private:
00047     std::auto_ptr<reco::PhotonCollection> selPhotons_;
00048     std::auto_ptr<reco::SuperClusterCollection> selSuperClusters_;
00049   };
00050 
00051   class PhotonSelectorBase : public edm::EDFilter {
00052   public:
00053     PhotonSelectorBase( const edm::ParameterSet & cfg ) {
00054       std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
00055       produces<reco::PhotonCollection>().setBranchAlias( alias + "Photons" );
00056       produces<reco::SuperClusterCollection>().setBranchAlias( alias + "SuperClusters" );
00057     }
00058    };
00059 
00060   template<>
00061   struct StoreManagerTrait<reco::PhotonCollection> {
00062     typedef PhotonCollectionStoreManager type;
00063     typedef PhotonSelectorBase base;
00064   };
00065 
00066 }
00067 
00068 #endif