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), counted(
false), readAttemptCounter(0)
47 <<
"Les Houches file contained invalid"
48 " event header." << std::endl;
50 int idwtup = runInfo->getHEPRUP()->IDWTUP;
53 <<
"Non-allowed egative event weight encountered."
60 <<
"Event weight not set to one for abs(IDWTUP) == 3"
76 <<
"Les Houches file contained invalid event"
77 " in particle line " << (
i + 1)
83 std::getline(in, line);
84 std::istringstream ss(line);
89 ss >>
pdf->id.first >>
pdf->id.second
90 >>
pdf->x.first >>
pdf->x.second
92 >>
pdf->xPDF.first >>
pdf->xPDF.second;
95 <<
"Les Houches event contained"
96 " unparseable PDF information."
102 size_t found = line.find(
"amcatnlo");
104 if ( found != std::string::npos) {
105 std::string avalue = line.substr(found+1,line.size());
106 found = avalue.find(
"_");
107 avalue = avalue.substr(found+1,avalue.size());
108 NEVT = atof(avalue.c_str());
116 <<
"Les Houches file contained spurious"
117 " content after event data." << std::endl;
122 runInfo(runInfo), hepeup(hepeup), counted(
false), readAttemptCounter(0)
129 const std::vector<std::string> &
comments) :
130 runInfo(runInfo), hepeup(hepeup), pdf(pdf ? new
PDF(*pdf) : 0),
131 comments(comments), counted(
false), readAttemptCounter(0)
137 runInfo(runInfo), hepeup(product.hepeup()),
138 pdf(product.pdf() ? new
PDF(*product.pdf()) : 0),
139 comments(product.comments_begin(), product.comments_end()),
140 counted(
false), readAttemptCounter(0)
149 static inline void pop(std::vector<T> &vec,
unsigned int index)
151 unsigned int size = vec.size() - 1;
152 std::memmove(&vec[index], &vec[index + 1], (size - index) *
sizeof(
T));
158 if (index < 0 || index >= hepeup.
NUP) {
160 <<
"removeParticle: Index " << (index + 1)
161 <<
" out of bounds." << std::endl;
178 for(
int i = 0;
i < hepeup.
NUP;
i++) {
179 if (hepeup.
MOTHUP[
i].first == index) {
180 if (hepeup.
MOTHUP[
i].second > 0)
182 <<
"removeParticle: Particle "
183 << (
i + 2) <<
" has two mothers."
188 if (hepeup.
MOTHUP[
i].first > index)
190 if (hepeup.
MOTHUP[
i].second > index)
201 std::find(ids.begin(), ids.end(), id) != ids.end())
207 double weight,
double matchWeight)
211 <<
"LHEEvent::count called twice on same event!"
215 weight, matchWeight);
223 info->set_id1(
pdf->id.first);
224 info->set_id2(
pdf->id.second);
225 info->set_x1(
pdf->x.first);
226 info->set_x2(
pdf->x.second);
227 info->set_pdf1(
pdf->xPDF.first);
228 info->set_pdf2(
pdf->xPDF.second);
229 info->set_scalePDF(
pdf->scalePDF);
236 info->set_pdf1(-1.0);
237 info->set_pdf2(-1.0);
242 info->set_pdf1(-1.0);
243 info->set_pdf2(-1.0);
258 std::auto_ptr<HepMC::GenEvent> hepmc(
new HepMC::GenEvent);
270 <<
"Les Houches Event does not contain any partons. "
271 <<
"Not much to convert." ;
277 std::vector<HepMC::GenVertex*> genVertices;
280 for(
unsigned int i = 0;
i < nup;
i++)
284 for(
unsigned int i = 0;
i < nup;
i++) {
298 HepMC::GenVertex *current_vtx = in_par->end_vertex();
301 current_vtx =
new HepMC::GenVertex(
302 HepMC::FourVector(0, 0, 0, cTau));
305 genVertices.push_back(current_vtx);
308 for(
unsigned int j = mother1;
j <= mother2;
j++)
309 if (!genParticles.at(
j)->end_vertex())
310 current_vtx->add_particle_in(genParticles.at(
j));
313 current_vtx->add_particle_out(genParticles.at(
i));
327 HepMC::FourVector(0.0, 0.0, +heprup->EBMUP.first,
328 heprup->EBMUP.first),
329 heprup->IDBMUP.first);
331 HepMC::FourVector(0.0, 0.0, -heprup->EBMUP.second,
332 heprup->EBMUP.second),
333 heprup->IDBMUP.second);
337 HepMC::GenVertex *v1 =
new HepMC::GenVertex();
338 HepMC::GenVertex *v2 =
new HepMC::GenVertex();
339 v1->add_particle_in(b1);
340 v2->add_particle_in(b2);
342 hepmc->add_vertex(v1);
343 hepmc->add_vertex(v2);
344 hepmc->set_beam_particles(b1, b2);
347 if (genParticles.size() >= 2) {
348 if (!genParticles.at(0)->production_vertex() &&
349 !genParticles.at(1)->production_vertex()) {
350 v1->add_particle_out(genParticles.at(0));
351 v2->add_particle_out(genParticles.at(1));
354 <<
"Initial partons do already have a"
355 " production vertex. " << std::endl
356 <<
"Beam particles not connected.";
359 <<
"Can't find any initial partons to be"
360 " connected to the beam particles.";
362 for(std::vector<HepMC::GenVertex*>::const_iterator iter = genVertices.begin();
363 iter != genVertices.end(); ++iter)
364 hepmc->add_vertex(*iter);
367 for(
unsigned int i = 0;
i < nup;
i++) {
368 if (!genParticles.at(
i)->parent_event()) {
370 <<
"Not all LHE particles could be stored"
371 " stored in the HepMC event. "
373 <<
"Check the mother-daughter relations"
374 " in the given LHE input file.";
379 hepmc->set_signal_process_vertex(
380 const_cast<HepMC::GenVertex*>(
397 particle->set_generated_mass(
hepeup.
PUP.at(i)[4]);
398 particle->set_status(status > 0 ? (status == 2 ? 3 : status) : 3);
405 double px = 0, py = 0, pz = 0, E = 0;
407 for(HepMC::GenEvent::particle_const_iterator iter = event->particles_begin();
408 iter !=
event->particles_end(); iter++) {
409 int status = (*iter)->status();
410 HepMC::FourVector fv = (*iter)->momentum();
414 *iter != event->beam_particles().first &&
415 *iter !=
event->beam_particles().second) {
431 if (px*px + py*py + pz*pz + E*E > 0.1) {
433 <<
"Energy-momentum badly conserved. "
434 << std::setprecision(3)
436 << std::setw(7) << E <<
", "
437 << std::setw(7) << px <<
", "
438 << std::setw(7) << py <<
", "
439 << std::setw(7) << pz <<
"]";
448 const HepMC::GenEvent *
event,
bool status3)
450 double largestMass2 = -9.0e-30;
451 const HepMC::GenVertex *vertex = 0;
452 for(HepMC::GenEvent::vertex_const_iterator iter = event->vertices_begin();
453 iter !=
event->vertices_end(); ++iter) {
454 if ((*iter)->particles_in_size() < 2)
456 if ((*iter)->particles_out_size() < 1 ||
457 ((*iter)->particles_out_size() == 1 &&
458 (!(*(*iter)->particles_out_const_begin())->end_vertex() ||
459 !(*(*iter)->particles_out_const_begin())
460 ->end_vertex()->particles_out_size())))
463 double px = 0.0, py = 0.0, pz = 0.0, E = 0.0;
464 bool hadStatus3 =
false;
465 for(HepMC::GenVertex::particles_out_const_iterator iter2 =
466 (*iter)->particles_out_const_begin();
467 iter2 != (*iter)->particles_out_const_end(); ++iter2) {
468 hadStatus3 = hadStatus3 || (*iter2)->status() == 3;
469 px += (*iter2)->momentum().px();
470 py += (*iter2)->momentum().py();
471 pz += (*iter2)->momentum().pz();
472 E += (*iter2)->momentum().e();
474 if (status3 && !hadStatus3)
477 double mass2 = E * E - (px * px + py * py + pz * pz);
478 if (mass2 > largestMass2) {
480 largestMass2 = mass2;
488 HepMC::FourVector
time,
489 std::set<const HepMC::GenVertex*> &visited)
491 HepMC::FourVector curTime = vertex->position();
492 bool needsFixup = curTime.t() < time.t();
494 if (!visited.insert(vertex).second && !needsFixup)
498 vertex->set_position(time);
502 for(HepMC::GenVertex::particles_out_const_iterator iter =
503 vertex->particles_out_const_begin();
504 iter != vertex->particles_out_const_end(); ++iter) {
505 HepMC::GenVertex *endVertex = (*iter)->end_vertex();
513 std::set<const HepMC::GenVertex*> visited;
514 HepMC::FourVector zeroTime;
516 iter !=
event->vertices_end(); ++iter)
std::vector< std::string > comments
const HEPRUP * getHEPRUP() const
void fillEventInfo(HepMC::GenEvent *hepmc) const
std::pair< double, double > EBMUP
static void fixSubTree(HepMC::GenVertex *vertex, HepMC::FourVector time, std::set< const HepMC::GenVertex * > &visited)
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
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
static int skipWhitespace(std::istream &in)
tuple size
Write out results.
std::vector< std::pair< int, int > > ICOLUP