![]() |
HepMC Reference DocumentationHepMC |
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 ( you can ask HepMC::Flow to choose 00032 // a unique code for you using Flow::set_unique_icode() ). 00033 // The first two code indices are reserved for color codes, so we store 00034 // these codes with the particles as follows: 00035 // q2->flow().set_icode(1,678); 00036 // g->flow().set_icode(1,678); 00037 // q3->flow().set_icode(1,678); 00038 // q1->flow().set_icode(1,269); 00039 // g->flow().set_icode(2,269); 00040 // q4->flow().set_icode(1,269); 00041 // later on if we wish to know the color partner of q1 we can ask for a list 00042 // of all particles connected via this code to q1 which do have less than 00043 // 2 color partners using: 00044 // vector<GenParticle*> result=q1->dangling_connected_partners(q1->icode(1),1,2); 00045 // this will return a list containing q1 and q4. 00046 // vector<GenParticle*> result=q1->connected_partners(q1->icode(1),1,2); 00047 // would return a list containing q1, g, and q4. 00048 // 00049 00050 #include <iostream> 00051 #include <map> 00052 #include <vector> 00053 00054 namespace HepMC { 00055 00056 class GenParticle; 00057 00059 00066 class Flow { 00067 00069 friend std::ostream& operator<<( std::ostream& ostr, const Flow& f ); 00070 00071 public: 00073 Flow( GenParticle* particle_owner = 0 ); 00075 Flow( const Flow& ); 00076 virtual ~Flow(); 00078 void swap( Flow & other); 00080 Flow& operator=( const Flow& ); 00082 bool operator==( const Flow& a ) const; //compares only flow 00084 bool operator!=( const Flow& a ) const; //patterns not owner 00085 00087 void print( std::ostream& ostr = std::cout ) const; 00088 00091 std::vector<HepMC::GenParticle*> connected_partners( int code, int code_index =1, 00092 int num_indices = 2 ) const; 00096 std::vector<HepMC::GenParticle*> dangling_connected_partners( int code, 00097 int code_index = 1, int num_indices = 2 ) const; 00098 00100 // access methods // 00102 00104 const GenParticle* particle_owner() const; 00106 int icode( int code_index = 1 ) const; 00108 Flow set_icode( int code_index, int code ); 00110 Flow set_unique_icode( int code_index = 1 ); 00111 00113 // container access // 00115 00117 bool empty() const; 00119 int size() const; 00121 void clear(); 00123 bool erase( int code_index ); 00124 00126 typedef std::map<int,int>::iterator iterator; 00128 typedef std::map<int,int>::const_iterator const_iterator; 00130 iterator begin(); 00132 iterator end(); 00134 const_iterator begin() const; 00136 const_iterator end() const; 00137 00138 protected: // intended for internal use only 00140 void connected_partners( std::vector<HepMC::GenParticle*>* output, 00141 int code, 00142 int code_index, 00143 int num_indices ) const; 00145 void dangling_connected_partners( std::vector<HepMC::GenParticle*>* 00146 output, 00147 std::vector<HepMC::GenParticle*>* 00148 visited_particles, 00149 int code, int code_index, 00150 int num_indices ) const; 00151 private: 00152 GenParticle* m_particle_owner; 00153 std::map<int,int> m_icode; // stores flow patterns as(code_index,icode) 00154 }; 00155 00157 // INLINE Access Methods // 00159 00160 inline const GenParticle* Flow::particle_owner() const { 00161 return m_particle_owner; 00162 } 00163 inline int Flow::icode( int code_index ) const { 00164 std::map<int,int>::const_iterator a = m_icode.find(code_index); 00165 return a==m_icode.end() ? 0 : (*a).second; 00166 } 00167 inline Flow Flow::set_icode( int code_index, int code ) { 00168 m_icode[code_index] = code; 00169 return *this; 00170 } 00171 inline Flow Flow::set_unique_icode( int flow_num ) { 00174 m_icode[flow_num] = size_t(this); 00175 return *this; 00176 } 00177 inline bool Flow::empty() const { return (bool)m_icode.empty(); } 00178 inline int Flow::size() const { return (int)m_icode.size(); } 00179 inline void Flow::clear() { m_icode.clear(); } 00180 inline bool Flow::erase( int code_index ) { 00181 // this will return true if the number of elements removed is nonzero 00182 return m_icode.erase( code_index )==0 ? false : true ; 00183 } 00184 inline Flow::iterator Flow::begin() { return m_icode.begin(); } 00185 inline Flow::iterator Flow::end() { return m_icode.end(); } 00186 inline Flow::const_iterator Flow::begin() const { return m_icode.begin(); } 00187 inline Flow::const_iterator Flow::end() const { return m_icode.end(); } 00188 00190 // INLINE Operators // 00192 00193 inline bool Flow::operator==( const Flow& a ) const { 00197 return (m_icode == a.m_icode); 00198 } 00199 inline bool Flow::operator!=( const Flow& a ) const { 00200 return !( *this == a ); 00201 } 00202 inline Flow& Flow::operator=( const Flow& inflow ) { 00206 // 00207 m_icode = inflow.m_icode; 00208 return *this; 00209 } 00210 00211 } // HepMC 00212 00213 #endif // HEPMC_FLOW_H 00214 //-------------------------------------------------------------------------- 00215