File indexing completed on 2025-11-03 09:50:42
0001 
0002 #ifndef HEPMC_GEN_VERTEX_H
0003 #define HEPMC_GEN_VERTEX_H
0004 
0005 
0006 
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 
0015 
0016 
0017 
0018 
0019 
0020 #ifdef __SUNPRO_CC    
0021 #define NEED_SOLARIS_FRIEND_FEATURE
0022 #endif 
0023 
0024 #include "HepMC/WeightContainer.h"
0025 #include "HepMC/SimpleVector.h"
0026 #include "HepMC/IteratorRange.h"
0027 #include <iostream>
0028 #include <iterator>
0029 #include <vector>
0030 #include <set>
0031 #include <algorithm>
0032 #include <cstddef>
0033 
0034 namespace HepMC {
0035 
0036     class GenVertexParticleRange;
0037     class GenParticleProductionRange;
0038     class ConstGenParticleProductionRange;
0039     class GenParticleEndRange;
0040     class ConstGenParticleEndRange;
0041 
0042     class GenParticle;
0043     class GenEvent;
0044 
0045     
0046 
0047     
0048     
0049     
0050     
0051     
0052     class GenVertex {
0053 
0054         
0055     friend std::ostream& operator<<( std::ostream&, const GenVertex& );
0056     friend class GenEvent;
0057 
0058 #ifdef NEED_SOLARIS_FRIEND_FEATURE
0059     
0060     
0061     
0062     public: 
0063     class vertex_iterator;
0064     friend class vertex_iterator;
0065     class particle_iterator;
0066     friend class particle_iterator;
0067 #endif 
0068 
0069     public:
0070         
0071     GenVertex( const FourVector& position =FourVector(0,0,0,0),
0072            int id = 0, 
0073            const WeightContainer& weights = std::vector<double>() );
0074     GenVertex( const GenVertex& invertex );            
0075     virtual    ~GenVertex();
0076 
0077         void swap( GenVertex & other); 
0078     GenVertex& operator= ( const GenVertex& invertex ); 
0079     bool       operator==( const GenVertex& a ) const; 
0080     bool       operator!=( const GenVertex& a ) const; 
0081     void       print( std::ostream& ostr = std::cout ) const; 
0082 
0083     double     check_momentum_conservation() const;
0084 
0085     
0086     void       add_particle_in( GenParticle* inparticle );
0087     
0088     void       add_particle_out( GenParticle* outparticle );
0089     
0090     
0091     
0092     
0093     GenParticle* remove_particle( GenParticle* particle ); 
0094 
0095     operator    HepMC::FourVector() const; 
0096     operator   HepMC::ThreeVector() const; 
0097 
0098     
0099     
0100     
0101 
0102     
0103     GenEvent*               parent_event() const;
0104     
0105     ThreeVector             point3d() const;
0106     
0107     const FourVector &      position() const;
0108     
0109     void                    set_position( const FourVector& position = FourVector(0,0,0,0) );
0110     
0111     
0112     int                     id() const;  
0113     void                    set_id( int id );  
0114 
0115     
0116     
0117     
0118     
0119     
0120     
0121     
0122     
0123     
0124     
0125     int                     barcode() const; 
0126 
0127     
0128     bool                    suggest_barcode( int the_bar_code );
0129     
0130     
0131     WeightContainer&        weights();
0132     
0133     const WeightContainer&  weights() const;
0134 
0135     
0136     GenVertexParticleRange particles( IteratorRange range = relatives );
0137     
0138     GenParticleProductionRange particles_in( GenParticle&, IteratorRange range = relatives );
0139     
0140     ConstGenParticleProductionRange particles_in( GenParticle const &, IteratorRange range = relatives ) const;
0141     
0142     GenParticleEndRange particles_out( GenParticle&, IteratorRange range = relatives );
0143     
0144     ConstGenParticleEndRange particles_out( GenParticle const &, IteratorRange range = relatives ) const;
0145 
0146     
0147     
0148     
0149 
0150     
0151     typedef std::vector<HepMC::GenParticle*>::const_iterator 
0152     particles_in_const_iterator;
0153     
0154     typedef std::vector<HepMC::GenParticle*>::const_iterator 
0155     particles_out_const_iterator;
0156     
0157     particles_in_const_iterator         particles_in_const_begin() const;
0158     
0159     particles_in_const_iterator         particles_in_const_end() const;
0160     
0161     particles_out_const_iterator        particles_out_const_begin() const;
0162     
0163     particles_out_const_iterator        particles_out_const_end() const;
0164     
0165     int                                 particles_in_size() const;
0166     
0167     int                                 particles_out_size() const;
0168 
0169     protected:
0170     
0171 
0172     
0173     
0174     
0175     void                    set_parent_event_( GenEvent* evt ); 
0176     void                    set_barcode_( int the_bar_code ); 
0177     void                    change_parent_event_( GenEvent* evt ); 
0178 
0179     
0180     
0181     
0182     
0183     
0184     
0185 
0186     
0187 
0188     
0189     
0190     
0191     
0192     
0193     
0194     class edge_iterator :
0195       public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
0196     public:
0197         edge_iterator();
0198         
0199         edge_iterator( const GenVertex& vtx, IteratorRange range =family );
0200         
0201         edge_iterator( const edge_iterator& p );
0202         virtual        ~edge_iterator();
0203         
0204         edge_iterator& operator=( const edge_iterator& p );
0205         
0206         GenParticle*      operator*(void) const;
0207         
0208         edge_iterator& operator++(void); 
0209         
0210         edge_iterator  operator++(int);   
0211         
0212         bool           operator==( const edge_iterator& a ) const;
0213         
0214         bool           operator!=( const edge_iterator& a ) const;
0215         
0216         bool           is_parent() const;
0217         
0218         bool           is_child() const;
0219         
0220         const GenVertex*  vertex_root() const;
0221     private:
0222         
0223         edge_iterator& operator--(void);
0224         
0225         edge_iterator  operator--(int);
0226     private:
0227         const GenVertex*  m_vertex;
0228         IteratorRange  m_range;
0229         std::vector<HepMC::GenParticle*>::const_iterator m_set_iter;
0230         bool           m_is_inparticle_iter;
0231         bool           m_is_past_end;
0232     };
0233     friend class edge_iterator;
0234     
0235     int              edges_size( IteratorRange range = family ) const;
0236     
0237     edge_iterator    edges_begin( IteratorRange range = family) const;
0238     
0239     edge_iterator    edges_end( IteratorRange  ) const;
0240 
0241     public:
0242     
0243     
0244     
0245 
0246     
0247 
0248     
0249     
0250     
0251     
0252     
0253     
0254     
0255     
0256     
0257     
0258     
0259     
0260     
0261     
0262     
0263     class vertex_iterator :
0264       public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
0265     public:
0266         vertex_iterator();
0267         
0268         vertex_iterator( GenVertex& vtx_root, IteratorRange range );
0269         
0270         vertex_iterator( GenVertex& vtx_root, IteratorRange range,
0271                  std::set<const HepMC::GenVertex*>& visited_vertices );
0272             
0273         vertex_iterator( const vertex_iterator& v_iter );
0274         virtual             ~vertex_iterator();
0275         
0276         vertex_iterator&    operator=( const vertex_iterator& );
0277         
0278         GenVertex*          operator*(void) const;
0279         
0280         vertex_iterator&    operator++(void);  
0281         
0282         vertex_iterator     operator++(int);   
0283         
0284         bool                operator==( const vertex_iterator& ) const;
0285         
0286         bool                operator!=( const vertex_iterator& ) const;
0287         
0288         GenVertex*          vertex_root() const;
0289         
0290         IteratorRange       range() const;
0291         
0292         void                copy_with_own_set( const vertex_iterator& 
0293                            v_iter,
0294                            std::set<const HepMC::GenVertex*>& 
0295                            visited_vertices );
0296 
0297     protected:                  
0298         
0299         GenVertex* follow_edge_(); 
0300         
0301         void    copy_recursive_iterator_( const vertex_iterator* 
0302                           recursive_v_iter );
0303     private:
0304         
0305         vertex_iterator&    operator--(void);
0306         
0307         vertex_iterator     operator--(int);
0308 
0309     private:
0310         GenVertex*       m_vertex;   
0311         IteratorRange    m_range;
0312         std::set<const HepMC::GenVertex*>* m_visited_vertices;
0313         bool             m_it_owns_set;  
0314                                          
0315         edge_iterator    m_edge; 
0316         vertex_iterator* m_recursive_iterator;
0317     };  
0318     friend class vertex_iterator;
0319     
0320     vertex_iterator     vertices_begin( IteratorRange range = relatives );
0321     
0322     vertex_iterator     vertices_end( IteratorRange  );
0323  
0324     public:
0325     
0326     
0327     
0328 
0329     
0330 
0331     
0332     
0333     
0334     
0335     
0336     
0337     
0338     
0339     class particle_iterator :
0340       public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
0341     public:
0342         particle_iterator();
0343         
0344         particle_iterator( GenVertex& vertex_root, IteratorRange range );
0345         
0346         particle_iterator( const particle_iterator& );
0347         virtual             ~particle_iterator();
0348         
0349         particle_iterator&  operator=( const particle_iterator& );
0350         
0351         GenParticle*        operator*(void) const;
0352         
0353         particle_iterator&  operator++(void); 
0354         
0355         particle_iterator   operator++(int); 
0356         
0357         bool                operator==( const particle_iterator& ) const;
0358         
0359         bool                operator!=( const particle_iterator& ) const;
0360     protected:
0361         GenParticle*        advance_to_first_(); 
0362     private:
0363         vertex_iterator     m_vertex_iterator;
0364         edge_iterator       m_edge;     
0365     };
0366     friend class particle_iterator;
0367     
0368     particle_iterator       particles_begin( IteratorRange range 
0369                          = relatives );
0370     
0371     particle_iterator       particles_end( IteratorRange 
0372                             );
0373 
0374     
0375     protected: 
0376         
0377     void delete_adopted_particles();
0378     
0379     void remove_particle_in( GenParticle* );
0380     
0381     void remove_particle_out( GenParticle* );
0382     
0383         
0384     void convert_position( const double& );
0385 
0386     private: 
0387     FourVector              m_position;      
0388     std::vector<HepMC::GenParticle*>  m_particles_in;  
0389     std::vector<HepMC::GenParticle*>  m_particles_out; 
0390     int                  m_id;
0391     WeightContainer      m_weights;       
0392     GenEvent*            m_event;
0393     int                  m_barcode;   
0394 
0395     
0396     };  
0397 
0398     
0399     
0400     
0401 
0402     inline GenVertex::operator HepMC::FourVector() const { return position(); }
0403 
0404     inline GenVertex::operator HepMC::ThreeVector() const { return point3d(); }
0405 
0406     inline const FourVector & GenVertex::position() const { return m_position; }
0407 
0408     inline GenEvent* GenVertex::parent_event() const { return m_event; }
0409 
0410     inline ThreeVector GenVertex::point3d() const { 
0411     return ThreeVector(m_position.x(),m_position.y(),m_position.z()); 
0412     }
0413 
0414     inline int GenVertex::id() const { return m_id; }
0415 
0416     inline int  GenVertex::barcode() const { return m_barcode; }
0417     inline void GenVertex::set_barcode_( int bc ) { m_barcode = bc; }
0418 
0419     inline WeightContainer& GenVertex::weights() { return m_weights; }
0420 
0421     inline const WeightContainer& GenVertex::weights() const 
0422     { return m_weights; }
0423 
0424     inline void GenVertex::set_position( const FourVector& pos ) {
0425     m_position = pos;
0426     }
0427 
0428     inline void GenVertex::set_id( int pid ) { m_id = pid; }
0429 
0430     
0431     
0432     
0433 
0434     inline GenVertex::particles_in_const_iterator 
0435     GenVertex::particles_in_const_begin() const { 
0436     return m_particles_in.begin(); 
0437     }
0438 
0439     inline GenVertex::particles_in_const_iterator 
0440     GenVertex::particles_in_const_end() const { 
0441     return m_particles_in.end(); 
0442     }
0443 
0444     inline GenVertex::particles_out_const_iterator 
0445     GenVertex::particles_out_const_begin() const { 
0446     return m_particles_out.begin();
0447     }
0448 
0449     inline GenVertex::particles_out_const_iterator 
0450     GenVertex::particles_out_const_end() const {    
0451     return m_particles_out.end(); 
0452     }
0453 
0454     inline int GenVertex::particles_in_size() const {
0455     return m_particles_in.size(); 
0456     }
0457 
0458     inline int GenVertex::particles_out_size() const {
0459     return m_particles_out.size(); 
0460     }   
0461 
0462     inline bool GenVertex::edge_iterator::operator==( 
0463     const edge_iterator& a ) const { 
0464     return **this == *a; 
0465     }
0466 
0467     inline bool GenVertex::edge_iterator::operator!=(
0468     const edge_iterator& a ) const { 
0469     return !(**this == *a); 
0470     }
0471 
0472     inline const GenVertex* GenVertex::edge_iterator::vertex_root() const {
0473     return m_vertex;
0474     }
0475 
0476     inline GenVertex::edge_iterator GenVertex::edges_begin( IteratorRange 
0477                               range ) const {
0478     return GenVertex::edge_iterator(*this, range);
0479     }
0480 
0481     inline GenVertex::edge_iterator GenVertex::edges_end( IteratorRange 
0482                              ) const {
0483     return GenVertex::edge_iterator();
0484     }
0485 
0486     inline bool GenVertex::vertex_iterator::operator==( 
0487     const vertex_iterator& a ) const {
0488     return **this == *a; 
0489     }
0490 
0491     inline bool GenVertex::vertex_iterator::operator!=( 
0492     const vertex_iterator& a ) const {
0493     return !(**this == *a); 
0494     }
0495 
0496     inline GenVertex* GenVertex::vertex_iterator::vertex_root() const {
0497     return m_vertex; 
0498     }
0499 
0500     inline IteratorRange GenVertex::vertex_iterator::range() const {
0501     return m_range; 
0502     }
0503 
0504     inline GenVertex::vertex_iterator GenVertex::vertices_begin( 
0505     IteratorRange range ){
0506     
0507     return vertex_iterator( *this, range );
0508     }
0509 
0510     inline GenVertex::vertex_iterator GenVertex::vertices_end( 
0511     IteratorRange  ) {
0512     return vertex_iterator();
0513     }
0514 
0515     inline bool GenVertex::particle_iterator::operator==( 
0516     const particle_iterator& a ) const {
0517     return **this == *a; 
0518     }
0519 
0520     inline bool GenVertex::particle_iterator::operator!=( 
0521     const particle_iterator& a ) const {
0522     return !(**this == *a); 
0523     }
0524 
0525     inline GenVertex::particle_iterator GenVertex::particles_begin( 
0526     IteratorRange range ) {
0527     return particle_iterator( *this, range );
0528     }
0529 
0530     inline GenVertex::particle_iterator GenVertex::particles_end(
0531     IteratorRange  ){
0532     return particle_iterator();
0533     }
0534 
0535 } 
0536 
0537 #endif  
0538 
0539 
0540 
0541 
0542