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
00019
00020 #ifdef __SUNPRO_CC // Solaris CC 5.2
00021 #define NEED_SOLARIS_FRIEND_FEATURE
00022 #endif // Platform
00023
00024 #include "HepMC/WeightContainer.h"
00025 #include "HepMC/SimpleVector.h"
00026 #include <iostream>
00027 #include <iterator>
00028 #include <vector>
00029 #include <set>
00030 #include <algorithm>
00031
00032 namespace HepMC {
00033
00035 enum IteratorRange { parents, children, family,
00036 ancestors, descendants, relatives };
00037 class GenParticle;
00038 class GenEvent;
00039
00041
00047 class GenVertex {
00048
00050 friend std::ostream& operator<<( std::ostream&, const GenVertex& );
00051 friend class GenEvent;
00052
00053 #ifdef NEED_SOLARIS_FRIEND_FEATURE
00054
00055
00056
00057 public:
00058 class vertex_iterator;
00059 friend class vertex_iterator;
00060 class particle_iterator;
00061 friend class particle_iterator;
00062 #endif // NEED_SOLARIS_FRIEND_FEATURE
00063
00064 public:
00066 GenVertex( const FourVector& position =FourVector(0,0,0,0),
00067 int id = 0,
00068 const WeightContainer& weights = std::vector<double>() );
00069 GenVertex( const GenVertex& invertex );
00070 virtual ~GenVertex();
00071
00072 void swap( GenVertex & other);
00073 GenVertex& operator= ( const GenVertex& invertex );
00074 bool operator==( const GenVertex& a ) const;
00075 bool operator!=( const GenVertex& a ) const;
00076 void print( std::ostream& ostr = std::cout ) const;
00077
00078 double check_momentum_conservation() const;
00079
00081 void add_particle_in( GenParticle* inparticle );
00083 void add_particle_out( GenParticle* outparticle );
00088 GenParticle* remove_particle( GenParticle* particle );
00089
00090 operator HepMC::FourVector() const;
00091 operator HepMC::ThreeVector() const;
00092
00094
00096
00098 GenEvent* parent_event() const;
00100 ThreeVector point3d() const;
00102 FourVector position() const;
00104 void set_position( const FourVector& position = FourVector(0,0,0,0) );
00107 int id() const;
00108 void set_id( int id );
00109
00114 int barcode() const;
00115
00117 bool suggest_barcode( int the_bar_code );
00118
00120 WeightContainer& weights();
00122 const WeightContainer& weights() const;
00123
00125
00127
00129 typedef std::vector<HepMC::GenParticle*>::const_iterator
00130 particles_in_const_iterator;
00132 typedef std::vector<HepMC::GenParticle*>::const_iterator
00133 particles_out_const_iterator;
00135 particles_in_const_iterator particles_in_const_begin() const;
00137 particles_in_const_iterator particles_in_const_end() const;
00139 particles_out_const_iterator particles_out_const_begin() const;
00141 particles_out_const_iterator particles_out_const_end() const;
00143 int particles_in_size() const;
00145 int particles_out_size() const;
00146
00147 protected:
00148
00149
00153 void set_parent_event_( GenEvent* evt );
00154 void set_barcode_( int the_bar_code );
00155 void change_parent_event_( GenEvent* evt );
00156
00158
00160
00161
00162
00163
00165
00172 class edge_iterator :
00173 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00174 public:
00175 edge_iterator();
00177 edge_iterator( const GenVertex& vtx, IteratorRange range =family );
00179 edge_iterator( const edge_iterator& p );
00180 virtual ~edge_iterator();
00182 edge_iterator& operator=( const edge_iterator& p );
00184 GenParticle* operator*(void) const;
00186 edge_iterator& operator++(void);
00188 edge_iterator operator++(int);
00190 bool operator==( const edge_iterator& a ) const;
00192 bool operator!=( const edge_iterator& a ) const;
00194 bool is_parent() const;
00196 bool is_child() const;
00198 const GenVertex* vertex_root() const;
00199 private:
00200 const GenVertex* m_vertex;
00201 IteratorRange m_range;
00202 std::vector<HepMC::GenParticle*>::const_iterator m_set_iter;
00203 bool m_is_inparticle_iter;
00204 bool m_is_past_end;
00205 };
00206 friend class edge_iterator;
00208 int edges_size( IteratorRange range = family ) const;
00210 edge_iterator edges_begin( IteratorRange range = family) const;
00212 edge_iterator edges_end( IteratorRange ) const;
00213
00214 public:
00216
00218
00220
00236 class vertex_iterator :
00237 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00238 public:
00239 vertex_iterator();
00241 vertex_iterator( GenVertex& vtx_root, IteratorRange range );
00243 vertex_iterator( GenVertex& vtx_root, IteratorRange range,
00244 std::set<const HepMC::GenVertex*>& visited_vertices );
00246 vertex_iterator( const vertex_iterator& v_iter );
00247 virtual ~vertex_iterator();
00249 vertex_iterator& operator=( const vertex_iterator& );
00251 GenVertex* operator*(void) const;
00253 vertex_iterator& operator++(void);
00255 vertex_iterator operator++(int);
00257 bool operator==( const vertex_iterator& ) const;
00259 bool operator!=( const vertex_iterator& ) const;
00261 GenVertex* vertex_root() const;
00263 IteratorRange range() const;
00265 void copy_with_own_set( const vertex_iterator&
00266 v_iter,
00267 std::set<const HepMC::GenVertex*>&
00268 visited_vertices );
00269
00270 protected:
00272 GenVertex* follow_edge_();
00274 void copy_recursive_iterator_( const vertex_iterator*
00275 recursive_v_iter );
00276 private:
00277 GenVertex* m_vertex;
00278 IteratorRange m_range;
00279 std::set<const HepMC::GenVertex*>* m_visited_vertices;
00280 bool m_it_owns_set;
00281
00282 edge_iterator m_edge;
00283 vertex_iterator* m_recursive_iterator;
00284 };
00285 friend class vertex_iterator;
00287 vertex_iterator vertices_begin( IteratorRange range = relatives );
00289 vertex_iterator vertices_end( IteratorRange );
00290
00291 public:
00293
00295
00297
00306 class particle_iterator :
00307 public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{
00308 public:
00309 particle_iterator();
00311 particle_iterator( GenVertex& vertex_root, IteratorRange range );
00313 particle_iterator( const particle_iterator& );
00314 virtual ~particle_iterator();
00316 particle_iterator& operator=( const particle_iterator& );
00318 GenParticle* operator*(void) const;
00320 particle_iterator& operator++(void);
00322 particle_iterator operator++(int);
00324 bool operator==( const particle_iterator& ) const;
00326 bool operator!=( const particle_iterator& ) const;
00327 protected:
00328 GenParticle* advance_to_first_();
00329 private:
00330 vertex_iterator m_vertex_iterator;
00331 edge_iterator m_edge;
00332 };
00333 friend class particle_iterator;
00335 particle_iterator particles_begin( IteratorRange range
00336 = relatives );
00338 particle_iterator particles_end( IteratorRange
00339 );
00340
00342 protected:
00344 void delete_adopted_particles();
00346 void remove_particle_in( GenParticle* );
00348 void remove_particle_out( GenParticle* );
00349
00350 private:
00351 FourVector m_position;
00352 std::vector<HepMC::GenParticle*> m_particles_in;
00353 std::vector<HepMC::GenParticle*> m_particles_out;
00354 int m_id;
00355 WeightContainer m_weights;
00356 GenEvent* m_event;
00357 int m_barcode;
00358
00359
00360 };
00361
00363
00365
00366 inline GenVertex::operator HepMC::FourVector() const { return position(); }
00367
00368 inline GenVertex::operator HepMC::ThreeVector() const { return point3d(); }
00369
00370 inline FourVector GenVertex::position() const { return m_position; }
00371
00372 inline GenEvent* GenVertex::parent_event() const { return m_event; }
00373
00374 inline ThreeVector GenVertex::point3d() const {
00375 return ThreeVector(m_position.x(),m_position.y(),m_position.z());
00376 }
00377
00378 inline int GenVertex::id() const { return m_id; }
00379
00380 inline int GenVertex::barcode() const { return m_barcode; }
00381 inline void GenVertex::set_barcode_( int bc ) { m_barcode = bc; }
00382
00383 inline WeightContainer& GenVertex::weights() { return m_weights; }
00384
00385 inline const WeightContainer& GenVertex::weights() const
00386 { return m_weights; }
00387
00388 inline void GenVertex::set_position( const FourVector& position ) {
00389 m_position = position;
00390 }
00391
00392 inline void GenVertex::set_id( int id ) { m_id = id; }
00393
00395
00397
00398 inline GenVertex::particles_in_const_iterator
00399 GenVertex::particles_in_const_begin() const {
00400 return m_particles_in.begin();
00401 }
00402
00403 inline GenVertex::particles_in_const_iterator
00404 GenVertex::particles_in_const_end() const {
00405 return m_particles_in.end();
00406 }
00407
00408 inline GenVertex::particles_out_const_iterator
00409 GenVertex::particles_out_const_begin() const {
00410 return m_particles_out.begin();
00411 }
00412
00413 inline GenVertex::particles_out_const_iterator
00414 GenVertex::particles_out_const_end() const {
00415 return m_particles_out.end();
00416 }
00417
00418 inline int GenVertex::particles_in_size() const {
00419 return m_particles_in.size();
00420 }
00421
00422 inline int GenVertex::particles_out_size() const {
00423 return m_particles_out.size();
00424 }
00425
00426 inline bool GenVertex::edge_iterator::operator==(
00427 const edge_iterator& a ) const {
00428 return **this == *a;
00429 }
00430
00431 inline bool GenVertex::edge_iterator::operator!=(
00432 const edge_iterator& a ) const {
00433 return !(**this == *a);
00434 }
00435
00436 inline const GenVertex* GenVertex::edge_iterator::vertex_root() const {
00437 return m_vertex;
00438 }
00439
00440 inline GenVertex::edge_iterator GenVertex::edges_begin( IteratorRange
00441 range ) const {
00442 return GenVertex::edge_iterator(*this, range);
00443 }
00444
00445 inline GenVertex::edge_iterator GenVertex::edges_end( IteratorRange
00446 ) const {
00447 return GenVertex::edge_iterator();
00448 }
00449
00450 inline bool GenVertex::vertex_iterator::operator==(
00451 const vertex_iterator& a ) const {
00452 return **this == *a;
00453 }
00454
00455 inline bool GenVertex::vertex_iterator::operator!=(
00456 const vertex_iterator& a ) const {
00457 return !(**this == *a);
00458 }
00459
00460 inline GenVertex* GenVertex::vertex_iterator::vertex_root() const {
00461 return m_vertex;
00462 }
00463
00464 inline IteratorRange GenVertex::vertex_iterator::range() const {
00465 return m_range;
00466 }
00467
00468 inline GenVertex::vertex_iterator GenVertex::vertices_begin(
00469 IteratorRange range ){
00470
00471 return vertex_iterator( *this, range );
00472 }
00473
00474 inline GenVertex::vertex_iterator GenVertex::vertices_end(
00475 IteratorRange ) {
00476 return vertex_iterator();
00477 }
00478
00479 inline bool GenVertex::particle_iterator::operator==(
00480 const particle_iterator& a ) const {
00481 return **this == *a;
00482 }
00483
00484 inline bool GenVertex::particle_iterator::operator!=(
00485 const particle_iterator& a ) const {
00486 return !(**this == *a);
00487 }
00488
00489 inline GenVertex::particle_iterator GenVertex::particles_begin(
00490 IteratorRange range ) {
00491 return particle_iterator( *this, range );
00492 }
00493
00494 inline GenVertex::particle_iterator GenVertex::particles_end(
00495 IteratorRange ){
00496 return particle_iterator();
00497 }
00498
00499 }
00500
00501 #endif // HEPMC_GEN_VERTEX_H
00502
00503
00504
00505
00506