MARLEY (Model of Argon Reaction Low Energy Yields) v2.0.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Loading...
Searching...
No Matches
HepMC3::GenEvent Class Reference

Stores event-related information. More...

#include <GenEvent.h>

Public Member Functions

 GenEvent (const GenEvent &)
 Copy constructor.
 
 GenEvent (std::shared_ptr< GenRunInfo > run, Units::MomentumUnit mu=Units::GEV, Units::LengthUnit lu=Units::MM)
 Constructor with associated run.
 
 GenEvent (Units::MomentumUnit mu=Units::GEV, Units::LengthUnit lu=Units::MM)
 Event constructor without a run.
 
 ~GenEvent ()
 Destructor.
 
GenEventoperator= (const GenEvent &)
 Copy Assignment operator.
 
Particle and vertex access
const std::vector< ConstGenParticlePtr > & particles () const
 Get list of particles (const)
 
const std::vector< ConstGenVertexPtr > & vertices () const
 Get list of vertices (const)
 
const std::vector< GenParticlePtr > & particles ()
 Get/set list of particles (non-const)
 
const std::vector< GenVertexPtr > & vertices ()
 Get/set list of vertices (non-const)
 
int particles_size () const
 Particles size, HepMC2 compatibility.
 
bool particles_empty () const
 Particles empty, HepMC2 compatibility.
 
int vertices_size () const
 Vertices size, HepMC2 compatibility.
 
bool vertices_empty () const
 Vertices empty, HepMC2 compatibility.
 
Event weights
const std::vector< double > & weights () const
 Get event weight values as a vector.
 
std::vector< double > & weights ()
 Get event weights as a vector (non-const)
 
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.
 
void set_run_info (std::shared_ptr< GenRunInfo > run)
 Set the GenRunInfo object by smart pointer.
 
int event_number () const
 Get event number.
 
void set_event_number (const int &num)
 Set event number.
 
const Units::MomentumUnitmomentum_unit () const
 Get momentum unit.
 
const Units::LengthUnitlength_unit () const
 Get length unit.
 
void set_units (Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
 Change event units Converts event from current units to new ones.
 
GenHeavyIonPtr heavy_ion ()
 Get heavy ion generator additional information.
 
ConstGenHeavyIonPtr heavy_ion () const
 Get heavy ion generator additional information (const version)
 
void set_heavy_ion (GenHeavyIonPtr hi)
 Set heavy ion generator additional information.
 
GenPdfInfoPtr pdf_info ()
 Get PDF information.
 
ConstGenPdfInfoPtr pdf_info () const
 Get PDF information (const version)
 
void set_pdf_info (GenPdfInfoPtr pi)
 Set PDF information.
 
GenCrossSectionPtr cross_section ()
 Get cross-section information.
 
ConstGenCrossSectionPtr cross_section () const
 Get cross-section information (const version)
 
void set_cross_section (GenCrossSectionPtr cs)
 Set cross-section information.
 
Event position
const FourVectorevent_pos () const
 Vertex representing the overall event position.
 
std::vector< ConstGenParticlePtr > beams () const
 Vector of beam particles.
 
std::vector< ConstGenParticlePtr > beams (const int status) const
 Vector of beam particles.
 
const std::vector< GenParticlePtr > & beams ()
 Vector of beam particles.
 
void shift_position_by (const FourVector &delta)
 Shift position of all vertices in the event by delta.
 
void shift_position_to (const FourVector &newpos)
 Shift position of all vertices in the event to op.
 
bool boost (const FourVector &delta)
 Boost event using x,y,z components of delta as velocities.
 
bool rotate (const FourVector &delta)
 Rotate event using x,y,z components of delta as rotation angles.
 
bool reflect (const int axis)
 Change sign of axis.
 
Additional attributes

Add event attribute to event

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

void add_attribute (const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
 
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 add_attributes (const std::string &name, const std::vector< std::shared_ptr< Attribute > > &atts, const std::vector< int > &ids)
 Add multiple attributes to event.
 
void add_attributes (const std::string &name, const std::vector< std::pair< int, std::shared_ptr< Attribute > > > &atts)
 Add multiple attributes to event.
 
void remove_attribute (const std::string &name, const int &id=0)
 Remove attribute.
 
template<class T>
std::shared_ptr< T > attribute (const std::string &name, const int &id=0) const
 Get attribute of type T.
 
std::string attribute_as_string (const std::string &name, const int &id=0) const
 Get attribute of any type as string.
 
std::vector< std::string > attribute_names (const int &id=0) const
 Get list of attribute names.
 
std::map< std::string, std::map< int, std::shared_ptr< Attribute > > > attributes () const
 Get a copy of the list of attributes.
 
Particle and vertex modification
void add_particle (GenParticlePtr p)
 Add particle.
 
void add_vertex (GenVertexPtr v)
 Add vertex.
 
void remove_particle (GenParticlePtr p)
 Remove particle from the event.
 
void remove_particles (std::vector< GenParticlePtr > v)
 Remove a set of particles.
 
void remove_vertex (GenVertexPtr v)
 Remove vertex from the event.
 
void add_tree (const std::vector< GenParticlePtr > &parts)
 Add whole tree in topological order.
 
void reserve (const size_t &parts, const size_t &verts=0)
 Reserve memory for particles and vertices.
 
void clear ()
 Remove contents of this event.
 
Deprecated functionality
void set_beam_particles (GenParticlePtr p1, GenParticlePtr p2)
 Set incoming beam particles.
 
void add_beam_particle (GenParticlePtr p1)
 Add particle to root vertex.
 
Methods to fill GenEventData and to read it back
void write_data (GenEventData &data) const
 Fill GenEventData object.
 
void read_data (const GenEventData &data)
 Fill GenEvent based on GenEventData.
 

Detailed Description

Stores event-related information.

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

Definition at line 47 of file GenEvent.h.

Constructor & Destructor Documentation

◆ GenEvent() [1/3]

HepMC3::GenEvent::GenEvent ( Units::MomentumUnit mu = Units::GEV,
Units::LengthUnit lu = Units::MM )

Event constructor without a run.

Definition at line 490 of file marley_hepmc3.cc.

492 : m_momentum_unit(mu), m_length_unit(lu), //m_weights(std::vector<double>(1, 1.0)),//Prevent from different number of weights and names
493 m_rootvertex(std::make_shared<GenVertex>()) {}

Referenced by GenEvent(), and operator=().

◆ GenEvent() [2/3]

HepMC3::GenEvent::GenEvent ( std::shared_ptr< GenRunInfo > run,
Units::MomentumUnit mu = Units::GEV,
Units::LengthUnit lu = Units::MM )

Constructor with associated run.

Definition at line 496 of file marley_hepmc3.cc.

499 : m_momentum_unit(mu), m_length_unit(lu), //m_weights(std::vector<double>(1, 1.0)),//Prevent from different number of weights and names
500 m_rootvertex(std::make_shared<GenVertex>()),
501 m_run_info(run) {
502 if ( run && !run->weight_names().empty() ) {
503 m_weights = std::vector<double>(run->weight_names().size(), 1.0);
504 }
505}

◆ GenEvent() [3/3]

HepMC3::GenEvent::GenEvent ( const GenEvent & e)

Copy constructor.

Definition at line 531 of file marley_hepmc3.cc.

531 {
532 if (this != &e)
533 {
534 std::lock(m_lock_attributes, e.m_lock_attributes);
535 std::lock_guard<std::recursive_mutex> lhs_lk(m_lock_attributes, std::adopt_lock);
536 std::lock_guard<std::recursive_mutex> rhs_lk(e.m_lock_attributes, std::adopt_lock);
537 GenEventData tdata;
538 e.write_data(tdata);
539 read_data(tdata);
540 m_run_info = e.m_run_info;
541 }
542}
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.

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

◆ ~GenEvent()

HepMC3::GenEvent::~GenEvent ( )

Destructor.

Definition at line 544 of file marley_hepmc3.cc.

544 {
545 for ( auto attm = m_attributes.begin(); attm != m_attributes.end(); ++attm) {
546 for ( auto att = attm->second.begin(); att != attm->second.end(); ++att) { if (att->second) att->second->m_event = nullptr;}
547 }
548 for ( auto v = m_vertices.begin(); v != m_vertices.end(); ++v ) if (*v) if ((*v)->m_event == this) (*v)->m_event = nullptr;
549 for ( auto p = m_particles.begin(); p != m_particles.end(); ++p ) if (*p) if ((*p)->m_event == this) (*p)->m_event = nullptr;
550}

Member Function Documentation

◆ add_attribute()

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

Disallow empty strings

Definition at line 1265 of file marley_hepmc3.cc.

1265 {
1267 if (name.length() == 0) return;
1268 if (!att) return;
1269 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1270 if (m_attributes.count(name) == 0) m_attributes[name] = std::map<int, std::shared_ptr<Attribute> >();
1271 m_attributes[name][id] = att;
1272 att->m_event = this;
1273 if ( id > 0 && id <= int(particles().size()) ) {
1274 att->m_particle = particles()[id - 1];
1275 }
1276 if ( id < 0 && -id <= int(vertices().size()) ) {
1277 att->m_vertex = vertices()[-id - 1];
1278 }
1279}
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)

References particles(), and vertices().

Referenced by HepMC3::GenParticle::add_attribute(), HepMC3::GenVertex::add_attribute(), marley::Generator::add_state_to_event(), add_tree(), marley::Generator::create_event(), marley::Generator::create_event(), marley::Generator::finish_event_metadata(), set_cross_section(), set_heavy_ion(), and set_pdf_info().

◆ add_attributes() [1/3]

void HepMC3::GenEvent::add_attributes ( const std::string & name,
const std::vector< std::pair< int, std::shared_ptr< Attribute > > > & atts )

Add multiple attributes to event.

This will overwrite existing attributes if attributes with the same names are present

Disallow empty strings

Definition at line 1339 of file marley_hepmc3.cc.

1339 {
1340 if (name.length() == 0) return;
1341 if (atts.empty()) return;
1342 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1343 if (m_attributes.count(name) == 0) m_attributes[name] = std::map<int, std::shared_ptr<Attribute> >();
1344 auto& tmap = m_attributes[name];
1345 const int particles_size = int(m_particles.size());
1346 const int vertices_size = int(m_vertices.size());
1347 for (const auto& att: atts) {
1349 if (!att.second) continue;
1350 tmap.insert(att);
1351 att.second->m_event = this;
1352 if ( att.first > 0 && att.first <= particles_size )
1353 { att.second->m_particle = m_particles[att.first - 1]; }
1354 else {
1355 if ( att.first < 0 && -att.first <= vertices_size ) {
1356 att.second->m_vertex = m_vertices[-att.first - 1];
1357 }
1358 }
1359 }
1360}
int vertices_size() const
Vertices size, HepMC2 compatibility.
Definition GenEvent.h:95
int particles_size() const
Particles size, HepMC2 compatibility.
Definition GenEvent.h:91

References particles_size(), and vertices_size().

◆ add_attributes() [2/3]

void HepMC3::GenEvent::add_attributes ( const std::string & name,
const std::vector< std::shared_ptr< Attribute > > & atts,
const std::vector< int > & ids )

Add multiple attributes to event.

This will overwrite existing attributes if attributes with the same names are present

Disallow empty strings

Definition at line 1314 of file marley_hepmc3.cc.

1314 {
1315 if (name.length() == 0) return;
1316 size_t N = ids.size();
1317 if(!N) return;
1318 if ( N != atts.size()) return;
1319
1320 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1321 if (m_attributes.count(name) == 0) m_attributes[name] = std::map<int, std::shared_ptr<Attribute> >();
1322 auto& tmap = m_attributes[name];
1323 const int particles_size = int(m_particles.size());
1324 const int vertices_size = int(m_vertices.size());
1325 for (size_t i = 0; i < N; i++) {
1327 if (!atts[i]) continue;
1328 tmap[ids.at(i)] = atts[i];
1329 atts[i]->m_event = this;
1330 if ( ids.at(i) > 0 && ids.at(i) <= particles_size )
1331 { atts[i]->m_particle = m_particles[ids.at(i) - 1]; }
1332 else {
1333 if ( ids.at(i) < 0 && -ids.at(i) <= vertices_size ) {
1334 atts[i]->m_vertex = m_vertices[-ids.at(i) - 1];
1335 }
1336 }
1337 }
1338}

References particles_size(), and vertices_size().

◆ add_attributes() [3/3]

void HepMC3::GenEvent::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.

This will overwrite existing attributes if attributes with the same names are present

Disallow empty strings

Definition at line 1282 of file marley_hepmc3.cc.

1282 {
1283 size_t N = names.size();
1284 if ( N == 0 ) return;
1285 if (N != atts.size()) return;
1286 if (N != ids.size()) return;
1287
1288 std::vector<std::string> unames = names;
1289 vector<std::string>::iterator ip;
1290 ip = std::unique(unames.begin(), unames.end());
1291 unames.resize(std::distance(unames.begin(), ip));
1292 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1293 for (const auto& name: unames) {
1294 if (m_attributes.count(name) == 0) m_attributes[name] = std::map<int, std::shared_ptr<Attribute> >();
1295 }
1296 const int particles_size = int(m_particles.size());
1297 const int vertices_size = int(m_vertices.size());
1298 for (size_t i = 0; i < N; i++) {
1300 if (names.at(i).length() == 0) continue;
1301 if (!atts[i]) continue;
1302 m_attributes[names.at(i)][ids.at(i)] = atts[i];
1303 atts[i]->m_event = this;
1304 if ( ids.at(i) > 0 && ids.at(i) <= particles_size )
1305 { atts[i]->m_particle = m_particles[ids.at(i) - 1]; }
1306 else {
1307 if ( ids.at(i) < 0 && -ids.at(i) <= vertices_size ) {
1308 atts[i]->m_vertex = m_vertices[-ids.at(i) - 1];
1309 }
1310 }
1311 }
1312}

References particles_size(), and vertices_size().

◆ add_beam_particle()

void HepMC3::GenEvent::add_beam_particle ( GenParticlePtr p1)

Add particle to root vertex.

Definition at line 1226 of file marley_hepmc3.cc.

1226 {
1227 if (!p1)
1228 {
1229 HEPMC3_WARNING_LEVEL(700,"Attempting to add an empty particle as beam particle. Ignored.")
1230 return;
1231 }
1232 if (p1->in_event() && p1->parent_event() != this)
1233 {
1234 HEPMC3_WARNING_LEVEL(700,"Attempting to add particle from another event. Ignored.")
1235 return;
1236 }
1237 if (p1->production_vertex()) p1->production_vertex()->remove_particle_out(p1);
1238 //Particle w/o production vertex is added to root vertex.
1239 add_particle(p1);
1240 p1->set_status(4);
1241}
void add_particle(GenParticlePtr p)
Add particle.

References add_particle().

◆ add_particle()

void HepMC3::GenEvent::add_particle ( GenParticlePtr p)

Add particle.

Definition at line 516 of file marley_hepmc3.cc.

516 {
517 if ( !p || p->in_event() ) return;
518
519 m_particles.emplace_back(p);
520
521 p->m_event = this;
522 p->m_id = particles().size();
523
524 // Particles without production vertex are added to the root vertex
525 if ( !p->production_vertex() ) {
526 m_rootvertex->add_particle_out(p);
527 }
528}

References particles().

Referenced by add_beam_particle(), and add_vertex().

◆ add_tree()

void HepMC3::GenEvent::add_tree ( const std::vector< GenParticlePtr > & parts)

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 736 of file marley_hepmc3.cc.

736 {
737 m_particles.reserve(m_particles.size() + parts.size());
738 m_vertices.reserve(m_vertices.size() + parts.size());
739 std::shared_ptr<IntAttribute> existing_hc = attribute<IntAttribute>("cycles");
740 bool has_cycles = false;
741 std::map<GenVertexPtr, int> sortingv;
742 std::vector<GenVertexPtr> noinv;
743 if (existing_hc) if (existing_hc->value() != 0) has_cycles = true;
744 if (!existing_hc)
745 {
746 for (const GenParticlePtr& p: parts) {
747 GenVertexPtr v = p->production_vertex();
748 if (v) sortingv[v]=0;
749 if ( !v || v->particles_in().empty()) {
750 GenVertexPtr v2 = p->end_vertex();
751 if (v2) {noinv.emplace_back(v2); sortingv[v2] = 0;}
752 }
753 }
754 for (const GenVertexPtr& v: noinv) {
755 std::map<ConstGenVertexPtr, int> sorting_temp(sortingv.begin(), sortingv.end());
756 has_cycles = (has_cycles || visit_children(sorting_temp, v));
757 }
758 }
759 if (has_cycles) {
760 add_attribute("cycles", std::make_shared<IntAttribute>(1));
761 /* Commented out as improvemnts allow us to do sorting in other way.
762 for ( std::map<GenVertexPtr,int>::iterator vi=sortingv.begin();vi!=sortingv.end();++vi) if ( !vi->first->in_event() ) add_vertex(vi->first);
763 return;
764 */
765 }
766
767 std::deque<GenVertexPtr> sorting;
768
769 // Find all starting vertices (end vertex of particles that have no production vertex)
770 for (const auto& p: parts) {
771 const GenVertexPtr &v = p->production_vertex();
772 if ( !v || v->particles_in().empty() ) {
773 const GenVertexPtr &v2 = p->end_vertex();
774 if (v2) sorting.emplace_back(v2);
775 }
776 }
777
778 HEPMC3_DEBUG_CODE_BLOCK(
779 unsigned int sorting_loop_count = 0;
780 unsigned int max_deque_size = 0;
781 )
782
783 // Add vertices to the event in topological order
784 while ( !sorting.empty() ) {
785 HEPMC3_DEBUG_CODE_BLOCK(
786 if ( sorting.size() > max_deque_size ) max_deque_size = sorting.size();
787 ++sorting_loop_count;
788 )
789
790 GenVertexPtr &v = sorting.front();
791
792 bool added = false;
793
794 // Add all mothers to the front of the list
795 for (const auto& p: v->particles_in() ) {
796 GenVertexPtr v2 = p->production_vertex();
797 if ( v2 && !v2->in_event() && find(sorting.begin(), sorting.end(), v2) == sorting.end() ) {
798 sorting.push_front(v2);
799 added = true;
800 }
801 }
802
803 // If we have added at least one production vertex,
804 // our vertex is not the first one on the list
805 if ( added ) continue;
806
807 // If vertex not yet added
808 if ( !v->in_event() ) {
809 add_vertex(v);
810
811 // Add all end vertices to the end of the list
812 for (const auto& p: v->particles_out()) {
813 GenVertexPtr v2 = p->end_vertex();
814 if ( v2 && !v2->in_event()&& find(sorting.begin(), sorting.end(), v2) == sorting.end() ) {
815 sorting.emplace_back(v2);
816 }
817 }
818 }
819
820 sorting.pop_front();
821 }
822
823 // LL: Make sure root vertex has index zero and is not written out
824 if ( m_rootvertex->id() != 0 ) {
825 const int vx = -1 - m_rootvertex->id();
826 const int rootid = m_rootvertex->id();
827 if ( vx >= 0 && vx < (int) m_vertices.size() && m_vertices[vx] == m_rootvertex ) {
828 auto next = m_vertices.erase(m_vertices.begin() + vx);
829 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
830 for (auto & vt1: m_attributes) {
831 std::vector< std::pair< int, std::shared_ptr<Attribute> > > changed_attributes;
832 for ( const auto& vt2 : vt1.second ) {
833 if ( vt2.first <= rootid ) {
834 changed_attributes.emplace_back(vt2);
835 }
836 }
837 for ( const auto& val : changed_attributes ) {
838 vt1.second.erase(val.first);
839 vt1.second[val.first == rootid? 0: val.first + 1] = val.second;
840 }
841 }
842 m_rootvertex->m_id = 0;
843 while ( next != m_vertices.end() ) {
844 ++((*next++)->m_id);
845 }
846 } else {
847 HEPMC3_WARNING_LEVEL(700,"GenEvent::add_tree Suspicious looking rootvertex found. Will try to cope.")
848 }
849 }
850
851 HEPMC3_DEBUG_CODE_BLOCK(
852 HEPMC3_DEBUG(6, "GenEvent - particles sorted: "
853 << this->particles().size() << ", max deque size: "
854 << max_deque_size << ", iterations: " << sorting_loop_count)
855 )
856}
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:418
void add_vertex(GenVertexPtr v)
Add vertex.
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)

References add_attribute(), add_vertex(), attribute(), and particles().

◆ add_vertex()

void HepMC3::GenEvent::add_vertex ( GenVertexPtr v)

Add vertex.

Definition at line 567 of file marley_hepmc3.cc.

567 {
568 if ( !v|| v->in_event() ) return;
569 m_vertices.emplace_back(v);
570
571 v->m_event = this;
572 v->m_id = -(int)vertices().size();
573
574 // Add all incoming and outgoing particles and restore their production/end vertices
575 for (const auto& p: v->particles_in()) {
576 if (!p->in_event()) add_particle(p);
577 p->m_end_vertex = v->shared_from_this();
578 }
579
580 for (const auto& p: v->particles_out()) {
581 if (!p->in_event()) add_particle(p);
582 p->m_production_vertex = v;
583 }
584}

References add_particle(), and vertices().

Referenced by add_tree().

◆ attribute()

template<class T>
std::shared_ptr< T > HepMC3::GenEvent::attribute ( const std::string & name,
const int & id = 0 ) const

Get attribute of type T.

Definition at line 418 of file GenEvent.h.

418 {
419 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
420 std::map< std::string, std::map<int, std::shared_ptr<Attribute> > >::iterator i1 = m_attributes.find(name);
421 if ( i1 == m_attributes.end() ) {
422 if ( id == 0 && run_info() ) {
423 return run_info()->attribute<T>(name);
424 }
425 return std::shared_ptr<T>();
426 }
427
428 std::map<int, std::shared_ptr<Attribute> >::iterator i2 = i1->second.find(id);
429 if (i2 == i1->second.end() ) return std::shared_ptr<T>();
430
431 if (!i2->second->is_parsed() ) {
432
433 std::shared_ptr<T> att = std::make_shared<T>();
434 att->m_event = this;
435
436 if ( id > 0 && id <= int(particles().size()) ) {
437 att->m_particle = m_particles[id - 1];
438 }
439 if ( id < 0 && -id <= int(vertices().size()) ) {
440 att->m_vertex = m_vertices[-id - 1];
441 }
442 if ( att->from_string(i2->second->unparsed_string()) &&
443 att->init() ) {
444 // update map with new pointer
445 i2->second = att;
446 return att;
447 } else {
448 return std::shared_ptr<T>();
449 }
450 }
451 else return std::dynamic_pointer_cast<T>(i2->second);
452}
std::shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
Definition GenEvent.h:144

References particles(), run_info(), and vertices().

Referenced by add_tree(), HepMC3::GenParticle::attribute(), HepMC3::GenVertex::attribute(), cross_section(), cross_section(), heavy_ion(), heavy_ion(), pdf_info(), pdf_info(), and HepMC3::GenVertex::position().

◆ attribute_as_string()

std::string HepMC3::GenEvent::attribute_as_string ( const std::string & name,
const int & id = 0 ) const

Get attribute of any type as string.

Definition at line 1244 of file marley_hepmc3.cc.

1244 {
1245 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1246 auto i1 = m_attributes.find(name);
1247 if ( i1 == m_attributes.end() ) {
1248 if ( id == 0 && run_info() ) {
1249 return run_info()->attribute_as_string(name);
1250 }
1251 return {};
1252 }
1253
1254 auto i2 = i1->second.find(id);
1255 if (i2 == i1->second.end() ) return {};
1256
1257 if ( !i2->second ) return {};
1258
1259 std::string ret;
1260 i2->second->to_string(ret);
1261
1262 return ret;
1263}

References run_info().

Referenced by HepMC3::GenParticle::attribute_as_string(), and HepMC3::GenVertex::attribute_as_string().

◆ attribute_names()

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

Get list of attribute names.

Definition at line 1081 of file marley_hepmc3.cc.

1081 {
1082 std::vector<std::string> results;
1083
1084 for (const att_key_t& vt1: m_attributes) {
1085 if ( vt1.second.count(id) == 1 ) {
1086 results.emplace_back(vt1.first);
1087 }
1088 }
1089
1090 return results;
1091}

Referenced by HepMC3::GenParticle::attribute_names(), HepMC3::GenVertex::attribute_names(), and HepMC3::Print::line().

◆ attributes()

std::map< std::string, std::map< int, std::shared_ptr< Attribute > > > HepMC3::GenEvent::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 268 of file GenEvent.h.

268 {
269 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
270 return m_attributes;
271 }

Referenced by HepMC3::Print::content(), write_data(), and HepMC3::WriterAscii::write_event().

◆ beams() [1/3]

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

Vector of beam particles.

Definition at line 902 of file marley_hepmc3.cc.

902 {
903 return m_rootvertex->particles_out();
904}

◆ beams() [2/3]

std::vector< ConstGenParticlePtr > HepMC3::GenEvent::beams ( ) const

Vector of beam particles.

Definition at line 897 of file marley_hepmc3.cc.

897 {
898 return std::const_pointer_cast<const GenVertex>(m_rootvertex)->particles_out();
899}

◆ beams() [3/3]

std::vector< ConstGenParticlePtr > HepMC3::GenEvent::beams ( const int status) const

Vector of beam particles.

Definition at line 890 of file marley_hepmc3.cc.

890 {
891 if (!status) return std::const_pointer_cast<const GenVertex>(m_rootvertex)->particles_out();
892 std::vector<ConstGenParticlePtr> ret;
893 for (auto& p: m_rootvertex->particles_out()) if (p->status() == status) ret.emplace_back(p);
894 return ret;
895}

◆ boost()

bool HepMC3::GenEvent::boost ( const FourVector & delta)

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

Definition at line 1015 of file marley_hepmc3.cc.

1016{
1017 double deltalength2 = delta.length2();
1018 if (deltalength2 > 1.0)
1019 {
1020 HEPMC3_WARNING_LEVEL(400,"GenEvent::boost: wrong large boost vector. Will leave event as is.")
1021 return false;
1022 }
1023 if (std::abs(deltalength2-1.0) < std::numeric_limits<double>::epsilon())
1024 {
1025 HEPMC3_WARNING_LEVEL(400,"GenEvent::boost: too large gamma. Will leave event as is.")
1026 return false;
1027 }
1028 if (std::abs(deltalength2) < std::numeric_limits<double>::epsilon())
1029 {
1030 HEPMC3_WARNING_LEVEL(400,"GenEvent::boost: wrong small boost vector. Will leave event as is.")
1031 return true;
1032 }
1033 long double deltaX = delta.x();
1034 long double deltaY = delta.y();
1035 long double deltaZ = delta.z();
1036 long double deltalength = std::sqrt(deltalength2);
1037 long double gamma = 1.0/std::sqrt(1.0-deltalength2);
1038
1039 for ( auto& p: m_particles)
1040 {
1041 const FourVector& mom = p->momentum();
1042
1043 long double tempX = mom.x();
1044 long double tempY = mom.y();
1045 long double tempZ = mom.z();
1046 long double tempE = mom.e();
1047 long double nr = (deltaX*tempX+deltaY*tempY+deltaZ*tempZ)/deltalength;
1048 long double gfac = (gamma-1)*nr/deltalength-tempE*gamma;
1049 tempX+=(deltaX*gfac);
1050 tempY+=(deltaY*gfac);
1051 tempZ+=(deltaZ*gfac);
1052 tempE = gamma*(tempE-deltalength*nr);
1053 FourVector temp(tempX, tempY, tempZ, tempE);
1054 p->set_momentum(temp);
1055 }
1056
1057 return true;
1058}

References HepMC3::FourVector::e(), HepMC3::FourVector::length2(), HepMC3::FourVector::x(), HepMC3::FourVector::y(), and HepMC3::FourVector::z().

◆ clear()

void HepMC3::GenEvent::clear ( )

Remove contents of this event.

Definition at line 1060 of file marley_hepmc3.cc.

1060 {
1061 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1062 m_event_number = 0;
1063 m_rootvertex = std::make_shared<GenVertex>();
1064 m_weights.clear();
1065 m_attributes.clear();
1066 m_particles.clear();
1067 m_vertices.clear();
1068}

Referenced by read_data(), and HepMC3::ReaderAscii::read_event().

◆ cross_section() [1/2]

GenCrossSectionPtr HepMC3::GenEvent::cross_section ( )
inline

Get cross-section information.

Definition at line 182 of file GenEvent.h.

182{ return attribute<GenCrossSection>("GenCrossSection"); }

References attribute().

◆ cross_section() [2/2]

ConstGenCrossSectionPtr HepMC3::GenEvent::cross_section ( ) const
inline

Get cross-section information (const version)

Definition at line 184 of file GenEvent.h.

184{ return attribute<GenCrossSection>("GenCrossSection"); }

References attribute().

◆ event_number()

int HepMC3::GenEvent::event_number ( ) const
inline

Get event number.

Definition at line 155 of file GenEvent.h.

155{ return m_event_number; }

Referenced by write_data(), and HepMC3::WriterAscii::write_event().

◆ event_pos()

const FourVector & HepMC3::GenEvent::event_pos ( ) const

Vertex representing the overall event position.

Definition at line 886 of file marley_hepmc3.cc.

886 {
887 return m_rootvertex->data().position;
888}

Referenced by HepMC3::GenVertex::position(), shift_position_by(), shift_position_to(), write_data(), and HepMC3::WriterAscii::write_event().

◆ heavy_ion() [1/2]

GenHeavyIonPtr HepMC3::GenEvent::heavy_ion ( )
inline

Get heavy ion generator additional information.

Definition at line 168 of file GenEvent.h.

168{ return attribute<GenHeavyIon>("GenHeavyIon"); }

References attribute().

◆ heavy_ion() [2/2]

ConstGenHeavyIonPtr HepMC3::GenEvent::heavy_ion ( ) const
inline

Get heavy ion generator additional information (const version)

Definition at line 170 of file GenEvent.h.

170{ return attribute<GenHeavyIon>("GenHeavyIon"); }

References attribute().

◆ length_unit()

const Units::LengthUnit & HepMC3::GenEvent::length_unit ( ) const
inline

Get length unit.

Definition at line 162 of file GenEvent.h.

162{ return m_length_unit; }

Referenced by HepMC3::Print::listing(), write_data(), and HepMC3::WriterAscii::write_event().

◆ momentum_unit()

const Units::MomentumUnit & HepMC3::GenEvent::momentum_unit ( ) const
inline

Get momentum unit.

Definition at line 160 of file GenEvent.h.

160{ return m_momentum_unit; }

Referenced by HepMC3::Print::listing(), write_data(), and HepMC3::WriterAscii::write_event().

◆ operator=()

GenEvent & HepMC3::GenEvent::operator= ( const GenEvent & e)

Copy Assignment operator.

Definition at line 552 of file marley_hepmc3.cc.

552 {
553 if (this != &e)
554 {
555 std::lock(m_lock_attributes, e.m_lock_attributes);
556 std::lock_guard<std::recursive_mutex> lhs_lk(m_lock_attributes, std::adopt_lock);
557 std::lock_guard<std::recursive_mutex> rhs_lk(e.m_lock_attributes, std::adopt_lock);
558 GenEventData tdata;
559 e.write_data(tdata);
560 read_data(tdata);
561 m_run_info = e.m_run_info;
562 }
563 return *this;
564}

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

◆ particles() [1/2]

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

Get/set list of particles (non-const)

Definition at line 80 of file GenEvent.h.

80{ return m_particles; }

◆ particles() [2/2]

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

Get list of particles (const)

Definition at line 507 of file marley_hepmc3.cc.

507 {
508 return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles));
509}

Referenced by add_attribute(), add_particle(), add_tree(), attribute(), HepMC3::Print::content(), HepMC3::ReaderAscii::read_event(), marley::ProjectileDirectionRotator::rotate_event(), write_data(), and HepMC3::WriterAscii::write_event().

◆ particles_empty()

bool HepMC3::GenEvent::particles_empty ( ) const
inline

Particles empty, HepMC2 compatibility.

Definition at line 93 of file GenEvent.h.

93{ return m_particles.empty(); }

◆ particles_size()

int HepMC3::GenEvent::particles_size ( ) const
inline

Particles size, HepMC2 compatibility.

Definition at line 91 of file GenEvent.h.

91{ return m_particles.size(); }

Referenced by add_attributes(), add_attributes(), and add_attributes().

◆ pdf_info() [1/2]

GenPdfInfoPtr HepMC3::GenEvent::pdf_info ( )
inline

Get PDF information.

Definition at line 175 of file GenEvent.h.

175{ return attribute<GenPdfInfo>("GenPdfInfo"); }

References attribute().

◆ pdf_info() [2/2]

ConstGenPdfInfoPtr HepMC3::GenEvent::pdf_info ( ) const
inline

Get PDF information (const version)

Definition at line 177 of file GenEvent.h.

177{ return attribute<GenPdfInfo>("GenPdfInfo"); }

References attribute().

◆ read_data()

void HepMC3::GenEvent::read_data ( const GenEventData & data)

Fill GenEvent based on GenEventData.

Disallow empty strings

Definition at line 1150 of file marley_hepmc3.cc.

1150 {
1151 this->clear();
1152 this->set_event_number(data.event_number);
1153 //Note: set_units checks the current unit of event, i.e. applicable only for fully constructed event.
1154 m_momentum_unit = data.momentum_unit;
1155 m_length_unit = data.length_unit;
1156 this->shift_position_to(data.event_pos);
1157
1158 // Fill weights
1159 this->weights() = data.weights;
1160 m_particles.reserve(data.particles.size());
1161 m_vertices.reserve(data.vertices.size());
1162
1163 // Fill particle information
1164 for ( const GenParticleData &pd: data.particles ) {
1165 m_particles.emplace_back(std::make_shared<GenParticle>(pd));
1166 m_particles.back()->m_event = this;
1167 m_particles.back()->m_id = m_particles.size();
1168 }
1169
1170 // Fill vertex information
1171 for ( const GenVertexData &vd: data.vertices ) {
1172 m_vertices.emplace_back(std::make_shared<GenVertex>(vd));
1173 m_vertices.back()->m_event = this;
1174 m_vertices.back()->m_id = -(int)m_vertices.size();
1175 }
1176
1177 // Restore links
1178 for (unsigned int i = 0; i < data.links1.size(); ++i) {
1179 const int id1 = data.links1[i];
1180 const int id2 = data.links2[i];
1181 /* @note:
1182 The meaningfull combinations for (id1,id2) are:
1183 (+-) -- particle has end vertex
1184 (-+) -- particle has production vertex
1185 */
1186 if ((id1 < 0 && id2 <0) || (id1 > 0 && id2 > 0)) {
1187 HEPMC3_WARNING_LEVEL(600,"GenEvent::read_data: wrong link: " << id1 << " " << id2);
1188 continue;
1189 }
1190
1191 if ( id1 > 0 ) { m_vertices[ (-id2)-1 ]->add_particle_in ( m_particles[ id1-1 ] ); continue; }
1192 if ( id1 < 0 ) { m_vertices[ (-id1)-1 ]->add_particle_out( m_particles[ id2-1 ] ); continue; }
1193 }
1194 for (auto& p: m_particles) if (!p->production_vertex()) m_rootvertex->add_particle_out(p);
1195
1196 // Read attributes
1197 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1198 for (unsigned int i = 0; i < data.attribute_id.size(); ++i) {
1200 const std::string name = data.attribute_name[i];
1201 if (name.length() == 0) continue;
1202 const int id = data.attribute_id[i];
1203 if (m_attributes.count(name) == 0) m_attributes[name] = std::map<int, std::shared_ptr<Attribute> >();
1204 auto att = std::make_shared<StringAttribute>(data.attribute_string[i]);
1205 att->m_event = this;
1206 if ( id > 0 && id <= int(m_particles.size()) ) {
1207 att->m_particle = m_particles[id - 1];
1208 }
1209 if ( id < 0 && -id <= int(m_vertices.size()) ) {
1210 att->m_vertex = m_vertices[-id - 1];
1211 }
1212 m_attributes[name][id] = att;
1213 }
1214}
const std::vector< double > & weights() const
Get event weight values as a vector.
Definition GenEvent.h:105
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.
Definition GenEvent.h:211
void set_event_number(const int &num)
Set event number.
Definition GenEvent.h:157
void clear()
Remove contents of this event.

References HepMC3::GenEventData::attribute_id, HepMC3::GenEventData::attribute_name, HepMC3::GenEventData::attribute_string, clear(), HepMC3::GenEventData::event_number, HepMC3::GenEventData::event_pos, HepMC3::GenEventData::length_unit, HepMC3::GenEventData::links1, HepMC3::GenEventData::links2, HepMC3::GenEventData::momentum_unit, HepMC3::GenEventData::particles, set_event_number(), shift_position_to(), HepMC3::GenEventData::vertices, weights(), and HepMC3::GenEventData::weights.

Referenced by GenEvent(), marley::EventFileReader::next_event(), operator=(), and HepMC3::ReaderAscii::read_event().

◆ reflect()

bool HepMC3::GenEvent::reflect ( const int axis)

Change sign of axis.

Definition at line 983 of file marley_hepmc3.cc.

984{
985 if ( axis > 3 || axis < 0 )
986 {
987 HEPMC3_WARNING_LEVEL(400,"GenEvent::reflect: wrong axis")
988 return false;
989 }
990 switch (axis)
991 {
992 case 0:
993 for ( auto& p: m_particles) { FourVector temp = p->momentum(); temp.setX(-p->momentum().x()); p->set_momentum(temp);}
994 for ( auto& v: m_vertices) { FourVector temp = v->position(); temp.setX(-v->position().x()); v->set_position(temp);}
995 break;
996 case 1:
997 for ( auto& p: m_particles) { FourVector temp = p->momentum(); temp.setY(-p->momentum().y()); p->set_momentum(temp);}
998 for ( auto& v: m_vertices) { FourVector temp = v->position(); temp.setY(-v->position().y()); v->set_position(temp);}
999 break;
1000 case 2:
1001 for ( auto& p: m_particles) { FourVector temp = p->momentum(); temp.setZ(-p->momentum().z()); p->set_momentum(temp);}
1002 for ( auto& v: m_vertices) { FourVector temp = v->position(); temp.setZ(-v->position().z()); v->set_position(temp);}
1003 break;
1004 case 3:
1005 for ( auto& p: m_particles) { FourVector temp = p->momentum(); temp.setT(-p->momentum().e()); p->set_momentum(temp);}
1006 for ( auto& v: m_vertices) { FourVector temp = v->position(); temp.setT(-v->position().t()); v->set_position(temp);}
1007 break;
1008 default:
1009 return false;
1010 }
1011
1012 return true;
1013}

References HepMC3::FourVector::setT(), HepMC3::FourVector::setX(), HepMC3::FourVector::setY(), and HepMC3::FourVector::setZ().

◆ remove_attribute()

void HepMC3::GenEvent::remove_attribute ( const std::string & name,
const int & id = 0 )

Remove attribute.

Definition at line 1070 of file marley_hepmc3.cc.

1070 {
1071 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
1072 auto i1 = m_attributes.find(name);
1073 if ( i1 == m_attributes.end() ) return;
1074
1075 auto i2 = i1->second.find(id);
1076 if ( i2 == i1->second.end() ) return;
1077
1078 i1->second.erase(i2);
1079}

Referenced by HepMC3::GenParticle::remove_attribute(), and HepMC3::GenVertex::remove_attribute().

◆ remove_particle()

void HepMC3::GenEvent::remove_particle ( GenParticlePtr p)

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

Definition at line 587 of file marley_hepmc3.cc.

587 {
588 if ( !p || p->parent_event() != this ) return;
589
590 HEPMC3_DEBUG(30, "GenEvent::remove_particle - called with particle: " << p->id());
591 GenVertexPtr end_vtx = p->end_vertex();
592 if ( end_vtx ) {
593 end_vtx->remove_particle_in(p);
594
595 // If that was the only incoming particle, remove vertex from the event
596 if ( end_vtx->particles_in().empty() ) remove_vertex(end_vtx);
597 }
598
599 GenVertexPtr prod_vtx = p->production_vertex();
600 if ( prod_vtx ) {
601 prod_vtx->remove_particle_out(p);
602
603 // If that was the only outgoing particle, remove vertex from the event
604 if ( prod_vtx->particles_out().empty() ) remove_vertex(prod_vtx);
605 }
606
607 HEPMC3_DEBUG(30, "GenEvent::remove_particle - erasing particle: " << p->id())
608
609 int idx = p->id();
610 auto it = m_particles.erase(m_particles.begin() + idx-1);
611
612 // Remove attributes of this particle
613 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
614 for (att_key_t& vt1: m_attributes) {
615 auto vt2 = vt1.second.find(idx);
616 if (vt2 == vt1.second.end()) continue;
617 vt1.second.erase(vt2);
618 }
619
620 //
621 // Reassign id of attributes with id above this one
622 //
623 std::vector< std::pair< int, std::shared_ptr<Attribute> > > changed_attributes;
624
625 for (att_key_t& vt1: m_attributes) {
626 changed_attributes.clear();
627
628 for (auto vt2 = vt1.second.begin(); vt2 != vt1.second.end(); ++vt2) {
629 if ( (*vt2).first > p->id() ) {
630 changed_attributes.emplace_back(*vt2);
631 }
632 }
633
634 std::sort(changed_attributes.begin(),changed_attributes.end(), [](const std::pair< int, std::shared_ptr<Attribute> > &a, const std::pair< int, std::shared_ptr<Attribute> > &b) { return a.first < b.first; });
635 for ( const auto& val: changed_attributes ) {
636 vt1.second.erase(val.first);
637 vt1.second[val.first-1] = val.second;
638 }
639 }
640 // Reassign id of particles with id above this one
641 for (; it != m_particles.end(); ++it) {
642 --((*it)->m_id);
643 }
644
645 // Finally - set parent event and id of this particle to 0
646 p->m_event = nullptr;
647 p->m_id = 0;
648}
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.

References remove_vertex().

Referenced by remove_particles(), and remove_vertex().

◆ remove_particles()

void HepMC3::GenEvent::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.

Definition at line 650 of file marley_hepmc3.cc.

650 {
651 std::sort(v.begin(), v.end(), [](const GenParticlePtr& p1, const GenParticlePtr& p2) { return p1->id() > p2->id();});
652
653 for (auto p = v.begin(); p != v.end(); ++p) {
654 remove_particle(*p);
655 }
656}
void remove_particle(GenParticlePtr p)
Remove particle from the event.

References remove_particle().

◆ remove_vertex()

void HepMC3::GenEvent::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 658 of file marley_hepmc3.cc.

658 {
659 if ( !v || v->parent_event() != this ) return;
660
661 HEPMC3_DEBUG(30, "GenEvent::remove_vertex - called with vertex: " << v->id());
662 std::shared_ptr<GenVertex> null_vtx;
663
664 for (const auto& p: v->particles_in()) {
665 p->m_end_vertex = std::weak_ptr<GenVertex>();
666 }
667
668 for (const auto& p: v->particles_out()) {
669 p->m_production_vertex = std::weak_ptr<GenVertex>();
670
671 // recursive delete rest of the tree
673 }
674
675 // Erase this vertex from vertices list
676 HEPMC3_DEBUG(30, "GenEvent::remove_vertex - erasing vertex: " << v->id())
677
678 int idx = -v->id();
679 auto it = m_vertices.erase(m_vertices.begin() + idx-1);
680 // Remove attributes of this vertex
681 std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
682 for (att_key_t& vt1: m_attributes) {
683 auto vt2 = vt1.second.find(-idx);
684 if (vt2 == vt1.second.end()) continue;
685 vt1.second.erase(vt2);
686 }
687
688 //
689 // Reassign id of attributes with id below this one
690 //
691
692 std::vector< std::pair< int, std::shared_ptr<Attribute> > > changed_attributes;
693
694 for ( att_key_t& vt1: m_attributes ) {
695 changed_attributes.clear();
696
697 for (auto vt2 = vt1.second.begin(); vt2 != vt1.second.end(); ++vt2) {
698 if ( (*vt2).first < v->id() ) {
699 changed_attributes.emplace_back(*vt2);
700 }
701 }
702
703 std::reverse(changed_attributes.begin(),changed_attributes.end());
704 std::sort(changed_attributes.begin(),changed_attributes.end(),[](const std::pair< int, std::shared_ptr<Attribute> > &a, const std::pair< int, std::shared_ptr<Attribute> > &b) { return a.first > b.first; });
705 for ( const auto& val: changed_attributes ) {
706 vt1.second.erase(val.first);
707 vt1.second[val.first+1] = val.second;
708 }
709 }
710
711 // Reassign id of particles with id above this one
712 for (; it != m_vertices.end(); ++it) {
713 ++((*it)->m_id);
714 }
715
716 // Finally - set parent event and id of this vertex to 0
717 v->m_event = nullptr;
718 v->m_id = 0;
719}

References remove_particle().

Referenced by remove_particle().

◆ reserve()

void HepMC3::GenEvent::reserve ( const size_t & parts,
const size_t & verts = 0 )

Reserve memory for particles and vertices.

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

Definition at line 859 of file marley_hepmc3.cc.

859 {
860 m_particles.reserve(parts);
861 m_vertices.reserve(verts);
862}

◆ rotate()

bool HepMC3::GenEvent::rotate ( const FourVector & delta)

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

Definition at line 917 of file marley_hepmc3.cc.

918{
919 long double cosa = std::cos(delta.x());
920 long double sina = std::sin(delta.x());
921 long double cosb = std::cos(delta.y());
922 long double sinb = std::sin(delta.y());
923 long double cosg = std::cos(delta.z());
924 long double sing = std::sin(delta.z());
925
926 for ( auto& p: m_particles)
927 {
928 const FourVector& mom = p->momentum();
929 long double tempX = mom.x();
930 long double tempY = mom.y();
931 long double tempZ = mom.z();
932
933 long double tempY_ = cosa*tempY+sina*tempZ;
934 long double tempZ_ = -sina*tempY+cosa*tempZ;
935 tempY = tempY_;
936 tempZ = tempZ_;
937
938 long double tempX_ = cosb*tempX-sinb*tempZ;
939 tempZ_ = sinb*tempX+cosb*tempZ;
940 tempX = tempX_;
941 tempZ = tempZ_;
942
943 tempX_ = cosg*tempX+sing*tempY;
944 tempY_ = -sing*tempX+cosg*tempY;
945 tempX = tempX_;
946 tempY = tempY_;
947
948 FourVector temp(tempX, tempY, tempZ, mom.e());
949 p->set_momentum(temp);
950 }
951 for (auto& v: m_vertices)
952 {
953 const FourVector& pos = v->position();
954 if (pos.is_zero()) continue;
955
956 long double tempX = pos.x();
957 long double tempY = pos.y();
958 long double tempZ = pos.z();
959
960 long double tempY_ = cosa*tempY+sina*tempZ;
961 long double tempZ_ = -sina*tempY+cosa*tempZ;
962 tempY = tempY_;
963 tempZ = tempZ_;
964
965 long double tempX_ = cosb*tempX-sinb*tempZ;
966 tempZ_ = sinb*tempX+cosb*tempZ;
967 tempX = tempX_;
968 tempZ = tempZ_;
969
970 tempX_ = cosg*tempX+sing*tempY;
971 tempY_ = -sing*tempX+cosg*tempY;
972 tempX = tempX_;
973 tempY = tempY_;
974
975 FourVector temp(tempX, tempY, tempZ, pos.t());
976 v->set_position(temp);
977 }
978
979
980 return true;
981}

References HepMC3::FourVector::e(), HepMC3::FourVector::is_zero(), HepMC3::FourVector::t(), HepMC3::FourVector::x(), HepMC3::FourVector::y(), and HepMC3::FourVector::z().

◆ run_info()

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

◆ set_beam_particles()

void HepMC3::GenEvent::set_beam_particles ( GenParticlePtr p1,
GenParticlePtr p2 )

Set incoming beam particles.

Deprecated
Backward compatibility

Definition at line 1221 of file marley_hepmc3.cc.

1221 {
1222 m_rootvertex->add_particle_out(p1);
1223 m_rootvertex->add_particle_out(p2);
1224}

◆ set_cross_section()

void HepMC3::GenEvent::set_cross_section ( GenCrossSectionPtr cs)
inline

Set cross-section information.

Definition at line 186 of file GenEvent.h.

186{ add_attribute("GenCrossSection",cs); }

References add_attribute().

◆ set_event_number()

void HepMC3::GenEvent::set_event_number ( const int & num)
inline

Set event number.

Definition at line 157 of file GenEvent.h.

157{ m_event_number = num; }

Referenced by read_data().

◆ set_heavy_ion()

void HepMC3::GenEvent::set_heavy_ion ( GenHeavyIonPtr hi)
inline

Set heavy ion generator additional information.

Definition at line 172 of file GenEvent.h.

172{ add_attribute("GenHeavyIon",hi); }

References add_attribute().

◆ set_pdf_info()

void HepMC3::GenEvent::set_pdf_info ( GenPdfInfoPtr pi)
inline

Set PDF information.

Definition at line 179 of file GenEvent.h.

179{ add_attribute("GenPdfInfo",pi); }

References add_attribute().

◆ set_run_info()

void HepMC3::GenEvent::set_run_info ( std::shared_ptr< GenRunInfo > run)
inline

Set the GenRunInfo object by smart pointer.

Definition at line 148 of file GenEvent.h.

148 {
149 m_run_info = run;
150 if ( run && !run->weight_names().empty() )
151 m_weights.resize(run->weight_names().size(), 1.0);
152 }

Referenced by marley::CommandHandler::cmd_convert(), marley::CommandHandler::cmd_reweight(), marley::EventFileReader::next_event(), and HepMC3::ReaderAscii::read_event().

◆ set_units()

void HepMC3::GenEvent::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 865 of file marley_hepmc3.cc.

865 {
866 if ( new_momentum_unit != m_momentum_unit ) {
867 for ( GenParticlePtr& p: m_particles ) {
868 Units::convert(p->m_data.momentum, m_momentum_unit, new_momentum_unit);
869 Units::convert(p->m_data.mass, m_momentum_unit, new_momentum_unit);
870 }
871
872 m_momentum_unit = new_momentum_unit;
873 }
874
875 if ( new_length_unit != m_length_unit ) {
876 for (GenVertexPtr& v: m_vertices) {
877 FourVector &fv = v->m_data.position;
878 if ( !fv.is_zero() ) Units::convert( fv, m_length_unit, new_length_unit );
879 }
880
881 m_length_unit = new_length_unit;
882 }
883}
static void convert(T &m, MomentumUnit from, MomentumUnit to)
Convert FourVector to different momentum unit.
Definition Units.h:81

References HepMC3::Units::convert(), and HepMC3::FourVector::is_zero().

◆ shift_position_by()

void HepMC3::GenEvent::shift_position_by ( const FourVector & delta)

Shift position of all vertices in the event by delta.

Definition at line 906 of file marley_hepmc3.cc.

906 {
907 m_rootvertex->set_position(event_pos() + delta);
908
909 // Offset all vertices
910 for ( GenVertexPtr& v: m_vertices ) {
911 if ( v->has_set_position() ) {
912 v->set_position(v->position() + delta);
913 }
914 }
915}
const FourVector & event_pos() const
Vertex representing the overall event position.

References event_pos().

Referenced by shift_position_to().

◆ shift_position_to()

void HepMC3::GenEvent::shift_position_to ( const FourVector & newpos)
inline

Shift position of all vertices in the event to op.

Definition at line 211 of file GenEvent.h.

211 {
212 const FourVector delta = newpos - event_pos();
213 shift_position_by(delta);
214 }
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.

References event_pos(), and shift_position_by().

Referenced by read_data().

◆ vertices() [1/2]

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

Get/set list of vertices (non-const)

Definition at line 82 of file GenEvent.h.

82{ return m_vertices; }

◆ vertices() [2/2]

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

Get list of vertices (const)

Definition at line 511 of file marley_hepmc3.cc.

511 {
512 return *(reinterpret_cast<const std::vector<ConstGenVertexPtr>*>(&m_vertices));
513}

Referenced by add_attribute(), add_vertex(), attribute(), HepMC3::Print::content(), HepMC3::Print::listing(), HepMC3::ReaderAscii::read_event(), write_data(), and HepMC3::WriterAscii::write_event().

◆ vertices_empty()

bool HepMC3::GenEvent::vertices_empty ( ) const
inline

Vertices empty, HepMC2 compatibility.

Definition at line 97 of file GenEvent.h.

97{ return m_vertices.empty(); }

◆ vertices_size()

int HepMC3::GenEvent::vertices_size ( ) const
inline

Vertices size, HepMC2 compatibility.

Definition at line 95 of file GenEvent.h.

95{ return m_vertices.size(); }

Referenced by add_attributes(), add_attributes(), and add_attributes().

◆ weight() [1/3]

double & HepMC3::GenEvent::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 121 of file GenEvent.h.

121 {
122 if (!run_info()) throw std::runtime_error("GenEvent::weight(const std::string&): named access to event weights requires the event to have a GenRunInfo");
123 int pos = run_info()->weight_index(name);
124 if ( pos < 0 ) throw std::runtime_error("GenEvent::weight(const std::string&): no weight with given name in this run");
125 if ( pos >= int(m_weights.size())) throw std::runtime_error("GenEvent::weight(const std::string&): weight index outside of range");
126 return m_weights[pos];
127 }

References run_info().

◆ weight() [2/3]

double HepMC3::GenEvent::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 114 of file GenEvent.h.

114 {
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 return weight(run_info()->weight_index(name));
117 }
double weight(const unsigned long &index=0) const
Definition GenEvent.h:110

References run_info(), and weight().

◆ weight() [3/3]

double HepMC3::GenEvent::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 110 of file GenEvent.h.

110{ 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; }

References weights().

Referenced by weight().

◆ weight_names()

const std::vector< std::string > & HepMC3::GenEvent::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 130 of file GenEvent.h.

130 {
131 if (!run_info()) throw std::runtime_error("GenEvent::weight_names(): access to event weight names requires the event to have a GenRunInfo");
132 const std::vector<std::string>& weightnames = run_info()->weight_names();
133 if (weightnames.empty()) throw std::runtime_error("GenEvent::weight_names(): no event weight names are registered for this run");
134 return weightnames;
135 }

References run_info().

◆ weights() [1/2]

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

Get event weights as a vector (non-const)

Definition at line 107 of file GenEvent.h.

107{ return m_weights; }

◆ weights() [2/2]

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

Get event weight values as a vector.

Definition at line 105 of file GenEvent.h.

105{ return m_weights; }

Referenced by marley::CommandHandler::cmd_reweight(), HepMC3::Print::content(), read_data(), weight(), write_data(), and HepMC3::WriterAscii::write_event().

◆ write_data()

void HepMC3::GenEvent::write_data ( GenEventData & data) const

Fill GenEventData object.

Definition at line 1093 of file marley_hepmc3.cc.

1093 {
1094 // Reserve memory for containers
1095 data.particles.reserve(this->particles().size());
1096 data.vertices.reserve(this->vertices().size());
1097 data.links1.reserve(this->particles().size()*2);
1098 data.links2.reserve(this->particles().size()*2);
1099 data.attribute_id.reserve(m_attributes.size());
1100 data.attribute_name.reserve(m_attributes.size());
1101 data.attribute_string.reserve(m_attributes.size());
1102
1103 // Fill event data
1104 data.event_number = this->event_number();
1105 data.momentum_unit = this->momentum_unit();
1106 data.length_unit = this->length_unit();
1107 data.event_pos = this->event_pos();
1108
1109 // Fill containers
1110 data.weights = this->weights();
1111
1112 for (const ConstGenParticlePtr& p: this->particles()) {
1113 data.particles.emplace_back(p->data());
1114 }
1115
1116 for (const ConstGenVertexPtr& v: this->vertices()) {
1117 data.vertices.emplace_back(v->data());
1118 int v_id = v->id();
1119
1120 for (const ConstGenParticlePtr& p: v->particles_in()) {
1121 data.links1.emplace_back(p->id());
1122 data.links2.emplace_back(v_id);
1123 }
1124
1125 for (const ConstGenParticlePtr& p: v->particles_out()) {
1126 data.links1.emplace_back(v_id);
1127 data.links2.emplace_back(p->id());
1128 }
1129 }
1130
1131 for (const att_key_t& vt1: this->attributes()) {
1132 for (const att_val_t& vt2: vt1.second) {
1133 std::string st;
1134
1135 bool status = vt2.second->to_string(st);
1136
1137 if ( !status ) {
1138 HEPMC3_WARNING_LEVEL(300,"GenEvent::write_data: problem serializing attribute: " << vt1.first)
1139 }
1140 else {
1141 data.attribute_id.emplace_back(vt2.first);
1142 data.attribute_name.emplace_back(vt1.first);
1143 data.attribute_string.emplace_back(st);
1144 }
1145 }
1146 }
1147}
std::map< std::string, std::map< int, std::shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
Definition GenEvent.h:268
int event_number() const
Get event number.
Definition GenEvent.h:155
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
Definition GenEvent.h:160
const Units::LengthUnit & length_unit() const
Get length unit.
Definition GenEvent.h:162

References HepMC3::GenEventData::attribute_id, HepMC3::GenEventData::attribute_name, HepMC3::GenEventData::attribute_string, attributes(), event_number(), HepMC3::GenEventData::event_number, event_pos(), HepMC3::GenEventData::event_pos, length_unit(), HepMC3::GenEventData::length_unit, HepMC3::GenEventData::links1, HepMC3::GenEventData::links2, momentum_unit(), HepMC3::GenEventData::momentum_unit, particles(), HepMC3::GenEventData::particles, vertices(), HepMC3::GenEventData::vertices, weights(), and HepMC3::GenEventData::weights.

Referenced by GenEvent(), and operator=().


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