hepmc - Blame information for rev 69

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