11 #include "HepMC/GenEvent.h" 12 #include "HepMC/GenVertex.h" 13 #include "HepMC/GenParticle.h" 14 #include "HepMC/SimpleVector.h" 28 }
while(std::isspace(ch));
29 if (ch != std::istream::traits_type::eof())
38 runInfo(runInfo), weights_(0), counted(
false),
39 readAttemptCounter(0), npLO_(-99), npNLO_(-99)
49 <<
"Les Houches file contained invalid" 50 " event header." << std::endl;
55 int idwtup = runInfo->getHEPRUP()->IDWTUP;
58 <<
"Non-allowed negative event weight encountered." 65 <<
"Event weight not set to one for abs(IDWTUP) == 3" 81 <<
"Les Houches file contained invalid event" 82 " in particle line " << (
i + 1)
88 std::getline(in, line);
89 std::istringstream ss(line);
94 ss >>
pdf->id.first >>
pdf->id.second
95 >>
pdf->x.first >>
pdf->x.second
97 >>
pdf->xPDF.first >>
pdf->xPDF.second;
100 <<
"Les Houches event contained" 101 " unparseable PDF information." 112 <<
"Les Houches file contained spurious" 113 " content after event data." << std::endl;
126 const std::vector<std::string> &
comments) :
127 runInfo(runInfo), hepeup(hepeup), pdf(pdf ? new
PDF(*pdf) :
nullptr),
138 comments(product.comments_begin(), product.comments_end()),
152 if (index < 0 || index >= hepeup.
NUP) {
154 <<
"removeParticle: Index " << (index + 1)
155 <<
" out of bounds." << std::endl;
172 for(
int i = 0;
i < hepeup.
NUP;
i++) {
173 if (hepeup.
MOTHUP[
i].first == index) {
174 if (hepeup.
MOTHUP[
i].second > 0)
176 <<
"removeParticle: Particle " 177 << (
i + 2) <<
" has two mothers." 182 if (hepeup.
MOTHUP[
i].first > index)
184 if (hepeup.
MOTHUP[
i].second > index)
195 std::find(ids.begin(), ids.end(),
id) != ids.end())
201 double weight,
double matchWeight)
205 <<
"LHEEvent::count called twice on same event!" 209 weight, matchWeight);
217 info->set_id1(
pdf->id.first);
218 info->set_id2(
pdf->id.second);
219 info->set_x1(
pdf->x.first);
220 info->set_x2(
pdf->x.second);
221 info->set_pdf1(
pdf->xPDF.first);
222 info->set_pdf2(
pdf->xPDF.second);
223 info->set_scalePDF(
pdf->scalePDF);
230 info->set_pdf1(-1.0);
231 info->set_pdf2(-1.0);
236 info->set_pdf1(-1.0);
237 info->set_pdf2(-1.0);
252 std::unique_ptr<HepMC::GenEvent> hepmc(
new HepMC::GenEvent);
264 <<
"Les Houches Event does not contain any partons. " 265 <<
"Not much to convert." ;
271 std::vector<HepMC::GenVertex*> genVertices;
274 for(
unsigned int i = 0;
i < nup;
i++)
278 for(
unsigned int i = 0;
i < nup;
i++) {
292 HepMC::GenVertex *current_vtx = in_par->end_vertex();
295 current_vtx =
new HepMC::GenVertex(
296 HepMC::FourVector(0, 0, 0, cTau));
299 genVertices.push_back(current_vtx);
302 for(
unsigned int j = mother1; j <= mother2; j++)
303 if (!genParticles.at(j)->end_vertex())
304 current_vtx->add_particle_in(genParticles.at(j));
307 current_vtx->add_particle_out(genParticles.at(
i));
321 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first,
322 heprup->EBMUP.first),
323 heprup->IDBMUP.first);
325 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second,
326 heprup->EBMUP.second),
327 heprup->IDBMUP.second);
331 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
332 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
333 v1->add_particle_in(b1);
334 v2->add_particle_in(b2);
336 hepmc->add_vertex(v1);
337 hepmc->add_vertex(v2);
338 hepmc->set_beam_particles(b1, b2);
341 if (genParticles.size() >= 2) {
342 if (!genParticles.at(0)->production_vertex() &&
343 !genParticles.at(1)->production_vertex()) {
344 v1->add_particle_out(genParticles.at(0));
345 v2->add_particle_out(genParticles.at(1));
348 <<
"Initial partons do already have a" 349 " production vertex. " << std::endl
350 <<
"Beam particles not connected.";
353 <<
"Can't find any initial partons to be" 354 " connected to the beam particles.";
356 for(std::vector<HepMC::GenVertex*>::const_iterator iter = genVertices.begin();
357 iter != genVertices.end(); ++iter)
358 hepmc->add_vertex(*iter);
361 for(
unsigned int i = 0;
i < nup;
i++) {
362 if (!genParticles.at(
i)->parent_event()) {
364 <<
"Not all LHE particles could be stored" 365 " stored in the HepMC event. " 367 <<
"Check the mother-daughter relations" 368 " in the given LHE input file.";
373 hepmc->set_signal_process_vertex(
374 const_cast<HepMC::GenVertex*>(
391 particle->set_generated_mass(
hepeup.
PUP.at(i)[4]);
392 particle->set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
399 double px = 0, py = 0, pz = 0, E = 0;
401 for(HepMC::GenEvent::particle_const_iterator iter = event->particles_begin();
402 iter !=
event->particles_end(); iter++) {
403 int status = (*iter)->status();
404 HepMC::FourVector fv = (*iter)->momentum();
408 *iter != event->beam_particles().first &&
409 *iter !=
event->beam_particles().second) {
425 if (px*px + py*py + pz*pz + E*E > 0.1) {
427 <<
"Energy-momentum badly conserved. " 428 << std::setprecision(3)
430 << std::setw(7) << E <<
", " 431 << std::setw(7) << px <<
", " 432 << std::setw(7) << py <<
", " 433 << std::setw(7) << pz <<
"]";
442 const HepMC::GenEvent *
event,
bool status3)
444 double largestMass2 = -9.0e-30;
445 const HepMC::GenVertex *vertex =
nullptr;
446 for(HepMC::GenEvent::vertex_const_iterator iter = event->vertices_begin();
447 iter !=
event->vertices_end(); ++iter) {
448 if ((*iter)->particles_in_size() < 2)
450 if ((*iter)->particles_out_size() < 1 ||
451 ((*iter)->particles_out_size() == 1 &&
452 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
453 !(*(*iter)->particles_out_const_begin())
454 ->end_vertex()->particles_out_size())))
457 double px = 0.0, py = 0.0, pz = 0.0, E = 0.0;
458 bool hadStatus3 =
false;
459 for(HepMC::GenVertex::particles_out_const_iterator iter2 =
460 (*iter)->particles_out_const_begin();
461 iter2 != (*iter)->particles_out_const_end(); ++iter2) {
462 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
463 px += (*iter2)->momentum().px();
464 py += (*iter2)->momentum().py();
465 pz += (*iter2)->momentum().pz();
466 E += (*iter2)->momentum().e();
468 if (status3 && !hadStatus3)
471 double mass2 = E * E - (px * px + py * py + pz * pz);
472 if (mass2 > largestMass2) {
474 largestMass2 = mass2;
482 HepMC::FourVector& _time,
483 std::set<const HepMC::GenVertex*> &
visited)
485 HepMC::FourVector
time = _time;
486 HepMC::FourVector curTime = vertex->position();
487 bool needsFixup = curTime.t() < time.t();
489 if (!visited.insert(vertex).second && !needsFixup)
493 vertex->set_position(time);
497 for(HepMC::GenVertex::particles_out_const_iterator iter =
498 vertex->particles_out_const_begin();
499 iter != vertex->particles_out_const_end(); ++iter) {
500 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
508 std::set<const HepMC::GenVertex*>
visited;
509 HepMC::FourVector zeroTime;
511 iter !=
event->vertices_end(); ++iter)
static void fixSubTree(HepMC::GenVertex *vertex, HepMC::FourVector &_time, std::set< const HepMC::GenVertex * > &visited)
std::vector< std::string > comments
const HEPRUP * getHEPRUP() const
void fillEventInfo(HepMC::GenEvent *hepmc) const
std::pair< double, double > EBMUP
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
std::pair< double, double > XPDWUP
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
LHEEvent(const boost::shared_ptr< LHERunInfo > &runInfo, std::istream &in)
std::vector< std::pair< int, int > > MOTHUP
const boost::shared_ptr< LHERunInfo > runInfo
HepMC::GenParticle * makeHepMCParticle(unsigned int i) const
static void removeParticle(lhef::HEPEUP &hepeup, int index)
std::vector< FiveVector > PUP
std::vector< double > SPINUP
void fillPdfInfo(HepMC::PdfInfo *info) const
Abs< T >::type abs(const T &t)
std::unique_ptr< HepMC::GenEvent > asHepMCEvent() const
const std::vector< float > & scales() const
static const HepMC::GenVertex * findSignalVertex(const HepMC::GenEvent *event, bool status3=true)
double originalXWGTUP() const
std::vector< float > scales_
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
static int skipWhitespace(std::istream &in)
std::vector< std::pair< int, int > > ICOLUP
const std::vector< WGT > & weights() const
std::vector< WGT > weights_