00001
00002 #ifndef HEPMC_GEN_EVENT_H
00003 #define HEPMC_GEN_EVENT_H
00004
00006
00007
00008
00009
00010
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00027 namespace HepMC {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00049 template <class InputIterator, class OutputIterator, class Predicate>
00050 void copy_if( InputIterator first, InputIterator last, OutputIterator out,
00051 Predicate pred ) {
00052 for ( ; first != last; ++first ) { if ( pred(*first) ) out = *first; }
00053 }
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00091
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00104
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 #include "HepMC/GenVertex.h"
00124 #include "HepMC/GenParticle.h"
00125 #include "HepMC/WeightContainer.h"
00126 #include "HepMC/HeavyIon.h"
00127 #include "HepMC/PdfInfo.h"
00128 #include <map>
00129 #include <vector>
00130 #include <algorithm>
00131 #include <iostream>
00132
00133 namespace HepMC {
00134
00136
00142 class GenEvent {
00143 friend class GenParticle;
00144 friend class GenVertex;
00145 public:
00147 GenEvent( int signal_process_id = 0, int event_number = 0,
00148 GenVertex* signal_vertex = 0,
00149 const WeightContainer& weights = std::vector<double>(),
00150 const std::vector<long>& randomstates = std::vector<long>() );
00152 GenEvent( int signal_process_id, int event_number,
00153 GenVertex* signal_vertex, const WeightContainer& weights,
00154 const std::vector<long>& randomstates,
00155 const HeavyIon& ion, const PdfInfo& pdf );
00156 GenEvent( const GenEvent& inevent );
00157 GenEvent& operator=( const GenEvent& inevent );
00158 virtual ~GenEvent();
00159
00160 void swap( GenEvent & other );
00161
00162 void print( std::ostream& ostr = std::cout ) const;
00163 void print_version( std::ostream& ostr = std::cout ) const;
00164
00166 GenParticle* barcode_to_particle( int barCode ) const;
00168 GenVertex* barcode_to_vertex( int barCode ) const;
00169
00171
00173
00174 int signal_process_id() const;
00175 int event_number() const;
00176 int mpi() const;
00177 double event_scale() const;
00178 double alphaQCD() const;
00179 double alphaQED() const;
00180
00181 GenVertex* signal_process_vertex() const;
00183 bool valid_beam_particles() const;
00185 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const;
00186
00192 WeightContainer& weights();
00193 const WeightContainer& weights() const;
00194
00196 HeavyIon const * heavy_ion() const;
00197 HeavyIon* heavy_ion();
00199 PdfInfo const * pdf_info() const;
00200 PdfInfo* pdf_info();
00201
00203 std::vector<long> random_states() const;
00204
00205 void set_signal_process_id( int id );
00206 void set_event_number( int eventno );
00207 void set_mpi( int );
00208 void set_event_scale( double scale );
00209 void set_alphaQCD( double a );
00210 void set_alphaQED( double a );
00211
00213 void set_signal_process_vertex( GenVertex* );
00215 bool set_beam_particles(GenParticle*, GenParticle*);
00217 bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &);
00219 void set_random_states( const std::vector<long>& randomstates );
00220
00222 void set_heavy_ion( const HeavyIon& ion );
00224 void set_pdf_info( const PdfInfo& p );
00225
00227 int particles_size() const;
00229 bool particles_empty() const;
00231 int vertices_size() const;
00233 bool vertices_empty() const;
00234
00236
00238
00239 bool add_vertex( GenVertex* vtx );
00240 bool remove_vertex( GenVertex* vtx );
00241 void clear();
00242
00243 public:
00245
00247
00248
00249
00250
00252
00256 class vertex_const_iterator :
00257 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00258
00259 public:
00261 vertex_const_iterator(
00262 const
00263 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
00264 : m_map_iterator(i) {}
00265 vertex_const_iterator() {}
00267 vertex_const_iterator( const vertex_const_iterator& i )
00268 { *this = i; }
00269 virtual ~vertex_const_iterator() {}
00271 vertex_const_iterator& operator=( const vertex_const_iterator& i )
00272 { m_map_iterator = i.m_map_iterator; return *this; }
00274 GenVertex* operator*(void) const { return m_map_iterator->second; }
00276 vertex_const_iterator& operator++(void)
00277 { ++m_map_iterator; return *this; }
00279 vertex_const_iterator operator++(int)
00280 { vertex_const_iterator out(*this); ++(*this); return out; }
00282 bool operator==( const vertex_const_iterator& a ) const
00283 { return m_map_iterator == a.m_map_iterator; }
00285 bool operator!=( const vertex_const_iterator& a ) const
00286 { return !(m_map_iterator == a.m_map_iterator); }
00287 protected:
00289 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
00290 m_map_iterator;
00291 };
00292 friend class vertex_const_iterator;
00294 vertex_const_iterator vertices_begin() const
00295 { return GenEvent::vertex_const_iterator(
00296 m_vertex_barcodes.begin() ); }
00298 vertex_const_iterator vertices_end() const
00299 { return GenEvent::vertex_const_iterator(
00300 m_vertex_barcodes.end() ); }
00301
00302
00304
00308 class vertex_iterator :
00309 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00310
00311 public:
00313 vertex_iterator(
00314 const
00315 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
00316 : m_map_iterator( i ) {}
00317 vertex_iterator() {}
00319 vertex_iterator( const vertex_iterator& i ) { *this = i; }
00320 virtual ~vertex_iterator() {}
00322 vertex_iterator& operator=( const vertex_iterator& i ) {
00323 m_map_iterator = i.m_map_iterator;
00324 return *this;
00325 }
00327 operator vertex_const_iterator() const
00328 { return vertex_const_iterator(m_map_iterator); }
00330 GenVertex* operator*(void) const
00331 { return m_map_iterator->second; }
00333 vertex_iterator& operator++(void)
00334 { ++m_map_iterator; return *this; }
00336 vertex_iterator operator++(int)
00337 { vertex_iterator out(*this); ++(*this); return out; }
00339 bool operator==( const vertex_iterator& a ) const
00340 { return m_map_iterator == a.m_map_iterator; }
00342 bool operator!=( const vertex_iterator& a ) const
00343 { return !(m_map_iterator == a.m_map_iterator); }
00344 protected:
00346 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
00347 m_map_iterator;
00348 };
00349 friend class vertex_iterator;
00351 vertex_iterator vertices_begin()
00352 { return GenEvent::vertex_iterator(
00353 m_vertex_barcodes.begin() ); }
00355 vertex_iterator vertices_end()
00356 { return GenEvent::vertex_iterator(
00357 m_vertex_barcodes.end() ); }
00358
00359 public:
00361
00363
00364
00365
00366
00367
00368
00369
00371
00375 class particle_const_iterator :
00376 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00377
00378 public:
00380 particle_const_iterator(
00381 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
00382 : m_map_iterator(i) {}
00383 particle_const_iterator() {}
00385 particle_const_iterator( const particle_const_iterator& i )
00386 { *this = i; }
00387 virtual ~particle_const_iterator() {}
00389 particle_const_iterator& operator=(
00390 const particle_const_iterator& i )
00391 { m_map_iterator = i.m_map_iterator; return *this; }
00393 GenParticle* operator*(void) const
00394 { return m_map_iterator->second; }
00396 particle_const_iterator& operator++(void)
00397 { ++m_map_iterator; return *this; }
00399 particle_const_iterator operator++(int)
00400 { particle_const_iterator out(*this); ++(*this); return out; }
00402 bool operator==( const particle_const_iterator& a ) const
00403 { return m_map_iterator == a.m_map_iterator; }
00405 bool operator!=( const particle_const_iterator& a ) const
00406 { return !(m_map_iterator == a.m_map_iterator); }
00407 protected:
00409 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
00410 };
00411 friend class particle_const_iterator;
00413 particle_const_iterator particles_begin() const
00414 { return GenEvent::particle_const_iterator(
00415 m_particle_barcodes.begin() ); }
00417 particle_const_iterator particles_end() const
00418 { return GenEvent::particle_const_iterator(
00419 m_particle_barcodes.end() ); }
00420
00422
00426 class particle_iterator :
00427 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00428
00429 public:
00431 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
00432 : m_map_iterator( i ) {}
00433 particle_iterator() {}
00435 particle_iterator( const particle_iterator& i ) { *this = i; }
00436 virtual ~particle_iterator() {}
00438 particle_iterator& operator=( const particle_iterator& i ) {
00439 m_map_iterator = i.m_map_iterator;
00440 return *this;
00441 }
00443 operator particle_const_iterator() const
00444 { return particle_const_iterator(m_map_iterator); }
00446 GenParticle* operator*(void) const
00447 { return m_map_iterator->second; }
00449 particle_iterator& operator++(void)
00450 { ++m_map_iterator; return *this; }
00452 particle_iterator operator++(int)
00453 { particle_iterator out(*this); ++(*this); return out; }
00455 bool operator==( const particle_iterator& a ) const
00456 { return m_map_iterator == a.m_map_iterator; }
00458 bool operator!=( const particle_iterator& a ) const
00459 { return !(m_map_iterator == a.m_map_iterator); }
00460 protected:
00462 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
00463 };
00464 friend class particle_iterator;
00466 particle_iterator particles_begin()
00467 { return GenEvent::particle_iterator(
00468 m_particle_barcodes.begin() ); }
00470 particle_iterator particles_end()
00471 { return GenEvent::particle_iterator(
00472 m_particle_barcodes.end() ); }
00473
00475 protected:
00476
00477
00478
00480 bool set_barcode( GenParticle* p, int suggested_barcode =0 );
00482 bool set_barcode( GenVertex* v, int suggested_barcode =0 );
00484 void remove_barcode( GenParticle* p );
00486 void remove_barcode( GenVertex* v );
00487
00488
00489 void delete_all_vertices();
00490
00491 private:
00492 int m_signal_process_id;
00493 int m_event_number;
00494 int m_mpi;
00495 double m_event_scale;
00496 double m_alphaQCD;
00497 double m_alphaQED;
00498 GenVertex* m_signal_process_vertex;
00499 GenParticle* m_beam_particle_1;
00500 GenParticle* m_beam_particle_2;
00501 WeightContainer m_weights;
00502
00503 std::vector<long> m_random_states;
00504
00505
00506 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
00507 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
00508 HeavyIon* m_heavy_ion;
00509 PdfInfo* m_pdf_info;
00510
00511
00512 };
00513
00515
00517
00522 inline int GenEvent::signal_process_id() const
00523 { return m_signal_process_id; }
00524
00525 inline int GenEvent::event_number() const { return m_event_number; }
00526
00529 inline int GenEvent::mpi() const { return m_mpi; }
00530
00531 inline double GenEvent::event_scale() const { return m_event_scale; }
00532
00533 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
00534
00535 inline double GenEvent::alphaQED() const { return m_alphaQED; }
00536
00537 inline GenVertex* GenEvent::signal_process_vertex() const {
00539 return m_signal_process_vertex;
00540 }
00541
00542 inline WeightContainer& GenEvent::weights() { return m_weights; }
00543
00544 inline const WeightContainer& GenEvent::weights() const
00545 { return m_weights; }
00546
00547 inline HeavyIon const * GenEvent::heavy_ion() const
00548 { return m_heavy_ion; }
00549
00550 inline HeavyIon* GenEvent::heavy_ion()
00551 { return m_heavy_ion; }
00552
00553 inline PdfInfo const * GenEvent::pdf_info() const
00554 { return m_pdf_info; }
00555
00556 inline PdfInfo* GenEvent::pdf_info()
00557 { return m_pdf_info; }
00558
00564 inline std::vector<long> GenEvent::random_states() const
00565 { return m_random_states; }
00566
00567 inline void GenEvent::set_signal_process_id( int id )
00568 { m_signal_process_id = id; }
00569
00570 inline void GenEvent::set_event_number( int eventno )
00571 { m_event_number = eventno; }
00572
00574 inline void GenEvent::set_mpi( int nmpi )
00575 { m_mpi = nmpi; }
00576
00577
00578 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
00579
00580 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
00581
00582 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
00583
00584 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
00585 m_signal_process_vertex = vtx;
00586 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
00587 }
00588
00589 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
00590 { m_heavy_ion = new HeavyIon(ion); }
00591
00592 inline void GenEvent::set_pdf_info( const PdfInfo& p )
00593 { m_pdf_info = new PdfInfo(p); }
00594
00595 inline void GenEvent::set_random_states( const std::vector<long>&
00596 randomstates )
00597 { m_random_states = randomstates; }
00598
00599 inline void GenEvent::remove_barcode( GenParticle* p )
00600 { m_particle_barcodes.erase( p->barcode() ); }
00601
00602 inline void GenEvent::remove_barcode( GenVertex* v )
00603 { m_vertex_barcodes.erase( v->barcode() ); }
00604
00618 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
00619 {
00620 std::map<int,HepMC::GenParticle*>::const_iterator i
00621 = m_particle_barcodes.find(barCode);
00622 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
00623 }
00624
00638 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
00639 {
00640 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
00641 = m_vertex_barcodes.find(barCode);
00642 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
00643 }
00644
00645 inline int GenEvent::particles_size() const {
00646 return (int)m_particle_barcodes.size();
00647 }
00648 inline bool GenEvent::particles_empty() const {
00649 return (bool)m_particle_barcodes.empty();
00650 }
00651 inline int GenEvent::vertices_size() const {
00652 return (int)m_vertex_barcodes.size();
00653 }
00654 inline bool GenEvent::vertices_empty() const {
00655 return (bool)m_vertex_barcodes.empty();
00656 }
00657
00658
00659 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
00660 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
00661 }
00662
00663 }
00664
00665 #endif // HEPMC_GEN_EVENT_H
00666
00667
00668
00669