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),
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)
125 const std::vector<std::string> &
comments) :
126 runInfo(runInfo), hepeup(hepeup), pdf(pdf ? new
PDF(*pdf) : 0),
127 comments(comments), counted(
false), readAttemptCounter(0)
133 runInfo(runInfo), hepeup(product.hepeup()),
134 pdf(product.pdf() ? new
PDF(*product.pdf()) : 0),
136 comments(product.comments_begin(), product.comments_end()),
137 counted(
false), readAttemptCounter(0)
146 static inline void pop(std::vector<T> &vec,
unsigned int index)
148 unsigned int size = vec.size() - 1;
149 std::memmove(&vec[index], &vec[index + 1], (size - index) *
sizeof(
T));
155 if (index < 0 || index >= hepeup.
NUP) {
157 <<
"removeParticle: Index " << (index + 1)
158 <<
" out of bounds." << std::endl;
175 for(
int i = 0;
i < hepeup.
NUP;
i++) {
176 if (hepeup.
MOTHUP[
i].first == index) {
177 if (hepeup.
MOTHUP[
i].second > 0)
179 <<
"removeParticle: Particle "
180 << (
i + 2) <<
" has two mothers."
185 if (hepeup.
MOTHUP[
i].first > index)
187 if (hepeup.
MOTHUP[
i].second > index)
198 std::find(ids.begin(), ids.end(), id) != ids.end())
204 double weight,
double matchWeight)
208 <<
"LHEEvent::count called twice on same event!"
212 weight, matchWeight);
220 info->set_id1(
pdf->id.first);
221 info->set_id2(
pdf->id.second);
222 info->set_x1(
pdf->x.first);
223 info->set_x2(
pdf->x.second);
224 info->set_pdf1(
pdf->xPDF.first);
225 info->set_pdf2(
pdf->xPDF.second);
226 info->set_scalePDF(
pdf->scalePDF);
233 info->set_pdf1(-1.0);
234 info->set_pdf2(-1.0);
239 info->set_pdf1(-1.0);
240 info->set_pdf2(-1.0);
255 std::auto_ptr<HepMC::GenEvent> hepmc(
new HepMC::GenEvent);
267 <<
"Les Houches Event does not contain any partons. "
268 <<
"Not much to convert." ;
274 std::vector<HepMC::GenVertex*> genVertices;
277 for(
unsigned int i = 0;
i < nup;
i++)
281 for(
unsigned int i = 0;
i < nup;
i++) {
295 HepMC::GenVertex *current_vtx = in_par->end_vertex();
298 current_vtx =
new HepMC::GenVertex(
299 HepMC::FourVector(0, 0, 0, cTau));
302 genVertices.push_back(current_vtx);
305 for(
unsigned int j = mother1;
j <= mother2;
j++)
306 if (!genParticles.at(
j)->end_vertex())
307 current_vtx->add_particle_in(genParticles.at(
j));
310 current_vtx->add_particle_out(genParticles.at(
i));
324 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first,
325 heprup->EBMUP.first),
326 heprup->IDBMUP.first);
328 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second,
329 heprup->EBMUP.second),
330 heprup->IDBMUP.second);
334 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
335 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
336 v1->add_particle_in(b1);
337 v2->add_particle_in(b2);
339 hepmc->add_vertex(v1);
340 hepmc->add_vertex(v2);
341 hepmc->set_beam_particles(b1, b2);
344 if (genParticles.size() >= 2) {
345 if (!genParticles.at(0)->production_vertex() &&
346 !genParticles.at(1)->production_vertex()) {
347 v1->add_particle_out(genParticles.at(0));
348 v2->add_particle_out(genParticles.at(1));
351 <<
"Initial partons do already have a"
352 " production vertex. " << std::endl
353 <<
"Beam particles not connected.";
356 <<
"Can't find any initial partons to be"
357 " connected to the beam particles.";
359 for(std::vector<HepMC::GenVertex*>::const_iterator iter = genVertices.begin();
360 iter != genVertices.end(); ++iter)
361 hepmc->add_vertex(*iter);
364 for(
unsigned int i = 0;
i < nup;
i++) {
365 if (!genParticles.at(
i)->parent_event()) {
367 <<
"Not all LHE particles could be stored"
368 " stored in the HepMC event. "
370 <<
"Check the mother-daughter relations"
371 " in the given LHE input file.";
376 hepmc->set_signal_process_vertex(
377 const_cast<HepMC::GenVertex*>(
394 particle->set_generated_mass(
hepeup.
PUP.at(i)[4]);
395 particle->set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
402 double px = 0, py = 0, pz = 0, E = 0;
404 for(HepMC::GenEvent::particle_const_iterator iter = event->particles_begin();
405 iter !=
event->particles_end(); iter++) {
406 int status = (*iter)->status();
407 HepMC::FourVector fv = (*iter)->momentum();
411 *iter != event->beam_particles().first &&
412 *iter !=
event->beam_particles().second) {
428 if (px*px + py*py + pz*pz + E*E > 0.1) {
430 <<
"Energy-momentum badly conserved. "
431 << std::setprecision(3)
433 << std::setw(7) << E <<
", "
434 << std::setw(7) << px <<
", "
435 << std::setw(7) << py <<
", "
436 << std::setw(7) << pz <<
"]";
445 const HepMC::GenEvent *
event,
bool status3)
447 double largestMass2 = -9.0e-30;
448 const HepMC::GenVertex *vertex = 0;
449 for(HepMC::GenEvent::vertex_const_iterator iter = event->vertices_begin();
450 iter !=
event->vertices_end(); ++iter) {
451 if ((*iter)->particles_in_size() < 2)
453 if ((*iter)->particles_out_size() < 1 ||
454 ((*iter)->particles_out_size() == 1 &&
455 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
456 !(*(*iter)->particles_out_const_begin())
457 ->end_vertex()->particles_out_size())))
460 double px = 0.0, py = 0.0, pz = 0.0, E = 0.0;
461 bool hadStatus3 =
false;
462 for(HepMC::GenVertex::particles_out_const_iterator iter2 =
463 (*iter)->particles_out_const_begin();
464 iter2 != (*iter)->particles_out_const_end(); ++iter2) {
465 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
466 px += (*iter2)->momentum().px();
467 py += (*iter2)->momentum().py();
468 pz += (*iter2)->momentum().pz();
469 E += (*iter2)->momentum().e();
471 if (status3 && !hadStatus3)
474 double mass2 = E * E - (px * px + py * py + pz * pz);
475 if (mass2 > largestMass2) {
477 largestMass2 = mass2;
485 HepMC::FourVector& _time,
486 std::set<const HepMC::GenVertex*> &visited)
488 HepMC::FourVector
time = _time;
489 HepMC::FourVector curTime = vertex->position();
490 bool needsFixup = curTime.t() < time.t();
492 if (!visited.insert(vertex).second && !needsFixup)
496 vertex->set_position(time);
500 for(HepMC::GenVertex::particles_out_const_iterator iter =
501 vertex->particles_out_const_begin();
502 iter != vertex->particles_out_const_end(); ++iter) {
503 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
511 std::set<const HepMC::GenVertex*> visited;
512 HepMC::FourVector zeroTime;
514 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