CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackFromPVSelector.cc
Go to the documentation of this file.
1 // Includes
8 
10 
13 
16 
17 #include <memory>
18 #include <vector>
19 #include <sstream>
20 
21 
23 // class definition
26 {
27 public:
28  // construction/destruction
29  TrackFromPVSelector(const edm::ParameterSet& iConfig);
30  virtual ~TrackFromPVSelector();
31 
32  // member functions
33  void produce(edm::Event& iEvent,const edm::EventSetup& iSetup) override;
34  void endJob() override;
35 
36 private:
37  // member data
38  double max_dxy_ ;
39  double max_dz_ ;
42 };
43 
44 
45 
47 // construction/destruction
49 
50 //______________________________________________________________________________
52  : max_dxy_ ( iConfig.getParameter<double>( "max_dxy" ) )
53  , max_dz_ ( iConfig.getParameter<double>( "max_dz" ) )
54  , v_recoVertexToken_( consumes< std::vector<reco::Vertex> >( iConfig.getParameter<edm::InputTag>( "srcVertex" ) ) )
55  , v_recoTrackToken_ ( consumes< std::vector<reco::Track> >( iConfig.getParameter<edm::InputTag>( "srcTrack" ) ) )
56 {
57  produces<std::vector<reco::Track> >();
58 }
59 
60 
61 //______________________________________________________________________________
63 
65 // implementation of member functions
67 
68 //______________________________________________________________________________
70 {
71  std::auto_ptr<std::vector<reco::Track> > goodTracks(new std::vector<reco::Track >);
72 
74  iEvent.getByToken( v_recoVertexToken_, VertexHandle );
75 
77  iEvent.getByToken( v_recoTrackToken_, TrackHandle );
78 
79  if( (VertexHandle->size() == 0) || (TrackHandle->size() == 0) )
80  {
81  iEvent.put(goodTracks);
82  return ;
83  }
84 
85  reco::Vertex PV = VertexHandle->front();
86  //typename std::vector<reco::Track>::const_iterator TrackIt ;
87  std::vector<reco::Track>::const_iterator TrackIt ;
88 
89  for (TrackIt = TrackHandle->begin(); TrackIt != TrackHandle->end(); ++TrackIt) {
90  if ( fabs(TrackIt->dxy(PV.position())) < max_dxy_ &&
91  fabs(TrackIt->dz(PV.position())) < max_dz_ ){
92  goodTracks -> push_back(*TrackIt) ;
93  }
94  }
95 
96  iEvent.put(goodTracks);
97 
98 }
99 
101 {
102 }
103 
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< std::vector< reco::Vertex > > v_recoVertexToken_
const Point & position() const
position
Definition: Vertex.h:92
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< std::vector< reco::Track > > v_recoTrackToken_
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
TrackFromPVSelector(const edm::ParameterSet &iConfig)
return(e1-e2)*(e1-e2)+dp *dp