12 #include "HepMC3/Version.h"
29 m_buffer_size( 256*1024 ),
32 HEPMC3_WARNING(
"WriterAsciiHepMC2::WriterAsciiHepMC2: HepMC2 format is outdated. Please use HepMC3 format instead." )
37 HEPMC3_ERROR(
"WriterAsciiHepMC2: could not open output file: "<<filename )
42 m_file <<
"HepMC::IO_GenEvent-START_EVENT_LISTING" << std::endl;
52 m_buffer_size( 256*1024 ),
55 HEPMC3_WARNING(
"WriterAsciiHepMC2::WriterAsciiHepMC2: HepMC2 format is outdated. Please use HepMC3 format instead." )
58 (*m_stream) <<
"HepMC::Version " <<
version() << std::endl;
59 (*m_stream) <<
"HepMC::IO_GenEvent-START_EVENT_LISTING" << std::endl;
87 std::shared_ptr<IntAttribute> A_signal_process_vertex=evt.
attribute<
IntAttribute>(
"signal_process_vertex");
89 double event_scale=A_event_scale?(A_event_scale->value()):0.0;
90 double alphaQED=A_alphaQED?(A_alphaQED->value()):0.0;
91 double alphaQCD=A_alphaQCD?(A_alphaQCD->value()):0.0;
92 int signal_process_id=A_signal_process_id?(A_signal_process_id->value()):0;
93 int mpi=A_mpi?(A_mpi->value()):0;
94 int signal_process_vertex=A_signal_process_vertex?(A_signal_process_vertex->value()):0;
96 std::vector<long> m_random_states;
97 for (
int i=0; i<100; i++)
99 std::shared_ptr<IntAttribute> rs=evt.
attribute<
IntAttribute>(
"random_states"+std::to_string((
long long unsigned int)i));
101 m_random_states.push_back(rs->value());
105 std::vector<int> beams;
107 for(ConstGenVertexPtr v: evt.
vertices() )
109 for(ConstGenParticlePtr p: v->particles_in())
111 if (!p->production_vertex()) {
if (p->status()==4) beams.push_back(idbeam); idbeam++;}
112 else if (p->production_vertex()->id()==0) {
if (p->status()==4) beams.push_back(idbeam); idbeam++;}
114 for( ConstGenParticlePtr p: v->particles_out()) {
if (p->status()==4) beams.push_back(idbeam); idbeam++;}
119 if (beams.size()>0) idbeam1+=beams[0]+1;
120 if (beams.size()>1) idbeam2+=beams[1]+1;
128 signal_process_vertex,
135 for (
size_t q=0; q<m_random_states.size(); q++)
148 std::vector<std::string> names =
run_info()->weight_names();
149 for (
size_t q=0; q<evt.
weights().size(); q++)
170 for (
auto vt2: vt1.second )
174 bool status = vt2.second->to_string(st);
178 HEPMC3_WARNING(
"WriterAsciiHepMC2::write_event: problem serializing attribute: "<<vt1.first )
182 if (vt1.first==
"GenPdfInfo")
195 for(ConstGenVertexPtr v: evt.
vertices() )
197 int production_vertex = 0;
198 production_vertex=v->id();
200 for(ConstGenParticlePtr p: v->particles_in())
202 if (!p->production_vertex())
write_particle( p, production_vertex );
205 if (p->production_vertex()->id()==0)
write_particle( p, production_vertex );
208 for(ConstGenParticlePtr p: v->particles_out())
223 }
catch (
const std::bad_alloc& e) {
226 HEPMC3_WARNING(
"WriterAsciiHepMC2::allocate_buffer:"<<e.what()<<
" buffer size too large. Dividing by 2. New size: " <<
m_buffer_size )
232 HEPMC3_ERROR(
"WriterAsciiHepMC2::allocate_buffer: could not allocate buffer!" )
243 ret.reserve( s.length()*2 );
244 for ( std::string::const_iterator it = s.begin(); it != s.end(); ++it )
263 std::vector<double> weights;
264 for (
int i=0; i<100; i++)
266 std::shared_ptr<DoubleAttribute> rs=v->attribute<
DoubleAttribute>(
"weight"+std::to_string((
long long unsigned int)i));
268 weights.push_back(rs->value());
274 for(ConstGenParticlePtr p: v->particles_in())
276 if (!p->production_vertex()) orph++;
279 if (p->production_vertex()->id()==0)orph++;
298 m_cursor += sprintf(
m_cursor,
" %i %lu %lu",orph,v->particles_out().size(),weights.size());
352 if (p->end_vertex()->id()!=0)
353 ev=p->end_vertex()->id();
355 std::shared_ptr<DoubleAttribute> A_theta=p->attribute<
DoubleAttribute>(
"theta");
356 std:: shared_ptr<DoubleAttribute> A_phi=p->attribute<
DoubleAttribute>(
"phi");
365 std::shared_ptr<VectorIntAttribute> A_flows=p->attribute<
VectorIntAttribute>(
"flows");
368 std::vector<int> flowsv=A_flows->value();
369 int flowsize=flowsv.size();
371 for (
size_t k=0; k<flowsv.size(); k++)
m_cursor += sprintf(
m_cursor,
" %lu %i", k+1, flowsv.at(k));
375 std::shared_ptr<IntAttribute> A_flow1=p->attribute<
IntAttribute>(
"flow1");
376 std::shared_ptr<IntAttribute> A_flow2=p->attribute<
IntAttribute>(
"flow2");
377 std::shared_ptr<IntAttribute> A_flow3=p->attribute<
IntAttribute>(
"flow3");
379 if (A_flow1) flowsize++;
380 if (A_flow2) flowsize++;
381 if (A_flow3) flowsize++;
415 std::ofstream* ofs =
dynamic_cast<std::ofstream*
>(
m_stream);
416 if (ofs && !ofs->is_open())
return;
418 (*m_stream) <<
"HepMC::IO_GenEvent-END_EVENT_LISTING" << std::endl << std::endl;
419 if (ofs) ofs->close();
424 if (prec < 2 || prec > 24)
return;
434 if (size < 256)
return;