![]() |
HepMC Reference DocumentationHepMC |
00001 00002 // testHepMCMethods.cc 00003 // 00004 // garren@fnal.gov, March 2009 00005 // 00006 // various methods used by the test jobs 00008 00009 #include "testHepMCMethods.h" 00010 00011 double findPiZero( HepMC::GenEvent * evt ) 00012 { 00013 for ( HepMC::GenEvent::particle_const_iterator p 00014 = evt->particles_begin(); p != evt->particles_end(); ++p ){ 00015 if ( (*p)->pdg_id() == 111 ) { 00016 return (*p)->generated_mass(); 00017 } 00018 } 00019 return 0.; 00020 } 00021 00022 void particleTypes( HepMC::GenEvent * evt ) 00023 { 00024 int numDecayed = 0, numUndecayed = 0, numBeam = 0; 00025 int numDecayed2 = 0, numUndecayed2 = 0, numBeam2 = 0; 00026 for ( HepMC::GenEvent::particle_const_iterator p 00027 = evt->particles_begin(); p != evt->particles_end(); ++p ){ 00028 if ( (*p)->is_undecayed() ) { 00029 ++numUndecayed; 00030 } 00031 if ( (*p)->has_decayed() ) { 00032 ++numDecayed; 00033 } 00034 if ( (*p)->is_beam() ) { 00035 ++numBeam; 00036 } 00037 if ( (*p)->status() == 1 ) { 00038 ++numUndecayed2; 00039 } 00040 if ( (*p)->status() == 2 ) { 00041 ++numDecayed2; 00042 } 00043 if ( (*p)->status() == 4 ) { 00044 ++numBeam2; 00045 } 00046 } 00047 if( numUndecayed != numUndecayed2 ) { 00048 std::cerr << "ERROR: incorrect count of undecayed particles: " 00049 << numUndecayed << " does not match " 00050 << numUndecayed2 << std::endl; 00051 } 00052 if( numDecayed != numDecayed2 ) { 00053 std::cerr << "ERROR: incorrect count of undecayed particles: " 00054 << numDecayed << " does not match " 00055 << numDecayed2 << std::endl; 00056 } 00057 if( numBeam != numBeam2 ) { 00058 std::cerr << "ERROR: incorrect count of undecayed particles: " 00059 << numBeam << " does not match " 00060 << numBeam2 << std::endl; 00061 } 00062 int ndcy = numUndecayed + numDecayed; 00063 if( ndcy > evt->particles_size() ) { 00064 std::cerr << "ERROR: count does not add up: " 00065 << ndcy << " is greater than the number of particles in the event: " 00066 << evt->particles_size() << std::endl; 00067 } 00068 std::cout << "Event " << evt->event_number() 00069 << " has " << evt->particles_size() 00070 << " particles, " << numDecayed 00071 << " decayed particles, " << numUndecayed 00072 << " undecayed particles, and " << numBeam 00073 << " beam particles " 00074 << std::endl; 00075 return; 00076 }