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::GenVertex Class Reference

Stores vertex-related information. More...

#include <GenVertex.h>

Inheritance diagram for HepMC3::GenVertex:

Public Member Functions

Constructors
 GenVertex (const FourVector &position=FourVector::ZERO_VECTOR())
 Default constructor.
 
 GenVertex (const GenVertexData &data)
 Constructor based on vertex data.
 
Accessors
GenEventparent_event ()
 Get parent event.
 
const GenEventparent_event () const
 Get parent event.
 
bool in_event () const
 Check if this vertex belongs to an event.
 
int id () const
 
int status () const
 Get vertex status code.
 
void set_status (int stat)
 Set vertex status code.
 
const GenVertexDatadata () const
 Get vertex data.
 
void add_particle_in (GenParticlePtr p)
 Add incoming particle.
 
void add_particle_out (GenParticlePtr p)
 Add outgoing particle.
 
void remove_particle_in (GenParticlePtr p)
 Remove incoming particle.
 
void remove_particle_out (GenParticlePtr p)
 Remove outgoing particle.
 
int particles_in_size () const
 Number of incoming particles, HepMC2 compatiility.
 
int particles_out_size () const
 Number of outgoing particles, HepMC2 compatiility.
 
const std::vector< GenParticlePtr > & particles_in ()
 Get list of incoming particles.
 
const std::vector< ConstGenParticlePtr > & particles_in () const
 Get list of incoming particles (for const access)
 
const std::vector< GenParticlePtr > & particles_out ()
 Get list of outgoing particles.
 
const std::vector< ConstGenParticlePtr > & particles_out () const
 Get list of outgoing particles (for const access)
 
const FourVectorposition () const
 Get vertex position.
 
bool has_set_position () const
 Check if position of this vertex is set.
 
void set_position (const FourVector &new_pos)
 Set vertex position.
 
bool add_attribute (const std::string &name, std::shared_ptr< Attribute > att)
 Add event attribute to this vertex.
 
std::vector< std::string > attribute_names () const
 Get list of names of attributes assigned to this particle.
 
void remove_attribute (const std::string &name)
 Remove attribute.
 
template<class T>
std::shared_ptr< T > attribute (const std::string &name) const
 Get attribute of type T.
 
std::string attribute_as_string (const std::string &name) const
 Get attribute of any type as string.
 

Friends

class GenEvent
 

Detailed Description

Stores vertex-related information.

Definition at line 29 of file GenVertex.h.

Constructor & Destructor Documentation

◆ GenVertex() [1/2]

HepMC3::GenVertex::GenVertex ( const FourVector & position = FourVector::ZERO_VECTOR())

Default constructor.

Definition at line 351 of file marley_hepmc3.cc.

351 :
352 m_event(nullptr),
353 m_id(0) {
354 m_data.status = 0;
355 m_data.position = pos;
356}

◆ GenVertex() [2/2]

HepMC3::GenVertex::GenVertex ( const GenVertexData & data)

Constructor based on vertex data.

Definition at line 358 of file marley_hepmc3.cc.

358 :
359 m_event(nullptr),
360 m_id(0),
361 m_data(dat) {
362}

Member Function Documentation

◆ add_attribute()

bool HepMC3::GenVertex::add_attribute ( const std::string & name,
std::shared_ptr< Attribute > att )

Add event attribute to this vertex.

This will overwrite existing attribute if an attribute with the same name is present. The attribute will be stored in the parent_event().

Returns
false if there is no parent_event();

Definition at line 443 of file marley_hepmc3.cc.

443 {
444 if ( !parent_event() ) return false;
445 parent_event()->add_attribute(name, att, id());
446 return true;
447}
void add_attribute(const std::string &name, const std::shared_ptr< Attribute > &att, const int &id=0)
GenEvent * parent_event()
Get parent event.
Definition GenVertex.h:56

References HepMC3::GenEvent::add_attribute(), and parent_event().

◆ add_particle_in()

void HepMC3::GenVertex::add_particle_in ( GenParticlePtr p)

Add incoming particle.

Definition at line 365 of file marley_hepmc3.cc.

365 {
366 if (!p) return;
367
368 // Avoid duplicates
369 if (std::find(particles_in().begin(), particles_in().end(), p) != particles_in().end()) return;
370
371 m_particles_in.emplace_back(p);
372
373 if ( p->end_vertex() ) p->end_vertex()->remove_particle_in(p);
374
375 p->m_end_vertex = shared_from_this();
376
377 if (m_event) m_event->add_particle(p);
378}
const std::vector< GenParticlePtr > & particles_in()
Get list of incoming particles.
Definition GenVertex.h:93

References particles_in().

◆ add_particle_out()

void HepMC3::GenVertex::add_particle_out ( GenParticlePtr p)

Add outgoing particle.

Definition at line 381 of file marley_hepmc3.cc.

381 {
382 if (!p) return;
383
384 // Avoid duplicates
385 if (std::find(particles_out().begin(), particles_out().end(), p) != particles_out().end()) return;
386
387 m_particles_out.emplace_back(p);
388
389 if ( p->production_vertex() ) p->production_vertex()->remove_particle_out(p);
390
391 p->m_production_vertex = shared_from_this();
392
393 if (m_event) m_event->add_particle(p);
394}
const std::vector< GenParticlePtr > & particles_out()
Get list of outgoing particles.
Definition GenVertex.h:97

References particles_out().

◆ attribute()

template<class T>
std::shared_ptr< T > HepMC3::GenVertex::attribute ( const std::string & name) const

Get attribute of type T.

Definition at line 156 of file GenVertex.h.

156 {
157 return parent_event()?
158 parent_event()->attribute<T>(name, id()): std::shared_ptr<T>();
159}
std::shared_ptr< T > attribute(const std::string &name, const int &id=0) const
Get attribute of type T.
Definition GenEvent.h:418
int id() const
Definition GenVertex.h:67

References HepMC3::GenEvent::attribute(), id(), and parent_event().

◆ attribute_as_string()

std::string HepMC3::GenVertex::attribute_as_string ( const std::string & name) const

Get attribute of any type as string.

Definition at line 453 of file marley_hepmc3.cc.

453 {
454 return parent_event() ? parent_event()->attribute_as_string(name, id()) : std::string();
455}
std::string attribute_as_string(const std::string &name, const int &id=0) const
Get attribute of any type as string.

References HepMC3::GenEvent::attribute_as_string(), and parent_event().

◆ attribute_names()

std::vector< std::string > HepMC3::GenVertex::attribute_names ( ) const

Get list of names of attributes assigned to this particle.

Definition at line 457 of file marley_hepmc3.cc.

457 {
458 if ( parent_event() ) return parent_event()->attribute_names(id());
459
460 return {};
461}
std::vector< std::string > attribute_names(const int &id=0) const
Get list of attribute names.

References HepMC3::GenEvent::attribute_names(), and parent_event().

◆ data()

const GenVertexData & HepMC3::GenVertex::data ( ) const
inline

Get vertex data.

Definition at line 75 of file GenVertex.h.

75{ return m_data; }

◆ has_set_position()

bool HepMC3::GenVertex::has_set_position ( ) const
inline

Check if position of this vertex is set.

Definition at line 109 of file GenVertex.h.

109{ return !(m_data.position.is_zero()); }

Referenced by position().

◆ id()

int HepMC3::GenVertex::id ( ) const
inline

Get the vertex unique identifier

Note
This is not the same as id() in HepMC v2, which is now status()

Definition at line 67 of file GenVertex.h.

67{ return m_id; }

Referenced by attribute().

◆ in_event()

bool HepMC3::GenVertex::in_event ( ) const
inline

Check if this vertex belongs to an event.

Definition at line 62 of file GenVertex.h.

62{ return parent_event() != nullptr; }

References parent_event().

◆ parent_event() [1/2]

GenEvent * HepMC3::GenVertex::parent_event ( )
inline

Get parent event.

Definition at line 56 of file GenVertex.h.

56{ return m_event; }

Referenced by add_attribute(), attribute(), attribute_as_string(), attribute_names(), in_event(), position(), and remove_attribute().

◆ parent_event() [2/2]

const GenEvent * HepMC3::GenVertex::parent_event ( ) const
inline

Get parent event.

Definition at line 59 of file GenVertex.h.

59{ return m_event; }

◆ particles_in() [1/2]

const std::vector< GenParticlePtr > & HepMC3::GenVertex::particles_in ( )
inline

Get list of incoming particles.

Definition at line 93 of file GenVertex.h.

93{ return m_particles_in; }

Referenced by add_particle_in().

◆ particles_in() [2/2]

const std::vector< ConstGenParticlePtr > & HepMC3::GenVertex::particles_in ( ) const

Get list of incoming particles (for const access)

Definition at line 411 of file marley_hepmc3.cc.

411 {
412 return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles_in));
413}

◆ particles_in_size()

int HepMC3::GenVertex::particles_in_size ( ) const
inline

Number of incoming particles, HepMC2 compatiility.

Definition at line 87 of file GenVertex.h.

87{ return m_particles_in.size(); }

◆ particles_out() [1/2]

const std::vector< GenParticlePtr > & HepMC3::GenVertex::particles_out ( )
inline

Get list of outgoing particles.

Definition at line 97 of file GenVertex.h.

97{ return m_particles_out; }

Referenced by add_particle_out().

◆ particles_out() [2/2]

const std::vector< ConstGenParticlePtr > & HepMC3::GenVertex::particles_out ( ) const

Get list of outgoing particles (for const access)

Definition at line 415 of file marley_hepmc3.cc.

415 {
416 return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles_out));
417}

◆ particles_out_size()

int HepMC3::GenVertex::particles_out_size ( ) const
inline

Number of outgoing particles, HepMC2 compatiility.

Definition at line 89 of file GenVertex.h.

89{ return m_particles_out.size(); }

◆ position()

const FourVector & HepMC3::GenVertex::position ( ) const

Get vertex position.

Returns the position of this vertex. If a position is not set on this vertex, the production vertices of ancestors are searched to find the inherited position. FourVector(0,0,0,0) is returned if no position information is found.

Definition at line 419 of file marley_hepmc3.cc.

419 {
420 if ( has_set_position() ) return m_data.position;
421
422 // No position information - look at event and/or search ancestors
423 if ( parent_event() )
424 {
425 std::shared_ptr<IntAttribute> cycles = parent_event()->attribute<IntAttribute>("cycles");
426 //This could be a recussive call. Try to prevent it.
427 if (!cycles || cycles->value() == 0)
428 {
429 for (const auto& p: m_particles_in) {
430 ConstGenVertexPtr v = p->production_vertex();
431 if (v) return v->position();
432 }
433 }
434 return parent_event()->event_pos();
435 }
437}
static const FourVector & ZERO_VECTOR()
Static null FourVector = (0,0,0,0)
Definition FourVector.h:306
const FourVector & event_pos() const
Vertex representing the overall event position.
bool has_set_position() const
Check if position of this vertex is set.
Definition GenVertex.h:109

References HepMC3::GenEvent::attribute(), HepMC3::GenEvent::event_pos(), has_set_position(), parent_event(), and HepMC3::FourVector::ZERO_VECTOR().

◆ remove_attribute()

void HepMC3::GenVertex::remove_attribute ( const std::string & name)

Remove attribute.

Definition at line 449 of file marley_hepmc3.cc.

449 {
450 if ( parent_event() ) parent_event()->remove_attribute(name, id());
451}
void remove_attribute(const std::string &name, const int &id=0)
Remove attribute.

References parent_event(), and HepMC3::GenEvent::remove_attribute().

◆ remove_particle_in()

void HepMC3::GenVertex::remove_particle_in ( GenParticlePtr p)

Remove incoming particle.

Definition at line 396 of file marley_hepmc3.cc.

396 {
397 if (!p) return;
398 if (std::find(m_particles_in.begin(), m_particles_in.end(), p) == m_particles_in.end()) return;
399 p->m_end_vertex.reset();
400 m_particles_in.erase(std::remove(m_particles_in.begin(), m_particles_in.end(), p), m_particles_in.end());
401}

◆ remove_particle_out()

void HepMC3::GenVertex::remove_particle_out ( GenParticlePtr p)

Remove outgoing particle.

Definition at line 404 of file marley_hepmc3.cc.

404 {
405 if (!p) return;
406 if (std::find(m_particles_out.begin(), m_particles_out.end(), p) == m_particles_out.end()) return;
407 p->m_production_vertex.reset();
408 m_particles_out.erase(std::remove(m_particles_out.begin(), m_particles_out.end(), p), m_particles_out.end());
409}

◆ set_position()

void HepMC3::GenVertex::set_position ( const FourVector & new_pos)

Set vertex position.

Definition at line 439 of file marley_hepmc3.cc.

439 {
440 m_data.position = new_pos;
441}

◆ set_status()

void HepMC3::GenVertex::set_status ( int stat)
inline

Set vertex status code.

Definition at line 72 of file GenVertex.h.

72{ m_data.status = stat; }

◆ status()

int HepMC3::GenVertex::status ( ) const
inline

Get vertex status code.

Definition at line 70 of file GenVertex.h.

70{ return m_data.status; }

Friends And Related Symbol Documentation

◆ GenEvent

friend class GenEvent
friend

Definition at line 31 of file GenVertex.h.


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