00001
00002
00003
00004
00005
00006
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, std::ostream & os )
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 os << "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 }
00077
00078 void repairUnits(HepMC::GenEvent* evt,
00079 HepMC::Units::MomentumUnit from,
00080 HepMC::Units::MomentumUnit to )
00081 {
00082
00083 const double factor = HepMC::Units::conversion_factor( from, to );
00084
00085
00086 for ( HepMC::GenEvent::particle_iterator p = evt->particles_begin();
00087 p != evt->particles_end(); ++p )
00088 {
00089 HepMC::FourVector mom = (*p)->momentum();
00090 double gm = (*p)->generatedMass();
00091 (*p)->set_momentum( HepMC::FourVector( factor*mom.px(),
00092 factor*mom.py(),
00093 factor*mom.pz(),
00094 factor*mom.e() ) );
00095 if( gm > 0. ) (*p)->set_generated_mass( factor*gm );
00096 }
00097 }