ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/RecoAlgos/interface/GsfElectronSelector.h
Revision: 1.1.1.1 (vendor branch)
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: ANA
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
version CMSSW_2_2_10

File Contents

# User Rev Content
1 dgele 1.1 #ifndef RecoAlgos_GsfElectronSelector_h
2     #define RecoAlgos_GsfElectronSelector_h
3     /** \class GsfElectronSelector
4     *
5     * selects a subset of an electron collection. Also clones
6     * all referenced objects
7     *
8     * \author Luca Lista, INFN
9     *
10     * \version $Revision: 1.1 $
11     *
12     * $Id: GsfElectronSelector.h,v 1.1 2007/12/11 11:04:17 llista Exp $
13     *
14     */
15    
16     #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
17     #include "DataFormats/EgammaReco/interface/SuperCluster.h"
18     #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
19     #include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h"
20     #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
21     #include "PhysicsTools/UtilAlgos/interface/ObjectSelector.h"
22    
23     namespace helper {
24     struct GsfElectronCollectionStoreManager {
25     typedef reco::GsfElectronCollection collection;
26     GsfElectronCollectionStoreManager(const edm::Handle<reco::GsfElectronCollection>&) :
27     selElectrons_( new reco::GsfElectronCollection ),
28     selSuperClusters_( new reco::SuperClusterCollection ),
29     selTracks_( new reco::GsfTrackCollection ),
30     selTrackExtras_( new reco::TrackExtraCollection ),
31     selGsfTrackExtras_( new reco::GsfTrackExtraCollection ),
32     selHits_( new TrackingRecHitCollection ) {
33     }
34     template<typename I>
35     void cloneAndStore( const I & begin, const I & end, edm::Event & evt ) {
36     using namespace reco;
37     TrackingRecHitRefProd rHits = evt.template getRefBeforePut<TrackingRecHitCollection>();
38     TrackExtraRefProd rTrackExtras = evt.template getRefBeforePut<TrackExtraCollection>();
39     GsfTrackExtraRefProd rGsfTrackExtras = evt.template getRefBeforePut<GsfTrackExtraCollection>();
40     GsfTrackRefProd rTracks = evt.template getRefBeforePut<GsfTrackCollection>();
41     GsfElectronRefProd rElectrons = evt.template getRefBeforePut<GsfElectronCollection>();
42     SuperClusterRefProd rSuperClusters = evt.template getRefBeforePut<SuperClusterCollection>();
43     size_t idx = 0, tidx = 0, hidx = 0;
44     for( I i = begin; i != end; ++ i ) {
45     const GsfElectron & ele = * * i;
46     selElectrons_->push_back( GsfElectron( ele ) );
47     selElectrons_->back().setGsfTrack( GsfTrackRef( rTracks, idx ) );
48     selElectrons_->back().setSuperCluster( SuperClusterRef( rSuperClusters, idx ++ ) );
49     selSuperClusters_->push_back( SuperCluster( * ( ele.superCluster() ) ) );
50     GsfTrackRef trkRef = ele.gsfTrack();
51     if ( trkRef.isNonnull() ) {
52     selTracks_->push_back( GsfTrack( * trkRef ) );
53     GsfTrack & trk = selTracks_->back();
54     selTrackExtras_->push_back( TrackExtra( trk.outerPosition(), trk.outerMomentum(), trk.outerOk(),
55     trk.innerPosition(), trk.innerMomentum(), trk.innerOk(),
56     trk.outerStateCovariance(), trk.outerDetId(),
57     trk.innerStateCovariance(), trk.innerDetId(),
58     trk.seedDirection() ) );
59     selGsfTrackExtras_->push_back( GsfTrackExtra( *(trk.gsfExtra()) ) );
60     TrackExtra & tx = selTrackExtras_->back();
61     for( trackingRecHit_iterator hit = trk.recHitsBegin(); hit != trk.recHitsEnd(); ++ hit ) {
62     selHits_->push_back( (*hit)->clone() );
63     tx.add( TrackingRecHitRef( rHits, hidx ++ ) );
64     }
65     trk.setGsfExtra( GsfTrackExtraRef( rGsfTrackExtras, tidx ) );
66     trk.setExtra( TrackExtraRef( rTrackExtras, tidx ++ ) );
67     }
68     }
69     }
70    
71     edm::OrphanHandle<reco::GsfElectronCollection> put( edm::Event & evt ) {
72     edm::OrphanHandle<reco::GsfElectronCollection> h = evt.put( selElectrons_ );
73     evt.put( selSuperClusters_ );
74     evt.put( selTracks_ );
75     evt.put( selTrackExtras_ );
76     evt.put( selGsfTrackExtras_ );
77     evt.put( selHits_ );
78     return h;
79     }
80    
81     size_t size() const { return selElectrons_->size(); }
82     private:
83     std::auto_ptr<reco::GsfElectronCollection> selElectrons_;
84     std::auto_ptr<reco::SuperClusterCollection> selSuperClusters_;
85     std::auto_ptr<reco::GsfTrackCollection> selTracks_;
86     std::auto_ptr<reco::TrackExtraCollection> selTrackExtras_;
87     std::auto_ptr<reco::GsfTrackExtraCollection> selGsfTrackExtras_;
88     std::auto_ptr<TrackingRecHitCollection> selHits_;
89     };
90    
91     class GsfElectronSelectorBase : public edm::EDFilter {
92     public:
93     GsfElectronSelectorBase( const edm::ParameterSet & cfg ) {
94     std::string alias( cfg.getParameter<std::string>( "@module_label" ) );
95     produces<reco::GsfElectronCollection>().setBranchAlias( alias + "GsfElectrons" );
96     produces<reco::SuperClusterCollection>().setBranchAlias( alias + "SuperClusters" );
97     produces<reco::GsfTrackCollection>().setBranchAlias( alias + "GsfTracks" );
98     produces<reco::GsfTrackExtraCollection>().setBranchAlias( alias + "GsfTrackExtras" );
99     produces<reco::TrackExtraCollection>().setBranchAlias( alias + "TrackExtras" );
100     produces<TrackingRecHitCollection>().setBranchAlias( alias + "RecHits" );
101     }
102     };
103    
104     template<>
105     struct StoreManagerTrait<reco::GsfElectronCollection> {
106     typedef GsfElectronCollectionStoreManager type;
107     typedef GsfElectronSelectorBase base;
108     };
109     }
110    
111     #endif