HepMC Reference Documentation

HepMC

GenVertex.h

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 #ifndef HEPMC_GEN_VERTEX_H
00003 #define HEPMC_GEN_VERTEX_H
00004 
00006 // Matt.Dobbs@Cern.CH, September 1999, refer to:
00007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
00008 // High Energy Physics", Computer Physics Communications (to be published).
00009 //
00010 // GenVertex within an event
00011 // A vertex is indirectly (via particle "edges") linked to other 
00012 //   vertices ("nodes") to form a composite "graph"
00014 
00015 // --> HANDLE COMPILER INCONSISTENCIES
00016 // This pre-compiler directive is included (2002-01-16) to allow compatibility
00017 // with several compilers.
00018 // Mar 27, 2004: HepMC is now standard compliant only. 
00019 //   I've removed forward_iterator, and it will no longer compile on gcc < 3. 
00020 #ifdef __SUNPRO_CC    // Solaris CC 5.2
00021 #define NEED_SOLARIS_FRIEND_FEATURE
00022 #endif // Platform
00023 
00024 #include "HepMC/WeightContainer.h"
00025 #include "HepMC/SimpleVector.h"
00026 #include <iostream>
00027 #include <iterator>
00028 #include <vector>
00029 #include <set>
00030 #include <algorithm>
00031 
00032 namespace HepMC {
00033 
00035     enum IteratorRange { parents, children, family, 
00036                          ancestors, descendants, relatives };
00037     class GenParticle;
00038     class GenEvent;
00039 
00041 
00047     class GenVertex {
00048 
00050         friend std::ostream& operator<<( std::ostream&, const GenVertex& );
00051         friend class GenEvent;
00052 
00053 #ifdef NEED_SOLARIS_FRIEND_FEATURE
00054         // This bit of ugly code is only for CC-5.2 compiler. 
00055         // M.Dobbs 2002/02/19 
00056         // It is not needed by linux gcc, nor Windows Visual C++.
00057     public: 
00058         class vertex_iterator;
00059         friend class vertex_iterator;
00060         class particle_iterator;
00061         friend class particle_iterator;
00062 #endif // NEED_SOLARIS_FRIEND_FEATURE
00063 
00064     public:
00066         GenVertex( const FourVector& position =FourVector(0,0,0,0),
00067                    int id = 0, 
00068                    const WeightContainer& weights = std::vector<double>() );
00069         GenVertex( const GenVertex& invertex );            
00070         virtual    ~GenVertex();
00071 
00072         void swap( GenVertex & other); 
00073         GenVertex& operator= ( const GenVertex& invertex ); 
00074         bool       operator==( const GenVertex& a ) const; 
00075         bool       operator!=( const GenVertex& a ) const; 
00076         void       print( std::ostream& ostr = std::cout ) const; 
00077 
00078         double     check_momentum_conservation() const;
00079 
00081         void       add_particle_in( GenParticle* inparticle );
00083         void       add_particle_out( GenParticle* outparticle );
00088         GenParticle* remove_particle( GenParticle* particle ); 
00089 
00090         operator    HepMC::FourVector() const; 
00091         operator   HepMC::ThreeVector() const; 
00092 
00094         // access methods //
00096 
00098         GenEvent*               parent_event() const;
00100         ThreeVector             point3d() const;
00102         FourVector              position() const;
00104         void                    set_position( const FourVector& position = FourVector(0,0,0,0) );
00107         int                     id() const;  
00108         void                    set_id( int id );  
00109 
00114         int                     barcode() const; 
00115 
00117         bool                    suggest_barcode( int the_bar_code );
00118         
00120         WeightContainer&        weights();
00122         const WeightContainer&  weights() const;
00123 
00125         // Iterators      // users should use prefer to use particle_iterator
00127 
00129         typedef std::vector<HepMC::GenParticle*>::const_iterator 
00130         particles_in_const_iterator;
00132         typedef std::vector<HepMC::GenParticle*>::const_iterator 
00133         particles_out_const_iterator;
00135         particles_in_const_iterator         particles_in_const_begin() const;
00137         particles_in_const_iterator         particles_in_const_end() const;
00139         particles_out_const_iterator        particles_out_const_begin() const;
00141         particles_out_const_iterator        particles_out_const_end() const;
00143         int                                 particles_in_size() const;
00145         int                                 particles_out_size() const;
00146 
00147     protected:
00148         static unsigned int     counter(); 
00149 
00153         void                    set_parent_event_( GenEvent* evt ); 
00154         void                    set_barcode_( int the_bar_code ); 
00155 
00157         // edge_iterator           // (protected - for internal use only)
00159         // If the user wants the functionality of the edge_iterator, he should
00160         // use particle_iterator with IteratorRange = family, parents, children
00161         //
00162 
00164 
00171         class edge_iterator :
00172           public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00173         public:
00174             edge_iterator();
00176             edge_iterator( const GenVertex& vtx, IteratorRange range =family );
00178             edge_iterator( const edge_iterator& p );
00179             virtual        ~edge_iterator();
00181             edge_iterator& operator=( const edge_iterator& p );
00183             GenParticle*      operator*(void) const;
00185             edge_iterator& operator++(void); // Pre-fix increment 
00187             edge_iterator  operator++(int);   // Post-fix increment
00189             bool           operator==( const edge_iterator& a ) const;
00191             bool           operator!=( const edge_iterator& a ) const;
00193             bool           is_parent() const;
00195             bool           is_child() const;
00197             const GenVertex*  vertex_root() const;
00198         private:
00199             const GenVertex*  m_vertex;
00200             IteratorRange  m_range;
00201             std::vector<HepMC::GenParticle*>::const_iterator m_set_iter;
00202             bool           m_is_inparticle_iter;
00203             bool           m_is_past_end;
00204         };
00205         friend class edge_iterator;
00207         int              edges_size( IteratorRange range = family ) const;
00209         edge_iterator    edges_begin( IteratorRange range = family) const;
00211         edge_iterator    edges_end( IteratorRange /* dummy_range */ ) const;
00212 
00213     public:
00215         // vertex_iterator           //
00217 
00219 
00235         class vertex_iterator :
00236           public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00237         public:
00238             vertex_iterator();
00240             vertex_iterator( GenVertex& vtx_root, IteratorRange range );
00242             vertex_iterator( GenVertex& vtx_root, IteratorRange range,
00243                              std::set<const HepMC::GenVertex*>& visited_vertices );
00245             vertex_iterator( const vertex_iterator& v_iter );
00246             virtual             ~vertex_iterator();
00248             vertex_iterator&    operator=( const vertex_iterator& );
00250             GenVertex*          operator*(void) const;
00252             vertex_iterator&    operator++(void);  //Pre-fix increment 
00254             vertex_iterator     operator++(int);   //Post-fix increment
00256             bool                operator==( const vertex_iterator& ) const;
00258             bool                operator!=( const vertex_iterator& ) const;
00260             GenVertex*          vertex_root() const;
00262             IteratorRange       range() const;
00264             void                copy_with_own_set( const vertex_iterator& 
00265                                                    v_iter,
00266                                                    std::set<const HepMC::GenVertex*>& 
00267                                                    visited_vertices );
00268 
00269         protected:                  // intended for internal use only
00271             GenVertex* follow_edge_(); 
00273             void    copy_recursive_iterator_( const vertex_iterator* 
00274                                               recursive_v_iter );
00275         private:
00276             GenVertex*       m_vertex;   // the vertex associated to this iter
00277             IteratorRange    m_range;
00278             std::set<const HepMC::GenVertex*>* m_visited_vertices;
00279             bool             m_it_owns_set;  // true if it is responsible for 
00280                                              // deleting the visited vertex set
00281             edge_iterator    m_edge; // particle edge pointing to return vtx
00282             vertex_iterator* m_recursive_iterator;
00283         };      
00284         friend class vertex_iterator;
00286         vertex_iterator     vertices_begin( IteratorRange range = relatives );
00288         vertex_iterator     vertices_end( IteratorRange /* dummy_range */ );
00289  
00290     public:
00292         // particle_iterator         //
00294 
00296 
00305         class particle_iterator :
00306           public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
00307         public:
00308             particle_iterator();
00310             particle_iterator( GenVertex& vertex_root, IteratorRange range );
00312             particle_iterator( const particle_iterator& );
00313             virtual             ~particle_iterator();
00315             particle_iterator&  operator=( const particle_iterator& );
00317             GenParticle*        operator*(void) const;
00319             particle_iterator&  operator++(void); 
00321             particle_iterator   operator++(int); 
00323             bool                operator==( const particle_iterator& ) const;
00325             bool                operator!=( const particle_iterator& ) const;
00326         protected:
00327             GenParticle*        advance_to_first_(); 
00328         private:
00329             vertex_iterator     m_vertex_iterator;
00330             edge_iterator       m_edge;     // points to the return
00331         };
00332         friend class particle_iterator;
00334         particle_iterator       particles_begin( IteratorRange range 
00335                                                  = relatives );
00337         particle_iterator       particles_end( IteratorRange 
00338                                                /* dummy_range */ );
00339 
00341     protected: 
00343         void delete_adopted_particles();
00345         void remove_particle_in( GenParticle* );
00347         void remove_particle_out( GenParticle* );
00348         
00349     private: // GenVertex data members
00350         FourVector              m_position;      //4-vec of vertex [mm]
00351         std::vector<HepMC::GenParticle*>  m_particles_in;  //all incoming particles
00352         std::vector<HepMC::GenParticle*>  m_particles_out; //all outgoing particles
00353         int                  m_id;
00354         WeightContainer      m_weights;       // weights for this vtx
00355         GenEvent*            m_event;
00356         int                  m_barcode;   // unique identifier in the event
00357 
00358         static unsigned int  s_counter;
00359     };  
00360 
00362     // INLINES access methods //
00364 
00365     inline GenVertex::operator HepMC::FourVector() const { return position(); }
00366 
00367     inline GenVertex::operator HepMC::ThreeVector() const { return point3d(); }
00368 
00369     inline FourVector GenVertex::position() const { return m_position; }
00370 
00371     inline GenEvent* GenVertex::parent_event() const { return m_event; }
00372 
00373     inline ThreeVector GenVertex::point3d() const { 
00374         return ThreeVector(m_position.x(),m_position.y(),m_position.z()); 
00375     }
00376 
00377     inline int GenVertex::id() const { return m_id; }
00378 
00379     inline int  GenVertex::barcode() const { return m_barcode; }
00380     inline void GenVertex::set_barcode_( int bc ) { m_barcode = bc; }
00381 
00382     inline WeightContainer& GenVertex::weights() { return m_weights; }
00383 
00384     inline const WeightContainer& GenVertex::weights() const 
00385     { return m_weights; }
00386 
00387     inline void GenVertex::set_position( const FourVector& position ) {
00388         m_position = position;
00389     }
00390 
00391     inline void GenVertex::set_id( int id ) { m_id = id; }
00392 
00394     // INLINES  //
00396 
00397     inline GenVertex::particles_in_const_iterator 
00398     GenVertex::particles_in_const_begin() const { 
00399         return m_particles_in.begin(); 
00400     }
00401 
00402     inline GenVertex::particles_in_const_iterator 
00403     GenVertex::particles_in_const_end() const { 
00404         return m_particles_in.end(); 
00405     }
00406 
00407     inline GenVertex::particles_out_const_iterator 
00408     GenVertex::particles_out_const_begin() const { 
00409         return m_particles_out.begin();
00410     }
00411 
00412     inline GenVertex::particles_out_const_iterator 
00413     GenVertex::particles_out_const_end() const {        
00414         return m_particles_out.end(); 
00415     }
00416 
00417     inline int GenVertex::particles_in_size() const {
00418         return m_particles_in.size(); 
00419     }
00420 
00421     inline int GenVertex::particles_out_size() const {
00422         return m_particles_out.size(); 
00423     }   
00424 
00425     inline bool GenVertex::edge_iterator::operator==( 
00426         const edge_iterator& a ) const { 
00427         return **this == *a; 
00428     }
00429 
00430     inline bool GenVertex::edge_iterator::operator!=(
00431         const edge_iterator& a ) const { 
00432         return !(**this == *a); 
00433     }
00434 
00435     inline const GenVertex* GenVertex::edge_iterator::vertex_root() const {
00436         return m_vertex;
00437     }
00438 
00439     inline GenVertex::edge_iterator GenVertex::edges_begin( IteratorRange 
00440                                                       range ) const {
00441         return GenVertex::edge_iterator(*this, range);
00442     }
00443 
00444     inline GenVertex::edge_iterator GenVertex::edges_end( IteratorRange 
00445                                                     /* dummy_range */ ) const {
00446         return GenVertex::edge_iterator();
00447     }
00448 
00449     inline bool GenVertex::vertex_iterator::operator==( 
00450         const vertex_iterator& a ) const {
00451         return **this == *a; 
00452     }
00453 
00454     inline bool GenVertex::vertex_iterator::operator!=( 
00455         const vertex_iterator& a ) const {
00456         return !(**this == *a); 
00457     }
00458 
00459     inline GenVertex* GenVertex::vertex_iterator::vertex_root() const {
00460         return m_vertex; 
00461     }
00462 
00463     inline IteratorRange GenVertex::vertex_iterator::range() const {
00464         return m_range; 
00465     }
00466 
00467     inline GenVertex::vertex_iterator GenVertex::vertices_begin( 
00468         IteratorRange range ){
00469         // this is not const because the it could return itself
00470         return vertex_iterator( *this, range );
00471     }
00472 
00473     inline GenVertex::vertex_iterator GenVertex::vertices_end( 
00474         IteratorRange /* dummy_range */ ) {
00475         return vertex_iterator();
00476     }
00477 
00478     inline bool GenVertex::particle_iterator::operator==( 
00479         const particle_iterator& a ) const {
00480         return **this == *a; 
00481     }
00482 
00483     inline bool GenVertex::particle_iterator::operator!=( 
00484         const particle_iterator& a ) const {
00485         return !(**this == *a); 
00486     }
00487 
00488     inline GenVertex::particle_iterator GenVertex::particles_begin( 
00489         IteratorRange range ) {
00490         return particle_iterator( *this, range );
00491     }
00492 
00493     inline GenVertex::particle_iterator GenVertex::particles_end(
00494         IteratorRange /* dummy_range */ ){
00495         return particle_iterator();
00496     }
00497 
00498 } // HepMC
00499 
00500 #endif  // HEPMC_GEN_VERTEX_H
00501 //--------------------------------------------------------------------------
00502 
00503 
00504 
00505 

Generated on Tue Feb 5 13:25:44 2008 for HepMC by  doxygen 1.5.1-3