Changeset 571 in svn for trunk/Utilities/HepMC/src/GenEvent.cc
- Timestamp:
- Nov 2, 2011, 5:06:22 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/HepMC/src/GenEvent.cc
r349 r571 14 14 15 15 #include "GenEvent.h" 16 #include "GenCrossSection.h" 16 17 #include "Version.h" 18 #include "StreamHelpers.h" 17 19 18 20 namespace HepMC { … … 38 40 m_vertex_barcodes(), 39 41 m_particle_barcodes(), 42 m_cross_section(0), 40 43 m_heavy_ion(0), 41 44 m_pdf_info(0), … … 71 74 m_vertex_barcodes(), 72 75 m_particle_barcodes(), 76 m_cross_section(0), 73 77 m_heavy_ion( new HeavyIon(ion) ), 74 78 m_pdf_info( new PdfInfo(pdf) ), … … 102 106 m_vertex_barcodes(), 103 107 m_particle_barcodes(), 108 m_cross_section(0), 104 109 m_heavy_ion(0), 105 110 m_pdf_info(0), … … 136 141 m_vertex_barcodes(), 137 142 m_particle_barcodes(), 143 m_cross_section(0), 138 144 m_heavy_ion( new HeavyIon(ion) ), 139 145 m_pdf_info( new PdfInfo(pdf) ), … … 162 168 m_vertex_barcodes ( /* inevent.m_vertex_barcodes */ ), 163 169 m_particle_barcodes ( /* inevent.m_particle_barcodes */ ), 170 m_cross_section ( inevent.cross_section() ? new GenCrossSection(*inevent.cross_section()) : 0 ), 164 171 m_heavy_ion ( inevent.heavy_ion() ? new HeavyIon(*inevent.heavy_ion()) : 0 ), 165 172 m_pdf_info ( inevent.pdf_info() ? new PdfInfo(*inevent.pdf_info()) : 0 ), … … 168 175 { 169 176 /// deep copy - makes a copy of all vertices! 170 //++s_counter;171 177 // 172 178 … … 234 240 m_vertex_barcodes.swap( other.m_vertex_barcodes ); 235 241 m_particle_barcodes.swap( other.m_particle_barcodes ); 242 std::swap(m_cross_section , other.m_cross_section ); 236 243 std::swap(m_heavy_ion , other.m_heavy_ion ); 237 244 std::swap(m_pdf_info , other.m_pdf_info ); … … 252 259 { 253 260 /// Deep destructor. 254 /// deletes all vertices/particles in this evt255 /// 261 /// deletes all vertices/particles in this GenEvent 262 /// deletes the associated HeavyIon and PdfInfo 256 263 delete_all_vertices(); 264 delete m_cross_section; 257 265 delete m_heavy_ion; 258 266 delete m_pdf_info; 259 //--s_counter;260 267 } 261 268 … … 281 288 : 0 ) 282 289 << "\n"; 283 //ostr << " Current Memory Usage: "284 // << GenEvent::counter() << " events, "285 // << GenVertex::counter() << " vertices, "286 // << GenParticle::counter() << " particles.\n";287 290 write_units( ostr ); 291 write_cross_section(ostr); 288 292 ostr << " Entries this event: " << vertices_size() << " vertices, " 289 293 << particles_size() << " particles.\n"; … … 302 306 // Weights 303 307 ostr << " Wgts(" << weights().size() << ")="; 304 for ( WeightContainer::const_iterator wgt = weights().begin(); 305 wgt != weights().end(); ++wgt ) { ostr << *wgt << " "; } 306 ostr << "\n"; 308 weights().print(ostr); 307 309 ostr << " EventScale " << event_scale() 308 310 << " [energy] \t alphaQCD=" << alphaQCD() … … 367 369 /// 368 370 delete_all_vertices(); 371 // remove existing objects and set pointers to null 372 delete m_cross_section; 373 m_cross_section = 0; 369 374 delete m_heavy_ion; 375 m_heavy_ion = 0; 370 376 delete m_pdf_info; 377 m_pdf_info = 0; 371 378 m_signal_process_id = 0; 372 379 m_beam_particle_1 = 0; 373 380 m_beam_particle_2 = 0; 374 381 m_event_number = 0; 382 m_mpi = -1; 375 383 m_event_scale = -1; 376 384 m_alphaQCD = -1; … … 378 386 m_weights = std::vector<double>(); 379 387 m_random_states = std::vector<long>(); 380 //m_momentum_unit = ; 381 //m_position_unit = ; 388 // resetting unit information 389 m_momentum_unit = Units::default_momentum_unit(); 390 m_position_unit = Units::default_length_unit(); 382 391 // error check just to be safe 383 392 if ( m_vertex_barcodes.size() != 0 … … 388 397 << m_vertex_barcodes.size() << " " 389 398 << m_particle_barcodes.size() << std::endl; 390 //std::cerr << "Total Number vtx,particle in memory "391 // << "after method called = "392 // << GenVertex::counter() << "\t"393 // << GenParticle::counter() << std::endl;394 399 } 395 400 return; … … 420 425 << m_vertex_barcodes.size() << " " 421 426 << m_particle_barcodes.size() << std::endl; 422 //std::cerr << "Total Number vtx,particle in memory "423 // << "after method called = "424 // << GenVertex::counter() << "\t"425 // << GenParticle::counter() << std::endl;426 427 } 427 428 } … … 602 603 } 603 604 605 void GenEvent::write_cross_section( std::ostream& os ) const 606 { 607 // write the GenCrossSection information if the cross section was set 608 if( !cross_section() ) return; 609 if( cross_section()->is_set() ) { 610 os << " Cross Section: " << cross_section()->cross_section() ; 611 os << " +/- " << cross_section()->cross_section_error() ; 612 os << std::endl; 613 } 614 } 615 604 616 bool GenEvent::use_momentum_unit( Units::MomentumUnit newunit ) { 605 617 // currently not exception-safe. … … 651 663 } 652 664 665 bool GenEvent::is_valid() const { 666 /// A GenEvent is presumed valid if it has both associated 667 /// particles and vertices. No other information is checked. 668 if ( vertices_empty() ) return false; 669 if ( particles_empty() ) return false; 670 return true; 671 } 672 673 std::ostream & GenEvent::write_beam_particles(std::ostream & os, 674 std::pair<HepMC::GenParticle *,HepMC::GenParticle *> pr ) 675 { 676 GenParticle* p = pr.first; 677 if(!p) { 678 detail::output( os, 0 ); 679 } else { 680 detail::output( os, p->barcode() ); 681 } 682 p = pr.second; 683 if(!p) { 684 detail::output( os, 0 ); 685 } else { 686 detail::output( os, p->barcode() ); 687 } 688 689 return os; 690 } 691 692 std::ostream & GenEvent::write_vertex(std::ostream & os, GenVertex const * v) 693 { 694 if ( !v || !os ) { 695 std::cerr << "GenEvent::write_vertex !v||!os, " 696 << "v="<< v << " setting badbit" << std::endl; 697 os.clear(std::ios::badbit); 698 return os; 699 } 700 // First collect info we need 701 // count the number of orphan particles going into v 702 int num_orphans_in = 0; 703 for ( GenVertex::particles_in_const_iterator p1 704 = v->particles_in_const_begin(); 705 p1 != v->particles_in_const_end(); ++p1 ) { 706 if ( !(*p1)->production_vertex() ) ++num_orphans_in; 707 } 708 // 709 os << 'V'; 710 detail::output( os, v->barcode() ); // v's unique identifier 711 detail::output( os, v->id() ); 712 detail::output( os, v->position().x() ); 713 detail::output( os, v->position().y() ); 714 detail::output( os, v->position().z() ); 715 detail::output( os, v->position().t() ); 716 detail::output( os, num_orphans_in ); 717 detail::output( os, (int)v->particles_out_size() ); 718 detail::output( os, (int)v->weights().size() ); 719 for ( WeightContainer::const_iterator w = v->weights().begin(); 720 w != v->weights().end(); ++w ) { 721 detail::output( os, *w ); 722 } 723 detail::output( os,'\n'); 724 // incoming particles 725 for ( GenVertex::particles_in_const_iterator p2 726 = v->particles_in_const_begin(); 727 p2 != v->particles_in_const_end(); ++p2 ) { 728 if ( !(*p2)->production_vertex() ) { 729 write_particle( os, *p2 ); 730 } 731 } 732 // outgoing particles 733 for ( GenVertex::particles_out_const_iterator p3 734 = v->particles_out_const_begin(); 735 p3 != v->particles_out_const_end(); ++p3 ) { 736 write_particle( os, *p3 ); 737 } 738 return os; 739 } 740 741 std::ostream & GenEvent::write_particle( std::ostream & os, GenParticle const * p ) 742 { 743 if ( !p || !os ) { 744 std::cerr << "GenEvent::write_particle !p||!os, " 745 << "p="<< p << " setting badbit" << std::endl; 746 os.clear(std::ios::badbit); 747 return os; 748 } 749 os << 'P'; 750 detail::output( os, p->barcode() ); 751 detail::output( os, p->pdg_id() ); 752 detail::output( os, p->momentum().px() ); 753 detail::output( os, p->momentum().py() ); 754 detail::output( os, p->momentum().pz() ); 755 detail::output( os, p->momentum().e() ); 756 detail::output( os, p->generated_mass() ); 757 detail::output( os, p->status() ); 758 detail::output( os, p->polarization().theta() ); 759 detail::output( os, p->polarization().phi() ); 760 // since end_vertex is oftentimes null, this CREATES a null vertex 761 // in the map 762 detail::output( os, ( p->end_vertex() ? p->end_vertex()->barcode() : 0 ) ); 763 os << ' ' << p->flow() << "\n"; 764 765 return os; 766 } 767 653 768 } // HepMC
Note:
See TracChangeset
for help on using the changeset viewer.