6 #include "HepMC/GenParticle.h"
7 #include "HepMC/GenVertex.h"
8 #include "HepMC/GenEvent.h"
9 #include "HepMC/SearchVector.h"
16 : m_position(position), m_id(id), m_weights(weights), m_event(0),
24 : m_position( invertex.position() ),
27 m_id( invertex.id() ),
28 m_weights( invertex.weights() ),
47 if ( !(*part1)->production_vertex() ) {
63 GenVertex::~GenVertex() {
73 m_position.
swap( other.m_position );
74 m_particles_in.swap( other.m_particles_in );
75 m_particles_out.swap( other.m_particles_out );
76 std::swap( m_id, other.m_id );
77 m_weights.
swap( other.m_weights );
78 std::swap( m_event, other.m_event );
79 std::swap( m_barcode, other.m_barcode );
123 if ( **ia != **ib )
return false;
134 if ( **ia != **ib )
return false;
142 return !( a == *this );
147 std::ios_base::fmtflags orig = ostr.flags();
148 std::streamsize prec = ostr.precision();
160 ostr.setf(std::ios::scientific, std::ios::floatfield);
161 ostr.setf(std::ios_base::showpos);
169 ostr.setf(std::ios::fmtflags(0), std::ios::floatfield);
170 ostr.unsetf(std::ios_base::showpos);
173 ostr <<
"GenVertex:";
196 ostr.setf(std::ios::scientific, std::ios::floatfield);
197 ostr.setf(std::ios_base::showpos);
205 ostr.setf(std::ios::fmtflags(0), std::ios::floatfield);
206 ostr.unsetf(std::ios_base::showpos);
209 ostr <<
"GenVertex:";
224 wgt !=
weights().
end(); wgt++ ) { ostr << *wgt <<
" "; }
233 ostr << m_particles_in.size();
234 }
else { ostr <<
" "; }
236 ostr << **part1 << std::endl;
243 ostr << m_particles_out.size();
244 }
else { ostr <<
" "; }
246 ostr << **part2 << std::endl;
250 ostr.precision(prec);
257 double sumpx = 0, sumpy = 0, sumpz = 0;
260 sumpx += (*part1)->momentum().px();
261 sumpy += (*part1)->momentum().py();
262 sumpz += (*part1)->momentum().pz();
266 sumpx -= (*part2)->momentum().px();
267 sumpy -= (*part2)->momentum().py();
268 sumpz -= (*part2)->momentum().pz();
270 return sqrt( sumpx*sumpx + sumpy*sumpy + sumpz*sumpz );
274 if ( !inparticle )
return;
280 m_particles_in.push_back( inparticle );
285 if ( !outparticle )
return;
291 m_particles_out.push_back( outparticle );
305 if ( !particle )
return 0;
319 if ( !particle )
return;
325 if ( !particle )
return;
333 if ( m_particles_out.empty() && m_particles_in.empty() )
return;
337 for ( std::vector<GenParticle*>::iterator part1 = m_particles_out.begin();
338 part1 != m_particles_out.end(); ) {
339 if ( !(*part1)->end_vertex() ) {
342 (*part1)->set_production_vertex_(0);
346 m_particles_out.clear();
351 for ( std::vector<GenParticle*>::iterator part2 = m_particles_in.begin();
352 part2 != m_particles_in.end(); ) {
353 if ( !(*part2)->production_vertex() ) {
356 (*part2)->set_end_vertex_(0);
360 m_particles_in.clear();
374 if ( the_bar_code >0 ) {
375 std::cerr <<
"GenVertex::suggest_barcode WARNING, vertex bar codes"
376 <<
"\n MUST be negative integers. Positive integers "
377 <<
"\n are reserved for particles only. Your suggestion "
378 <<
"\n has been rejected." << std::endl;
381 bool success =
false;
396 if ( orig_evt != new_evt ) {
403 if ( !(*part1)->production_vertex() ) {
406 (*part1)->barcode() );
414 (*part2)->barcode() );
440 std::ostream& operator<<( std::ostream& ostr,
const GenVertex& vtx ) {
442 else ostr <<
"Address " << &vtx;
446 << vtx.position().y() <<
","
447 << vtx.position().z() <<
","
448 << vtx.position().t();
449 }
else { ostr << 0; }
450 ostr <<
" #in:" << vtx.particles_in_size()
451 <<
" #out:" << vtx.particles_out_size();
462 GenVertex::edge_iterator::edge_iterator() : m_vertex(0), m_range(family),
463 m_is_inparticle_iter(false), m_is_past_end(true)
466 GenVertex::edge_iterator::edge_iterator(
const GenVertex& vtx,
468 m_vertex(&vtx), m_range(family)
482 if ( range == descendants || range == children ) m_range = children;
483 if ( range == ancestors || range == parents ) m_range = parents;
485 if ( m_vertex->m_particles_in.empty() &&
486 m_vertex->m_particles_out.empty() ) {
488 m_is_inparticle_iter =
false;
489 m_is_past_end =
true;
490 }
else if ( m_range == parents && m_vertex->m_particles_in.empty() ){
492 m_is_inparticle_iter =
true;
493 m_is_past_end =
true;
494 }
else if ( m_range == children && m_vertex->m_particles_out.empty() ){
496 m_is_inparticle_iter =
false;
497 m_is_past_end =
true;
498 }
else if ( m_range == children ) {
500 m_set_iter = m_vertex->m_particles_out.begin();
501 m_is_inparticle_iter =
false;
502 m_is_past_end =
false;
503 }
else if ( m_range == family && m_vertex->m_particles_in.empty() ) {
506 m_set_iter = m_vertex->m_particles_out.begin();
507 m_is_inparticle_iter =
false;
508 m_is_past_end =
false;
511 m_set_iter = m_vertex->m_particles_in.begin();
512 m_is_inparticle_iter =
true;
513 m_is_past_end =
false;
521 GenVertex::edge_iterator::~edge_iterator() {}
525 m_vertex = p.m_vertex;
527 m_set_iter = p.m_set_iter;
528 m_is_inparticle_iter = p.m_is_inparticle_iter;
529 m_is_past_end = p.m_is_past_end;
534 if ( !m_vertex || m_is_past_end )
return 0;
542 if ( m_is_past_end )
return *
this;
545 if ( m_range == family && m_is_inparticle_iter &&
546 m_set_iter == m_vertex->m_particles_in.end() ) {
549 m_set_iter = m_vertex->m_particles_out.begin();
550 m_is_inparticle_iter =
false;
551 }
else if ( m_range == parents &&
552 m_set_iter == m_vertex->m_particles_in.end() ) {
555 m_is_past_end =
true;
560 if( m_is_inparticle_iter ) {
563 if ( m_set_iter == m_vertex->m_particles_in.end() ) {
565 m_is_past_end =
true;
570 if ( m_set_iter == m_vertex->m_particles_out.end() ) {
572 m_is_past_end =
true;
586 if ( **
this && (**this)->end_vertex() == m_vertex )
return true;
591 if ( **
this && (**this)->production_vertex() == m_vertex )
return true;
596 if ( range == children )
return m_particles_out.size();
597 if ( range == parents )
return m_particles_in.size();
598 if ( range == family )
return m_particles_out.size()
599 + m_particles_in.size();
607 GenVertex::vertex_iterator::vertex_iterator()
608 : m_vertex(0), m_range(), m_visited_vertices(0), m_it_owns_set(0),
609 m_recursive_iterator(0)
612 GenVertex::vertex_iterator::vertex_iterator(
GenVertex& vtx_root,
614 : m_vertex(&vtx_root), m_range(range)
618 m_visited_vertices =
new std::set<const GenVertex*>;
620 m_visited_vertices->insert( m_vertex );
621 m_recursive_iterator = 0;
625 m_edge != m_vertex->
edges_end( m_range )) ++*
this;
628 GenVertex::vertex_iterator::vertex_iterator(
GenVertex& vtx_root,
629 IteratorRange range, std::set<const HepMC::GenVertex*>& visited_vertices ) :
630 m_vertex(&vtx_root), m_range(range),
631 m_visited_vertices(&visited_vertices), m_it_owns_set(0),
632 m_recursive_iterator(0)
642 m_edge != m_vertex->
edges_end( m_range )) ++*
this;
646 : m_vertex(0), m_visited_vertices(0), m_it_owns_set(0),
647 m_recursive_iterator(0)
652 GenVertex::vertex_iterator::~vertex_iterator() {
653 if ( m_recursive_iterator )
delete m_recursive_iterator;
654 if ( m_it_owns_set )
delete m_visited_vertices;
667 if ( m_recursive_iterator )
delete m_recursive_iterator;
668 m_recursive_iterator = 0;
669 if ( m_it_owns_set )
delete m_visited_vertices;
670 m_visited_vertices = 0;
673 m_vertex = v_iter.m_vertex;
674 m_range = v_iter.m_range;
675 if ( v_iter.m_it_owns_set ) {
679 new std::set<const GenVertex*>(*v_iter.m_visited_vertices);
682 m_visited_vertices = v_iter.m_visited_vertices;
689 m_edge = v_iter.m_edge;
690 copy_recursive_iterator_( v_iter.m_recursive_iterator );
699 if ( m_recursive_iterator )
return **m_recursive_iterator;
705 if ( m_vertex )
return m_vertex;
713 if ( !m_vertex )
return *
this;
715 if ( m_edge == m_vertex->edges_end( m_range ) ) {
722 if ( follow_edge_() ) {
731 if ( m_recursive_iterator ) {
732 ++(*m_recursive_iterator);
733 if ( **m_recursive_iterator ) {
736 delete m_recursive_iterator;
737 m_recursive_iterator = 0;
746 if ( m_edge == m_vertex->edges_end( m_range ) )
return *
this;
760 std::set<const HepMC::GenVertex*>& visited_vertices ) {
767 if ( m_recursive_iterator )
delete m_recursive_iterator;
768 m_recursive_iterator = 0;
769 if ( m_it_owns_set )
delete m_visited_vertices;
770 m_visited_vertices = 0;
771 m_it_owns_set =
false;
773 m_vertex = v_iter.m_vertex;
774 m_range = v_iter.m_range;
775 m_visited_vertices = &visited_vertices;
776 m_it_owns_set =
false;
777 m_edge = v_iter.m_edge;
778 copy_recursive_iterator_( v_iter.m_recursive_iterator );
789 if ( m_recursive_iterator || !m_vertex || !*m_edge )
return 0;
795 if ( m_range <= family && m_it_owns_set == 0 )
return 0;
800 if ( (*m_edge)->production_vertex() ==
801 (*m_edge)->end_vertex() )
return 0;
805 (*m_edge)->production_vertex() :
806 (*m_edge)->end_vertex() );
809 if ( !vtx || !(m_visited_vertices->insert(vtx).second) )
return 0;
812 *m_visited_vertices);
814 return **m_recursive_iterator;
823 if ( !recursive_v_iter )
return;
825 m_recursive_iterator->m_vertex = recursive_v_iter->m_vertex;
826 m_recursive_iterator->m_range = recursive_v_iter->m_range;
827 m_recursive_iterator->m_visited_vertices = m_visited_vertices;
828 m_recursive_iterator->m_it_owns_set = 0;
829 m_recursive_iterator->m_edge = recursive_v_iter->m_edge;
830 m_recursive_iterator->copy_recursive_iterator_(
831 recursive_v_iter->m_recursive_iterator );
838 GenVertex::particle_iterator::particle_iterator() {}
840 GenVertex::particle_iterator::particle_iterator(
GenVertex& vertex_root,
844 if ( range <= family ) {
849 m_vertex_iterator.range() );
854 GenVertex::particle_iterator::particle_iterator(
859 GenVertex::particle_iterator::~particle_iterator() {}
864 m_vertex_iterator = p_iter.m_vertex_iterator;
865 m_edge = p_iter.m_edge;
879 }
else if ( *m_vertex_iterator ) {
882 if ( !*(++m_vertex_iterator) )
return *
this;
884 m_vertex_iterator.range() );
904 if ( !*m_edge )
return *(++*
this);
908 if ( m_vertex_iterator.range() == relatives &&
909 m_edge.is_parent() &&
910 (*m_edge)->production_vertex() )
return *(++*
this);
void convert_position(const double &)
vertex_iterator & operator++(void)
Pre-fix increment.
GenVertex * follow_edge_()
non-null if recursive iter. created
int barcode() const
unique identifier
edge_iterator edges_end(IteratorRange) const
end range
double z() const
return z
bool is_parent() const
true if parent of root vtx
std::vector< HepMC::GenParticle * >::const_iterator particles_in_const_iterator
const iterator for incoming particles
bool set_barcode(GenParticle *p, int suggested_barcode=false)
set the barcode - intended for use by GenParticle
GenParticle * remove_particle(GenParticle *particle)
remove a particle
edge_iterator edges_begin(IteratorRange range=family) const
begin range
void print(std::ostream &ostr=std::cout) const
print vertex information
void add_particle_in(GenParticle *inparticle)
add incoming particle
GenParticle * operator*(void) const
return a pointer to a particle
void copy_with_own_set(const vertex_iterator &v_iter, std::set< const HepMC::GenVertex * > &visited_vertices)
intended for internal use only.
particles_out_const_iterator particles_out_const_end() const
end iteration of outgoing particles
std::vector< HepMC::GenParticle * >::const_iterator particles_out_const_iterator
const iterator for outgoing particles
bool suggest_barcode(int the_bar_code)
In general there is no reason to "suggest_barcode".
edge_iterator & operator++(void)
Pre-fix increment.
void remove_barcode(GenParticle *p)
intended for use by GenParticle
vertex_iterator & operator=(const vertex_iterator &)
make a copy
double y() const
return y
GenVertex * production_vertex() const
pointer to the production vertex
void set_barcode_(int the_bar_code)
set identifier
GenVertex contains information about decay vertices.
std::vector< double >::const_iterator const_iterator
const iterator for the weight container
bool is_child() const
true if child of root vtx
void swap(FourVector &other)
swap
The GenEvent class is the core of HepMC.
bool operator==(const GenVertex &a) const
equality
void remove_particle_out(GenParticle *)
for internal use only - remove particle from outgoing list
void add_particle_out(GenParticle *outparticle)
add outgoing particle
GenVertex * operator*(void) const
return a pointer to a vertex
particles_in_const_iterator particles_in_const_end() const
end iteration of incoming particles
double check_momentum_conservation() const
|Sum (three_mom_in-three_mom_out)|
bool operator!=(const GenVertex &a) const
inequality
void change_parent_event_(GenEvent *evt)
for use with swap
double x() const
return x
GenEvent * parent_event() const
pointer to the event that owns this vertex
void set_production_vertex_(GenVertex *productionvertex=0)
set production vertex - for internal use only
int particles_out_size() const
number of outgoing particles
void remove_particle_in(GenParticle *)
for internal use only - remove particle from incoming list
particles_out_const_iterator particles_out_const_begin() const
begin iteration of outgoing particles
edge_iterator & operator=(const edge_iterator &p)
make a copy
particle_iterator & operator++(void)
Pre-fix increment.
WeightContainer & weights()
direct access to the weights container is allowed.
const FourVector & position() const
vertex position and time
void set_parent_event_(GenEvent *evt)
set parent event
FourVector is a simple representation of a physics 4 vector.
iterator end()
end of the weight container
GenVertex * end_vertex() const
pointer to the decay vertex
IteratorRange
type of iteration
std::vector< HepMC::GenParticle * >::iterator already_in_vector(std::vector< HepMC::GenParticle * > *, GenParticle *)
returns true if GenParticle is in the vector
GenParticle * advance_to_first_()
"first" particle
int edges_size(IteratorRange range=family) const
size
Container for the Weights associated with an event or vertex.
void copy_recursive_iterator_(const vertex_iterator *recursive_v_iter)
copy recursive iterator
GenVertex(const FourVector &position=FourVector(0, 0, 0, 0), int id=0, const WeightContainer &weights=std::vector< double >())
default constructor
particles_in_const_iterator particles_in_const_begin() const
begin iteration of incoming particles
void swap(WeightContainer &other)
swap
int particles_in_size() const
number of incoming particles
GenParticle * operator*(void) const
return a pointer to a particle
void delete_adopted_particles()
for internal use only
void swap(GenVertex &other)
swap
double t() const
return t
void set_end_vertex_(GenVertex *decayvertex=0)
set decay vertex - for internal use only
particle_iterator & operator=(const particle_iterator &)
make a copy
size_type size() const
size of weight container
The GenParticle class contains information about generated particles.
GenVertex & operator=(const GenVertex &invertex)
shallow