CMS 3D CMS Logo

PATSecondaryVertexSlimmer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <memory>
3 
4 // user include files
8 
12 
19 
20 namespace pat {
22  public:
24  ~PATSecondaryVertexSlimmer() override;
25 
26  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
27 
28  private:
34  };
35 } // namespace pat
36 
38  : src_(consumes<reco::VertexCompositePtrCandidateCollection>(iConfig.getParameter<edm::InputTag>("src"))),
39  srcLegacy_(mayConsume<std::vector<reco::Vertex> >(iConfig.getParameter<edm::InputTag>("src"))),
40  srcV0s_(mayConsume<reco::VertexCompositeCandidateCollection>(iConfig.getParameter<edm::InputTag>("src"))),
41  map_(consumes<edm::Association<pat::PackedCandidateCollection> >(
42  iConfig.getParameter<edm::InputTag>("packedPFCandidates"))),
43  map2_(mayConsume<edm::Association<pat::PackedCandidateCollection> >(
44  iConfig.existsAs<edm::InputTag>("lostTracksCandidates")
45  ? iConfig.getParameter<edm::InputTag>("lostTracksCandidates")
46  : edm::InputTag("lostTracks"))) {
47  produces<reco::VertexCompositePtrCandidateCollection>();
48 }
49 
51 
53  auto outPtr = std::make_unique<reco::VertexCompositePtrCandidateCollection>();
54 
56  iEvent.getByToken(src_, candVertices);
57 
59  iEvent.getByToken(map_, pf2pc);
60 
61  // if reco::VertexCompositePtrCandidate secondary vertices are present
62  if (candVertices.isValid()) {
63  outPtr->reserve(candVertices->size());
64  for (unsigned int i = 0, n = candVertices->size(); i < n; ++i) {
65  reco::VertexCompositePtrCandidate v = (*candVertices)[i];
66 
67  std::vector<reco::CandidatePtr> daughters = v.daughterPtrVector();
68  v.clearDaughters();
69 
70  for (std::vector<reco::CandidatePtr>::const_iterator it = daughters.begin(); it != daughters.end(); ++it) {
71  if ((*pf2pc)[*it].isNonnull() && (*pf2pc)[*it]->numberOfHits() > 0)
72  v.addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc)[*it])));
73  }
74 
75  outPtr->push_back(v);
76  }
77  }
78  // otherwise fallback to reco::Vertex secondary vertices
79  else {
81  iEvent.getByToken(srcLegacy_, vertices);
82 
83  if (vertices.isValid()) {
85  iEvent.getByToken(map2_, pf2pc2);
86 
87  outPtr->reserve(vertices->size());
88  for (unsigned int i = 0, n = vertices->size(); i < n; ++i) {
89  const reco::Vertex& v = (*vertices)[i];
90  outPtr->push_back(reco::VertexCompositePtrCandidate(0, v.p4(), v.position(), v.error(), v.chi2(), v.ndof()));
91 
92  for (reco::Vertex::trackRef_iterator it = v.tracks_begin(); it != v.tracks_end(); it++) {
93  if (v.trackWeight(*it) > 0.5) {
94  if ((*pf2pc)[*it].isNonnull() && (*pf2pc)[*it]->numberOfHits() > 0) {
95  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc)[*it])));
96  } else {
97  if ((*pf2pc2)[*it].isNonnull()) {
98  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc2)[*it])));
99  } else {
100  edm::LogError("PATSecondaryVertexSlimmer") << "HELPME" << std::endl;
101  }
102  }
103  }
104  }
105  }
106  } else {
109  iEvent.getByToken(srcV0s_, srcV0s);
110 
112  iEvent.getByToken(map2_, pf2pc2);
113 
114  outPtr->reserve(srcV0s->size());
115  for (unsigned int i = 0, n = srcV0s->size(); i < n; ++i) {
116  const reco::VertexCompositeCandidate& v = (*srcV0s)[i];
117  outPtr->push_back(reco::VertexCompositePtrCandidate(
118  0, v.p4(), v.vertex(), v.vertexCovariance(), v.vertexChi2(), v.vertexNdof()));
119 
120  for (size_t dIdx = 0; dIdx < v.numberOfDaughters(); dIdx++) {
121  reco::TrackRef trackRef = (dynamic_cast<const reco::RecoChargedCandidate*>(v.daughter(dIdx)))->track();
122  if ((*pf2pc)[trackRef].isNonnull() && (*pf2pc)[trackRef]->numberOfHits() > 0) {
123  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc)[trackRef])));
124  } else {
125  if ((*pf2pc2)[trackRef].isNonnull()) {
126  outPtr->back().addDaughter(reco::CandidatePtr(edm::refToPtr((*pf2pc2)[trackRef])));
127  } else {
128  edm::LogError("PATSecondaryVertexSlimmer") << "HELPME" << std::endl;
129  }
130  }
131  }
132  }
133 
134  } // if reco::Vertex
135  } // if Candidate
136 
137  iEvent.put(std::move(outPtr));
138 }
139 
reco::Vertex::trackRef_iterator
std::vector< TrackBaseRef >::const_iterator trackRef_iterator
The iteratator for the vector<TrackRef>
Definition: Vertex.h:38
edm::StreamID
Definition: StreamID.h:30
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pat::PATSecondaryVertexSlimmer::srcV0s_
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > srcV0s_
Definition: PATSecondaryVertexSlimmer.cc:31
edm::EDGetTokenT< reco::VertexCompositePtrCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATSecondaryVertexSlimmer::src_
const edm::EDGetTokenT< reco::VertexCompositePtrCandidateCollection > src_
Definition: PATSecondaryVertexSlimmer.cc:29
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
reco::VertexCompositeCandidate
Definition: VertexCompositeCandidate.h:16
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::Handle
Definition: AssociativeIterator.h:50
reco::VertexCompositePtrCandidate
Definition: VertexCompositePtrCandidate.h:16
edm::Ref< TrackCollection >
pat::PATSecondaryVertexSlimmer::srcLegacy_
const edm::EDGetTokenT< std::vector< reco::Vertex > > srcLegacy_
Definition: PATSecondaryVertexSlimmer.cc:30
edm::refToPtr
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
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
pat::PATSecondaryVertexSlimmer
Definition: PATSecondaryVertexSlimmer.cc:21
BPhysicsValidation_cfi.daughters
daughters
Definition: BPhysicsValidation_cfi.py:11
VertexCompositeCandidate.h
VertexCompositePtrCandidate.h
pat::PATSecondaryVertexSlimmer::~PATSecondaryVertexSlimmer
~PATSecondaryVertexSlimmer() override
Definition: PATSecondaryVertexSlimmer.cc:50
edm::global::EDProducer
Definition: EDProducer.h:32
Vertex.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PackedCandidate.h
iEvent
int iEvent
Definition: GenABIO.cc:224
RefToPtr.h
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
edm::Ptr< Candidate >
pat::PackedCandidateCollection
std::vector< pat::PackedCandidate > PackedCandidateCollection
Definition: PackedCandidate.h:1131
reco::VertexCompositeCandidateCollection
std::vector< VertexCompositeCandidate > VertexCompositeCandidateCollection
collection of Candidate objects
Definition: VertexCompositeCandidateFwd.h:19
pat::PATSecondaryVertexSlimmer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: PATSecondaryVertexSlimmer.cc:52
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HltBtagValidation_cff.Vertex
Vertex
Definition: HltBtagValidation_cff.py:32
RecoChargedCandidate.h
pat::PATSecondaryVertexSlimmer::map2_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map2_
Definition: PATSecondaryVertexSlimmer.cc:33
Frameworkfwd.h
pat::PATSecondaryVertexSlimmer::map_
const edm::EDGetTokenT< edm::Association< pat::PackedCandidateCollection > > map_
Definition: PATSecondaryVertexSlimmer.cc:32
ParameterSet.h
EDProducer.h
pat::PATSecondaryVertexSlimmer::PATSecondaryVertexSlimmer
PATSecondaryVertexSlimmer(const edm::ParameterSet &)
Definition: PATSecondaryVertexSlimmer.cc:37
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
VertexCompositeCandidateFwd.h
reco::Vertex
Definition: Vertex.h:35
reco::VertexCompositePtrCandidateCollection
std::vector< VertexCompositePtrCandidate > VertexCompositePtrCandidateCollection
collection of Candidate objects
Definition: VertexCompositePtrCandidateFwd.h:19
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7