Rev 36 | Rev 92 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| 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: |
||
| 41 | // bool operator() ( const GenParticle* p ) { |
||
| 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. |
||
| 74 | // signal_process_vertex() pointer to the vertex containing the signal process |
||
| 75 | // weights() Vector of doubles which specify th weight of the evnt, |
||
| 76 | // the first entry will be the "event weight" used for |
||
| 77 | // hit and miss etc., but a general vector is used to |
||
| 78 | // allow for reweighting etc. We envision a list of |
||
| 79 | // WeightTags to be included with a run class which |
||
| 80 | // would specify the meaning of the Weights . |
||
| 81 | // random_states() Vector of integers which specify the random number |
||
| 82 | // generator's state for this event. It is left to the |
||
| 83 | // generator to make use of this. We envision a vector of |
||
| 84 | // RndmStatesTags to be included with a run class which |
||
| 85 | // would specify the meaning of the random_states. |
||
| 86 | // |
||
| 87 | /////////////////////// |
||
| 88 | // Memory allocation // |
||
| 89 | /////////////////////// |
||
| 90 | // -When a vertex (particle) is added to a event (vertex), it is "adopted" |
||
| 91 | // and becomes the responsibility of the event (vertex) to delete that |
||
| 92 | // particle. |
||
| 93 | // -objects responsible for deleting memory: |
||
| 94 | // -events delete included vertices |
||
| 95 | // -each vertex deletes its outgoing particles which do not have decay |
||
| 96 | // vertices |
||
| 97 | // -each vertex deletes its incoming particles which do not |
||
| 98 | // have creation vertices |
||
| 99 | // |
||
| 100 | //////////////////////// |
||
| 101 | // About the Barcodes // |
||
| 102 | //////////////////////// |
||
| 103 | // - each vertex or particle has a barcode, which is just an integer which |
||
| 104 | // uniquely identifies it inside the event (i.e. there is a one to one |
||
| 105 | // mapping between particle memory addresses and particle barcodes... and |
||
| 106 | // the same applied for vertices) |
||
| 107 | // - The value of a barcode has NO MEANING and NO ORDER! |
||
| 108 | // For the user's convenience, when an event is read in via an IO_method |
||
| 109 | // from an indexed list (like the HEPEVT common block), then the index will |
||
| 110 | // become the barcode for that particle. |
||
| 111 | // - particle barcodes are always positive integers |
||
| 112 | // vertex barcodes are always negative integers |
||
| 113 | // The barcodes are chosen and set automatically when a vertex or particle |
||
| 114 | // comes under the ownership of an event (i.e. it is contained in an event). |
||
| 115 | // - You can tell when a particle or vertex is owned, because its |
||
| 116 | // parent_event() return value will return a pointer to the event which owns |
||
| 117 | // it (or null if its an orphan). |
||
| 118 | // |
||
| 119 | |||
| 120 | #include "HepMC/GenVertex.h" |
||
| 121 | #include "HepMC/GenParticle.h" |
||
| 122 | #include "HepMC/WeightContainer.h" |
||
| 14 | garren | 123 | #include "HepMC/HeavyIon.h" |
| 36 | garren | 124 | #include "HepMC/PdfInfo.h" |
| 2 | garren | 125 | #include <map> |
| 126 | #include <vector> |
||
| 127 | #include <algorithm> |
||
| 128 | #include <iostream> |
||
| 129 | |||
| 130 | namespace HepMC { |
||
| 131 | |||
| 65 | garren | 132 | //! The GenEvent class is the core of HepMC |
| 133 | |||
| 134 | /// |
||
| 135 | /// \class GenEvent |
||
| 136 | /// HepMC::GenEvent contains information about generated particles. |
||
| 137 | /// GenEvent is structured as a set of vertices which contain the particles. |
||
| 138 | /// |
||
| 2 | garren | 139 | class GenEvent { |
| 140 | friend class GenParticle; |
||
| 141 | friend class GenVertex; |
||
| 142 | public: |
||
| 65 | garren | 143 | /// default constructor |
| 2 | garren | 144 | GenEvent( int signal_process_id = 0, int event_number = 0, |
| 145 | GenVertex* signal_vertex = 0, |
||
| 146 | const WeightContainer& weights = std::vector<double>(), |
||
| 147 | const std::vector<long int>& randomstates |
||
| 36 | garren | 148 | = std::vector<long int>(), HeavyIon* ion = 0, PdfInfo* pdf = 0 ); |
| 65 | garren | 149 | GenEvent( const GenEvent& inevent ); //!< deep copy |
| 150 | GenEvent& operator=( const GenEvent& inevent ); //!< make a deep copy |
||
| 151 | virtual ~GenEvent(); //!<deletes all vertices/particles in this evt |
||
| 2 | garren | 152 | |
| 65 | garren | 153 | void print( std::ostream& ostr = std::cout ) const; //!< dumps to ostr |
| 2 | garren | 154 | |
| 65 | garren | 155 | /// assign a barcode to a particle |
| 2 | garren | 156 | GenParticle* barcode_to_particle( int barCode ) const; |
| 65 | garren | 157 | /// assign a barcode to a vertex |
| 2 | garren | 158 | GenVertex* barcode_to_vertex( int barCode ) const; |
| 159 | |||
| 160 | //////////////////// |
||
| 161 | // access methods // |
||
| 162 | //////////////////// |
||
| 163 | |||
| 65 | garren | 164 | int signal_process_id() const; //!< unique signal process id |
| 165 | int event_number() const; //!< event number |
||
| 166 | double event_scale() const; //!< energy scale, see hep-ph/0109068 |
||
| 167 | double alphaQCD() const; //!< QCD coupling, see hep-ph/0109068 |
||
| 168 | double alphaQED() const; //!< QED coupling, see hep-ph/0109068 |
||
| 169 | /// pointer to the vertex containing the signal process |
||
| 2 | garren | 170 | GenVertex* signal_process_vertex() const; |
| 171 | |||
| 65 | garren | 172 | /// direct access to the weights container is allowed. |
| 173 | /// Thus you can use myevt.weights()[2]; |
||
| 174 | /// to access element 2 of the weights. |
||
| 175 | /// or use myevt.weights().push_back( mywgt ); to add an element. |
||
| 176 | /// and you can set the weights with myevt.weights() = myvector; |
||
| 177 | WeightContainer& weights(); //!< direct access to WeightContainer |
||
| 178 | const WeightContainer& weights() const; //!< direct access to WeightContainer |
||
| 2 | garren | 179 | |
| 65 | garren | 180 | /// access the HeavyIon container if it exists |
| 14 | garren | 181 | HeavyIon* heavy_ion() const; |
| 65 | garren | 182 | /// access the PdfInfo container if it exists |
| 36 | garren | 183 | PdfInfo* pdf_info() const; |
| 14 | garren | 184 | |
| 65 | garren | 185 | /// vector of integers containing information about the random state |
| 2 | garren | 186 | std::vector<long int> random_states() const; |
| 187 | |||
| 65 | garren | 188 | void set_signal_process_id( int id ); //!< set unique signal process id |
| 189 | void set_event_number( int eventno ); //!< set event number |
||
| 190 | void set_event_scale( double scale ); //!< set energy scale |
||
| 191 | void set_alphaQCD( double a ); //!< set QCD coupling |
||
| 192 | void set_alphaQED( double a ); //!< set QED coupling |
||
| 193 | |||
| 194 | /// set pointer to the vertex containing the signal process |
||
| 2 | garren | 195 | void set_signal_process_vertex( GenVertex* ); |
| 65 | garren | 196 | /// provide random state information |
| 2 | garren | 197 | void set_random_states( const std::vector<long int>& randomstates ); |
| 198 | |||
| 65 | garren | 199 | /// provide a pointer to the HeavyIon container |
| 14 | garren | 200 | void set_heavy_ion( HeavyIon* ion ); |
| 65 | garren | 201 | /// provide a pointer to the PdfInfo container |
| 36 | garren | 202 | void set_pdf_info( PdfInfo* p ); |
| 14 | garren | 203 | |
| 65 | garren | 204 | /// how many particle barcodes exist? |
| 2 | garren | 205 | int particles_size() const; |
| 65 | garren | 206 | /// return true if there are no particle barcodes |
| 2 | garren | 207 | bool particles_empty() const; |
| 65 | garren | 208 | /// how many vertex barcodes exist? |
| 2 | garren | 209 | int vertices_size() const; |
| 65 | garren | 210 | /// return true if there are no vertex barcodes |
| 2 | garren | 211 | bool vertices_empty() const; |
| 212 | |||
| 65 | garren | 213 | bool add_vertex( GenVertex* vtx ); //!< adds to evt and adopts |
| 214 | bool remove_vertex( GenVertex* vtx ); //!< erases vtx from evt, |
||
| 2 | garren | 215 | |
| 216 | public: |
||
| 217 | /////////////////////////////// |
||
| 218 | // vertex_iterators // |
||
| 219 | /////////////////////////////// |
||
| 220 | // Note: the XXX_iterator is "resolvable" as XXX_const_iterator, but |
||
| 221 | // not the reverse, which is consistent with STL, |
||
| 222 | // see Musser, Derge, Saini 2ndEd. p. 69,70. |
||
| 65 | garren | 223 | |
| 224 | //! const vertex iterator |
||
| 225 | |||
| 226 | /// \class vertex_const_iterator |
||
| 227 | /// HepMC::GenEvent::vertex_const_iterator |
||
| 228 | /// is used to iterate over all vertices in the event. |
||
| 2 | garren | 229 | class vertex_const_iterator : |
| 230 | public std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t>{ |
||
| 231 | // Iterates over all vertices in this event |
||
| 232 | public: |
||
| 65 | garren | 233 | /// constructor requiring vertex information |
| 2 | garren | 234 | vertex_const_iterator( |
| 235 | const |
||
| 236 | std::map<int,GenVertex*,std::greater<int> >::const_iterator& i) |
||
| 237 | : m_map_iterator(i) {} |
||
| 238 | vertex_const_iterator() {} |
||
| 65 | garren | 239 | /// copy constructor |
| 2 | garren | 240 | vertex_const_iterator( const vertex_const_iterator& i ) |
| 241 | { *this = i; } |
||
| 242 | virtual ~vertex_const_iterator() {} |
||
| 65 | garren | 243 | /// make a copy |
| 2 | garren | 244 | vertex_const_iterator& operator=( const vertex_const_iterator& i ) |
| 245 | { m_map_iterator = i.m_map_iterator; return *this; } |
||
| 65 | garren | 246 | /// return a pointer to a GenVertex |
| 2 | garren | 247 | GenVertex* operator*(void) const { return m_map_iterator->second; } |
| 65 | garren | 248 | /// Pre-fix increment |
| 2 | garren | 249 | vertex_const_iterator& operator++(void) //Pre-fix increment |
| 250 | { ++m_map_iterator; return *this; } |
||
| 65 | garren | 251 | /// Post-fix increment |
| 2 | garren | 252 | vertex_const_iterator operator++(int) //Post-fix increment |
| 253 | { vertex_const_iterator out(*this); ++(*this); return out; } |
||
| 65 | garren | 254 | /// equality |
| 2 | garren | 255 | bool operator==( const vertex_const_iterator& a ) const |
| 256 | { return m_map_iterator == a.m_map_iterator; } |
||
| 65 | garren | 257 | /// inequality |
| 2 | garren | 258 | bool operator!=( const vertex_const_iterator& a ) const |
| 259 | { return !(m_map_iterator == a.m_map_iterator); } |
||
| 260 | protected: |
||
| 65 | garren | 261 | /// const iterator to a vertex map |
| 2 | garren | 262 | std::map<int,GenVertex*,std::greater<int> >::const_iterator |
| 263 | m_map_iterator; |
||
| 264 | }; |
||
| 265 | friend class vertex_const_iterator; |
||
| 65 | garren | 266 | /// begin vertex iteration |
| 2 | garren | 267 | vertex_const_iterator vertices_begin() const |
| 268 | { return GenEvent::vertex_const_iterator( |
||
| 269 | m_vertex_barcodes.begin() ); } |
||
| 65 | garren | 270 | /// end vertex iteration |
| 2 | garren | 271 | vertex_const_iterator vertices_end() const |
| 272 | { return GenEvent::vertex_const_iterator( |
||
| 273 | m_vertex_barcodes.end() ); } |
||
| 274 | |||
| 65 | garren | 275 | |
| 276 | //! non-const vertex iterator |
||
| 277 | |||
| 278 | /// \class vertex_iterator |
||
| 279 | /// HepMC::GenEvent::vertex_iterator |
||
| 280 | /// is used to iterate over all vertices in the event. |
||
| 2 | garren | 281 | class vertex_iterator : |
| 282 | public std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t>{ |
||
| 283 | // Iterates over all vertices in this event |
||
| 284 | public: |
||
| 65 | garren | 285 | /// constructor requiring vertex information |
| 2 | garren | 286 | vertex_iterator( |
| 287 | const |
||
| 288 | std::map<int,GenVertex*,std::greater<int> >::iterator& i ) |
||
| 289 | : m_map_iterator( i ) {} |
||
| 290 | vertex_iterator() {} |
||
| 65 | garren | 291 | /// copy constructor |
| 2 | garren | 292 | vertex_iterator( const vertex_iterator& i ) { *this = i; } |
| 293 | virtual ~vertex_iterator() {} |
||
| 65 | garren | 294 | /// make a copy |
| 2 | garren | 295 | vertex_iterator& operator=( const vertex_iterator& i ) { |
| 296 | m_map_iterator = i.m_map_iterator; |
||
| 297 | return *this; |
||
| 298 | } |
||
| 65 | garren | 299 | /// const vertex iterator |
| 2 | garren | 300 | operator vertex_const_iterator() const |
| 301 | { return vertex_const_iterator(m_map_iterator); } |
||
| 65 | garren | 302 | /// return a pointer to a GenVertex |
| 2 | garren | 303 | GenVertex* operator*(void) const |
| 304 | { return m_map_iterator->second; } |
||
| 65 | garren | 305 | /// Pre-fix increment |
| 2 | garren | 306 | vertex_iterator& operator++(void) //Pre-fix increment |
| 307 | { ++m_map_iterator; return *this; } |
||
| 65 | garren | 308 | /// Post-fix increment |
| 2 | garren | 309 | vertex_iterator operator++(int) //Post-fix increment |
| 310 | { vertex_iterator out(*this); ++(*this); return out; } |
||
| 65 | garren | 311 | /// equality |
| 2 | garren | 312 | bool operator==( const vertex_iterator& a ) const |
| 313 | { return m_map_iterator == a.m_map_iterator; } |
||
| 65 | garren | 314 | /// inequality |
| 2 | garren | 315 | bool operator!=( const vertex_iterator& a ) const |
| 316 | { return !(m_map_iterator == a.m_map_iterator); } |
||
| 317 | protected: |
||
| 65 | garren | 318 | /// iterator to the vertex map |
| 2 | garren | 319 | std::map<int,GenVertex*,std::greater<int> >::iterator |
| 320 | m_map_iterator; |
||
| 321 | }; |
||
| 322 | friend class vertex_iterator; |
||
| 65 | garren | 323 | /// begin vertex iteration |
| 2 | garren | 324 | vertex_iterator vertices_begin() |
| 325 | { return GenEvent::vertex_iterator( |
||
| 326 | m_vertex_barcodes.begin() ); } |
||
| 65 | garren | 327 | /// end vertex iteration |
| 2 | garren | 328 | vertex_iterator vertices_end() |
| 329 | { return GenEvent::vertex_iterator( |
||
| 330 | m_vertex_barcodes.end() ); } |
||
| 331 | |||
| 332 | public: |
||
| 333 | /////////////////////////////// |
||
| 334 | // particle_iterator // |
||
| 335 | /////////////////////////////// |
||
| 336 | // Example of iterating over all particles in the event: |
||
| 337 | // for ( GenEvent::particle_const_iterator p = particles_begin(); |
||
| 338 | // p != particles_end(); ++p ) { |
||
| 339 | // (*p)->print(); |
||
| 340 | // } |
||
| 341 | // |
||
| 65 | garren | 342 | |
| 343 | //! const particle iterator |
||
| 344 | |||
| 345 | /// \class particle_const_iterator |
||
| 346 | /// HepMC::GenEvent::particle_const_iterator |
||
| 347 | /// is used to iterate over all particles in the event. |
||
| 2 | garren | 348 | class particle_const_iterator : |
| 349 | public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{ |
||
| 350 | // Iterates over all vertices in this event |
||
| 351 | public: |
||
| 65 | garren | 352 | /// iterate over particles |
| 2 | garren | 353 | particle_const_iterator( |
| 354 | const std::map<int,GenParticle*>::const_iterator& i ) |
||
| 355 | : m_map_iterator(i) {} |
||
| 356 | particle_const_iterator() {} |
||
| 65 | garren | 357 | /// copy constructor |
| 2 | garren | 358 | particle_const_iterator( const particle_const_iterator& i ) |
| 359 | { *this = i; } |
||
| 360 | virtual ~particle_const_iterator() {} |
||
| 65 | garren | 361 | /// make a copy |
| 2 | garren | 362 | particle_const_iterator& operator=( |
| 363 | const particle_const_iterator& i ) |
||
| 364 | { m_map_iterator = i.m_map_iterator; return *this; } |
||
| 65 | garren | 365 | /// return a pointer to GenParticle |
| 2 | garren | 366 | GenParticle* operator*(void) const |
| 367 | { return m_map_iterator->second; } |
||
| 65 | garren | 368 | /// Pre-fix increment |
| 2 | garren | 369 | particle_const_iterator& operator++(void) //Pre-fix increment |
| 370 | { ++m_map_iterator; return *this; } |
||
| 65 | garren | 371 | /// Post-fix increment |
| 2 | garren | 372 | particle_const_iterator operator++(int) //Post-fix increment |
| 373 | { particle_const_iterator out(*this); ++(*this); return out; } |
||
| 65 | garren | 374 | /// equality |
| 2 | garren | 375 | bool operator==( const particle_const_iterator& a ) const |
| 376 | { return m_map_iterator == a.m_map_iterator; } |
||
| 65 | garren | 377 | /// inequality |
| 2 | garren | 378 | bool operator!=( const particle_const_iterator& a ) const |
| 379 | { return !(m_map_iterator == a.m_map_iterator); } |
||
| 380 | protected: |
||
| 65 | garren | 381 | /// const iterator to the GenParticle map |
| 2 | garren | 382 | std::map<int,GenParticle*>::const_iterator m_map_iterator; |
| 383 | }; |
||
| 384 | friend class particle_const_iterator; |
||
| 65 | garren | 385 | /// begin particle iteration |
| 2 | garren | 386 | particle_const_iterator particles_begin() const |
| 387 | { return GenEvent::particle_const_iterator( |
||
| 388 | m_particle_barcodes.begin() ); } |
||
| 65 | garren | 389 | /// end particle iteration |
| 2 | garren | 390 | particle_const_iterator particles_end() const |
| 391 | { return GenEvent::particle_const_iterator( |
||
| 392 | m_particle_barcodes.end() ); } |
||
| 393 | |||
| 65 | garren | 394 | //! non-const particle iterator |
| 395 | |||
| 396 | /// \class particle_iterator |
||
| 397 | /// HepMC::GenEvent::particle_iterator |
||
| 398 | /// is used to iterate over all particles in the event. |
||
| 399 | class particle_iterator : |
||
| 2 | garren | 400 | public std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t>{ |
| 401 | // Iterates over all vertices in this event |
||
| 402 | public: |
||
| 65 | garren | 403 | /// iterate over particles |
| 2 | garren | 404 | particle_iterator( const std::map<int,GenParticle*>::iterator& i ) |
| 405 | : m_map_iterator( i ) {} |
||
| 406 | particle_iterator() {} |
||
| 65 | garren | 407 | /// copy constructor |
| 2 | garren | 408 | particle_iterator( const particle_iterator& i ) { *this = i; } |
| 409 | virtual ~particle_iterator() {} |
||
| 65 | garren | 410 | /// make a copy |
| 2 | garren | 411 | particle_iterator& operator=( const particle_iterator& i ) { |
| 412 | m_map_iterator = i.m_map_iterator; |
||
| 413 | return *this; |
||
| 414 | } |
||
| 65 | garren | 415 | /// const particle iterator |
| 2 | garren | 416 | operator particle_const_iterator() const |
| 417 | { return particle_const_iterator(m_map_iterator); } |
||
| 65 | garren | 418 | /// return pointer to GenParticle |
| 2 | garren | 419 | GenParticle* operator*(void) const |
| 420 | { return m_map_iterator->second; } |
||
| 65 | garren | 421 | /// Pre-fix increment |
| 422 | particle_iterator& operator++(void) |
||
| 2 | garren | 423 | { ++m_map_iterator; return *this; } |
| 65 | garren | 424 | /// Post-fix increment |
| 425 | particle_iterator operator++(int) |
||
| 2 | garren | 426 | { particle_iterator out(*this); ++(*this); return out; } |
| 65 | garren | 427 | /// equality |
| 2 | garren | 428 | bool operator==( const particle_iterator& a ) const |
| 429 | { return m_map_iterator == a.m_map_iterator; } |
||
| 65 | garren | 430 | /// inequality |
| 2 | garren | 431 | bool operator!=( const particle_iterator& a ) const |
| 432 | { return !(m_map_iterator == a.m_map_iterator); } |
||
| 433 | protected: |
||
| 65 | garren | 434 | /// iterator for GenParticle map |
| 2 | garren | 435 | std::map<int,GenParticle*>::iterator m_map_iterator; |
| 436 | }; |
||
| 437 | friend class particle_iterator; |
||
| 65 | garren | 438 | /// begin particle iteration |
| 2 | garren | 439 | particle_iterator particles_begin() |
| 440 | { return GenEvent::particle_iterator( |
||
| 441 | m_particle_barcodes.begin() ); } |
||
| 65 | garren | 442 | /// end particle iteration |
| 2 | garren | 443 | particle_iterator particles_end() |
| 444 | { return GenEvent::particle_iterator( |
||
| 445 | m_particle_barcodes.end() ); } |
||
| 446 | |||
| 447 | //////////////////////////////////////////////// |
||
| 448 | protected: |
||
| 449 | // |
||
| 450 | // Following methods intended for use by GenParticle/Vertex classes: |
||
| 451 | // In general there is no reason they should be used elsewhere. |
||
| 65 | garren | 452 | /// set the barcode - intended for use by GenParticle |
| 2 | garren | 453 | bool set_barcode( GenParticle* p, int suggested_barcode =0 ); |
| 65 | garren | 454 | /// set the barcode - intended for use by GenVertex |
| 2 | garren | 455 | bool set_barcode( GenVertex* v, int suggested_barcode =0 ); |
| 65 | garren | 456 | /// intended for use by GenParticle |
| 2 | garren | 457 | void remove_barcode( GenParticle* p ); |
| 65 | garren | 458 | /// intended for use by GenVertex |
| 2 | garren | 459 | void remove_barcode( GenVertex* v ); |
| 460 | |||
| 65 | garren | 461 | static unsigned int counter(); //!<num GenEvent objects in memory |
| 462 | void delete_all_vertices(); //!<delete all vertices owned by this event |
||
| 2 | garren | 463 | |
| 464 | private: // data members |
||
| 465 | int m_signal_process_id; |
||
| 466 | int m_event_number; |
||
| 467 | double m_event_scale;// energy scale, see hep-ph/0109068 |
||
| 468 | double m_alphaQCD; // QCD coupling, see hep-ph/0109068 |
||
| 469 | double m_alphaQED; // QED coupling, see hep-ph/0109068 |
||
| 470 | GenVertex* m_signal_process_vertex; |
||
| 471 | WeightContainer m_weights; // weights for this event first weight |
||
| 472 | // is used by default for hit and miss |
||
| 473 | std::vector<long int> m_random_states; // container of rndm num |
||
| 474 | // generator states |
||
| 475 | |||
| 476 | std::map< int,GenVertex*,std::greater<int> > m_vertex_barcodes; |
||
| 477 | std::map< int,GenParticle*,std::less<int> > m_particle_barcodes; |
||
| 14 | garren | 478 | HeavyIon* m_heavy_ion; // undefined by default |
| 36 | garren | 479 | PdfInfo* m_pdf_info; // undefined by default |
| 2 | garren | 480 | |
| 481 | static unsigned int s_counter; |
||
| 482 | }; |
||
| 483 | |||
| 484 | /////////////////////////// |
||
| 485 | // INLINE Access Methods // |
||
| 486 | /////////////////////////// |
||
| 487 | |||
| 65 | garren | 488 | /// The integer ID that uniquely specifies this signal |
| 489 | /// process, i.e. MSUB in Pythia. It is necessary to |
||
| 490 | /// package this with each event rather than with the run |
||
| 491 | /// because many processes may be generated within one run. |
||
| 2 | garren | 492 | inline int GenEvent::signal_process_id() const |
| 493 | { return m_signal_process_id; } |
||
| 494 | |||
| 495 | inline int GenEvent::event_number() const { return m_event_number; } |
||
| 496 | |||
| 497 | inline double GenEvent::event_scale() const { return m_event_scale; } |
||
| 498 | |||
| 499 | inline double GenEvent::alphaQCD() const { return m_alphaQCD; } |
||
| 500 | |||
| 501 | inline double GenEvent::alphaQED() const { return m_alphaQED; } |
||
| 502 | |||
| 503 | inline GenVertex* GenEvent::signal_process_vertex() const { |
||
| 65 | garren | 504 | /// returns a (mutable) pointer to the signal process vertex |
| 2 | garren | 505 | return m_signal_process_vertex; |
| 506 | } |
||
| 507 | |||
| 508 | inline WeightContainer& GenEvent::weights() { return m_weights; } |
||
| 509 | |||
| 510 | inline const WeightContainer& GenEvent::weights() const |
||
| 511 | { return m_weights; } |
||
| 512 | |||
| 14 | garren | 513 | inline HeavyIon* GenEvent::heavy_ion() const |
| 514 | { return m_heavy_ion; } |
||
| 515 | |||
| 36 | garren | 516 | inline PdfInfo* GenEvent::pdf_info() const |
| 517 | { return m_pdf_info; } |
||
| 518 | |||
| 65 | garren | 519 | /// Vector of integers which specify the random number |
| 520 | /// generator's state for this event. It is left to the |
||
| 521 | /// generator to make use of this. We envision a vector of |
||
| 522 | /// RndmStatesTags to be included with a run class which |
||
| 523 | /// would specify the meaning of the random_states. |
||
| 2 | garren | 524 | inline std::vector<long int> GenEvent::random_states() const |
| 525 | { return m_random_states; } |
||
| 526 | |||
| 527 | inline void GenEvent::set_signal_process_id( int id ) |
||
| 528 | { m_signal_process_id = id; } |
||
| 529 | |||
| 530 | inline void GenEvent::set_event_number( int eventno ) |
||
| 531 | { m_event_number = eventno; } |
||
| 532 | |||
| 533 | |||
| 534 | inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; } |
||
| 535 | |||
| 536 | inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; } |
||
| 537 | |||
| 538 | inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; } |
||
| 539 | |||
| 540 | inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) { |
||
| 541 | m_signal_process_vertex = vtx; |
||
| 542 | if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex ); |
||
| 543 | } |
||
| 544 | |||
| 14 | garren | 545 | inline void GenEvent::set_heavy_ion( HeavyIon* ion ) |
| 546 | { m_heavy_ion = ion; } |
||
| 547 | |||
| 36 | garren | 548 | inline void GenEvent::set_pdf_info( PdfInfo* p ) |
| 549 | { m_pdf_info = p; } |
||
| 550 | |||
| 2 | garren | 551 | inline void GenEvent::set_random_states( const std::vector<long int>& |
| 552 | randomstates ) |
||
| 553 | { m_random_states = randomstates; } |
||
| 554 | |||
| 555 | inline void GenEvent::remove_barcode( GenParticle* p ) |
||
| 556 | { m_particle_barcodes.erase( p->barcode() ); } |
||
| 557 | |||
| 558 | inline void GenEvent::remove_barcode( GenVertex* v ) |
||
| 559 | { m_vertex_barcodes.erase( v->barcode() ); } |
||
| 560 | |||
| 65 | garren | 561 | /// Each vertex or particle has a barcode, which is just an integer which |
| 562 | /// uniquely identifies it inside the event (i.e. there is a one to one |
||
| 563 | /// mapping between particle memory addresses and particle barcodes... and |
||
| 564 | /// the same applied for vertices). |
||
| 565 | /// |
||
| 566 | /// The value of a barcode has NO MEANING and NO ORDER! |
||
| 567 | /// For the user's convenience, when an event is read in via an IO_method |
||
| 568 | /// from an indexed list (like the HEPEVT common block), then the index will |
||
| 569 | /// become the barcode for that particle. |
||
| 570 | /// |
||
| 571 | /// Particle barcodes are always positive integers. |
||
| 572 | /// The barcodes are chosen and set automatically when a vertex or particle |
||
| 573 | /// comes under the ownership of an event (i.e. it is contained in an event). |
||
| 2 | garren | 574 | inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const |
| 575 | { |
||
| 576 | std::map<int,GenParticle*>::const_iterator i |
||
| 577 | = m_particle_barcodes.find(barCode); |
||
| 578 | return ( i != m_particle_barcodes.end() ) ? (*i).second : 0; |
||
| 579 | } |
||
| 580 | |||
| 65 | garren | 581 | /// Each vertex or particle has a barcode, which is just an integer which |
| 582 | /// uniquely identifies it inside the event (i.e. there is a one to one |
||
| 583 | /// mapping between particle memory addresses and particle barcodes... and |
||
| 584 | /// the same applied for vertices). |
||
| 585 | /// |
||
| 586 | /// The value of a barcode has NO MEANING and NO ORDER! |
||
| 587 | /// For the user's convenience, when an event is read in via an IO_method |
||
| 588 | /// from an indexed list (like the HEPEVT common block), then the index will |
||
| 589 | /// become the barcode for that particle. |
||
| 590 | /// |
||
| 591 | /// Vertex barcodes are always negative integers. |
||
| 592 | /// The barcodes are chosen and set automatically when a vertex or particle |
||
| 593 | /// comes under the ownership of an event (i.e. it is contained in an event). |
||
| 2 | garren | 594 | inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const |
| 595 | { |
||
| 596 | std::map<int,GenVertex*,std::greater<int> >::const_iterator i |
||
| 597 | = m_vertex_barcodes.find(barCode); |
||
| 598 | return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0; |
||
| 599 | } |
||
| 600 | |||
| 601 | inline int GenEvent::particles_size() const { |
||
| 602 | return (int)m_particle_barcodes.size(); |
||
| 603 | } |
||
| 604 | inline bool GenEvent::particles_empty() const { |
||
| 605 | return (bool)m_particle_barcodes.empty(); |
||
| 606 | } |
||
| 607 | inline int GenEvent::vertices_size() const { |
||
| 608 | return (int)m_vertex_barcodes.size(); |
||
| 609 | } |
||
| 610 | inline bool GenEvent::vertices_empty() const { |
||
| 611 | return (bool)m_vertex_barcodes.empty(); |
||
| 612 | } |
||
| 613 | |||
| 614 | } // HepMC |
||
| 615 | |||
| 616 | #endif // HEPMC_GEN_EVENT_H |
||
| 617 | |||
| 618 | //-------------------------------------------------------------------------- |
||
| 619 | |||
| 620 |