00001
00002 #ifndef HEPMC_GEN_VERTEX_H
00003 #define HEPMC_GEN_VERTEX_H
00004
00006
00007
00008
00009
00010
00011
00012
00014
00015
00016
00017
00018
00020
00021 #include "CLHEP/HepMC/WeightContainer.h"
00022 #include "CLHEP/Vector/LorentzVector.h"
00023 #include "CLHEP/Geometry/Point3D.h"
00024 #include "CLHEP/config/CLHEP.h"
00025 #include "CLHEP/config/iostream.h"
00026 #include <iterator>
00027 #include <vector>
00028 #include <set>
00029 #include <algorithm>
00030
00031 namespace HepMC {
00032
00033 enum IteratorRange { parents, children, family,
00034 ancestors, descendants, relatives };
00035 class GenParticle;
00036 class GenEvent;
00037
00042 class GenVertex {
00043
00044 friend class GenEvent;
00045 friend std::ostream& operator<<( std::ostream&, const GenVertex& );
00046
00047 public:
00048
00049 #if defined __GNUG__ && ( __GNUG__ < 3 )
00050 typedef std::forward_iterator<GenVertex*,ptrdiff_t> forwardVertexIterType;
00051 #else
00052 typedef std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t> forwardVertexIterType;
00053 #endif
00054
00055 GenVertex( const HepLorentzVector& position =HepLorentzVector(0,0,0,0),
00056 int id = 0,
00057 const WeightContainer& weights = std::vector<double>() );
00058 GenVertex( const GenVertex& invertex );
00059 virtual ~GenVertex();
00060
00061 GenVertex& operator= ( const GenVertex& invertex );
00062 bool operator==( const GenVertex& a ) const;
00063 bool operator!=( const GenVertex& a ) const;
00064 void print( std::ostream& ostr = std::cout ) const;
00065
00066 double check_momentum_conservation() const;
00067
00068 void add_particle_in( GenParticle* inparticle );
00069 void add_particle_out( GenParticle* outparticle );
00070
00071
00072
00073
00074
00075
00076 GenParticle* remove_particle( GenParticle* particle );
00077
00078 operator HepLorentzVector() const;
00079 operator HepPoint3D() const;
00080
00082
00084
00085 GenEvent* parent_event() const;
00086 HepPoint3D point3d() const;
00087 HepLorentzVector position() const;
00088 void set_position( const HepLorentzVector& position
00089 = HepLorentzVector(0,0,0,0) );
00090
00091
00092 int id() const;
00093 void set_id( int id );
00094
00095
00096
00097
00098
00099
00100
00101
00102 int barcode() const;
00103 bool suggest_barcode( int the_bar_code );
00104
00105
00106 WeightContainer& weights();
00107 const WeightContainer& weights() const;
00108
00109
00110 GenParticle * mother() const;
00111 GenParticle * secondMother() const;
00112 GenParticle * beginDaughters() const;
00113 GenParticle * endDaughters() const;
00114
00115 std::vector<GenParticle*> listChildren() const;
00116 std::vector<GenParticle*> listDescendants();
00117 std::vector<GenParticle*> listParents() const;
00118 std::vector<GenParticle*> listAncestors();
00119
00121
00123
00124 typedef std::set<GenParticle*>::const_iterator
00125 particles_in_const_iterator;
00126 typedef std::set<GenParticle*>::const_iterator
00127 particles_out_const_iterator;
00128 particles_in_const_iterator particles_in_const_begin() const;
00129 particles_in_const_iterator particles_in_const_end() const;
00130 particles_out_const_iterator particles_out_const_begin() const;
00131 particles_out_const_iterator particles_out_const_end() const;
00132 int particles_in_size() const;
00133 int particles_out_size() const;
00134
00135 protected:
00136 static unsigned int counter();
00137
00138
00139
00140
00141 void set_parent_event_( GenEvent* evt );
00142 void set_barcode_( int the_bar_code );
00143
00144 public:
00146
00148
00149
00150
00151 class edge_iterator :
00152 public forwardVertexIterType {
00153
00154
00155
00156
00157
00158 public:
00159 edge_iterator();
00160 edge_iterator( const GenVertex& vtx, IteratorRange range =family );
00161 edge_iterator( const edge_iterator& p );
00162 virtual ~edge_iterator();
00163 edge_iterator& operator=( const edge_iterator& p );
00164 GenParticle* operator*(void) const;
00165 edge_iterator& operator++(void);
00166 edge_iterator operator++(int);
00167 bool operator==( const edge_iterator& a ) const;
00168 bool operator!=( const edge_iterator& a ) const;
00169 bool is_parent() const;
00170 bool is_child() const;
00171 const GenVertex* vertex_root() const;
00172 private:
00173 const GenVertex* m_vertex;
00174 IteratorRange m_range;
00175 std::set<GenParticle*>::const_iterator m_set_iter;
00176 bool m_is_inparticle_iter;
00177 bool m_is_past_end;
00178 };
00179 friend class edge_iterator;
00180 int edges_size( IteratorRange range = family ) const;
00181 edge_iterator edges_begin( IteratorRange range = family) const;
00182 edge_iterator edges_end( IteratorRange ) const;
00183
00184 public:
00186
00188
00189 public forwardVertexIterType {
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 public:
00205 vertex_iterator();
00206 vertex_iterator( GenVertex& vtx_root, IteratorRange range );
00207
00208 vertex_iterator( GenVertex& vtx_root, IteratorRange range,
00209 std::set<const GenVertex*>& visited_vertices );
00210 vertex_iterator( const vertex_iterator& v_iter );
00211 virtual ~vertex_iterator();
00212 vertex_iterator& operator=( const vertex_iterator& );
00213 GenVertex* operator*(void) const;
00214 vertex_iterator& operator++(void);
00215 vertex_iterator operator++(int);
00216 bool operator==( const vertex_iterator& ) const;
00217 bool operator!=( const vertex_iterator& ) const;
00218 GenVertex* vertex_root() const;
00219 IteratorRange range() const;
00220 void copy_with_own_set( const vertex_iterator&
00221 v_iter,
00222 std::set<const GenVertex*>&
00223 visited_vertices );
00224 protected:
00225 GenVertex* follow_edge_();
00226 void copy_recursive_iterator_( const vertex_iterator*
00227 recursive_v_iter );
00228 private:
00229 GenVertex* m_vertex;
00230 IteratorRange m_range;
00231 std::set<const GenVertex*>* m_visited_vertices;
00232 bool m_it_owns_set;
00233
00234 edge_iterator m_edge;
00235 vertex_iterator* m_recursive_iterator;
00236 };
00237 friend class vertex_iterator;
00238 vertex_iterator vertices_begin( IteratorRange range = relatives );
00239 vertex_iterator vertices_end( IteratorRange );
00240
00241 public:
00243
00245
00246 public forwardVertexIterType {
00247
00248
00249
00250
00251
00252
00253
00254 public:
00255 particle_iterator();
00256 particle_iterator( GenVertex& vertex_root, IteratorRange range );
00257 particle_iterator( const particle_iterator& );
00258 virtual ~particle_iterator();
00259 particle_iterator& operator=( const particle_iterator& );
00260 GenParticle* operator*(void) const;
00261 particle_iterator& operator++(void);
00262 particle_iterator operator++(int);
00263 bool operator==( const particle_iterator& ) const;
00264 bool operator!=( const particle_iterator& ) const;
00265 protected:
00266 GenParticle* advance_to_first_();
00267 private:
00268 vertex_iterator m_vertex_iterator;
00269 edge_iterator m_edge;
00270 };
00271 friend class particle_iterator;
00272 particle_iterator particles_begin( IteratorRange range
00273 = relatives );
00274 particle_iterator particles_end( IteratorRange
00275 );
00276
00278 protected:
00279 void delete_adopted_particles();
00280
00281 private:
00282 HepLorentzVector m_position;
00283 std::set<GenParticle*> m_particles_in;
00284 std::set<GenParticle*> m_particles_out;
00285 int m_id;
00286 WeightContainer m_weights;
00287 GenEvent* m_event;
00288 int m_barcode;
00289
00290 static unsigned int s_counter;
00291 };
00292
00294
00296
00297 inline GenVertex::operator HepLorentzVector() const { return position(); }
00298
00299 inline GenVertex::operator HepPoint3D() const { return point3d(); }
00300
00301 inline HepLorentzVector GenVertex::position() const { return m_position; }
00302
00303 inline GenEvent* GenVertex::parent_event() const { return m_event; }
00304
00305 inline HepPoint3D GenVertex::point3d() const {
00306 return (HepPoint3D)m_position;
00307 }
00308
00309 inline int GenVertex::id() const { return m_id; }
00310
00311 inline int GenVertex::barcode() const { return m_barcode; }
00312 inline void GenVertex::set_barcode_( int bc ) { m_barcode = bc; }
00313
00314 inline WeightContainer& GenVertex::weights() { return m_weights; }
00315
00316 inline const WeightContainer& GenVertex::weights() const
00317 { return m_weights; }
00318
00319 inline void GenVertex::set_position( const HepLorentzVector& position ) {
00320 m_position = position;
00321 }
00322
00323 inline void GenVertex::set_id( int id ) { m_id = id; }
00324
00326
00328
00329 inline GenVertex::particles_in_const_iterator
00330 GenVertex::particles_in_const_begin() const {
00331 return m_particles_in.begin();
00332 }
00333
00334 inline GenVertex::particles_in_const_iterator
00335 GenVertex::particles_in_const_end() const {
00336 return m_particles_in.end();
00337 }
00338
00339 inline GenVertex::particles_out_const_iterator
00340 GenVertex::particles_out_const_begin() const {
00341 return m_particles_out.begin();
00342 }
00343
00344 inline GenVertex::particles_out_const_iterator
00345 GenVertex::particles_out_const_end() const {
00346 return m_particles_out.end();
00347 }
00348
00349 inline int GenVertex::particles_in_size() const {
00350 return m_particles_in.size();
00351 }
00352
00353 inline int GenVertex::particles_out_size() const {
00354 return m_particles_out.size();
00355 }
00356
00357 inline bool GenVertex::edge_iterator::operator==(
00358 const edge_iterator& a ) const {
00359 return **this == *a;
00360 }
00361
00362 inline bool GenVertex::edge_iterator::operator!=(
00363 const edge_iterator& a ) const {
00364 return !(**this == *a);
00365 }
00366
00367 inline const GenVertex* GenVertex::edge_iterator::vertex_root() const {
00368 return m_vertex;
00369 }
00370
00371 inline GenVertex::edge_iterator GenVertex::edges_begin( IteratorRange
00372 range ) const {
00373 return GenVertex::edge_iterator(*this, range);
00374 }
00375
00376 inline GenVertex::edge_iterator GenVertex::edges_end( IteratorRange
00377 ) const {
00378 return GenVertex::edge_iterator();
00379 }
00380
00381 inline bool GenVertex::vertex_iterator::operator==(
00382 const vertex_iterator& a ) const {
00383 return **this == *a;
00384 }
00385
00386 inline bool GenVertex::vertex_iterator::operator!=(
00387 const vertex_iterator& a ) const {
00388 return !(**this == *a);
00389 }
00390
00391 inline GenVertex* GenVertex::vertex_iterator::vertex_root() const {
00392 return m_vertex;
00393 }
00394
00395 inline IteratorRange GenVertex::vertex_iterator::range() const {
00396 return m_range;
00397 }
00398
00399 inline GenVertex::vertex_iterator GenVertex::vertices_begin(
00400 IteratorRange range ){
00401
00402 return vertex_iterator( *this, range );
00403 }
00404
00405 inline GenVertex::vertex_iterator GenVertex::vertices_end(
00406 IteratorRange ) {
00407 return vertex_iterator();
00408 }
00409
00410 inline bool GenVertex::particle_iterator::operator==(
00411 const particle_iterator& a ) const {
00412 return **this == *a;
00413 }
00414
00415 inline bool GenVertex::particle_iterator::operator!=(
00416 const particle_iterator& a ) const {
00417 return !(**this == *a);
00418 }
00419
00420 inline GenVertex::particle_iterator GenVertex::particles_begin(
00421 IteratorRange range ) {
00422 return particle_iterator( *this, range );
00423 }
00424
00425 inline GenVertex::particle_iterator GenVertex::particles_end(
00426 IteratorRange ){
00427 return particle_iterator();
00428 }
00429
00430 }
00431
00432 #endif // HEPMC_GEN_VERTEX_H
00433
00434
00435
00436
00437