Fork me on GitHub

source: svn/trunk/Utilities/HepMC/interface/GenEvent.h@ 661

Last change on this file since 661 was 572, checked in by cp3-support, 13 years ago

upgrade HepMC to version 2.06.05

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