CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronFromPVSelector.cc
Go to the documentation of this file.
1 // Includes
8 
10 
13 
16 
19 
22 
23 #include <memory>
24 #include <vector>
25 #include <sstream>
26 
27 
29 // class definition
32 {
33 public:
34  // construction/destruction
37 
38  // member functions
39  void produce(edm::Event& iEvent,const edm::EventSetup& iSetup);
40  void endJob();
41 
42 private:
43  // member data
46  double max_dxy_ ;
47  double max_dz_ ;
48 };
49 
50 
51 
53 // construction/destruction
55 
56 //______________________________________________________________________________
58  : srcPart_(iConfig.getParameter<edm::InputTag>("srcElectron"))
59  , srcPV_ (iConfig.getParameter<edm::InputTag>("srcVertex"))
60  , max_dxy_(iConfig.getParameter<double>("max_dxy"))
61  , max_dz_ (iConfig.getParameter<double>("max_dz"))
62 {
63  produces<std::vector<reco::GsfElectron> >();
64 }
65 
66 
67 //______________________________________________________________________________
69 
71 // implementation of member functions
73 
74 //______________________________________________________________________________
76 {
77  std::auto_ptr<std::vector<reco::GsfElectron> > goodGsfElectrons(new std::vector<reco::GsfElectron >);
78 
80  iEvent.getByLabel(srcPV_,VertexHandle);
81 
83  iEvent.getByLabel(srcPart_,GsfElectronHandle);
84 
85  if( (VertexHandle->size() == 0) || (GsfElectronHandle->size() == 0) )
86  {
87  iEvent.put(goodGsfElectrons);
88  return ;
89  }
90 
91 
92  reco::Vertex PV = VertexHandle->front();
93  std::vector<reco::GsfElectron>::const_iterator GsfElectronIt ;
94 // typename std::vector<reco::GsfElectron>::const_iterator GsfElectronIt ;
95 
96  for (GsfElectronIt = GsfElectronHandle->begin(); GsfElectronIt != GsfElectronHandle->end(); ++GsfElectronIt) {
97 
98  //int q = GsfElectronIt->gsfTrack()->charge() ;
99 
100  if ( fabs(GsfElectronIt->gsfTrack()->dxy(PV.position())) < max_dxy_ &&
101  fabs(GsfElectronIt->gsfTrack()->dz(PV.position())) < max_dz_ ) {
102  goodGsfElectrons -> push_back(*GsfElectronIt) ;
103  }
104  }
105 
106  iEvent.put(goodGsfElectrons);
107 
108 }
109 
111 {
112 }
113 
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
const Point & position() const
position
Definition: Vertex.h:93
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
GsfElectronFromPVSelector(const edm::ParameterSet &iConfig)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356