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
00124
00125
00126
00127 #include "HepMC/GenVertex.h"
00128 #include "HepMC/GenParticle.h"
00129 #include "HepMC/WeightContainer.h"
00130 #include "HepMC/GenCrossSection.h"
00131 #include "HepMC/HeavyIon.h"
00132 #include "HepMC/PdfInfo.h"
00133 #include "HepMC/Units.h"
00134 #include "HepMC/HepMCDefs.h"
00135 #include <map>
00136 #include <string>
00137 #include <vector>
00138 #include <algorithm>
00139 #include <iostream>
00140
00141 namespace HepMC {
00142
00143 class GenEventVertexRange;
00144 class ConstGenEventVertexRange;
00145 class GenEventParticleRange;
00146 class ConstGenEventParticleRange;
00147
00149
00155 class GenEvent {
00156 friend class GenParticle;
00157 friend class GenVertex;
00158 public:
00160 GenEvent( int signal_process_id = 0, int event_number = 0,
00161 GenVertex* signal_vertex = 0,
00162 const WeightContainer& weights = std::vector<double>(),
00163 const std::vector<long>& randomstates = std::vector<long>(),
00164 Units::MomentumUnit = Units::default_momentum_unit(),
00165 Units::LengthUnit = Units::default_length_unit() );
00167 GenEvent( int signal_process_id, int event_number,
00168 GenVertex* signal_vertex, const WeightContainer& weights,
00169 const std::vector<long>& randomstates,
00170 const HeavyIon& ion, const PdfInfo& pdf,
00171 Units::MomentumUnit = Units::default_momentum_unit(),
00172 Units::LengthUnit = Units::default_length_unit() );
00174 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00175 int signal_process_id = 0, int event_number = 0,
00176 GenVertex* signal_vertex = 0,
00177 const WeightContainer& weights = std::vector<double>(),
00178 const std::vector<long>& randomstates = std::vector<long>() );
00180 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00181 int signal_process_id, int event_number,
00182 GenVertex* signal_vertex, const WeightContainer& weights,
00183 const std::vector<long>& randomstates,
00184 const HeavyIon& ion, const PdfInfo& pdf );
00185 GenEvent( const GenEvent& inevent );
00186 GenEvent& operator=( const GenEvent& inevent );
00187 virtual ~GenEvent();
00188
00189 void swap( GenEvent & other );
00190
00191 void print( std::ostream& ostr = std::cout ) const;
00192 void print_version( std::ostream& ostr = std::cout ) const;
00193
00195 GenParticle* barcode_to_particle( int barCode ) const;
00197 GenVertex* barcode_to_vertex( int barCode ) const;
00198
00200
00202
00203 int signal_process_id() const;
00204 int event_number() const;
00205 int mpi() const;
00206 double event_scale() const;
00207 double alphaQCD() const;
00208 double alphaQED() const;
00209
00210 GenVertex* signal_process_vertex() const;
00212 bool valid_beam_particles() const;
00214 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const;
00217 bool is_valid() const;
00218
00224 WeightContainer& weights();
00225 const WeightContainer& weights() const;
00226
00228 GenCrossSection const * cross_section() const;
00229 GenCrossSection* cross_section();
00231 HeavyIon const * heavy_ion() const;
00232 HeavyIon* heavy_ion();
00234 PdfInfo const * pdf_info() const;
00235 PdfInfo* pdf_info();
00236
00238 const std::vector<long>& random_states() const;
00239
00241 int particles_size() const;
00243 bool particles_empty() const;
00245 int vertices_size() const;
00247 bool vertices_empty() const;
00248
00251 void write_units( std::ostream & os = std::cout ) const;
00255 void write_cross_section( std::ostream& ostr = std::cout ) const;
00256
00258 Units::MomentumUnit momentum_unit() const;
00260 Units::LengthUnit length_unit() const;
00261
00262 std::ostream& write(std::ostream&);
00263 std::istream& read(std::istream&);
00264
00266
00268
00269 bool add_vertex( GenVertex* vtx );
00270 bool remove_vertex( GenVertex* vtx );
00271 void clear();
00272
00273 void set_signal_process_id( int id );
00274 void set_event_number( int eventno );
00275 void set_mpi( int );
00276 void set_event_scale( double scale );
00277 void set_alphaQCD( double a );
00278 void set_alphaQED( double a );
00279
00281 void set_signal_process_vertex( GenVertex* );
00283 bool set_beam_particles(GenParticle*, GenParticle*);
00285 bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &);
00287 void set_random_states( const std::vector<long>& randomstates );
00288
00290 void set_cross_section( const GenCrossSection& );
00292 void set_heavy_ion( const HeavyIon& ion );
00294 void set_pdf_info( const PdfInfo& p );
00295
00298 void use_units( Units::MomentumUnit, Units::LengthUnit );
00302 void use_units( std::string&, std::string& );
00303
00306 void define_units( Units::MomentumUnit, Units::LengthUnit );
00310 void define_units( std::string&, std::string& );
00311
00313 GenEventVertexRange vertex_range();
00315 ConstGenEventVertexRange vertex_range() const;
00317 GenEventParticleRange particle_range();
00319 ConstGenEventParticleRange particle_range() const;
00320
00321 public:
00323
00325
00326
00327
00328
00330
00334 class vertex_const_iterator :
00335 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00336
00337 public:
00339 vertex_const_iterator(
00340 const
00341 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
00342 : m_map_iterator(i) {}
00343 vertex_const_iterator() {}
00345 vertex_const_iterator( const vertex_const_iterator& i )
00346 { *this = i; }
00347 virtual ~vertex_const_iterator() {}
00349 vertex_const_iterator& operator=( const vertex_const_iterator& i )
00350 { m_map_iterator = i.m_map_iterator; return *this; }
00352 GenVertex* operator*(void) const { return m_map_iterator->second; }
00354 vertex_const_iterator& operator++(void)
00355 { ++m_map_iterator; return *this; }
00357 vertex_const_iterator operator++(int)
00358 { vertex_const_iterator out(*this); ++(*this); return out; }
00360 bool operator==( const vertex_const_iterator& a ) const
00361 { return m_map_iterator == a.m_map_iterator; }
00363 bool operator!=( const vertex_const_iterator& a ) const
00364 { return !(m_map_iterator == a.m_map_iterator); }
00365 protected:
00367 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
00368 m_map_iterator;
00369 private:
00371 vertex_const_iterator& operator--(void);
00373 vertex_const_iterator operator--(int);
00374 };
00375 friend class vertex_const_iterator;
00377 vertex_const_iterator vertices_begin() const
00378 { return GenEvent::vertex_const_iterator(
00379 m_vertex_barcodes.begin() ); }
00381 vertex_const_iterator vertices_end() const
00382 { return GenEvent::vertex_const_iterator(
00383 m_vertex_barcodes.end() ); }
00384
00385
00387
00391 class vertex_iterator :
00392 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00393
00394 public:
00396 vertex_iterator(
00397 const
00398 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
00399 : m_map_iterator( i ) {}
00400 vertex_iterator() {}
00402 vertex_iterator( const vertex_iterator& i ) { *this = i; }
00403 virtual ~vertex_iterator() {}
00405 vertex_iterator& operator=( const vertex_iterator& i ) {
00406 m_map_iterator = i.m_map_iterator;
00407 return *this;
00408 }
00410 operator vertex_const_iterator() const
00411 { return vertex_const_iterator(m_map_iterator); }
00413 GenVertex* operator*(void) const
00414 { return m_map_iterator->second; }
00416 vertex_iterator& operator++(void)
00417 { ++m_map_iterator; return *this; }
00419 vertex_iterator operator++(int)
00420 { vertex_iterator out(*this); ++(*this); return out; }
00422 bool operator==( const vertex_iterator& a ) const
00423 { return m_map_iterator == a.m_map_iterator; }
00425 bool operator!=( const vertex_iterator& a ) const
00426 { return !(m_map_iterator == a.m_map_iterator); }
00427 protected:
00429 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
00430 m_map_iterator;
00431 private:
00433 vertex_iterator& operator--(void);
00435 vertex_iterator operator--(int);
00436
00437 };
00438 friend class vertex_iterator;
00440 vertex_iterator vertices_begin()
00441 { return GenEvent::vertex_iterator(
00442 m_vertex_barcodes.begin() ); }
00444 vertex_iterator vertices_end()
00445 { return GenEvent::vertex_iterator(
00446 m_vertex_barcodes.end() ); }
00447
00448 public:
00450
00452
00453
00454
00455
00456
00457
00458
00460
00464 class particle_const_iterator :
00465 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00466
00467 public:
00469 particle_const_iterator(
00470 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
00471 : m_map_iterator(i) {}
00472 particle_const_iterator() {}
00474 particle_const_iterator( const particle_const_iterator& i )
00475 { *this = i; }
00476 virtual ~particle_const_iterator() {}
00478 particle_const_iterator& operator=(
00479 const particle_const_iterator& i )
00480 { m_map_iterator = i.m_map_iterator; return *this; }
00482 GenParticle* operator*(void) const
00483 { return m_map_iterator->second; }
00485 particle_const_iterator& operator++(void)
00486 { ++m_map_iterator; return *this; }
00488 particle_const_iterator operator++(int)
00489 { particle_const_iterator out(*this); ++(*this); return out; }
00491 bool operator==( const particle_const_iterator& a ) const
00492 { return m_map_iterator == a.m_map_iterator; }
00494 bool operator!=( const particle_const_iterator& a ) const
00495 { return !(m_map_iterator == a.m_map_iterator); }
00496 protected:
00498 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
00499 private:
00501 particle_const_iterator& operator--(void);
00503 particle_const_iterator operator--(int);
00504 };
00505 friend class particle_const_iterator;
00507 particle_const_iterator particles_begin() const
00508 { return GenEvent::particle_const_iterator(
00509 m_particle_barcodes.begin() ); }
00511 particle_const_iterator particles_end() const
00512 { return GenEvent::particle_const_iterator(
00513 m_particle_barcodes.end() ); }
00514
00516
00520 class particle_iterator :
00521 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00522
00523 public:
00525 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
00526 : m_map_iterator( i ) {}
00527 particle_iterator() {}
00529 particle_iterator( const particle_iterator& i ) { *this = i; }
00530 virtual ~particle_iterator() {}
00532 particle_iterator& operator=( const particle_iterator& i ) {
00533 m_map_iterator = i.m_map_iterator;
00534 return *this;
00535 }
00537 operator particle_const_iterator() const
00538 { return particle_const_iterator(m_map_iterator); }
00540 GenParticle* operator*(void) const
00541 { return m_map_iterator->second; }
00543 particle_iterator& operator++(void)
00544 { ++m_map_iterator; return *this; }
00546 particle_iterator operator++(int)
00547 { particle_iterator out(*this); ++(*this); return out; }
00549 bool operator==( const particle_iterator& a ) const
00550 { return m_map_iterator == a.m_map_iterator; }
00552 bool operator!=( const particle_iterator& a ) const
00553 { return !(m_map_iterator == a.m_map_iterator); }
00554 protected:
00556 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
00557 private:
00559 particle_iterator& operator--(void);
00561 particle_iterator operator--(int);
00562 };
00563 friend class particle_iterator;
00565 particle_iterator particles_begin()
00566 { return GenEvent::particle_iterator(
00567 m_particle_barcodes.begin() ); }
00569 particle_iterator particles_end()
00570 { return GenEvent::particle_iterator(
00571 m_particle_barcodes.end() ); }
00572
00574 protected:
00575
00576
00577
00579 bool set_barcode( GenParticle* p, int suggested_barcode =false );
00581 bool set_barcode( GenVertex* v, int suggested_barcode =false );
00583 void remove_barcode( GenParticle* p );
00585 void remove_barcode( GenVertex* v );
00586
00587 void delete_all_vertices();
00588
00589 private:
00591 bool use_momentum_unit( Units::MomentumUnit );
00592 bool use_momentum_unit( std::string& );
00594 bool use_length_unit( Units::LengthUnit );
00595 bool use_length_unit( std::string& );
00596
00597
00598
00600 std::ostream & write_beam_particles( std::ostream &,
00601 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
00603 std::ostream & write_vertex( std::ostream &, GenVertex const * );
00605 std::ostream & write_particle( std::ostream&, GenParticle const * );
00607 std::istream & find_file_type( std::istream & );
00609 std::istream & find_end_key( std::istream &, int & );
00611 std::istream & read_units( std::istream & );
00613 std::istream & read_weight_names( std::istream & );
00615 std::istream & process_event_line( std::istream &, int &, int &, int &, int & );
00616
00617 private:
00618 int m_signal_process_id;
00619 int m_event_number;
00620 int m_mpi;
00621 double m_event_scale;
00622 double m_alphaQCD;
00623 double m_alphaQED;
00624 GenVertex* m_signal_process_vertex;
00625 GenParticle* m_beam_particle_1;
00626 GenParticle* m_beam_particle_2;
00627 WeightContainer m_weights;
00628
00629 std::vector<long> m_random_states;
00630
00631
00632 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
00633 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
00634 GenCrossSection* m_cross_section;
00635 HeavyIon* m_heavy_ion;
00636 PdfInfo* m_pdf_info;
00637 Units::MomentumUnit m_momentum_unit;
00638 Units::LengthUnit m_position_unit;
00639
00640 };
00641
00642
00644
00646
00648 std::ostream & operator << (std::ostream &, GenEvent &);
00650 std::istream & operator >> (std::istream &, GenEvent &);
00652 std::istream & set_input_units(std::istream &,
00653 Units::MomentumUnit, Units::LengthUnit);
00655 std::ostream & write_HepMC_IO_block_begin(std::ostream & );
00657 std::ostream & write_HepMC_IO_block_end(std::ostream & );
00658
00659
00661
00663
00664
00665 inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l)
00666 {
00667 evt.use_units(m, l);
00668 return evt;
00669 }
00670
00672
00674
00679 inline int GenEvent::signal_process_id() const
00680 { return m_signal_process_id; }
00681
00682 inline int GenEvent::event_number() const { return m_event_number; }
00683
00686 inline int GenEvent::mpi() const { return m_mpi; }
00687
00688 inline double GenEvent::event_scale() const { return m_event_scale; }
00689
00690 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
00691
00692 inline double GenEvent::alphaQED() const { return m_alphaQED; }
00693
00694 inline GenVertex* GenEvent::signal_process_vertex() const {
00696 return m_signal_process_vertex;
00697 }
00698
00699 inline WeightContainer& GenEvent::weights() { return m_weights; }
00700
00701 inline const WeightContainer& GenEvent::weights() const
00702 { return m_weights; }
00703
00704 inline GenCrossSection const * GenEvent::cross_section() const
00705 { return m_cross_section; }
00706
00707 inline GenCrossSection* GenEvent::cross_section()
00708 { return m_cross_section; }
00709
00710 inline HeavyIon const * GenEvent::heavy_ion() const
00711 { return m_heavy_ion; }
00712
00713 inline HeavyIon* GenEvent::heavy_ion()
00714 { return m_heavy_ion; }
00715
00716 inline PdfInfo const * GenEvent::pdf_info() const
00717 { return m_pdf_info; }
00718
00719 inline PdfInfo* GenEvent::pdf_info()
00720 { return m_pdf_info; }
00721
00727 inline const std::vector<long>& GenEvent::random_states() const
00728 { return m_random_states; }
00729
00730 inline void GenEvent::set_signal_process_id( int id )
00731 { m_signal_process_id = id; }
00732
00733 inline void GenEvent::set_event_number( int eventno )
00734 { m_event_number = eventno; }
00735
00737 inline void GenEvent::set_mpi( int nmpi )
00738 { m_mpi = nmpi; }
00739
00740
00741 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
00742
00743 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
00744
00745 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
00746
00747 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
00748 m_signal_process_vertex = vtx;
00749 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
00750 }
00751
00752 inline void GenEvent::set_cross_section( const GenCrossSection& xs )
00753 {
00754 delete m_cross_section;
00755 m_cross_section = new GenCrossSection(xs);
00756 }
00757
00758 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
00759 {
00760 delete m_heavy_ion;
00761 m_heavy_ion = new HeavyIon(ion);
00762 }
00763
00764 inline void GenEvent::set_pdf_info( const PdfInfo& p )
00765 {
00766 delete m_pdf_info;
00767 m_pdf_info = new PdfInfo(p);
00768 }
00769
00770 inline void GenEvent::set_random_states( const std::vector<long>&
00771 randomstates )
00772 { m_random_states = randomstates; }
00773
00774 inline void GenEvent::remove_barcode( GenParticle* p )
00775 { m_particle_barcodes.erase( p->barcode() ); }
00776
00777 inline void GenEvent::remove_barcode( GenVertex* v )
00778 { m_vertex_barcodes.erase( v->barcode() ); }
00779
00798 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
00799 {
00800 std::map<int,HepMC::GenParticle*>::const_iterator i
00801 = m_particle_barcodes.find(barCode);
00802 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
00803 }
00804
00823 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
00824 {
00825 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
00826 = m_vertex_barcodes.find(barCode);
00827 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
00828 }
00829
00830 inline int GenEvent::particles_size() const {
00831 return (int)m_particle_barcodes.size();
00832 }
00833 inline bool GenEvent::particles_empty() const {
00834 return (bool)m_particle_barcodes.empty();
00835 }
00836 inline int GenEvent::vertices_size() const {
00837 return (int)m_vertex_barcodes.size();
00838 }
00839 inline bool GenEvent::vertices_empty() const {
00840 return (bool)m_vertex_barcodes.empty();
00841 }
00842
00843
00844 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
00845 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
00846 }
00847
00848
00849 inline Units::MomentumUnit GenEvent::momentum_unit() const {
00850 return m_momentum_unit;
00851 }
00852 inline Units::LengthUnit GenEvent::length_unit() const {
00853 return m_position_unit;
00854 }
00855
00856 inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
00857 use_momentum_unit( new_m );
00858 use_length_unit( new_l );
00859 }
00860
00861 inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) {
00862 use_momentum_unit( new_m );
00863 use_length_unit( new_l );
00864 }
00865
00866 inline void GenEvent::define_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
00867 m_momentum_unit = new_m;
00868 m_position_unit = new_l;
00869 }
00870
00871 }
00872
00873 #endif // HEPMC_GEN_EVENT_H
00874
00875
00876
00877