45 return HepMC::FourVector(10*point.x(), 10*point.y(), 10*point.z(), 0);
51 return HepMC::FourVector(lvec.px(), lvec.py(), lvec.pz(), std::hypot(lvec.P(),
std::max(0., lvec.mass())));
61 signalParticlePdgIds_ = pset.
getParameter<std::vector<int>>(
"signalParticlePdgIds");
63 produces<edm::HepMCProduct>(
"unsmeared");
69 event.getByToken(genParticlesToken_, genParticlesHandle);
72 event.getByToken(genEventInfoToken_, genEventInfoHandle);
76 HepMC::GenEvent* hepmc_event =
new HepMC::GenEvent();
77 hepmc_event->set_event_number(event.
id().
event());
78 hepmc_event->set_signal_process_id(genEventInfoHandle->
signalProcessID());
79 hepmc_event->set_event_scale(genEventInfoHandle->
qScale());
80 hepmc_event->set_alphaQED(genEventInfoHandle->
alphaQED());
81 hepmc_event->set_alphaQCD(genEventInfoHandle->
alphaQCD());
83 hepmc_event->weights() = genEventInfoHandle->
weights();
87 const int pdf_id1 = pdf->
id.first, pdf_id2 = pdf->
id.second;
88 const double pdf_x1 = pdf->
x.first, pdf_x2 = pdf->
x.second;
89 const double pdf_scalePDF = pdf->
scalePDF;
90 const double pdf_xPDF1 = pdf->
xPDF.first, pdf_xPDF2 = pdf->
xPDF.second;
91 HepMC::PdfInfo hepmc_pdfInfo(pdf_id1, pdf_id2, pdf_x1, pdf_x2, pdf_scalePDF, pdf_xPDF1, pdf_xPDF2);
92 hepmc_event->set_pdf_info(hepmc_pdfInfo);
95 std::map<const reco::Candidate*, HepMC::GenParticle*> genCandToHepMCMap;
96 std::vector<HepMC::GenParticle*> hepmc_particles;
97 for (
unsigned int i=0,
n=genParticlesHandle->
size();
i<
n; ++
i )
101 hepmc_particle->suggest_barcode(
i+1);
105 if ( pTable_->particle(p->
pdgId()) ) particleMass = pTable_->particle(p->
pdgId())->
mass();
106 else particleMass = p->
mass();
108 hepmc_particle->set_generated_mass(particleMass);
110 hepmc_particles.push_back(hepmc_particle);
111 genCandToHepMCMap[
p] = hepmc_particle;
117 HepMC::GenVertex* vertex1 =
new HepMC::GenVertex(FourVector(parton1->
vertex()));
118 HepMC::GenVertex* vertex2 =
new HepMC::GenVertex(FourVector(parton2->
vertex()));
119 hepmc_event->add_vertex(vertex1);
120 hepmc_event->add_vertex(vertex2);
121 vertex1->add_particle_in(hepmc_particles[0]);
122 vertex2->add_particle_in(hepmc_particles[1]);
123 hepmc_event->set_beam_particles(hepmc_particles[0], hepmc_particles[1]);
126 typedef std::map<const reco::Candidate*, HepMC::GenVertex*> ParticleToVertexMap;
127 ParticleToVertexMap particleToVertexMap;
128 particleToVertexMap[parton1] = vertex1;
129 particleToVertexMap[parton2] = vertex2;
130 for (
unsigned int i=2, n=genParticlesHandle->
size();
i<
n; ++
i )
135 for (
unsigned int j=0, nMothers=p->
numberOfMothers(); j<nMothers; ++j )
139 HepMC::GenVertex* vertex;
140 if ( particleToVertexMap.find(elder) == particleToVertexMap.end() )
142 vertex =
new HepMC::GenVertex(FourVector(elder->
vertex()));
143 hepmc_event->add_vertex(vertex);
144 particleToVertexMap[elder] = vertex;
148 vertex = particleToVertexMap[elder];
153 vertex->add_particle_in(genCandToHepMCMap[mother]);
154 vertex->add_particle_out(hepmc_particles[
i]);
159 bool hasSignalVertex =
false;
160 if ( !signalParticlePdgIds_.empty() ) {
162 for (
auto v = hepmc_event->vertices_begin();
v != hepmc_event->vertices_end(); ++
v ) {
165 const int pdgId = (*p)->pdg_id();
166 if (
std::find(signalParticlePdgIds_.begin(), signalParticlePdgIds_.end(),
pdgId) != signalParticlePdgIds_.end() ) {
167 hepmc_event->set_signal_process_vertex(*
v);
168 hasSignalVertex =
true;
172 if ( hasSignalVertex )
break;
176 if ( !hasSignalVertex ) hepmc_event->set_signal_process_vertex(*(vertex1->vertices_begin()));
179 hepmc_product->addHepMCData(hepmc_event);
180 event.put(
std::move(hepmc_product),
"unsmeared");
void produce(edm::Event &event, const edm::EventSetup &eventSetup) override
T getParameter(std::string const &) const
EventNumber_t event() const
edm::EDGetTokenT< GenEventInfoProduct > genEventInfoToken_
#define DEFINE_FWK_MODULE(type)
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
std::pair< double, double > x
~GenParticles2HepMCConverter()
edm::ESHandle< ParticleDataTable > pTable_
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
HepMC::FourVector FourVector(const reco::Candidate::Point &point)
edm::EDGetTokenT< reco::CandidateView > genParticlesToken_
void getData(T &iHolder) const
std::pair< double, double > xPDF
virtual int status() const =0
status word
virtual const LorentzVector & p4() const =0
four-momentum Lorentz vector
HepMC::FourVector FourVector(const reco::Candidate::LorentzVector &lvec)
virtual int pdgId() const =0
PDG identifier.
virtual size_type numberOfMothers() const =0
number of mothers (zero or one in most of but not all the cases)
std::vector< int > signalParticlePdgIds_
virtual double mass() const =0
mass
math::XYZTLorentzVector LorentzVector
Lorentz vector.
std::vector< double > & weights()
const_reference at(size_type pos) const
math::XYZPoint Point
point in the space
virtual const Point & vertex() const =0
vertex position
unsigned int signalProcessID() const
GenParticles2HepMCConverter(const edm::ParameterSet &pset)
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point