hepmc - Blame information for rev 390
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 ) { |
| 306 | garren | 42 | // if ( p && p->pdg_id() == 22 ) return true; |
| 43 | // return false; | ||
| 2 | garren | 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" | ||
| 390 | garren | 126 | #include "HepMC/GenCrossSection.h" |
| 14 | garren | 127 | #include "HepMC/HeavyIon.h" |
| 36 | garren | 128 | #include "HepMC/PdfInfo.h" |
| 335 | garren | 129 | #include "HepMC/Units.h" |
| 389 | garren | 130 | #include "HepMC/HepMCDefs.h" |
| 2 | garren | 131 | #include <map> |
| 274 | garren | 132 | #include <string> |
| 2 | garren | 133 | #include <vector> |
| 134 | #include <algorithm> | ||
| 135 | #include <iostream> | ||
| 136 | |||
| 137 | namespace HepMC { | ||
| 138 | |||
| 65 | garren | 139 | //! The GenEvent class is the core of HepMC |
| 140 | |||
| 141 | /// | ||
| 142 | /// \class GenEvent | ||
| 143 | /// HepMC::GenEvent contains information about generated particles. | ||
| 144 | /// GenEvent is structured as a set of vertices which contain the particles. | ||
| 145 | /// | ||
| 2 | garren | 146 | class GenEvent { |
| 147 | friend class GenParticle; | ||
| 148 | friend class GenVertex; | ||
| 149 | public: | ||
| 390 | garren | 150 | /// default constructor creates null pointers to HeavyIon, PdfInfo, and GenCrossSection |
| 2 | garren | 151 | GenEvent( int signal_process_id = 0, int event_number = 0, |
| 152 | GenVertex* signal_vertex = 0, | ||
| 153 | const WeightContainer& weights = std::vector<double>(), | ||
| 337 | garren | 154 | const std::vector<long>& randomstates = std::vector<long>(), |
| 155 | Units::MomentumUnit = Units::default_momentum_unit(), | ||
| 156 | Units::LengthUnit = Units::default_length_unit() ); | ||
| 92 | garren | 157 | /// explicit constructor that takes HeavyIon and PdfInfo |
| 158 | GenEvent( int signal_process_id, int event_number, | ||
| 159 | GenVertex* signal_vertex, const WeightContainer& weights, | ||
| 173 | garren | 160 | const std::vector<long>& randomstates, |
| 337 | garren | 161 | const HeavyIon& ion, const PdfInfo& pdf, |
| 162 | Units::MomentumUnit = Units::default_momentum_unit(), | ||
| 163 | Units::LengthUnit = Units::default_length_unit() ); | ||
| 344 | garren | 164 | /// constructor requiring units - all else is default |
| 165 | GenEvent( Units::MomentumUnit, Units::LengthUnit, | ||
| 166 | int signal_process_id = 0, int event_number = 0, | ||
| 167 | GenVertex* signal_vertex = 0, | ||
| 168 | const WeightContainer& weights = std::vector<double>(), | ||
| 169 | const std::vector<long>& randomstates = std::vector<long>() ); | ||
| 170 | /// explicit constructor with units first that takes HeavyIon and PdfInfo | ||
| 171 | GenEvent( Units::MomentumUnit, Units::LengthUnit, | ||
| 172 | int signal_process_id, int event_number, | ||
| 173 | GenVertex* signal_vertex, const WeightContainer& weights, | ||
| 174 | const std::vector<long>& randomstates, | ||
| 175 | const HeavyIon& ion, const PdfInfo& pdf ); | ||
| 65 | garren | 176 | GenEvent( const GenEvent& inevent ); //!< deep copy |
| 177 | GenEvent& operator=( const GenEvent& inevent ); //!< make a deep copy | ||
| 178 | virtual ~GenEvent(); //!<deletes all vertices/particles in this evt | ||
| 147 | garren | 179 | |
| 180 | void swap( GenEvent & other ); //!< swap | ||
| 2 | garren | 181 | |
| 65 | garren | 182 | void print( std::ostream& ostr = std::cout ) const; //!< dumps to ostr |
| 173 | garren | 183 | void print_version( std::ostream& ostr = std::cout ) const; //!< dumps release version to ostr |
| 2 | garren | 184 | |
| 65 | garren | 185 | /// assign a barcode to a particle |
| 2 | garren | 186 | GenParticle* barcode_to_particle( int barCode ) const; |
| 65 | garren | 187 | /// assign a barcode to a vertex |
| 2 | garren | 188 | GenVertex* barcode_to_vertex( int barCode ) const; |
| 189 | |||
| 190 | //////////////////// | ||
| 191 | // access methods // | ||
| 192 | //////////////////// | ||
| 193 | |||
| 65 | garren | 194 | int signal_process_id() const; //!< unique signal process id |
| 195 | int event_number() const; //!< event number | ||
| 103 | garren | 196 | int mpi() const; //!< number of multi parton interactions |
| 65 | garren | 197 | double event_scale() const; //!< energy scale, see hep-ph/0109068 |
| 198 | double alphaQCD() const; //!< QCD coupling, see hep-ph/0109068 | ||
| 199 | double alphaQED() const; //!< QED coupling, see hep-ph/0109068 | ||
| 200 | /// pointer to the vertex containing the signal process | ||
| 2 | garren | 201 | GenVertex* signal_process_vertex() const; |
| 105 | garren | 202 | /// test to see if we have two valid beam particles |
| 203 | bool valid_beam_particles() const; | ||
| 204 | /// pair of pointers to the two incoming beam particles | ||
| 173 | garren | 205 | std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beam_particles() const; |
| 390 | garren | 206 | /// check GenEvent for validity |
| 207 | /// A GenEvent is presumed valid if it has particles and/or vertices. | ||
| 208 | bool is_valid() const; | ||
| 2 | garren | 209 | |
| 65 | garren | 210 | /// direct access to the weights container is allowed. |
| 211 | /// Thus you can use myevt.weights()[2]; | ||
| 212 | /// to access element 2 of the weights. | ||
| 213 | /// or use myevt.weights().push_back( mywgt ); to add an element. | ||
| 214 | /// and you can set the weights with myevt.weights() = myvector; | ||
| 215 | WeightContainer& weights(); //!< direct access to WeightContainer | ||
| 216 | const WeightContainer& weights() const; //!< direct access to WeightContainer | ||
| 2 | garren | 217 | |
| 390 | garren | 218 | /// access the GenCrossSection container if it exists |
| 219 | GenCrossSection const * cross_section() const; | ||
| 220 | GenCrossSection* cross_section(); | ||
| 65 | garren | 221 | /// access the HeavyIon container if it exists |
| 390 | garren | 222 | HeavyIon const * heavy_ion() const; |
| 92 | garren | 223 | HeavyIon* heavy_ion(); |
| 65 | garren | 224 | /// access the PdfInfo container if it exists |
| 390 | garren | 225 | PdfInfo const * pdf_info() const; |
| 92 | garren | 226 | PdfInfo* pdf_info(); |
| 14 | garren | 227 | |
| 65 | garren | 228 | /// vector of integers containing information about the random state |
| 282 | garren | 229 | const std::vector<long>& random_states() const; |
| 2 | garren | 230 | |
| 65 | garren | 231 | /// how many particle barcodes exist? |
| 2 | garren | 232 | int particles_size() const; |
| 65 | garren | 233 | /// return true if there are no particle barcodes |
| 2 | garren | 234 | bool particles_empty() const; |
| 65 | garren | 235 | /// how many vertex barcodes exist? |
| 2 | garren | 236 | int vertices_size() const; |
| 65 | garren | 237 | /// return true if there are no vertex barcodes |
| 2 | garren | 238 | bool vertices_empty() const; |
| 239 | |||
| 274 | garren | 240 | void write_units( std::ostream & os = std::cout ) const; |
| 241 | |||
| 335 | garren | 242 | /// Units used by the GenParticle momentum FourVector. |
| 243 | Units::MomentumUnit momentum_unit() const; | ||
| 244 | /// Units used by the GenVertex position FourVector. | ||
| 245 | Units::LengthUnit length_unit() const; | ||
| 390 | garren | 246 | |
| 247 | std::ostream& write(std::ostream&); | ||
| 248 | std::istream& read(std::istream&); | ||
| 274 | garren | 249 | |
| 105 | garren | 250 | ///////////////////// |
| 251 | // mutator methods // | ||
| 252 | ///////////////////// | ||
| 96 | garren | 253 | |
| 65 | garren | 254 | bool add_vertex( GenVertex* vtx ); //!< adds to evt and adopts |
| 96 | garren | 255 | bool remove_vertex( GenVertex* vtx ); //!< erases vtx from evt |
| 256 | void clear(); //!< empties the entire event | ||
| 274 | garren | 257 | |
| 290 | garren | 258 | void set_signal_process_id( int id ); //!< set unique signal process id |
| 259 | void set_event_number( int eventno ); //!< set event number | ||
| 260 | void set_mpi( int ); //!< set number of multi parton interactions | ||
| 261 | void set_event_scale( double scale ); //!< set energy scale | ||
| 262 | void set_alphaQCD( double a ); //!< set QCD coupling | ||
| 263 | void set_alphaQED( double a ); //!< set QED coupling | ||
| 264 | |||
| 265 | /// set pointer to the vertex containing the signal process | ||
| 266 | void set_signal_process_vertex( GenVertex* ); | ||
| 267 | /// set incoming beam particles | ||
| 268 | bool set_beam_particles(GenParticle*, GenParticle*); | ||
| 269 | /// use a pair of GenParticle*'s to set incoming beam particles | ||
| 270 | bool set_beam_particles(std::pair<HepMC::GenParticle*,HepMC::GenParticle*> const &); | ||
| 271 | /// provide random state information | ||
| 272 | void set_random_states( const std::vector<long>& randomstates ); | ||
| 273 | |||
| 390 | garren | 274 | /// provide a pointer to the GenCrossSection container |
| 275 | void set_cross_section( const GenCrossSection& ); | ||
| 290 | garren | 276 | /// provide a pointer to the HeavyIon container |
| 277 | void set_heavy_ion( const HeavyIon& ion ); | ||
| 278 | /// provide a pointer to the PdfInfo container | ||
| 279 | void set_pdf_info( const PdfInfo& p ); | ||
| 274 | garren | 280 | |
| 341 | garren | 281 | /// set the units using enums |
| 335 | garren | 282 | void use_units( Units::MomentumUnit, Units::LengthUnit ); |
| 341 | garren | 283 | /// set the units using strings |
| 335 | garren | 284 | /// the string must match the enum exactly |
| 285 | void use_units( std::string&, std::string& ); | ||
| 274 | garren | 286 | |
| 2 | garren | 287 | public: |
| 288 | /////////////////////////////// | ||
| 289 | // vertex_iterators // | ||
| 290 | /////////////////////////////// | ||
| 291 | // Note: the XXX_iterator is "resolvable" as XXX_const_iterator, but | ||
| 292 | // not the reverse, which is consistent with STL, | ||
| 293 | // see Musser, Derge, Saini 2ndEd. p. 69,70. | ||
| 65 | garren | 294 | |
| 295 | //! const vertex iterator | ||
| 296 | |||
| 297 | /// \class vertex_const_iterator | ||
| 298 | /// HepMC::GenEvent::vertex_const_iterator | ||
| 299 | /// is used to iterate over all vertices in the event. | ||
| 2 | garren | 300 | class vertex_const_iterator : |
| 173 | garren | 301 | public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{ |
| 2 | garren | 302 | // Iterates over all vertices in this event |
| 303 | public: | ||
| 65 | garren | 304 | /// constructor requiring vertex information |
| 2 | garren | 305 | vertex_const_iterator( |
| 306 | const | ||
| 173 | garren | 307 | std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i) |
| 2 | garren | 308 | : m_map_iterator(i) {} |
| 309 | vertex_const_iterator() {} | ||
| 65 | garren | 310 | /// copy constructor |
| 2 | garren | 311 | vertex_const_iterator( const vertex_const_iterator& i ) |
| 312 | { *this = i; } | ||
| 313 | virtual ~vertex_const_iterator() {} | ||
| 65 | garren | 314 | /// make a copy |
| 2 | garren | 315 | vertex_const_iterator& operator=( const vertex_const_iterator& i ) |
| 316 | { m_map_iterator = i.m_map_iterator; return *this; } | ||
| 65 | garren | 317 | /// return a pointer to a GenVertex |
| 2 | garren | 318 | GenVertex* operator*(void) const { return m_map_iterator->second; } |
| 65 | garren | 319 | /// Pre-fix increment |
| 2 | garren | 320 | vertex_const_iterator& operator++(void) //Pre-fix increment |
| 321 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 322 | /// Post-fix increment |
| 2 | garren | 323 | vertex_const_iterator operator++(int) //Post-fix increment |
| 324 | { vertex_const_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 325 | /// equality |
| 2 | garren | 326 | bool operator==( const vertex_const_iterator& a ) const |
| 327 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 328 | /// inequality |
| 2 | garren | 329 | bool operator!=( const vertex_const_iterator& a ) const |
| 330 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 331 | protected: | ||
| 65 | garren | 332 | /// const iterator to a vertex map |
| 173 | garren | 333 | std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator |
| 2 | garren | 334 | m_map_iterator; |
| 390 | garren | 335 | private: |
| 336 | /// Pre-fix increment -- is not allowed | ||
| 337 | vertex_const_iterator& operator--(void); | ||
| 338 | /// Post-fix increment -- is not allowed | ||
| 339 | vertex_const_iterator operator--(int); | ||
| 2 | garren | 340 | }; |
| 341 | friend class vertex_const_iterator; | ||
| 65 | garren | 342 | /// begin vertex iteration |
| 2 | garren | 343 | vertex_const_iterator vertices_begin() const |
| 344 | { return GenEvent::vertex_const_iterator( | ||
| 345 | m_vertex_barcodes.begin() ); } | ||
| 65 | garren | 346 | /// end vertex iteration |
| 2 | garren | 347 | vertex_const_iterator vertices_end() const |
| 348 | { return GenEvent::vertex_const_iterator( | ||
| 349 | m_vertex_barcodes.end() ); } | ||
| 350 | |||
| 65 | garren | 351 | |
| 352 | //! non-const vertex iterator | ||
| 353 | |||
| 354 | /// \class vertex_iterator | ||
| 355 | /// HepMC::GenEvent::vertex_iterator | ||
| 356 | /// is used to iterate over all vertices in the event. | ||
| 2 | garren | 357 | class vertex_iterator : |
| 173 | garren | 358 | public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{ |
| 2 | garren | 359 | // Iterates over all vertices in this event |
| 360 | public: | ||
| 65 | garren | 361 | /// constructor requiring vertex information |
| 2 | garren | 362 | vertex_iterator( |
| 363 | const | ||
| 173 | garren | 364 | std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i ) |
| 2 | garren | 365 | : m_map_iterator( i ) {} |
| 366 | vertex_iterator() {} | ||
| 65 | garren | 367 | /// copy constructor |
| 2 | garren | 368 | vertex_iterator( const vertex_iterator& i ) { *this = i; } |
| 369 | virtual ~vertex_iterator() {} | ||
| 65 | garren | 370 | /// make a copy |
| 2 | garren | 371 | vertex_iterator& operator=( const vertex_iterator& i ) { |
| 372 | m_map_iterator = i.m_map_iterator; | ||
| 373 | return *this; | ||
| 374 | } | ||
| 65 | garren | 375 | /// const vertex iterator |
| 2 | garren | 376 | operator vertex_const_iterator() const |
| 377 | { return vertex_const_iterator(m_map_iterator); } | ||
| 65 | garren | 378 | /// return a pointer to a GenVertex |
| 2 | garren | 379 | GenVertex* operator*(void) const |
| 380 | { return m_map_iterator->second; } | ||
| 65 | garren | 381 | /// Pre-fix increment |
| 2 | garren | 382 | vertex_iterator& operator++(void) //Pre-fix increment |
| 383 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 384 | /// Post-fix increment |
| 2 | garren | 385 | vertex_iterator operator++(int) //Post-fix increment |
| 386 | { vertex_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 387 | /// equality |
| 2 | garren | 388 | bool operator==( const vertex_iterator& a ) const |
| 389 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 390 | /// inequality |
| 2 | garren | 391 | bool operator!=( const vertex_iterator& a ) const |
| 392 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 393 | protected: | ||
| 65 | garren | 394 | /// iterator to the vertex map |
| 173 | garren | 395 | std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator |
| 2 | garren | 396 | m_map_iterator; |
| 390 | garren | 397 | private: |
| 398 | /// Pre-fix increment | ||
| 399 | vertex_iterator& operator--(void); | ||
| 400 | /// Post-fix increment | ||
| 401 | vertex_iterator operator--(int); | ||
| 402 | |||
| 2 | garren | 403 | }; |
| 404 | friend class vertex_iterator; | ||
| 65 | garren | 405 | /// begin vertex iteration |
| 2 | garren | 406 | vertex_iterator vertices_begin() |
| 407 | { return GenEvent::vertex_iterator( | ||
| 408 | m_vertex_barcodes.begin() ); } | ||
| 65 | garren | 409 | /// end vertex iteration |
| 2 | garren | 410 | vertex_iterator vertices_end() |
| 411 | { return GenEvent::vertex_iterator( | ||
| 412 | m_vertex_barcodes.end() ); } | ||
| 413 | |||
| 414 | public: | ||
| 415 | /////////////////////////////// | ||
| 416 | // particle_iterator // | ||
| 417 | /////////////////////////////// | ||
| 418 | // Example of iterating over all particles in the event: | ||
| 419 | // for ( GenEvent::particle_const_iterator p = particles_begin(); | ||
| 420 | // p != particles_end(); ++p ) { | ||
| 421 | // (*p)->print(); | ||
| 422 | // } | ||
| 423 | // | ||
| 65 | garren | 424 | |
| 425 | //! const particle iterator | ||
| 426 | |||
| 427 | /// \class particle_const_iterator | ||
| 428 | /// HepMC::GenEvent::particle_const_iterator | ||
| 429 | /// is used to iterate over all particles in the event. | ||
| 2 | garren | 430 | class particle_const_iterator : |
| 173 | garren | 431 | public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{ |
| 2 | garren | 432 | // Iterates over all vertices in this event |
| 433 | public: | ||
| 65 | garren | 434 | /// iterate over particles |
| 2 | garren | 435 | particle_const_iterator( |
| 173 | garren | 436 | const std::map<int,HepMC::GenParticle*>::const_iterator& i ) |
| 2 | garren | 437 | : m_map_iterator(i) {} |
| 438 | particle_const_iterator() {} | ||
| 65 | garren | 439 | /// copy constructor |
| 2 | garren | 440 | particle_const_iterator( const particle_const_iterator& i ) |
| 441 | { *this = i; } | ||
| 442 | virtual ~particle_const_iterator() {} | ||
| 65 | garren | 443 | /// make a copy |
| 2 | garren | 444 | particle_const_iterator& operator=( |
| 445 | const particle_const_iterator& i ) | ||
| 446 | { m_map_iterator = i.m_map_iterator; return *this; } | ||
| 65 | garren | 447 | /// return a pointer to GenParticle |
| 2 | garren | 448 | GenParticle* operator*(void) const |
| 449 | { return m_map_iterator->second; } | ||
| 65 | garren | 450 | /// Pre-fix increment |
| 2 | garren | 451 | particle_const_iterator& operator++(void) //Pre-fix increment |
| 452 | { ++m_map_iterator; return *this; } | ||
| 65 | garren | 453 | /// Post-fix increment |
| 2 | garren | 454 | particle_const_iterator operator++(int) //Post-fix increment |
| 455 | { particle_const_iterator out(*this); ++(*this); return out; } | ||
| 65 | garren | 456 | /// equality |
| 2 | garren | 457 | bool operator==( const particle_const_iterator& a ) const |
| 458 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 459 | /// inequality |
| 2 | garren | 460 | bool operator!=( const particle_const_iterator& a ) const |
| 461 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 462 | protected: | ||
| 65 | garren | 463 | /// const iterator to the GenParticle map |
| 173 | garren | 464 | std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator; |
| 390 | garren | 465 | private: |
| 466 | /// Pre-fix increment | ||
| 467 | particle_const_iterator& operator--(void); | ||
| 468 | /// Post-fix increment | ||
| 469 | particle_const_iterator operator--(int); | ||
| 2 | garren | 470 | }; |
| 471 | friend class particle_const_iterator; | ||
| 65 | garren | 472 | /// begin particle iteration |
| 2 | garren | 473 | particle_const_iterator particles_begin() const |
| 474 | { return GenEvent::particle_const_iterator( | ||
| 475 | m_particle_barcodes.begin() ); } | ||
| 65 | garren | 476 | /// end particle iteration |
| 2 | garren | 477 | particle_const_iterator particles_end() const |
| 478 | { return GenEvent::particle_const_iterator( | ||
| 479 | m_particle_barcodes.end() ); } | ||
| 480 | |||
| 65 | garren | 481 | //! non-const particle iterator |
| 482 | |||
| 483 | /// \class particle_iterator | ||
| 484 | /// HepMC::GenEvent::particle_iterator | ||
| 485 | /// is used to iterate over all particles in the event. | ||
| 486 | class particle_iterator : | ||
| 173 | garren | 487 | public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{ |
| 2 | garren | 488 | // Iterates over all vertices in this event |
| 489 | public: | ||
| 65 | garren | 490 | /// iterate over particles |
| 173 | garren | 491 | particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i ) |
| 2 | garren | 492 | : m_map_iterator( i ) {} |
| 493 | particle_iterator() {} | ||
| 65 | garren | 494 | /// copy constructor |
| 2 | garren | 495 | particle_iterator( const particle_iterator& i ) { *this = i; } |
| 496 | virtual ~particle_iterator() {} | ||
| 65 | garren | 497 | /// make a copy |
| 2 | garren | 498 | particle_iterator& operator=( const particle_iterator& i ) { |
| 499 | m_map_iterator = i.m_map_iterator; | ||
| 500 | return *this; | ||
| 501 | } | ||
| 65 | garren | 502 | /// const particle iterator |
| 2 | garren | 503 | operator particle_const_iterator() const |
| 504 | { return particle_const_iterator(m_map_iterator); } | ||
| 65 | garren | 505 | /// return pointer to GenParticle |
| 2 | garren | 506 | GenParticle* operator*(void) const |
| 507 | { return m_map_iterator->second; } | ||
| 65 | garren | 508 | /// Pre-fix increment |
| 509 | particle_iterator& operator++(void) | ||
| 2 | garren | 510 | { ++m_map_iterator; return *this; } |
| 65 | garren | 511 | /// Post-fix increment |
| 512 | particle_iterator operator++(int) | ||
| 2 | garren | 513 | { particle_iterator out(*this); ++(*this); return out; } |
| 65 | garren | 514 | /// equality |
| 2 | garren | 515 | bool operator==( const particle_iterator& a ) const |
| 516 | { return m_map_iterator == a.m_map_iterator; } | ||
| 65 | garren | 517 | /// inequality |
| 2 | garren | 518 | bool operator!=( const particle_iterator& a ) const |
| 519 | { return !(m_map_iterator == a.m_map_iterator); } | ||
| 520 | protected: | ||
| 65 | garren | 521 | /// iterator for GenParticle map |
| 173 | garren | 522 | std::map<int,HepMC::GenParticle*>::iterator m_map_iterator; |
| 390 | garren | 523 | private: |
| 524 | /// Pre-fix increment | ||
| 525 | particle_iterator& operator--(void); | ||
| 526 | /// Post-fix increment | ||
| 527 | particle_iterator operator--(int); | ||
| 2 | garren | 528 | }; |
| 529 | friend class particle_iterator; | ||
| 65 | garren | 530 | /// begin particle iteration |
| 2 | garren | 531 | particle_iterator particles_begin() |
| 532 | { return GenEvent::particle_iterator( | ||
| 533 | m_particle_barcodes.begin() ); } | ||
| 65 | garren | 534 | /// end particle iteration |
| 2 | garren | 535 | particle_iterator particles_end() |
| 536 | { return GenEvent::particle_iterator( | ||
| 537 | m_particle_barcodes.end() ); } | ||
| 538 | |||
| 539 | //////////////////////////////////////////////// | ||
| 540 | protected: | ||
| 541 | // | ||
| 542 | // Following methods intended for use by GenParticle/Vertex classes: | ||
| 543 | // In general there is no reason they should be used elsewhere. | ||
| 65 | garren | 544 | /// set the barcode - intended for use by GenParticle |
| 306 | garren | 545 | bool set_barcode( GenParticle* p, int suggested_barcode =false ); |
| 65 | garren | 546 | /// set the barcode - intended for use by GenVertex |
| 306 | garren | 547 | bool set_barcode( GenVertex* v, int suggested_barcode =false ); |
| 65 | garren | 548 | /// intended for use by GenParticle |
| 2 | garren | 549 | void remove_barcode( GenParticle* p ); |
| 65 | garren | 550 | /// intended for use by GenVertex |
| 2 | garren | 551 | void remove_barcode( GenVertex* v ); |
| 552 | |||
| 65 | garren | 553 | void delete_all_vertices(); //!<delete all vertices owned by this event |
| 2 | garren | 554 | |
| 335 | garren | 555 | private: // methods |
| 556 | /// internal method used when converting momentum units | ||
| 557 | bool use_momentum_unit( Units::MomentumUnit ); | ||
| 558 | bool use_momentum_unit( std::string& ); | ||
| 559 | /// internal method used when converting length units | ||
| 560 | bool use_length_unit( Units::LengthUnit ); | ||
| 561 | bool use_length_unit( std::string& ); | ||
| 390 | garren | 562 | |
| 563 | // the following internal methods are used by read() and write() | ||
| 335 | garren | 564 | |
| 390 | garren | 565 | /// send the beam particles to ASCII output |
| 566 | std::ostream & write_beam_particles( std::ostream &, | ||
| 567 | std::pair<HepMC::GenParticle *,HepMC::GenParticle *> ); | ||
| 568 | /// send a GenVertex to ASCII output | ||
| 569 | std::ostream & write_vertex( std::ostream &, GenVertex const * ); | ||
| 570 | /// send a GenParticle to ASCII output | ||
| 571 | std::ostream & write_particle( std::ostream&, GenParticle const * ); | ||
| 572 | /// find the file type | ||
| 573 | std::istream & find_file_type( std::istream & ); | ||
| 574 | /// find the key at the end of the block | ||
| 575 | std::istream & find_end_key( std::istream &, int & ); | ||
| 576 | /// get unit information from ASCII input | ||
| 577 | std::istream & read_units( std::istream & ); | ||
| 578 | |||
| 2 | garren | 579 | private: // data members |
| 580 | int m_signal_process_id; | ||
| 581 | int m_event_number; | ||
| 103 | garren | 582 | int m_mpi; // number of multi paricle interactions |
| 2 | garren | 583 | double m_event_scale;// energy scale, see hep-ph/0109068 |
| 584 | double m_alphaQCD; // QCD coupling, see hep-ph/0109068 | ||
| 585 | double m_alphaQED; // QED coupling, see hep-ph/0109068 | ||
| 586 | GenVertex* m_signal_process_vertex; | ||
| 105 | garren | 587 | GenParticle* m_beam_particle_1; |
| 588 | GenParticle* m_beam_particle_2; | ||
| 2 | garren | 589 | WeightContainer m_weights; // weights for this event first weight |
| 590 | // is used by default for hit and miss | ||
| 173 | garren | 591 | std::vector<long> m_random_states; // container of rndm num |
| 2 | garren | 592 | // generator states |
| 593 | |||
| 173 | garren | 594 | std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes; |
| 595 | std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes; | ||
| 390 | garren | 596 | GenCrossSection* m_cross_section; // undefined by default |
| 335 | garren | 597 | HeavyIon* m_heavy_ion; // undefined by default |
| 598 | PdfInfo* m_pdf_info; // undefined by default | ||
| 599 | Units::MomentumUnit m_momentum_unit; // default value set by configure switch | ||
| 600 | Units::LengthUnit m_position_unit; // default value set by configure switch | ||
| 2 | garren | 601 | |
| 602 | }; | ||
| 603 | |||
| 335 | garren | 604 | |
| 2 | garren | 605 | /////////////////////////// |
| 390 | garren | 606 | // IO Free Functions // |
| 607 | /////////////////////////// | ||
| 608 | |||
| 609 | /// standard streaming IO output operator | ||
| 610 | std::ostream & operator << (std::ostream &, GenEvent &); | ||
| 611 | /// standard streaming IO input operator | ||
| 612 | std::istream & operator >> (std::istream &, GenEvent &); | ||
| 613 | /// set the units for this input stream | ||
| 614 | std::istream & set_input_units(std::istream &, | ||
| 615 | Units::MomentumUnit, Units::LengthUnit); | ||
| 616 | /// Explicitly write the begin block lines that IO_GenEvent uses | ||
| 617 | std::ostream & write_HepMC_IO_block_begin(std::ostream & ); | ||
| 618 | /// Explicitly write the end block line that IO_GenEvent uses | ||
| 619 | std::ostream & write_HepMC_IO_block_end(std::ostream & ); | ||
| 620 | |||
| 621 | |||
| 622 | /////////////////////////// | ||
| 335 | garren | 623 | // INLINE Free Functions // |
| 624 | /////////////////////////// | ||
| 625 | |||
| 626 | // Implemented in terms of GenEvent::use_... | ||
| 627 | inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l) | ||
| 628 | { | ||
| 629 | evt.use_units(m, l); | ||
| 630 | return evt; | ||
| 631 | } | ||
| 632 | |||
| 633 | /////////////////////////// | ||
| 2 | garren | 634 | // INLINE Access Methods // |
| 635 | /////////////////////////// | ||
| 636 | |||
| 65 | garren | 637 | /// The integer ID that uniquely specifies this signal |
| 638 | /// process, i.e. MSUB in Pythia. It is necessary to | ||
| 639 | /// package this with each event rather than with the run | ||
| 640 | /// because many processes may be generated within one run. | ||
| 2 | garren | 641 | inline int GenEvent::signal_process_id() const |
| 642 | { return m_signal_process_id; } | ||
| 643 | |||
| 644 | inline int GenEvent::event_number() const { return m_event_number; } | ||
| 645 | |||
| 103 | garren | 646 | /// Returns the number of multi parton interactions in the event. |
| 647 | /// This number is -1 if it is not set. | ||
| 648 | inline int GenEvent::mpi() const { return m_mpi; } | ||
| 649 | |||
| 2 | garren | 650 | inline double GenEvent::event_scale() const { return m_event_scale; } |
| 651 | |||
| 652 | inline double GenEvent::alphaQCD() const { return m_alphaQCD; } | ||
| 653 | |||
| 654 | inline double GenEvent::alphaQED() const { return m_alphaQED; } | ||
| 655 | |||
| 656 | inline GenVertex* GenEvent::signal_process_vertex() const { | ||
| 65 | garren | 657 | /// returns a (mutable) pointer to the signal process vertex |
| 2 | garren | 658 | return m_signal_process_vertex; |
| 659 | } | ||
| 660 | |||
| 661 | inline WeightContainer& GenEvent::weights() { return m_weights; } | ||
| 662 | |||
| 663 | inline const WeightContainer& GenEvent::weights() const | ||
| 664 | { return m_weights; } | ||
| 665 | |||
| 390 | garren | 666 | inline GenCrossSection const * GenEvent::cross_section() const |
| 667 | { return m_cross_section; } | ||
| 668 | |||
| 669 | inline GenCrossSection* GenEvent::cross_section() | ||
| 670 | { return m_cross_section; } | ||
| 671 | |||
| 297 | garren | 672 | inline HeavyIon const * GenEvent::heavy_ion() const |
| 14 | garren | 673 | { return m_heavy_ion; } |
| 674 | |||
| 92 | garren | 675 | inline HeavyIon* GenEvent::heavy_ion() |
| 676 | { return m_heavy_ion; } | ||
| 677 | |||
| 297 | garren | 678 | inline PdfInfo const * GenEvent::pdf_info() const |
| 36 | garren | 679 | { return m_pdf_info; } |
| 680 | |||
| 92 | garren | 681 | inline PdfInfo* GenEvent::pdf_info() |
| 682 | { return m_pdf_info; } | ||
| 683 | |||
| 65 | garren | 684 | /// Vector of integers which specify the random number |
| 685 | /// generator's state for this event. It is left to the | ||
| 686 | /// generator to make use of this. We envision a vector of | ||
| 687 | /// RndmStatesTags to be included with a run class which | ||
| 688 | /// would specify the meaning of the random_states. | ||
| 282 | garren | 689 | inline const std::vector<long>& GenEvent::random_states() const |
| 2 | garren | 690 | { return m_random_states; } |
| 691 | |||
| 692 | inline void GenEvent::set_signal_process_id( int id ) | ||
| 693 | { m_signal_process_id = id; } | ||
| 694 | |||
| 695 | inline void GenEvent::set_event_number( int eventno ) | ||
| 696 | { m_event_number = eventno; } | ||
| 697 | |||
| 103 | garren | 698 | /// Use this to set the number of multi parton interactions in each event. |
| 699 | inline void GenEvent::set_mpi( int nmpi ) | ||
| 700 | { m_mpi = nmpi; } | ||
| 2 | garren | 701 | |
| 103 | garren | 702 | |
| 2 | garren | 703 | inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; } |
| 704 | |||
| 705 | inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; } | ||
| 706 | |||
| 707 | inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; } | ||
| 708 | |||
| 709 | inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) { | ||
| 710 | m_signal_process_vertex = vtx; | ||
| 711 | if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex ); | ||
| 712 | } | ||
| 713 | |||
| 390 | garren | 714 | inline void GenEvent::set_cross_section( const GenCrossSection& xs ) |
| 715 | { | ||
| 716 | delete m_cross_section; | ||
| 717 | m_cross_section = new GenCrossSection(xs); | ||
| 718 | } | ||
| 719 | |||
| 92 | garren | 720 | inline void GenEvent::set_heavy_ion( const HeavyIon& ion ) |
| 390 | garren | 721 | { |
| 722 | delete m_heavy_ion; | ||
| 723 | m_heavy_ion = new HeavyIon(ion); | ||
| 724 | } | ||
| 14 | garren | 725 | |
| 92 | garren | 726 | inline void GenEvent::set_pdf_info( const PdfInfo& p ) |
| 390 | garren | 727 | { |
| 728 | delete m_pdf_info; | ||
| 729 | m_pdf_info = new PdfInfo(p); | ||
| 730 | } | ||
| 36 | garren | 731 | |
| 173 | garren | 732 | inline void GenEvent::set_random_states( const std::vector<long>& |
| 2 | garren | 733 | randomstates ) |
| 734 | { m_random_states = randomstates; } | ||
| 735 | |||
| 736 | inline void GenEvent::remove_barcode( GenParticle* p ) | ||
| 737 | { m_particle_barcodes.erase( p->barcode() ); } | ||
| 738 | |||
| 739 | inline void GenEvent::remove_barcode( GenVertex* v ) | ||
| 740 | { m_vertex_barcodes.erase( v->barcode() ); } | ||
| 741 | |||
| 65 | garren | 742 | /// Each vertex or particle has a barcode, which is just an integer which |
| 743 | /// uniquely identifies it inside the event (i.e. there is a one to one | ||
| 744 | /// mapping between particle memory addresses and particle barcodes... and | ||
| 745 | /// the same applied for vertices). | ||
| 746 | /// | ||
| 747 | /// The value of a barcode has NO MEANING and NO ORDER! | ||
| 748 | /// For the user's convenience, when an event is read in via an IO_method | ||
| 749 | /// from an indexed list (like the HEPEVT common block), then the index will | ||
| 750 | /// become the barcode for that particle. | ||
| 751 | /// | ||
| 752 | /// Particle barcodes are always positive integers. | ||
| 753 | /// The barcodes are chosen and set automatically when a vertex or particle | ||
| 754 | /// comes under the ownership of an event (i.e. it is contained in an event). | ||
| 2 | garren | 755 | inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const |
| 756 | { | ||
| 173 | garren | 757 | std::map<int,HepMC::GenParticle*>::const_iterator i |
| 2 | garren | 758 | = m_particle_barcodes.find(barCode); |
| 759 | return ( i != m_particle_barcodes.end() ) ? (*i).second : 0; | ||
| 760 | } | ||
| 761 | |||
| 65 | garren | 762 | /// Each vertex or particle has a barcode, which is just an integer which |
| 763 | /// uniquely identifies it inside the event (i.e. there is a one to one | ||
| 764 | /// mapping between particle memory addresses and particle barcodes... and | ||
| 765 | /// the same applied for vertices). | ||
| 766 | /// | ||
| 767 | /// The value of a barcode has NO MEANING and NO ORDER! | ||
| 768 | /// For the user's convenience, when an event is read in via an IO_method | ||
| 769 | /// from an indexed list (like the HEPEVT common block), then the index will | ||
| 770 | /// become the barcode for that particle. | ||
| 771 | /// | ||
| 772 | /// Vertex barcodes are always negative integers. | ||
| 773 | /// The barcodes are chosen and set automatically when a vertex or particle | ||
| 774 | /// comes under the ownership of an event (i.e. it is contained in an event). | ||
| 2 | garren | 775 | inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const |
| 776 | { | ||
| 777 | std::map<int,GenVertex*,std::greater<int> >::const_iterator i | ||
| 778 | = m_vertex_barcodes.find(barCode); | ||
| 779 | return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0; | ||
| 780 | } | ||
| 781 | |||
| 782 | inline int GenEvent::particles_size() const { | ||
| 783 | return (int)m_particle_barcodes.size(); | ||
| 784 | } | ||
| 785 | inline bool GenEvent::particles_empty() const { | ||
| 786 | return (bool)m_particle_barcodes.empty(); | ||
| 787 | } | ||
| 788 | inline int GenEvent::vertices_size() const { | ||
| 789 | return (int)m_vertex_barcodes.size(); | ||
| 790 | } | ||
| 791 | inline bool GenEvent::vertices_empty() const { | ||
| 792 | return (bool)m_vertex_barcodes.empty(); | ||
| 793 | } | ||
| 105 | garren | 794 | |
| 795 | // beam particles | ||
| 173 | garren | 796 | inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const { |
| 105 | garren | 797 | return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2); |
| 798 | } | ||
| 2 | garren | 799 | |
| 335 | garren | 800 | // units |
| 801 | inline Units::MomentumUnit GenEvent::momentum_unit() const { | ||
| 802 | return m_momentum_unit; | ||
| 274 | garren | 803 | } |
| 335 | garren | 804 | inline Units::LengthUnit GenEvent::length_unit() const { |
| 805 | return m_position_unit; | ||
| 274 | garren | 806 | } |
| 335 | garren | 807 | |
| 808 | inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) { | ||
| 809 | use_momentum_unit( new_m ); | ||
| 810 | use_length_unit( new_l ); | ||
| 274 | garren | 811 | } |
| 335 | garren | 812 | |
| 813 | inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) { | ||
| 814 | use_momentum_unit( new_m ); | ||
| 815 | use_length_unit( new_l ); | ||
| 274 | garren | 816 | } |
| 817 | |||
| 2 | garren | 818 | } // HepMC |
| 819 | |||
| 820 | #endif // HEPMC_GEN_EVENT_H | ||
| 821 | |||
| 822 | //-------------------------------------------------------------------------- | ||
| 823 | |||
| 824 |
