CLHEP/HepMC/Flow.h

00001 //--------------------------------------------------------------------------
00002 #ifndef HEPMC_FLOW_H
00003 #define HEPMC_FLOW_H
00004 
00006 // Matt.Dobbs@Cern.CH, January 2000, 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 // particle's flow object
00011 // keeps track of an arbitrary number of flow patterns within a graph 
00012 // (i.e. color flow, charge flow, lepton number flow, ...) 
00013 // Flow patterns are coded with an integer, in the same manner as in Herwig.
00014 // Note: 0 is NOT allowed as code index nor as flow code since it
00015 //       is used to indicate null.
00017 
00018 // This class can be used to keep track of flow patterns within 
00019 //  a graph. An example is color flow. If we have two quarks going through
00020 //  an s-channel gluon to form two more quarks:
00021 //
00022 //  \q1       /q3   then we can keep track of the color flow with the
00023 //   \_______/      HepMC::Flow class as follows: 
00024 //   /   g   \. 
00025 //  /q2       \q4
00026 //
00027 //  lets say the color flows from q2-->g-->q3  and q1-->g-->q4
00028 //  the individual colors are unimportant, but the flow pattern is.
00029 //  We can capture this flow by assigning the first pattern (q2-->g-->q3)
00030 //  a unique (arbitrary) flow code 678 and the second pattern (q1-->g-->q4)
00031 //  flow code 269.
00032 //  The first two code indices are reserved for color codes, so we store 
00033 //  these codes with the particles as follows:
00034 //    q2->flow().set_icode(1,678);
00035 //    g->flow().set_icode(1,678);
00036 //    q3->flow().set_icode(1,678);
00037 //    q1->flow().set_icode(1,269);
00038 //    g->flow().set_icode(2,269);
00039 //    q4->flow().set_icode(1,269);
00040 //  later on if we wish to know the color partner of q1 we can ask for a list
00041 //  of all particles connected via this code to q1 which do have less than 
00042 //  2 color partners using:
00043 //    set<GenParticle*> result=q1->dangling_connected_partners(q1->icode(1),1,2);
00044 //  this will return a list containing q1 and q4.
00045 //    set<GenParticle*> result=q1->connected_partners(q1->icode(1),1,2);
00046 //  would return a list containing q1, g, and q4.
00047 //
00048 
00049 #include "CLHEP/config/CLHEP.h"
00050 #include "CLHEP/config/iostream.h"
00051 #include <map>
00052 #include <set>
00053 
00054 namespace HepMC {
00055 
00056     class GenParticle;
00057 
00058     class Flow {
00059 
00060         friend std::ostream& operator<<( std::ostream& ostr, const Flow& f );
00061         
00062     public:
00063         Flow( GenParticle* particle_owner = 0 );
00064         Flow( const Flow& );
00065         virtual         ~Flow();
00066         Flow&           operator=( const Flow& );
00067         bool            operator==( const Flow& a ) const; //compares only flow
00068         bool            operator!=( const Flow& a ) const; //patterns not owner
00069 
00070         void            print( std::ostream& ostr = std::cout ) const;
00071 
00072         // returns all connected particles which have "code" in any  of the 
00073         //  num_indices beginning with index code_index.
00074         std::set<GenParticle*> connected_partners( int code, int code_index =1,
00075                                                    int num_indices = 2 ) const;
00076         // same as connected_partners, but returns only those particles which
00077         //  are connected to <=1 other particles (i.e. the flow line "dangles"
00078         //  at these particles)
00079         std::set<GenParticle*> dangling_connected_partners( int code, 
00080                                int code_index = 1, int num_indices = 2 ) const;
00081 
00083         // access methods //
00085         const GenParticle* particle_owner() const;
00086         int             icode( int code_index = 1 ) const;
00087         Flow            set_icode( int code_index, int code );
00088 
00090         // container access //
00092 
00093         bool            empty() const;
00094         int             size() const;
00095         void            clear();
00096         bool            erase( int code_index );
00097 
00098         typedef std::map<int,int>::iterator       iterator;
00099         typedef std::map<int,int>::const_iterator const_iterator;
00100         iterator            begin();
00101         iterator            end();
00102         const_iterator      begin() const;
00103         const_iterator      end() const;
00104 
00105     protected: // intended for internal use only
00106         void            connected_partners( std::set<GenParticle*>* output, 
00107                                             int code,
00108                                             int code_index,
00109                                             int num_indices ) const;
00110         void            dangling_connected_partners( std::set<GenParticle*>* 
00111                                                      output, 
00112                                                      std::set<GenParticle*>*
00113                                                      visited_particles, 
00114                                                      int code, int code_index, 
00115                                                      int num_indices ) const; 
00116     private:
00117         GenParticle*         m_particle_owner;
00118         std::map<int,int> m_icode; // stores flow patterns as(code_index,icode)
00119     };  
00120 
00122     // INLINE Access Methods //
00124 
00125     inline const GenParticle* Flow::particle_owner() const {
00126         return m_particle_owner;
00127     }
00128     inline int Flow::icode( int code_index ) const {
00129         std::map<int,int>::const_iterator a = m_icode.find(code_index);
00130         return a==m_icode.end() ? 0 : (*a).second;
00131     }
00132     inline Flow Flow::set_icode( int code_index, int code ) {
00133         m_icode[code_index] = code;
00134         return *this;
00135     }
00136     inline bool Flow::empty() const { return (bool)m_icode.empty(); }
00137     inline int Flow::size() const { return (int)m_icode.size(); }
00138     inline void Flow::clear() { m_icode.clear(); }
00139     inline bool Flow::erase( int code_index ) {
00140         return (bool)m_icode.erase( code_index );
00141     }
00142     inline Flow::iterator Flow::begin() { return m_icode.begin(); }
00143     inline Flow::iterator Flow::end() { return m_icode.end(); }
00144     inline Flow::const_iterator Flow::begin() const { return m_icode.begin(); }
00145     inline Flow::const_iterator Flow::end() const { return m_icode.end(); }
00146 
00148     // INLINE Operators      //
00150 
00151     inline bool Flow::operator==( const Flow& a ) const {
00152         // equivalent flows have the same flow codes for all flow_numbers 
00153         // (i.e. their m_icode maps are identical), but they need not have the
00154         // same m_particle owner
00155         return (m_icode == a.m_icode);
00156     }
00157     inline bool Flow::operator!=( const Flow& a ) const {
00158         return !( *this == a );
00159     }
00160     inline Flow& Flow::operator=( const Flow& inflow ) {
00161         // copies only the m_icode ... not the particle_owner
00162         // this is intuitive behaviour so you can do
00163         // oneparticle->flow() = otherparticle->flow()
00164         //
00165         m_icode = inflow.m_icode;
00166         return *this;
00167     }
00168 
00169 } // HepMC
00170 
00171 #endif  // HEPMC_FLOW_H
00172 //--------------------------------------------------------------------------
00173 

Class Library for High Energy Physics (version 1.8)