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 "HepMC/Units.h"
00129 #include "HepMC/HepMCDefs.h"
00130 #include <map>
00131 #include <string>
00132 #include <vector>
00133 #include <algorithm>
00134 #include <iostream>
00135
00136 namespace HepMC {
00137
00139
00145 class GenEvent {
00146 friend class GenParticle;
00147 friend class GenVertex;
00148 public:
00150 GenEvent( int signal_process_id = 0, int event_number = 0,
00151 GenVertex* signal_vertex = 0,
00152 const WeightContainer& weights = std::vector<double>(),
00153 const std::vector<long>& randomstates = std::vector<long>(),
00154 Units::MomentumUnit = Units::default_momentum_unit(),
00155 Units::LengthUnit = Units::default_length_unit() );
00157 GenEvent( int signal_process_id, int event_number,
00158 GenVertex* signal_vertex, const WeightContainer& weights,
00159 const std::vector<long>& randomstates,
00160 const HeavyIon& ion, const PdfInfo& pdf,
00161 Units::MomentumUnit = Units::default_momentum_unit(),
00162 Units::LengthUnit = Units::default_length_unit() );
00164 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00165 int signal_process_id = 0, int event_number = 0,
00166 GenVertex* signal_vertex = 0,
00167 const WeightContainer& weights = std::vector<double>(),
00168 const std::vector<long>& randomstates = std::vector<long>() );
00170 GenEvent( Units::MomentumUnit, Units::LengthUnit,
00171 int signal_process_id, int event_number,
00172 GenVertex* signal_vertex, const WeightContainer& weights,
00173 const std::vector<long>& randomstates,
00174 const HeavyIon& ion, const PdfInfo& pdf );
00175 GenEvent( const GenEvent& inevent );
00176 GenEvent& operator=( const GenEvent& inevent );
00177 virtual ~GenEvent();
00178
00179 void swap( GenEvent & other );
00180
00181 void print( std::ostream& ostr = std::cout ) const;
00182 void print_version( std::ostream& ostr = std::cout ) const;
00183
00185 GenParticle* barcode_to_particle( int barCode ) const;
00187 GenVertex* barcode_to_vertex( int barCode ) const;
00188
00190
00192
00193 int signal_process_id() const;
00194 int event_number() const;
00195 int mpi() const;
00196 double event_scale() const;
00197 double alphaQCD() const;
00198 double alphaQED() const;
00199
00200 GenVertex* signal_process_vertex() const;
00202 bool valid_beam_particles() const;
00204 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const;
00205
00211 WeightContainer& weights();
00212 const WeightContainer& weights() const;
00213
00215 HeavyIon const * heavy_ion() const;
00216 HeavyIon* heavy_ion();
00218 PdfInfo const * pdf_info() const;
00219 PdfInfo* pdf_info();
00220
00222 const std::vector<long>& random_states() const;
00223
00225 int particles_size() const;
00227 bool particles_empty() const;
00229 int vertices_size() const;
00231 bool vertices_empty() const;
00232
00233 void write_units( std::ostream & os = std::cout ) const;
00234
00236 Units::MomentumUnit momentum_unit() const;
00238 Units::LengthUnit length_unit() const;
00239
00241
00243
00244 bool add_vertex( GenVertex* vtx );
00245 bool remove_vertex( GenVertex* vtx );
00246 void clear();
00247
00248 void set_signal_process_id( int id );
00249 void set_event_number( int eventno );
00250 void set_mpi( int );
00251 void set_event_scale( double scale );
00252 void set_alphaQCD( double a );
00253 void set_alphaQED( double a );
00254
00256 void set_signal_process_vertex( GenVertex* );
00258 bool set_beam_particles(GenParticle*, GenParticle*);
00260 bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &);
00262 void set_random_states( const std::vector<long>& randomstates );
00263
00265 void set_heavy_ion( const HeavyIon& ion );
00267 void set_pdf_info( const PdfInfo& p );
00268
00270 void use_units( Units::MomentumUnit, Units::LengthUnit );
00273 void use_units( std::string&, std::string& );
00274
00275 public:
00277
00279
00280
00281
00282
00284
00288 class vertex_const_iterator :
00289 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00290
00291 public:
00293 vertex_const_iterator(
00294 const
00295 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
00296 : m_map_iterator(i) {}
00297 vertex_const_iterator() {}
00299 vertex_const_iterator( const vertex_const_iterator& i )
00300 { *this = i; }
00301 virtual ~vertex_const_iterator() {}
00303 vertex_const_iterator& operator=( const vertex_const_iterator& i )
00304 { m_map_iterator = i.m_map_iterator; return *this; }
00306 GenVertex* operator*(void) const { return m_map_iterator->second; }
00308 vertex_const_iterator& operator++(void)
00309 { ++m_map_iterator; return *this; }
00311 vertex_const_iterator operator++(int)
00312 { vertex_const_iterator out(*this); ++(*this); return out; }
00314 bool operator==( const vertex_const_iterator& a ) const
00315 { return m_map_iterator == a.m_map_iterator; }
00317 bool operator!=( const vertex_const_iterator& a ) const
00318 { return !(m_map_iterator == a.m_map_iterator); }
00319 protected:
00321 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
00322 m_map_iterator;
00323 };
00324 friend class vertex_const_iterator;
00326 vertex_const_iterator vertices_begin() const
00327 { return GenEvent::vertex_const_iterator(
00328 m_vertex_barcodes.begin() ); }
00330 vertex_const_iterator vertices_end() const
00331 { return GenEvent::vertex_const_iterator(
00332 m_vertex_barcodes.end() ); }
00333
00334
00336
00340 class vertex_iterator :
00341 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
00342
00343 public:
00345 vertex_iterator(
00346 const
00347 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
00348 : m_map_iterator( i ) {}
00349 vertex_iterator() {}
00351 vertex_iterator( const vertex_iterator& i ) { *this = i; }
00352 virtual ~vertex_iterator() {}
00354 vertex_iterator& operator=( const vertex_iterator& i ) {
00355 m_map_iterator = i.m_map_iterator;
00356 return *this;
00357 }
00359 operator vertex_const_iterator() const
00360 { return vertex_const_iterator(m_map_iterator); }
00362 GenVertex* operator*(void) const
00363 { return m_map_iterator->second; }
00365 vertex_iterator& operator++(void)
00366 { ++m_map_iterator; return *this; }
00368 vertex_iterator operator++(int)
00369 { vertex_iterator out(*this); ++(*this); return out; }
00371 bool operator==( const vertex_iterator& a ) const
00372 { return m_map_iterator == a.m_map_iterator; }
00374 bool operator!=( const vertex_iterator& a ) const
00375 { return !(m_map_iterator == a.m_map_iterator); }
00376 protected:
00378 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
00379 m_map_iterator;
00380 };
00381 friend class vertex_iterator;
00383 vertex_iterator vertices_begin()
00384 { return GenEvent::vertex_iterator(
00385 m_vertex_barcodes.begin() ); }
00387 vertex_iterator vertices_end()
00388 { return GenEvent::vertex_iterator(
00389 m_vertex_barcodes.end() ); }
00390
00391 public:
00393
00395
00396
00397
00398
00399
00400
00401
00403
00407 class particle_const_iterator :
00408 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00409
00410 public:
00412 particle_const_iterator(
00413 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
00414 : m_map_iterator(i) {}
00415 particle_const_iterator() {}
00417 particle_const_iterator( const particle_const_iterator& i )
00418 { *this = i; }
00419 virtual ~particle_const_iterator() {}
00421 particle_const_iterator& operator=(
00422 const particle_const_iterator& i )
00423 { m_map_iterator = i.m_map_iterator; return *this; }
00425 GenParticle* operator*(void) const
00426 { return m_map_iterator->second; }
00428 particle_const_iterator& operator++(void)
00429 { ++m_map_iterator; return *this; }
00431 particle_const_iterator operator++(int)
00432 { particle_const_iterator out(*this); ++(*this); return out; }
00434 bool operator==( const particle_const_iterator& a ) const
00435 { return m_map_iterator == a.m_map_iterator; }
00437 bool operator!=( const particle_const_iterator& a ) const
00438 { return !(m_map_iterator == a.m_map_iterator); }
00439 protected:
00441 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
00442 };
00443 friend class particle_const_iterator;
00445 particle_const_iterator particles_begin() const
00446 { return GenEvent::particle_const_iterator(
00447 m_particle_barcodes.begin() ); }
00449 particle_const_iterator particles_end() const
00450 { return GenEvent::particle_const_iterator(
00451 m_particle_barcodes.end() ); }
00452
00454
00458 class particle_iterator :
00459 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
00460
00461 public:
00463 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
00464 : m_map_iterator( i ) {}
00465 particle_iterator() {}
00467 particle_iterator( const particle_iterator& i ) { *this = i; }
00468 virtual ~particle_iterator() {}
00470 particle_iterator& operator=( const particle_iterator& i ) {
00471 m_map_iterator = i.m_map_iterator;
00472 return *this;
00473 }
00475 operator particle_const_iterator() const
00476 { return particle_const_iterator(m_map_iterator); }
00478 GenParticle* operator*(void) const
00479 { return m_map_iterator->second; }
00481 particle_iterator& operator++(void)
00482 { ++m_map_iterator; return *this; }
00484 particle_iterator operator++(int)
00485 { particle_iterator out(*this); ++(*this); return out; }
00487 bool operator==( const particle_iterator& a ) const
00488 { return m_map_iterator == a.m_map_iterator; }
00490 bool operator!=( const particle_iterator& a ) const
00491 { return !(m_map_iterator == a.m_map_iterator); }
00492 protected:
00494 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
00495 };
00496 friend class particle_iterator;
00498 particle_iterator particles_begin()
00499 { return GenEvent::particle_iterator(
00500 m_particle_barcodes.begin() ); }
00502 particle_iterator particles_end()
00503 { return GenEvent::particle_iterator(
00504 m_particle_barcodes.end() ); }
00505
00507 protected:
00508
00509
00510
00512 bool set_barcode( GenParticle* p, int suggested_barcode =false );
00514 bool set_barcode( GenVertex* v, int suggested_barcode =false );
00516 void remove_barcode( GenParticle* p );
00518 void remove_barcode( GenVertex* v );
00519
00520 void delete_all_vertices();
00521
00522 private:
00524 bool use_momentum_unit( Units::MomentumUnit );
00525 bool use_momentum_unit( std::string& );
00527 bool use_length_unit( Units::LengthUnit );
00528 bool use_length_unit( std::string& );
00529
00530 private:
00531 int m_signal_process_id;
00532 int m_event_number;
00533 int m_mpi;
00534 double m_event_scale;
00535 double m_alphaQCD;
00536 double m_alphaQED;
00537 GenVertex* m_signal_process_vertex;
00538 GenParticle* m_beam_particle_1;
00539 GenParticle* m_beam_particle_2;
00540 WeightContainer m_weights;
00541
00542 std::vector<long> m_random_states;
00543
00544
00545 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
00546 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
00547 HeavyIon* m_heavy_ion;
00548 PdfInfo* m_pdf_info;
00549 Units::MomentumUnit m_momentum_unit;
00550 Units::LengthUnit m_position_unit;
00551
00552
00553 };
00554
00555
00557
00559
00560
00561 inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l)
00562 {
00563 evt.use_units(m, l);
00564 return evt;
00565 }
00566
00568
00570
00575 inline int GenEvent::signal_process_id() const
00576 { return m_signal_process_id; }
00577
00578 inline int GenEvent::event_number() const { return m_event_number; }
00579
00582 inline int GenEvent::mpi() const { return m_mpi; }
00583
00584 inline double GenEvent::event_scale() const { return m_event_scale; }
00585
00586 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
00587
00588 inline double GenEvent::alphaQED() const { return m_alphaQED; }
00589
00590 inline GenVertex* GenEvent::signal_process_vertex() const {
00592 return m_signal_process_vertex;
00593 }
00594
00595 inline WeightContainer& GenEvent::weights() { return m_weights; }
00596
00597 inline const WeightContainer& GenEvent::weights() const
00598 { return m_weights; }
00599
00600 inline HeavyIon const * GenEvent::heavy_ion() const
00601 { return m_heavy_ion; }
00602
00603 inline HeavyIon* GenEvent::heavy_ion()
00604 { return m_heavy_ion; }
00605
00606 inline PdfInfo const * GenEvent::pdf_info() const
00607 { return m_pdf_info; }
00608
00609 inline PdfInfo* GenEvent::pdf_info()
00610 { return m_pdf_info; }
00611
00617 inline const std::vector<long>& GenEvent::random_states() const
00618 { return m_random_states; }
00619
00620 inline void GenEvent::set_signal_process_id( int id )
00621 { m_signal_process_id = id; }
00622
00623 inline void GenEvent::set_event_number( int eventno )
00624 { m_event_number = eventno; }
00625
00627 inline void GenEvent::set_mpi( int nmpi )
00628 { m_mpi = nmpi; }
00629
00630
00631 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
00632
00633 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
00634
00635 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
00636
00637 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
00638 m_signal_process_vertex = vtx;
00639 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
00640 }
00641
00642 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
00643 { m_heavy_ion = new HeavyIon(ion); }
00644
00645 inline void GenEvent::set_pdf_info( const PdfInfo& p )
00646 { m_pdf_info = new PdfInfo(p); }
00647
00648 inline void GenEvent::set_random_states( const std::vector<long>&
00649 randomstates )
00650 { m_random_states = randomstates; }
00651
00652 inline void GenEvent::remove_barcode( GenParticle* p )
00653 { m_particle_barcodes.erase( p->barcode() ); }
00654
00655 inline void GenEvent::remove_barcode( GenVertex* v )
00656 { m_vertex_barcodes.erase( v->barcode() ); }
00657
00671 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
00672 {
00673 std::map<int,HepMC::GenParticle*>::const_iterator i
00674 = m_particle_barcodes.find(barCode);
00675 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
00676 }
00677
00691 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
00692 {
00693 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
00694 = m_vertex_barcodes.find(barCode);
00695 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
00696 }
00697
00698 inline int GenEvent::particles_size() const {
00699 return (int)m_particle_barcodes.size();
00700 }
00701 inline bool GenEvent::particles_empty() const {
00702 return (bool)m_particle_barcodes.empty();
00703 }
00704 inline int GenEvent::vertices_size() const {
00705 return (int)m_vertex_barcodes.size();
00706 }
00707 inline bool GenEvent::vertices_empty() const {
00708 return (bool)m_vertex_barcodes.empty();
00709 }
00710
00711
00712 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
00713 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
00714 }
00715
00716
00717 inline Units::MomentumUnit GenEvent::momentum_unit() const {
00718 return m_momentum_unit;
00719 }
00720 inline Units::LengthUnit GenEvent::length_unit() const {
00721 return m_position_unit;
00722 }
00723
00724 inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
00725 use_momentum_unit( new_m );
00726 use_length_unit( new_l );
00727 }
00728
00729 inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) {
00730 use_momentum_unit( new_m );
00731 use_length_unit( new_l );
00732 }
00733
00734 }
00735
00736 #endif // HEPMC_GEN_EVENT_H
00737
00738
00739
00740