hepmc - Blame information for rev 120
Subversion Repositories:
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | garren | 1 | ////////////////////////////////////////////////////////////////////////// |
| 2 | // Matt.Dobbs@Cern.CH, January 2000 | ||
| 3 | // particle's flow object | ||
| 4 | ////////////////////////////////////////////////////////////////////////// | ||
| 5 | |||
| 6 | #include "HepMC/Flow.h" | ||
| 7 | #include "HepMC/GenParticle.h" | ||
| 95 | garren | 8 | #include "HepMC/GenParticleComparison.h" |
| 2 | garren | 9 | #include "HepMC/GenVertex.h" |
| 10 | |||
| 11 | namespace HepMC { | ||
| 12 | |||
| 13 | Flow::Flow( GenParticle* particle_owner ) | ||
| 14 | : m_particle_owner(particle_owner) | ||
| 15 | {} | ||
| 16 | |||
| 17 | Flow::Flow( const Flow& inflow ) : | ||
| 18 | m_particle_owner(inflow.m_particle_owner) | ||
| 19 | { | ||
| 65 | garren | 20 | /// copies both the m_icode AND the m_particle_owner |
| 2 | garren | 21 | *this = inflow; |
| 22 | } | ||
| 23 | |||
| 24 | Flow::~Flow() { | ||
| 25 | m_icode.clear(); | ||
| 26 | } | ||
| 27 | |||
| 28 | void Flow::print( std::ostream& ostr ) const { | ||
| 29 | ostr << "Flow(" << m_particle_owner << "): " << *this << std::endl; | ||
| 30 | } | ||
| 31 | |||
| 95 | garren | 32 | std::set<GenParticle*,GenParticleComparison> Flow::connected_partners( int code, int code_index, |
| 2 | garren | 33 | int num_indices ) const { |
| 65 | garren | 34 | /// Returns all flow partners which have "code" in any of the |
| 35 | /// num_indices beginning with index code_index. | ||
| 36 | /// m_particle_owner is included in the result. | ||
| 37 | /// Return is by value since the set should never be very big. | ||
| 38 | /// EXAMPLE: if you want to find all flow partners that have the same | ||
| 39 | /// code in indices 2,3,4 as particle p has in index 2, you would use: | ||
| 40 | /// set<GenParticle*> result = | ||
| 41 | /// p->flow().connected_partners(p->flow().icode(2),2,3); | ||
| 2 | garren | 42 | // |
| 95 | garren | 43 | std::set<GenParticle*,GenParticleComparison> output; |
| 2 | garren | 44 | for ( int i = code_index; i!=code_index+num_indices; ++i ) { |
| 45 | if ( icode(i)==code ) { | ||
| 46 | output.insert(m_particle_owner); | ||
| 47 | connected_partners( &output, code, code_index, num_indices ); | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | return output; | ||
| 52 | } | ||
| 53 | |||
| 95 | garren | 54 | void Flow::connected_partners( std::set<GenParticle*,GenParticleComparison>* output, int code, |
| 2 | garren | 55 | int code_index, int num_indices ) const |
| 56 | { | ||
| 65 | garren | 57 | /// protected: for recursive use by Flow::connected_partners() |
| 2 | garren | 58 | // |
| 59 | if ( !m_particle_owner ) return; // nothing to do | ||
| 60 | // look for connected partners joined to this m_particle_owner | ||
| 61 | // through its end_vertex | ||
| 62 | if ( m_particle_owner->end_vertex() ) { | ||
| 63 | for ( GenVertex::particle_iterator p | ||
| 64 | = m_particle_owner->end_vertex()->particles_begin(family); | ||
| 65 | p != m_particle_owner->end_vertex()->particles_end(family); | ||
| 66 | ++p ) { | ||
| 67 | // if the particle has the correct flow code and is not yet in | ||
| 68 | // the set, then we recursively call connected_partners | ||
| 69 | for ( int index = code_index; index!=code_index+num_indices; | ||
| 70 | ++index ){ | ||
| 71 | if ( (*p)->flow(index)==code && | ||
| 72 | output->insert(*p).second ) { | ||
| 73 | (*p)->flow().connected_partners( output, code, | ||
| 74 | code_index, | ||
| 75 | num_indices ); | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | // same for production_vertex | ||
| 81 | if ( m_particle_owner->production_vertex() ) { | ||
| 82 | for ( GenVertex::particle_iterator p | ||
| 83 | = m_particle_owner->production_vertex()-> | ||
| 84 | particles_begin( family ); | ||
| 85 | p != m_particle_owner->production_vertex()-> | ||
| 86 | particles_end( family ); ++p ) { | ||
| 87 | // if the particle has the correct flow code and is not yet in | ||
| 88 | // the set, then we recursively call connected_partners | ||
| 89 | for ( int index = code_index; index!=code_index+num_indices; | ||
| 90 | ++index ){ | ||
| 91 | if ( (*p)->flow(index)==code && | ||
| 92 | output->insert(*p).second ) { | ||
| 93 | (*p)->flow().connected_partners( output, code, | ||
| 94 | code_index, | ||
| 95 | num_indices ); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
| 101 | |||
| 95 | garren | 102 | std::set<GenParticle*,GenParticleComparison> Flow::dangling_connected_partners( int code, |
| 2 | garren | 103 | int code_index, int num_indices ) const { |
| 95 | garren | 104 | std::set<GenParticle*,GenParticleComparison> output; |
| 105 | std::set<GenParticle*,GenParticleComparison> visited_particles; | ||
| 2 | garren | 106 | for ( int i = code_index; i!=code_index+num_indices; ++i ) { |
| 107 | if ( icode(i)==code ) { | ||
| 108 | visited_particles.insert(m_particle_owner); | ||
| 109 | dangling_connected_partners( &output, &visited_particles, code, | ||
| 110 | code_index, num_indices ); | ||
| 111 | break; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | return output; | ||
| 115 | } | ||
| 116 | |||
| 95 | garren | 117 | void Flow::dangling_connected_partners( std::set<GenParticle*,GenParticleComparison>* output, |
| 118 | std::set<GenParticle*,GenParticleComparison>* | ||
| 2 | garren | 119 | visited_particles, |
| 120 | int code, int code_index, | ||
| 121 | int num_indices ) const | ||
| 122 | { | ||
| 65 | garren | 123 | /// protected: for recursive use by Flow::dangling_connected_partners |
| 2 | garren | 124 | // |
| 125 | if ( !m_particle_owner ) return; // nothing to do | ||
| 126 | int count_partners = 0; | ||
| 127 | // look for connected partners joined to this m_particle_owner | ||
| 128 | // through its end_vertex | ||
| 129 | if ( m_particle_owner->end_vertex() ) { | ||
| 130 | for ( GenVertex::particle_iterator p | ||
| 131 | = m_particle_owner->end_vertex()->particles_begin(family); | ||
| 132 | p != m_particle_owner->end_vertex()->particles_end(family); | ||
| 133 | ++p ) { | ||
| 134 | // if the particle has the correct flow code and is not yet in | ||
| 135 | // the set, then we recursively call connected_partners | ||
| 136 | for ( int index = code_index; index!=code_index+num_indices; | ||
| 137 | ++index ){ | ||
| 138 | if ( (*p)->flow(index)==code ) { | ||
| 139 | if ( *p!=m_particle_owner ) ++count_partners; | ||
| 140 | if ( visited_particles->insert(*p).second ) { | ||
| 141 | (*p)->flow().dangling_connected_partners( output, | ||
| 142 | visited_particles, code, | ||
| 143 | code_index, num_indices ); | ||
| 144 | |||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | } | ||
| 150 | // same for production_vertex | ||
| 151 | if ( m_particle_owner->production_vertex() ) { | ||
| 152 | for ( GenVertex::particle_iterator p = m_particle_owner-> | ||
| 153 | production_vertex()-> | ||
| 154 | particles_begin( family ); | ||
| 155 | p != m_particle_owner->production_vertex()-> | ||
| 156 | particles_end( family ); | ||
| 157 | ++p ) { | ||
| 158 | // if the particle has the correct flow code and is not yet in | ||
| 159 | // the set, then we recursively call connected_partners | ||
| 160 | for ( int index = code_index; index!=code_index+num_indices; | ||
| 161 | ++index ){ | ||
| 162 | if ( (*p)->flow(index)==code ) { | ||
| 163 | if ( *p!=m_particle_owner ) ++count_partners; | ||
| 164 | if ( visited_particles->insert(*p).second ) { | ||
| 165 | (*p)->flow().dangling_connected_partners( output, | ||
| 166 | visited_particles, code, | ||
| 167 | code_index, num_indices ); | ||
| 168 | |||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | } | ||
| 173 | } | ||
| 174 | if ( count_partners <= 1 ) output->insert( m_particle_owner ); | ||
| 175 | } | ||
| 176 | |||
| 177 | ///////////// | ||
| 178 | // Friends // | ||
| 179 | ///////////// | ||
| 180 | |||
| 69 | garren | 181 | /// send Flow informatin to ostr for printing |
| 2 | garren | 182 | std::ostream& operator<<( std::ostream& ostr, const Flow& f ) { |
| 183 | ostr << f.m_icode.size(); | ||
| 184 | for ( std::map<int,int>::const_iterator i = f.m_icode.begin(); | ||
| 185 | i != f.m_icode.end(); ++i ) { | ||
| 186 | ostr << " " << (*i).first << " " << (*i).second; | ||
| 187 | } | ||
| 188 | return ostr; | ||
| 189 | } | ||
| 190 | |||
| 191 | } // HepMC | ||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | |||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | |||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | |||
| 209 |
