11 #include "HepMC/GenEvent.h"
12 #include "HepMC/GenVertex.h"
13 #include "HepMC/GenParticle.h"
14 #include "HepMC/SimpleVector.h"
27 }
while (std::isspace(ch));
28 if (ch != std::istream::traits_type::eof())
39 readAttemptCounter(0),
49 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid"
56 int idwtup =
runInfo->getHEPRUP()->IDWTUP;
58 edm::LogWarning(
"Generator|LHEInterface") <<
"Non-allowed negative event weight encountered." << std::endl;
63 edm::LogInfo(
"Generator|LHEInterface") <<
"Event weight not set to one for abs(IDWTUP) == 3" << std::endl;
74 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid event"
76 << (
i + 1) <<
"." << std::endl;
82 std::istringstream
ss(
line);
87 ss >>
pdf->id.first >>
pdf->id.second >>
pdf->x.first >>
pdf->x.second >>
pdf->scalePDF >>
pdf->xPDF.first >>
90 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches event contained"
91 " unparseable PDF information."
101 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches file contained spurious"
102 " content after event data."
107 : runInfo(runInfo), hepeup(hepeup), counted(
false), readAttemptCounter(0), npLO_(-99), npNLO_(-99) {}
112 const std::vector<std::string> &
comments)
115 pdf(pdf ? new
PDF(*pdf) : nullptr),
118 readAttemptCounter(0),
124 hepeup(product.hepeup()),
125 pdf(product.pdf() ? new
PDF(*product.pdf()) : nullptr),
127 comments(product.comments_begin(), product.comments_end()),
129 readAttemptCounter(0),
130 originalXWGTUP_(product.originalXWGTUP()),
131 scales_(product.scales()),
132 npLO_(product.npLO()),
133 npNLO_(product.npNLO()) {}
141 <<
"removeParticle: Index " << (
index + 1) <<
" out of bounds." << std::endl;
162 <<
"removeParticle: Particle " << (
i + 2) <<
" has two mothers." << std::endl;
177 std::find(ids.begin(), ids.end(),
id) != ids.end())
184 edm::LogWarning(
"Generator|LHEInterface") <<
"LHEEvent::count called twice on same event!" << std::endl;
197 info->set_pdf1(
pdf->xPDF.first);
198 info->set_pdf2(
pdf->xPDF.second);
199 info->set_scalePDF(
pdf->scalePDF);
206 info->set_pdf1(-1.0);
207 info->set_pdf2(-1.0);
212 info->set_pdf1(-1.0);
213 info->set_pdf2(-1.0);
237 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches Event does not contain any partons. "
238 <<
"Not much to convert.";
244 std::vector<HepMC::GenVertex *> genVertices;
247 for (
unsigned int i = 0;
i < nup;
i++)
251 for (
unsigned int i = 0;
i < nup;
i++) {
265 HepMC::GenVertex *current_vtx = in_par->end_vertex();
268 current_vtx =
new HepMC::GenVertex(HepMC::FourVector(0, 0, 0,
cTau));
271 genVertices.push_back(current_vtx);
274 for (
unsigned int j = mother1;
j <= mother2;
j++)
293 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first, heprup->EBMUP.first), heprup->IDBMUP.first);
295 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second, heprup->EBMUP.second), heprup->IDBMUP.second);
299 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
300 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
301 v1->add_particle_in(
b1);
302 v2->add_particle_in(
b2);
304 hepmc->add_vertex(v1);
305 hepmc->add_vertex(v2);
306 hepmc->set_beam_particles(
b1,
b2);
314 edm::LogWarning(
"Generator|LHEInterface") <<
"Initial partons do already have a"
315 " production vertex. "
317 <<
"Beam particles not connected.";
319 edm::LogWarning(
"Generator|LHEInterface") <<
"Can't find any initial partons to be"
320 " connected to the beam particles.";
322 for (std::vector<HepMC::GenVertex *>::const_iterator iter = genVertices.begin(); iter != genVertices.end(); ++iter)
323 hepmc->add_vertex(*iter);
326 for (
unsigned int i = 0;
i < nup;
i++) {
328 edm::LogWarning(
"Generator|LHEInterface") <<
"Not all LHE particles could be stored"
329 " stored in the HepMC event. "
331 <<
"Check the mother-daughter relations"
332 " in the given LHE input file.";
337 hepmc->set_signal_process_vertex(const_cast<HepMC::GenVertex *>(
findSignalVertex(hepmc.get(),
false)));
349 particle->set_generated_mass(
hepeup.
PUP.at(
i)[4]);
356 double px = 0,
py = 0, pz = 0, E = 0;
358 for (HepMC::GenEvent::particle_const_iterator iter =
event->particles_begin(); iter !=
event->particles_end();
360 int status = (*iter)->status();
361 HepMC::FourVector fv = (*iter)->momentum();
364 if (
status == 3 && *iter !=
event->beam_particles().first && *iter !=
event->beam_particles().second) {
380 if (
px *
px +
py *
py + pz * pz + E * E > 0.1) {
382 <<
"Energy-momentum badly conserved. " << std::setprecision(3) <<
"sum p_i = [" << std::setw(7) << E <<
", "
383 << std::setw(7) <<
px <<
", " << std::setw(7) <<
py <<
", " << std::setw(7) << pz <<
"]";
392 double largestMass2 = -9.0e-30;
393 const HepMC::GenVertex *
vertex =
nullptr;
394 for (HepMC::GenEvent::vertex_const_iterator iter =
event->vertices_begin(); iter !=
event->vertices_end(); ++iter) {
395 if ((*iter)->particles_in_size() < 2)
397 if ((*iter)->particles_out_size() < 1 ||
398 ((*iter)->particles_out_size() == 1 &&
399 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
400 !(*(*iter)->particles_out_const_begin())->end_vertex()->particles_out_size())))
403 double px = 0.0,
py = 0.0, pz = 0.0, E = 0.0;
404 bool hadStatus3 =
false;
405 for (HepMC::GenVertex::particles_out_const_iterator iter2 = (*iter)->particles_out_const_begin();
406 iter2 != (*iter)->particles_out_const_end();
408 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
409 px += (*iter2)->momentum().px();
410 py += (*iter2)->momentum().py();
411 pz += (*iter2)->momentum().pz();
412 E += (*iter2)->momentum().e();
414 if (status3 && !hadStatus3)
417 double mass2 = E * E - (
px *
px +
py *
py + pz * pz);
418 if (mass2 > largestMass2) {
420 largestMass2 = mass2;
428 HepMC::FourVector &_time,
429 std::set<const HepMC::GenVertex *> &
visited) {
430 HepMC::FourVector
time = _time;
431 HepMC::FourVector curTime =
vertex->position();
432 bool needsFixup = curTime.t() <
time.t();
442 for (HepMC::GenVertex::particles_out_const_iterator iter =
vertex->particles_out_const_begin();
443 iter !=
vertex->particles_out_const_end();
445 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
452 std::set<const HepMC::GenVertex *>
visited;
453 HepMC::FourVector zeroTime;