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