CMS 3D CMS Logo

V0VertexTrackProducer.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <vector>
12 
14 public:
16  ~V0VertexTrackProducer() override = default;
17  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
18 
19  void produce(edm::StreamID streamID, edm::Event& iEvent, edm::EventSetup const& iSetup) const override;
20 
21 private:
23 };
24 
26  : vccToken_{consumes<reco::VertexCompositeCandidateCollection>(
27  iConfig.getParameter<edm::InputTag>("vertexCompositeCandidates"))} {
28  produces<std::vector<reco::Track>>();
29 }
30 
33  iEvent.getByToken(vccToken_, vccHandle);
34 
35  std::unique_ptr<std::vector<reco::Track>> outputTracks(new std::vector<reco::Track>());
36 
37  if (vccHandle.isValid()) {
38  // Loop over VertexCompositeCandidates and associate tracks
39  for (const auto& vcc : *vccHandle) {
40  for (size_t i = 0; i < vcc.numberOfDaughters(); ++i) {
41  const reco::Candidate* daughter = vcc.daughter(i);
42  const reco::RecoChargedCandidate* chargedDaughter = dynamic_cast<const reco::RecoChargedCandidate*>(daughter);
43  if (chargedDaughter) {
44  const reco::TrackRef trackRef = chargedDaughter->track();
45  if (trackRef.isNonnull()) {
46  outputTracks->push_back(*trackRef);
47  }
48  }
49  }
50  }
51  } else {
52  edm::LogError("V0VertexTrackProducer") << "Error >> Failed to get VertexCompositeCandidateCollection";
53  }
54  iEvent.put(std::move(outputTracks));
55 }
56 
59  desc.add<edm::InputTag>("vertexCompositeCandidates", edm::InputTag("generalV0Candidates:Kshort"));
60  descriptions.addWithDefaultLabel(desc);
61 }
62 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
void produce(edm::StreamID streamID, edm::Event &iEvent, edm::EventSetup const &iSetup) const override
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:232
V0VertexTrackProducer(const edm::ParameterSet &)
Log< level::Error, false > LogError
int iEvent
Definition: GenABIO.cc:224
reco::TrackRef track() const override
reference to a track
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~V0VertexTrackProducer() override=default
bool isValid() const
Definition: HandleBase.h:70
const edm::EDGetTokenT< reco::VertexCompositeCandidateCollection > vccToken_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511