test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATSecondaryVertexSlimmer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 
4 // user include files
8 
12 
16 
17 namespace pat {
19  public:
22 
23  virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const;
24  private:
29  };
30 }
31 
33  src_(consumes<reco::VertexCompositePtrCandidateCollection>(iConfig.getParameter<edm::InputTag>("src"))),
34  srcLegacy_(mayConsume<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("src"))),
35  map_(consumes<edm::Association<pat::PackedCandidateCollection> >(iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
36  map2_(mayConsume<edm::Association<pat::PackedCandidateCollection> >(iConfig.existsAs<edm::InputTag>("lostTracksCandidates") ? iConfig.getParameter<edm::InputTag>("lostTracksCandidates") : edm::InputTag("lostTracks") ))
37 {
38  produces< reco::VertexCompositePtrCandidateCollection >();
39 }
40 
42 
44 
45  auto outPtr = std::make_unique<reco::VertexCompositePtrCandidateCollection>();
46 
48  iEvent.getByToken(src_, candVertices);
49 
51  iEvent.getByToken(map_,pf2pc);
52 
53  // if reco::VertexCompositePtrCandidate secondary vertices are present
54  if( candVertices.isValid() )
55  {
56  outPtr->reserve(candVertices->size());
57  for (unsigned int i = 0, n = candVertices->size(); i < n; ++i) {
58 
59  reco::VertexCompositePtrCandidate v = (*candVertices)[i];
60 
61  std::vector<reco::CandidatePtr> daughters = v.daughterPtrVector();
62  v.clearDaughters();
63 
64  for(std::vector<reco::CandidatePtr>::const_iterator it = daughters.begin(); it != daughters.end(); ++it) {
65 
66  if((*pf2pc)[*it].isNonnull() && (*pf2pc)[*it]->numberOfHits() > 0)
67  v.addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc)[*it]) ));
68  }
69 
70  outPtr->push_back( v );
71  }
72  }
73  // otherwise fallback to reco::Vertex secondary vertices
74  else
75  {
77  iEvent.getByToken(srcLegacy_, vertices);
78 
80  iEvent.getByToken(map2_,pf2pc2);
81 
82  outPtr->reserve(vertices->size());
83  for (unsigned int i = 0, n = vertices->size(); i < n; ++i) {
84  const reco::Vertex &v = (*vertices)[i];
85  outPtr->push_back(reco::VertexCompositePtrCandidate(0,v.p4(),v.position(), v.error(), v.chi2(), v.ndof()));
86 
87  for(reco::Vertex::trackRef_iterator it=v.tracks_begin(); it != v.tracks_end(); it++) {
88  if(v.trackWeight(*it)>0.5) {
89  if((*pf2pc)[*it].isNonnull() && (*pf2pc)[*it]->numberOfHits() > 0) {
90  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc)[*it]) ));
91  }
92  else {
93  if((*pf2pc2)[*it].isNonnull()) {
94  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc2)[*it]) ));
95  }
96  else { edm::LogError("PATSecondaryVertexSlimmer") << "HELPME" << std::endl;}
97  }
98  }
99  }
100  }
101  }
102 
103  iEvent.put(std::move(outPtr));
104 }
105 
const edm::EDGetTokenT< std::vector< reco::Vertex > > srcLegacy_
Map map_
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
trackRef_iterator tracks_end() const
last iterator over tracks
Definition: Vertex.cc:81
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map2_
std::vector< pat::PackedCandidate > PackedCandidateCollection
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
PATSecondaryVertexSlimmer(const edm::ParameterSet &)
const Point & position() const
position
Definition: Vertex.h:109
std::vector< VertexCompositePtrCandidate > VertexCompositePtrCandidateCollection
collection of Candidate objects
int iEvent
Definition: GenABIO.cc:230
def move
Definition: eostools.py:510
double chi2() const
chi-squares
Definition: Vertex.h:98
float trackWeight(const TREF &r) const
returns the weight with which a Track has contributed to the vertex-fit.
Definition: Vertex.h:81
double ndof() const
Definition: Vertex.h:105
math::XYZTLorentzVectorD p4(float mass=0.13957018, float minWeight=0.5) const
Returns the four momentum of the sum of the tracks, assuming the given mass for the decay products...
Definition: Vertex.cc:135
Error error() const
return SMatrix
Definition: Vertex.h:139
void clearDaughters()
clear daughter references
const daughters & daughterPtrVector() const
references to daughtes
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector&lt;TrackRef&gt;
Definition: Vertex.h:37
void addDaughter(const CandidatePtr &)
add a daughter via a reference
const edm::EDGetTokenT< reco::VertexCompositePtrCandidateCollection > src_
trackRef_iterator tracks_begin() const
first iterator over tracks
Definition: Vertex.cc:76
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const