StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Flow.h
1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_FLOW_H
3 #define HEPMC_FLOW_H
4 
6 // Matt.Dobbs@Cern.CH, January 2000, refer to:
7 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
8 // High Energy Physics", Computer Physics Communications (to be published).
9 //
10 // particle's flow object
11 // keeps track of an arbitrary number of flow patterns within a graph
12 // (i.e. color flow, charge flow, lepton number flow, ...)
13 // Flow patterns are coded with an integer, in the same manner as in Herwig.
14 // Note: 0 is NOT allowed as code index nor as flow code since it
15 // is used to indicate null.
17 
18 // This class can be used to keep track of flow patterns within
19 // a graph. An example is color flow. If we have two quarks going through
20 // an s-channel gluon to form two more quarks:
21 //
22 // \q1 /q3 then we can keep track of the color flow with the
23 // \_______/ HepMC::Flow class as follows:
24 // / g \.
25 // /q2 \q4
26 //
27 // lets say the color flows from q2-->g-->q3 and q1-->g-->q4
28 // the individual colors are unimportant, but the flow pattern is.
29 // We can capture this flow by assigning the first pattern (q2-->g-->q3)
30 // a unique (arbitrary) flow code 678 and the second pattern (q1-->g-->q4)
31 // flow code 269 ( you can ask HepMC::Flow to choose
32 // a unique code for you using Flow::set_unique_icode() ).
33 // The first two code indices are reserved for color codes, so we store
34 // these codes with the particles as follows:
35 // q2->flow().set_icode(1,678);
36 // g->flow().set_icode(1,678);
37 // q3->flow().set_icode(1,678);
38 // q1->flow().set_icode(1,269);
39 // g->flow().set_icode(2,269);
40 // q4->flow().set_icode(1,269);
41 // later on if we wish to know the color partner of q1 we can ask for a list
42 // of all particles connected via this code to q1 which do have less than
43 // 2 color partners using:
44 // vector<GenParticle*> result=q1->dangling_connected_partners(q1->icode(1),1,2);
45 // this will return a list containing q1 and q4.
46 // vector<GenParticle*> result=q1->connected_partners(q1->icode(1),1,2);
47 // would return a list containing q1, g, and q4.
48 //
49 
50 #include <iostream>
51 #include <map>
52 #include <vector>
53 
54 namespace HepMC {
55 
56  class GenParticle;
57 
59 
66  class Flow {
67 
69  friend std::ostream& operator<<( std::ostream& ostr, const Flow& f );
70 
71  public:
75  Flow( const Flow& );
76  virtual ~Flow();
78  void swap( Flow & other);
80  Flow& operator=( const Flow& );
82  bool operator==( const Flow& a ) const; //compares only flow
84  bool operator!=( const Flow& a ) const; //patterns not owner
85 
87  void print( std::ostream& ostr = std::cout ) const;
88 
91  std::vector<HepMC::GenParticle*> connected_partners( int code, int code_index =1,
92  int num_indices = 2 ) const;
96  std::vector<HepMC::GenParticle*> dangling_connected_partners( int code,
97  int code_index = 1, int num_indices = 2 ) const;
98 
100  // access methods //
102 
104  const GenParticle* particle_owner() const;
106  int icode( int code_index = 1 ) const;
108  Flow set_icode( int code_index, int code );
110  Flow set_unique_icode( int code_index = 1 );
111 
113  // container access //
115 
117  bool empty() const;
119  int size() const;
121  void clear();
123  bool erase( int code_index );
124 
126  typedef std::map<int,int>::iterator iterator;
128  typedef std::map<int,int>::const_iterator const_iterator;
130  iterator begin();
132  iterator end();
134  const_iterator begin() const;
136  const_iterator end() const;
137 
138  protected: // intended for internal use only
140  void connected_partners( std::vector<HepMC::GenParticle*>* output,
141  int code,
142  int code_index,
143  int num_indices ) const;
145  void dangling_connected_partners( std::vector<HepMC::GenParticle*>*
146  output,
147  std::vector<HepMC::GenParticle*>*
148  visited_particles,
149  int code, int code_index,
150  int num_indices ) const;
151  private:
152  GenParticle* m_particle_owner;
153  std::map<int,int> m_icode; // stores flow patterns as(code_index,icode)
154  };
155 
157  // INLINE Access Methods //
159 
160  inline const GenParticle* Flow::particle_owner() const {
161  return m_particle_owner;
162  }
163  inline int Flow::icode( int code_index ) const {
164  std::map<int,int>::const_iterator a = m_icode.find(code_index);
165  return a==m_icode.end() ? 0 : (*a).second;
166  }
167  inline Flow Flow::set_icode( int code_index, int code ) {
168  m_icode[code_index] = code;
169  return *this;
170  }
171  inline Flow Flow::set_unique_icode( int flow_num ) {
174  m_icode[flow_num] = size_t(this);
175  return *this;
176  }
177  inline bool Flow::empty() const { return (bool)m_icode.empty(); }
178  inline int Flow::size() const { return (int)m_icode.size(); }
179  inline void Flow::clear() { m_icode.clear(); }
180  inline bool Flow::erase( int code_index ) {
181  // this will return true if the number of elements removed is nonzero
182  return m_icode.erase( code_index )==0 ? false : true ;
183  }
184  inline Flow::iterator Flow::begin() { return m_icode.begin(); }
185  inline Flow::iterator Flow::end() { return m_icode.end(); }
186  inline Flow::const_iterator Flow::begin() const { return m_icode.begin(); }
187  inline Flow::const_iterator Flow::end() const { return m_icode.end(); }
188 
190  // INLINE Operators //
192 
193  inline bool Flow::operator==( const Flow& a ) const {
197  return (m_icode == a.m_icode);
198  }
199  inline bool Flow::operator!=( const Flow& a ) const {
200  return !( *this == a );
201  }
202  inline Flow& Flow::operator=( const Flow& inflow ) {
206  //
207  m_icode = inflow.m_icode;
208  return *this;
209  }
210 
211 } // HepMC
212 
213 #endif // HEPMC_FLOW_H
214 //--------------------------------------------------------------------------
215 
Flow set_unique_icode(int code_index=1)
set unique flow code
Definition: Flow.h:171
void print(std::ostream &ostr=std::cout) const
print Flow information to ostr
Definition: Flow.cc:34
bool operator!=(const Flow &a) const
inequality
Definition: Flow.h:199
iterator end()
end of flow pattern container
Definition: Flow.h:185
bool empty() const
return true if there is no flow container
Definition: Flow.h:177
std::map< int, int >::const_iterator const_iterator
const iterator for flow pattern container
Definition: Flow.h:128
bool operator==(const Flow &a) const
equality
Definition: Flow.h:193
Flow & operator=(const Flow &)
make a copy
Definition: Flow.h:202
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
friend std::ostream & operator<<(std::ostream &ostr, const Flow &f)
for printing
Definition: Flow.cc:190
iterator begin()
beginning of flow pattern container
Definition: Flow.h:184
Flow set_icode(int code_index, int code)
set flow code
Definition: Flow.h:167
int size() const
size of flow pattern container
Definition: Flow.h:178
const GenParticle * particle_owner() const
find particle owning this Flow
Definition: Flow.h:160
std::map< int, int >::iterator iterator
iterator for flow pattern container
Definition: Flow.h:126
std::vector< HepMC::GenParticle * > dangling_connected_partners(int code, int code_index=1, int num_indices=2) const
Definition: Flow.cc:108
Flow(GenParticle *particle_owner=0)
default constructor
Definition: Flow.cc:13
bool erase(int code_index)
empty flow pattern container
Definition: Flow.h:180
void clear()
clear flow patterns
Definition: Flow.h:179
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