10#ifndef HEPMC3_GENEVENT_H
11#define HEPMC3_GENEVENT_H
14#include "HepMC3/GenParticle_fwd.h"
15#include "HepMC3/GenVertex_fwd.h"
16#include "HepMC3/GenPdfInfo_fwd.h"
17#include "HepMC3/GenHeavyIon_fwd.h"
18#include "HepMC3/GenCrossSection_fwd.h"
52 GenEvent(std::shared_ptr<GenRunInfo> run,
69 const std::vector<ConstGenParticlePtr>&
particles()
const;
71 const std::vector<ConstGenVertexPtr>&
vertices()
const;
103 double weight(
const unsigned long& index=0)
const {
if ( index <
weights().size() )
return weights().at(index);
else throw std::runtime_error(
"GenEvent::weight(const unsigned long&): weight index outside of range");
return 0.0; }
107 double weight(
const std::string& name)
const {
108 if (!
run_info())
throw std::runtime_error(
"GenEvent::weight(const std::string&): named access to event weights requires the event to have a GenRunInfo");
114 double&
weight(
const std::string& name) {
115 if (!
run_info())
throw std::runtime_error(
"GenEvent::weight(const std::string&): named access to event weights requires the event to have a GenRunInfo");
116 int pos =
run_info()->weight_index(name);
117 if ( pos < 0 )
throw std::runtime_error(
"GenEvent::weight(const std::string&): no weight with given name in this run");
118 if ( pos >=
int(
m_weights.size()))
throw std::runtime_error(
"GenEvent::weight(const std::string&): weight index outside of range");
124 if (!
run_info())
throw std::runtime_error(
"GenEvent::weight_names(): access to event weight names requires the event to have a GenRunInfo");
125 const std::vector<std::string>& weightnames =
run_info()->weight_names();
126 if (weightnames.empty())
throw std::runtime_error(
"GenEvent::weight_names(): no event weight names are registered for this run");
143 if ( run && !run->weight_names().empty() )
144 m_weights.resize(run->weight_names().size(), 1.0);
161 GenHeavyIonPtr
heavy_ion() {
return attribute<GenHeavyIon>(
"GenHeavyIon"); }
163 ConstGenHeavyIonPtr
heavy_ion()
const {
return attribute<GenHeavyIon>(
"GenHeavyIon"); }
168 GenPdfInfoPtr
pdf_info() {
return attribute<GenPdfInfo>(
"GenPdfInfo"); }
170 ConstGenPdfInfoPtr
pdf_info()
const {
return attribute<GenPdfInfo>(
"GenPdfInfo"); }
175 GenCrossSectionPtr
cross_section() {
return attribute<GenCrossSection>(
"GenCrossSection"); }
177 ConstGenCrossSectionPtr
cross_section()
const {
return attribute<GenCrossSection>(
"GenCrossSection"); }
191 std::vector<ConstGenParticlePtr>
beams()
const;
194 const std::vector<GenParticlePtr> &
beams();
221 void add_attribute(
const std::string &name,
const std::shared_ptr<Attribute> &att,
const int&
id = 0);
227 void add_attributes(
const std::vector<std::string> &names,
const std::vector<std::shared_ptr<Attribute> > &atts,
const std::vector<int>& ids);
233 void add_attributes(
const std::string& name,
const std::vector<std::shared_ptr<Attribute> > &atts,
const std::vector<int>& ids);
239 void add_attributes(
const std::string& name,
const std::vector<std::pair<
int, std::shared_ptr<Attribute> > > &atts);
247 std::shared_ptr<T>
attribute(
const std::string &name,
const int&
id = 0)
const;
257 std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >
attributes()
const {
352 void Streamer(TBuffer &b);
361#if !defined(__CINT__)
388 mutable std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >
m_attributes;
391 typedef std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >::value_type
att_key_t;
394 typedef std::map<int, std::shared_ptr<Attribute> >::value_type
att_val_t;
404#if !defined(__CINT__)
411 std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >::iterator i1 =
415 return run_info()->attribute<T>(name);
417 return std::shared_ptr<T>();
420 std::map<int, std::shared_ptr<Attribute> >::iterator i2 = i1->second.find(
id);
421 if (i2 == i1->second.end() )
return std::shared_ptr<T>();
423 if (!i2->second->is_parsed() ) {
425 std::shared_ptr<T> att = std::make_shared<T>();
428 if (
id > 0 &&
id <=
int(
particles().size()) )
430 if (
id < 0 && -
id <=
int(
vertices().size()) )
432 if ( att->from_string(i2->second->unparsed_string()) &&
438 return std::shared_ptr<T>();
441 else return std::dynamic_pointer_cast<T>(i2->second);
Definition of attribute class GenCrossSection.
Definition of attribute class GenHeavyIon.
Definition of event attribute class GenPdfInfo.
Definition of class GenRunInfo.
Definition of class Units.
Stores event-related information.
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
std::recursive_mutex m_lock_attributes
Mutex lock for the m_attibutes map.
void add_vertex(GenVertexPtr v)
Add vertex.
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.
int vertices_size() const
Vertices size, HepMC2 compatiility.
bool vertices_empty() const
Vertices empty, HepMC2 compatiility.
int event_number() const
Get event number.
std::vector< std::string > attribute_names(const int &id=0) const
Get list of attribute names.
void write_data(GenEventData &data) const
Fill GenEventData object.
std::shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
void remove_particle(GenParticlePtr v)
Remove particle from the event.
ConstGenCrossSectionPtr cross_section() const
Get cross-section information (const version)
void remove_particles(std::vector< GenParticlePtr > v)
Remove a set of particles.
void add_particle(GenParticlePtr p)
Add particle.
void set_units(Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
Change event units Converts event from current units to new ones.
std::vector< double > m_weights
Event weights.
ConstGenHeavyIonPtr heavy_ion() const
Get heavy ion generator additional information (const version)
std::map< int, std::shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
std::map< std::string, std::map< int, std::shared_ptr< Attribute > > >::value_type att_key_t
Attribute map key type.
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.
void set_event_number(const int &num)
Set event number.
double & weight(const std::string &name)
std::vector< ConstGenParticlePtr > beams() const
Vector of beam particles.
int m_event_number
Event number.
void set_run_info(std::shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
ConstGenPdfInfoPtr pdf_info() const
Get PDF information (const version)
std::vector< double > & weights()
Get event weights as a vector (non-const)
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
const Units::LengthUnit & length_unit() const
Get length unit.
bool reflect(const int axis)
Change sign of axis.
double weight(const unsigned long &index=0) const
void set_cross_section(GenCrossSectionPtr cs)
Set cross-section information.
const FourVector & event_pos() const
Vertex representing the overall event position.
std::map< std::string, std::map< int, std::shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
void set_heavy_ion(GenHeavyIonPtr hi)
Set heavy ion generator additional information.
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
std::map< std::string, std::map< int, std::shared_ptr< Attribute > > > m_attributes
Map of event, particle and vertex attributes.
GenPdfInfoPtr pdf_info()
Get PDF information.
const std::vector< std::string > & weight_names() const
Units::MomentumUnit m_momentum_unit
Momentum unit.
bool particles_empty() const
Particles empty, HepMC2 compatiility.
void remove_attribute(const std::string &name, const int &id=0)
Remove attribute.
std::vector< GenVertexPtr > m_vertices
List of vertices.
GenVertexPtr m_rootvertex
The root vertex is stored outside the normal vertices list to block user access to it.
std::string attribute_as_string(const std::string &name, const int &id=0) const
Get attribute of any type as string.
const std::vector< double > & weights() const
Get event weight values as a vector.
double weight(const std::string &name) const
void clear()
Remove contents of this event.
int particles_size() const
Particles size, HepMC2 compatiility.
Units::LengthUnit m_length_unit
Length unit.
bool boost(const FourVector &v)
Boost event using x,y,z components of v as velocities.
GenHeavyIonPtr heavy_ion()
Get heavy ion generator additional information.
std::shared_ptr< GenRunInfo > m_run_info
Global run information.
std::vector< GenParticlePtr > m_particles
List of particles.
void add_beam_particle(GenParticlePtr p1)
Add particle to root vertex.
void add_attributes(const std::vector< std::string > &names, const std::vector< std::shared_ptr< Attribute > > &atts, const std::vector< int > &ids)
Add multiple attributes to event.
void set_beam_particles(GenParticlePtr p1, GenParticlePtr p2)
Set incoming beam particles.
bool rotate(const FourVector &v)
Rotate event using x,y,z components of v as rotation angles.
void set_pdf_info(GenPdfInfoPtr pi)
Set PDF information.
GenCrossSectionPtr cross_section()
Get cross-section information.
const std::vector< GenParticlePtr > & particles()
Get/set list of particles (non-const)
const std::vector< GenVertexPtr > & vertices()
Get/set list of vertices (non-const)
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
GenEvent & operator=(const GenEvent &)
Assignment operator.
void reserve(const size_t &particles, const size_t &vertices=0)
Reserve memory for particles and vertices.
Stores particle-related information.
Stores vertex-related information.
LengthUnit
Position units.
MomentumUnit
Momentum units.
Stores serializable event information.