11 #include "HepMC/IO_AsciiParticles.h"
12 #include "HepMC/GenEvent.h"
13 #include "HepMC/Version.h"
19 m_mode(mode), m_finished_first_event_io(0)
21 if(std::string(filename) == std::string(
"cout")) {
22 m_outstream = &(std::cout);
25 m_file =
new std::fstream(filename, mode);
27 if ( (m_mode&std::ios::out && m_mode&std::ios::in) ||
28 (m_mode&std::ios::app && m_mode&std::ios::in) ) {
29 std::cerr <<
"IO_AsciiParticles::IO_AsciiParticles Error, open of file requested "
30 <<
"of input AND output type. Not allowed. Closing file."
40 m_outstream->precision(m_precision);
42 m_outstream->setf(std::ios::dec,std::ios::basefield);
43 m_outstream->setf(std::ios::scientific,std::ios::floatfield);
46 IO_AsciiParticles::~IO_AsciiParticles() {
54 ostr <<
"IO_AsciiParticles: formated ascii file IO for eye and machine reading.\n"
55 <<
"\tFile openmode: " << m_mode
56 <<
" file state: " << m_outstream->rdstate()
57 <<
" bad:" << (m_outstream->rdstate()&std::ios::badbit)
58 <<
" eof:" << (m_outstream->rdstate()&std::ios::eofbit)
59 <<
" fail:" << (m_outstream->rdstate()&std::ios::failbit)
60 <<
" good:" << (m_outstream->rdstate()&std::ios::goodbit) << std::endl;
67 if ( !evt || !m_outstream )
return;
68 if ( !(m_mode&std::ios::out) ) {
69 std::cerr <<
"HepMC::IO_AsciiParticles::write_event "
70 <<
" attempt to write to input file." << std::endl;
75 if ( !m_finished_first_event_io ) {
76 m_finished_first_event_io = 1;
77 *m_outstream <<
"0 Run HepMC::IO_AsciiParticles eye-readable events output"
79 *m_outstream <<
"# HepMC::Version " <<
versionName() << std::endl;
81 " # stat pdg moth1 px py pz energy mass eta"
87 *m_outstream << evt->
event_number() <<
" Event" << std::endl;
96 output( (
int)random_states.size() );
97 for ( std::vector<long int>::iterator rs = random_states.begin();
98 rs != random_states.end(); ++rs ) {
109 int nparticles=0, imoth=0, ip=0, istati;
111 *m_outstream << evt->
particles_size() <<
" particles" << std::endl;
118 istati = (*part)->status();
119 if( (*part)->end_vertex() && istati == 1) {
120 std::cout <<
"final particle with end vertex!" << std::endl;
124 orig = (*part)->production_vertex();
130 part1 != part; part1++ ) {
132 if( (*part1)->end_vertex() == orig ) { ifound =
true;
break; }
134 if(!ifound) imoth = 0;
137 m_outstream->width(4);
138 *m_outstream << ip <<
" ";
140 m_outstream->width(3);
141 *m_outstream << istati <<
" ";
143 m_outstream->width(5);
144 *m_outstream << (*part)->pdg_id() <<
" ";
146 m_outstream->width(3);
147 *m_outstream << imoth <<
" ";
149 if((*part)->momentum().px() >= 0.) *m_outstream <<
" ";
150 *m_outstream << (*part)->momentum().px() <<
" ";
151 if((*part)->momentum().py() >= 0.) *m_outstream <<
" ";
152 *m_outstream << (*part)->momentum().py() <<
" ";
153 if((*part)->momentum().pz() >= 0.) *m_outstream <<
" ";
154 *m_outstream << (*part)->momentum().pz() <<
" "
155 << (*part)->momentum().e() <<
" ";
157 xmassi = (*part)->generatedMass();
158 if(fabs(xmassi) < 0.0001) xmassi =0.;
159 m_outstream->setf(std::ios::fixed);
160 m_outstream->precision(3);
161 m_outstream->width(8);
162 *m_outstream << xmassi <<
" ";
163 m_outstream->setf(std::ios::scientific,std::ios::floatfield);
164 m_outstream->precision(m_precision);
166 m_outstream->setf(std::ios::fixed);
167 m_outstream->precision(3);
168 m_outstream->width(6);
169 etai = (*part)->momentum().eta();
170 if(etai > 999.)etai = 999.;
171 if(etai < -999.)etai = -999.;
172 *m_outstream << etai << std::endl;
173 m_outstream->setf(std::ios::scientific,std::ios::floatfield);
174 m_outstream->precision(m_precision);
185 <<
"IO_AsciiParticles::fill_next_event error - passed null event."
191 std::cerr <<
"HepMC::IO_AsciiParticles::fill_next_event "
192 <<
" no file for input" << std::endl;
193 if ( !(m_mode&std::ios::in) ) {
194 std::cerr <<
"HepMC::IO_AsciiParticles::fill_next_event "
195 <<
" attempt to read from output file" << std::endl;
198 std::cerr <<
"IO_AsciiParticles input is not yet implemented" << std::endl;
204 if ( !m_outstream )
return;
205 if ( !(m_mode&std::ios::out) ) {
206 std::cerr <<
"HepMC::IO_AsciiParticles::write_particle_data_table "
207 <<
" attempt to write to input file." << std::endl;
213 *m_outstream <<
"\n" <<
"HepMC::IO_AsciiParticles-COMMENT\n";
214 *m_outstream << comment << std::endl;
IO_AsciiParticles(const char *filename="IO_AsciiParticles.dat", std::ios::openmode mode=std::ios::out)
constructor requiring a file name and std::ios mode
int barcode() const
unique identifier
bool fill_next_event(GenEvent *evt)
get the next event
int particles_size() const
how many particle barcodes exist?
bool write_end_listing()
write end tag
particle_const_iterator particles_begin() const
begin particle iteration
GenVertex contains information about decay vertices.
std::vector< double >::const_iterator const_iterator
const iterator for the weight container
The GenEvent class is the core of HepMC.
GenVertex * signal_process_vertex() const
pointer to the vertex containing the signal process
void write_event(const GenEvent *evt)
write this event
iterator begin()
begining of the weight container
void write_comment(const std::string comment)
std::string versionName()
return HepMC version
WeightContainer & weights()
direct access to WeightContainer
int vertices_size() const
how many vertex barcodes exist?
particle_const_iterator particles_end() const
end particle iteration
iterator end()
end of the weight container
int event_number() const
event number
int signal_process_id() const
unique signal process id
void print(std::ostream &ostr=std::cout) const
write to ostr
const std::vector< long > & random_states() const
vector of integers containing information about the random state
double event_scale() const
energy scale, see hep-ph/0109068
size_type size() const
size of weight container
double alphaQCD() const
QCD coupling, see hep-ph/0109068.