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"
70 const std::vector<ConstGenParticlePtr>&
particles()
const;
72 const std::vector<ConstGenVertexPtr>&
vertices()
const;
92 double weight(
const size_t& index=0)
const {
return weights().at(index); }
96 double weight(
const std::string& name)
const {
97 if (!
run_info())
throw WeightError(
"GenEvent::weight(str): named access to event weights requires the event to have a GenRunInfo");
103 double&
weight(
const std::string& name) {
104 if (!
run_info())
throw WeightError(
"GenEvent::weight(str): named access to event weights requires the event to have a GenRunInfo");
105 int pos=
run_info()->weight_index(name);
106 if (pos<0)
throw WeightError(
"GenEvent::weight(str): no weight with given name in this run");
111 const std::vector<std::string>&
weight_names(
const std::string& )
const {
112 if (!
run_info())
throw WeightError(
"GenEvent::weight_names(): access to event weight names requires the event to have a GenRunInfo");
113 const std::vector<std::string>& weightnames =
run_info()->weight_names();
114 if (weightnames.empty())
throw WeightError(
"GenEvent::weight_names(): no event weight names are registered for this run");
131 if ( run && !run->weight_names().empty() )
132 m_weights.resize(run->weight_names().size(), 1.0);
149 GenHeavyIonPtr
heavy_ion() {
return attribute<GenHeavyIon>(
"GenHeavyIon"); }
151 ConstGenHeavyIonPtr
heavy_ion()
const {
return attribute<GenHeavyIon>(
"GenHeavyIon"); }
156 GenPdfInfoPtr
pdf_info() {
return attribute<GenPdfInfo>(
"GenPdfInfo"); }
158 ConstGenPdfInfoPtr
pdf_info()
const {
return attribute<GenPdfInfo>(
"GenPdfInfo"); }
163 GenCrossSectionPtr
cross_section() {
return attribute<GenCrossSection>(
"GenCrossSection"); }
165 ConstGenCrossSectionPtr
cross_section()
const {
return attribute<GenCrossSection>(
"GenCrossSection"); }
179 std::vector<ConstGenParticlePtr>
beams()
const;
182 const std::vector<GenParticlePtr> &
beams();
209 void add_attribute(
const string &name,
const shared_ptr<Attribute> &att,
const int&
id = 0) {
214 if (
id > 0 &&
id <=
int(
particles().size()) )
216 if (
id < 0 && -
id <=
int(
vertices().size()) )
217 att->m_vertex =
vertices()[-
id - 1];
226 shared_ptr<T>
attribute(
const string &name,
const int&
id = 0)
const;
236 std::map< string, std::map<int, shared_ptr<Attribute> > >
attributes()
const {
331 void Streamer(TBuffer &b);
340#if !defined(__CINT__)
367 mutable std::map< string, std::map<int, shared_ptr<Attribute> > >
m_attributes;
370 typedef std::map< string, std::map<int, shared_ptr<Attribute> > >::value_type
att_key_t;
373 typedef std::map<int, shared_ptr<Attribute> >::value_type
att_val_t;
383#if !defined(__CINT__)
390 std::map< string, std::map<int, shared_ptr<Attribute> > >::iterator i1 =
394 return run_info()->attribute<T>(name);
396 return shared_ptr<T>();
399 std::map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(
id);
400 if (i2 == i1->second.end() )
return shared_ptr<T>();
402 if (!i2->second->is_parsed() ) {
404 shared_ptr<T> att = make_shared<T>();
407 if (
id > 0 &&
id <=
int(
particles().size()) )
409 if (
id < 0 && -
id <=
int(
vertices().size()) )
411 if ( att->from_string(i2->second->unparsed_string()) &&
417 return shared_ptr<T>();
420 else return dynamic_pointer_cast<T>(i2->second);
Implementation of error and warning macros.
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::map< int, shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
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 event_number() const
Get event number.
double weight(const size_t &index=0) const
void remove_attribute(const string &name, const int &id=0)
Remove attribute.
void write_data(GenEventData &data) const
Fill GenEventData object.
shared_ptr< GenRunInfo > m_run_info
Global run information.
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< ConstGenParticlePtr > beams() const
Vector of beam particles.
std::vector< double > m_weights
Event weights.
ConstGenHeavyIonPtr heavy_ion() const
Get heavy ion generator additional information (const version)
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.
string attribute_as_string(const string &name, const int &id=0) const
Get attribute of any type as string.
void add_attribute(const string &name, const shared_ptr< Attribute > &att, const int &id=0)
Add event attribute to event.
void set_event_number(const int &num)
Set event number.
void set_run_info(shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
double & weight(const std::string &name)
int m_event_number
Event number.
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)
std::map< string, std::map< int, shared_ptr< Attribute > > > m_attributes
Map of event, particle and vertex attributes.
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.
GenEvent(Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
Event constructor without a run.
shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
void set_cross_section(GenCrossSectionPtr cs)
Set cross-section information.
const FourVector & event_pos() const
Vertex representing the overall event position.
void set_heavy_ion(GenHeavyIonPtr hi)
Set heavy ion generator additional information.
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
GenPdfInfoPtr pdf_info()
Get PDF information.
Units::MomentumUnit m_momentum_unit
Momentum unit.
bool rotate(const FourVector v)
Rotate event using x,y,z components of v as rotation angles.
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.
const std::vector< double > & weights() const
Get event weight values as a vector.
bool boost(const FourVector v)
Boost event using x,y,z components of v as velocities.
double weight(const std::string &name) const
void clear()
Remove contents of this event.
Units::LengthUnit m_length_unit
Length unit.
GenHeavyIonPtr heavy_ion()
Get heavy ion generator additional information.
shared_ptr< T > attribute(const string &name, const int &id=0) const
Get attribute of type T.
std::vector< GenParticlePtr > m_particles
List of particles.
std::vector< string > attribute_names(const int &id=0) const
Get list of attribute names.
void add_beam_particle(GenParticlePtr p1)
Add particle to root vertex.
void set_beam_particles(GenParticlePtr p1, GenParticlePtr p2)
Set incoming beam particles.
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.
std::map< string, std::map< int, shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
const std::vector< std::string > & weight_names(const std::string &) const
void reserve(const size_t &particles, const size_t &vertices=0)
Reserve memory for particles and vertices.
std::map< string, std::map< int, shared_ptr< Attribute > > >::value_type att_key_t
Attribute map key type.
Stores particle-related information.
Stores vertex-related information.
LengthUnit
Position units.
MomentumUnit
Momentum units.
Stores serializable event information.
Exception related to weight lookups, setting, and index consistency.