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;
118 runInfo(runInfo), hepeup(hepeup), counted(
false), readAttemptCounter(0),
119 npLO_(-99), npNLO_(-99)
126 const std::vector<std::string> &
comments) :
127 runInfo(runInfo), hepeup(hepeup), pdf(pdf ? new
PDF(*pdf) : 0),
128 comments(comments), counted(
false), readAttemptCounter(0),
129 npLO_(-99), npNLO_(-99)
135 runInfo(runInfo), hepeup(product.hepeup()),
136 pdf(product.pdf() ? new
PDF(*product.pdf()) : 0),
138 comments(product.comments_begin(), product.comments_end()),
139 counted(
false), readAttemptCounter(0),
140 originalXWGTUP_(product.originalXWGTUP()), scales_(product.scales()),
141 npLO_(product.npLO()), npNLO_(product.npNLO())
150 static inline void pop(std::vector<T> &vec,
unsigned int index)
152 unsigned int size = vec.size() - 1;
153 std::memmove(&vec[index], &vec[index + 1], (size - index) *
sizeof(
T));
159 if (index < 0 || index >= hepeup.
NUP) {
161 <<
"removeParticle: Index " << (index + 1)
162 <<
" out of bounds." << std::endl;
179 for(
int i = 0;
i < hepeup.
NUP;
i++) {
180 if (hepeup.
MOTHUP[
i].first == index) {
181 if (hepeup.
MOTHUP[
i].second > 0)
183 <<
"removeParticle: Particle "
184 << (
i + 2) <<
" has two mothers."
189 if (hepeup.
MOTHUP[
i].first > index)
191 if (hepeup.
MOTHUP[
i].second > index)
202 std::find(ids.begin(), ids.end(), id) != ids.end())
208 double weight,
double matchWeight)
212 <<
"LHEEvent::count called twice on same event!"
216 weight, matchWeight);
224 info->set_id1(
pdf->id.first);
225 info->set_id2(
pdf->id.second);
226 info->set_x1(
pdf->x.first);
227 info->set_x2(
pdf->x.second);
228 info->set_pdf1(
pdf->xPDF.first);
229 info->set_pdf2(
pdf->xPDF.second);
230 info->set_scalePDF(
pdf->scalePDF);
237 info->set_pdf1(-1.0);
238 info->set_pdf2(-1.0);
243 info->set_pdf1(-1.0);
244 info->set_pdf2(-1.0);
259 std::auto_ptr<HepMC::GenEvent> hepmc(
new HepMC::GenEvent);
271 <<
"Les Houches Event does not contain any partons. "
272 <<
"Not much to convert." ;
278 std::vector<HepMC::GenVertex*> genVertices;
281 for(
unsigned int i = 0;
i < nup;
i++)
285 for(
unsigned int i = 0;
i < nup;
i++) {
299 HepMC::GenVertex *current_vtx = in_par->end_vertex();
302 current_vtx =
new HepMC::GenVertex(
303 HepMC::FourVector(0, 0, 0, cTau));
306 genVertices.push_back(current_vtx);
309 for(
unsigned int j = mother1;
j <= mother2;
j++)
310 if (!genParticles.at(
j)->end_vertex())
311 current_vtx->add_particle_in(genParticles.at(
j));
314 current_vtx->add_particle_out(genParticles.at(
i));
328 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first,
329 heprup->EBMUP.first),
330 heprup->IDBMUP.first);
332 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second,
333 heprup->EBMUP.second),
334 heprup->IDBMUP.second);
338 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
339 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
340 v1->add_particle_in(b1);
341 v2->add_particle_in(b2);
343 hepmc->add_vertex(v1);
344 hepmc->add_vertex(v2);
345 hepmc->set_beam_particles(b1, b2);
348 if (genParticles.size() >= 2) {
349 if (!genParticles.at(0)->production_vertex() &&
350 !genParticles.at(1)->production_vertex()) {
351 v1->add_particle_out(genParticles.at(0));
352 v2->add_particle_out(genParticles.at(1));
355 <<
"Initial partons do already have a"
356 " production vertex. " << std::endl
357 <<
"Beam particles not connected.";
360 <<
"Can't find any initial partons to be"
361 " connected to the beam particles.";
363 for(std::vector<HepMC::GenVertex*>::const_iterator iter = genVertices.begin();
364 iter != genVertices.end(); ++iter)
365 hepmc->add_vertex(*iter);
368 for(
unsigned int i = 0;
i < nup;
i++) {
369 if (!genParticles.at(
i)->parent_event()) {
371 <<
"Not all LHE particles could be stored"
372 " stored in the HepMC event. "
374 <<
"Check the mother-daughter relations"
375 " in the given LHE input file.";
380 hepmc->set_signal_process_vertex(
381 const_cast<HepMC::GenVertex*>(
398 particle->set_generated_mass(
hepeup.
PUP.at(i)[4]);
399 particle->set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
406 double px = 0, py = 0, pz = 0, E = 0;
408 for(HepMC::GenEvent::particle_const_iterator iter = event->particles_begin();
409 iter !=
event->particles_end(); iter++) {
410 int status = (*iter)->status();
411 HepMC::FourVector fv = (*iter)->momentum();
415 *iter != event->beam_particles().first &&
416 *iter !=
event->beam_particles().second) {
432 if (px*px + py*py + pz*pz + E*E > 0.1) {
434 <<
"Energy-momentum badly conserved. "
435 << std::setprecision(3)
437 << std::setw(7) << E <<
", "
438 << std::setw(7) << px <<
", "
439 << std::setw(7) << py <<
", "
440 << std::setw(7) << pz <<
"]";
449 const HepMC::GenEvent *
event,
bool status3)
451 double largestMass2 = -9.0e-30;
452 const HepMC::GenVertex *vertex = 0;
453 for(HepMC::GenEvent::vertex_const_iterator iter = event->vertices_begin();
454 iter !=
event->vertices_end(); ++iter) {
455 if ((*iter)->particles_in_size() < 2)
457 if ((*iter)->particles_out_size() < 1 ||
458 ((*iter)->particles_out_size() == 1 &&
459 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
460 !(*(*iter)->particles_out_const_begin())
461 ->end_vertex()->particles_out_size())))
464 double px = 0.0, py = 0.0, pz = 0.0, E = 0.0;
465 bool hadStatus3 =
false;
466 for(HepMC::GenVertex::particles_out_const_iterator iter2 =
467 (*iter)->particles_out_const_begin();
468 iter2 != (*iter)->particles_out_const_end(); ++iter2) {
469 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
470 px += (*iter2)->momentum().px();
471 py += (*iter2)->momentum().py();
472 pz += (*iter2)->momentum().pz();
473 E += (*iter2)->momentum().e();
475 if (status3 && !hadStatus3)
478 double mass2 = E * E - (px * px + py * py + pz * pz);
479 if (mass2 > largestMass2) {
481 largestMass2 = mass2;
489 HepMC::FourVector& _time,
490 std::set<const HepMC::GenVertex*> &
visited)
492 HepMC::FourVector
time = _time;
493 HepMC::FourVector curTime = vertex->position();
494 bool needsFixup = curTime.t() < time.t();
496 if (!visited.insert(vertex).second && !needsFixup)
500 vertex->set_position(time);
504 for(HepMC::GenVertex::particles_out_const_iterator iter =
505 vertex->particles_out_const_begin();
506 iter != vertex->particles_out_const_end(); ++iter) {
507 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
515 std::set<const HepMC::GenVertex*>
visited;
516 HepMC::FourVector zeroTime;
518 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
static void pop(std::vector< T > &vec, unsigned int index)
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)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
static const HepMC::GenVertex * findSignalVertex(const HepMC::GenEvent *event, bool status3=true)
static bool checkHepMCTree(const HepMC::GenEvent *event)
std::auto_ptr< HepMC::GenEvent > asHepMCEvent() const
VertexRefVector::iterator vertex_iterator
iterator over a vector of references to Vertex objects in the same collection
volatile std::atomic< bool > shutdown_flag false
static int skipWhitespace(std::istream &in)
tuple size
Write out results.
std::vector< std::pair< int, int > > ICOLUP