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>()), //m_weights(std::vector<double>(1, 1.0)),//Prevent from different number of weights and names
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>()), //m_weights(std::vector<double>(1, 1.0)),//Prevent from different number of weights and names
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( GenVertexPtr v ) {
99  if( v->in_event() ) return;
100  m_vertices.push_back(v);
101 
102  v->m_event = this;
103  v->m_id = -(int)vertices().size();
104 
105  // Add all incoming and outgoing particles and restore their production/end vertices
106  for(auto p: v->particles_in() ) {
107  if(!p->in_event()) add_particle(p);
108  p->m_end_vertex = v->shared_from_this();
109  }
110 
111  for(auto p: v->particles_out() ) {
112  if(!p->in_event()) add_particle(p);
113  p->m_production_vertex = v;
114  }
115 }
116 
117 
118 void GenEvent::remove_particle( GenParticlePtr p ) {
119  if( !p || p->parent_event() != this ) return;
120 
121  DEBUG( 30, "GenEvent::remove_particle - called with particle: "<<p->id() );
122  GenVertexPtr end_vtx = p->end_vertex();
123  if( end_vtx ) {
124  end_vtx->remove_particle_in(p);
125 
126  // If that was the only incoming particle, remove vertex from the event
127  if( end_vtx->particles_in().size() == 0 ) remove_vertex(end_vtx);
128  }
129 
130  GenVertexPtr prod_vtx = p->production_vertex();
131  if( prod_vtx ) {
132  prod_vtx->remove_particle_out(p);
133 
134  // If that was the only outgoing particle, remove vertex from the event
135  if( prod_vtx->particles_out().size() == 0 ) remove_vertex(prod_vtx);
136  }
137 
138  DEBUG( 30, "GenEvent::remove_particle - erasing particle: " << p->id() )
139 
140  int idx = p->id();
141  vector<GenParticlePtr>::iterator it = m_particles.erase(m_particles.begin() + idx-1 );
142 
143  // Remove attributes of this particle
144  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
145  vector<string> atts = p->attribute_names();
146  for(const string &s: atts) {
147  p->remove_attribute(s);
148  }
149 
150  //
151  // Reassign id of attributes with id above this one
152  //
153  vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
154 
155  for(att_key_t& vt1: m_attributes ) {
156  changed_attributes.clear();
157 
158  for ( std::map<int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();++vt2){
159  if( (*vt2).first > p->id() ) {
160  changed_attributes.push_back(*vt2);
161  }
162  }
163 
164  for( att_val_t val: changed_attributes ) {
165  vt1.second.erase(val.first);
166  vt1.second[val.first-1] = val.second;
167  }
168  }
169  // Reassign id of particles with id above this one
170  for(;it != m_particles.end(); ++it) {
171  --((*it)->m_id);
172  }
173 
174  // Finally - set parent event and id of this particle to 0
175  p->m_event = nullptr;
176  p->m_id = 0;
177 }
178 
179  struct sort_by_id_asc {
180  inline bool operator()(const GenParticlePtr& p1, const GenParticlePtr& p2) {
181  return (p1->id() > p2->id());
182  }
183  };
184 
185 void GenEvent::remove_particles( vector<GenParticlePtr> v ) {
186 
187  sort( v.begin(), v.end(), sort_by_id_asc() );
188 
189  for (std::vector<GenParticlePtr>::iterator p=v.begin();p!=v.end();++p) {
190  remove_particle(*p);
191  }
192 }
193 
194 void GenEvent::remove_vertex( GenVertexPtr v ) {
195  if( !v || v->parent_event() != this ) return;
196 
197  DEBUG( 30, "GenEvent::remove_vertex - called with vertex: "<<v->id() );
198  shared_ptr<GenVertex> null_vtx;
199 
200  for(auto p: v->particles_in() ) {
201  p->m_end_vertex = std::weak_ptr<GenVertex>();
202  }
203 
204  for(auto p: v->particles_out() ) {
205  p->m_production_vertex = std::weak_ptr<GenVertex>();
206 
207  // recursive delete rest of the tree
208  remove_particle(p);
209  }
210 
211  // Erase this vertex from vertices list
212  DEBUG( 30, "GenEvent::remove_vertex - erasing vertex: " << v->id() )
213 
214  int idx = -v->id();
215  vector<GenVertexPtr>::iterator it = m_vertices.erase(m_vertices.begin() + idx-1 );
216  // Remove attributes of this vertex
217  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
218  vector<string> atts = v->attribute_names();
219  for(string s: atts) {
220  v->remove_attribute(s);
221  }
222 
223  //
224  // Reassign id of attributes with id below this one
225  //
226 
227  vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
228 
229  for( att_key_t& vt1: m_attributes ) {
230  changed_attributes.clear();
231 
232  for ( std::map<int, shared_ptr<Attribute> >::iterator vt2=vt1.second.begin();vt2!=vt1.second.end();++vt2){
233  if( (*vt2).first < v->id() ) {
234  changed_attributes.push_back(*vt2);
235  }
236  }
237 
238  for( att_val_t val: changed_attributes ) {
239  vt1.second.erase(val.first);
240  vt1.second[val.first+1] = val.second;
241  }
242  }
243 
244  // Reassign id of particles with id above this one
245  for(;it != m_vertices.end(); ++it) {
246  ++((*it)->m_id);
247  }
248 
249  // Finally - set parent event and id of this vertex to 0
250  v->m_event = nullptr;
251  v->m_id = 0;
252 }
253 /// @todo This looks dangerously similar to the recusive event traversel that we forbade in the
254 /// Core library due to wories about generator dependence
255 static bool visit_children(std::map<ConstGenVertexPtr,int> &a, ConstGenVertexPtr v)
256 {
257 for ( ConstGenParticlePtr p: v->particles_out())
258  if (p->end_vertex())
259  {
260  if (a[p->end_vertex()]!=0) return true;
261  else a[p->end_vertex()]++;
262  if (visit_children(a, p->end_vertex())) return true;
263  }
264 return false;
265 }
266 
267 void GenEvent::add_tree( const vector<GenParticlePtr> &parts ) {
268 
269  shared_ptr<IntAttribute> existing_hc=attribute<IntAttribute>("cycles");
270  bool has_cycles=false;
271  std::map<GenVertexPtr,int> sortingv;
272  std::vector<GenVertexPtr> noinv;
273  if (existing_hc) if (existing_hc->value()!=0) has_cycles=true;
274  if(!existing_hc)
275  {
276  for(GenParticlePtr p: parts ) {
277  GenVertexPtr v = p->production_vertex();
278  if(v) sortingv[v]=0;
279  if( !v || v->particles_in().size()==0 ) {
280  GenVertexPtr v2 = p->end_vertex();
281  if(v2) {noinv.push_back(v2); sortingv[v2]=0;}
282  }
283  }
284  for (GenVertexPtr v: noinv){
285  std::map<ConstGenVertexPtr,int> sorting_temp(sortingv.begin(), sortingv.end());
286  has_cycles=(has_cycles||visit_children(sorting_temp, v));
287  }
288  }
289  if (has_cycles) {
290  add_attribute("cycles", std::make_shared<IntAttribute>(1));
291  /* Commented out as improvemnts allow us to do sorting in other way.
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 
297  deque<GenVertexPtr> sorting;
298 
299  // Find all starting vertices (end vertex of particles that have no production vertex)
300  for(auto p: parts ) {
301  const GenVertexPtr &v = p->production_vertex();
302  if( !v || v->particles_in().size()==0 ) {
303  const GenVertexPtr &v2 = p->end_vertex();
304  if(v2) sorting.push_back(v2);
305  }
306  }
307 
309  unsigned int sorting_loop_count = 0;
310  unsigned int max_deque_size = 0;
311  )
312 
313  // Add vertices to the event in topological order
314  while( !sorting.empty() ) {
316  if( sorting.size() > max_deque_size ) max_deque_size = sorting.size();
317  ++sorting_loop_count;
318  )
319 
320  GenVertexPtr &v = sorting.front();
321 
322  bool added = false;
323 
324  // Add all mothers to the front of the list
325  for( auto p: v->particles_in() ) {
326  GenVertexPtr v2 = p->production_vertex();
327  if( v2 && !v2->in_event() && find(sorting.begin(),sorting.end(),v2)==sorting.end()){
328  sorting.push_front(v2);
329  added = true;
330  }
331  }
332 
333  // If we have added at least one production vertex,
334  // our vertex is not the first one on the list
335  if( added ) continue;
336 
337  // If vertex not yet added
338  if( !v->in_event() ) {
339 
340  add_vertex(v);
341 
342  // Add all end vertices to the end of the list
343  for(auto p: v->particles_out() ) {
344  GenVertexPtr v2 = p->end_vertex();
345  if( v2 && !v2->in_event()&& find(sorting.begin(),sorting.end(),v2)==sorting.end() ) {
346  sorting.push_back(v2);
347  }
348  }
349  }
350 
351  sorting.pop_front();
352  }
353 
354  // LL: Make sure root vertex has index zero and is not written out
355  if ( m_rootvertex->id() != 0 ) {
356  const int vx = -1 - m_rootvertex->id();
357  const int rootid = m_rootvertex->id();
358  if ( vx >= 0 && vx < m_vertices.size() && m_vertices[vx] == m_rootvertex ) {
359  auto next = m_vertices.erase(m_vertices.begin() + vx);
360  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
361  for(auto & vt1: m_attributes ) {
362  vector< pair< int, shared_ptr<Attribute> > > changed_attributes;
363  for ( auto vt2 : vt1.second )
364  if( vt2.first <= rootid )
365  changed_attributes.push_back(vt2);
366  for( auto val : changed_attributes ) {
367  vt1.second.erase(val.first);
368  vt1.second[val.first == rootid? 0: val.first + 1] = val.second;
369  }
370  }
371  m_rootvertex->set_id(0);
372  while ( next != m_vertices.end() ) {
373  ++((*next++)->m_id);
374  }
375  } else {
376  WARNING( "ReaderAsciiHepMC2: Suspicious looking rootvertex found. Will try to cope." )
377  }
378  }
379 
381  DEBUG( 6, "GenEvent - particles sorted: "
382  <<this->particles().size()<<", max deque size: "
383  <<max_deque_size<<", iterations: "<<sorting_loop_count )
384  )
385 return;
386 }
387 
388 
389 void GenEvent::reserve(const size_t& parts, const size_t& verts) {
390  m_particles.reserve(parts);
391  m_vertices.reserve(verts);
392 }
393 
394 
395 void GenEvent::set_units( Units::MomentumUnit new_momentum_unit, Units::LengthUnit new_length_unit) {
396  if( new_momentum_unit != m_momentum_unit ) {
397  for( GenParticlePtr p: m_particles ) {
398  Units::convert( p->m_data.momentum, m_momentum_unit, new_momentum_unit );
399  }
400 
401  m_momentum_unit = new_momentum_unit;
402  }
403 
404  if( new_length_unit != m_length_unit ) {
405  for(GenVertexPtr &v: m_vertices ) {
406  FourVector &fv = v->m_data.position;
407  if( !fv.is_zero() ) Units::convert( fv, m_length_unit, new_length_unit );
408  }
409 
410  m_length_unit = new_length_unit;
411  }
412 }
413 
414 
416  return m_rootvertex->data().position;
417 }
418 
419 vector<ConstGenParticlePtr> GenEvent::beams() const {
420  return std::const_pointer_cast<const GenVertex>(m_rootvertex)->particles_out();
421 }
422 
423 const vector<GenParticlePtr> & GenEvent::beams() {
424  return m_rootvertex->particles_out();
425 }
426 
428  m_rootvertex->set_position( event_pos() + delta );
429 
430  // Offset all vertices
431  for ( GenVertexPtr v: m_vertices ) {
432  if ( v->has_set_position() )
433  v->set_position( v->position() + delta );
434  }
435 }
436 
437 
439  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
440  m_event_number = 0;
441  m_rootvertex = make_shared<GenVertex>();
442  m_weights.clear();
443  m_attributes.clear();
444  m_particles.clear();
445  m_vertices.clear();
446 }
447 
448 
449 
450 
451 void GenEvent::remove_attribute(const string &name, const int& id) {
452  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
453  map< string, map<int, shared_ptr<Attribute> > >::iterator i1 =
454  m_attributes.find(name);
455  if( i1 == m_attributes.end() ) return;
456 
457  map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(id);
458  if( i2 == i1->second.end() ) return;
459 
460  i1->second.erase(i2);
461 }
462 
463 vector<string> GenEvent::attribute_names( const int& id) const {
464  vector<string> results;
465 
466  for(const att_key_t& vt1: m_attributes ) {
467  for( const att_val_t& vt2: vt1.second ) {
468  if( vt2.first == id ) results.push_back( vt1.first );
469  }
470  }
471 
472  return results;
473 }
474 
476  // Reserve memory for containers
477  data.particles.reserve( this->particles().size() );
478  data.vertices.reserve( this->vertices().size() );
479  data.links1.reserve( this->particles().size()*2 );
480  data.links2.reserve( this->particles().size()*2 );
481  data.attribute_id.reserve( m_attributes.size() );
482  data.attribute_name.reserve( m_attributes.size() );
483  data.attribute_string.reserve( m_attributes.size() );
484 
485  // Fill event data
486  data.event_number = this->event_number();
487  data.momentum_unit = this->momentum_unit();
488  data.length_unit = this->length_unit();
489  data.event_pos = this->event_pos();
490 
491  // Fill containers
492  data.weights = this->weights();
493 
494  for( ConstGenParticlePtr p: this->particles() ) {
495  data.particles.push_back( p->data() );
496  }
497 
498  for(ConstGenVertexPtr v: this->vertices() ) {
499  data.vertices.push_back( v->data() );
500  int v_id = v->id();
501 
502  for(ConstGenParticlePtr p: v->particles_in() ) {
503  data.links1.push_back( p->id() );
504  data.links2.push_back( v_id );
505  }
506 
507  for(ConstGenParticlePtr p: v->particles_out() ) {
508  data.links1.push_back( v_id );
509  data.links2.push_back( p->id() );
510  }
511  }
512 
513  for( const att_key_t& vt1: this->attributes() ) {
514  for( const att_val_t& vt2: vt1.second ) {
515 
516  string st;
517 
518  bool status = vt2.second->to_string(st);
519 
520  if( !status ) {
521  WARNING( "GenEvent::write_data: problem serializing attribute: "<<vt1.first )
522  }
523  else {
524  data.attribute_id.push_back(vt2.first);
525  data.attribute_name.push_back(vt1.first);
526  data.attribute_string.push_back(st);
527  }
528  }
529  }
530 }
531 
532 
534  this->clear();
535  this->set_event_number( data.event_number );
536 //Note: set_units checks the current unit of event, i.e. applicable only for fully constructed event.
539  this->shift_position_to( data.event_pos );
540 
541  // Fill weights
542  this->weights() = data.weights;
543 
544  // Fill particle information
545  for( const GenParticleData &pd: data.particles ) {
546  GenParticlePtr p = make_shared<GenParticle>(pd);
547 
548  m_particles.push_back(p);
549 
550  p->m_event = this;
551  p->m_id = m_particles.size();
552  }
553 
554  // Fill vertex information
555  for( const GenVertexData &vd: data.vertices ) {
556  GenVertexPtr v = make_shared<GenVertex>(vd);
557 
558  m_vertices.push_back(v);
559 
560  v->m_event = this;
561  v->m_id = -(int)m_vertices.size();
562  }
563 
564  // Restore links
565  for( unsigned int i=0; i<data.links1.size(); ++i) {
566  int id1 = data.links1[i];
567  int id2 = data.links2[i];
568 /* @note:
569 The meaningfull combinations for (id1,id2) are:
570 (+-) -- particle has end vertex
571 (-+) -- particle has production vertex
572 */
573  if ( (id1<0&&id2<0)|| (id1>0&&id2>0) ) { WARNING( "GenEvent::read_data: wrong link: "<<id1<<" "<<id2 ); continue;}
574 
575  if ( id1 > 0 ) { m_vertices[ (-id2)-1 ]->add_particle_in ( m_particles[ id1-1 ] ); continue; }
576  if ( id1 < 0 ) { m_vertices[ (-id1)-1 ]->add_particle_out( m_particles[ id2-1 ] ); continue; }
577  }
578  for (auto p: m_particles) if (!p->production_vertex()) m_rootvertex->add_particle_out(p);
579 
580  // Read attributes
581  for( unsigned int i=0; i<data.attribute_id.size(); ++i) {
582  add_attribute( data.attribute_name[i],
583  make_shared<StringAttribute>(data.attribute_string[i]),
584  data.attribute_id[i] );
585  }
586 }
587 
588 
589 
590 //
591 // Deprecated functions
592 //
593 
595  add_particle( GenParticlePtr(p) );
596 }
597 
598 
600  add_vertex( GenVertexPtr(v) );
601 }
602 
603 
604 void GenEvent::set_beam_particles(GenParticlePtr p1, GenParticlePtr p2) {
605  m_rootvertex->add_particle_out(p1);
606  m_rootvertex->add_particle_out(p2);
607 }
608 
609 void GenEvent::add_beam_particle(GenParticlePtr p1){
610  if( p1->in_event()) if (p1->parent_event()!=this)
611  {
612  WARNING("Attempting to add particle from anothe event. Ignored.")
613  return;
614  }
615  if (p1->production_vertex()) p1->production_vertex()->remove_particle_out(p1);
616 //Particle w/o production vertex is added to root vertex.
617  add_particle(p1);
618  p1->set_status(4);
619  return;
620 }
621 
622 
623 string GenEvent::attribute_as_string(const string &name, const int& id) const {
624  std::lock_guard<std::recursive_mutex> lock(m_lock_attributes);
625  std::map< string, std::map<int, shared_ptr<Attribute> > >::iterator i1 =
626  m_attributes.find(name);
627  if( i1 == m_attributes.end() ) {
628  if ( id == 0 && run_info() ) {
629  return run_info()->attribute_as_string(name);
630  }
631  return string();
632  }
633 
634  std::map<int, shared_ptr<Attribute> >::iterator i2 = i1->second.find(id);
635  if (i2 == i1->second.end() ) return string();
636 
637  if( !i2->second ) return string();
638 
639  string ret;
640  i2->second->to_string(ret);
641 
642  return ret;
643 }
644 
645 } // namespace HepMC3
Units::MomentumUnit m_momentum_unit
Momentum unit.
Definition: GenEvent.h:347
int event_number() const
Get event number.
Definition: GenEvent.h:136
void remove_particle(GenParticlePtr v)
Remove particle from the event.
Definition: GenEvent.cc:118
const Units::MomentumUnit & momentum_unit() const
Get momentum unit.
Definition: GenEvent.h:141
HepMC3 main namespace.
Definition: WriterDOT.h:19
void add_beam_particle(GenParticlePtr p1)
Add particle to root vertex.
Definition: GenEvent.cc:609
const Units::LengthUnit & length_unit() const
Get length unit.
Definition: GenEvent.h:143
void remove_particles(std::vector< GenParticlePtr > v)
Remove a set of particles.
Definition: GenEvent.cc:185
void add_vertex(GenVertexPtr v)
Add vertex.
Definition: GenEvent.cc:98
std::vector< int > attribute_id
Attribute owner id.
Definition: GenEventData.h:54
void write_data(GenEventData &data) const
Fill GenEventData object.
Definition: GenEvent.cc:475
Definition of class GenParticle.
void remove_vertex(GenVertexPtr v)
Remove vertex from the event.
Definition: GenEvent.cc:194
const std::vector< ConstGenVertexPtr > & vertices() const
Get list of vertices (const)
Definition: GenEvent.cc:44
void shift_position_by(const FourVector &delta)
Shift position of all vertices in the event by delta.
Definition: GenEvent.cc:427
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
STL namespace.
std::vector< string > attribute_names(const int &id=0) const
Get list of attribute names.
Definition: GenEvent.cc:463
Definition of class GenVertex.
Stores particle-related information.
Definition: GenParticle.h:30
int event_number
Event number.
Definition: GenEventData.h:27
void add_particle(GenParticlePtr p)
Add particle.
Definition: GenEvent.cc:50
shared_ptr< GenRunInfo > run_info() const
Get a pointer to the the GenRunInfo object.
Definition: GenEvent.h:125
static void convert(FourVector &m, MomentumUnit from, MomentumUnit to)
Convert FourVector to different momentum unit.
Definition: Units.h:76
Definition of struct GenEventData.
Units::MomentumUnit momentum_unit
Momentum unit.
Definition: GenEventData.h:28
bool is_zero() const
Check if the length of this vertex is zero.
Definition: FourVector.h:154
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
const std::vector< double > & weights() const
Get event weight values as a vector.
Definition: GenEvent.h:87
const FourVector & event_pos() const
Vertex representing the overall event position.
Definition: GenEvent.cc:415
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
Stores event-related information.
Definition: GenEvent.h:42
std::map< string, std::map< int, shared_ptr< Attribute > > > attributes() const
Get a copy of the list of attributes.
Definition: GenEvent.h:229
Stores serializable event information.
Definition: GenEventData.h:26
Generic 4-vector.
Definition: FourVector.h:34
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:604
shared_ptr< GenRunInfo > m_run_info
Global run information.
Definition: GenEvent.h:355
void remove_attribute(const string &name, const int &id=0)
Remove attribute.
Definition: GenEvent.cc:451
Stores serializable particle information.
string attribute_as_string(const string &name, const int &id=0) const
Get attribute of any type as string.
Definition: GenEvent.cc:623
static bool visit_children(std::map< ConstGenVertexPtr, int > &a, ConstGenVertexPtr v)
Definition: GenEvent.cc:255
void read_data(const GenEventData &data)
Fill GenEvent based on GenEventData.
Definition: GenEvent.cc:533
std::map< int, shared_ptr< Attribute > >::value_type att_val_t
Attribute map value type.
Definition: GenEvent.h:366
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:40
std::vector< GenParticleData > particles
Particles.
Definition: GenEventData.h:31
void add_tree(const std::vector< GenParticlePtr > &particles)
Add whole tree in topological order.
Definition: GenEvent.cc:267
#define WARNING(MESSAGE)
Macro for printing warning messages.
Definition: Errors.h:26
Units::LengthUnit m_length_unit
Length unit.
Definition: GenEvent.h:349
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:389
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:395
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
GenVertexPtr m_rootvertex
The root vertex is stored outside the normal vertices list to block user access to it...
Definition: GenEvent.h:352
std::vector< ConstGenParticlePtr > beams() const
Vector of beam particles.
Definition: GenEvent.cc:419
Definition of class GenEvent.
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:438
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