13 #include "HepMC/GenEvent.h" 14 #include "HepMC/GenVertex.h" 15 #include "HepMC/GenParticle.h" 16 #include "HepMC/SimpleVector.h" 29 }
while (std::isspace(ch));
30 if (ch != std::istream::traits_type::eof())
41 readAttemptCounter(0),
52 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid" 59 int idwtup =
runInfo->getHEPRUP()->IDWTUP;
61 edm::LogWarning(
"Generator|LHEInterface") <<
"Non-allowed negative event weight encountered." << std::endl;
66 edm::LogInfo(
"Generator|LHEInterface") <<
"Event weight not set to one for abs(IDWTUP) == 3" << std::endl;
77 throw cms::Exception(
"InvalidFormat") <<
"Les Houches file contained invalid event" 79 << (
i + 1) <<
"." << std::endl;
85 std::istringstream
ss(
line);
89 pdf = std::make_unique<PDF>();
90 ss >>
pdf->id.first >>
pdf->id.second >>
pdf->x.first >>
pdf->x.second >>
pdf->scalePDF >>
pdf->xPDF.first >>
93 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches event contained" 94 " unparseable PDF information." 104 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches file contained spurious" 105 " content after event data." 110 :
runInfo(
runInfo), hepeup(hepeup), counted(
false), readAttemptCounter(0), npLO_(-99), npNLO_(-99), evtnum_(-1) {}
115 const std::vector<std::string> &comments)
118 pdf(pdf ? new
PDF(*pdf) : nullptr),
121 readAttemptCounter(0),
128 hepeup(product.hepeup()),
129 pdf(product.pdf() ? new
PDF(*product.pdf()) : nullptr),
131 comments(product.comments_begin(), product.comments_end()),
133 readAttemptCounter(0),
134 originalXWGTUP_(product.originalXWGTUP()),
135 scales_(product.
scales()),
136 npLO_(product.npLO()),
137 npNLO_(product.npNLO()),
138 evtnum_(product.evtnum()) {}
146 <<
"removeParticle: Index " << (
index + 1) <<
" out of bounds." << std::endl;
167 <<
"removeParticle: Particle " << (
i + 2) <<
" has two mothers." << std::endl;
182 std::find(ids.begin(), ids.end(),
id) != ids.end())
189 edm::LogWarning(
"Generator|LHEInterface") <<
"LHEEvent::count called twice on same event!" << std::endl;
202 info->set_pdf1(
pdf->xPDF.first);
203 info->set_pdf2(
pdf->xPDF.second);
204 info->set_scalePDF(
pdf->scalePDF);
211 info->set_pdf1(-1.0);
212 info->set_pdf2(-1.0);
217 info->set_pdf1(-1.0);
218 info->set_pdf2(-1.0);
242 edm::LogWarning(
"Generator|LHEInterface") <<
"Les Houches Event does not contain any partons. " 243 <<
"Not much to convert.";
249 std::vector<HepMC::GenVertex *> genVertices;
252 for (
unsigned int i = 0;
i < nup;
i++)
256 for (
unsigned int i = 0;
i < nup;
i++) {
270 HepMC::GenVertex *current_vtx = in_par->end_vertex();
273 current_vtx =
new HepMC::GenVertex(HepMC::FourVector(0, 0, 0,
cTau));
276 genVertices.push_back(current_vtx);
279 for (
unsigned int j = mother1;
j <= mother2;
j++)
298 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first, heprup->EBMUP.first), heprup->IDBMUP.first);
300 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second, heprup->EBMUP.second), heprup->IDBMUP.second);
304 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
305 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
306 v1->add_particle_in(
b1);
307 v2->add_particle_in(
b2);
309 hepmc->add_vertex(v1);
310 hepmc->add_vertex(v2);
311 hepmc->set_beam_particles(
b1,
b2);
319 edm::LogWarning(
"Generator|LHEInterface") <<
"Initial partons do already have a" 320 " production vertex. " 322 <<
"Beam particles not connected.";
324 edm::LogWarning(
"Generator|LHEInterface") <<
"Can't find any initial partons to be" 325 " connected to the beam particles.";
327 for (std::vector<HepMC::GenVertex *>::const_iterator iter = genVertices.begin(); iter != genVertices.end(); ++iter)
328 hepmc->add_vertex(*iter);
331 for (
unsigned int i = 0;
i < nup;
i++) {
333 edm::LogWarning(
"Generator|LHEInterface") <<
"Not all LHE particles could be stored" 334 " stored in the HepMC event. " 336 <<
"Check the mother-daughter relations" 337 " in the given LHE input file.";
342 hepmc->set_signal_process_vertex(const_cast<HepMC::GenVertex *>(
findSignalVertex(hepmc.get(),
false)));
354 particle->set_generated_mass(
hepeup.
PUP.at(
i)[4]);
361 double px = 0,
py = 0, pz = 0, E = 0;
363 for (HepMC::GenEvent::particle_const_iterator iter =
event->particles_begin(); iter !=
event->particles_end();
365 int status = (*iter)->status();
366 HepMC::FourVector fv = (*iter)->momentum();
369 if (
status == 3 && *iter !=
event->beam_particles().first && *iter !=
event->beam_particles().second) {
385 if (
px *
px +
py *
py + pz * pz + E * E > 0.1) {
387 <<
"Energy-momentum badly conserved. " << std::setprecision(3) <<
"sum p_i = [" << std::setw(7) << E <<
", " 388 << std::setw(7) <<
px <<
", " << std::setw(7) <<
py <<
", " << std::setw(7) << pz <<
"]";
397 double largestMass2 = -9.0e-30;
398 const HepMC::GenVertex *
vertex =
nullptr;
399 for (HepMC::GenEvent::vertex_const_iterator iter =
event->vertices_begin(); iter !=
event->vertices_end(); ++iter) {
400 if ((*iter)->particles_in_size() < 2)
402 if ((*iter)->particles_out_size() < 1 ||
403 ((*iter)->particles_out_size() == 1 &&
404 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
405 !(*(*iter)->particles_out_const_begin())->end_vertex()->particles_out_size())))
408 double px = 0.0,
py = 0.0, pz = 0.0, E = 0.0;
409 bool hadStatus3 =
false;
410 for (HepMC::GenVertex::particles_out_const_iterator iter2 = (*iter)->particles_out_const_begin();
411 iter2 != (*iter)->particles_out_const_end();
413 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
414 px += (*iter2)->momentum().px();
415 py += (*iter2)->momentum().py();
416 pz += (*iter2)->momentum().pz();
417 E += (*iter2)->momentum().e();
419 if (status3 && !hadStatus3)
422 double mass2 = E * E - (
px *
px +
py *
py + pz * pz);
423 if (mass2 > largestMass2) {
425 largestMass2 = mass2;
433 HepMC::FourVector &_time,
434 std::set<const HepMC::GenVertex *> &
visited) {
435 HepMC::FourVector
time = _time;
436 HepMC::FourVector curTime =
vertex->position();
437 bool needsFixup = curTime.t() <
time.t();
447 for (HepMC::GenVertex::particles_out_const_iterator iter =
vertex->particles_out_const_begin();
448 iter !=
vertex->particles_out_const_end();
450 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
457 std::set<const HepMC::GenVertex *>
visited;
458 HepMC::FourVector zeroTime;
double cTau(int pdgID, const HepPDT::ParticleDataTable *pdt)
LHEEvent(const std::shared_ptr< LHERunInfo > &runInfo, std::istream &in)
std::vector< std::string > comments
std::vector< std::pair< int, int > > ICOLUP
std::pair< double, double > EBMUP
const std::shared_ptr< LHERunInfo > runInfo
static void fixHepMCEventTimeOrdering(HepMC::GenEvent *event)
void removeResonances(const std::vector< int > &ids)
void count(LHERunInfo::CountMode count, double weight=1.0, double matchWeight=1.0)
std::vector< double > VTIMUP
Log< level::Error, false > LogError
std::pair< double, double > XPDWUP
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::unique_ptr< HepMC::GenEvent > asHepMCEvent() const
void fillEventInfo(HepMC::GenEvent *hepmc) const
static void removeParticle(lhef::HEPEUP &hepeup, int index)
std::vector< FiveVector > PUP
std::vector< double > SPINUP
Abs< T >::type abs(const T &t)
const HEPRUP * getHEPRUP() const
std::vector< std::pair< int, int > > MOTHUP
Log< level::Info, false > LogInfo
void fillPdfInfo(HepMC::PdfInfo *info) const
static void fixSubTree(HepMC::GenVertex *vertex, HepMC::FourVector &_time, std::set< const HepMC::GenVertex *> &visited)
HepMC::GenParticle * makeHepMCParticle(unsigned int i) const
static const HepMC::GenVertex * findSignalVertex(const HepMC::GenEvent *event, bool status3=true)
std::unique_ptr< PDF > pdf
static bool checkHepMCTree(const HepMC::GenEvent *event)
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
Log< level::Warning, false > LogWarning
static int skipWhitespace(std::istream &in)