![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // Matt.Dobbs@Cern.CH, January 2000 00003 // particle's flow object 00005 00006 #include "HepMC/Flow.h" 00007 #include "HepMC/GenParticle.h" 00008 #include "HepMC/GenVertex.h" 00009 #include "HepMC/SearchVector.h" 00010 00011 namespace HepMC { 00012 00013 Flow::Flow( GenParticle* particle_owner ) 00014 : m_particle_owner(particle_owner) 00015 {} 00016 00017 Flow::Flow( const Flow& inflow ) : 00018 m_particle_owner(inflow.m_particle_owner), 00019 m_icode(inflow.m_icode) 00020 { 00022 } 00023 00024 Flow::~Flow() { 00025 m_icode.clear(); 00026 } 00027 00028 void Flow::swap( Flow & other) 00029 { 00030 std::swap( m_particle_owner, other.m_particle_owner ); 00031 m_icode.swap( other.m_icode ); 00032 } 00033 00034 void Flow::print( std::ostream& ostr ) const { 00035 ostr << "Flow(" << m_particle_owner << "): " << *this << std::endl; 00036 } 00037 00038 std::vector<GenParticle*> Flow::connected_partners( int code, int code_index, 00039 int num_indices ) const { 00048 // 00049 std::vector<GenParticle*> output; 00050 for ( int i = code_index; i!=code_index+num_indices; ++i ) { 00051 if ( icode(i)==code ) { 00052 output.push_back(m_particle_owner); 00053 connected_partners( &output, code, code_index, num_indices ); 00054 break; 00055 } 00056 } 00057 return output; 00058 } 00059 00060 void Flow::connected_partners( std::vector<HepMC::GenParticle*>* output, int code, 00061 int code_index, int num_indices ) const 00062 { 00064 // 00065 if ( !m_particle_owner ) return; // nothing to do 00066 // look for connected partners joined to this m_particle_owner 00067 // through its end_vertex 00068 if ( m_particle_owner->end_vertex() ) { 00069 for ( GenVertex::particle_iterator p 00070 = m_particle_owner->end_vertex()->particles_begin(family); 00071 p != m_particle_owner->end_vertex()->particles_end(family); 00072 ++p ) { 00073 // if the particle has the correct flow code and is not yet in 00074 // the set, then we recursively call connected_partners 00075 for ( int index = code_index; index!=code_index+num_indices; 00076 ++index ){ 00077 if ( (*p)->flow(index)==code && not_in_vector(output,(*p)) ) { 00078 output->push_back(*p); 00079 (*p)->flow().connected_partners( output, code, 00080 code_index, 00081 num_indices ); 00082 } 00083 } 00084 } 00085 } 00086 // same for production_vertex 00087 if ( m_particle_owner->production_vertex() ) { 00088 for ( GenVertex::particle_iterator p 00089 = m_particle_owner->production_vertex()-> 00090 particles_begin( family ); 00091 p != m_particle_owner->production_vertex()-> 00092 particles_end( family ); ++p ) { 00093 // if the particle has the correct flow code and is not yet in 00094 // the set, then we recursively call connected_partners 00095 for ( int index = code_index; index!=code_index+num_indices; 00096 ++index ){ 00097 if ( (*p)->flow(index)==code && not_in_vector(output,(*p)) ) { 00098 output->push_back(*p); 00099 (*p)->flow().connected_partners( output, code, 00100 code_index, 00101 num_indices ); 00102 } 00103 } 00104 } 00105 } 00106 } 00107 00108 std::vector<GenParticle*> Flow::dangling_connected_partners( int code, 00109 int code_index, int num_indices ) const { 00110 std::vector<GenParticle*> output; 00111 std::vector<GenParticle*> visited_particles; 00112 for ( int i = code_index; i!=code_index+num_indices; ++i ) { 00113 if ( icode(i)==code ) { 00114 visited_particles.push_back(m_particle_owner); 00115 dangling_connected_partners( &output, &visited_particles, code, 00116 code_index, num_indices ); 00117 break; 00118 } 00119 } 00120 return output; 00121 } 00122 00123 void Flow::dangling_connected_partners( std::vector<HepMC::GenParticle*>* output, 00124 std::vector<HepMC::GenParticle*>* 00125 visited_particles, 00126 int code, int code_index, 00127 int num_indices ) const 00128 { 00130 // 00131 if ( !m_particle_owner ) return; // nothing to do 00132 int count_partners = 0; 00133 // look for connected partners joined to this m_particle_owner 00134 // through its end_vertex 00135 if ( m_particle_owner->end_vertex() ) { 00136 for ( GenVertex::particle_iterator p 00137 = m_particle_owner->end_vertex()->particles_begin(family); 00138 p != m_particle_owner->end_vertex()->particles_end(family); 00139 ++p ) { 00140 // if the particle has the correct flow code and is not yet in 00141 // the set, then we recursively call connected_partners 00142 for ( int index = code_index; index!=code_index+num_indices; 00143 ++index ){ 00144 if ( (*p)->flow(index)==code ) { 00145 if ( *p!=m_particle_owner ) ++count_partners; 00146 if ( not_in_vector(visited_particles,(*p)) ) { 00147 visited_particles->push_back(*p); 00148 (*p)->flow().dangling_connected_partners( output, 00149 visited_particles, code, 00150 code_index, num_indices ); 00151 00152 } 00153 } 00154 } 00155 } 00156 } 00157 // same for production_vertex 00158 if ( m_particle_owner->production_vertex() ) { 00159 for ( GenVertex::particle_iterator p = m_particle_owner-> 00160 production_vertex()-> 00161 particles_begin( family ); 00162 p != m_particle_owner->production_vertex()-> 00163 particles_end( family ); 00164 ++p ) { 00165 // if the particle has the correct flow code and is not yet in 00166 // the set, then we recursively call connected_partners 00167 for ( int index = code_index; index!=code_index+num_indices; 00168 ++index ){ 00169 if ( (*p)->flow(index)==code ) { 00170 if ( *p!=m_particle_owner ) ++count_partners; 00171 if ( not_in_vector(visited_particles,(*p)) ) { 00172 visited_particles->push_back(*p); 00173 (*p)->flow().dangling_connected_partners( output, 00174 visited_particles, code, 00175 code_index, num_indices ); 00176 00177 } 00178 } 00179 } 00180 } 00181 } 00182 if ( count_partners <= 1 ) output->push_back( m_particle_owner ); 00183 } 00184 00186 // Friends // 00188 00190 std::ostream& operator<<( std::ostream& ostr, const Flow& f ) { 00191 ostr << f.m_icode.size(); 00192 for ( std::map<int,int>::const_iterator i = f.m_icode.begin(); 00193 i != f.m_icode.end(); ++i ) { 00194 ostr << " " << (*i).first << " " << (*i).second; 00195 } 00196 return ostr; 00197 } 00198 00199 } // HepMC 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217