HepMC3 event record library
GenEvent.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 /**
7  * @file GenEvent.cc
8  * @brief Implementation of \b class GenEvent
9  *
10  */
11 #include "HepMC3/GenEvent.h"
12 #include "HepMC3/GenParticle.h"
13 #include "HepMC3/GenVertex.h"
15 
16 #include <deque>
17 #include <algorithm> // sort
18 using namespace std;
19 
20 namespace HepMC3 {
21 
22 GenEvent::GenEvent(Units::MomentumUnit mu,
24  : m_event_number(0), m_weights(std::vector<double>(1, 1.0)),
25  m_momentum_unit(mu), m_length_unit(lu),
26  m_rootvertex(make_shared<GenVertex>()) {}
27 
28 
29 GenEvent::GenEvent(shared_ptr<GenRunInfo> run,
32  : m_event_number(0), m_weights(std::vector<double>(1, 1.0)),
33  m_momentum_unit(mu), m_length_unit(lu),
34  m_rootvertex(make_shared<GenVertex>()),
35  m_run_info(run) {
36  if ( run && !run->weight_names().empty() )
37  m_weights = std::vector<double>(run->weight_names().size(), 1.0);
38 }
39 
40 const std::vector<ConstGenParticlePtr>& GenEvent::particles() const {
41  return *(reinterpret_cast<const std::vector<ConstGenParticlePtr>*>(&m_particles));
42 }
43 
44 const std::vector<ConstGenVertexPtr>& GenEvent::vertices() const {
45  return *(reinterpret_cast<const std::vector<ConstGenVertexPtr>*>(&m_vertices));
46 }
47 
48 
49 // void GenEvent::add_particle( const GenParticlePtr &p ) {
50 void GenEvent::add_particle( GenParticlePtr p ) {
51  if( p->in_event() ) return;
52 
53  m_particles.push_back(p);
54 
55  p->m_event = this;
56  p->m_id = particles().size();
57 
58  // Particles without production vertex are added to the root vertex
59  if( !p->production_vertex() )
60  m_rootvertex->add_particle_out(p);
61 }
62 
63 
65  if (this != &e)
66  {
68  std::lock_guard<std::recursive_mutex> lhs_lk(m_lock_attributes, std::adopt_lock);
69  std::lock_guard<std::recursive_mutex> rhs_lk(e.m_lock_attributes, std::adopt_lock);
70  GenEventData tdata;
71  e.write_data(tdata);
72  read_data(tdata);
73 }
74 }
75 
77  for ( std::map< string, std::map<int, shared_ptr<Attribute> > >::iterator attm=m_attributes.begin();attm!=m_attributes.end();++attm)
78  for ( std::map<int, shared_ptr<Attribute> >::iterator att=attm->second.begin();att!=attm->second.end();++att) att->second->m_event = nullptr;
79 
80  for ( std::vector<GenVertexPtr>::iterator v=m_vertices.begin();v!=m_vertices.end();++v ) if ((*v)->m_event==this) (*v)->m_event=nullptr;
81  for ( std::vector<GenParticlePtr>::iterator p=m_particles.begin();p!=m_particles.end();++p ) if ((*p)->m_event==this) (*p)->m_event=nullptr;
82 }
83 
85  if (this != &e)
86  {
88  std::lock_guard<std::recursive_mutex> lhs_lk(m_lock_attributes, std::adopt_lock);
89  std::lock_guard<std::recursive_mutex> rhs_lk(e.m_lock_attributes, std::adopt_lock);
90  GenEventData tdata;
91  e.write_data(tdata);
92  read_data(tdata);
93  }
94  return *this;
95 }
96 
97 
98 // void GenEvent::add_vertex( const GenVertexPtr &v ) {
99 void GenEvent::add_vertex( GenVertexPtr v ) {
100  if( v->in_event() ) return;
101  m_vertices.push_back(v);
102 
103  v->m_event = this;
104  v->m_id = -(int)vertices().size();
105 
106  // Add all incoming and outgoing particles and restore their production/end vertices
107  for(auto p: v->particles_in() ) {
108  if(!p->in_event()) add_particle(p);
109  p->m_end_vertex = v->shared_from_this();
110  }
111 
112  for(auto p: v->particles_out() ) {
113  if(!p->in_event()) add_particle(p);
114  p->m_production_vertex = v;
115  }
116 }
117 
118 
119 void GenEvent::remove_particle( GenParticlePtr p ) {
120  if( !p || p->parent_event() != this ) return;
121 
122  DEBUG( 30, "GenEvent::remove_particle - called with particle: "<<p->id() );
123  GenVertexPtr end_vtx = p->end_vertex();
124  if( end_vtx ) {
125  end_vtx->remove_particle_in(p);
126 
127  // If that was the only incoming particle, remove vertex from the event
128  if( end_vtx->particles_in().size() == 0 ) remove_vertex(end_vtx);
129  }
130 
131  GenVertexPtr prod_vtx = p->production_vertex();
132  if( prod_vtx ) {
133  prod_vtx->remove_particle_out(p);
134 
135  // If that was the only outgoing particle, remove vertex from the event
136  if( prod_vtx->particles_out().size() == 0 ) remove_vertex(prod_vtx);
137  }
138 
139  DEBUG( 30, "GenEvent::remove_particle - erasing particle: " << p->id() )
140 
141  int idx = p->id();
142  vector<GenParticlePtr>::iterator it = m_particles.erase(m_particles.begin() + idx-1 );
143 
144  // Remove attributes of this particle
145  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
146  vector<string> atts = p->attribute_names();
147  for(const string &s: atts) {
148  p->remove_attribute(s);
149  }
150 
151  //
152  // Reassign id of attributes with id above this one
153  //
154  vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
155 
156  for(att_key_t& vt1: m_attributes ) {
157  changed_attributes.clear();
158 
159  for ( std::map<int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();++vt2){
160  if( (*vt2).first > p->id() ) {
161  changed_attributes.push_back(*vt2);
162  }
163  }
164 
165  for( att_val_t val: changed_attributes ) {
166  vt1.second.erase(val.first);
167  vt1.second[val.first-1] = val.second;
168  }
169  }
170  // Reassign id of particles with id above this one
171  for(;it != m_particles.end(); ++it) {
172  --((*it)->m_id);
173  }
174 
175  // Finally - set parent event and id of this particle to 0
176  p->m_event = nullptr;
177  p->m_id = 0;
178 }
179 
180  struct sort_by_id_asc {
181  inline bool operator()(const GenParticlePtr& p1, const GenParticlePtr& p2) {
182  return (p1->id() > p2->id());
183  }
184  };
185 
186 void GenEvent::remove_particles( vector<GenParticlePtr> v ) {
187 
188  sort( v.begin(), v.end(), sort_by_id_asc() );
189 
190  for (std::vector<GenParticlePtr>::iterator p=v.begin();p!=v.end();++p) {
191  remove_particle(*p);
192  }
193 }
194 
195 void GenEvent::remove_vertex( GenVertexPtr v ) {
196  if( !v || v->parent_event() != this ) return;
197 
198  DEBUG( 30, "GenEvent::remove_vertex - called with vertex: "<<v->id() );
199  shared_ptr<GenVertex> null_vtx;
200 
201  for(auto p: v->particles_in() ) {
202  p->m_end_vertex = std::weak_ptr<GenVertex>();
203  }
204 
205  for(auto p: v->particles_out() ) {
206  p->m_production_vertex = std::weak_ptr<GenVertex>();
207 
208  // recursive delete rest of the tree
209  remove_particle(p);
210  }
211 
212  // Erase this vertex from vertices list
213  DEBUG( 30, "GenEvent::remove_vertex - erasing vertex: " << v->id() )
214 
215  int idx = -v->id();
216  vector<GenVertexPtr>::iterator it = m_vertices.erase(m_vertices.begin() + idx-1 );
217  // Remove attributes of this vertex
218  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
219  vector<string> atts = v->attribute_names();
220  for(string s: atts) {
221  v->remove_attribute(s);
222  }
223 
224  //
225  // Reassign id of attributes with id below this one
226  //
227 
228  vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
229 
230  for( att_key_t& vt1: m_attributes ) {
231  changed_attributes.clear();
232 
233  for ( std::map<int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();++vt2){
234  if( (*vt2).first < v->id() ) {
235  changed_attributes.push_back(*vt2);
236  }
237  }
238 
239  for( att_val_t val: changed_attributes ) {
240  vt1.second.erase(val.first);
241  vt1.second[val.first+1] = val.second;
242  }
243  }
244 
245  // Reassign id of particles with id above this one
246  for(;it != m_vertices.end(); ++it) {
247  ++((*it)->m_id);
248  }
249 
250  // Finally - set parent event and id of this vertex to 0
251  v->m_event = nullptr;
252  v->m_id = 0;
253 }
254 /// @todo This looks dangerously similar to the recusive event traversel that we forbade in the
255 /// Core library due to wories about generator dependence
256 static bool visit_children(std::map<ConstGenVertexPtr,int> &a, ConstGenVertexPtr v)
257 {
258 for ( ConstGenParticlePtr p: v->particles_out())
259  if (p->end_vertex())
260  {
261  if (a[p->end_vertex()]!=0) return true;
262  else a[p->end_vertex()]++;
263  if (visit_children(a, p->end_vertex())) return true;
264  }
265 return false;
266 }
267 
268 void GenEvent::add_tree( const vector<GenParticlePtr> &parts ) {
269 
270  shared_ptr<IntAttribute> existing_hc=attribute<IntAttribute>("cycles");
271  bool has_cycles=false;
272  std::map<GenVertexPtr,int> sortingv;
273  std::vector<GenVertexPtr> noinv;
274  if (existing_hc) if (existing_hc->value()!=0) has_cycles=true;
275  if(!existing_hc)
276  {
277  for(GenParticlePtr p: parts ) {
278  GenVertexPtr v = p->production_vertex();
279  if(v) sortingv[v]=0;
280  if( !v || v->particles_in().size()==0 ) {
281  GenVertexPtr v2 = p->end_vertex();
282  if(v2) {noinv.push_back(v2); sortingv[v2]=0;}
283  }
284  }
285  for (GenVertexPtr v: noinv){
286  std::map<ConstGenVertexPtr,int> sorting_temp(sortingv.begin(), sortingv.end());
287  has_cycles=(has_cycles||visit_children(sorting_temp, v));
288  }
289  }
290  if (has_cycles) {
291  add_attribute("cycles", std::make_shared<IntAttribute>(1));
292  for( std::map<GenVertexPtr,int>::iterator vi=sortingv.begin();vi!=sortingv.end();++vi) if( !vi->first->in_event() ) add_vertex(vi->first);
293  return;
294  }
295 
296  deque<GenVertexPtr> sorting;
297 
298  // Find all starting vertices (end vertex of particles that have no production vertex)
299  for(auto p: parts ) {
300  const GenVertexPtr &v = p->production_vertex();
301  if( !v || v->particles_in().size()==0 ) {
302  const GenVertexPtr &v2 = p->end_vertex();
303  if(v2) sorting.push_back(v2);
304  }
305  }
306 
308  unsigned int sorting_loop_count = 0;
309  unsigned int max_deque_size = 0;
310  )
311 
312  // Add vertices to the event in topological order
313  while( !sorting.empty() ) {
315  if( sorting.size() > max_deque_size ) max_deque_size = sorting.size();
316  ++sorting_loop_count;
317  )
318 
319  GenVertexPtr &v = sorting.front();
320 
321  bool added = false;
322 
323  // Add all mothers to the front of the list
324  for( auto p: v->particles_in() ) {
325  GenVertexPtr v2 = p->production_vertex();
326  if( v2 && !v2->in_event() ) {
327  sorting.push_front(v2);
328  added = true;
329  }
330  }
331 
332  // If we have added at least one production vertex,
333  // our vertex is not the first one on the list
334  if( added ) continue;
335 
336  // If vertex not yet added
337  if( !v->in_event() ) {
338 
339  add_vertex(v);
340 
341  // Add all end vertices to the end of the list
342  for(auto p: v->particles_out() ) {
343  GenVertexPtr v2 = p->end_vertex();
344  if( v2 && !v2->in_event() ) {
345  sorting.push_back(v2);
346  }
347  }
348  }
349 
350  sorting.pop_front();
351  }
352 
354  DEBUG( 6, "GenEvent - particles sorted: "
355  <<this->particles().size()<<", max deque size: "
356  <<max_deque_size<<", iterations: "<<sorting_loop_count )
357  )
358 return;
359 }
360 
361 
362 void GenEvent::reserve(const size_t& parts, const size_t& verts) {
363  m_particles.reserve(parts);
364  m_vertices.reserve(verts);
365 }
366 
367 
368 void GenEvent::set_units( Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit) {
369  if( new_momentum_unit != m_momentum_unit ) {
370  for( GenParticlePtr p: m_particles ) {
371  Units::convert( p->m_data.momentum, m_momentum_unit, new_momentum_unit );
372  }
373 
374  m_momentum_unit = new_momentum_unit;
375  }
376 
377  if( new_length_unit != m_length_unit ) {
378  for(GenVertexPtr &v: m_vertices ) {
379  FourVector &fv = v->m_data.position;
380  if( !fv.is_zero() ) Units::convert( fv, m_length_unit, new_length_unit );
381  }
382 
383  m_length_unit = new_length_unit;
384  }
385 }
386 
387 
389  return m_rootvertex->data().position;
390 }
391 
392 vector<ConstGenParticlePtr> GenEvent::beams() const {
393  return std::const_pointer_cast<const GenVertex>(m_rootvertex)->particles_out();
394 }
395 
396 const vector<GenParticlePtr> & GenEvent::beams() {
397  return m_rootvertex->particles_out();
398 }
399 
401  m_rootvertex->set_position( event_pos() + delta );
402 
403  // Offset all vertices
404  for ( GenVertexPtr v: m_vertices ) {
405  if ( v->has_set_position() )
406  v->set_position( v->position() + delta );
407  }
408 }
409 
410 
412  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
413  m_event_number = 0;
414  m_rootvertex = make_shared<GenVertex>();
415  m_weights.clear();
416  m_attributes.clear();
417  m_particles.clear();
418  m_vertices.clear();
419 }
420 
421 
422 
423 
424 void GenEvent::remove_attribute(const string &name, const int& id) {
425  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
426  map< string, map<int, shared_ptr<Attribute> > >::iterator i1 =
427  m_attributes.find(name);
428  if( i1 == m_attributes.end() ) return;
429 
430  map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(id);
431  if( i2 == i1->second.end() ) return;
432 
433  i1->second.erase(i2);
434 }
435 
436 vector<string> GenEvent::attribute_names( const int& id) const {
437  vector<string> results;
438 
439  for(const att_key_t& vt1: m_attributes ) {
440  for( const att_val_t& vt2: vt1.second ) {
441  if( vt2.first == id ) results.push_back( vt1.first );
442  }
443  }
444 
445  return results;
446 }
447 
449  // Reserve memory for containers
450  data.particles.reserve( this->particles().size() );
451  data.vertices.reserve( this->vertices().size() );
452  data.links1.reserve( this->particles().size()*2 );
453  data.links2.reserve( this->particles().size()*2 );
454  data.attribute_id.reserve( m_attributes.size() );
455  data.attribute_name.reserve( m_attributes.size() );
456  data.attribute_string.reserve( m_attributes.size() );
457 
458  // Fill event data
459  data.event_number = this->event_number();
460  data.momentum_unit = this->momentum_unit();
461  data.length_unit = this->length_unit();
462  data.event_pos = this->event_pos();
463 
464  // Fill containers
465  data.weights = this->weights();
466 
467  for( ConstGenParticlePtr p: this->particles() ) {
468  data.particles.push_back( p->data() );
469  }
470 
471  for(ConstGenVertexPtr v: this->vertices() ) {
472  data.vertices.push_back( v->data() );
473  int v_id = v->id();
474 
475  for(ConstGenParticlePtr p: v->particles_in() ) {
476  data.links1.push_back( p->id() );
477  data.links2.push_back( v_id );
478  }
479 
480  for(ConstGenParticlePtr p: v->particles_out() ) {
481  data.links1.push_back( v_id );
482  data.links2.push_back( p->id() );
483  }
484  }
485 
486  for( const att_key_t& vt1: this->attributes() ) {
487  for( const att_val_t& vt2: vt1.second ) {
488 
489  string st;
490 
491  bool status = vt2.second->to_string(st);
492 
493  if( !status ) {
494  WARNING( "GenEvent::write_data: problem serializing attribute: "<<vt1.first )
495  }
496  else {
497  data.attribute_id.push_back(vt2.first);
498  data.attribute_name.push_back(vt1.first);
499  data.attribute_string.push_back(st);
500  }
501  }
502  }
503 }
504 
505 
507  this->clear();
508  this->set_event_number( data.event_number );
509  this->set_units( data.momentum_unit, data.length_unit );
510  this->shift_position_to( data.event_pos );
511 
512  // Fill weights
513  this->weights() = data.weights;
514 
515  // Fill particle information
516  for( const GenParticleData &pd: data.particles ) {
517  GenParticlePtr p = make_shared<GenParticle>(pd);
518 
519  m_particles.push_back(p);
520 
521  p->m_event = this;
522  p->m_id = m_particles.size();
523  }
524 
525  // Fill vertex information
526  for( const GenVertexData &vd: data.vertices ) {
527  GenVertexPtr v = make_shared<GenVertex>(vd);
528 
529  m_vertices.push_back(v);
530 
531  v->m_event = this;
532  v->m_id = -(int)m_vertices.size();
533  }
534 
535  // Restore links
536  for( unsigned int i=0; i<data.links1.size(); ++i) {
537  int id1 = data.links1[i];
538  int id2 = data.links2[i];
539 
540  if( id1 > 0 ) m_vertices[ (-id2)-1 ]->add_particle_in ( m_particles[ id1-1 ] );
541  else m_vertices[ (-id1)-1 ]->add_particle_out( m_particles[ id2-1 ] );
542  }
543 
544  // Read attributes
545  for( unsigned int i=0; i<data.attribute_id.size(); ++i) {
546  add_attribute( data.attribute_name[i],
547  make_shared<StringAttribute>(data.attribute_string[i]),
548  data.attribute_id[i] );
549  }
550 }
551 
552 
553 
554 //
555 // Deprecated functions
556 //
557 
559  add_particle( GenParticlePtr(p) );
560 }
561 
562 
564  add_vertex( GenVertexPtr(v) );
565 }
566 
567 
568 void GenEvent::set_beam_particles(GenParticlePtr p1, GenParticlePtr p2) {
569  m_rootvertex->add_particle_out(p1);
570  m_rootvertex->add_particle_out(p2);
571 }
572 
573 void GenEvent::add_beam_particle(GenParticlePtr p1){
574  m_rootvertex->add_particle_out(p1);
575 }
576 
577 
578 string GenEvent::attribute_as_string(const string &name, const int& id) const {
579  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
580  std::map< string, std::map<int, shared_ptr<Attribute> > >::iterator i1 =
581  m_attributes.find(name);
582  if( i1 == m_attributes.end() ) {
583  if ( id == 0 && run_info() ) {
584  return run_info()->attribute_as_string(name);
585  }
586  return string();
587  }
588 
589  std::map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(id);
590  if (i2 == i1->second.end() ) return string();
591 
592  if( !i2->second ) return string();
593 
594  string ret;
595  i2->second->to_string(ret);
596 
597  return ret;
598 }
599 
600 } // namespace HepMC3
Units::MomentumUnit m_momentum_unit
Momentum unit.
Definition: GenEvent.h:347
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
Definition: GenEvent.cc:44
void remove_particle(GenParticlePtr v)
Remove particle from the event.
Definition: GenEvent.cc:119
void add_beam_particle(GenParticlePtr p1)
Add particle to root vertex.
Definition: GenEvent.cc:573
void remove_particles(std::vector< GenParticlePtr > v)
Remove a set of particles.
Definition: GenEvent.cc:186
void add_vertex(GenVertexPtr v)
Add vertex.
Definition: GenEvent.cc:99
std::vector< int > attribute_id
Attribute owner id.
Definition: GenEventData.h:54
Definition of class GenParticle.
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.
Definition: GenEvent.cc:195
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.
Definition: GenEvent.cc:400
GenEvent(Units::MomentumUnit momentum_unit=Units::GEV, Units::LengthUnit length_unit=Units::MM)
Event constructor without a run.
Definition: GenEvent.cc:22
Stores vertex-related information.
Definition: GenVertex.h:27
std::vector< int > links2
Second id of the vertex links.
Definition: GenEventData.h:52
std::vector< GenVertexPtr > m_vertices
List of vertices.
Definition: GenEvent.h:338
Definition of class GenVertex.
bool is_zero() const
Check if the length of this vertex is zero.
Definition: FourVector.h:154
Stores particle-related information.
Definition: GenParticle.h:30
const Units::LengthUnit & length_unit() const
Get length unit.
Definition: GenEvent.h:143
int event_number
Event number.
Definition: GenEventData.h:27
void add_particle(GenParticlePtr p)
Add particle.
Definition: GenEvent.cc:50
static void convert(FourVector &m, MomentumUnit from, MomentumUnit to)
Convert FourVector to different momentum unit.
Definition: Units.h:76
Definition of struct GenEventData.
int event_number() const
Get event number.
Definition: GenEvent.h:136
shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
Definition: GenEvent.h:125
Units::MomentumUnit momentum_unit
Momentum unit.
Definition: GenEventData.h:28
const FourVector & event_pos() const
Vertex representing the overall event position.
Definition: GenEvent.cc:388
std::vector< int > links1
First id of the vertex links.
Definition: GenEventData.h:51
#define DEBUG(LEVEL, MESSAGE)
Macro for printing debug messages with appropriate debug level.
Definition: Errors.h:32
FourVector event_pos
Event position.
Definition: GenEventData.h:35
std::vector< std::string > attribute_string
Attribute serialized as string.
Definition: GenEventData.h:56
LengthUnit
Position units.
Definition: Units.h:32
#define DEBUG_CODE_BLOCK(x)
Macro for storing code useful for debugging.
Definition: Errors.h:34
MomentumUnit
Momentum units.
Definition: Units.h:29
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
Definition: GenEvent.h:141
Stores event-related information.
Definition: GenEvent.h:42
Stores serializable event information.
Definition: GenEventData.h:26
Generic 4-vector.
Definition: FourVector.h:34
void write_data(GenEventData &data) const
Fill GenEventData object.
Definition: GenEvent.cc:448
std::recursive_mutex m_lock_attributes
Mutex lock for the m_attibutes map.
Definition: GenEvent.h:369
std::vector< std::string > attribute_name
Attribute name.
Definition: GenEventData.h:55
Stores serializable vertex information.
Definition: GenVertexData.h:22
void set_beam_particles(GenParticlePtr p1, GenParticlePtr p2)
Set incoming beam particles.
Definition: GenEvent.cc:568
void remove_attribute(const string &name, const int &id=0)
Remove attribute.
Definition: GenEvent.cc:424
Stores serializable particle information.
static bool visit_children(std::map< ConstGenVertexPtr, int > &a, ConstGenVertexPtr v)
Definition: GenEvent.cc:256
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
Definition: GenEvent.cc:506
std::map< int, shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
Definition: GenEvent.h:366
std::vector< GenParticleData > particles
Particles.
Definition: GenEventData.h:31
std::vector< ConstGenParticlePtr > beams() const
Vector of beam particles.
Definition: GenEvent.cc:392
string attribute_as_string(const string &name, const int &id=0) const
Get attribute of any type as string.
Definition: GenEvent.cc:578
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
Definition: GenEvent.cc:268
#define WARNING(MESSAGE)
Macro for printing warning messages.
Definition: Errors.h:26
Units::LengthUnit m_length_unit
Length unit.
Definition: GenEvent.h:349
std::map< string, std::map< int, shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
Definition: GenEvent.h:229
std::vector< GenParticlePtr > m_particles
List of particles.
Definition: GenEvent.h:336
void reserve(const size_t &particles, const size_t &vertices=0)
Reserve memory for particles and vertices.
Definition: GenEvent.cc:362
std::map< string, std::map< int, shared_ptr< Attribute > > > m_attributes
Map of event, particle and vertex attributes.
Definition: GenEvent.h:360
void set_units(Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit)
Change event units Converts event from current units to new ones.
Definition: GenEvent.cc:368
void add_attribute(const string &name, const shared_ptr< Attribute > &att, const int &id=0)
Add event attribute to event.
Definition: GenEvent.h:202
int m_event_number
Event number.
Definition: GenEvent.h:341
std::vector< double > weights
Weights.
Definition: GenEventData.h:33
std::vector< GenVertexData > vertices
Vertices.
Definition: GenEventData.h:32
const std::vector< double > & weights() const
Get event weight values as a vector.
Definition: GenEvent.h:87
GenVertexPtr m_rootvertex
The root vertex is stored outside the normal vertices list to block user access to it...
Definition: GenEvent.h:352
Definition of class GenEvent.
std::vector< string > attribute_names(const int &id=0) const
Get list of attribute names.
Definition: GenEvent.cc:436
GenEvent & operator=(const GenEvent &)
Assignment operator.
Definition: GenEvent.cc:84
std::map< string, std::map< int, shared_ptr< Attribute > > >::value_type att_key_t
Attribute map key type.
Definition: GenEvent.h:363
~GenEvent()
Destructor.
Definition: GenEvent.cc:76
void clear()
Remove contents of this event.
Definition: GenEvent.cc:411
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:40
std::vector< double > m_weights
Event weights.
Definition: GenEvent.h:344
Units::LengthUnit length_unit
Length unit.
Definition: GenEventData.h:29
void set_event_number(const int &num)
Set event number.
Definition: GenEvent.h:138
void shift_position_to(const FourVector &newpos)
Shift position of all vertices in the event to op.
Definition: GenEvent.h:188