117 std::ostringstream out;
121 out.precision( std::numeric_limits<double>::digits10 + 1 );
123 out.setf(std::ios::dec,std::ios::basefield);
124 out.setf(std::ios::scientific,std::ios::floatfield);
126 long evt_vertices_size=evt->vertices().size();
127 std::shared_ptr<HepMC3::DoubleAttribute> A_alphaQCD=evt->attribute<HepMC3::DoubleAttribute>(
HepMCStr::alphaQCD);
128 double evt_alphaQCD=(A_alphaQCD?(A_alphaQCD->value()):0.0);
129 std::shared_ptr<HepMC3::DoubleAttribute> A_alphaQED=evt->attribute<HepMC3::DoubleAttribute>(
HepMCStr::alphaQED);
130 double evt_alphaQED=(A_alphaQED?(A_alphaQED->value()):0.0);
131 std::shared_ptr<HepMC3::DoubleAttribute> A_event_scale=evt->attribute<HepMC3::DoubleAttribute>(
HepMCStr::event_scale);
132 double evt_event_scale=(A_event_scale?(A_event_scale->value()):0.0);
133 std::shared_ptr<HepMC3::VectorLongIntAttribute> A_random_states=evt->attribute<HepMC3::VectorLongIntAttribute>(
HepMCStr::random_states);
134 std::vector<long int> random_states=(A_random_states?(A_random_states->value()):std::vector<long int>());
135 long random_states_size=random_states.size();
136 out <<
"# -- GenEvent -->\n";
137 out <<
"#" << evt->event_number()
138 <<
" " << evt_event_scale
139 <<
" " << evt_alphaQCD
140 <<
" " << evt_alphaQED
143 <<
" " << evt_vertices_size
144 <<
" " << random_states_size
147 std::copy( random_states.begin(), random_states.end(), std::ostream_iterator<long int>(out,
" ") );
148 out << evt->weights().size() <<
"\n";
151 std::copy( evt->weights().begin(), evt->weights().end(), std::ostream_iterator<double>(out,
" ") );
154 out <<
"#-- particles --\n";
155 for (
const auto& p: *evt) {
160 std::ostringstream buf;
161 buf.precision( std::numeric_limits<float>::digits10 + 1 );
162 buf.setf(std::ios::dec,std::ios::basefield);
163 buf.setf(std::ios::scientific,std::ios::floatfield);
165 const float px =
static_cast<float>(mom.px());
166 const float py =
static_cast<float>(mom.py());
167 const float pz =
static_cast<float>(mom.pz());
168 const float m =
static_cast<float>(mom.m());
169 const float e =
static_cast<float>(std::sqrt( std::pow( px, 2 ) + std::pow( py, 2 ) + std::pow( pz, 2 ) + std::pow( m, 2 ) ) );
170 buf << px <<
" " << py <<
" " << pz <<
" " << e <<
" " << m <<
"\n";
174 out <<
"# "<< p->status()
175 <<
" " << pol.theta()
177 <<
" " << ( p->end_vertex() ?
HepMC::barcode(p->end_vertex()) : 0 )
183 out <<
"#-- vertices -- \n";
184 for (
const auto& v: evt->vertices()) {
188 std::ostringstream buf;
189 buf.precision( std::numeric_limits<float>::digits10 + 1 );
190 buf.setf(std::ios::dec,std::ios::basefield);
191 buf.setf(std::ios::scientific,std::ios::floatfield);
193 buf << pos.x() <<
" " << pos.y() <<
" " << pos.z() <<
" " << pos.t() <<
"\n";
197 std::string svertexeights(
"1.0");
198 auto vertexeights=v->attribute<HepMC3::VectorDoubleAttribute>(
HepMCStr::weights);
199 if (vertexeights) vertexeights->to_string(svertexeights);
200 out << svertexeights;
204 out <<
"#<-- GenEvent --\n";
206 (*m_ioBackend) << out.str() << std::flush;
207 return StatusCode::SUCCESS;
217 std::string protocol =
"ascii";
218 std::string fileName =
"hepmc.genevent.txt";
229 std::string::size_type protocolPos = url.find(
s_protocolSep);
231 if ( std::string::npos != protocolPos ) {
232 protocol = url.substr( 0, protocolPos );
233 fileName = url.substr( protocolPos+1, std::string::npos );
240 std::transform( protocol.begin(), protocol.end(), protocol.begin(), [](
unsigned char c){ return std::tolower(c); } );
241 if (
"ascii" == protocol ) {
242 m_ioBackend =
new std::ofstream( fileName.c_str(), std::ios::out | std::ios::trunc );
245 ATH_MSG_WARNING(
"UNKNOWN protocol [" << protocol <<
"] !!" <<
endmsg <<
"Will use [ascii] instead...");
247 m_ioBackend =
new std::ofstream( fileName.c_str(), std::ios::out | std::ios::trunc );
249 ATH_MSG_DEBUG(
"Using protocol [" << protocol <<
"] and write to ["<< fileName <<
"]");