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/GenCrossSection.h"
00127 #include "HepMC/HeavyIon.h"
00128 #include "HepMC/PdfInfo.h"
00129 #include "HepMC/Units.h"
00130 #include "HepMC/HepMCDefs.h"
00131 #include <map>
00132 #include <string>
00133 #include <vector>
00134 #include <algorithm>
00135 #include <iostream>
00136
00137 namespace HepMC {
00138
00140
00146 class GenEvent {
00147 friend class GenParticle;
00148 friend class GenVertex;
00149 public:
00151 GenEvent( int signal_process_id = 0, int event_number = 0,
00152 GenVertex* signal_vertex = 0,
00153 const WeightContainer& weights = std::vector<double>(),
00154 const std::vector<long>& randomstates = std::vector<long>(),
00155 Units::MomentumUnit = Units::default_momentum_unit(),
00156 Units::LengthUnit = Units::default_length_unit() );
00158 GenEvent( int signal_process_id, int event_number,
00159 GenVertex* signal_vertex, const WeightContainer& weights,
00160 const std::vector<long>& randomstates,
00161 const HeavyIon& ion, const PdfInfo& pdf,
00162 Units::MomentumUnit = Units::default_momentum_unit(),
00163 Units::LengthUnit = Units::default_length_unit() );
00165 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00166 int signal_process_id = 0, int event_number = 0,
00167 GenVertex* signal_vertex = 0,
00168 const WeightContainer& weights = std::vector<double>(),
00169 const std::vector<long>& randomstates = std::vector<long>() );
00171 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00172 int signal_process_id, int event_number,
00173 GenVertex* signal_vertex, const WeightContainer& weights,
00174 const std::vector<long>& randomstates,
00175 const HeavyIon& ion, const PdfInfo& pdf );
00176 GenEvent( const GenEvent& inevent );
00177 GenEvent& operator=( const GenEvent& inevent );
00178 virtual ~GenEvent();
00179
00180 void swap( GenEvent & other );
00181
00182 void print( std::ostream& ostr = std::cout ) const;
00183 void print_version( std::ostream& ostr = std::cout ) const;
00184
00186 GenParticle* barcode_to_particle( int barCode ) const;
00188 GenVertex* barcode_to_vertex( int barCode ) const;
00189
00191
00193
00194 int signal_process_id() const;
00195 int event_number() const;
00196 int mpi() const;
00197 double event_scale() const;
00198 double alphaQCD() const;
00199 double alphaQED() const;
00200
00201 GenVertex* signal_process_vertex() const;
00203 bool valid_beam_particles() const;
00205 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const;
00208 bool is_valid() const;
00209
00215 WeightContainer& weights();
00216 const WeightContainer& weights() const;
00217
00219 GenCrossSection const * cross_section() const;
00220 GenCrossSection* cross_section();
00222 HeavyIon const * heavy_ion() const;
00223 HeavyIon* heavy_ion();
00225 PdfInfo const * pdf_info() const;
00226 PdfInfo* pdf_info();
00227
00229 const std::vector<long>& random_states() const;
00230
00232 int particles_size() const;
00234 bool particles_empty() const;
00236 int vertices_size() const;
00238 bool vertices_empty() const;
00239
00240 void write_units( std::ostream & os = std::cout ) const;
00241
00243 Units::MomentumUnit momentum_unit() const;
00245 Units::LengthUnit length_unit() const;
00246
00247 std::ostream& write(std::ostream&);
00248 std::istream& read(std::istream&);
00249
00251
00253
00254 bool add_vertex( GenVertex* vtx );
00255 bool remove_vertex( GenVertex* vtx );
00256 void clear();
00257
00258 void set_signal_process_id( int id );
00259 void set_event_number( int eventno );
00260 void set_mpi( int );
00261 void set_event_scale( double scale );
00262 void set_alphaQCD( double a );
00263 void set_alphaQED( double a );
00264
00266 void set_signal_process_vertex( GenVertex* );
00268 bool set_beam_particles(GenParticle*, GenParticle*);
00270 bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &);
00272 void set_random_states( const std::vector<long>& randomstates );
00273
00275 void set_cross_section( const GenCrossSection& );
00277 void set_heavy_ion( const HeavyIon& ion );
00279 void set_pdf_info( const PdfInfo& p );
00280
00282 void use_units( Units::MomentumUnit, Units::LengthUnit );
00285 void use_units( std::string&, std::string& );
00286
00287 public:
00289
00291
00292
00293
00294
00296
00300 class vertex_const_iterator :
00301 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00302
00303 public:
00305 vertex_const_iterator(
00306 const
00307 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
00308 : m_map_iterator(i) {}
00309 vertex_const_iterator() {}
00311 vertex_const_iterator( const vertex_const_iterator& i )
00312 { *this = i; }
00313 virtual ~vertex_const_iterator() {}
00315 vertex_const_iterator& operator=( const vertex_const_iterator& i )
00316 { m_map_iterator = i.m_map_iterator; return *this; }
00318 GenVertex* operator*(void) const { return m_map_iterator->second; }
00320 vertex_const_iterator& operator++(void)
00321 { ++m_map_iterator; return *this; }
00323 vertex_const_iterator operator++(int)
00324 { vertex_const_iterator out(*this); ++(*this); return out; }
00326 bool operator==( const vertex_const_iterator& a ) const
00327 { return m_map_iterator == a.m_map_iterator; }
00329 bool operator!=( const vertex_const_iterator& a ) const
00330 { return !(m_map_iterator == a.m_map_iterator); }
00331 protected:
00333 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
00334 m_map_iterator;
00335 private:
00337 vertex_const_iterator& operator--(void);
00339 vertex_const_iterator operator--(int);
00340 };
00341 friend class vertex_const_iterator;
00343 vertex_const_iterator vertices_begin() const
00344 { return GenEvent::vertex_const_iterator(
00345 m_vertex_barcodes.begin() ); }
00347 vertex_const_iterator vertices_end() const
00348 { return GenEvent::vertex_const_iterator(
00349 m_vertex_barcodes.end() ); }
00350
00351
00353
00357 class vertex_iterator :
00358 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00359
00360 public:
00362 vertex_iterator(
00363 const
00364 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
00365 : m_map_iterator( i ) {}
00366 vertex_iterator() {}
00368 vertex_iterator( const vertex_iterator& i ) { *this = i; }
00369 virtual ~vertex_iterator() {}
00371 vertex_iterator& operator=( const vertex_iterator& i ) {
00372 m_map_iterator = i.m_map_iterator;
00373 return *this;
00374 }
00376 operator vertex_const_iterator() const
00377 { return vertex_const_iterator(m_map_iterator); }
00379 GenVertex* operator*(void) const
00380 { return m_map_iterator->second; }
00382 vertex_iterator& operator++(void)
00383 { ++m_map_iterator; return *this; }
00385 vertex_iterator operator++(int)
00386 { vertex_iterator out(*this); ++(*this); return out; }
00388 bool operator==( const vertex_iterator& a ) const
00389 { return m_map_iterator == a.m_map_iterator; }
00391 bool operator!=( const vertex_iterator& a ) const
00392 { return !(m_map_iterator == a.m_map_iterator); }
00393 protected:
00395 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
00396 m_map_iterator;
00397 private:
00399 vertex_iterator& operator--(void);
00401 vertex_iterator operator--(int);
00402
00403 };
00404 friend class vertex_iterator;
00406 vertex_iterator vertices_begin()
00407 { return GenEvent::vertex_iterator(
00408 m_vertex_barcodes.begin() ); }
00410 vertex_iterator vertices_end()
00411 { return GenEvent::vertex_iterator(
00412 m_vertex_barcodes.end() ); }
00413
00414 public:
00416
00418
00419
00420
00421
00422
00423
00424
00426
00430 class particle_const_iterator :
00431 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00432
00433 public:
00435 particle_const_iterator(
00436 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
00437 : m_map_iterator(i) {}
00438 particle_const_iterator() {}
00440 particle_const_iterator( const particle_const_iterator& i )
00441 { *this = i; }
00442 virtual ~particle_const_iterator() {}
00444 particle_const_iterator& operator=(
00445 const particle_const_iterator& i )
00446 { m_map_iterator = i.m_map_iterator; return *this; }
00448 GenParticle* operator*(void) const
00449 { return m_map_iterator->second; }
00451 particle_const_iterator& operator++(void)
00452 { ++m_map_iterator; return *this; }
00454 particle_const_iterator operator++(int)
00455 { particle_const_iterator out(*this); ++(*this); return out; }
00457 bool operator==( const particle_const_iterator& a ) const
00458 { return m_map_iterator == a.m_map_iterator; }
00460 bool operator!=( const particle_const_iterator& a ) const
00461 { return !(m_map_iterator == a.m_map_iterator); }
00462 protected:
00464 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
00465 private:
00467 particle_const_iterator& operator--(void);
00469 particle_const_iterator operator--(int);
00470 };
00471 friend class particle_const_iterator;
00473 particle_const_iterator particles_begin() const
00474 { return GenEvent::particle_const_iterator(
00475 m_particle_barcodes.begin() ); }
00477 particle_const_iterator particles_end() const
00478 { return GenEvent::particle_const_iterator(
00479 m_particle_barcodes.end() ); }
00480
00482
00486 class particle_iterator :
00487 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00488
00489 public:
00491 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
00492 : m_map_iterator( i ) {}
00493 particle_iterator() {}
00495 particle_iterator( const particle_iterator& i ) { *this = i; }
00496 virtual ~particle_iterator() {}
00498 particle_iterator& operator=( const particle_iterator& i ) {
00499 m_map_iterator = i.m_map_iterator;
00500 return *this;
00501 }
00503 operator particle_const_iterator() const
00504 { return particle_const_iterator(m_map_iterator); }
00506 GenParticle* operator*(void) const
00507 { return m_map_iterator->second; }
00509 particle_iterator& operator++(void)
00510 { ++m_map_iterator; return *this; }
00512 particle_iterator operator++(int)
00513 { particle_iterator out(*this); ++(*this); return out; }
00515 bool operator==( const particle_iterator& a ) const
00516 { return m_map_iterator == a.m_map_iterator; }
00518 bool operator!=( const particle_iterator& a ) const
00519 { return !(m_map_iterator == a.m_map_iterator); }
00520 protected:
00522 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
00523 private:
00525 particle_iterator& operator--(void);
00527 particle_iterator operator--(int);
00528 };
00529 friend class particle_iterator;
00531 particle_iterator particles_begin()
00532 { return GenEvent::particle_iterator(
00533 m_particle_barcodes.begin() ); }
00535 particle_iterator particles_end()
00536 { return GenEvent::particle_iterator(
00537 m_particle_barcodes.end() ); }
00538
00540 protected:
00541
00542
00543
00545 bool set_barcode( GenParticle* p, int suggested_barcode =false );
00547 bool set_barcode( GenVertex* v, int suggested_barcode =false );
00549 void remove_barcode( GenParticle* p );
00551 void remove_barcode( GenVertex* v );
00552
00553 void delete_all_vertices();
00554
00555 private:
00557 bool use_momentum_unit( Units::MomentumUnit );
00558 bool use_momentum_unit( std::string& );
00560 bool use_length_unit( Units::LengthUnit );
00561 bool use_length_unit( std::string& );
00562
00563
00564
00566 std::ostream & write_beam_particles( std::ostream &,
00567 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
00569 std::ostream & write_vertex( std::ostream &, GenVertex const * );
00571 std::ostream & write_particle( std::ostream&, GenParticle const * );
00573 std::istream & find_file_type( std::istream & );
00575 std::istream & find_end_key( std::istream &, int & );
00577 std::istream & read_units( std::istream & );
00578
00579 private:
00580 int m_signal_process_id;
00581 int m_event_number;
00582 int m_mpi;
00583 double m_event_scale;
00584 double m_alphaQCD;
00585 double m_alphaQED;
00586 GenVertex* m_signal_process_vertex;
00587 GenParticle* m_beam_particle_1;
00588 GenParticle* m_beam_particle_2;
00589 WeightContainer m_weights;
00590
00591 std::vector<long> m_random_states;
00592
00593
00594 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
00595 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
00596 GenCrossSection* m_cross_section;
00597 HeavyIon* m_heavy_ion;
00598 PdfInfo* m_pdf_info;
00599 Units::MomentumUnit m_momentum_unit;
00600 Units::LengthUnit m_position_unit;
00601
00602 };
00603
00604
00606
00608
00610 std::ostream & operator << (std::ostream &, GenEvent &);
00612 std::istream & operator >> (std::istream &, GenEvent &);
00614 std::istream & set_input_units(std::istream &,
00615 Units::MomentumUnit, Units::LengthUnit);
00617 std::ostream & write_HepMC_IO_block_begin(std::ostream & );
00619 std::ostream & write_HepMC_IO_block_end(std::ostream & );
00620
00621
00623
00625
00626
00627 inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l)
00628 {
00629 evt.use_units(m, l);
00630 return evt;
00631 }
00632
00634
00636
00641 inline int GenEvent::signal_process_id() const
00642 { return m_signal_process_id; }
00643
00644 inline int GenEvent::event_number() const { return m_event_number; }
00645
00648 inline int GenEvent::mpi() const { return m_mpi; }
00649
00650 inline double GenEvent::event_scale() const { return m_event_scale; }
00651
00652 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
00653
00654 inline double GenEvent::alphaQED() const { return m_alphaQED; }
00655
00656 inline GenVertex* GenEvent::signal_process_vertex() const {
00658 return m_signal_process_vertex;
00659 }
00660
00661 inline WeightContainer& GenEvent::weights() { return m_weights; }
00662
00663 inline const WeightContainer& GenEvent::weights() const
00664 { return m_weights; }
00665
00666 inline GenCrossSection const * GenEvent::cross_section() const
00667 { return m_cross_section; }
00668
00669 inline GenCrossSection* GenEvent::cross_section()
00670 { return m_cross_section; }
00671
00672 inline HeavyIon const * GenEvent::heavy_ion() const
00673 { return m_heavy_ion; }
00674
00675 inline HeavyIon* GenEvent::heavy_ion()
00676 { return m_heavy_ion; }
00677
00678 inline PdfInfo const * GenEvent::pdf_info() const
00679 { return m_pdf_info; }
00680
00681 inline PdfInfo* GenEvent::pdf_info()
00682 { return m_pdf_info; }
00683
00689 inline const std::vector<long>& GenEvent::random_states() const
00690 { return m_random_states; }
00691
00692 inline void GenEvent::set_signal_process_id( int id )
00693 { m_signal_process_id = id; }
00694
00695 inline void GenEvent::set_event_number( int eventno )
00696 { m_event_number = eventno; }
00697
00699 inline void GenEvent::set_mpi( int nmpi )
00700 { m_mpi = nmpi; }
00701
00702
00703 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
00704
00705 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
00706
00707 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
00708
00709 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
00710 m_signal_process_vertex = vtx;
00711 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
00712 }
00713
00714 inline void GenEvent::set_cross_section( const GenCrossSection& xs )
00715 {
00716 delete m_cross_section;
00717 m_cross_section = new GenCrossSection(xs);
00718 }
00719
00720 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
00721 {
00722 delete m_heavy_ion;
00723 m_heavy_ion = new HeavyIon(ion);
00724 }
00725
00726 inline void GenEvent::set_pdf_info( const PdfInfo& p )
00727 {
00728 delete m_pdf_info;
00729 m_pdf_info = new PdfInfo(p);
00730 }
00731
00732 inline void GenEvent::set_random_states( const std::vector<long>&
00733 randomstates )
00734 { m_random_states = randomstates; }
00735
00736 inline void GenEvent::remove_barcode( GenParticle* p )
00737 { m_particle_barcodes.erase( p->barcode() ); }
00738
00739 inline void GenEvent::remove_barcode( GenVertex* v )
00740 { m_vertex_barcodes.erase( v->barcode() ); }
00741
00755 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
00756 {
00757 std::map<int,HepMC::GenParticle*>::const_iterator i
00758 = m_particle_barcodes.find(barCode);
00759 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
00760 }
00761
00775 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
00776 {
00777 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
00778 = m_vertex_barcodes.find(barCode);
00779 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
00780 }
00781
00782 inline int GenEvent::particles_size() const {
00783 return (int)m_particle_barcodes.size();
00784 }
00785 inline bool GenEvent::particles_empty() const {
00786 return (bool)m_particle_barcodes.empty();
00787 }
00788 inline int GenEvent::vertices_size() const {
00789 return (int)m_vertex_barcodes.size();
00790 }
00791 inline bool GenEvent::vertices_empty() const {
00792 return (bool)m_vertex_barcodes.empty();
00793 }
00794
00795
00796 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
00797 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
00798 }
00799
00800
00801 inline Units::MomentumUnit GenEvent::momentum_unit() const {
00802 return m_momentum_unit;
00803 }
00804 inline Units::LengthUnit GenEvent::length_unit() const {
00805 return m_position_unit;
00806 }
00807
00808 inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
00809 use_momentum_unit( new_m );
00810 use_length_unit( new_l );
00811 }
00812
00813 inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) {
00814 use_momentum_unit( new_m );
00815 use_length_unit( new_l );
00816 }
00817
00818 }
00819
00820 #endif // HEPMC_GEN_EVENT_H
00821
00822
00823
00824