10 #include "Pythia8/Pythia8ToHepMC.h"
11 #include "HepMC/GenEvent.h"
21 bool Pythia8ToHepMC::fill_next_event(
Pythia8::Event& pyev, GenEvent* evt,
26 std::cerr <<
"Pythia8ToHepMC::fill_next_event error - passed null event."
33 evt->set_event_number(ievnum);
34 m_internal_event_number = ievnum;
36 evt->set_event_number(m_internal_event_number);
37 ++m_internal_event_number;
41 double momFac = HepMC::Units::conversion_factor(HepMC::Units::GEV,
42 evt->momentum_unit());
43 double lenFac = HepMC::Units::conversion_factor(HepMC::Units::MM,
48 std::vector<GenParticle*> hepevt_particles( pyev.size() );
49 for (
int i = 1; i < pyev.size(); ++i) {
52 hepevt_particles[i] =
new GenParticle(
53 FourVector( momFac * pyev[i].px(), momFac * pyev[i].py(),
54 momFac * pyev[i].pz(), momFac * pyev[i].e() ),
55 pyev[i].
id(), pyev.statusHepMC(i) );
56 hepevt_particles[i]->suggest_barcode(i);
57 hepevt_particles[i]->set_generated_mass( momFac * pyev[i].m() );
60 int colType = pyev[i].colType();
61 if (colType == 1 || colType == 2)
62 hepevt_particles[i]->set_flow(1, pyev[i].col());
63 if (colType == -1 || colType == 2)
64 hepevt_particles[i]->set_flow(2, pyev[i].acol());
69 evt->set_beam_particles( hepevt_particles[1], hepevt_particles[2] );
74 for (
int i = 1; i < pyev.size(); ++i) {
75 GenParticle *p = hepevt_particles[i];
78 std::vector<int> mothers = pyev.motherList(i);
79 unsigned int imother = 0;
81 if ( !mothers.empty() ) mother = mothers[imother];
82 GenVertex* prod_vtx = p->production_vertex();
83 while ( !prod_vtx && mother > 0 ) {
84 prod_vtx = hepevt_particles[mother]->end_vertex();
85 if ( prod_vtx ) prod_vtx->add_particle_out( p );
86 mother = ( ++imother < mothers.size() ) ? mothers[imother] : -1;
91 FourVector prod_pos( lenFac * pyev[i].xProd(), lenFac * pyev[i].yProd(),
92 lenFac * pyev[i].zProd(), lenFac * pyev[i].tProd() );
93 if ( !prod_vtx && ( mothers.size() > 0 || prod_pos != FourVector() ) ) {
94 prod_vtx =
new GenVertex();
95 prod_vtx->add_particle_out( p );
96 evt->add_vertex( prod_vtx );
100 if ( prod_vtx && prod_vtx->position() == FourVector() )
101 prod_vtx->set_position( prod_pos );
106 if ( !mothers.empty() ) mother = mothers[imother];
107 while ( prod_vtx && mother > 0 ) {
110 if ( !hepevt_particles[mother]->end_vertex() ) {
111 prod_vtx->add_particle_in( hepevt_particles[mother] );
118 }
else if (hepevt_particles[mother]->end_vertex() != prod_vtx ) {
119 if ( m_print_inconsistency ) std::cerr
120 <<
"HepMC::Pythia8ToHepMC: inconsistent mother/daugher "
121 <<
"information in Pythia8 event " << std::endl
122 <<
"i = " << i <<
" mother = " << mother
123 <<
"\n This warning can be turned off with the "
124 <<
"Pythia8ToHepMC::print_inconsistency switch." << std::endl;
128 mother = ( ++imother < mothers.size() ) ? mothers[imother] : -1;
133 bool doHadr = (pyset == 0) ? m_free_parton_warnings
134 : pyset->flag(
"HadronLevel:all") && pyset->flag(
"HadronLevel:Hadronize");
139 for (
int i = 1; i < pyev.size(); ++i) {
140 if ( !hepevt_particles[i]->end_vertex() &&
141 !hepevt_particles[i]->production_vertex() ) {
142 std::cerr <<
"hanging particle " << i << std::endl;
143 GenVertex* prod_vtx =
new GenVertex();
144 prod_vtx->add_particle_out( hepevt_particles[i] );
145 evt->add_vertex( prod_vtx );
149 if ( doHadr && m_free_parton_warnings ) {
150 if ( hepevt_particles[i]->pdg_id() == 21 &&
151 !hepevt_particles[i]->end_vertex() ) {
152 std::cerr <<
"gluon without end vertex " << i << std::endl;
153 if ( m_crash_on_problem ) exit(1);
155 if ( abs(hepevt_particles[i]->pdg_id()) <= 6 &&
156 !hepevt_particles[i]->end_vertex() ) {
157 std::cerr <<
"quark without end vertex " << i << std::endl;
158 if ( m_crash_on_problem ) exit(1);
165 if (m_store_pdf && pyinfo != 0) {
166 int id1pdf = pyinfo->id1pdf();
167 int id2pdf = pyinfo->id2pdf();
168 if ( m_convert_gluon_to_0 ) {
169 if (id1pdf == 21) id1pdf = 0;
170 if (id2pdf == 21) id2pdf = 0;
174 evt->set_pdf_info( PdfInfo( id1pdf, id2pdf, pyinfo->x1pdf(),
175 pyinfo->x2pdf(), pyinfo->QFac(), pyinfo->pdf1(), pyinfo->pdf2() ) );
179 if (m_store_proc && pyinfo != 0) {
180 evt->set_signal_process_id( pyinfo->code() );
181 evt->set_event_scale( pyinfo->QRen() );
182 if (evt->alphaQED() <= 0) evt->set_alphaQED( pyinfo->alphaEM() );
183 if (evt->alphaQCD() <= 0) evt->set_alphaQCD( pyinfo->alphaS() );
188 if (m_store_xsec && pyinfo != 0) {
191 pyinfo->sigmaErr() * 1e9);
192 evt->set_cross_section(xsec);
193 evt->weights().push_back( pyinfo->weight() );
void set_cross_section(double xs, double xs_err)
Set cross section and error in pb.
The GenCrossSection class stores the generated cross section.