StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Flow.cc
1 // Matt.Dobbs@Cern.CH, January 2000
3 // particle's flow object
5 
6 #include "HepMC/Flow.h"
7 #include "HepMC/GenParticle.h"
8 #include "HepMC/GenVertex.h"
9 #include "HepMC/SearchVector.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  m_icode(inflow.m_icode)
20  {
22  }
23 
24  Flow::~Flow() {
25  m_icode.clear();
26  }
27 
28  void Flow::swap( Flow & other)
29  {
30  std::swap( m_particle_owner, other.m_particle_owner );
31  m_icode.swap( other.m_icode );
32  }
33 
34  void Flow::print( std::ostream& ostr ) const {
35  ostr << "Flow(" << m_particle_owner << "): " << *this << std::endl;
36  }
37 
38  std::vector<GenParticle*> Flow::connected_partners( int code, int code_index,
39  int num_indices ) const {
48  //
49  std::vector<GenParticle*> output;
50  for ( int i = code_index; i!=code_index+num_indices; ++i ) {
51  if ( icode(i)==code ) {
52  output.push_back(m_particle_owner);
53  connected_partners( &output, code, code_index, num_indices );
54  break;
55  }
56  }
57  return output;
58  }
59 
60  void Flow::connected_partners( std::vector<HepMC::GenParticle*>* output, int code,
61  int code_index, int num_indices ) const
62  {
64  //
65  if ( !m_particle_owner ) return; // nothing to do
66  // look for connected partners joined to this m_particle_owner
67  // through its end_vertex
68  if ( m_particle_owner->end_vertex() ) {
70  = m_particle_owner->end_vertex()->particles_begin(family);
71  p != m_particle_owner->end_vertex()->particles_end(family);
72  ++p ) {
73  // if the particle has the correct flow code and is not yet in
74  // the set, then we recursively call connected_partners
75  for ( int index = code_index; index!=code_index+num_indices;
76  ++index ){
77  if ( (*p)->flow(index)==code && not_in_vector(output,(*p)) ) {
78  output->push_back(*p);
79  (*p)->flow().connected_partners( output, code,
80  code_index,
81  num_indices );
82  }
83  }
84  }
85  }
86  // same for production_vertex
87  if ( m_particle_owner->production_vertex() ) {
89  = m_particle_owner->production_vertex()->
90  particles_begin( family );
91  p != m_particle_owner->production_vertex()->
92  particles_end( family ); ++p ) {
93  // if the particle has the correct flow code and is not yet in
94  // the set, then we recursively call connected_partners
95  for ( int index = code_index; index!=code_index+num_indices;
96  ++index ){
97  if ( (*p)->flow(index)==code && not_in_vector(output,(*p)) ) {
98  output->push_back(*p);
99  (*p)->flow().connected_partners( output, code,
100  code_index,
101  num_indices );
102  }
103  }
104  }
105  }
106  }
107 
108  std::vector<GenParticle*> Flow::dangling_connected_partners( int code,
109  int code_index, int num_indices ) const {
110  std::vector<GenParticle*> output;
111  std::vector<GenParticle*> visited_particles;
112  for ( int i = code_index; i!=code_index+num_indices; ++i ) {
113  if ( icode(i)==code ) {
114  visited_particles.push_back(m_particle_owner);
115  dangling_connected_partners( &output, &visited_particles, code,
116  code_index, num_indices );
117  break;
118  }
119  }
120  return output;
121  }
122 
123  void Flow::dangling_connected_partners( std::vector<HepMC::GenParticle*>* output,
124  std::vector<HepMC::GenParticle*>*
125  visited_particles,
126  int code, int code_index,
127  int num_indices ) const
128  {
130  //
131  if ( !m_particle_owner ) return; // nothing to do
132  int count_partners = 0;
133  // look for connected partners joined to this m_particle_owner
134  // through its end_vertex
135  if ( m_particle_owner->end_vertex() ) {
137  = m_particle_owner->end_vertex()->particles_begin(family);
138  p != m_particle_owner->end_vertex()->particles_end(family);
139  ++p ) {
140  // if the particle has the correct flow code and is not yet in
141  // the set, then we recursively call connected_partners
142  for ( int index = code_index; index!=code_index+num_indices;
143  ++index ){
144  if ( (*p)->flow(index)==code ) {
145  if ( *p!=m_particle_owner ) ++count_partners;
146  if ( not_in_vector(visited_particles,(*p)) ) {
147  visited_particles->push_back(*p);
148  (*p)->flow().dangling_connected_partners( output,
149  visited_particles, code,
150  code_index, num_indices );
151 
152  }
153  }
154  }
155  }
156  }
157  // same for production_vertex
158  if ( m_particle_owner->production_vertex() ) {
159  for ( GenVertex::particle_iterator p = m_particle_owner->
160  production_vertex()->
161  particles_begin( family );
162  p != m_particle_owner->production_vertex()->
163  particles_end( family );
164  ++p ) {
165  // if the particle has the correct flow code and is not yet in
166  // the set, then we recursively call connected_partners
167  for ( int index = code_index; index!=code_index+num_indices;
168  ++index ){
169  if ( (*p)->flow(index)==code ) {
170  if ( *p!=m_particle_owner ) ++count_partners;
171  if ( not_in_vector(visited_particles,(*p)) ) {
172  visited_particles->push_back(*p);
173  (*p)->flow().dangling_connected_partners( output,
174  visited_particles, code,
175  code_index, num_indices );
176 
177  }
178  }
179  }
180  }
181  }
182  if ( count_partners <= 1 ) output->push_back( m_particle_owner );
183  }
184 
186  // Friends //
188 
190  std::ostream& operator<<( std::ostream& ostr, const Flow& f ) {
191  ostr << f.m_icode.size();
192  for ( std::map<int,int>::const_iterator i = f.m_icode.begin();
193  i != f.m_icode.end(); ++i ) {
194  ostr << " " << (*i).first << " " << (*i).second;
195  }
196  return ostr;
197  }
198 
199 } // HepMC
200 
201 
202 
203 
204 
205 
206 
207 
208 
209 
210 
211 
212 
213 
214 
215 
216 
217 
particle_iterator particles_begin(IteratorRange range=relatives)
begin particle range
Definition: GenVertex.h:525
void print(std::ostream &ostr=std::cout) const
print Flow information to ostr
Definition: Flow.cc:34
std::vector< HepMC::GenParticle * > connected_partners(int code, int code_index=1, int num_indices=2) const
Definition: Flow.cc:38
void swap(Flow &other)
swap
Definition: Flow.cc:28
GenVertex * production_vertex() const
pointer to the production vertex
Definition: GenParticle.h:218
particle_iterator particles_end(IteratorRange)
end particle range
Definition: GenVertex.h:530
bool not_in_vector(std::vector< HepMC::GenParticle * > *, GenParticle *)
returns true if it cannot find GenParticle* in the vector
Definition: SearchVector.cc:11
std::vector< HepMC::GenParticle * > dangling_connected_partners(int code, int code_index=1, int num_indices=2) const
Definition: Flow.cc:108
GenVertex * end_vertex() const
pointer to the decay vertex
Definition: GenParticle.h:221
Flow(GenParticle *particle_owner=0)
default constructor
Definition: Flow.cc:13
int icode(int code_index=1) const
flow code
Definition: Flow.h:163
The GenParticle class contains information about generated particles.
Definition: GenParticle.h:60
The flow object.
Definition: Flow.h:66