File indexing completed on 2025-01-18 10:01:09
0001
0002 #ifndef HEPMC_GEN_EVENT_H
0003 #define HEPMC_GEN_EVENT_H
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 namespace HepMC {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 template <class InputIterator, class OutputIterator, class Predicate>
0050 void copy_if( InputIterator first, InputIterator last, OutputIterator out,
0051 Predicate pred ) {
0052 for ( ; first != last; ++first ) { if ( pred(*first) ) out = *first; }
0053 }
0054 }
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 #include "HepMC/GenVertex.h"
0128 #include "HepMC/GenParticle.h"
0129 #include "HepMC/WeightContainer.h"
0130 #include "HepMC/GenCrossSection.h"
0131 #include "HepMC/HeavyIon.h"
0132 #include "HepMC/PdfInfo.h"
0133 #include "HepMC/Units.h"
0134 #include "HepMC/HepMCDefs.h"
0135 #include <map>
0136 #include <string>
0137 #include <vector>
0138 #include <algorithm>
0139 #include <iostream>
0140
0141 namespace HepMC {
0142
0143 class GenEventVertexRange;
0144 class ConstGenEventVertexRange;
0145 class GenEventParticleRange;
0146 class ConstGenEventParticleRange;
0147
0148
0149
0150
0151
0152
0153
0154
0155 class GenEvent {
0156 friend class GenParticle;
0157 friend class GenVertex;
0158 public:
0159
0160 GenEvent( int signal_process_id = 0, int event_number = 0,
0161 GenVertex* signal_vertex = 0,
0162 const WeightContainer& weights = std::vector<double>(),
0163 const std::vector<long>& randomstates = std::vector<long>(),
0164 Units::MomentumUnit = Units::default_momentum_unit(),
0165 Units::LengthUnit = Units::default_length_unit() );
0166
0167 GenEvent( int signal_process_id, int event_number,
0168 GenVertex* signal_vertex, const WeightContainer& weights,
0169 const std::vector<long>& randomstates,
0170 const HeavyIon& ion, const PdfInfo& pdf,
0171 Units::MomentumUnit = Units::default_momentum_unit(),
0172 Units::LengthUnit = Units::default_length_unit() );
0173
0174 GenEvent( Units::MomentumUnit, Units::LengthUnit,
0175 int signal_process_id = 0, int event_number = 0,
0176 GenVertex* signal_vertex = 0,
0177 const WeightContainer& weights = std::vector<double>(),
0178 const std::vector<long>& randomstates = std::vector<long>() );
0179
0180 GenEvent( Units::MomentumUnit, Units::LengthUnit,
0181 int signal_process_id, int event_number,
0182 GenVertex* signal_vertex, const WeightContainer& weights,
0183 const std::vector<long>& randomstates,
0184 const HeavyIon& ion, const PdfInfo& pdf );
0185 GenEvent( const GenEvent& inevent );
0186 GenEvent& operator=( const GenEvent& inevent );
0187 virtual ~GenEvent();
0188
0189 void swap( GenEvent & other );
0190
0191 void print( std::ostream& ostr = std::cout ) const;
0192 void print_version( std::ostream& ostr = std::cout ) const;
0193
0194
0195 GenParticle* barcode_to_particle( int barCode ) const;
0196
0197 GenVertex* barcode_to_vertex( int barCode ) const;
0198
0199
0200
0201
0202
0203 int signal_process_id() const;
0204 int event_number() const;
0205 int mpi() const;
0206 double event_scale() const;
0207 double alphaQCD() const;
0208 double alphaQED() const;
0209
0210 GenVertex* signal_process_vertex() const;
0211
0212 bool valid_beam_particles() const;
0213
0214 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const;
0215
0216
0217 bool is_valid() const;
0218
0219
0220
0221
0222
0223
0224 WeightContainer& weights();
0225 const WeightContainer& weights() const;
0226
0227
0228 GenCrossSection const * cross_section() const;
0229 GenCrossSection* cross_section();
0230
0231 HeavyIon const * heavy_ion() const;
0232 HeavyIon* heavy_ion();
0233
0234 PdfInfo const * pdf_info() const;
0235 PdfInfo* pdf_info();
0236
0237
0238 const std::vector<long>& random_states() const;
0239
0240
0241 int particles_size() const;
0242
0243 bool particles_empty() const;
0244
0245 int vertices_size() const;
0246
0247 bool vertices_empty() const;
0248
0249
0250
0251 void write_units( std::ostream & os = std::cout ) const;
0252
0253
0254
0255 void write_cross_section( std::ostream& ostr = std::cout ) const;
0256
0257
0258 Units::MomentumUnit momentum_unit() const;
0259
0260 Units::LengthUnit length_unit() const;
0261
0262 std::ostream& write(std::ostream&);
0263 std::istream& read(std::istream&);
0264
0265
0266
0267
0268
0269 bool add_vertex( GenVertex* vtx );
0270 bool remove_vertex( GenVertex* vtx );
0271 void clear();
0272
0273 void set_signal_process_id( int id );
0274 void set_event_number( int eventno );
0275 void set_mpi( int );
0276 void set_event_scale( double scale );
0277 void set_alphaQCD( double a );
0278 void set_alphaQED( double a );
0279
0280
0281 void set_signal_process_vertex( GenVertex* );
0282
0283 bool set_beam_particles(GenParticle*, GenParticle*);
0284
0285 bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &);
0286
0287 void set_random_states( const std::vector<long>& randomstates );
0288
0289
0290 void set_cross_section( const GenCrossSection& );
0291
0292 void set_heavy_ion( const HeavyIon& ion );
0293
0294 void set_pdf_info( const PdfInfo& p );
0295
0296
0297
0298 void use_units( Units::MomentumUnit, Units::LengthUnit );
0299
0300
0301
0302 void use_units( std::string&, std::string& );
0303
0304
0305
0306 void define_units( Units::MomentumUnit, Units::LengthUnit );
0307
0308
0309
0310 void define_units( std::string&, std::string& );
0311
0312
0313 GenEventVertexRange vertex_range();
0314
0315 ConstGenEventVertexRange vertex_range() const;
0316
0317 GenEventParticleRange particle_range();
0318
0319 ConstGenEventParticleRange particle_range() const;
0320
0321 public:
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334 class vertex_const_iterator :
0335 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
0336
0337 public:
0338
0339 vertex_const_iterator(
0340 const
0341 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
0342 : m_map_iterator(i) {}
0343 vertex_const_iterator() {}
0344
0345 vertex_const_iterator( const vertex_const_iterator& i )
0346 { *this = i; }
0347 virtual ~vertex_const_iterator() {}
0348
0349 vertex_const_iterator& operator=( const vertex_const_iterator& i )
0350 { m_map_iterator = i.m_map_iterator; return *this; }
0351
0352 GenVertex* operator*(void) const { return m_map_iterator->second; }
0353
0354 vertex_const_iterator& operator++(void)
0355 { ++m_map_iterator; return *this; }
0356
0357 vertex_const_iterator operator++(int)
0358 { vertex_const_iterator out(*this); ++(*this); return out; }
0359
0360 bool operator==( const vertex_const_iterator& a ) const
0361 { return m_map_iterator == a.m_map_iterator; }
0362
0363 bool operator!=( const vertex_const_iterator& a ) const
0364 { return !(m_map_iterator == a.m_map_iterator); }
0365 protected:
0366
0367 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
0368 m_map_iterator;
0369 private:
0370
0371 vertex_const_iterator& operator--(void);
0372
0373 vertex_const_iterator operator--(int);
0374 };
0375 friend class vertex_const_iterator;
0376
0377 vertex_const_iterator vertices_begin() const
0378 { return GenEvent::vertex_const_iterator(
0379 m_vertex_barcodes.begin() ); }
0380
0381 vertex_const_iterator vertices_end() const
0382 { return GenEvent::vertex_const_iterator(
0383 m_vertex_barcodes.end() ); }
0384
0385
0386
0387
0388
0389
0390
0391 class vertex_iterator :
0392 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
0393
0394 public:
0395
0396 vertex_iterator(
0397 const
0398 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
0399 : m_map_iterator( i ) {}
0400 vertex_iterator() {}
0401
0402 vertex_iterator( const vertex_iterator& i ) { *this = i; }
0403 virtual ~vertex_iterator() {}
0404
0405 vertex_iterator& operator=( const vertex_iterator& i ) {
0406 m_map_iterator = i.m_map_iterator;
0407 return *this;
0408 }
0409
0410 operator vertex_const_iterator() const
0411 { return vertex_const_iterator(m_map_iterator); }
0412
0413 GenVertex* operator*(void) const
0414 { return m_map_iterator->second; }
0415
0416 vertex_iterator& operator++(void)
0417 { ++m_map_iterator; return *this; }
0418
0419 vertex_iterator operator++(int)
0420 { vertex_iterator out(*this); ++(*this); return out; }
0421
0422 bool operator==( const vertex_iterator& a ) const
0423 { return m_map_iterator == a.m_map_iterator; }
0424
0425 bool operator!=( const vertex_iterator& a ) const
0426 { return !(m_map_iterator == a.m_map_iterator); }
0427 protected:
0428
0429 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
0430 m_map_iterator;
0431 private:
0432
0433 vertex_iterator& operator--(void);
0434
0435 vertex_iterator operator--(int);
0436
0437 };
0438 friend class vertex_iterator;
0439
0440 vertex_iterator vertices_begin()
0441 { return GenEvent::vertex_iterator(
0442 m_vertex_barcodes.begin() ); }
0443
0444 vertex_iterator vertices_end()
0445 { return GenEvent::vertex_iterator(
0446 m_vertex_barcodes.end() ); }
0447
0448 public:
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464 class particle_const_iterator :
0465 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
0466
0467 public:
0468
0469 particle_const_iterator(
0470 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
0471 : m_map_iterator(i) {}
0472 particle_const_iterator() {}
0473
0474 particle_const_iterator( const particle_const_iterator& i )
0475 { *this = i; }
0476 virtual ~particle_const_iterator() {}
0477
0478 particle_const_iterator& operator=(
0479 const particle_const_iterator& i )
0480 { m_map_iterator = i.m_map_iterator; return *this; }
0481
0482 GenParticle* operator*(void) const
0483 { return m_map_iterator->second; }
0484
0485 particle_const_iterator& operator++(void)
0486 { ++m_map_iterator; return *this; }
0487
0488 particle_const_iterator operator++(int)
0489 { particle_const_iterator out(*this); ++(*this); return out; }
0490
0491 bool operator==( const particle_const_iterator& a ) const
0492 { return m_map_iterator == a.m_map_iterator; }
0493
0494 bool operator!=( const particle_const_iterator& a ) const
0495 { return !(m_map_iterator == a.m_map_iterator); }
0496 protected:
0497
0498 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
0499 private:
0500
0501 particle_const_iterator& operator--(void);
0502
0503 particle_const_iterator operator--(int);
0504 };
0505 friend class particle_const_iterator;
0506
0507 particle_const_iterator particles_begin() const
0508 { return GenEvent::particle_const_iterator(
0509 m_particle_barcodes.begin() ); }
0510
0511 particle_const_iterator particles_end() const
0512 { return GenEvent::particle_const_iterator(
0513 m_particle_barcodes.end() ); }
0514
0515
0516
0517
0518
0519
0520 class particle_iterator :
0521 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
0522
0523 public:
0524
0525 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
0526 : m_map_iterator( i ) {}
0527 particle_iterator() {}
0528
0529 particle_iterator( const particle_iterator& i ) { *this = i; }
0530 virtual ~particle_iterator() {}
0531
0532 particle_iterator& operator=( const particle_iterator& i ) {
0533 m_map_iterator = i.m_map_iterator;
0534 return *this;
0535 }
0536
0537 operator particle_const_iterator() const
0538 { return particle_const_iterator(m_map_iterator); }
0539
0540 GenParticle* operator*(void) const
0541 { return m_map_iterator->second; }
0542
0543 particle_iterator& operator++(void)
0544 { ++m_map_iterator; return *this; }
0545
0546 particle_iterator operator++(int)
0547 { particle_iterator out(*this); ++(*this); return out; }
0548
0549 bool operator==( const particle_iterator& a ) const
0550 { return m_map_iterator == a.m_map_iterator; }
0551
0552 bool operator!=( const particle_iterator& a ) const
0553 { return !(m_map_iterator == a.m_map_iterator); }
0554 protected:
0555
0556 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
0557 private:
0558
0559 particle_iterator& operator--(void);
0560
0561 particle_iterator operator--(int);
0562 };
0563 friend class particle_iterator;
0564
0565 particle_iterator particles_begin()
0566 { return GenEvent::particle_iterator(
0567 m_particle_barcodes.begin() ); }
0568
0569 particle_iterator particles_end()
0570 { return GenEvent::particle_iterator(
0571 m_particle_barcodes.end() ); }
0572
0573
0574 protected:
0575
0576
0577
0578
0579 bool set_barcode( GenParticle* p, int suggested_barcode =false );
0580
0581 bool set_barcode( GenVertex* v, int suggested_barcode =false );
0582
0583 void remove_barcode( GenParticle* p );
0584
0585 void remove_barcode( GenVertex* v );
0586
0587 void delete_all_vertices();
0588
0589 private:
0590
0591 bool use_momentum_unit( Units::MomentumUnit );
0592 bool use_momentum_unit( std::string& );
0593
0594 bool use_length_unit( Units::LengthUnit );
0595 bool use_length_unit( std::string& );
0596
0597
0598
0599
0600 std::ostream & write_beam_particles( std::ostream &,
0601 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
0602
0603 std::ostream & write_vertex( std::ostream &, GenVertex const * );
0604
0605 std::ostream & write_particle( std::ostream&, GenParticle const * );
0606
0607 std::istream & find_file_type( std::istream & );
0608
0609 std::istream & find_end_key( std::istream &, int & );
0610
0611 std::istream & read_units( std::istream & );
0612
0613 std::istream & read_weight_names( std::istream & );
0614
0615 std::istream & process_event_line( std::istream &, int &, int &, int &, int & );
0616
0617 private:
0618 int m_signal_process_id;
0619 int m_event_number;
0620 int m_mpi;
0621 double m_event_scale;
0622 double m_alphaQCD;
0623 double m_alphaQED;
0624 GenVertex* m_signal_process_vertex;
0625 GenParticle* m_beam_particle_1;
0626 GenParticle* m_beam_particle_2;
0627 WeightContainer m_weights;
0628
0629 std::vector<long> m_random_states;
0630
0631
0632 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
0633 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
0634 GenCrossSection* m_cross_section;
0635 HeavyIon* m_heavy_ion;
0636 PdfInfo* m_pdf_info;
0637 Units::MomentumUnit m_momentum_unit;
0638 Units::LengthUnit m_position_unit;
0639
0640 };
0641
0642
0643
0644
0645
0646
0647
0648 std::ostream & operator << (std::ostream &, GenEvent &);
0649
0650 std::istream & operator >> (std::istream &, GenEvent &);
0651
0652 std::istream & set_input_units(std::istream &,
0653 Units::MomentumUnit, Units::LengthUnit);
0654
0655 std::ostream & write_HepMC_IO_block_begin(std::ostream & );
0656
0657 std::ostream & write_HepMC_IO_block_end(std::ostream & );
0658
0659
0660
0661
0662
0663
0664
0665 inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l)
0666 {
0667 evt.use_units(m, l);
0668 return evt;
0669 }
0670
0671
0672
0673
0674
0675
0676
0677
0678
0679 inline int GenEvent::signal_process_id() const
0680 { return m_signal_process_id; }
0681
0682 inline int GenEvent::event_number() const { return m_event_number; }
0683
0684
0685
0686 inline int GenEvent::mpi() const { return m_mpi; }
0687
0688 inline double GenEvent::event_scale() const { return m_event_scale; }
0689
0690 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
0691
0692 inline double GenEvent::alphaQED() const { return m_alphaQED; }
0693
0694 inline GenVertex* GenEvent::signal_process_vertex() const {
0695
0696 return m_signal_process_vertex;
0697 }
0698
0699 inline WeightContainer& GenEvent::weights() { return m_weights; }
0700
0701 inline const WeightContainer& GenEvent::weights() const
0702 { return m_weights; }
0703
0704 inline GenCrossSection const * GenEvent::cross_section() const
0705 { return m_cross_section; }
0706
0707 inline GenCrossSection* GenEvent::cross_section()
0708 { return m_cross_section; }
0709
0710 inline HeavyIon const * GenEvent::heavy_ion() const
0711 { return m_heavy_ion; }
0712
0713 inline HeavyIon* GenEvent::heavy_ion()
0714 { return m_heavy_ion; }
0715
0716 inline PdfInfo const * GenEvent::pdf_info() const
0717 { return m_pdf_info; }
0718
0719 inline PdfInfo* GenEvent::pdf_info()
0720 { return m_pdf_info; }
0721
0722
0723
0724
0725
0726
0727 inline const std::vector<long>& GenEvent::random_states() const
0728 { return m_random_states; }
0729
0730 inline void GenEvent::set_signal_process_id( int id )
0731 { m_signal_process_id = id; }
0732
0733 inline void GenEvent::set_event_number( int eventno )
0734 { m_event_number = eventno; }
0735
0736
0737 inline void GenEvent::set_mpi( int nmpi )
0738 { m_mpi = nmpi; }
0739
0740
0741 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
0742
0743 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
0744
0745 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
0746
0747 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
0748 m_signal_process_vertex = vtx;
0749 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
0750 }
0751
0752 inline void GenEvent::set_cross_section( const GenCrossSection& xs )
0753 {
0754 delete m_cross_section;
0755 m_cross_section = new GenCrossSection(xs);
0756 }
0757
0758 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
0759 {
0760 delete m_heavy_ion;
0761 m_heavy_ion = new HeavyIon(ion);
0762 }
0763
0764 inline void GenEvent::set_pdf_info( const PdfInfo& p )
0765 {
0766 delete m_pdf_info;
0767 m_pdf_info = new PdfInfo(p);
0768 }
0769
0770 inline void GenEvent::set_random_states( const std::vector<long>&
0771 randomstates )
0772 { m_random_states = randomstates; }
0773
0774 inline void GenEvent::remove_barcode( GenParticle* p )
0775 { m_particle_barcodes.erase( p->barcode() ); }
0776
0777 inline void GenEvent::remove_barcode( GenVertex* v )
0778 { m_vertex_barcodes.erase( v->barcode() ); }
0779
0780
0781
0782
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792
0793
0794
0795
0796
0797
0798 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
0799 {
0800 std::map<int,HepMC::GenParticle*>::const_iterator i
0801 = m_particle_barcodes.find(barCode);
0802 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
0803 }
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
0824 {
0825 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
0826 = m_vertex_barcodes.find(barCode);
0827 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
0828 }
0829
0830 inline int GenEvent::particles_size() const {
0831 return (int)m_particle_barcodes.size();
0832 }
0833 inline bool GenEvent::particles_empty() const {
0834 return (bool)m_particle_barcodes.empty();
0835 }
0836 inline int GenEvent::vertices_size() const {
0837 return (int)m_vertex_barcodes.size();
0838 }
0839 inline bool GenEvent::vertices_empty() const {
0840 return (bool)m_vertex_barcodes.empty();
0841 }
0842
0843
0844 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
0845 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
0846 }
0847
0848
0849 inline Units::MomentumUnit GenEvent::momentum_unit() const {
0850 return m_momentum_unit;
0851 }
0852 inline Units::LengthUnit GenEvent::length_unit() const {
0853 return m_position_unit;
0854 }
0855
0856 inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
0857 use_momentum_unit( new_m );
0858 use_length_unit( new_l );
0859 }
0860
0861 inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) {
0862 use_momentum_unit( new_m );
0863 use_length_unit( new_l );
0864 }
0865
0866 inline void GenEvent::define_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
0867 m_momentum_unit = new_m;
0868 m_position_unit = new_l;
0869 }
0870
0871 }
0872
0873 #endif
0874
0875
0876
0877