StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenVertex.h
1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_GEN_VERTEX_H
3 #define HEPMC_GEN_VERTEX_H
4 
6 // Matt.Dobbs@Cern.CH, September 1999, refer to:
7 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
8 // High Energy Physics", Computer Physics Communications (to be published).
9 //
10 // GenVertex within an event
11 // A vertex is indirectly (via particle "edges") linked to other
12 // vertices ("nodes") to form a composite "graph"
14 
15 // --> HANDLE COMPILER INCONSISTENCIES
16 // This pre-compiler directive is included (2002-01-16) to allow compatibility
17 // with several compilers.
18 // Mar 27, 2004: HepMC is now standard compliant only.
19 // I've removed forward_iterator, and it will no longer compile on gcc < 3.
20 #ifdef __SUNPRO_CC // Solaris CC 5.2
21 #define NEED_SOLARIS_FRIEND_FEATURE
22 #endif // Platform
23 
24 #include "HepMC/WeightContainer.h"
25 #include "HepMC/SimpleVector.h"
26 #include "HepMC/IteratorRange.h"
27 #include <iostream>
28 #include <iterator>
29 #include <vector>
30 #include <set>
31 #include <algorithm>
32 #include <cstddef>
33 
34 namespace HepMC {
35 
36  class GenVertexParticleRange;
37  class GenParticleProductionRange;
38  class ConstGenParticleProductionRange;
39  class GenParticleEndRange;
40  class ConstGenParticleEndRange;
41 
42  class GenParticle;
43  class GenEvent;
44 
46 
52  class GenVertex {
53 
55  friend std::ostream& operator<<( std::ostream&, const GenVertex& );
56  friend class GenEvent;
57 
58 #ifdef NEED_SOLARIS_FRIEND_FEATURE
59  // This bit of ugly code is only for CC-5.2 compiler.
60  // M.Dobbs 2002/02/19
61  // It is not needed by linux gcc, nor Windows Visual C++.
62  public:
63  class vertex_iterator;
64  friend class vertex_iterator;
65  class particle_iterator;
66  friend class particle_iterator;
67 #endif // NEED_SOLARIS_FRIEND_FEATURE
68 
69  public:
71  GenVertex( const FourVector& position =FourVector(0,0,0,0),
72  int id = 0,
73  const WeightContainer& weights = std::vector<double>() );
74  GenVertex( const GenVertex& invertex );
75  virtual ~GenVertex();
76 
77  void swap( GenVertex & other);
78  GenVertex& operator= ( const GenVertex& invertex );
79  bool operator==( const GenVertex& a ) const;
80  bool operator!=( const GenVertex& a ) const;
81  void print( std::ostream& ostr = std::cout ) const;
82 
83  double check_momentum_conservation() const;
84 
86  void add_particle_in( GenParticle* inparticle );
88  void add_particle_out( GenParticle* outparticle );
94 
95  operator HepMC::FourVector() const;
96  operator HepMC::ThreeVector() const;
97 
99  // access methods //
101 
103  GenEvent* parent_event() const;
105  ThreeVector point3d() const;
107  const FourVector & position() const;
109  void set_position( const FourVector& position = FourVector(0,0,0,0) );
112  int id() const;
113  void set_id( int id );
114 
125  int barcode() const;
126 
128  bool suggest_barcode( int the_bar_code );
129 
133  const WeightContainer& weights() const;
134 
136  GenVertexParticleRange particles( IteratorRange range = relatives );
140  ConstGenParticleProductionRange particles_in( GenParticle const &, IteratorRange range = relatives ) const;
144  ConstGenParticleEndRange particles_out( GenParticle const &, IteratorRange range = relatives ) const;
145 
147  // Iterators // users should use prefer to use particle_iterator
149 
151  typedef std::vector<HepMC::GenParticle*>::const_iterator
154  typedef std::vector<HepMC::GenParticle*>::const_iterator
165  int particles_in_size() const;
167  int particles_out_size() const;
168 
169  protected:
170  //static unsigned int counter(); //!< temporary for debugging
171 
175  void set_parent_event_( GenEvent* evt );
176  void set_barcode_( int the_bar_code );
177  void change_parent_event_( GenEvent* evt );
178 
180  // edge_iterator // (protected - for internal use only)
182  // If the user wants the functionality of the edge_iterator, he should
183  // use particle_iterator with IteratorRange = family, parents, children
184  //
185 
187 
195  public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
196  public:
197  edge_iterator();
199  edge_iterator( const GenVertex& vtx, IteratorRange range =family );
201  edge_iterator( const edge_iterator& p );
202  virtual ~edge_iterator();
206  GenParticle* operator*(void) const;
208  edge_iterator& operator++(void); // Pre-fix increment
210  edge_iterator operator++(int); // Post-fix increment
212  bool operator==( const edge_iterator& a ) const;
214  bool operator!=( const edge_iterator& a ) const;
216  bool is_parent() const;
218  bool is_child() const;
220  const GenVertex* vertex_root() const;
221  private:
223  edge_iterator& operator--(void);
225  edge_iterator operator--(int);
226  private:
227  const GenVertex* m_vertex;
228  IteratorRange m_range;
229  std::vector<HepMC::GenParticle*>::const_iterator m_set_iter;
230  bool m_is_inparticle_iter;
231  bool m_is_past_end;
232  };
233  friend class edge_iterator;
235  int edges_size( IteratorRange range = family ) const;
237  edge_iterator edges_begin( IteratorRange range = family) const;
239  edge_iterator edges_end( IteratorRange /* dummy_range */ ) const;
240 
241  public:
243  // vertex_iterator //
245 
247 
264  public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
265  public:
266  vertex_iterator();
270  vertex_iterator( GenVertex& vtx_root, IteratorRange range,
271  std::set<const HepMC::GenVertex*>& visited_vertices );
273  vertex_iterator( const vertex_iterator& v_iter );
274  virtual ~vertex_iterator();
278  GenVertex* operator*(void) const;
280  vertex_iterator& operator++(void); //Pre-fix increment
282  vertex_iterator operator++(int); //Post-fix increment
284  bool operator==( const vertex_iterator& ) const;
286  bool operator!=( const vertex_iterator& ) const;
288  GenVertex* vertex_root() const;
290  IteratorRange range() const;
292  void copy_with_own_set( const vertex_iterator&
293  v_iter,
294  std::set<const HepMC::GenVertex*>&
295  visited_vertices );
296 
297  protected: // intended for internal use only
302  recursive_v_iter );
303  private:
305  vertex_iterator& operator--(void);
307  vertex_iterator operator--(int);
308 
309  private:
310  GenVertex* m_vertex; // the vertex associated to this iter
311  IteratorRange m_range;
312  std::set<const HepMC::GenVertex*>* m_visited_vertices;
313  bool m_it_owns_set; // true if it is responsible for
314  // deleting the visited vertex set
315  edge_iterator m_edge; // particle edge pointing to return vtx
316  vertex_iterator* m_recursive_iterator;
317  };
318  friend class vertex_iterator;
320  vertex_iterator vertices_begin( IteratorRange range = relatives );
322  vertex_iterator vertices_end( IteratorRange /* dummy_range */ );
323 
324  public:
326  // particle_iterator //
328 
330 
340  public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
341  public:
344  particle_iterator( GenVertex& vertex_root, IteratorRange range );
347  virtual ~particle_iterator();
351  GenParticle* operator*(void) const;
357  bool operator==( const particle_iterator& ) const;
359  bool operator!=( const particle_iterator& ) const;
360  protected:
362  private:
363  vertex_iterator m_vertex_iterator;
364  edge_iterator m_edge; // points to the return
365  };
366  friend class particle_iterator;
369  = relatives );
372  /* dummy_range */ );
373 
375  protected:
384  void convert_position( const double& );
385 
386  private: // GenVertex data members
387  FourVector m_position; //4-vec of vertex [mm]
388  std::vector<HepMC::GenParticle*> m_particles_in; //all incoming particles
389  std::vector<HepMC::GenParticle*> m_particles_out; //all outgoing particles
390  int m_id;
391  WeightContainer m_weights; // weights for this vtx
392  GenEvent* m_event;
393  int m_barcode; // unique identifier in the event
394 
395  //static unsigned int s_counter;
396  };
397 
399  // INLINES access methods //
401 
402  inline GenVertex::operator HepMC::FourVector() const { return position(); }
403 
404  inline GenVertex::operator HepMC::ThreeVector() const { return point3d(); }
405 
406  inline const FourVector & GenVertex::position() const { return m_position; }
407 
408  inline GenEvent* GenVertex::parent_event() const { return m_event; }
409 
410  inline ThreeVector GenVertex::point3d() const {
411  return ThreeVector(m_position.x(),m_position.y(),m_position.z());
412  }
413 
414  inline int GenVertex::id() const { return m_id; }
415 
416  inline int GenVertex::barcode() const { return m_barcode; }
417  inline void GenVertex::set_barcode_( int bc ) { m_barcode = bc; }
418 
419  inline WeightContainer& GenVertex::weights() { return m_weights; }
420 
421  inline const WeightContainer& GenVertex::weights() const
422  { return m_weights; }
423 
424  inline void GenVertex::set_position( const FourVector& pos ) {
425  m_position = pos;
426  }
427 
428  inline void GenVertex::set_id( int pid ) { m_id = pid; }
429 
431  // INLINES //
433 
436  return m_particles_in.begin();
437  }
438 
441  return m_particles_in.end();
442  }
443 
446  return m_particles_out.begin();
447  }
448 
451  return m_particles_out.end();
452  }
453 
454  inline int GenVertex::particles_in_size() const {
455  return m_particles_in.size();
456  }
457 
458  inline int GenVertex::particles_out_size() const {
459  return m_particles_out.size();
460  }
461 
463  const edge_iterator& a ) const {
464  return **this == *a;
465  }
466 
468  const edge_iterator& a ) const {
469  return !(**this == *a);
470  }
471 
473  return m_vertex;
474  }
475 
477  range ) const {
478  return GenVertex::edge_iterator(*this, range);
479  }
480 
482  /* dummy_range */ ) const {
483  return GenVertex::edge_iterator();
484  }
485 
487  const vertex_iterator& a ) const {
488  return **this == *a;
489  }
490 
492  const vertex_iterator& a ) const {
493  return !(**this == *a);
494  }
495 
497  return m_vertex;
498  }
499 
501  return m_range;
502  }
503 
505  IteratorRange range ){
506  // this is not const because the it could return itself
507  return vertex_iterator( *this, range );
508  }
509 
511  IteratorRange /* dummy_range */ ) {
512  return vertex_iterator();
513  }
514 
516  const particle_iterator& a ) const {
517  return **this == *a;
518  }
519 
521  const particle_iterator& a ) const {
522  return !(**this == *a);
523  }
524 
526  IteratorRange range ) {
527  return particle_iterator( *this, range );
528  }
529 
531  IteratorRange /* dummy_range */ ){
532  return particle_iterator();
533  }
534 
535 } // HepMC
536 
537 #endif // HEPMC_GEN_VERTEX_H
538 //--------------------------------------------------------------------------
539 
540 
541 
542 
void convert_position(const double &)
Definition: GenVertex.cc:918
vertex_iterator & operator++(void)
Pre-fix increment.
Definition: GenVertex.cc:709
GenParticleEndRange particles_out(GenParticle &, IteratorRange range=relatives)
outgoing particle range
Definition: GenRanges.cc:51
particle_iterator particles_begin(IteratorRange range=relatives)
begin particle range
Definition: GenVertex.h:525
GenVertex * follow_edge_()
non-null if recursive iter. created
Definition: GenVertex.cc:781
bool operator==(const vertex_iterator &) const
equality
Definition: GenVertex.h:486
const GenVertex * vertex_root() const
root vertex of this iteration
Definition: GenVertex.h:472
bool operator!=(const particle_iterator &) const
inequality
Definition: GenVertex.h:520
int barcode() const
unique identifier
Definition: GenVertex.h:416
edge_iterator edges_end(IteratorRange) const
end range
Definition: GenVertex.h:481
double z() const
return z
Definition: SimpleVector.h:77
vertex_iterator vertices_end(IteratorRange)
end vertex range
Definition: GenVertex.h:510
bool is_parent() const
true if parent of root vtx
Definition: GenVertex.cc:585
std::vector< HepMC::GenParticle * >::const_iterator particles_in_const_iterator
const iterator for incoming particles
Definition: GenVertex.h:152
GenParticle * remove_particle(GenParticle *particle)
remove a particle
Definition: GenVertex.cc:295
edge_iterator edges_begin(IteratorRange range=family) const
begin range
Definition: GenVertex.h:476
void print(std::ostream &ostr=std::cout) const
print vertex information
Definition: GenVertex.cc:145
ThreeVector point3d() const
vertex position
Definition: GenVertex.h:410
void add_particle_in(GenParticle *inparticle)
add incoming particle
Definition: GenVertex.cc:273
GenParticle * operator*(void) const
return a pointer to a particle
Definition: GenVertex.cc:869
void copy_with_own_set(const vertex_iterator &v_iter, std::set< const HepMC::GenVertex * > &visited_vertices)
intended for internal use only.
Definition: GenVertex.cc:758
particles_out_const_iterator particles_out_const_end() const
end iteration of outgoing particles
Definition: GenVertex.h:450
std::vector< HepMC::GenParticle * >::const_iterator particles_out_const_iterator
const iterator for outgoing particles
Definition: GenVertex.h:155
bool suggest_barcode(int the_bar_code)
In general there is no reason to &quot;suggest_barcode&quot;.
Definition: GenVertex.cc:363
GenVertex * vertex_root() const
vertex that this iterator begins from
Definition: GenVertex.h:496
edge_iterator & operator++(void)
Pre-fix increment.
Definition: GenVertex.cc:538
void set_id(int id)
set vertex ID
Definition: GenVertex.h:428
vertex_iterator & operator=(const vertex_iterator &)
make a copy
Definition: GenVertex.cc:657
GenVertexParticleRange acts like a collection of particles.
Definition: GenRanges.h:140
double y() const
return y
Definition: SimpleVector.h:76
void set_position(const FourVector &position=FourVector(0, 0, 0, 0))
set vertex position and time
Definition: GenVertex.h:424
vertex_iterator vertices_begin(IteratorRange range=relatives)
begin vertex range
Definition: GenVertex.h:504
void set_barcode_(int the_bar_code)
set identifier
Definition: GenVertex.h:417
GenVertex contains information about decay vertices.
Definition: GenVertex.h:52
bool is_child() const
true if child of root vtx
Definition: GenVertex.cc:590
The GenEvent class is the core of HepMC.
Definition: GenEvent.h:155
GenParticleEndRange acts like a collection of particles.
Definition: GenRanges.h:224
particle_iterator particles_end(IteratorRange)
end particle range
Definition: GenVertex.h:530
bool operator==(const GenVertex &a) const
equality
Definition: GenVertex.cc:103
void remove_particle_out(GenParticle *)
for internal use only - remove particle from outgoing list
Definition: GenVertex.cc:323
void add_particle_out(GenParticle *outparticle)
add outgoing particle
Definition: GenVertex.cc:284
GenVertex * operator*(void) const
return a pointer to a vertex
Definition: GenVertex.cc:694
particles_in_const_iterator particles_in_const_end() const
end iteration of incoming particles
Definition: GenVertex.h:440
GenVertexParticleRange particles(IteratorRange range=relatives)
particle range
Definition: GenRanges.cc:36
double check_momentum_conservation() const
|Sum (three_mom_in-three_mom_out)|
Definition: GenVertex.cc:253
bool operator!=(const GenVertex &a) const
inequality
Definition: GenVertex.cc:140
void change_parent_event_(GenEvent *evt)
for use with swap
Definition: GenVertex.cc:419
ThreeVector is a simple representation of a position or displacement 3 vector.
Definition: SimpleVector.h:131
double x() const
return x
Definition: SimpleVector.h:75
GenEvent * parent_event() const
pointer to the event that owns this vertex
Definition: GenVertex.h:408
int particles_out_size() const
number of outgoing particles
Definition: GenVertex.h:458
int id() const
vertex ID
Definition: GenVertex.h:414
bool operator==(const edge_iterator &a) const
equality
Definition: GenVertex.h:462
void remove_particle_in(GenParticle *)
for internal use only - remove particle from incoming list
Definition: GenVertex.cc:317
particles_out_const_iterator particles_out_const_begin() const
begin iteration of outgoing particles
Definition: GenVertex.h:445
friend std::ostream & operator<<(std::ostream &, const GenVertex &)
print vertex information
Definition: GenVertex.cc:440
edge_iterator & operator=(const edge_iterator &p)
make a copy
Definition: GenVertex.cc:523
GenParticleProductionRange acts like a collection of particles.
Definition: GenRanges.h:170
particle_iterator & operator++(void)
Pre-fix increment.
Definition: GenVertex.cc:874
WeightContainer & weights()
direct access to the weights container is allowed.
Definition: GenVertex.h:419
const FourVector & position() const
vertex position and time
Definition: GenVertex.h:406
void set_parent_event_(GenEvent *evt)
set parent event
Definition: GenVertex.cc:388
FourVector is a simple representation of a physics 4 vector.
Definition: SimpleVector.h:42
bool operator!=(const edge_iterator &a) const
inequality
Definition: GenVertex.h:467
IteratorRange
type of iteration
Definition: IteratorRange.h:17
GenParticle * advance_to_first_()
&quot;first&quot; particle
Definition: GenVertex.cc:900
int edges_size(IteratorRange range=family) const
size
Definition: GenVertex.cc:595
Container for the Weights associated with an event or vertex.
void copy_recursive_iterator_(const vertex_iterator *recursive_v_iter)
copy recursive iterator
Definition: GenVertex.cc:817
bool operator==(const particle_iterator &) const
equality
Definition: GenVertex.h:515
GenVertex(const FourVector &position=FourVector(0, 0, 0, 0), int id=0, const WeightContainer &weights=std::vector< double >())
default constructor
Definition: GenVertex.cc:14
particles_in_const_iterator particles_in_const_begin() const
begin iteration of incoming particles
Definition: GenVertex.h:435
int particles_in_size() const
number of incoming particles
Definition: GenVertex.h:454
GenParticle * operator*(void) const
return a pointer to a particle
Definition: GenVertex.cc:533
void delete_adopted_particles()
for internal use only
Definition: GenVertex.cc:329
void swap(GenVertex &other)
swap
Definition: GenVertex.cc:71
GenParticleProductionRange particles_in(GenParticle &, IteratorRange range=relatives)
incoming particle range
Definition: GenRanges.cc:41
IteratorRange range() const
iterator range
Definition: GenVertex.h:500
particle_iterator & operator=(const particle_iterator &)
make a copy
Definition: GenVertex.cc:862
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60
bool operator!=(const vertex_iterator &) const
inequality
Definition: GenVertex.h:491
GenVertex & operator=(const GenVertex &invertex)
shallow
Definition: GenVertex.cc:82