hepmc - Blame information for rev 105
Subversion Repositories:
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | garren | 1 | //-------------------------------------------------------------------------- |
| 2 | #ifndef HEPMC_GEN_EVENT_H | ||
| 3 | #define HEPMC_GEN_EVENT_H | ||
| 4 | |||
| 5 | ////////////////////////////////////////////////////////////////////////// | ||
| 6 | // Matt.Dobbs@Cern.CH, September 1999, refer to: | ||
| 7 | // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for | ||
| 8 | // High Energy Physics", Computer Physics Communications (to be published). | ||
| 9 | // | ||
| 10 | // Event record for MC generators (for use at any stage of generation) | ||
| 11 | ////////////////////////////////////////////////////////////////////////// | ||
| 12 | // | ||
| 13 | // This class is intended as both a "container class" ( to store a MC | ||
| 14 | // event for interface between MC generators and detector simulation ) | ||
| 15 | // and also as a "work in progress class" ( that could be used inside | ||
| 16 | // a generator and modified as the event is built ). | ||
| 17 | // | ||
| 18 | // Iterators are provided which allow the user to easily obtain a | ||
| 19 | // list of particles or vertices in an event --- this list can be filled | ||
| 20 | // subject to some sort of selection criteria. Examples are given below | ||
| 21 | // ( see HepMC::copy_if and std::copy ) | ||
| 22 | |||
| 65 | garren | 23 | /// |
| 24 | /// \namespace HepMC | ||
| 25 | /// All classes in the HepMC packages are in the HepMC namespace | ||
| 26 | /// | ||
| 2 | garren | 27 | namespace HepMC { |
| 65 | garren | 28 | |
| 2 | garren | 29 | // To create a list from an iterator, use: (i.e. for a list of particles); |
| 30 | // #include <algorithm> | ||
| 31 | // list<GenParticle*> thelist; | ||
| 32 | // copy( evt->particles_begin(), evt->particles_end(), | ||
| 33 | // back_inserter(thelist) ); | ||
| 34 | // to create a list subject to a condition (predicate) use: | ||
| 35 | // list<GenParticle*> thelist; | ||
| 36 | // HepMC::copy_if( evt->particles_begin(), evt->particles_end(), | ||
| 37 | // back_inserter(thelist), is_photon() ); | ||
| 38 | // where is_photon() is a predicate like: | ||
| 39 | // class is_photon { | ||
| 40 | // public: | ||
| 105 | garren | 41 | // bool operator() ( GenParticle const * p ) { |
| 2 | garren | 42 | // if ( p && p->pdg_id() == 22 ) return 1; |
| 43 | // return 0; | ||
| 44 | // } | ||
| 45 | // }; | ||
| 46 | // which the user defines herself. | ||
| 65 | garren | 47 | |
| 48 | /// define the type of iterator to use | ||
| 2 | garren | 49 | template <class InputIterator, class OutputIterator, class Predicate> |
| 50 | void copy_if( InputIterator first, InputIterator last, OutputIterator out, | ||
| 51 | Predicate pred ) { | ||
| 52 | for ( ; first != last; ++first ) { if ( pred(*first) ) out = *first; } | ||
| 53 | } | ||
| 54 | } // HepMC | ||
| 55 | |||
| 56 | // Since a container of all vertices in the event is maintained, the time | ||
| 57 | // required to loop over all vertices (or particles) is very fast -- and | ||
| 58 | // the user does not gain much by first making his own list. | ||
| 59 | // (this is not true for the GenVertex:: versions of these iterators, which | ||
| 60 | // allow you to specify the vertex starting point and range) | ||
| 61 | |||
| 62 | // Data Members: | ||
| 63 | // signal_process_id() The integer ID that uniquely specifies this signal | ||
| 64 | // process, i.e. MSUB in Pythia. It is necessary to | ||
| 65 | // package this with each event rather than with the run | ||
| 66 | // because many processes may be generated within one | ||
| 67 | // run. | ||
| 68 | // event_number() Strictly speaking we cannot think of any reason that | ||
| 69 | // an event would need to know its own event number, it | ||
| 70 | // is more likely something that would be assigned by | ||
| 71 | // a database. It is included anyway (tradition?) since | ||
| 72 | // we expect it may be useful for debugging. It can | ||
| 73 | // be reset later by a database. | ||
| 103 | garren | 74 | // mpi() The number of multi parton interactions in the event. |
| 75 | // This is NOT beam pileup. Set to -1 by default. | ||
| 105 | garren | 76 | // beam_particles() A pair of pointers to the incoming beam particles. |
| 2 | garren | 77 | // signal_process_vertex() pointer to the vertex containing the signal process |
| 78 | // weights() Vector of doubles which specify th weight of the evnt, | ||
| 79 | // the first entry will be the "event weight" used for | ||
| 80 | // hit and miss etc., but a general vector is used to | ||
| 81 | // allow for reweighting etc. We envision a list of | ||
| 82 | // WeightTags to be included with a run class which | ||
| 83 | // would specify the meaning of the Weights . | ||
| 84 | // random_states() Vector of integers which specify the random number | ||
| 85 | // generator's state for this event. It is left to the | ||
| 86 | // generator to make use of this. We envision a vector of | ||
| 87 | // RndmStatesTags to be included with a run class which | ||
| 88 | // would specify the meaning of the random_states. | ||
| 89 | // | ||
| 90 | /////////////////////// | ||
| 91 | // Memory allocation // | ||
| 92 | /////////////////////// | ||
| 93 | // -When a vertex (particle) is added to a event (vertex), it is "adopted" | ||
| 94 | // and becomes the responsibility of the event (vertex) to delete that | ||
| 95 | // particle. | ||
| 96 | // -objects responsible for deleting memory: | ||
| 97 | // -events delete included vertices | ||
| 98 | // -each vertex deletes its outgoing particles which do not have decay | ||
| 99 | // vertices | ||
| 100 | // -each vertex deletes its incoming particles which do not | ||
| 101 | // have creation vertices | ||
| 102 | // | ||
| 103 | //////////////////////// | ||
| 104 | // About the Barcodes // | ||
| 105 | //////////////////////// | ||
| 106 | // - each vertex or particle has a barcode, which is just an integer which | ||
| 107 | // uniquely identifies it inside the event (i.e. there is a one to one | ||
| 108 | // mapping between particle memory addresses and particle barcodes... and | ||
| 109 | // the same applied for vertices) | ||
| 110 | // - The value of a barcode has NO MEANING and NO ORDER! | ||
| 111 | // For the user's convenience, when an event is read in via an IO_method | ||
| 112 | // from an indexed list (like the HEPEVT common block), then the index will | ||
| 113 | // become the barcode for that particle. | ||
| 114 | // - particle barcodes are always positive integers | ||
| 115 | // vertex barcodes are always negative integers | ||
| 116 | // The barcodes are chosen and set automatically when a vertex or particle | ||
| 117 | // comes under the ownership of an event (i.e. it is contained in an event). | ||
| 118 | // - You can tell when a particle or vertex is owned, because its | ||
| 119 | // parent_event() return value will return a pointer to the event which owns | ||
| 120 | // it (or null if its an orphan). | ||
| 121 | // | ||
| 122 | |||
| 123 | #include "HepMC/GenVertex.h" | ||
| 124 | #include "HepMC/GenParticle.h" | ||
| 125 | #include "HepMC/WeightContainer.h" | ||
| 14 | garren | 126 | #include "HepMC/HeavyIon.h" |
| 36 | garren | 127 | #include "HepMC/PdfInfo.h" |
| 2 | garren | 128 | #include <map> |
| 129 | #include <vector> | ||
| 130 | #include <algorithm> | ||
| 131 | #include <iostream> | ||
| 132 | |||
| 133 | namespace HepMC { | ||
| 134 | |||
| 65 | garren | 135 | //! The GenEvent class is the core of HepMC |
| 136 | |||
| 137 | /// | ||
| 138 | /// \class GenEvent | ||
| 139 | /// HepMC::GenEvent contains information about generated particles. | ||
| 140 | /// GenEvent is structured as a set of vertices which contain the particles. | ||
| 141 | /// | ||
| 2 | garren | 142 | class GenEvent { |
| 143 | friend class GenParticle; | ||
| 144 | friend class GenVertex; | ||
| 145 | public: | ||
| 92 | garren | 146 | /// default constructor creates null pointers to HeavyIon and PdfInfo |
| 2 | garren | 147 | GenEvent( int signal_process_id = 0, int event_number = 0, |
| 148 | GenVertex* signal_vertex = 0, | ||
| 149 | const WeightContainer& weights = std::vector<double>(), | ||
| 92 | garren | 150 | const std::vector<long int>& randomstates = std::vector<long int>() ); |
| 151 | /// explicit constructor that takes HeavyIon and PdfInfo | ||
| 152 | GenEvent( int signal_process_id, int event_number, | ||
| 153 | GenVertex* signal_vertex, const WeightContainer& weights, | ||
| 154 | const std::vector<long int>& randomstates, | ||
| 155 | const HeavyIon& ion, const PdfInfo& pdf ); | ||
| 65 | garren | 156 | GenEvent( const GenEvent& inevent ); //!< deep copy |
| 157 | GenEvent& operator=( const GenEvent& inevent ); //!< make a deep copy | ||
| 158 | virtual ~GenEvent(); //!<deletes all vertices/particles in this evt | ||
| 2 | garren | 159 | |
| 65 | garren | 160 | void print( std::ostream& ostr = std::cout ) const; //!< dumps to ostr |
| 2 | garren | 161 | |
| 65 | garren | 162 | /// assign a barcode to a particle |
| 2 | garren | 163 | GenParticle* barcode_to_particle( int barCode ) const; |
| 65 | garren | 164 | /// assign a barcode to a vertex |
| 2 | garren | 165 | GenVertex* barcode_to_vertex( int barCode ) const; |
| 166 | |||
| 167 | //////////////////// | ||
| 168 | // access methods // | ||
| 169 | //////////////////// | ||
| 170 | |||
| 65 | garren | 171 | int signal_process_id() const; //!< unique signal process id |
| 172 | int event_number() const; //!< event number | ||
| 103 | garren | 173 | int mpi() const; //!< number of multi parton interactions |
| 65 | garren | 174 | double event_scale() const; //!< energy scale, see hep-ph/0109068 |
| 175 | double alphaQCD() const; //!< QCD coupling, see hep-ph/0109068 | ||
| 176 | double alphaQED() const; //!< QED coupling, see hep-ph/0109068 | ||
| 177 | /// pointer to the vertex containing the signal process | ||
| 2 | garren | 178 | GenVertex* signal_process_vertex() const; |
| 105 | garren | 179 | /// test to see if we have two valid beam particles |
| 180 | bool valid_beam_particles() const; | ||
| 181 | /// pair of pointers to the two incoming beam particles | ||
| 182 | std::pair<GenParticle*,GenParticle*> beam_particles() const; | ||
| 2 | garren | 183 | |
| 65 | garren | 184 | /// direct access to the weights container is allowed. |
| 185 | /// Thus you can use myevt.weights()[2]; | ||
| 186 | /// to access element 2 of the weights. | ||
| 187 | /// or use myevt.weights().push_back( mywgt ); to add an element. | ||
| 188 | /// and you can set the weights with myevt.weights() = myvector; | ||
| 189 | WeightContainer& weights(); //!< direct access to WeightContainer | ||
| 190 | const WeightContainer& weights() const; //!< direct access to WeightContainer | ||
| 2 | garren | 191 | |
| 65 | garren | 192 | /// access the HeavyIon container if it exists |
| 92 | garren | 193 | HeavyIon* const heavy_ion() const; |
| 194 | HeavyIon* heavy_ion(); | ||
| 65 | garren | 195 | /// access the PdfInfo container if it exists |
| 92 | garren | 196 | PdfInfo* const pdf_info() const; |
| 197 | PdfInfo* pdf_info(); | ||
| 14 | garren | 198 | |
| 65 | garren | 199 | /// vector of integers containing information about the random state |
| 2 | garren | 200 | std::vector<long int> random_states() const; |
| 201 | |||
| 65 | garren | 202 | void set_signal_process_id( int id ); //!< set unique signal process id |
| 203 | void set_event_number( int eventno ); //!< set event number | ||
| 103 | garren | 204 | void set_mpi( int ); //!< set number of multi parton interactions |
| 65 | garren | 205 | void set_event_scale( double scale ); //!< set energy scale |
| 206 | void set_alphaQCD( double a ); //!< set QCD coupling | ||
| 207 | void set_alphaQED( double a ); //!< set QED coupling | ||
| 208 | |||
| 209 | /// set pointer to the vertex containing the signal process | ||
| 2 | garren | 210 | void set_signal_process_vertex( GenVertex* ); |
| 105 | garren | 211 | /// set incoming beam particles |
| 212 | bool set_beam_particles(GenParticle*, GenParticle*); | ||
| 213 | /// use a pair of GenParticle*'s to set incoming beam particles | ||
| 214 | bool set_beam_particles(std::pair<GenParticle*,GenParticle*> const &); | ||
| 65 | garren | 215 | /// provide random state information |
| 2 | garren | 216 | void set_random_states( const std::vector<long int>& randomstates ); |
| 217 | |||
| 65 | garren | 218 | /// provide a pointer to the HeavyIon container |
| 92 | garren | 219 | void set_heavy_ion( const HeavyIon& ion ); |
| 65 | garren | 220 | /// provide a pointer to the PdfInfo container |
| 92 | garren | 221 | void set_pdf_info( const PdfInfo& p ); |
| 14 | garren | 222 | |
| 65 | garren | 223 | /// how many particle barcodes exist? |
| 2 | garren | 224 | int particles_size() const; |
| 65 | garren | 225 | /// return true if there are no particle barcodes |
| 2 | garren | 226 | bool particles_empty() const; |
| 65 | garren | 227 | /// how many vertex barcodes exist? |
| 2 | garren | 228 | int vertices_size() const; |
| 65 | garren | 229 | /// return true if there are no vertex barcodes |
| 2 | garren | 230 | bool vertices_empty() const; |
| 231 | |||
| 105 | garren | 232 | ///////////////////// |
| 233 | // mutator methods // | ||
| 234 | ///////////////////// | ||
| 96 | garren | 235 | |
| 65 | garren | 236 | bool add_vertex( GenVertex* vtx ); //!< adds to evt and adopts |
| 96 | garren | 237 | bool remove_vertex( GenVertex* vtx ); //!< erases vtx from evt |
| 238 | void clear(); //!< empties the entire event | ||
| 2 | garren | 239 | |
| 240 | public: | ||
| 241 | /////////////////////////////// | ||
| 242 | // vertex_iterators // | ||
| 243 | /////////////////////////////// | ||
| 244 | // Note: the XXX_iterator is "resolvable" as XXX_const_iterator, but | ||
| 245 | // not the reverse, which is consistent with STL, | ||
| 246 | // see Musser, Derge, Saini 2ndEd. p. 69,70. | ||
| 65 | garren | 247 | |
| 248 | //! const vertex iterator | ||
| 249 | |||
| 250 | /// \class vertex_const_iterator | ||
| 251 | /// HepMC::GenEvent::vertex_const_iterator | ||
| 252 | /// is used to iterate over all vertices in the event. | ||
| 2 | garren | 253 | class vertex_const_iterator : |
| 254 | public std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t>{ | ||
| 255 | // Iterates over all vertices in this event | ||
| 256 | public: | ||
| 65 | garren | 257 | /// constructor requiring vertex information |
| 2 | garren | 258 | vertex_const_iterator( |
| 259 | const | ||
| 260 | std::map<int,GenVertex*,std::greater<int> >::const_iterator& i) | ||
| 261 | : m_map_iterator(i) {} | ||
| 262 | vertex_const_iterator() {} | ||
| 65 | garren | 263 | /// copy constructor |
| 2 | garren | 264 | vertex_const_iterator( const vertex_const_iterator& i ) |
| 265 | { *this = i; } | ||
| 266 | virtual ~vertex_const_iterator() {} | ||
| 65 | garren | 267 | /// make a copy |
| 2 | garren | 268 | vertex_const_iterator& operator=( const vertex_const_iterator& i ) |
| 269 | { m_map_iterator = i.m_map_iterator; return *this; } | ||
| 65 | garren | 270 | /// return a pointer to a GenVertex |
| 2 | garren | 271 | GenVertex* operator*(void) const { return m_map_iterator->second; } |
| 65 | garren | 272 | /// Pre-fix increment |
| 2 | garren | 273 | vertex_const_iterator& operator++(void) //Pre-fix increment |
| 274 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 275 | /// Post-fix increment |
| 2 | garren | 276 | vertex_const_iterator operator++(int) //Post-fix increment |
| 277 | { vertex_const_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 278 | /// equality |
| 2 | garren | 279 | bool operator==( const vertex_const_iterator& a ) const |
| 280 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 281 | /// inequality |
| 2 | garren | 282 | bool operator!=( const vertex_const_iterator& a ) const |
| 283 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 284 | protected: | ||
| 65 | garren | 285 | /// const iterator to a vertex map |
| 2 | garren | 286 | std::map<int,GenVertex*,std::greater<int> >::const_iterator |
| 287 | m_map_iterator; | ||
| 288 | }; | ||
| 289 | friend class vertex_const_iterator; | ||
| 65 | garren | 290 | /// begin vertex iteration |
| 2 | garren | 291 | vertex_const_iterator vertices_begin() const |
| 292 | { return GenEvent::vertex_const_iterator( | ||
| 293 | m_vertex_barcodes.begin() ); } | ||
| 65 | garren | 294 | /// end vertex iteration |
| 2 | garren | 295 | vertex_const_iterator vertices_end() const |
| 296 | { return GenEvent::vertex_const_iterator( | ||
| 297 | m_vertex_barcodes.end() ); } | ||
| 298 | |||
| 65 | garren | 299 | |
| 300 | //! non-const vertex iterator | ||
| 301 | |||
| 302 | /// \class vertex_iterator | ||
| 303 | /// HepMC::GenEvent::vertex_iterator | ||
| 304 | /// is used to iterate over all vertices in the event. | ||
| 2 | garren | 305 | class vertex_iterator : |
| 306 | public std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t>{ | ||
| 307 | // Iterates over all vertices in this event | ||
| 308 | public: | ||
| 65 | garren | 309 | /// constructor requiring vertex information |
| 2 | garren | 310 | vertex_iterator( |
| 311 | const | ||
| 312 | std::map<int,GenVertex*,std::greater<int> >::iterator& i ) | ||
| 313 | : m_map_iterator( i ) {} | ||
| 314 | vertex_iterator() {} | ||
| 65 | garren | 315 | /// copy constructor |
| 2 | garren | 316 | vertex_iterator( const vertex_iterator& i ) { *this = i; } |
| 317 | virtual ~vertex_iterator() {} | ||
| 65 | garren | 318 | /// make a copy |
| 2 | garren | 319 | vertex_iterator& operator=( const vertex_iterator& i ) { |
| 320 | m_map_iterator = i.m_map_iterator; | ||
| 321 | return *this; | ||
| 322 | } | ||
| 65 | garren | 323 | /// const vertex iterator |
| 2 | garren | 324 | operator vertex_const_iterator() const |
| 325 | { return vertex_const_iterator(m_map_iterator); } | ||
| 65 | garren | 326 | /// return a pointer to a GenVertex |
| 2 | garren | 327 | GenVertex* operator*(void) const |
| 328 | { return m_map_iterator->second; } | ||
| 65 | garren | 329 | /// Pre-fix increment |
| 2 | garren | 330 | vertex_iterator& operator++(void) //Pre-fix increment |
| 331 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 332 | /// Post-fix increment |
| 2 | garren | 333 | vertex_iterator operator++(int) //Post-fix increment |
| 334 | { vertex_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 335 | /// equality |
| 2 | garren | 336 | bool operator==( const vertex_iterator& a ) const |
| 337 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 338 | /// inequality |
| 2 | garren | 339 | bool operator!=( const vertex_iterator& a ) const |
| 340 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 341 | protected: | ||
| 65 | garren | 342 | /// iterator to the vertex map |
| 2 | garren | 343 | std::map<int,GenVertex*,std::greater<int> >::iterator |
| 344 | m_map_iterator; | ||
| 345 | }; | ||
| 346 | friend class vertex_iterator; | ||
| 65 | garren | 347 | /// begin vertex iteration |
| 2 | garren | 348 | vertex_iterator vertices_begin() |
| 349 | { return GenEvent::vertex_iterator( | ||
| 350 | m_vertex_barcodes.begin() ); } | ||
| 65 | garren | 351 | /// end vertex iteration |
| 2 | garren | 352 | vertex_iterator vertices_end() |
| 353 | { return GenEvent::vertex_iterator( | ||
| 354 | m_vertex_barcodes.end() ); } | ||
| 355 | |||
| 356 | public: | ||
| 357 | /////////////////////////////// | ||
| 358 | // particle_iterator // | ||
| 359 | /////////////////////////////// | ||
| 360 | // Example of iterating over all particles in the event: | ||
| 361 | // for ( GenEvent::particle_const_iterator p = particles_begin(); | ||
| 362 | // p != particles_end(); ++p ) { | ||
| 363 | // (*p)->print(); | ||
| 364 | // } | ||
| 365 | // | ||
| 65 | garren | 366 | |
| 367 | //! const particle iterator | ||
| 368 | |||
| 369 | /// \class particle_const_iterator | ||
| 370 | /// HepMC::GenEvent::particle_const_iterator | ||
| 371 | /// is used to iterate over all particles in the event. | ||
| 2 | garren | 372 | class particle_const_iterator : |
| 373 | public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{ | ||
| 374 | // Iterates over all vertices in this event | ||
| 375 | public: | ||
| 65 | garren | 376 | /// iterate over particles |
| 2 | garren | 377 | particle_const_iterator( |
| 378 | const std::map<int,GenParticle*>::const_iterator& i ) | ||
| 379 | : m_map_iterator(i) {} | ||
| 380 | particle_const_iterator() {} | ||
| 65 | garren | 381 | /// copy constructor |
| 2 | garren | 382 | particle_const_iterator( const particle_const_iterator& i ) |
| 383 | { *this = i; } | ||
| 384 | virtual ~particle_const_iterator() {} | ||
| 65 | garren | 385 | /// make a copy |
| 2 | garren | 386 | particle_const_iterator& operator=( |
| 387 | const particle_const_iterator& i ) | ||
| 388 | { m_map_iterator = i.m_map_iterator; return *this; } | ||
| 65 | garren | 389 | /// return a pointer to GenParticle |
| 2 | garren | 390 | GenParticle* operator*(void) const |
| 391 | { return m_map_iterator->second; } | ||
| 65 | garren | 392 | /// Pre-fix increment |
| 2 | garren | 393 | particle_const_iterator& operator++(void) //Pre-fix increment |
| 394 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 395 | /// Post-fix increment |
| 2 | garren | 396 | particle_const_iterator operator++(int) //Post-fix increment |
| 397 | { particle_const_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 398 | /// equality |
| 2 | garren | 399 | bool operator==( const particle_const_iterator& a ) const |
| 400 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 401 | /// inequality |
| 2 | garren | 402 | bool operator!=( const particle_const_iterator& a ) const |
| 403 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 404 | protected: | ||
| 65 | garren | 405 | /// const iterator to the GenParticle map |
| 2 | garren | 406 | std::map<int,GenParticle*>::const_iterator m_map_iterator; |
| 407 | }; | ||
| 408 | friend class particle_const_iterator; | ||
| 65 | garren | 409 | /// begin particle iteration |
| 2 | garren | 410 | particle_const_iterator particles_begin() const |
| 411 | { return GenEvent::particle_const_iterator( | ||
| 412 | m_particle_barcodes.begin() ); } | ||
| 65 | garren | 413 | /// end particle iteration |
| 2 | garren | 414 | particle_const_iterator particles_end() const |
| 415 | { return GenEvent::particle_const_iterator( | ||
| 416 | m_particle_barcodes.end() ); } | ||
| 417 | |||
| 65 | garren | 418 | //! non-const particle iterator |
| 419 | |||
| 420 | /// \class particle_iterator | ||
| 421 | /// HepMC::GenEvent::particle_iterator | ||
| 422 | /// is used to iterate over all particles in the event. | ||
| 423 | class particle_iterator : | ||
| 2 | garren | 424 | public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{ |
| 425 | // Iterates over all vertices in this event | ||
| 426 | public: | ||
| 65 | garren | 427 | /// iterate over particles |
| 2 | garren | 428 | particle_iterator( const std::map<int,GenParticle*>::iterator& i ) |
| 429 | : m_map_iterator( i ) {} | ||
| 430 | particle_iterator() {} | ||
| 65 | garren | 431 | /// copy constructor |
| 2 | garren | 432 | particle_iterator( const particle_iterator& i ) { *this = i; } |
| 433 | virtual ~particle_iterator() {} | ||
| 65 | garren | 434 | /// make a copy |
| 2 | garren | 435 | particle_iterator& operator=( const particle_iterator& i ) { |
| 436 | m_map_iterator = i.m_map_iterator; | ||
| 437 | return *this; | ||
| 438 | } | ||
| 65 | garren | 439 | /// const particle iterator |
| 2 | garren | 440 | operator particle_const_iterator() const |
| 441 | { return particle_const_iterator(m_map_iterator); } | ||
| 65 | garren | 442 | /// return pointer to GenParticle |
| 2 | garren | 443 | GenParticle* operator*(void) const |
| 444 | { return m_map_iterator->second; } | ||
| 65 | garren | 445 | /// Pre-fix increment |
| 446 | particle_iterator& operator++(void) | ||
| 2 | garren | 447 | { ++m_map_iterator; return *this; } |
| 65 | garren | 448 | /// Post-fix increment |
| 449 | particle_iterator operator++(int) | ||
| 2 | garren | 450 | { particle_iterator out(*this); ++(*this); return out; } |
| 65 | garren | 451 | /// equality |
| 2 | garren | 452 | bool operator==( const particle_iterator& a ) const |
| 453 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 454 | /// inequality |
| 2 | garren | 455 | bool operator!=( const particle_iterator& a ) const |
| 456 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 457 | protected: | ||
| 65 | garren | 458 | /// iterator for GenParticle map |
| 2 | garren | 459 | std::map<int,GenParticle*>::iterator m_map_iterator; |
| 460 | }; | ||
| 461 | friend class particle_iterator; | ||
| 65 | garren | 462 | /// begin particle iteration |
| 2 | garren | 463 | particle_iterator particles_begin() |
| 464 | { return GenEvent::particle_iterator( | ||
| 465 | m_particle_barcodes.begin() ); } | ||
| 65 | garren | 466 | /// end particle iteration |
| 2 | garren | 467 | particle_iterator particles_end() |
| 468 | { return GenEvent::particle_iterator( | ||
| 469 | m_particle_barcodes.end() ); } | ||
| 470 | |||
| 471 | //////////////////////////////////////////////// | ||
| 472 | protected: | ||
| 473 | // | ||
| 474 | // Following methods intended for use by GenParticle/Vertex classes: | ||
| 475 | // In general there is no reason they should be used elsewhere. | ||
| 65 | garren | 476 | /// set the barcode - intended for use by GenParticle |
| 2 | garren | 477 | bool set_barcode( GenParticle* p, int suggested_barcode =0 ); |
| 65 | garren | 478 | /// set the barcode - intended for use by GenVertex |
| 2 | garren | 479 | bool set_barcode( GenVertex* v, int suggested_barcode =0 ); |
| 65 | garren | 480 | /// intended for use by GenParticle |
| 2 | garren | 481 | void remove_barcode( GenParticle* p ); |
| 65 | garren | 482 | /// intended for use by GenVertex |
| 2 | garren | 483 | void remove_barcode( GenVertex* v ); |
| 484 | |||
| 65 | garren | 485 | static unsigned int counter(); //!<num GenEvent objects in memory |
| 486 | void delete_all_vertices(); //!<delete all vertices owned by this event | ||
| 2 | garren | 487 | |
| 488 | private: // data members | ||
| 489 | int m_signal_process_id; | ||
| 490 | int m_event_number; | ||
| 103 | garren | 491 | int m_mpi; // number of multi paricle interactions |
| 2 | garren | 492 | double m_event_scale;// energy scale, see hep-ph/0109068 |
| 493 | double m_alphaQCD; // QCD coupling, see hep-ph/0109068 | ||
| 494 | double m_alphaQED; // QED coupling, see hep-ph/0109068 | ||
| 495 | GenVertex* m_signal_process_vertex; | ||
| 105 | garren | 496 | GenParticle* m_beam_particle_1; |
| 497 | GenParticle* m_beam_particle_2; | ||
| 2 | garren | 498 | WeightContainer m_weights; // weights for this event first weight |
| 499 | // is used by default for hit and miss | ||
| 500 | std::vector<long int> m_random_states; // container of rndm num | ||
| 501 | // generator states | ||
| 502 | |||
| 503 | std::map< int,GenVertex*,std::greater<int> > m_vertex_barcodes; | ||
| 504 | std::map< int,GenParticle*,std::less<int> > m_particle_barcodes; | ||
| 14 | garren | 505 | HeavyIon* m_heavy_ion; // undefined by default |
| 36 | garren | 506 | PdfInfo* m_pdf_info; // undefined by default |
| 2 | garren | 507 | |
| 508 | static unsigned int s_counter; | ||
| 509 | }; | ||
| 510 | |||
| 511 | /////////////////////////// | ||
| 512 | // INLINE Access Methods // | ||
| 513 | /////////////////////////// | ||
| 514 | |||
| 65 | garren | 515 | /// The integer ID that uniquely specifies this signal |
| 516 | /// process, i.e. MSUB in Pythia. It is necessary to | ||
| 517 | /// package this with each event rather than with the run | ||
| 518 | /// because many processes may be generated within one run. | ||
| 2 | garren | 519 | inline int GenEvent::signal_process_id() const |
| 520 | { return m_signal_process_id; } | ||
| 521 | |||
| 522 | inline int GenEvent::event_number() const { return m_event_number; } | ||
| 523 | |||
| 103 | garren | 524 | /// Returns the number of multi parton interactions in the event. |
| 525 | /// This number is -1 if it is not set. | ||
| 526 | inline int GenEvent::mpi() const { return m_mpi; } | ||
| 527 | |||
| 2 | garren | 528 | inline double GenEvent::event_scale() const { return m_event_scale; } |
| 529 | |||
| 530 | inline double GenEvent::alphaQCD() const { return m_alphaQCD; } | ||
| 531 | |||
| 532 | inline double GenEvent::alphaQED() const { return m_alphaQED; } | ||
| 533 | |||
| 534 | inline GenVertex* GenEvent::signal_process_vertex() const { | ||
| 65 | garren | 535 | /// returns a (mutable) pointer to the signal process vertex |
| 2 | garren | 536 | return m_signal_process_vertex; |
| 537 | } | ||
| 538 | |||
| 539 | inline WeightContainer& GenEvent::weights() { return m_weights; } | ||
| 540 | |||
| 541 | inline const WeightContainer& GenEvent::weights() const | ||
| 542 | { return m_weights; } | ||
| 543 | |||
| 92 | garren | 544 | inline HeavyIon* const GenEvent::heavy_ion() const |
| 14 | garren | 545 | { return m_heavy_ion; } |
| 546 | |||
| 92 | garren | 547 | inline HeavyIon* GenEvent::heavy_ion() |
| 548 | { return m_heavy_ion; } | ||
| 549 | |||
| 550 | inline PdfInfo* const GenEvent::pdf_info() const | ||
| 36 | garren | 551 | { return m_pdf_info; } |
| 552 | |||
| 92 | garren | 553 | inline PdfInfo* GenEvent::pdf_info() |
| 554 | { return m_pdf_info; } | ||
| 555 | |||
| 65 | garren | 556 | /// Vector of integers which specify the random number |
| 557 | /// generator's state for this event. It is left to the | ||
| 558 | /// generator to make use of this. We envision a vector of | ||
| 559 | /// RndmStatesTags to be included with a run class which | ||
| 560 | /// would specify the meaning of the random_states. | ||
| 2 | garren | 561 | inline std::vector<long int> GenEvent::random_states() const |
| 562 | { return m_random_states; } | ||
| 563 | |||
| 564 | inline void GenEvent::set_signal_process_id( int id ) | ||
| 565 | { m_signal_process_id = id; } | ||
| 566 | |||
| 567 | inline void GenEvent::set_event_number( int eventno ) | ||
| 568 | { m_event_number = eventno; } | ||
| 569 | |||
| 103 | garren | 570 | /// Use this to set the number of multi parton interactions in each event. |
| 571 | inline void GenEvent::set_mpi( int nmpi ) | ||
| 572 | { m_mpi = nmpi; } | ||
| 2 | garren | 573 | |
| 103 | garren | 574 | |
| 2 | garren | 575 | inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; } |
| 576 | |||
| 577 | inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; } | ||
| 578 | |||
| 579 | inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; } | ||
| 580 | |||
| 581 | inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) { | ||
| 582 | m_signal_process_vertex = vtx; | ||
| 583 | if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex ); | ||
| 584 | } | ||
| 585 | |||
| 92 | garren | 586 | inline void GenEvent::set_heavy_ion( const HeavyIon& ion ) |
| 587 | { m_heavy_ion = new HeavyIon(ion); } | ||
| 14 | garren | 588 | |
| 92 | garren | 589 | inline void GenEvent::set_pdf_info( const PdfInfo& p ) |
| 590 | { m_pdf_info = new PdfInfo(p); } | ||
| 36 | garren | 591 | |
| 2 | garren | 592 | inline void GenEvent::set_random_states( const std::vector<long int>& |
| 593 | randomstates ) | ||
| 594 | { m_random_states = randomstates; } | ||
| 595 | |||
| 596 | inline void GenEvent::remove_barcode( GenParticle* p ) | ||
| 597 | { m_particle_barcodes.erase( p->barcode() ); } | ||
| 598 | |||
| 599 | inline void GenEvent::remove_barcode( GenVertex* v ) | ||
| 600 | { m_vertex_barcodes.erase( v->barcode() ); } | ||
| 601 | |||
| 65 | garren | 602 | /// Each vertex or particle has a barcode, which is just an integer which |
| 603 | /// uniquely identifies it inside the event (i.e. there is a one to one | ||
| 604 | /// mapping between particle memory addresses and particle barcodes... and | ||
| 605 | /// the same applied for vertices). | ||
| 606 | /// | ||
| 607 | /// The value of a barcode has NO MEANING and NO ORDER! | ||
| 608 | /// For the user's convenience, when an event is read in via an IO_method | ||
| 609 | /// from an indexed list (like the HEPEVT common block), then the index will | ||
| 610 | /// become the barcode for that particle. | ||
| 611 | /// | ||
| 612 | /// Particle barcodes are always positive integers. | ||
| 613 | /// The barcodes are chosen and set automatically when a vertex or particle | ||
| 614 | /// comes under the ownership of an event (i.e. it is contained in an event). | ||
| 2 | garren | 615 | inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const |
| 616 | { | ||
| 617 | std::map<int,GenParticle*>::const_iterator i | ||
| 618 | = m_particle_barcodes.find(barCode); | ||
| 619 | return ( i != m_particle_barcodes.end() ) ? (*i).second : 0; | ||
| 620 | } | ||
| 621 | |||
| 65 | garren | 622 | /// Each vertex or particle has a barcode, which is just an integer which |
| 623 | /// uniquely identifies it inside the event (i.e. there is a one to one | ||
| 624 | /// mapping between particle memory addresses and particle barcodes... and | ||
| 625 | /// the same applied for vertices). | ||
| 626 | /// | ||
| 627 | /// The value of a barcode has NO MEANING and NO ORDER! | ||
| 628 | /// For the user's convenience, when an event is read in via an IO_method | ||
| 629 | /// from an indexed list (like the HEPEVT common block), then the index will | ||
| 630 | /// become the barcode for that particle. | ||
| 631 | /// | ||
| 632 | /// Vertex barcodes are always negative integers. | ||
| 633 | /// The barcodes are chosen and set automatically when a vertex or particle | ||
| 634 | /// comes under the ownership of an event (i.e. it is contained in an event). | ||
| 2 | garren | 635 | inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const |
| 636 | { | ||
| 637 | std::map<int,GenVertex*,std::greater<int> >::const_iterator i | ||
| 638 | = m_vertex_barcodes.find(barCode); | ||
| 639 | return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0; | ||
| 640 | } | ||
| 641 | |||
| 642 | inline int GenEvent::particles_size() const { | ||
| 643 | return (int)m_particle_barcodes.size(); | ||
| 644 | } | ||
| 645 | inline bool GenEvent::particles_empty() const { | ||
| 646 | return (bool)m_particle_barcodes.empty(); | ||
| 647 | } | ||
| 648 | inline int GenEvent::vertices_size() const { | ||
| 649 | return (int)m_vertex_barcodes.size(); | ||
| 650 | } | ||
| 651 | inline bool GenEvent::vertices_empty() const { | ||
| 652 | return (bool)m_vertex_barcodes.empty(); | ||
| 653 | } | ||
| 105 | garren | 654 | |
| 655 | // beam particles | ||
| 656 | inline std::pair<GenParticle *,GenParticle *> GenEvent::beam_particles() const { | ||
| 657 | return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2); | ||
| 658 | } | ||
| 2 | garren | 659 | |
| 660 | } // HepMC | ||
| 661 | |||
| 662 | #endif // HEPMC_GEN_EVENT_H | ||
| 663 | |||
| 664 | //-------------------------------------------------------------------------- | ||
| 665 | |||
| 666 |
