#include <memory>
#include <string>
#include <vector>
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
: input_(config.getParameter<
edm::InputTag>(
"input")),
branch_(config.getParameter<
std::string>(
"branch")),
input_particles_(config.getParameter<
edm::InputTag>(
"inputGenParticles")),
request_gen_particles_(config.getParameter<bool>("requestGenParticles")),
is_slimmed_(config.getParameter<bool>("isSlimmed")) {
consumes<edm::View<reco::GenJet>>(input_);
consumes<reco::GenParticleCollection>(input_particles_);
gen_jets_ = new std::vector<ic::GenJet>();
if (request_gen_particles_) {
produces<reco::GenParticleRefVector>("requestedGenParticles");
}
}
void ICGenJetProducer::produce(edm::Event& event,
const edm::EventSetup& setup) {
edm::Handle<edm::View<reco::GenJet> > jets_handle;
event.getByLabel(input_, jets_handle);
edm::Handle<reco::GenParticleCollection> parts_handle;
std::map<reco::GenParticle const*, std::size_t> part_map;
if (request_gen_particles_) {
event.getByLabel(input_particles_, parts_handle);
for (unsigned i = 0; i < parts_handle->size(); ++i) {
part_map[&parts_handle->at(i)] = i;
}
}
std::auto_ptr<reco::GenParticleRefVector> part_requests(
new reco::GenParticleRefVector());
gen_jets_->clear();
gen_jets_->resize(jets_handle->size());
for (unsigned i = 0; i < jets_handle->size(); ++i) {
reco::GenJet const& src = jets_handle->at(i);
dest.
set_id(gen_jet_hasher_(&src));
if (request_gen_particles_) {
std::vector<std::size_t> constituents;
for (unsigned i = 0; i < src.getGenConstituents().size(); ++i) {
reco::GenParticle const* ptr = src.getGenConstituent(i);
std::map<reco::GenParticle const*, std::size_t>::const_iterator it =
part_map.find(ptr);
if (it != part_map.end()) {
constituents.push_back(particle_hasher_(ptr));
part_requests->push_back(
reco::GenParticleRef(parts_handle, it->second));
}
}
}
}
if (request_gen_particles_) event.put(part_requests, "requestedGenParticles");
}
void ICGenJetProducer::beginJob() {
}
void ICGenJetProducer::endJob() {}