00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include <iomanip>
00014
00015 #include "HepMC/GenEvent.h"
00016 #include "HepMC/GenCrossSection.h"
00017 #include "HepMC/Version.h"
00018 #include "HepMC/StreamHelpers.h"
00019
00020 namespace HepMC {
00021
00022 GenEvent::GenEvent( int signal_process_id,
00023 int event_number,
00024 GenVertex* signal_vertex,
00025 const WeightContainer& weights,
00026 const std::vector<long>& random_states,
00027 Units::MomentumUnit mom,
00028 Units::LengthUnit len ) :
00029 m_signal_process_id(signal_process_id),
00030 m_event_number(event_number),
00031 m_mpi(-1),
00032 m_event_scale(-1),
00033 m_alphaQCD(-1),
00034 m_alphaQED(-1),
00035 m_signal_process_vertex(signal_vertex),
00036 m_beam_particle_1(0),
00037 m_beam_particle_2(0),
00038 m_weights(weights),
00039 m_random_states(random_states),
00040 m_vertex_barcodes(),
00041 m_particle_barcodes(),
00042 m_cross_section(0),
00043 m_heavy_ion(0),
00044 m_pdf_info(0),
00045 m_momentum_unit(mom),
00046 m_position_unit(len)
00047 {
00053 }
00054
00055 GenEvent::GenEvent( int signal_process_id, int event_number,
00056 GenVertex* signal_vertex,
00057 const WeightContainer& weights,
00058 const std::vector<long>& random_states,
00059 const HeavyIon& ion,
00060 const PdfInfo& pdf,
00061 Units::MomentumUnit mom,
00062 Units::LengthUnit len ) :
00063 m_signal_process_id(signal_process_id),
00064 m_event_number(event_number),
00065 m_mpi(-1),
00066 m_event_scale(-1),
00067 m_alphaQCD(-1),
00068 m_alphaQED(-1),
00069 m_signal_process_vertex(signal_vertex),
00070 m_beam_particle_1(0),
00071 m_beam_particle_2(0),
00072 m_weights(weights),
00073 m_random_states(random_states),
00074 m_vertex_barcodes(),
00075 m_particle_barcodes(),
00076 m_cross_section(0),
00077 m_heavy_ion( new HeavyIon(ion) ),
00078 m_pdf_info( new PdfInfo(pdf) ),
00079 m_momentum_unit(mom),
00080 m_position_unit(len)
00081 {
00086 }
00087
00088 GenEvent::GenEvent( Units::MomentumUnit mom,
00089 Units::LengthUnit len,
00090 int signal_process_id,
00091 int event_number,
00092 GenVertex* signal_vertex,
00093 const WeightContainer& weights,
00094 const std::vector<long>& random_states ) :
00095 m_signal_process_id(signal_process_id),
00096 m_event_number(event_number),
00097 m_mpi(-1),
00098 m_event_scale(-1),
00099 m_alphaQCD(-1),
00100 m_alphaQED(-1),
00101 m_signal_process_vertex(signal_vertex),
00102 m_beam_particle_1(0),
00103 m_beam_particle_2(0),
00104 m_weights(weights),
00105 m_random_states(random_states),
00106 m_vertex_barcodes(),
00107 m_particle_barcodes(),
00108 m_cross_section(0),
00109 m_heavy_ion(0),
00110 m_pdf_info(0),
00111 m_momentum_unit(mom),
00112 m_position_unit(len)
00113 {
00120 }
00121
00122 GenEvent::GenEvent( Units::MomentumUnit mom,
00123 Units::LengthUnit len,
00124 int signal_process_id, int event_number,
00125 GenVertex* signal_vertex,
00126 const WeightContainer& weights,
00127 const std::vector<long>& random_states,
00128 const HeavyIon& ion,
00129 const PdfInfo& pdf ) :
00130 m_signal_process_id(signal_process_id),
00131 m_event_number(event_number),
00132 m_mpi(-1),
00133 m_event_scale(-1),
00134 m_alphaQCD(-1),
00135 m_alphaQED(-1),
00136 m_signal_process_vertex(signal_vertex),
00137 m_beam_particle_1(0),
00138 m_beam_particle_2(0),
00139 m_weights(weights),
00140 m_random_states(random_states),
00141 m_vertex_barcodes(),
00142 m_particle_barcodes(),
00143 m_cross_section(0),
00144 m_heavy_ion( new HeavyIon(ion) ),
00145 m_pdf_info( new PdfInfo(pdf) ),
00146 m_momentum_unit(mom),
00147 m_position_unit(len)
00148 {
00154 }
00155
00156 GenEvent::GenEvent( const GenEvent& inevent )
00157 : m_signal_process_id ( inevent.signal_process_id() ),
00158 m_event_number ( inevent.event_number() ),
00159 m_mpi ( inevent.mpi() ),
00160 m_event_scale ( inevent.event_scale() ),
00161 m_alphaQCD ( inevent.alphaQCD() ),
00162 m_alphaQED ( inevent.alphaQED() ),
00163 m_signal_process_vertex( ),
00164 m_beam_particle_1 ( ),
00165 m_beam_particle_2 ( ),
00166 m_weights ( ),
00167 m_random_states ( ),
00168 m_vertex_barcodes ( ),
00169 m_particle_barcodes ( ),
00170 m_cross_section ( inevent.cross_section() ? new GenCrossSection(*inevent.cross_section()) : 0 ),
00171 m_heavy_ion ( inevent.heavy_ion() ? new HeavyIon(*inevent.heavy_ion()) : 0 ),
00172 m_pdf_info ( inevent.pdf_info() ? new PdfInfo(*inevent.pdf_info()) : 0 ),
00173 m_momentum_unit ( inevent.momentum_unit() ),
00174 m_position_unit ( inevent.length_unit() )
00175 {
00177
00178
00179
00180
00181
00182
00183
00184 std::map<const GenVertex*,GenVertex*> map_in_to_new;
00185 for ( GenEvent::vertex_const_iterator v = inevent.vertices_begin();
00186 v != inevent.vertices_end(); ++v ) {
00187 GenVertex* newvertex = new GenVertex(
00188 (*v)->position(), (*v)->id(), (*v)->weights() );
00189 newvertex->suggest_barcode( (*v)->barcode() );
00190 map_in_to_new[*v] = newvertex;
00191 add_vertex( newvertex );
00192 }
00193
00194 if ( inevent.signal_process_vertex() ) {
00195 set_signal_process_vertex(
00196 map_in_to_new[inevent.signal_process_vertex()] );
00197 } else set_signal_process_vertex( 0 );
00198
00199
00200
00201 GenParticle* beam1(0);
00202 GenParticle* beam2(0);
00203 for ( GenEvent::particle_const_iterator p = inevent.particles_begin();
00204 p != inevent.particles_end(); ++p )
00205 {
00206 GenParticle* oldparticle = *p;
00207 GenParticle* newparticle = new GenParticle(*oldparticle);
00208 if ( oldparticle->end_vertex() ) {
00209 map_in_to_new[ oldparticle->end_vertex() ]->
00210 add_particle_in(newparticle);
00211 }
00212 if ( oldparticle->production_vertex() ) {
00213 map_in_to_new[ oldparticle->production_vertex() ]->
00214 add_particle_out(newparticle);
00215 }
00216 if ( oldparticle == inevent.beam_particles().first ) beam1 = newparticle;
00217 if ( oldparticle == inevent.beam_particles().second ) beam2 = newparticle;
00218 }
00219 set_beam_particles( beam1, beam2 );
00220
00221
00222 set_random_states( inevent.random_states() );
00223 weights() = inevent.weights();
00224 }
00225
00226 void GenEvent::swap( GenEvent & other )
00227 {
00228
00229 std::swap(m_signal_process_id , other.m_signal_process_id );
00230 std::swap(m_event_number , other.m_event_number );
00231 std::swap(m_mpi , other.m_mpi );
00232 std::swap(m_event_scale , other.m_event_scale );
00233 std::swap(m_alphaQCD , other.m_alphaQCD );
00234 std::swap(m_alphaQED , other.m_alphaQED );
00235 std::swap(m_signal_process_vertex, other.m_signal_process_vertex);
00236 std::swap(m_beam_particle_1 , other.m_beam_particle_1 );
00237 std::swap(m_beam_particle_2 , other.m_beam_particle_2 );
00238 m_weights.swap( other.m_weights );
00239 m_random_states.swap( other.m_random_states );
00240 m_vertex_barcodes.swap( other.m_vertex_barcodes );
00241 m_particle_barcodes.swap( other.m_particle_barcodes );
00242 std::swap(m_cross_section , other.m_cross_section );
00243 std::swap(m_heavy_ion , other.m_heavy_ion );
00244 std::swap(m_pdf_info , other.m_pdf_info );
00245 std::swap(m_momentum_unit , other.m_momentum_unit );
00246 std::swap(m_position_unit , other.m_position_unit );
00247
00248 for ( GenEvent::vertex_const_iterator vthis = vertices_begin();
00249 vthis != vertices_end(); ++vthis ) {
00250 (*vthis)->change_parent_event_( this );
00251 }
00252 for ( GenEvent::vertex_const_iterator voth = other.vertices_begin();
00253 voth != other.vertices_end(); ++voth ) {
00254 (*voth)->change_parent_event_( &other );
00255 }
00256 }
00257
00258 GenEvent::~GenEvent()
00259 {
00263 delete_all_vertices();
00264 delete m_cross_section;
00265 delete m_heavy_ion;
00266 delete m_pdf_info;
00267 }
00268
00269 GenEvent& GenEvent::operator=( const GenEvent& inevent )
00270 {
00272 GenEvent tmp( inevent );
00273 swap( tmp );
00274 return *this;
00275 }
00276
00277 void GenEvent::print( std::ostream& ostr ) const {
00282 ostr << "________________________________________"
00283 << "________________________________________\n";
00284 ostr << "GenEvent: #" << event_number()
00285 << " ID=" << signal_process_id()
00286 << " SignalProcessGenVertex Barcode: "
00287 << ( signal_process_vertex() ? signal_process_vertex()->barcode()
00288 : 0 )
00289 << "\n";
00290 write_units( ostr );
00291 ostr << " Entries this event: " << vertices_size() << " vertices, "
00292 << particles_size() << " particles.\n";
00293 if( m_beam_particle_1 && m_beam_particle_2 ) {
00294 ostr << " Beam Particle barcodes: " << beam_particles().first->barcode() << " "
00295 << beam_particles().second->barcode() << " \n";
00296 } else {
00297 ostr << " Beam Particles are not defined.\n";
00298 }
00299
00300 ostr << " RndmState(" << m_random_states.size() << ")=";
00301 for ( std::vector<long>::const_iterator rs
00302 = m_random_states.begin();
00303 rs != m_random_states.end(); ++rs ) { ostr << *rs << " "; }
00304 ostr << "\n";
00305
00306 ostr << " Wgts(" << weights().size() << ")=";
00307 for ( WeightContainer::const_iterator wgt = weights().begin();
00308 wgt != weights().end(); ++wgt ) { ostr << *wgt << " "; }
00309 ostr << "\n";
00310 ostr << " EventScale " << event_scale()
00311 << " [energy] \t alphaQCD=" << alphaQCD()
00312 << "\t alphaQED=" << alphaQED() << std::endl;
00313
00314 ostr << " GenParticle Legend\n";
00315 ostr << " Barcode PDG ID "
00316 << "( Px, Py, Pz, E )"
00317 << " Stat DecayVtx\n";
00318 ostr << "________________________________________"
00319 << "________________________________________\n";
00320
00321 for ( GenEvent::vertex_const_iterator vtx = this->vertices_begin();
00322 vtx != this->vertices_end(); ++vtx ) {
00323 (*vtx)->print(ostr);
00324 }
00325 ostr << "________________________________________"
00326 << "________________________________________" << std::endl;
00327 }
00328
00329 void GenEvent::print_version( std::ostream& ostr ) const {
00330 ostr << "---------------------------------------------" << std::endl;
00331 writeVersion( ostr );
00332 ostr << "---------------------------------------------" << std::endl;
00333 }
00334
00335 bool GenEvent::add_vertex( GenVertex* vtx ) {
00338 if ( !vtx ) return false;
00339
00340
00341 if ( vtx->parent_event() && vtx->parent_event() != this ) {
00342 bool remove_status = vtx->parent_event()->remove_vertex( vtx );
00343 if ( !remove_status ) {
00344 std::cerr << "GenEvent::add_vertex ERROR "
00345 << "GenVertex::parent_event points to \n"
00346 << "an event that does not point back to the "
00347 << "GenVertex. \n This probably indicates a deeper "
00348 << "problem. " << std::endl;
00349 }
00350 }
00351
00352
00353
00354 vtx->set_parent_event_( this );
00355 return ( m_vertex_barcodes.count(vtx->barcode()) ? true : false );
00356 }
00357
00358 bool GenEvent::remove_vertex( GenVertex* vtx ) {
00361 if ( m_signal_process_vertex == vtx ) m_signal_process_vertex = 0;
00362 if ( vtx->parent_event() == this ) vtx->set_parent_event_( 0 );
00363 return ( m_vertex_barcodes.count(vtx->barcode()) ? false : true );
00364 }
00365
00366 void GenEvent::clear()
00367 {
00371 delete_all_vertices();
00372
00373 delete m_cross_section;
00374 m_cross_section = 0;
00375 delete m_heavy_ion;
00376 m_heavy_ion = 0;
00377 delete m_pdf_info;
00378 m_pdf_info = 0;
00379 m_signal_process_id = 0;
00380 m_beam_particle_1 = 0;
00381 m_beam_particle_2 = 0;
00382 m_event_number = 0;
00383 m_mpi = -1;
00384 m_event_scale = -1;
00385 m_alphaQCD = -1;
00386 m_alphaQED = -1;
00387 m_weights = std::vector<double>();
00388 m_random_states = std::vector<long>();
00389
00390 m_momentum_unit = Units::default_momentum_unit();
00391 m_position_unit = Units::default_length_unit();
00392
00393 if ( m_vertex_barcodes.size() != 0
00394 || m_particle_barcodes.size() != 0 ) {
00395 std::cerr << "GenEvent::clear() strange result ... \n"
00396 << "either the particle and/or the vertex map isn't empty" << std::endl;
00397 std::cerr << "Number vtx,particle the event after deleting = "
00398 << m_vertex_barcodes.size() << " "
00399 << m_particle_barcodes.size() << std::endl;
00400 }
00401 return;
00402 }
00403
00404 void GenEvent::delete_all_vertices() {
00410
00411
00412 while ( !vertices_empty() ) {
00413 GenVertex* vtx = ( m_vertex_barcodes.begin() )->second;
00414 m_vertex_barcodes.erase( m_vertex_barcodes.begin() );
00415 delete vtx;
00416 }
00417
00418
00419 if ( !vertices_empty() || ! particles_empty() ) {
00420 std::cerr << "GenEvent::delete_all_vertices strange result ... "
00421 << "after deleting all vertices, \nthe particle and "
00422 << "vertex maps aren't empty.\n This probably "
00423 << "indicates deeper problems or memory leak in the "
00424 << "code." << std::endl;
00425 std::cerr << "Number vtx,particle the event after deleting = "
00426 << m_vertex_barcodes.size() << " "
00427 << m_particle_barcodes.size() << std::endl;
00428 }
00429 }
00430
00431 bool GenEvent::set_barcode( GenParticle* p, int suggested_barcode )
00432 {
00433 if ( p->parent_event() != this ) {
00434 std::cerr << "GenEvent::set_barcode attempted, but the argument's"
00435 << "\n parent_event is not this ... request rejected."
00436 << std::endl;
00437 return false;
00438 }
00439
00440
00441
00442
00443 if ( p->barcode() != 0 && p->barcode() != suggested_barcode ) {
00444 if ( m_particle_barcodes.count(p->barcode()) &&
00445 m_particle_barcodes[p->barcode()] == p ) {
00446 m_particle_barcodes.erase( p->barcode() );
00447 }
00448
00449
00450
00451 }
00452
00453
00454
00455 bool insert_success = true;
00456 if ( suggested_barcode > 0 ) {
00457 if ( m_particle_barcodes.count(suggested_barcode) ) {
00458
00459 if ( m_particle_barcodes[suggested_barcode] == p ) {
00460
00461 p->set_barcode_( suggested_barcode );
00462 return true;
00463 }
00464 insert_success = false;
00465 suggested_barcode = 0;
00466 } else {
00467 m_particle_barcodes[suggested_barcode] = p;
00468 p->set_barcode_( suggested_barcode );
00469 return true;
00470 }
00471 }
00472
00473
00474
00475 if ( suggested_barcode < 0 ) insert_success = false;
00476 if ( suggested_barcode <= 0 ) {
00477 if ( !m_particle_barcodes.empty() ) {
00478
00479
00480 suggested_barcode = m_particle_barcodes.rbegin()->first;
00481 ++suggested_barcode;
00482 }
00483
00484
00485
00486
00487
00488
00489 if ( suggested_barcode <= 10000 ) suggested_barcode = 10001;
00490 }
00491
00492 if ( m_particle_barcodes.count(suggested_barcode) ) {
00493 std::cerr << "GenEvent::set_barcode ERROR, this should never "
00494 << "happen \n report bug to matt.dobbs@cern.ch"
00495 << std::endl;
00496 }
00497 m_particle_barcodes[suggested_barcode] = p;
00498 p->set_barcode_( suggested_barcode );
00499 return insert_success;
00500 }
00501
00502 bool GenEvent::set_barcode( GenVertex* v, int suggested_barcode )
00503 {
00504 if ( v->parent_event() != this ) {
00505 std::cerr << "GenEvent::set_barcode attempted, but the argument's"
00506 << "\n parent_event is not this ... request rejected."
00507 << std::endl;
00508 return false;
00509 }
00510
00511
00512
00513
00514 if ( v->barcode() != 0 && v->barcode() != suggested_barcode ) {
00515 if ( m_vertex_barcodes.count(v->barcode()) &&
00516 m_vertex_barcodes[v->barcode()] == v ) {
00517 m_vertex_barcodes.erase( v->barcode() );
00518 }
00519
00520
00521
00522 }
00523
00524
00525
00526
00527 bool insert_success = true;
00528 if ( suggested_barcode < 0 ) {
00529 if ( m_vertex_barcodes.count(suggested_barcode) ) {
00530
00531 if ( m_vertex_barcodes[suggested_barcode] == v ) {
00532
00533 v->set_barcode_( suggested_barcode );
00534 return true;
00535 }
00536 insert_success = false;
00537 suggested_barcode = 0;
00538 } else {
00539 m_vertex_barcodes[suggested_barcode] = v;
00540 v->set_barcode_( suggested_barcode );
00541 return true;
00542 }
00543 }
00544
00545
00546
00547 if ( suggested_barcode > 0 ) insert_success = false;
00548 if ( suggested_barcode >= 0 ) {
00549 if ( !m_vertex_barcodes.empty() ) {
00550
00551
00552 suggested_barcode = m_vertex_barcodes.rbegin()->first;
00553 --suggested_barcode;
00554 }
00555 if ( suggested_barcode >= 0 ) suggested_barcode = -1;
00556 }
00557
00558 if ( m_vertex_barcodes.count(suggested_barcode) ) {
00559 std::cerr << "GenEvent::set_barcode ERROR, this should never "
00560 << "happen \n report bug to matt.dobbs@cern.ch"
00561 << std::endl;
00562 }
00563 m_vertex_barcodes[suggested_barcode] = v;
00564 v->set_barcode_( suggested_barcode );
00565 return insert_success;
00566 }
00567
00569 bool GenEvent::valid_beam_particles() const {
00570 bool have1 = false;
00571 bool have2 = false;
00572
00573 if(m_beam_particle_1 && m_beam_particle_2) {
00574
00575 for ( particle_const_iterator p = particles_begin();
00576 p != particles_end(); ++p ) {
00577 if( m_beam_particle_1 == *p ) have1 = true;
00578 if( m_beam_particle_2 == *p ) have2 = true;
00579 }
00580 }
00581 if( have1 && have2 ) return true;
00582 return false;
00583 }
00584
00587 bool GenEvent::set_beam_particles(GenParticle* bp1, GenParticle* bp2) {
00588 m_beam_particle_1 = bp1;
00589 m_beam_particle_2 = bp2;
00590 if( m_beam_particle_1 && m_beam_particle_2 ) return true;
00591 return false;
00592 }
00593
00596 bool GenEvent::set_beam_particles(std::pair<HepMC::GenParticle*, HepMC::GenParticle*> const & bp) {
00597 return set_beam_particles(bp.first,bp.second);
00598 }
00599
00600 void GenEvent::write_units( std::ostream & os ) const {
00601 os << " Momenutm units:" << std::setw(8) << name(momentum_unit());
00602 os << " Position units:" << std::setw(8) << name(length_unit());
00603 os << std::endl;
00604 }
00605
00606 bool GenEvent::use_momentum_unit( Units::MomentumUnit newunit ) {
00607
00608
00609 if ( m_momentum_unit != newunit ) {
00610 const double factor = Units::conversion_factor( m_momentum_unit, newunit );
00611
00612
00613 for ( GenEvent::particle_iterator p = particles_begin();
00614 p != particles_end(); ++p )
00615 {
00616 (*p)->convert_momentum(factor);
00617 }
00618
00619 m_momentum_unit = newunit;
00620 }
00621 return true;
00622 }
00623
00624 bool GenEvent::use_length_unit( Units::LengthUnit newunit ) {
00625
00626
00627 if ( m_position_unit != newunit ) {
00628 const double factor = Units::conversion_factor( m_position_unit, newunit );
00629
00630
00631 for ( GenEvent::vertex_iterator vtx = vertices_begin();
00632 vtx != vertices_end(); ++vtx ) {
00633 (*vtx)->convert_position(factor);
00634 }
00635
00636 m_position_unit = newunit;
00637 }
00638 return true;
00639 }
00640
00641 bool GenEvent::use_momentum_unit( std::string& newunit ) {
00642 if ( newunit == "MEV" ) return use_momentum_unit( Units::MEV );
00643 else if( newunit == "GEV" ) return use_momentum_unit( Units::GEV );
00644 else std::cerr << "GenEvent::use_momentum_unit ERROR: use either MEV or GEV\n";
00645 return false;
00646 }
00647
00648 bool GenEvent::use_length_unit( std::string& newunit ) {
00649 if ( newunit == "MM" ) return use_length_unit( Units::MM );
00650 else if( newunit == "CM" ) return use_length_unit( Units::CM );
00651 else std::cerr << "GenEvent::use_length_unit ERROR: use either MEV or GEV\n";
00652 return false;
00653 }
00654
00655 bool GenEvent::is_valid() const {
00658 if ( vertices_empty() ) return false;
00659 if ( particles_empty() ) return false;
00660 return true;
00661 }
00662
00663 std::ostream & GenEvent::write_beam_particles(std::ostream & os,
00664 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> pr )
00665 {
00666 GenParticle* p = pr.first;
00667 if(!p) {
00668 detail::output( os, 0 );
00669 } else {
00670 detail::output( os, p->barcode() );
00671 }
00672 p = pr.second;
00673 if(!p) {
00674 detail::output( os, 0 );
00675 } else {
00676 detail::output( os, p->barcode() );
00677 }
00678
00679 return os;
00680 }
00681
00682 std::ostream & GenEvent::write_vertex(std::ostream & os, GenVertex const * v)
00683 {
00684 if ( !v || !os ) {
00685 std::cerr << "GenEvent::write_vertex !v||!os, "
00686 << "v="<< v << " setting badbit" << std::endl;
00687 os.clear(std::ios::badbit);
00688 return os;
00689 }
00690
00691
00692 int num_orphans_in = 0;
00693 for ( GenVertex::particles_in_const_iterator p1
00694 = v->particles_in_const_begin();
00695 p1 != v->particles_in_const_end(); ++p1 ) {
00696 if ( !(*p1)->production_vertex() ) ++num_orphans_in;
00697 }
00698
00699 os << 'V';
00700 detail::output( os, v->barcode() );
00701 detail::output( os, v->id() );
00702 detail::output( os, v->position().x() );
00703 detail::output( os, v->position().y() );
00704 detail::output( os, v->position().z() );
00705 detail::output( os, v->position().t() );
00706 detail::output( os, num_orphans_in );
00707 detail::output( os, (int)v->particles_out_size() );
00708 detail::output( os, (int)v->weights().size() );
00709 for ( WeightContainer::const_iterator w = v->weights().begin();
00710 w != v->weights().end(); ++w ) {
00711 detail::output( os, *w );
00712 }
00713 detail::output( os,'\n');
00714
00715 for ( GenVertex::particles_in_const_iterator p2
00716 = v->particles_in_const_begin();
00717 p2 != v->particles_in_const_end(); ++p2 ) {
00718 if ( !(*p2)->production_vertex() ) {
00719 write_particle( os, *p2 );
00720 }
00721 }
00722
00723 for ( GenVertex::particles_out_const_iterator p3
00724 = v->particles_out_const_begin();
00725 p3 != v->particles_out_const_end(); ++p3 ) {
00726 write_particle( os, *p3 );
00727 }
00728 return os;
00729 }
00730
00731 std::ostream & GenEvent::write_particle( std::ostream & os, GenParticle const * p )
00732 {
00733 if ( !p || !os ) {
00734 std::cerr << "GenEvent::write_particle !p||!os, "
00735 << "p="<< p << " setting badbit" << std::endl;
00736 os.clear(std::ios::badbit);
00737 return os;
00738 }
00739 os << 'P';
00740 detail::output( os, p->barcode() );
00741 detail::output( os, p->pdg_id() );
00742 detail::output( os, p->momentum().px() );
00743 detail::output( os, p->momentum().py() );
00744 detail::output( os, p->momentum().pz() );
00745 detail::output( os, p->momentum().e() );
00746 detail::output( os, p->generated_mass() );
00747 detail::output( os, p->status() );
00748 detail::output( os, p->polarization().theta() );
00749 detail::output( os, p->polarization().phi() );
00750
00751
00752 detail::output( os, ( p->end_vertex() ? p->end_vertex()->barcode() : 0 ) );
00753 os << ' ' << p->flow() << "\n";
00754
00755 return os;
00756 }
00757
00758 }