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"
18 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4)
19 #include "DataFormats/HepMCCandidate/interface/GenStatusFlags.h"
23 : input_(config.getParameter<
edm::InputTag>(
"input")),
24 branch_(config.getParameter<
std::string>(
"branch")),
25 store_mothers_(config.getParameter<bool>(
"includeMothers")),
26 store_daughters_(config.getParameter<bool>(
"includeDaughters")),
27 store_statusFlags_(config.getParameter<bool>(
"includeStatusFlags")){
28 consumes<edm::View<reco::GenParticle>>(input_);
29 particles_ =
new std::vector<ic::GenParticle>();
39 void ICGenParticleProducer::produce(edm::Event& event,
40 const edm::EventSetup& setup) {
41 edm::Handle<edm::View<reco::GenParticle> > parts_handle;
42 event.getByLabel(input_, parts_handle);
47 for (
unsigned i = 0; i < parts_handle->size(); ++i) {
48 reco::GenParticle
const& src = parts_handle->at(i);
51 dest.
set_id(particle_hasher_(&src));
57 dest.
set_index(static_cast<int>((parts_handle->refAt(i).key())));
60 #if CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4 )
61 if (store_statusFlags_){
62 reco::GenStatusFlags statusflags = src.statusFlags();
63 if(statusflags.flags_.size()!=15){
64 throw cms::Exception(
"OptionNotSupported")<<
"size of status flags bitset is "<<statusflags.flags_.size()<<
" which is different to what was expected\n";
67 std::vector<bool> statusflags_;
68 for(
unsigned iFlag=0;iFlag<statusflags.flags_.size();iFlag++){
69 statusflags_.push_back(statusflags.flags_[iFlag]);
77 std::vector<int> mothers(src.motherRefVector().size(), 0);
78 for (
unsigned j = 0; j < src.motherRefVector().size(); ++j) {
79 mothers[j] =
static_cast<int>(src.motherRefVector().at(j).key());
83 if (store_daughters_) {
84 std::vector<int> daughters(src.daughterRefVector().size(), 0);
85 for (
unsigned j = 0; j < src.daughterRefVector().size(); ++j) {
86 daughters[j] =
static_cast<int>(src.daughterRefVector().at(j).key());
93 void ICGenParticleProducer::beginJob() {
95 #if !(CMSSW_MAJOR_VERSION > 7 || (CMSSW_MAJOR_VERSION == 7 && CMSSW_MINOR_VERSION >= 4))
96 if(store_statusFlags_){
97 throw cms::Exception(
"OptionNotSupported")<<
"status flags not supported for CMSSW versions before 7_4_X\n";
103 void ICGenParticleProducer::endJob() {}
void set_daughters(std::vector< int > const &daughters)
A vector of ic::GenParticle::index() values that identify the daughter particles. ...
DEFINE_FWK_MODULE(ICGenParticleProducer)
void set_phi(double const &phi)
Direct access to .
void set_id(std::size_t const &id)
Unique identifier.
void set_charge(int const &charge)
Electric charge.
void set_pdgid(int const &pdgid)
PDG number to identify the particle type, see this link
void set_energy(double const &energy)
Direct access to the energy.
void set_statusFlags(std::vector< bool > const &statusFlags)
A genstatusflags object to give information about the production of the particle. ...
void set_index(int const &index)
The index position of the particle in the original list.
void set_status(int const &status)
The generator-dependent particle status.
void set_pt(double const &pt)
Direct access to the .
ICGenParticleProducer(const edm::ParameterSet &)
void set_eta(double const &eta)
Direct access to .
void set_mothers(std::vector< int > const &mothers)
A vector of ic::GenParticle::index() values that identify the mother particles.
Stores the basic properties of generator-level particles as well as mother-daughter relations with ot...