00001
00002 #ifndef HEPMC_GEN_EVENT_H
00003 #define HEPMC_GEN_EVENT_H
00004
00006
00007
00008
00009
00010
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024
00025
00026
00027
00029
00030 namespace HepMC {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 template <class InputIterator, class OutputIterator, class Predicate>
00050 void copy_if( InputIterator first, InputIterator last, OutputIterator out,
00051 Predicate pred ) {
00052 for ( ; first != last; ++first ) { if ( pred(*first) ) out = *first; }
00053 }
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00088
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00101
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 #include "CLHEP/HepMC/GenVertex.h"
00121 #include "CLHEP/HepMC/GenParticle.h"
00122 #include "CLHEP/HepMC/WeightContainer.h"
00123 #include <map>
00124 #include <vector>
00125 #include <algorithm>
00126 #include "CLHEP/config/CLHEP.h"
00127 #include "CLHEP/config/iostream.h"
00128
00129 namespace HepMC {
00130
00135 class GenEvent {
00136 friend class GenParticle;
00137 friend class GenVertex;
00138 public:
00139
00140 #if defined __GNUG__ && ( __GNUG__ < 3 )
00141 typedef std::forward_iterator<GenVertex*,ptrdiff_t> forwardVertexIterType;
00142 typedef std::forward_iterator<GenParticle*,ptrdiff_t> forwardParticleIterType;
00143 #else
00144 typedef std::iterator<std::forward_iterator_tag,GenVertex*,ptrdiff_t> forwardVertexIterType;
00145 typedef std::iterator<std::forward_iterator_tag,GenParticle*,ptrdiff_t> forwardParticleIterType;
00146 #endif
00147
00148 GenEvent( int signal_process_id = 0, int event_number = 0,
00149 GenVertex* signal_vertex = 0,
00150 const WeightContainer& weights = std::vector<double>(),
00151 const std::vector<double>& randomstates
00152 = std::vector<double>() );
00153 GenEvent( const GenEvent& inevent );
00154 GenEvent& operator=( const GenEvent& inevent );
00155 virtual ~GenEvent();
00156
00157 void print( std::ostream& ostr = std::cout ) const;
00158
00159 GenParticle* barcode_to_particle( int barCode ) const;
00160 GenVertex* barcode_to_vertex( int barCode ) const;
00161
00163
00165
00166 int signal_process_id() const;
00167 int event_number() const;
00168 double event_scale() const;
00169 double alphaQCD() const;
00170 double alphaQED() const;
00171 GenVertex* signal_process_vertex() const;
00172
00173
00174
00175
00176
00177
00178 WeightContainer& weights();
00179 const WeightContainer& weights() const;
00180
00181 std::vector<double> random_states() const;
00182 double random_states( int i ) const;
00183
00184 void set_signal_process_id( int id );
00185 void set_event_number( int eventno );
00186 void set_event_scale( double scale );
00187 void set_alphaQCD( double a );
00188 void set_alphaQED( double a );
00189 void set_signal_process_vertex( GenVertex* );
00190 void set_random_states( const std::vector<double>& randomstates );
00191
00192 int particles_size() const;
00193 bool particles_empty() const;
00194 int vertices_size() const;
00195 bool vertices_empty() const;
00196
00197 bool add_vertex( GenVertex* vtx );
00198 bool remove_vertex( GenVertex* vtx );
00199
00200 GenParticle* particle( int i ) const { return barcode_to_particle(i); }
00201
00202 public:
00204
00206
00207
00208
00209 class vertex_const_iterator :
00210 public forwardVertexIterType {
00211
00212 public:
00213 vertex_const_iterator(
00214 const
00215 std::map<int,GenVertex*,std::greater<int> >::const_iterator& i)
00216 : m_map_iterator(i) {}
00217 vertex_const_iterator() {}
00218 vertex_const_iterator( const vertex_const_iterator& i )
00219 { *this = i; }
00220 virtual ~vertex_const_iterator() {}
00221 vertex_const_iterator& operator=( const vertex_const_iterator& i )
00222 { m_map_iterator = i.m_map_iterator; return *this; }
00223 GenVertex* operator*(void) const { return m_map_iterator->second; }
00224 vertex_const_iterator& operator++(void)
00225 { ++m_map_iterator; return *this; }
00226 vertex_const_iterator operator++(int)
00227 { vertex_const_iterator out(*this); ++(*this); return out; }
00228 bool operator==( const vertex_const_iterator& a ) const
00229 { return m_map_iterator == a.m_map_iterator; }
00230 bool operator!=( const vertex_const_iterator& a ) const
00231 { return !(m_map_iterator == a.m_map_iterator); }
00232 protected:
00233 std::map<int,GenVertex*,std::greater<int> >::const_iterator
00234 m_map_iterator;
00235 };
00236 friend class vertex_const_iterator;
00237 vertex_const_iterator vertices_begin() const
00238 { return GenEvent::vertex_const_iterator(
00239 m_vertex_barcodes.begin() ); }
00240 vertex_const_iterator vertices_end() const
00241 { return GenEvent::vertex_const_iterator(
00242 m_vertex_barcodes.end() ); }
00243
00244 class vertex_iterator :
00245 public forwardVertexIterType {
00246
00247 public:
00248 vertex_iterator(
00249 const
00250 std::map<int,GenVertex*,std::greater<int> >::iterator& i )
00251 : m_map_iterator( i ) {}
00252 vertex_iterator() {}
00253 vertex_iterator( const vertex_iterator& i ) { *this = i; }
00254 virtual ~vertex_iterator() {}
00255 vertex_iterator& operator=( const vertex_iterator& i ) {
00256 m_map_iterator = i.m_map_iterator;
00257 return *this;
00258 }
00259 operator vertex_const_iterator() const
00260 { return vertex_const_iterator(m_map_iterator); }
00261 GenVertex* operator*(void) const
00262 { return m_map_iterator->second; }
00263 vertex_iterator& operator++(void)
00264 { ++m_map_iterator; return *this; }
00265 vertex_iterator operator++(int)
00266 { vertex_iterator out(*this); ++(*this); return out; }
00267 bool operator==( const vertex_iterator& a ) const
00268 { return m_map_iterator == a.m_map_iterator; }
00269 bool operator!=( const vertex_iterator& a ) const
00270 { return !(m_map_iterator == a.m_map_iterator); }
00271 protected:
00272 std::map<int,GenVertex*,std::greater<int> >::iterator
00273 m_map_iterator;
00274 };
00275 friend class vertex_iterator;
00276 vertex_iterator vertices_begin()
00277 { return GenEvent::vertex_iterator(
00278 m_vertex_barcodes.begin() ); }
00279 vertex_iterator vertices_end()
00280 { return GenEvent::vertex_iterator(
00281 m_vertex_barcodes.end() ); }
00282
00283 public:
00285
00287
00288
00289
00290
00291
00292
00293 class particle_const_iterator :
00294 public forwardParticleIterType {
00295
00296 public:
00297 particle_const_iterator(
00298 const std::map<int,GenParticle*>::const_iterator& i )
00299 : m_map_iterator(i) {}
00300 particle_const_iterator() {}
00301 particle_const_iterator( const particle_const_iterator& i )
00302 { *this = i; }
00303 virtual ~particle_const_iterator() {}
00304 particle_const_iterator& operator=(
00305 const particle_const_iterator& i )
00306 { m_map_iterator = i.m_map_iterator; return *this; }
00307 GenParticle* operator*(void) const
00308 { return m_map_iterator->second; }
00309 particle_const_iterator& operator++(void)
00310 { ++m_map_iterator; return *this; }
00311 particle_const_iterator operator++(int)
00312 { particle_const_iterator out(*this); ++(*this); return out; }
00313 bool operator==( const particle_const_iterator& a ) const
00314 { return m_map_iterator == a.m_map_iterator; }
00315 bool operator!=( const particle_const_iterator& a ) const
00316 { return !(m_map_iterator == a.m_map_iterator); }
00317 protected:
00318 std::map<int,GenParticle*>::const_iterator m_map_iterator;
00319 };
00320 friend class particle_const_iterator;
00321 particle_const_iterator particles_begin() const
00322 { return GenEvent::particle_const_iterator(
00323 m_particle_barcodes.begin() ); }
00324 particle_const_iterator particles_end() const
00325 { return GenEvent::particle_const_iterator(
00326 m_particle_barcodes.end() ); }
00327
00328 class particle_iterator :
00329 public forwardParticleIterType {
00330
00331 public:
00332 particle_iterator( const std::map<int,GenParticle*>::iterator& i )
00333 : m_map_iterator( i ) {}
00334 particle_iterator() {}
00335 particle_iterator( const particle_iterator& i ) { *this = i; }
00336 virtual ~particle_iterator() {}
00337 particle_iterator& operator=( const particle_iterator& i ) {
00338 m_map_iterator = i.m_map_iterator;
00339 return *this;
00340 }
00341 operator particle_const_iterator() const
00342 { return particle_const_iterator(m_map_iterator); }
00343 GenParticle* operator*(void) const
00344 { return m_map_iterator->second; }
00345 particle_iterator& operator++(void)
00346 { ++m_map_iterator; return *this; }
00347 particle_iterator operator++(int)
00348 { particle_iterator out(*this); ++(*this); return out; }
00349 bool operator==( const particle_iterator& a ) const
00350 { return m_map_iterator == a.m_map_iterator; }
00351 bool operator!=( const particle_iterator& a ) const
00352 { return !(m_map_iterator == a.m_map_iterator); }
00353 protected:
00354 std::map<int,GenParticle*>::iterator m_map_iterator;
00355 };
00356 friend class particle_iterator;
00357 particle_iterator particles_begin()
00358 { return GenEvent::particle_iterator(
00359 m_particle_barcodes.begin() ); }
00360 particle_iterator particles_end()
00361 { return GenEvent::particle_iterator(
00362 m_particle_barcodes.end() ); }
00363
00365 protected:
00366
00367
00368
00369 bool set_barcode( GenParticle* p, int suggested_barcode =0 );
00370 bool set_barcode( GenVertex* v, int suggested_barcode =0 );
00371 void remove_barcode( GenParticle* p );
00372 void remove_barcode( GenVertex* v );
00373
00374 static unsigned int counter();
00375 void delete_all_vertices();
00376
00377 private:
00378 int m_signal_process_id;
00379 int m_event_number;
00380 double m_event_scale;
00381 double m_alphaQCD;
00382 double m_alphaQED;
00383 GenVertex* m_signal_process_vertex;
00384 WeightContainer m_weights;
00385
00386 std::vector<double> m_random_states;
00387
00388
00389 std::map< int,GenVertex*,std::greater<int> > m_vertex_barcodes;
00390 std::map< int,GenParticle*,std::less<int> > m_particle_barcodes;
00391
00392 static unsigned int s_counter;
00393 };
00394
00396
00398
00399 inline int GenEvent::signal_process_id() const
00400 { return m_signal_process_id; }
00401
00402 inline int GenEvent::event_number() const { return m_event_number; }
00403
00404 inline double GenEvent::event_scale() const { return m_event_scale; }
00405
00406 inline double GenEvent::alphaQCD() const { return m_alphaQCD; }
00407
00408 inline double GenEvent::alphaQED() const { return m_alphaQED; }
00409
00410 inline GenVertex* GenEvent::signal_process_vertex() const {
00411
00412 return m_signal_process_vertex;
00413 }
00414
00415 inline WeightContainer& GenEvent::weights() { return m_weights; }
00416
00417 inline const WeightContainer& GenEvent::weights() const
00418 { return m_weights; }
00419
00420 inline std::vector<double> GenEvent::random_states() const
00421 { return m_random_states; }
00422
00423 inline double GenEvent::random_states( int i ) const
00424 { return m_random_states[i]; }
00425
00426 inline void GenEvent::set_signal_process_id( int id )
00427 { m_signal_process_id = id; }
00428
00429 inline void GenEvent::set_event_number( int eventno )
00430 { m_event_number = eventno; }
00431
00432
00433 inline void GenEvent::set_event_scale( double sc ) { m_event_scale = sc; }
00434
00435 inline void GenEvent::set_alphaQCD( double a ) { m_alphaQCD = a; }
00436
00437 inline void GenEvent::set_alphaQED( double a ) { m_alphaQED = a; }
00438
00439 inline void GenEvent::set_signal_process_vertex( GenVertex* vtx ) {
00440 m_signal_process_vertex = vtx;
00441 if ( m_signal_process_vertex ) add_vertex( m_signal_process_vertex );
00442 }
00443
00444 inline void GenEvent::set_random_states( const std::vector<double>&
00445 randomstates )
00446 { m_random_states = randomstates; }
00447
00448 inline void GenEvent::remove_barcode( GenParticle* p )
00449 { m_particle_barcodes.erase( p->barcode() ); }
00450
00451 inline void GenEvent::remove_barcode( GenVertex* v )
00452 { m_vertex_barcodes.erase( v->barcode() ); }
00453
00454 inline GenParticle* GenEvent::barcode_to_particle( int barCode ) const
00455 {
00456 std::map<int,GenParticle*>::const_iterator i
00457 = m_particle_barcodes.find(barCode);
00458 return ( i != m_particle_barcodes.end() ) ? (*i).second : 0;
00459 }
00460
00461 inline GenVertex* GenEvent::barcode_to_vertex( int barCode ) const
00462 {
00463 std::map<int,GenVertex*,std::greater<int> >::const_iterator i
00464 = m_vertex_barcodes.find(barCode);
00465 return ( i != m_vertex_barcodes.end() ) ? (*i).second : 0;
00466 }
00467
00468 inline int GenEvent::particles_size() const {
00469 return (int)m_particle_barcodes.size();
00470 }
00471 inline bool GenEvent::particles_empty() const {
00472 return (bool)m_particle_barcodes.empty();
00473 }
00474 inline int GenEvent::vertices_size() const {
00475 return (int)m_vertex_barcodes.size();
00476 }
00477 inline bool GenEvent::vertices_empty() const {
00478 return (bool)m_vertex_barcodes.empty();
00479 }
00480
00481 }
00482
00483 #endif // HEPMC_GEN_EVENT_H
00484
00485
00486
00487