Go to the documentation of this file.00001 #ifndef RecoAlgos_GsfElectronSelector_h
00002 #define RecoAlgos_GsfElectronSelector_h
00003
00016 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00017 #include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
00018 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00019 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00020 #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h"
00021 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00022 #include "CommonTools/UtilAlgos/interface/ObjectSelector.h"
00023
00024 namespace helper {
00025 struct GsfElectronCollectionStoreManager {
00026 typedef reco::GsfElectronCollection collection;
00027 GsfElectronCollectionStoreManager(const edm::Handle<reco::GsfElectronCollection>&) :
00028 selElectrons_( new reco::GsfElectronCollection ),
00029 selElectronCores_ (new reco::GsfElectronCoreCollection ) ,
00030 selSuperClusters_( new reco::SuperClusterCollection ),
00031 selTracks_( new reco::GsfTrackCollection ),
00032 selTrackExtras_( new reco::TrackExtraCollection ),
00033 selGsfTrackExtras_( new reco::GsfTrackExtraCollection ),
00034 selHits_( new TrackingRecHitCollection ) {
00035 }
00036 template<typename I>
00037 void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) {
00038 using namespace reco;
00039 TrackingRecHitRefProd rHits = evt.template getRefBeforePut<TrackingRecHitCollection>();
00040 TrackExtraRefProd rTrackExtras = evt.template getRefBeforePut<TrackExtraCollection>();
00041 GsfTrackExtraRefProd rGsfTrackExtras = evt.template getRefBeforePut<GsfTrackExtraCollection>();
00042 GsfTrackRefProd rTracks = evt.template getRefBeforePut<GsfTrackCollection>();
00043 GsfElectronCoreRefProd rElectronCores = evt.template getRefBeforePut<GsfElectronCoreCollection>();
00044 GsfElectronRefProd rElectrons = evt.template getRefBeforePut<GsfElectronCollection>();
00045 SuperClusterRefProd rSuperClusters = evt.template getRefBeforePut<SuperClusterCollection>();
00046 size_t idx = 0, tidx = 0, hidx = 0;
00047 for( I i = begin; i != end; ++ i ) {
00048 const GsfElectron & ele = * * i;
00049 selElectronCores_->push_back( GsfElectronCore( *(ele.core()) ) );
00050 selElectronCores_->back().setGsfTrack( GsfTrackRef( rTracks, idx ) );
00051 selElectronCores_->back().setSuperCluster( SuperClusterRef( rSuperClusters, idx ) );
00052 selSuperClusters_->push_back( SuperCluster( * ( ele.superCluster() ) ) );
00053 selElectrons_->push_back(GsfElectron(ele,GsfElectronCoreRef(rElectronCores,idx++),CaloClusterPtr(),TrackRef(),TrackBaseRef(),GsfTrackRefVector()));
00054 GsfTrackRef trkRef = ele.gsfTrack();
00055 if ( trkRef.isNonnull() ) {
00056 selTracks_->push_back( GsfTrack( * trkRef ) );
00057 GsfTrack & trk = selTracks_->back();
00058 selTrackExtras_->push_back( TrackExtra( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
00059 trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
00060 trk.outerStateCovariance(), trk.outerDetId(),
00061 trk.innerStateCovariance(), trk.innerDetId(),
00062 trk.seedDirection() ) );
00063 selGsfTrackExtras_->push_back( GsfTrackExtra( *(trk.gsfExtra()) ) );
00064 TrackExtra & tx = selTrackExtras_->back();
00065 for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
00066 selHits_->push_back( (*hit)->clone() );
00067 tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
00068 }
00069 trk.setGsfExtra( GsfTrackExtraRef( rGsfTrackExtras, tidx ) );
00070 trk.setExtra( TrackExtraRef( rTrackExtras, tidx ++ ) );
00071 }
00072 }
00073 }
00074
00075 edm::OrphanHandle<reco::GsfElectronCollection> put( edm::Event & evt ) {
00076 edm::OrphanHandle<reco::GsfElectronCollection> h = evt.put( selElectrons_ );
00077 evt.put( selElectronCores_ );
00078 evt.put( selSuperClusters_ );
00079 evt.put( selTracks_ );
00080 evt.put( selTrackExtras_ );
00081 evt.put( selGsfTrackExtras_ );
00082 evt.put( selHits_ );
00083 return h;
00084 }
00085
00086 size_t size() const { return selElectrons_->size(); }
00087 private:
00088 std::auto_ptr<reco::GsfElectronCollection> selElectrons_;
00089 std::auto_ptr<reco::GsfElectronCoreCollection> selElectronCores_;
00090 std::auto_ptr<reco::SuperClusterCollection> selSuperClusters_;
00091 std::auto_ptr<reco::GsfTrackCollection> selTracks_;
00092 std::auto_ptr<reco::TrackExtraCollection> selTrackExtras_;
00093 std::auto_ptr<reco::GsfTrackExtraCollection> selGsfTrackExtras_;
00094 std::auto_ptr<TrackingRecHitCollection> selHits_;
00095 };
00096
00097 class GsfElectronSelectorBase : public edm::EDFilter {
00098 public:
00099 GsfElectronSelectorBase( const edm::ParameterSet & cfg ) {
00100 std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
00101 produces<reco::GsfElectronCollection>().setBranchAlias( alias + "GsfElectrons" );
00102 produces<reco::GsfElectronCoreCollection>().setBranchAlias( alias + "GsfElectronCores" );
00103 produces<reco::SuperClusterCollection>().setBranchAlias( alias + "SuperClusters" );
00104 produces<reco::GsfTrackCollection>().setBranchAlias( alias + "GsfTracks" );
00105 produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias + "GsfTrackExtras" );
00106 produces<reco::TrackExtraCollection>().setBranchAlias( alias + "TrackExtras" );
00107 produces<TrackingRecHitCollection>().setBranchAlias( alias + "RecHits" );
00108 }
00109 };
00110
00111 template<>
00112 struct StoreManagerTrait<reco::GsfElectronCollection> {
00113 typedef GsfElectronCollectionStoreManager type;
00114 typedef GsfElectronSelectorBase base;
00115 };
00116 }
00117
00118 #endif