]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TEvtGen/HepMC/GenEvent.h
Updates EvtGen Code
[u/mrichter/AliRoot.git] / TEvtGen / HepMC / GenEvent.h
CommitLineData
0ca57c2f 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 "HepMC/GenVertex.h"
128#include "HepMC/GenParticle.h"
129#include "HepMC/WeightContainer.h"
130#include "HepMC/GenCrossSection.h"
131#include "HepMC/HeavyIon.h"
132#include "HepMC/PdfInfo.h"
133#include "HepMC/Units.h"
134#include "HepMC/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 /// This method will convert momentum and position data if necessary
298 void use_units( Units::MomentumUnit, Units::LengthUnit );
299 /// set the units using strings
300 /// the string must match the enum exactly
301 /// This method will convert momentum and position data if necessary
302 void use_units( std::string&, std::string& );
303
304 /// set the units using enums
305 /// This method will NOT convert momentum and position data
306 void define_units( Units::MomentumUnit, Units::LengthUnit );
307 /// set the units using strings
308 /// the string must match the enum exactly
309 /// This method will NOT convert momentum and position data
310 void define_units( std::string&, std::string& );
311
312 /// vertex range
313 GenEventVertexRange vertex_range();
314 /// vertex range
315 ConstGenEventVertexRange vertex_range() const;
316 /// particle range
317 GenEventParticleRange particle_range();
318 /// particle range
319 ConstGenEventParticleRange particle_range() const;
320
321 public:
322 ///////////////////////////////
323 // vertex_iterators //
324 ///////////////////////////////
325 // Note: the XXX_iterator is "resolvable" as XXX_const_iterator, but
326 // not the reverse, which is consistent with STL,
327 // see Musser, Derge, Saini 2ndEd. p. 69,70.
328
329 //! const vertex iterator
330
331 /// \class vertex_const_iterator
332 /// HepMC::GenEvent::vertex_const_iterator
333 /// is used to iterate over all vertices in the event.
334 class vertex_const_iterator :
335 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
336 // Iterates over all vertices in this event
337 public:
338 /// constructor requiring vertex information
339 vertex_const_iterator(
340 const
341 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator& i)
342 : m_map_iterator(i) {}
343 vertex_const_iterator() {}
344 /// copy constructor
345 vertex_const_iterator( const vertex_const_iterator& i )
346 { *this = i; }
347 virtual ~vertex_const_iterator() {}
348 /// make a copy
349 vertex_const_iterator& operator=( const vertex_const_iterator& i )
350 { m_map_iterator = i.m_map_iterator; return *this; }
351 /// return a pointer to a GenVertex
352 GenVertex* operator*(void) const { return m_map_iterator->second; }
353 /// Pre-fix increment
354 vertex_const_iterator& operator++(void) //Pre-fix increment
355 { ++m_map_iterator; return *this; }
356 /// Post-fix increment
357 vertex_const_iterator operator++(int) //Post-fix increment
358 { vertex_const_iterator out(*this); ++(*this); return out; }
359 /// equality
360 bool operator==( const vertex_const_iterator& a ) const
361 { return m_map_iterator == a.m_map_iterator; }
362 /// inequality
363 bool operator!=( const vertex_const_iterator& a ) const
364 { return !(m_map_iterator == a.m_map_iterator); }
365 protected:
366 /// const iterator to a vertex map
367 std::map<int,HepMC::GenVertex*,std::greater<int> >::const_iterator
368 m_map_iterator;
369 private:
370 /// Pre-fix increment -- is not allowed
371 vertex_const_iterator& operator--(void);
372 /// Post-fix increment -- is not allowed
373 vertex_const_iterator operator--(int);
374 };
375 friend class vertex_const_iterator;
376 /// begin vertex iteration
377 vertex_const_iterator vertices_begin() const
378 { return GenEvent::vertex_const_iterator(
379 m_vertex_barcodes.begin() ); }
380 /// end vertex iteration
381 vertex_const_iterator vertices_end() const
382 { return GenEvent::vertex_const_iterator(
383 m_vertex_barcodes.end() ); }
384
385
386 //! non-const vertex iterator
387
388 /// \class vertex_iterator
389 /// HepMC::GenEvent::vertex_iterator
390 /// is used to iterate over all vertices in the event.
391 class vertex_iterator :
392 public std::iterator<std::forward_iterator_tag,HepMC::GenVertex*,ptrdiff_t>{
393 // Iterates over all vertices in this event
394 public:
395 /// constructor requiring vertex information
396 vertex_iterator(
397 const
398 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator& i )
399 : m_map_iterator( i ) {}
400 vertex_iterator() {}
401 /// copy constructor
402 vertex_iterator( const vertex_iterator& i ) { *this = i; }
403 virtual ~vertex_iterator() {}
404 /// make a copy
405 vertex_iterator& operator=( const vertex_iterator& i ) {
406 m_map_iterator = i.m_map_iterator;
407 return *this;
408 }
409 /// const vertex iterator
410 operator vertex_const_iterator() const
411 { return vertex_const_iterator(m_map_iterator); }
412 /// return a pointer to a GenVertex
413 GenVertex* operator*(void) const
414 { return m_map_iterator->second; }
415 /// Pre-fix increment
416 vertex_iterator& operator++(void) //Pre-fix increment
417 { ++m_map_iterator; return *this; }
418 /// Post-fix increment
419 vertex_iterator operator++(int) //Post-fix increment
420 { vertex_iterator out(*this); ++(*this); return out; }
421 /// equality
422 bool operator==( const vertex_iterator& a ) const
423 { return m_map_iterator == a.m_map_iterator; }
424 /// inequality
425 bool operator!=( const vertex_iterator& a ) const
426 { return !(m_map_iterator == a.m_map_iterator); }
427 protected:
428 /// iterator to the vertex map
429 std::map<int,HepMC::GenVertex*,std::greater<int> >::iterator
430 m_map_iterator;
431 private:
432 /// Pre-fix increment
433 vertex_iterator& operator--(void);
434 /// Post-fix increment
435 vertex_iterator operator--(int);
436
437 };
438 friend class vertex_iterator;
439 /// begin vertex iteration
440 vertex_iterator vertices_begin()
441 { return GenEvent::vertex_iterator(
442 m_vertex_barcodes.begin() ); }
443 /// end vertex iteration
444 vertex_iterator vertices_end()
445 { return GenEvent::vertex_iterator(
446 m_vertex_barcodes.end() ); }
447
448 public:
449 ///////////////////////////////
450 // particle_iterator //
451 ///////////////////////////////
452 // Example of iterating over all particles in the event:
453 // for ( GenEvent::particle_const_iterator p = particles_begin();
454 // p != particles_end(); ++p ) {
455 // (*p)->print();
456 // }
457 //
458
459 //! const particle iterator
460
461 /// \class particle_const_iterator
462 /// HepMC::GenEvent::particle_const_iterator
463 /// is used to iterate over all particles in the event.
464 class particle_const_iterator :
465 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
466 // Iterates over all vertices in this event
467 public:
468 /// iterate over particles
469 particle_const_iterator(
470 const std::map<int,HepMC::GenParticle*>::const_iterator& i )
471 : m_map_iterator(i) {}
472 particle_const_iterator() {}
473 /// copy constructor
474 particle_const_iterator( const particle_const_iterator& i )
475 { *this = i; }
476 virtual ~particle_const_iterator() {}
477 /// make a copy
478 particle_const_iterator& operator=(
479 const particle_const_iterator& i )
480 { m_map_iterator = i.m_map_iterator; return *this; }
481 /// return a pointer to GenParticle
482 GenParticle* operator*(void) const
483 { return m_map_iterator->second; }
484 /// Pre-fix increment
485 particle_const_iterator& operator++(void) //Pre-fix increment
486 { ++m_map_iterator; return *this; }
487 /// Post-fix increment
488 particle_const_iterator operator++(int) //Post-fix increment
489 { particle_const_iterator out(*this); ++(*this); return out; }
490 /// equality
491 bool operator==( const particle_const_iterator& a ) const
492 { return m_map_iterator == a.m_map_iterator; }
493 /// inequality
494 bool operator!=( const particle_const_iterator& a ) const
495 { return !(m_map_iterator == a.m_map_iterator); }
496 protected:
497 /// const iterator to the GenParticle map
498 std::map<int,HepMC::GenParticle*>::const_iterator m_map_iterator;
499 private:
500 /// Pre-fix increment
501 particle_const_iterator& operator--(void);
502 /// Post-fix increment
503 particle_const_iterator operator--(int);
504 };
505 friend class particle_const_iterator;
506 /// begin particle iteration
507 particle_const_iterator particles_begin() const
508 { return GenEvent::particle_const_iterator(
509 m_particle_barcodes.begin() ); }
510 /// end particle iteration
511 particle_const_iterator particles_end() const
512 { return GenEvent::particle_const_iterator(
513 m_particle_barcodes.end() ); }
514
515 //! non-const particle iterator
516
517 /// \class particle_iterator
518 /// HepMC::GenEvent::particle_iterator
519 /// is used to iterate over all particles in the event.
520 class particle_iterator :
521 public std::iterator<std::forward_iterator_tag,HepMC::GenParticle*,ptrdiff_t>{
522 // Iterates over all vertices in this event
523 public:
524 /// iterate over particles
525 particle_iterator( const std::map<int,HepMC::GenParticle*>::iterator& i )
526 : m_map_iterator( i ) {}
527 particle_iterator() {}
528 /// copy constructor
529 particle_iterator( const particle_iterator& i ) { *this = i; }
530 virtual ~particle_iterator() {}
531 /// make a copy
532 particle_iterator& operator=( const particle_iterator& i ) {
533 m_map_iterator = i.m_map_iterator;
534 return *this;
535 }
536 /// const particle iterator
537 operator particle_const_iterator() const
538 { return particle_const_iterator(m_map_iterator); }
539 /// return pointer to GenParticle
540 GenParticle* operator*(void) const
541 { return m_map_iterator->second; }
542 /// Pre-fix increment
543 particle_iterator& operator++(void)
544 { ++m_map_iterator; return *this; }
545 /// Post-fix increment
546 particle_iterator operator++(int)
547 { particle_iterator out(*this); ++(*this); return out; }
548 /// equality
549 bool operator==( const particle_iterator& a ) const
550 { return m_map_iterator == a.m_map_iterator; }
551 /// inequality
552 bool operator!=( const particle_iterator& a ) const
553 { return !(m_map_iterator == a.m_map_iterator); }
554 protected:
555 /// iterator for GenParticle map
556 std::map<int,HepMC::GenParticle*>::iterator m_map_iterator;
557 private:
558 /// Pre-fix increment
559 particle_iterator& operator--(void);
560 /// Post-fix increment
561 particle_iterator operator--(int);
562 };
563 friend class particle_iterator;
564 /// begin particle iteration
565 particle_iterator particles_begin()
566 { return GenEvent::particle_iterator(
567 m_particle_barcodes.begin() ); }
568 /// end particle iteration
569 particle_iterator particles_end()
570 { return GenEvent::particle_iterator(
571 m_particle_barcodes.end() ); }
572
573 ////////////////////////////////////////////////
574 protected:
575 //
576 // Following methods intended for use by GenParticle/Vertex classes:
577 // In general there is no reason they should be used elsewhere.
578 /// set the barcode - intended for use by GenParticle
579 bool set_barcode( GenParticle* p, int suggested_barcode =false );
580 /// set the barcode - intended for use by GenVertex
581 bool set_barcode( GenVertex* v, int suggested_barcode =false );
582 /// intended for use by GenParticle
583 void remove_barcode( GenParticle* p );
584 /// intended for use by GenVertex
585 void remove_barcode( GenVertex* v );
586
587 void delete_all_vertices(); //!<delete all vertices owned by this event
588
589 private: // methods
590 /// internal method used when converting momentum units
591 bool use_momentum_unit( Units::MomentumUnit );
592 bool use_momentum_unit( std::string& );
593 /// internal method used when converting length units
594 bool use_length_unit( Units::LengthUnit );
595 bool use_length_unit( std::string& );
596
597 // the following internal methods are used by read() and write()
598
599 /// send the beam particles to ASCII output
600 std::ostream & write_beam_particles( std::ostream &,
601 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
602 /// send a GenVertex to ASCII output
603 std::ostream & write_vertex( std::ostream &, GenVertex const * );
604 /// send a GenParticle to ASCII output
605 std::ostream & write_particle( std::ostream&, GenParticle const * );
606 /// find the file type
607 std::istream & find_file_type( std::istream & );
608 /// find the key at the end of the block
609 std::istream & find_end_key( std::istream &, int & );
610 /// get unit information from ASCII input
611 std::istream & read_units( std::istream & );
612 /// get weight names from ASCII input
613 std::istream & read_weight_names( std::istream & );
614 /// read the event header line
615 std::istream & process_event_line( std::istream &, int &, int &, int &, int & );
616
617 private: // data members
618 int m_signal_process_id;
619 int m_event_number;
620 int m_mpi; // number of multi paricle interactions
621 double m_event_scale;// energy scale, see hep-ph/0109068
622 double m_alphaQCD; // QCD coupling, see hep-ph/0109068
623 double m_alphaQED; // QED coupling, see hep-ph/0109068
624 GenVertex* m_signal_process_vertex;
625 GenParticle* m_beam_particle_1;
626 GenParticle* m_beam_particle_2;
627 WeightContainer m_weights; // weights for this event first weight
628 // is used by default for hit and miss
629 std::vector<long> m_random_states; // container of rndm num
630 // generator states
631
632 std::map< int,HepMC::GenVertex*,std::greater<int> > m_vertex_barcodes;
633 std::map< int,HepMC::GenParticle*,std::less<int> > m_particle_barcodes;
634 GenCrossSection* m_cross_section; // undefined by default
635 HeavyIon* m_heavy_ion; // undefined by default
636 PdfInfo* m_pdf_info; // undefined by default
637 Units::MomentumUnit m_momentum_unit; // default value set by configure switch
638 Units::LengthUnit m_position_unit; // default value set by configure switch
639
640 };
641
642
643 ///////////////////////////
644 // IO Free Functions //
645 ///////////////////////////
646
647 /// standard streaming IO output operator
648 std::ostream & operator << (std::ostream &, GenEvent &);
649 /// standard streaming IO input operator
650 std::istream & operator >> (std::istream &, GenEvent &);
651 /// set the units for this input stream
652 std::istream & set_input_units(std::istream &,
653 Units::MomentumUnit, Units::LengthUnit);
654 /// Explicitly write the begin block lines that IO_GenEvent uses
655 std::ostream & write_HepMC_IO_block_begin(std::ostream & );
656 /// Explicitly write the end block line that IO_GenEvent uses
657 std::ostream & write_HepMC_IO_block_end(std::ostream & );
658
659
660 ///////////////////////////
661 // INLINE Free Functions //
662 ///////////////////////////
663
664 // Implemented in terms of GenEvent::use_...
665 inline GenEvent& convert_units(GenEvent & evt, Units::MomentumUnit m, Units::LengthUnit l)
666 {
667 evt.use_units(m, l);
668 return evt;
669 }
670
671 ///////////////////////////
672 // INLINE Access Methods //
673 ///////////////////////////
674
675 /// The integer ID that uniquely specifies this signal
676 /// process, i.e. MSUB in Pythia. It is necessary to
677 /// package this with each event rather than with the run
678 /// because many processes may be generated within one run.
679 inline int GenEvent::signal_process_id() const
680 { return m_signal_process_id; }
681
682 inline int GenEvent::event_number() const { return m_event_number; }
683
684 /// Returns the number of multi parton interactions in the event.
685 /// This number is -1 if it is not set.
686 inline int GenEvent::mpi() const { return m_mpi; }
687
688 inline double GenEvent::event_scale() const { return m_event_scale; }
689
690 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
691
692 inline double GenEvent::alphaQED() const { return m_alphaQED; }
693
694 inline GenVertex* GenEvent::signal_process_vertex() const {
695 /// returns a (mutable) pointer to the signal process vertex
696 return m_signal_process_vertex;
697 }
698
699 inline WeightContainer& GenEvent::weights() { return m_weights; }
700
701 inline const WeightContainer& GenEvent::weights() const
702 { return m_weights; }
703
704 inline GenCrossSection const * GenEvent::cross_section() const
705 { return m_cross_section; }
706
707 inline GenCrossSection* GenEvent::cross_section()
708 { return m_cross_section; }
709
710 inline HeavyIon const * GenEvent::heavy_ion() const
711 { return m_heavy_ion; }
712
713 inline HeavyIon* GenEvent::heavy_ion()
714 { return m_heavy_ion; }
715
716 inline PdfInfo const * GenEvent::pdf_info() const
717 { return m_pdf_info; }
718
719 inline PdfInfo* GenEvent::pdf_info()
720 { return m_pdf_info; }
721
722 /// Vector of integers which specify the random number
723 /// generator's state for this event. It is left to the
724 /// generator to make use of this. We envision a vector of
725 /// RndmStatesTags to be included with a run class which
726 /// would specify the meaning of the random_states.
727 inline const std::vector<long>& GenEvent::random_states() const
728 { return m_random_states; }
729
730 inline void GenEvent::set_signal_process_id( int id )
731 { m_signal_process_id = id; }
732
733 inline void GenEvent::set_event_number( int eventno )
734 { m_event_number = eventno; }
735
736 /// Use this to set the number of multi parton interactions in each event.
737 inline void GenEvent::set_mpi( int nmpi )
738 { m_mpi = nmpi; }
739
740
741 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
742
743 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
744
745 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
746
747 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
748 m_signal_process_vertex = vtx;
749 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
750 }
751
752 inline void GenEvent::set_cross_section( const GenCrossSection& xs )
753 {
754 delete m_cross_section;
755 m_cross_section = new GenCrossSection(xs);
756 }
757
758 inline void GenEvent::set_heavy_ion( const HeavyIon& ion )
759 {
760 delete m_heavy_ion;
761 m_heavy_ion = new HeavyIon(ion);
762 }
763
764 inline void GenEvent::set_pdf_info( const PdfInfo& p )
765 {
766 delete m_pdf_info;
767 m_pdf_info = new PdfInfo(p);
768 }
769
770 inline void GenEvent::set_random_states( const std::vector<long>&
771 randomstates )
772 { m_random_states = randomstates; }
773
774 inline void GenEvent::remove_barcode( GenParticle* p )
775 { m_particle_barcodes.erase( p->barcode() ); }
776
777 inline void GenEvent::remove_barcode( GenVertex* v )
778 { m_vertex_barcodes.erase( v->barcode() ); }
779
780 /// Each vertex or particle has a barcode, which is just an integer which
781 /// uniquely identifies it inside the event (i.e. there is a one to one
782 /// mapping between particle memory addresses and particle barcodes... and
783 /// the same applied for vertices).
784 ///
785 /// The value of a barcode has NO MEANING and NO ORDER!
786 /// For the user's convenience, when an event is read in via an IO_method
787 /// from an indexed list (like the HEPEVT common block), then the index will
788 /// become the barcode for that particle.
789 ///
790 /// Particle barcodes are always positive integers.
791 /// The barcodes are chosen and set automatically when a vertex or particle
792 /// comes under the ownership of an event (i.e. it is contained in an event).
793 ///
794 /// Please note that the barcodes are intended for internal use within
795 /// HepMC as a unique identifier for the particles and vertices.
796 /// Using the barcode to encode extra information is an abuse of
797 /// the barcode data member and causes confusion among users.
798 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
799 {
800 std::map<int,HepMC::GenParticle*>::const_iterator i
801 = m_particle_barcodes.find(barCode);
802 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
803 }
804
805 /// Each vertex or particle has a barcode, which is just an integer which
806 /// uniquely identifies it inside the event (i.e. there is a one to one
807 /// mapping between particle memory addresses and particle barcodes... and
808 /// the same applied for vertices).
809 ///
810 /// The value of a barcode has NO MEANING and NO ORDER!
811 /// For the user's convenience, when an event is read in via an IO_method
812 /// from an indexed list (like the HEPEVT common block), then the index will
813 /// become the barcode for that particle.
814 ///
815 /// Vertex barcodes are always negative integers.
816 /// The barcodes are chosen and set automatically when a vertex or particle
817 /// comes under the ownership of an event (i.e. it is contained in an event).
818 ///
819 /// Please note that the barcodes are intended for internal use within
820 /// HepMC as a unique identifier for the particles and vertices.
821 /// Using the barcode to encode extra information is an abuse of
822 /// the barcode data member and causes confusion among users.
823 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
824 {
825 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
826 = m_vertex_barcodes.find(barCode);
827 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
828 }
829
830 inline int GenEvent::particles_size() const {
831 return (int)m_particle_barcodes.size();
832 }
833 inline bool GenEvent::particles_empty() const {
834 return (bool)m_particle_barcodes.empty();
835 }
836 inline int GenEvent::vertices_size() const {
837 return (int)m_vertex_barcodes.size();
838 }
839 inline bool GenEvent::vertices_empty() const {
840 return (bool)m_vertex_barcodes.empty();
841 }
842
843 // beam particles
844 inline std::pair<HepMC::GenParticle *,HepMC::GenParticle *> GenEvent::beam_particles() const {
845 return std::pair<GenParticle *,GenParticle *> (m_beam_particle_1, m_beam_particle_2);
846 }
847
848 // units
849 inline Units::MomentumUnit GenEvent::momentum_unit() const {
850 return m_momentum_unit;
851 }
852 inline Units::LengthUnit GenEvent::length_unit() const {
853 return m_position_unit;
854 }
855
856 inline void GenEvent::use_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
857 use_momentum_unit( new_m );
858 use_length_unit( new_l );
859 }
860
861 inline void GenEvent::use_units( std::string& new_m, std::string& new_l ) {
862 use_momentum_unit( new_m );
863 use_length_unit( new_l );
864 }
865
866 inline void GenEvent::define_units( Units::MomentumUnit new_m, Units::LengthUnit new_l ) {
867 m_momentum_unit = new_m;
868 m_position_unit = new_l;
869 }
870
871} // HepMC
872
873#endif // HEPMC_GEN_EVENT_H
874
875//--------------------------------------------------------------------------
876
877