5 #include "FWCore/Framework/interface/Event.h"
6 #include "FWCore/Framework/interface/EventSetup.h"
7 #include "FWCore/Framework/interface/MakerMacros.h"
8 #include "FWCore/ParameterSet/interface/ParameterSet.h"
9 #include "FWCore/Utilities/interface/InputTag.h"
10 #include "DataFormats/Common/interface/Handle.h"
11 #include "DataFormats/Common/interface/View.h"
12 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
20 : input_(config.getParameter<
edm::InputTag>(
"input")),
21 branch_(config.getParameter<
std::string>(
"branch")),
22 input_particles_(config.getParameter<
edm::InputTag>(
"inputGenParticles")),
23 request_gen_particles_(config.getParameter<bool>(
"requestGenParticles")),
24 is_slimmed_(config.getParameter<bool>(
"isSlimmed")) {
25 consumes<edm::View<reco::GenJet>>(input_);
26 consumes<reco::GenParticleCollection>(input_particles_);
27 gen_jets_ =
new std::vector<ic::GenJet>();
28 if (request_gen_particles_) {
29 produces<reco::GenParticleRefVector>(
"requestedGenParticles");
33 PrintOptional(1, request_gen_particles_,
"requestGenParticles");
38 void ICGenJetProducer::produce(edm::Event& event,
39 const edm::EventSetup& setup) {
40 edm::Handle<edm::View<reco::GenJet> > jets_handle;
41 event.getByLabel(input_, jets_handle);
43 edm::Handle<reco::GenParticleCollection> parts_handle;
44 std::map<reco::GenParticle const*, std::size_t> part_map;
45 if (request_gen_particles_) {
46 event.getByLabel(input_particles_, parts_handle);
47 for (
unsigned i = 0; i < parts_handle->size(); ++i) {
48 part_map[&parts_handle->at(i)] = i;
52 std::auto_ptr<reco::GenParticleRefVector> part_requests(
53 new reco::GenParticleRefVector());
56 gen_jets_->resize(jets_handle->size());
58 for (
unsigned i = 0; i < jets_handle->size(); ++i) {
59 reco::GenJet
const& src = jets_handle->at(i);
61 dest.
set_id(gen_jet_hasher_(&src));
70 if (request_gen_particles_) {
71 std::vector<std::size_t> constituents;
72 for (
unsigned i = 0; i < src.getGenConstituents().size(); ++i) {
73 reco::GenParticle
const* ptr = src.getGenConstituent(i);
74 std::map<reco::GenParticle const*, std::size_t>::const_iterator it =
76 if (it != part_map.end()) {
77 constituents.push_back(particle_hasher_(ptr));
78 part_requests->push_back(
79 reco::GenParticleRef(parts_handle, it->second));
85 if (request_gen_particles_)
event.put(part_requests,
"requestedGenParticles");
88 void ICGenJetProducer::beginJob() {
92 void ICGenJetProducer::endJob() {}
void set_n_constituents(unsigned const &n_constituents)
The number of GenParticle constituents.
ICGenJetProducer(const edm::ParameterSet &)
Stores the basic properties of a generator-level jet, in particular can save the IDs of the GenPartic...
void set_phi(double const &phi)
Direct access to .
void set_id(std::size_t const &id)
Unique identifier.
void set_constituents(std::vector< std::size_t > const &constituents)
A vector of ic::GenParticle::id() values corresponding to the constituent particles.
void set_charge(int const &charge)
Electric charge.
void set_flavour(int const &flavour)
The true flavour of the jet.
void set_energy(double const &energy)
Direct access to the energy.
DEFINE_FWK_MODULE(ICGenJetProducer)
void set_pt(double const &pt)
Direct access to the .
void set_eta(double const &eta)
Direct access to .