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."
107 size_t found = line.find(
"amcatnlo");
109 if ( found != std::string::npos) {
110 std::string avalue = line.substr(found+1,line.size());
111 found = avalue.find(
"_");
112 avalue = avalue.substr(found+1,avalue.size());
113 NEVT = atof(avalue.c_str());
121 <<
"Les Houches file contained spurious"
122 " content after event data." << std::endl;
127 runInfo(runInfo), hepeup(hepeup), counted(
false), readAttemptCounter(0)
134 const std::vector<std::string> &
comments) :
135 runInfo(runInfo), hepeup(hepeup), pdf(pdf ? new
PDF(*pdf) : 0),
136 comments(comments), counted(
false), readAttemptCounter(0)
142 runInfo(runInfo), hepeup(product.hepeup()),
143 pdf(product.pdf() ? new
PDF(*product.pdf()) : 0),
145 comments(product.comments_begin(), product.comments_end()),
146 counted(
false), readAttemptCounter(0)
155 static inline void pop(std::vector<T> &vec,
unsigned int index)
157 unsigned int size = vec.size() - 1;
158 std::memmove(&vec[index], &vec[index + 1], (size - index) *
sizeof(
T));
164 if (index < 0 || index >= hepeup.
NUP) {
166 <<
"removeParticle: Index " << (index + 1)
167 <<
" out of bounds." << std::endl;
184 for(
int i = 0;
i < hepeup.
NUP;
i++) {
185 if (hepeup.
MOTHUP[
i].first == index) {
186 if (hepeup.
MOTHUP[
i].second > 0)
188 <<
"removeParticle: Particle "
189 << (
i + 2) <<
" has two mothers."
194 if (hepeup.
MOTHUP[
i].first > index)
196 if (hepeup.
MOTHUP[
i].second > index)
207 std::find(ids.begin(), ids.end(), id) != ids.end())
213 double weight,
double matchWeight)
217 <<
"LHEEvent::count called twice on same event!"
221 weight, matchWeight);
229 info->set_id1(
pdf->id.first);
230 info->set_id2(
pdf->id.second);
231 info->set_x1(
pdf->x.first);
232 info->set_x2(
pdf->x.second);
233 info->set_pdf1(
pdf->xPDF.first);
234 info->set_pdf2(
pdf->xPDF.second);
235 info->set_scalePDF(
pdf->scalePDF);
242 info->set_pdf1(-1.0);
243 info->set_pdf2(-1.0);
248 info->set_pdf1(-1.0);
249 info->set_pdf2(-1.0);
264 std::auto_ptr<HepMC::GenEvent> hepmc(
new HepMC::GenEvent);
276 <<
"Les Houches Event does not contain any partons. "
277 <<
"Not much to convert." ;
283 std::vector<HepMC::GenVertex*> genVertices;
286 for(
unsigned int i = 0;
i < nup;
i++)
290 for(
unsigned int i = 0;
i < nup;
i++) {
304 HepMC::GenVertex *current_vtx = in_par->end_vertex();
307 current_vtx =
new HepMC::GenVertex(
308 HepMC::FourVector(0, 0, 0, cTau));
311 genVertices.push_back(current_vtx);
314 for(
unsigned int j = mother1;
j <= mother2;
j++)
315 if (!genParticles.at(
j)->end_vertex())
316 current_vtx->add_particle_in(genParticles.at(
j));
319 current_vtx->add_particle_out(genParticles.at(
i));
333 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first,
334 heprup->EBMUP.first),
335 heprup->IDBMUP.first);
337 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second,
338 heprup->EBMUP.second),
339 heprup->IDBMUP.second);
343 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
344 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
345 v1->add_particle_in(b1);
346 v2->add_particle_in(b2);
348 hepmc->add_vertex(v1);
349 hepmc->add_vertex(v2);
350 hepmc->set_beam_particles(b1, b2);
353 if (genParticles.size() >= 2) {
354 if (!genParticles.at(0)->production_vertex() &&
355 !genParticles.at(1)->production_vertex()) {
356 v1->add_particle_out(genParticles.at(0));
357 v2->add_particle_out(genParticles.at(1));
360 <<
"Initial partons do already have a"
361 " production vertex. " << std::endl
362 <<
"Beam particles not connected.";
365 <<
"Can't find any initial partons to be"
366 " connected to the beam particles.";
368 for(std::vector<HepMC::GenVertex*>::const_iterator iter = genVertices.begin();
369 iter != genVertices.end(); ++iter)
370 hepmc->add_vertex(*iter);
373 for(
unsigned int i = 0;
i < nup;
i++) {
374 if (!genParticles.at(
i)->parent_event()) {
376 <<
"Not all LHE particles could be stored"
377 " stored in the HepMC event. "
379 <<
"Check the mother-daughter relations"
380 " in the given LHE input file.";
385 hepmc->set_signal_process_vertex(
386 const_cast<HepMC::GenVertex*>(
403 particle->set_generated_mass(
hepeup.
PUP.at(i)[4]);
404 particle->set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
411 double px = 0, py = 0, pz = 0, E = 0;
413 for(HepMC::GenEvent::particle_const_iterator iter = event->particles_begin();
414 iter !=
event->particles_end(); iter++) {
415 int status = (*iter)->status();
416 HepMC::FourVector fv = (*iter)->momentum();
420 *iter != event->beam_particles().first &&
421 *iter !=
event->beam_particles().second) {
437 if (px*px + py*py + pz*pz + E*E > 0.1) {
439 <<
"Energy-momentum badly conserved. "
440 << std::setprecision(3)
442 << std::setw(7) << E <<
", "
443 << std::setw(7) << px <<
", "
444 << std::setw(7) << py <<
", "
445 << std::setw(7) << pz <<
"]";
454 const HepMC::GenEvent *
event,
bool status3)
456 double largestMass2 = -9.0e-30;
457 const HepMC::GenVertex *vertex = 0;
458 for(HepMC::GenEvent::vertex_const_iterator iter = event->vertices_begin();
459 iter !=
event->vertices_end(); ++iter) {
460 if ((*iter)->particles_in_size() < 2)
462 if ((*iter)->particles_out_size() < 1 ||
463 ((*iter)->particles_out_size() == 1 &&
464 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
465 !(*(*iter)->particles_out_const_begin())
466 ->end_vertex()->particles_out_size())))
469 double px = 0.0, py = 0.0, pz = 0.0, E = 0.0;
470 bool hadStatus3 =
false;
471 for(HepMC::GenVertex::particles_out_const_iterator iter2 =
472 (*iter)->particles_out_const_begin();
473 iter2 != (*iter)->particles_out_const_end(); ++iter2) {
474 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
475 px += (*iter2)->momentum().px();
476 py += (*iter2)->momentum().py();
477 pz += (*iter2)->momentum().pz();
478 E += (*iter2)->momentum().e();
480 if (status3 && !hadStatus3)
483 double mass2 = E * E - (px * px + py * py + pz * pz);
484 if (mass2 > largestMass2) {
486 largestMass2 = mass2;
494 HepMC::FourVector& _time,
495 std::set<const HepMC::GenVertex*> &visited)
497 HepMC::FourVector
time = _time;
498 HepMC::FourVector curTime = vertex->position();
499 bool needsFixup = curTime.t() < time.t();
501 if (!visited.insert(vertex).second && !needsFixup)
505 vertex->set_position(time);
509 for(HepMC::GenVertex::particles_out_const_iterator iter =
510 vertex->particles_out_const_begin();
511 iter != vertex->particles_out_const_end(); ++iter) {
512 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
520 std::set<const HepMC::GenVertex*> visited;
521 HepMC::FourVector zeroTime;
523 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