CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VertexMerger.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <set>
3 
9 
16 
18  public:
19  VertexMerger(const edm::ParameterSet &params);
20 
21  virtual void produce(edm::Event &event, const edm::EventSetup &es) override;
22 
23  private:
24  bool trackFilter(const reco::TrackRef &track) const;
25 
27  double maxFraction;
29 };
30 
32  maxFraction(params.getParameter<double>("maxFraction")),
33  minSignificance(params.getParameter<double>("minSignificance"))
34 {
35  token_secondaryVertex = consumes<reco::VertexCollection>(params.getParameter<edm::InputTag>("secondaryVertices"));
36  produces<reco::VertexCollection>();
37 }
38 
39 static double computeSharedTracks(const reco::Vertex &pv,
40  const reco::Vertex &sv)
41 {
42  std::set<reco::TrackRef> pvTracks;
43  for(std::vector<reco::TrackBaseRef>::const_iterator iter = pv.tracks_begin();
44  iter != pv.tracks_end(); iter++) {
45  if (pv.trackWeight(*iter) >= 0.5)
46  pvTracks.insert(iter->castTo<reco::TrackRef>());
47  }
48 
49  unsigned int count = 0, total = 0;
50  for(std::vector<reco::TrackBaseRef>::const_iterator iter = sv.tracks_begin();
51  iter != sv.tracks_end(); iter++) {
52  if (sv.trackWeight(*iter) >= 0.5) {
53  total++;
54  count += pvTracks.count(iter->castTo<reco::TrackRef>());
55  }
56  }
57 
58  return (double)count / (double)total;
59 }
60 
62 {
63  using namespace reco;
64 
65  edm::Handle<VertexCollection> secondaryVertices;
66  event.getByToken(token_secondaryVertex, secondaryVertices);
67 
68  VertexDistance3D dist;
69  std::auto_ptr<VertexCollection> recoVertices(new VertexCollection);
70  for(std::vector<reco::Vertex>::const_iterator sv = secondaryVertices->begin();
71  sv != secondaryVertices->end(); ++sv) {
72  recoVertices->push_back(*sv);
73  }
74  for(std::vector<reco::Vertex>::iterator sv = recoVertices->begin();
75  sv != recoVertices->end(); ++sv) {
76 
77  bool shared=false;
78  for(std::vector<reco::Vertex>::iterator sv2 = recoVertices->begin();
79  sv2 != recoVertices->end(); ++sv2) {
80  double fr=computeSharedTracks(*sv2, *sv);
81  // std::cout << sv2-recoVertices->begin() << " vs " << sv-recoVertices->begin() << " : " << fr << " " << computeSharedTracks(*sv, *sv2) << " sig " << dist.distance(*sv,*sv2).significance() << std::endl;
82  // std::cout << (fr > maxFraction) << " && " << (dist.distance(*sv,*sv2).significance() < 2) << " && " << (sv-sv2!=0) << " && " << (fr >= computeSharedTracks(*sv2, *sv)) << std::endl;
83  if (fr > maxFraction && dist.distance(*sv,*sv2).significance() < minSignificance && sv-sv2!=0
84  && fr >= computeSharedTracks(*sv, *sv2) )
85  {
86  shared=true;
87  // std::cout << "shared " << sv-recoVertices->begin() << " and " << sv2-recoVertices->begin() << " fractions: " << fr << " , " << computeSharedTracks(*sv2, *sv) << " sig: " << dist.distance(*sv,*sv2).significance() << std::endl;
88 
89  }
90 
91 
92  }
93  if(shared) { sv=recoVertices->erase(sv)-1; }
94  // std::cout << "it = " << sv-recoVertices->begin() << " new size is: " << recoVertices->size() << std::endl;
95  }
96 
97  event.put(recoVertices);
98 
99 
100 
101 }
102 
T getParameter(std::string const &) const
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:44
VertexMerger(const edm::ParameterSet &params)
Definition: VertexMerger.cc:31
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
bool trackFilter(const reco::TrackRef &track) const
static double computeSharedTracks(const reco::Vertex &pv, const reco::Vertex &sv)
Definition: VertexMerger.cc:39
double maxFraction
Definition: VertexMerger.cc:27
float trackWeight(const TrackBaseRef &r) const
returns the weight with which a Track has contributed to the vertex-fit.
double minSignificance
Definition: VertexMerger.cc:28
virtual void produce(edm::Event &event, const edm::EventSetup &es) override
Definition: VertexMerger.cc:61
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
Definition: VertexMerger.cc:26
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:39