HepMC3 event record library
Public Member Functions
GenEvent Class Reference

Stores event-related information. More...

#include <GenEvent.h>

+ Collaboration diagram for GenEvent:

Public Member Functions

 GenEvent (Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
 Event constructor without a run. More...
 
 GenEvent (std::shared_ptr< GenRunInfo > run, Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
 Constructor with associated run. More...
 
 GenEvent (const GenEvent &)
 Copy constructor. More...
 
 ~GenEvent ()
 Destructor. More...
 
GenEventoperator= (const GenEvent &)
 Assignment operator. More...
 
Particle and vertex access
const std::vector
< ConstGenParticlePtr > & 
particles () const
 Get list of particles (const) More...
 
const std::vector
< ConstGenVertexPtr > & 
vertices () const
 Get list of vertices (const) More...
 
const std::vector
< GenParticlePtr > & 
particles ()
 Get/set list of particles (non-const) More...
 
const std::vector< GenVertexPtr > & vertices ()
 Get/set list of vertices (non-const) More...
 
Event weights
const std::vector< double > & weights () const
 Get event weight values as a vector. More...
 
std::vector< double > & weights ()
 Get event weights as a vector (non-const) More...
 
double weight (const unsigned long &index=0) const
 
double weight (const std::string &name) const
 
double & weight (const std::string &name)
 
const std::vector< std::string > & weight_names () const
 
Auxiliary info and event metadata
std::shared_ptr< GenRunInforun_info () const
 Get a pointer to the the GenRunInfo object. More...
 
void set_run_info (std::shared_ptr< GenRunInfo > run)
 Set the GenRunInfo object by smart pointer. More...
 
int event_number () const
 Get event number. More...
 
void set_event_number (const int &num)
 Set event number. More...
 
const Units::MomentumUnitmomentum_unit () const
 Get momentum unit. More...
 
const Units::LengthUnitlength_unit () const
 Get length unit. More...
 
void set_units (Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
 Change event units Converts event from current units to new ones. More...
 
GenHeavyIonPtr heavy_ion ()
 Get heavy ion generator additional information. More...
 
ConstGenHeavyIonPtr heavy_ion () const
 Get heavy ion generator additional information (const version) More...
 
void set_heavy_ion (GenHeavyIonPtr hi)
 Set heavy ion generator additional information. More...
 
GenPdfInfoPtr pdf_info ()
 Get PDF information. More...
 
ConstGenPdfInfoPtr pdf_info () const
 Get PDF information (const version) More...
 
void set_pdf_info (GenPdfInfoPtr pi)
 Set PDF information. More...
 
GenCrossSectionPtr cross_section ()
 Get cross-section information. More...
 
ConstGenCrossSectionPtr cross_section () const
 Get cross-section information (const version) More...
 
void set_cross_section (GenCrossSectionPtr cs)
 Set cross-section information. More...
 
Event position
const FourVectorevent_pos () const
 Vertex representing the overall event position. More...
 
std::vector< ConstGenParticlePtr > beams () const
 Vector of beam particles. More...
 
const std::vector
< GenParticlePtr > & 
beams ()
 Vector of beam particles. More...
 
void shift_position_by (const FourVector &delta)
 Shift position of all vertices in the event by delta. More...
 
void shift_position_to (const FourVector &newpos)
 Shift position of all vertices in the event to op. More...
 
bool boost (const FourVector &v)
 Boost event using x,y,z components of v as velocities. More...
 
bool rotate (const FourVector &v)
 Rotate event using x,y,z components of v as rotation angles. More...
 
bool reflect (const int axis)
 Change sign of axis. More...
 
Additional attributes
void add_attribute (const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
 Add event attribute to event. More...
 
void remove_attribute (const std::string &name, const int &id=0)
 Remove attribute. More...
 
template<class T >
std::shared_ptr< T > attribute (const std::string &name, const int &id=0) const
 Get attribute of type T. More...
 
std::string attribute_as_string (const std::string &name, const int &id=0) const
 Get attribute of any type as string. More...
 
std::vector< std::string > attribute_names (const int &id=0) const
 Get list of attribute names. More...
 
std::map< std::string,
std::map< int, std::shared_ptr
< Attribute > > > 
attributes () const
 Get a copy of the list of attributes. More...
 
Particle and vertex modification
void add_particle (GenParticlePtr p)
 Add particle. More...
 
void add_vertex (GenVertexPtr v)
 Add vertex. More...
 
void remove_particle (GenParticlePtr v)
 Remove particle from the event. More...
 
void remove_particles (std::vector< GenParticlePtr > v)
 Remove a set of particles. More...
 
void remove_vertex (GenVertexPtr v)
 Remove vertex from the event. More...
 
void add_tree (const std::vector< GenParticlePtr > &particles)
 Add whole tree in topological order. More...
 
void reserve (const size_t &particles, const size_t &vertices=0)
 Reserve memory for particles and vertices. More...
 
void clear ()
 Remove contents of this event. More...
 
Deprecated functionality
void add_particle (GenParticle *p)
 Add particle by raw pointer. More...
 
void add_vertex (GenVertex *v)
 Add vertex by raw pointer. More...
 
void set_beam_particles (GenParticlePtr p1, GenParticlePtr p2)
 Set incoming beam particles. More...
 
void add_beam_particle (GenParticlePtr p1)
 Add particle to root vertex. More...
 
Methods to fill GenEventData and to read it back
void write_data (GenEventData &data) const
 Fill GenEventData object. More...
 
void read_data (const GenEventData &data)
 Fill GenEvent based on GenEventData. More...
 

Fields

typedef std::map< std::string,
std::map< int, std::shared_ptr
< Attribute > > >::value_type 
att_key_t
 Attribute map key type. More...
 
typedef std::map< int,
std::shared_ptr< Attribute >
>::value_type 
att_val_t
 Attribute map value type. More...
 
std::vector< GenParticlePtr > m_particles
 List of particles. More...
 
std::vector< GenVertexPtr > m_vertices
 List of vertices. More...
 
int m_event_number
 Event number. More...
 
std::vector< double > m_weights
 Event weights. More...
 
Units::MomentumUnit m_momentum_unit
 Momentum unit. More...
 
Units::LengthUnit m_length_unit
 Length unit. More...
 
GenVertexPtr m_rootvertex
 The root vertex is stored outside the normal vertices list to block user access to it. More...
 
std::shared_ptr< GenRunInfom_run_info
 Global run information. More...
 
std::map< std::string,
std::map< int, std::shared_ptr
< Attribute > > > 
m_attributes
 Map of event, particle and vertex attributes. More...
 
std::recursive_mutex m_lock_attributes
 Mutex lock for the m_attibutes map. More...
 

Detailed Description

Stores event-related information.

Manages event-related information. Contains lists of GenParticle and GenVertex objects

Examples:
basic_tree.cc, class_example_write.cc, convert_example.cc, HepMC2_reader_example.cc, HepMC3_fileIO_example.cc, LHEF_example_cat.cc, pythia8_example.cc, rootIO_example_read.cc, and rootIO_example_write.cc.

Definition at line 41 of file GenEvent.h.

Member Typedef Documentation

typedef std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >::value_type att_key_t
private

Attribute map key type.

Definition at line 371 of file GenEvent.h.

typedef std::map<int, std::shared_ptr<Attribute> >::value_type att_val_t
private

Attribute map value type.

Definition at line 374 of file GenEvent.h.

Constructor & Destructor Documentation

GenEvent ( Units::MomentumUnit  momentum_unit = Units::GEV,
Units::LengthUnit  length_unit = Units::MM 
)

Event constructor without a run.

Definition at line 21 of file GenEvent.cc.

GenEvent ( std::shared_ptr< GenRunInfo run,
Units::MomentumUnit  momentum_unit = Units::GEV,
Units::LengthUnit  length_unit = Units::MM 
)

Constructor with associated run.

Definition at line 28 of file GenEvent.cc.

References GenEvent::m_weights.

GenEvent ( const GenEvent e)

Copy constructor.

Definition at line 63 of file GenEvent.cc.

References GenEvent::m_lock_attributes, GenEvent::read_data(), and GenEvent::write_data().

~GenEvent ( )

Destructor.

Definition at line 75 of file GenEvent.cc.

References GenEvent::m_attributes, GenEvent::m_particles, and GenEvent::m_vertices.

Member Function Documentation

void add_attribute ( const std::string &  name,
const std::shared_ptr< Attribute > &  att,
const int &  id = 0 
)
inline

Add event attribute to event.

This will overwrite existing attribute if an attribute with the same name is present

Disallow empty strings

Examples:
basic_tree.cc, and LHEF_example_cat.cc.

Definition at line 208 of file GenEvent.h.

References GenEvent::m_attributes, GenEvent::m_lock_attributes, GenEvent::particles(), and GenEvent::vertices().

void add_beam_particle ( GenParticlePtr  p1)

Add particle to root vertex.

Definition at line 779 of file GenEvent.cc.

References GenEvent::add_particle(), and HEPMC3_WARNING.

void add_particle ( GenParticlePtr  p)

Add particle.

Definition at line 49 of file GenEvent.cc.

References GenEvent::m_particles, GenEvent::m_rootvertex, and GenEvent::particles().

void add_particle ( GenParticle p)

Add particle by raw pointer.

Deprecated:
Use GenEvent::add_particle( const GenParticlePtr& ) instead

Definition at line 764 of file GenEvent.cc.

References GenEvent::add_particle().

void add_tree ( const std::vector< GenParticlePtr > &  particles)

Add whole tree in topological order.

This function will find the beam particles (particles that have no production vertices or their production vertices have no particles) and will add the whole decay tree starting from these particles.

Note
Any particles on this list that do not belong to the tree will be ignored.

Definition at line 267 of file GenEvent.cc.

References GenEvent::add_attribute(), GenEvent::add_vertex(), HEPMC3_DEBUG, HEPMC3_DEBUG_CODE_BLOCK, HEPMC3_WARNING, GenEvent::m_attributes, GenEvent::m_lock_attributes, GenEvent::m_rootvertex, GenEvent::m_vertices, GenEvent::particles(), and HepMC3::visit_children().

void add_vertex ( GenVertexPtr  v)

Add vertex.

Examples:
basic_tree.cc, and LHEF_example_cat.cc.

Definition at line 97 of file GenEvent.cc.

References GenEvent::add_particle(), GenEvent::m_vertices, and GenEvent::vertices().

void add_vertex ( GenVertex v)

Add vertex by raw pointer.

Deprecated:
Use GenEvent::add_vertex( const GenVertexPtr& ) instead

Definition at line 769 of file GenEvent.cc.

References GenEvent::add_vertex().

std::shared_ptr< T > attribute ( const std::string &  name,
const int &  id = 0 
) const
std::string attribute_as_string ( const std::string &  name,
const int &  id = 0 
) const

Get attribute of any type as string.

Definition at line 798 of file GenEvent.cc.

References GenEvent::m_attributes, GenEvent::m_lock_attributes, and GenEvent::run_info().

std::vector< std::string > attribute_names ( const int &  id = 0) const

Get list of attribute names.

Definition at line 633 of file GenEvent.cc.

References GenEvent::m_attributes.

std::map< std::string, std::map<int, std::shared_ptr<Attribute> > > attributes ( ) const
inline

Get a copy of the list of attributes.

Note
To avoid thread issues, this is returns a copy. Better solution may be needed.

Definition at line 237 of file GenEvent.h.

References GenEvent::m_attributes, and GenEvent::m_lock_attributes.

std::vector< ConstGenParticlePtr > beams ( ) const

Vector of beam particles.

Examples:
basic_tree.cc.

Definition at line 420 of file GenEvent.cc.

References GenEvent::m_rootvertex.

const std::vector< GenParticlePtr > & beams ( )

Vector of beam particles.

Definition at line 424 of file GenEvent.cc.

References GenEvent::m_rootvertex.

bool boost ( const FourVector v)

Boost event using x,y,z components of v as velocities.

Definition at line 558 of file GenEvent.cc.

References HepMC3::abs(), FourVector::e(), HEPMC3_WARNING, FourVector::length2(), GenEvent::m_particles, FourVector::x(), FourVector::y(), and FourVector::z().

void clear ( )
GenCrossSectionPtr cross_section ( )
inline

Get cross-section information.

Definition at line 162 of file GenEvent.h.

ConstGenCrossSectionPtr cross_section ( ) const
inline

Get cross-section information (const version)

Definition at line 164 of file GenEvent.h.

int event_number ( ) const
inline

Get event number.

Examples:
LHEF_example_cat.cc.

Definition at line 135 of file GenEvent.h.

References GenEvent::m_event_number.

const FourVector & event_pos ( ) const

Vertex representing the overall event position.

Definition at line 416 of file GenEvent.cc.

References GenEvent::m_rootvertex.

GenHeavyIonPtr heavy_ion ( )
inline

Get heavy ion generator additional information.

Definition at line 148 of file GenEvent.h.

ConstGenHeavyIonPtr heavy_ion ( ) const
inline

Get heavy ion generator additional information (const version)

Definition at line 150 of file GenEvent.h.

const Units::LengthUnit& length_unit ( ) const
inline

Get length unit.

Definition at line 142 of file GenEvent.h.

References GenEvent::m_length_unit.

const Units::MomentumUnit& momentum_unit ( ) const
inline

Get momentum unit.

Definition at line 140 of file GenEvent.h.

References GenEvent::m_momentum_unit.

GenEvent & operator= ( const GenEvent e)

Assignment operator.

Definition at line 83 of file GenEvent.cc.

References GenEvent::m_lock_attributes, GenEvent::read_data(), and GenEvent::write_data().

const std::vector< ConstGenParticlePtr > & particles ( ) const

Get list of particles (const)

Examples:
LHEF_example_cat.cc.

Definition at line 39 of file GenEvent.cc.

References GenEvent::m_particles.

const std::vector<GenParticlePtr>& particles ( )
inline

Get/set list of particles (non-const)

Definition at line 75 of file GenEvent.h.

References GenEvent::m_particles.

GenPdfInfoPtr pdf_info ( )
inline

Get PDF information.

Definition at line 155 of file GenEvent.h.

ConstGenPdfInfoPtr pdf_info ( ) const
inline

Get PDF information (const version)

Definition at line 157 of file GenEvent.h.

void read_data ( const GenEventData data)
bool reflect ( const int  axis)
void remove_attribute ( const std::string &  name,
const int &  id = 0 
)

Remove attribute.

Examples:
basic_tree.cc.

Definition at line 621 of file GenEvent.cc.

References GenEvent::m_attributes, and GenEvent::m_lock_attributes.

void remove_particle ( GenParticlePtr  v)

Remove particle from the event.

This function will remove whole sub-tree starting from this particle if it is the only incoming particle of this vertex. It will also production vertex of this particle if this vertex has no more outgoing particles

Examples:
basic_tree.cc.

Definition at line 117 of file GenEvent.cc.

References HEPMC3_DEBUG, GenEvent::m_attributes, GenEvent::m_lock_attributes, GenEvent::m_particles, and GenEvent::remove_vertex().

void remove_particles ( std::vector< GenParticlePtr >  v)

Remove a set of particles.

This function follows rules of GenEvent::remove_particle to remove a list of particles from the event.

Examples:
basic_tree.cc.

Definition at line 185 of file GenEvent.cc.

References GenEvent::remove_particle().

void remove_vertex ( GenVertexPtr  v)

Remove vertex from the event.

This will remove all sub-trees of all outgoing particles of this vertex

Definition at line 194 of file GenEvent.cc.

References HEPMC3_DEBUG, GenEvent::m_attributes, GenEvent::m_lock_attributes, GenEvent::m_vertices, and GenEvent::remove_particle().

void reserve ( const size_t &  particles,
const size_t &  vertices = 0 
)

Reserve memory for particles and vertices.

Helps optimize event creation when size of the event is known beforehand

Definition at line 389 of file GenEvent.cc.

References GenEvent::m_particles, and GenEvent::m_vertices.

bool rotate ( const FourVector v)

Rotate event using x,y,z components of v as rotation angles.

Definition at line 438 of file GenEvent.cc.

References FourVector::e(), GenEvent::m_particles, GenEvent::m_vertices, FourVector::t(), FourVector::x(), FourVector::y(), and FourVector::z().

std::shared_ptr<GenRunInfo> run_info ( ) const
inline

Get a pointer to the the GenRunInfo object.

Examples:
class_example_write.cc.

Definition at line 124 of file GenEvent.h.

References GenEvent::m_run_info.

void set_beam_particles ( GenParticlePtr  p1,
GenParticlePtr  p2 
)

Set incoming beam particles.

Deprecated:
Backward compatibility

Definition at line 774 of file GenEvent.cc.

References GenEvent::m_rootvertex.

void set_cross_section ( GenCrossSectionPtr  cs)
inline

Set cross-section information.

Definition at line 166 of file GenEvent.h.

References GenEvent::add_attribute().

void set_event_number ( const int &  num)
inline

Set event number.

Examples:
LHEF_example_cat.cc.

Definition at line 137 of file GenEvent.h.

References GenEvent::m_event_number.

void set_heavy_ion ( GenHeavyIonPtr  hi)
inline

Set heavy ion generator additional information.

Definition at line 152 of file GenEvent.h.

References GenEvent::add_attribute().

void set_pdf_info ( GenPdfInfoPtr  pi)
inline

Set PDF information.

Definition at line 159 of file GenEvent.h.

References GenEvent::add_attribute().

void set_run_info ( std::shared_ptr< GenRunInfo run)
inline

Set the GenRunInfo object by smart pointer.

Examples:
class_example_read.cc.

Definition at line 128 of file GenEvent.h.

References GenEvent::m_run_info, and GenEvent::m_weights.

void set_units ( Units::MomentumUnit  new_momentum_unit,
Units::LengthUnit  new_length_unit 
)

Change event units Converts event from current units to new ones.

Definition at line 395 of file GenEvent.cc.

References Units::convert(), FourVector::is_zero(), GenEvent::m_length_unit, GenEvent::m_momentum_unit, GenEvent::m_particles, and GenEvent::m_vertices.

void shift_position_by ( const FourVector delta)

Shift position of all vertices in the event by delta.

Examples:
basic_tree.cc.

Definition at line 428 of file GenEvent.cc.

References GenEvent::event_pos(), GenEvent::m_rootvertex, and GenEvent::m_vertices.

void shift_position_to ( const FourVector newpos)
inline

Shift position of all vertices in the event to op.

Definition at line 187 of file GenEvent.h.

References GenEvent::event_pos(), and GenEvent::shift_position_by().

const std::vector< ConstGenVertexPtr > & vertices ( ) const

Get list of vertices (const)

Definition at line 43 of file GenEvent.cc.

References GenEvent::m_vertices.

const std::vector<GenVertexPtr>& vertices ( )
inline

Get/set list of vertices (non-const)

Definition at line 77 of file GenEvent.h.

References GenEvent::m_vertices.

double weight ( const unsigned long &  index = 0) const
inline

Get event weight accessed by index (or the canonical/first one if there is no argument)

Note
It's the user's responsibility to ensure that the given index exists!

Definition at line 91 of file GenEvent.h.

References GenEvent::weights().

double weight ( const std::string &  name) const
inline

Get event weight accessed by weight name

Note
Requires there to be an attached GenRunInfo, otherwise will throw an exception
It's the user's responsibility to ensure that the given name exists!

Definition at line 95 of file GenEvent.h.

References GenEvent::run_info(), and GenEvent::weight().

double& weight ( const std::string &  name)
inline

Get event weight accessed by weight name

Note
Requires there to be an attached GenRunInfo, otherwise will throw an exception
It's the user's responsibility to ensure that the given name exists!

Definition at line 102 of file GenEvent.h.

References GenEvent::m_weights, and GenEvent::run_info().

const std::vector<std::string>& weight_names ( ) const
inline

Get event weight names, if there are some

Note
Requires there to be an attached GenRunInfo with registered weight names, otherwise will throw an exception

Definition at line 110 of file GenEvent.h.

References GenEvent::run_info().

const std::vector<double>& weights ( ) const
inline

Get event weight values as a vector.

Examples:
LHEF_example_cat.cc.

Definition at line 86 of file GenEvent.h.

References GenEvent::m_weights.

std::vector<double>& weights ( )
inline

Get event weights as a vector (non-const)

Definition at line 88 of file GenEvent.h.

References GenEvent::m_weights.

void write_data ( GenEventData data) const

Field Documentation

std::map< std::string, std::map<int, std::shared_ptr<Attribute> > > m_attributes
mutableprivate

Map of event, particle and vertex attributes.

Keys are name and ID (0 = event, <0 = vertex, >0 = particle)

Definition at line 368 of file GenEvent.h.

int m_event_number
private

Event number.

Definition at line 349 of file GenEvent.h.

Units::LengthUnit m_length_unit
private

Length unit.

Definition at line 357 of file GenEvent.h.

std::recursive_mutex m_lock_attributes
mutableprivate

Mutex lock for the m_attibutes map.

Definition at line 377 of file GenEvent.h.

Units::MomentumUnit m_momentum_unit
private

Momentum unit.

Definition at line 355 of file GenEvent.h.

std::vector<GenParticlePtr> m_particles
private

List of particles.

Definition at line 344 of file GenEvent.h.

GenVertexPtr m_rootvertex
private

The root vertex is stored outside the normal vertices list to block user access to it.

Definition at line 360 of file GenEvent.h.

std::shared_ptr<GenRunInfo> m_run_info
private

Global run information.

Definition at line 363 of file GenEvent.h.

std::vector<GenVertexPtr> m_vertices
private

List of vertices.

Definition at line 346 of file GenEvent.h.

std::vector<double> m_weights
private

Event weights.

Definition at line 352 of file GenEvent.h.


The documentation for this class was generated from the following files: