11 #include "HepMC/GenEvent.h" 12 #include "HepMC/GenParticle.h" 13 #include "HepMC/GenVertex.h" 15 #include "HepMC/Data/GenEventData.h" 16 #include "HepMC/Search/FindParticles.h" 27 : m_event_number(0), m_momentum_unit(mu),
43 if( p->in_event() )
return;
51 if( !p->production_vertex() )
58 if( v->in_event() )
return;
68 p->m_end_vertex = v->m_this.lock();
73 p->m_production_vertex = v->m_this.lock();
79 if( !p || p->parent_event() != this )
return;
81 DEBUG( 30,
"GenEvent::remove_particle - called with particle: "<<p->id() );
84 end_vtx->remove_particle_in(p);
87 if( end_vtx->particles_in().size() == 0 )
remove_vertex(end_vtx);
92 prod_vtx->remove_particle_out(p);
95 if( prod_vtx->particles_out().size() == 0 )
remove_vertex(prod_vtx);
98 DEBUG( 30,
"GenEvent::remove_particle - erasing particle: " << p->id() )
104 vector<string> atts = p->attribute_names();
105 FOREACH(
string s, atts) {
106 p->remove_attribute(s);
112 #ifndef HEPMC_HAS_CXX0X_GCC_ONLY 113 vector<att_val_t> changed_attributes;
116 changed_attributes.clear();
118 FOREACH(
const att_val_t& vt2, vt1.second ) {
119 if( vt2.first > p->id() ) {
120 changed_attributes.push_back(vt2);
124 FOREACH(
att_val_t val, changed_attributes ) {
125 vt1.second.erase(val.first);
126 vt1.second[val.first-1] = val.second;
130 vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
133 changed_attributes.clear();
135 for ( std::map<
int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();vt2++){
136 if( (*vt2).first > p->id() ) {
137 changed_attributes.push_back(*vt2);
141 FOREACH(
att_val_t val, changed_attributes ) {
142 vt1.second.erase(val.first);
143 vt1.second[val.first-1] = val.second;
159 return (p1->id() > p2->id());
175 if( !v || v->parent_event() != this )
return;
177 DEBUG( 30,
"GenEvent::remove_vertex - called with vertex: "<<v->id() );
178 shared_ptr<GenVertex> null_vtx;
181 p->m_end_vertex.reset();
185 p->m_production_vertex.reset();
192 DEBUG( 30,
"GenEvent::remove_vertex - erasing vertex: " << v->id() )
198 vector<string> atts = v->attribute_names();
199 FOREACH(
string s, atts) {
200 v->remove_attribute(s);
206 #ifndef HEPMC_HAS_CXX0X_GCC_ONLY 207 vector<att_val_t> changed_attributes;
210 changed_attributes.clear();
212 FOREACH(
const att_val_t& vt2, vt1.second ) {
213 if( vt2.first < v->id() ) {
214 changed_attributes.push_back(vt2);
218 FOREACH(
att_val_t val, changed_attributes ) {
219 vt1.second.erase(val.first);
220 vt1.second[val.first+1] = val.second;
234 vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
237 changed_attributes.clear();
239 for ( std::map<
int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();vt2++){
240 if( (*vt2).first < v->id() ) {
241 changed_attributes.push_back(*vt2);
245 FOREACH(
att_val_t val, changed_attributes ) {
246 vt1.second.erase(val.first);
247 vt1.second[val.first+1] = val.second;
264 deque<GenVertexPtr> sorting;
269 if( !v || v->particles_in().size()==0 ) {
271 if(v2) sorting.push_back(v2);
276 unsigned int sorting_loop_count = 0;
277 unsigned int max_deque_size = 0;
281 while( !sorting.empty() ) {
283 if( sorting.size() > max_deque_size ) max_deque_size = sorting.size();
284 ++sorting_loop_count;
294 if( v2 && !v2->in_event() ) {
295 sorting.push_front(v2);
302 if( added )
continue;
305 if( !v->in_event() ) {
312 if( v2 && !v2->in_event() ) {
313 sorting.push_back(v2);
322 DEBUG( 6,
"GenEvent - particles sorted: " 323 <<this->
particles().size()<<
", max deque size: " 324 <<max_deque_size<<
", iterations: "<<sorting_loop_count )
368 if ( v->has_set_position() )
369 v->set_position( v->position() + delta );
399 map< string, map<int, shared_ptr<Attribute> > >::iterator i1 =
m_attributes.find(name);
402 map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(
id);
403 if( i2 == i1->second.end() )
return;
405 i1->second.erase(i2);
409 vector<string> results;
412 FOREACH(
const att_val_t& vt2, vt1.second ) {
413 if( vt2.first ==
id ) results.push_back( vt1.first );
444 data.
vertices.push_back( v->data() );
448 data.
links1.push_back( p->id() );
449 data.
links2.push_back( v_id );
453 data.
links1.push_back( v_id );
454 data.
links2.push_back( p->id() );
459 FOREACH(
const att_val_t& vt2, vt1.second ) {
463 bool status = vt2.second->to_string(st);
466 WARNING(
"GenEvent::write_data: problem serializing attribute: "<<vt1.first )
508 for(
unsigned int i=0; i<data.
links1.size(); ++i) {
517 for(
unsigned int i=0; i<data.
attribute_id.size(); ++i) {
525 #ifndef HEPMC_NO_DEPRECATED 557 std::map< string, std::map<int, shared_ptr<Attribute> > >::iterator i1 =
m_attributes.find(name);
560 return run_info()->attribute_as_string(name);
565 std::map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(
id);
566 if (i2 == i1->second.end() )
return string();
568 if( !i2->second )
return string();
571 i2->second->to_string(ret);
const std::vector< GenParticlePtr > & particles() const
Get list of particles (const)
Stores serializable particle information.
std::vector< std::string > attribute_string
Attribute serialized as string.
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
string attribute_as_string(const string &name, int id=0) const
Get attribute of any type as string.
void remove_particles(std::vector< GenParticlePtr > v)
Remove a set of particles.
void add_vertex(GenVertexPtr v)
Add vertex.
std::vector< int > links1
First id of the vertex links.
std::map< string, std::map< int, shared_ptr< Attribute > > > m_attributes
Map of event, particle and vertex attributes.
std::pair< GenParticlePtr, GenParticlePtr > beam_particles() const
Get first two particles of the event_pos() vertex.
shared_ptr< T > m_data
Shared pointer.
bool valid_beam_particles() const
Test to see if we have exactly two particles in event_pos() vertex.
void set_event_number(int num)
Set event number.
int event_number() const
Get event number.
void remove_attribute(const string &name, int id=0)
Remove attribute.
SmartPointer< class GenParticle > GenParticlePtr
Smart pointer to GenParticle.
const std::map< string, std::map< int, shared_ptr< Attribute > > > & attributes() const
Get list of attributes.
void set_units(Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
Change event units Converts event from current units to new ones.
static void convert(FourVector &m, MomentumUnit from, MomentumUnit to)
Convert FourVector to different momentum unit.
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
void remove_particle(GenParticlePtr v)
Remove particle from the event.
std::vector< GenVertexData > vertices
Vertices.
Smart pointer for HepMC objects.
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.
bool is_zero() const
Check if the length of this vertex is zero.
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.
Stores vertex-related information.
void clear()
Remove contents of this event.
shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
std::map< int, shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
std::vector< GenParticlePtr > m_particles
List of particles.
Units::LengthUnit m_length_unit
Length unit.
std::vector< double > m_weights
Event weights.
Stores serializable vertex information.
const std::vector< GenParticlePtr > & beams() const
Vector of beam particles.
GenVertexPtr m_rootvertex
The root vertex is stored outside the normal vertices list to block user access to it...
std::vector< int > attribute_id
Attribute owner id.
std::vector< string > attribute_names(int id=0) const
Get list of attribute names.
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
std::vector< int > links2
Second id of the vertex links.
void add_attribute(const string &name, const shared_ptr< Attribute > &att, int id=0)
Add event attribute to event.
void add_particle(GenParticlePtr p)
Add particle.
std::vector< GenVertexPtr > m_vertices
List of vertices.
MomentumUnit
Momentum units.
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.
std::map< string, std::map< int, shared_ptr< Attribute > > >::value_type att_key_t
Attribute map key type.
GenEvent(Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
Event constructor without a run.
shared_ptr< GenRunInfo > m_run_info
Global run information.
const std::vector< GenVertexPtr > & vertices() const
Get list of vertices (const)
int event_number
Event number.
void reserve(unsigned int particles, unsigned int vertices=0)
Reserve memory for particles and vertices.
void set_beam_particles(const GenParticlePtr &p1, const GenParticlePtr &p2)
Set incoming beam particles.
std::vector< std::string > attribute_name
Attribute name.
Units::LengthUnit length_unit
Length unit.
const FourVector & event_pos() const
Vertex representing the overall event position.
Definition of template class SmartPointer.
std::vector< GenParticleData > particles
Particles.
std::vector< double > weights
Weights.
Units::MomentumUnit m_momentum_unit
Momentum unit.
Units::MomentumUnit momentum_unit
Momentum unit.
const Units::LengthUnit & length_unit() const
Get length unit.
Stores serializable event information.
SmartPointer< class GenVertex > GenVertexPtr
Smart pointer to GenVertex.
const std::vector< double > & weights() const
Get event weight values as a vector.
void write_data(GenEventData &data) const
Fill GenEventData object.
Stores particle-related information.
LengthUnit
Position units.
FourVector event_pos
Event position.