CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DoubleVertexFilter.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <set>
3 
9 
15 
17  public:
19 
20  virtual void produce(edm::StreamID, edm::Event &event, const edm::EventSetup &es) const override;
21 
22  private:
23  bool trackFilter(const reco::TrackRef &track) const;
24 
27  double maxFraction;
28 };
29 
31  maxFraction(params.getParameter<double>("maxFraction"))
32 {
33  token_primaryVertex = consumes<reco::VertexCollection>(params.getParameter<edm::InputTag>("primaryVertices"));
34  token_secondaryVertex = consumes<reco::VertexCollection>(params.getParameter<edm::InputTag>("secondaryVertices"));
35  produces<reco::VertexCollection>();
36 }
37 
38 static double computeSharedTracks(const reco::Vertex &pv,
39  const reco::Vertex &sv)
40 {
41  std::set<reco::TrackRef> pvTracks;
42  for(std::vector<reco::TrackBaseRef>::const_iterator iter = pv.tracks_begin();
43  iter != pv.tracks_end(); iter++) {
44  if (pv.trackWeight(*iter) >= 0.5)
45  pvTracks.insert(iter->castTo<reco::TrackRef>());
46  }
47 
48  unsigned int count = 0, total = 0;
49  for(std::vector<reco::TrackBaseRef>::const_iterator iter = sv.tracks_begin();
50  iter != sv.tracks_end(); iter++) {
51  if (sv.trackWeight(*iter) >= 0.5) {
52  total++;
53  count += pvTracks.count(iter->castTo<reco::TrackRef>());
54  }
55  }
56 
57  return (double)count / (double)total;
58 }
59 
61 {
62  using namespace reco;
63 
65  event.getByToken(token_primaryVertex, primaryVertices);
66 
68  event.getByToken(token_secondaryVertex, secondaryVertices);
69 
70  std::vector<reco::Vertex>::const_iterator pv = primaryVertices->begin();
71 
72  std::auto_ptr<VertexCollection> recoVertices(new VertexCollection);
73  for(std::vector<reco::Vertex>::const_iterator sv = secondaryVertices->begin();
74  sv != secondaryVertices->end(); ++sv) {
75  if (computeSharedTracks(*pv, *sv) > maxFraction)
76  continue;
77 
78  recoVertices->push_back(*sv);
79  }
80 
81  event.put(recoVertices);
82 }
83 
T getParameter(std::string const &) const
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
bool trackFilter(const reco::TrackRef &track) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
edm::EDGetTokenT< reco::VertexCollection > token_primaryVertex
static double computeSharedTracks(const reco::Vertex &pv, const reco::Vertex &sv)
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
DoubleVertexFilter(const edm::ParameterSet &params)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::EDGetTokenT< reco::VertexCollection > token_secondaryVertex
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39
virtual void produce(edm::StreamID, edm::Event &event, const edm::EventSetup &es) const override