6 #include "HepMC/IO_HEPEVT.h"
7 #include "HepMC/GenEvent.h"
12 IO_HEPEVT::IO_HEPEVT() : m_trust_mothers_before_daughters(1),
13 m_trust_both_mothers_and_daughters(0),
14 m_print_inconsistency_errors(1),
15 m_trust_beam_particles(true)
18 IO_HEPEVT::~IO_HEPEVT(){}
20 void IO_HEPEVT::print( std::ostream& ostr )
const {
21 ostr <<
"IO_HEPEVT: reads an event from the FORTRAN HEPEVT "
23 <<
" trust_mothers_before_daughters = "
24 << m_trust_mothers_before_daughters
25 <<
" trust_both_mothers_and_daughters = "
26 << m_trust_both_mothers_and_daughters
27 <<
", print_inconsistency_errors = "
28 << m_print_inconsistency_errors << std::endl;
31 bool IO_HEPEVT::fill_next_event(
GenEvent* evt ) {
49 <<
"IO_HEPEVT::fill_next_event error - passed null event."
59 std::vector<GenParticle*> hepevt_particle(
60 HEPEVT_Wrapper::number_entries()+1 );
61 hepevt_particle[0] = 0;
62 for (
int i1 = 1; i1 <= HEPEVT_Wrapper::number_entries(); ++i1 ) {
63 hepevt_particle[i1] = build_particle(i1);
65 std::set<GenVertex*> new_vertices;
69 if( trust_beam_particles() ) {
74 for (
int i = 1; i <= HEPEVT_Wrapper::number_entries(); ++i ) {
82 if ( m_trust_mothers_before_daughters ||
83 m_trust_both_mothers_and_daughters ) {
84 build_production_vertex( i, hepevt_particle, evt );
89 if ( !m_trust_mothers_before_daughters ||
90 m_trust_both_mothers_and_daughters ) {
91 build_end_vertex( i, hepevt_particle, evt );
99 for (
int i3 = 1; i3 <= HEPEVT_Wrapper::number_entries(); ++i3 ) {
100 if ( !hepevt_particle[i3]->end_vertex() &&
101 !hepevt_particle[i3]->production_vertex() ) {
110 void IO_HEPEVT::write_event(
const GenEvent* evt ) {
120 std::vector<GenParticle*> index_to_particle(
121 HEPEVT_Wrapper::max_number_entries()+1 );
122 index_to_particle[0]=0;
123 std::map<GenParticle*,int> particle_to_index;
124 int particle_counter=0;
130 = (*v)->particles_in_const_begin();
131 p1 != (*v)->particles_in_const_end(); ++p1 ) {
133 if ( particle_counter >
134 HEPEVT_Wrapper::max_number_entries() )
break;
135 index_to_particle[particle_counter] = *p1;
136 particle_to_index[*p1] = particle_counter;
141 = (*v)->particles_out_const_begin();
142 p2 != (*v)->particles_out_const_end(); ++p2 ) {
143 if ( !(*p2)->end_vertex() ) {
145 if ( particle_counter >
146 HEPEVT_Wrapper::max_number_entries() ) {
149 index_to_particle[particle_counter] = *p2;
150 particle_to_index[*p2] = particle_counter;
154 if ( particle_counter > HEPEVT_Wrapper::max_number_entries() ) {
155 particle_counter = HEPEVT_Wrapper::max_number_entries();
159 HEPEVT_Wrapper::set_event_number( evt->
event_number() );
160 HEPEVT_Wrapper::set_number_entries( particle_counter );
161 for (
int i = 1; i <= particle_counter; ++i ) {
162 HEPEVT_Wrapper::set_status( i, index_to_particle[i]->status() );
163 HEPEVT_Wrapper::set_id( i, index_to_particle[i]->pdg_id() );
164 FourVector m = index_to_particle[i]->momentum();
165 HEPEVT_Wrapper::set_momentum( i, m.
px(), m.
py(), m.
pz(), m.
e() );
166 HEPEVT_Wrapper::set_mass( i, index_to_particle[i]->generatedMass() );
169 if ( index_to_particle[i]->production_vertex() &&
170 index_to_particle[i]->production_vertex()->particles_in_size()) {
172 production_vertex()->position();
173 HEPEVT_Wrapper::set_position( i, p.
x(), p.
y(), p.
z(), p.
t() );
174 int num_mothers = index_to_particle[i]->production_vertex()->
176 int first_mother = find_in_map( particle_to_index,
177 *(index_to_particle[i]->
178 production_vertex()->
179 particles_in_const_begin()));
180 int last_mother = first_mother + num_mothers - 1;
181 if ( first_mother == 0 ) last_mother = 0;
182 HEPEVT_Wrapper::set_parents( i, first_mother, last_mother );
184 HEPEVT_Wrapper::set_position( i, 0, 0, 0, 0 );
185 HEPEVT_Wrapper::set_parents( i, 0, 0 );
187 HEPEVT_Wrapper::set_children( i, 0, 0 );
191 void IO_HEPEVT::build_production_vertex(
int i,
192 std::vector<HepMC::GenParticle*>&
200 int mother = HEPEVT_Wrapper::first_parent(i);
202 while ( !prod_vtx && mother > 0 ) {
203 prod_vtx = hepevt_particle[mother]->end_vertex();
206 if ( ++mother > HEPEVT_Wrapper::last_parent(i) ) mother = 0;
211 FourVector prod_pos( HEPEVT_Wrapper::x(i), HEPEVT_Wrapper::y(i),
212 HEPEVT_Wrapper::z(i), HEPEVT_Wrapper::t(i)
214 if ( !prod_vtx && (HEPEVT_Wrapper::number_parents(i)>0
227 mother = HEPEVT_Wrapper::first_parent(i);
228 while ( prod_vtx && mother > 0 ) {
229 if ( !hepevt_particle[mother]->end_vertex() ) {
232 }
else if (hepevt_particle[mother]->end_vertex() != prod_vtx ) {
241 if ( m_print_inconsistency_errors ) std::cerr
242 <<
"HepMC::IO_HEPEVT: inconsistent mother/daugher "
243 <<
"information in HEPEVT event "
244 << HEPEVT_Wrapper::event_number()
245 <<
". \n I recommend you try "
246 <<
"inspecting the event first with "
247 <<
"\n\tHEPEVT_Wrapper::check_hepevt_consistency()"
248 <<
"\n This warning can be turned off with the "
249 <<
"IO_HEPEVT::print_inconsistency_errors switch."
252 if ( ++mother > HEPEVT_Wrapper::last_parent(i) ) mother = 0;
256 void IO_HEPEVT::build_end_vertex
257 (
int i, std::vector<HepMC::GenParticle*>& hepevt_particle,
GenEvent* evt )
265 int daughter = HEPEVT_Wrapper::first_child(i);
267 while ( !end_vtx && daughter > 0 ) {
268 end_vtx = hepevt_particle[daughter]->production_vertex();
270 if ( ++daughter > HEPEVT_Wrapper::last_child(i) ) daughter = 0;
274 if ( !end_vtx && HEPEVT_Wrapper::number_children(i)>0 ) {
282 daughter = HEPEVT_Wrapper::first_child(i);
283 while ( end_vtx && daughter > 0 ) {
284 if ( !hepevt_particle[daughter]->production_vertex() ) {
290 FourVector prod_pos( HEPEVT_Wrapper::x(daughter),
291 HEPEVT_Wrapper::y(daughter),
292 HEPEVT_Wrapper::z(daughter),
293 HEPEVT_Wrapper::t(daughter)
299 }
else if (hepevt_particle[daughter]->production_vertex()
306 if ( m_print_inconsistency_errors ) std::cerr
307 <<
"HepMC::IO_HEPEVT: inconsistent mother/daugher "
308 <<
"information in HEPEVT event "
309 << HEPEVT_Wrapper::event_number()
310 <<
". \n I recommend you try "
311 <<
"inspecting the event first with "
312 <<
"\n\tHEPEVT_Wrapper::check_hepevt_consistency()"
313 <<
"\n This warning can be turned off with the "
314 <<
"IO_HEPEVT::print_inconsistency_errors switch."
317 if ( ++daughter > HEPEVT_Wrapper::last_child(i) ) daughter = 0;
321 build_production_vertex( i, hepevt_particle, evt );
330 HEPEVT_Wrapper::py(index),
331 HEPEVT_Wrapper::pz(index),
332 HEPEVT_Wrapper::e(index) ),
333 HEPEVT_Wrapper::id(index),
334 HEPEVT_Wrapper::status(index) );
340 int IO_HEPEVT::find_in_map(
const std::map<HepMC::GenParticle*,int>& m,
342 std::map<GenParticle*,int>::const_iterator iter = m.find(p);
343 if ( iter == m.end() )
return 0;
double z() const
return z
std::vector< HepMC::GenParticle * >::const_iterator particles_in_const_iterator
const iterator for incoming particles
void add_particle_in(GenParticle *inparticle)
add incoming particle
std::vector< HepMC::GenParticle * >::const_iterator particles_out_const_iterator
const iterator for outgoing particles
double e() const
return E
double y() const
return y
void set_position(const FourVector &position=FourVector(0, 0, 0, 0))
set vertex position and time
void set_event_number(int eventno)
set event number
double px() const
return px
GenVertex * production_vertex() const
pointer to the production vertex
GenVertex contains information about decay vertices.
bool suggest_barcode(int the_bar_code)
In general there is no reason to "suggest_barcode".
The GenEvent class is the core of HepMC.
double pz() const
return pz
void add_particle_out(GenParticle *outparticle)
add outgoing particle
bool add_vertex(GenVertex *vtx)
adds to evt and adopts
vertex_const_iterator vertices_end() const
end vertex iteration
double x() const
return x
bool set_beam_particles(GenParticle *, GenParticle *)
set incoming beam particles
const FourVector & position() const
vertex position and time
FourVector is a simple representation of a physics 4 vector.
vertex_const_iterator vertices_begin() const
begin vertex iteration
GenVertex * end_vertex() const
pointer to the decay vertex
int event_number() const
event number
void setGeneratedMass(const double &m)
setGeneratedMass() is included for backwards compatibility with CLHEP HepMC
double py() const
return py
double t() const
return t
The GenParticle class contains information about generated particles.