/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 //-------------------------------------------------------------------------- 00002 #ifndef HEPMC_GEN_EVENT_H 00003 #define HEPMC_GEN_EVENT_H 00004 00006 // Matt.Dobbs@Cern.CH, September 1999, refer to: 00007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for 00008 // High Energy Physics", Computer Physics Communications (to be published). 00009 // 00010 // Event record for MC generators (for use at any stage of generation) 00012 // 00013 // This class is intended as both a "container class" ( to store a MC 00014 // event for interface between MC generators and detector simulation ) 00015 // and also as a "work in progress class" ( that could be used inside 00016 // a generator and modified as the event is built ). 00017 // 00018 // Iterators are provided which allow the user to easily obtain a 00019 // list of particles or vertices in an event --- this list can be filled 00020 // subject to some sort of selection criteria. Examples are given below 00021 // ( see HepMC::copy_if and std::copy ) 00022 00027 namespace HepMC { 00028 00029 // To create a list from an iterator, use: (i.e. for a list of particles); 00030 // #include <algorithm> 00031 // list<GenParticle*> thelist; 00032 // copy( evt->particles_begin(), evt->particles_end(), 00033 // back_inserter(thelist) ); 00034 // to create a list subject to a condition (predicate) use: 00035 // list<GenParticle*> thelist; 00036 // HepMC::copy_if( evt->particles_begin(), evt->particles_end(), 00037 // back_inserter(thelist), is_photon() ); 00038 // where is_photon() is a predicate like: 00039 // class is_photon { 00040 // public: 00041 // bool operator() ( GenParticle const * p ) { 00042 // if ( p && p->pdg_id() == 22 ) return 1; 00043 // return 0; 00044 // } 00045 // }; 00046 // which the user defines herself. 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 } // HepMC 00055 00056 // Since a container of all vertices in the event is maintained, the time 00057 // required to loop over all vertices (or particles) is very fast -- and 00058 // the user does not gain much by first making his own list. 00059 // (this is not true for the GenVertex:: versions of these iterators, which 00060 // allow you to specify the vertex starting point and range) 00061 00062 // Data Members: 00063 // signal_process_id() The integer ID that uniquely specifies this signal 00064 // process, i.e. MSUB in Pythia. It is necessary to 00065 // package this with each event rather than with the run 00066 // because many processes may be generated within one 00067 // run. 00068 // event_number() Strictly speaking we cannot think of any reason that 00069 // an event would need to know its own event number, it 00070 // is more likely something that would be assigned by 00071 // a database. It is included anyway (tradition?) since 00072 // we expect it may be useful for debugging. It can 00073 // be reset later by a database. 00074 // mpi() The number of multi parton interactions in the event. 00075 // This is NOT beam pileup. Set to -1 by default. 00076 // beam_particles() A pair of pointers to the incoming beam particles. 00077 // signal_process_vertex() pointer to the vertex containing the signal process 00078 // weights() Vector of doubles which specify th weight of the evnt, 00079 // the first entry will be the "event weight" used for 00080 // hit and miss etc., but a general vector is used to 00081 // allow for reweighting etc. We envision a list of 00082 // WeightTags to be included with a run class which 00083 // would specify the meaning of the Weights . 00084 // random_states() Vector of integers which specify the random number 00085 // generator's state for this event. It is left to the 00086 // generator to make use of this. We envision a vector of 00087 // RndmStatesTags to be included with a run class which 00088 // would specify the meaning of the random_states. 00089 // 00091 // Memory allocation // 00093 // -When a vertex (particle) is added to a event (vertex), it is "adopted" 00094 // and becomes the responsibility of the event (vertex) to delete that 00095 // particle. 00096 // -objects responsible for deleting memory: 00097 // -events delete included vertices 00098 // -each vertex deletes its outgoing particles which do not have decay 00099 // vertices 00100 // -each vertex deletes its incoming particles which do not 00101 // have creation vertices 00102 // 00104 // About the Barcodes // 00106 // - each vertex or particle has a barcode, which is just an integer which 00107 // uniquely identifies it inside the event (i.e. there is a one to one 00108 // mapping between particle memory addresses and particle barcodes... and 00109 // the same applied for vertices) 00110 // - The value of a barcode has NO MEANING and NO ORDER! 00111 // For the user's convenience, when an event is read in via an IO_method 00112 // from an indexed list (like the HEPEVT common block), then the index will 00113 // become the barcode for that particle. 00114 // - particle barcodes are always positive integers 00115 // vertex barcodes are always negative integers 00116 // The barcodes are chosen and set automatically when a vertex or particle 00117 // comes under the ownership of an event (i.e. it is contained in an event). 00118 // - You can tell when a particle or vertex is owned, because its 00119 // parent_event() return value will return a pointer to the event which owns 00120 // it (or null if its an orphan). 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 // access methods // 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 // mutator methods // 00238 00239 bool add_vertex( GenVertex* vtx ); 00240 bool remove_vertex( GenVertex* vtx ); 00241 void clear(); 00242 00243 public: 00245 // vertex_iterators // 00247 // Note: the XXX_iterator is "resolvable" as XXX_const_iterator, but 00248 // not the reverse, which is consistent with STL, 00249 // see Musser, Derge, Saini 2ndEd. p. 69,70. 00250 00252 00256 class vertex_const_iterator : 00257 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{ 00258 // Iterates over all vertices in this event 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) //Pre-fix increment 00277 { ++m_map_iterator; return *this; } 00279 vertex_const_iterator operator++(int) //Post-fix increment 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 // Iterates over all vertices in this event 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) //Pre-fix increment 00334 { ++m_map_iterator; return *this; } 00336 vertex_iterator operator++(int) //Post-fix increment 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 // particle_iterator // 00363 // Example of iterating over all particles in the event: 00364 // for ( GenEvent::particle_const_iterator p = particles_begin(); 00365 // p != particles_end(); ++p ) { 00366 // (*p)->print(); 00367 // } 00368 // 00369 00371 00375 class particle_const_iterator : 00376 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{ 00377 // Iterates over all vertices in this event 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) //Pre-fix increment 00397 { ++m_map_iterator; return *this; } 00399 particle_const_iterator operator++(int) //Post-fix increment 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 // Iterates over all vertices in this event 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 // Following methods intended for use by GenParticle/Vertex classes: 00478 // In general there is no reason they should be used elsewhere. 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 //static unsigned int counter(); //!<num GenEvent objects in memory 00489 void delete_all_vertices(); 00490 00491 private: // data members 00492 int m_signal_process_id; 00493 int m_event_number; 00494 int m_mpi; // number of multi paricle interactions 00495 double m_event_scale;// energy scale, see hep-ph/0109068 00496 double m_alphaQCD; // QCD coupling, see hep-ph/0109068 00497 double m_alphaQED; // QED coupling, see hep-ph/0109068 00498 GenVertex* m_signal_process_vertex; 00499 GenParticle* m_beam_particle_1; 00500 GenParticle* m_beam_particle_2; 00501 WeightContainer m_weights; // weights for this event first weight 00502 // is used by default for hit and miss 00503 std::vector<long> m_random_states; // container of rndm num 00504 // generator states 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; // undefined by default 00509 PdfInfo* m_pdf_info; // undefined by default 00510 00511 //static unsigned int s_counter; 00512 }; 00513 00515 // INLINE Access Methods // 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 // beam particles 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 } // HepMC 00664 00665 #endif // HEPMC_GEN_EVENT_H 00666 00667 //-------------------------------------------------------------------------- 00668 00669