12 #if ((__GNUC__*100)+__GNUC_MINOR__) >= 406
13 #pragma GCC diagnostic ignored "-Wshadow"
16 #include "HepMCInterface.h"
17 #include "HepMC/GenEvent.h"
20 #if ((__GNUC__*100)+__GNUC_MINOR__) >= 406
21 #pragma GCC diagnostic warning "-Wshadow"
30 I_Pythia8::I_Pythia8():
31 m_trust_mothers_before_daughters(true),
32 m_trust_both_mothers_and_daughters(false),
33 m_print_inconsistency_errors(true),
34 m_crash_on_problem(false),
35 m_freepartonwarnings(true),
36 m_convert_to_mev(false),
37 m_mom_scale_factor(1.),
38 m_internal_event_number(0) {;}
40 I_Pythia8::~I_Pythia8() {;}
48 bool I_Pythia8::fill_next_event(
Pythia8::Event& pyev, GenEvent* evt,
53 std::cerr <<
"I_Pythia8::fill_next_event error - passed null event."
60 evt->set_event_number(ievnum);
61 m_internal_event_number = ievnum;
63 evt->set_event_number(m_internal_event_number);
64 m_internal_event_number++;
68 #ifdef HEPMC_HAS_UNITS
69 set_convert_to_mev(
false);
71 set_convert_to_mev(
true);
76 std::vector<GenParticle*> hepevt_particles( pyev.size() );
78 for ( i = 1; i < pyev.size(); ++i ) {
83 istatus = pyev.statusHepMC(i);
87 hepevt_particles[i] =
new GenParticle(
88 FourVector( m_mom_scale_factor*pyev[i].p().px(),
89 m_mom_scale_factor*pyev[i].p().py(),
90 m_mom_scale_factor*pyev[i].p().pz(),
91 m_mom_scale_factor*pyev[i].p().e() ),
92 pyev[i].
id(), istatus );
93 hepevt_particles[i]->suggest_barcode(i);
96 int colType = pyev[i].colType();
97 if (colType == 1 || colType == 2)
98 hepevt_particles[i]->set_flow(1, pyev[i].col());
99 if (colType == -1 || colType == 2)
100 hepevt_particles[i]->set_flow(2, pyev[i].acol());
105 evt->set_beam_particles( hepevt_particles[1], hepevt_particles[2] );
111 for ( i = 1; i < pyev.size(); ++i ) {
114 if ( m_trust_mothers_before_daughters ||
115 m_trust_both_mothers_and_daughters ) {
116 GenParticle *p = hepevt_particles[i];
119 std::vector<int> mothers = pyev.motherList(i);
120 unsigned int imother = 0;
122 if ( !mothers.empty() ) mother = mothers[imother];
123 GenVertex* prod_vtx = p->production_vertex();
124 while ( !prod_vtx && mother > 0 ) {
125 prod_vtx = hepevt_particles[mother]->end_vertex();
126 if ( prod_vtx ) prod_vtx->add_particle_out( p );
128 if ( imother < mothers.size() ) mother = mothers[imother];
134 FourVector prod_pos( pyev[i].xProd(), pyev[i].yProd(),
135 pyev[i].zProd(), pyev[i].tProd() );
136 unsigned int nparents = mothers.size();
137 if ( !prod_vtx && ( nparents > 0 || prod_pos != FourVector() ) ) {
138 prod_vtx =
new GenVertex();
139 prod_vtx->add_particle_out( p );
140 evt->add_vertex( prod_vtx );
144 if ( prod_vtx && prod_vtx->position() == FourVector() )
145 prod_vtx->set_position( prod_pos );
150 if ( !mothers.empty() ) mother = mothers[imother];
151 while ( prod_vtx && mother > 0 ) {
154 if ( !hepevt_particles[mother]->end_vertex() ) {
155 prod_vtx->add_particle_in( hepevt_particles[mother] );
162 }
else if (hepevt_particles[mother]->end_vertex() != prod_vtx ) {
163 if ( m_print_inconsistency_errors ) std::cerr
164 <<
"HepMC::I_Pythia8: inconsistent mother/daugher "
165 <<
"information in Pythia8 event " << std::endl
166 <<
"i= " << i <<
" mother = " << mother
167 <<
"\n This warning can be turned off with the "
168 <<
"I_Pythia8::print_inconsistency_errors switch." << std::endl;
173 if ( imother < mothers.size() ) mother = mothers[imother];
179 std::cerr <<
"trust_daughters_before_mothers not implemented"
188 for ( i = 1; i < pyev.size(); ++i ) {
189 if ( !hepevt_particles[i]->end_vertex() &&
190 !hepevt_particles[i]->production_vertex() ) {
191 std::cerr <<
"hanging particle " << i << std::endl;
192 GenVertex* prod_vtx =
new GenVertex();
193 prod_vtx->add_particle_out( hepevt_particles[i] );
194 evt->add_vertex( prod_vtx );
198 if ( m_freepartonwarnings ) {
199 if ( hepevt_particles[i]->pdg_id() == 21 &&
200 !hepevt_particles[i]->end_vertex() ) {
201 std::cerr <<
"gluon without end vertex " << i << std::endl;
202 if ( m_crash_on_problem ) exit(1);
204 if ( abs(hepevt_particles[i]->pdg_id()) <= 6 &&
205 !hepevt_particles[i]->end_vertex() ) {
206 std::cerr <<
"quark without end vertex " << i << std::endl;
207 if ( m_crash_on_problem ) exit(1);
222 bool I_Pythia8::fill_next_event(
Pythia8::Pythia& pythia, GenEvent* evt,
223 int ievnum,
bool convertGluonTo0 ) {
226 bool doHadr = pythia.flag(
"HadronLevel:all") &&
227 pythia.flag(
"HadronLevel:Hadronize");
228 if (!doHadr) m_freepartonwarnings =
false;
231 bool result = fill_next_event( pythia.event, evt, ievnum );
235 put_pdf_info(evt, pythia, convertGluonTo0 );
238 evt->set_signal_process_id(pythia.info.code());
239 evt->set_event_scale(pythia.info.pTHat());
240 if (evt->alphaQED() <= 0) evt->set_alphaQED( pythia.info.alphaEM() );
241 if (evt->alphaQCD() <= 0) evt->set_alphaQCD( pythia.info.alphaS() );
245 evt->weights().push_back( pythia.info.weight() );
248 #ifdef HEPMC_HAS_CROSS_SECTION
251 pythia.info.sigmaErr() * 1e9);
252 evt->set_cross_section(xsec);
267 bool convertGluonTo0 ) {
270 int id1 = pythia.info.id1();
271 int id2 = pythia.info.id2();
272 if ( convertGluonTo0 ) {
273 if ( id1 == 21 ) id1 = 0;
274 if ( id2 == 21 ) id2 = 0;
278 double x1 = pythia.info.x1();
279 double x2 = pythia.info.x2();
280 double Q = pythia.info.QFac();
281 double pdf1 = pythia.info.pdf1();
282 double pdf2 = pythia.info.pdf2();
285 evt->set_pdf_info( PdfInfo( id1, id2, x1, x2, Q, pdf1, pdf2) ) ;
void set_cross_section(double xs, double xs_err)
Set cross section and error in pb.
The GenCrossSection class stores the generated cross section.