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"
20 #if !defined(__CINT__)
50 #if !defined(__CINT__)
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 {
281 void add_tree(
const std::vector<GenParticlePtr> &particles );
286 void reserve(
const size_t& particles,
const size_t& vertices = 0);
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);
Units::MomentumUnit m_momentum_unit
Momentum unit.
void set_run_info(shared_ptr< GenRunInfo > run)
Set the GenRunInfo object by smart pointer.
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
Definition of class GenRunInfo.
void remove_particle(GenParticlePtr v)
Remove particle from the event.
GenHeavyIonPtr heavy_ion()
Get heavy ion generator additional information.
void set_cross_section(GenCrossSectionPtr cs)
Set cross-section information.
void add_beam_particle(GenParticlePtr p1)
Add particle to root vertex.
Implementation of error and warning macros.
void remove_particles(std::vector< GenParticlePtr > v)
Remove a set of particles.
void add_vertex(GenVertexPtr v)
Add vertex.
const std::vector< std::string > & weight_names(const std::string &) const
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.
GenEvent(Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
Event constructor without a run.
Stores vertex-related information.
GenPdfInfoPtr pdf_info()
Get PDF information.
std::vector< GenVertexPtr > m_vertices
List of vertices.
ConstGenHeavyIonPtr heavy_ion() const
Get heavy ion generator additional information (const version)
Exception related to weight lookups, setting, and index consistency.
Definition of attribute class GenHeavyIon.
GenCrossSectionPtr cross_section()
Get cross-section information.
Stores particle-related information.
const Units::LengthUnit & length_unit() const
Get length unit.
ConstGenPdfInfoPtr pdf_info() const
Get PDF information (const version)
bool reflect(const int axis)
Change sign of axis.
shared_ptr< T > attribute(const string &name, const int &id=0) const
Get attribute of type T.
void add_particle(GenParticlePtr p)
Add particle.
int event_number() const
Get event number.
shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
const FourVector & event_pos() const
Vertex representing the overall event position.
const std::vector< GenParticlePtr > & particles()
Get/set list of particles (non-const)
LengthUnit
Position units.
MomentumUnit
Momentum units.
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
bool rotate(const FourVector v)
Rotate event using x,y,z components of v as rotation angles.
Stores event-related information.
Stores serializable event information.
void write_data(GenEventData &data) const
Fill GenEventData object.
void set_pdf_info(GenPdfInfoPtr pi)
Set PDF information.
std::recursive_mutex m_lock_attributes
Mutex lock for the m_attibutes map.
void set_beam_particles(GenParticlePtr p1, GenParticlePtr p2)
Set incoming beam particles.
std::vector< double > & weights()
Get event weights as a vector (non-const)
shared_ptr< GenRunInfo > m_run_info
Global run information.
void remove_attribute(const string &name, const int &id=0)
Remove attribute.
bool boost(const FourVector v)
Boost event using x,y,z components of v as velocities.
ConstGenCrossSectionPtr cross_section() const
Get cross-section information (const version)
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
std::map< int, shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
Definition of class Units.
double & weight(const std::string &name)
std::vector< ConstGenParticlePtr > beams() const
Vector of beam particles.
string attribute_as_string(const string &name, const int &id=0) const
Get attribute of any type as string.
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
Units::LengthUnit m_length_unit
Length unit.
std::map< string, std::map< int, shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
std::vector< GenParticlePtr > m_particles
List of particles.
const std::vector< GenVertexPtr > & vertices()
Get/set list of vertices (non-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 > > > m_attributes
Map of event, particle and vertex 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.
void add_attribute(const string &name, const shared_ptr< Attribute > &att, const int &id=0)
Add event attribute to event.
int m_event_number
Event number.
Definition of event attribute class GenPdfInfo.
double weight(const std::string &name) const
const std::vector< double > & weights() const
Get event weight values as a vector.
GenVertexPtr m_rootvertex
The root vertex is stored outside the normal vertices list to block user access to it...
Definition of attribute class GenCrossSection.
std::vector< string > attribute_names(const int &id=0) const
Get list of attribute names.
double weight(const size_t &index=0) const
GenEvent & operator=(const GenEvent &)
Assignment operator.
std::map< string, std::map< int, shared_ptr< Attribute > > >::value_type att_key_t
Attribute map key type.
void clear()
Remove contents of this event.
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
std::vector< double > m_weights
Event weights.
void set_heavy_ion(GenHeavyIonPtr hi)
Set heavy ion generator additional information.
void set_event_number(const int &num)
Set event number.
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.