CMS 3D CMS Logo

GsfElectronSelector.h

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

Generated on Tue Jun 9 17:41:49 2009 for CMSSW by  doxygen 1.5.4