00001 #include "Rivet/Event.hh"
00002 #include "Rivet/Tools/Logging.hh"
00003 #include "Rivet/Projections/Beam.hh"
00004 #include "Rivet/BeamConstraint.hh"
00005 #include "HepMC/GenEvent.h"
00006
00007 namespace Rivet {
00008
00009
00010
00011 void _geNormUnits(GenEvent& ge) {
00012
00013 #ifdef HEPMC_HAS_UNITS
00014 ge.use_units(HepMC::Units::GEV, HepMC::Units::MM);
00015 #endif
00016 }
00017
00018
00019 void _geRot180x(GenEvent& ge) {
00020 for (HepMC::GenEvent::particle_iterator ip = ge.particles_begin(); ip != ge.particles_end(); ++ip) {
00021 const HepMC::FourVector& mom = (*ip)->momentum();
00022 (*ip)->set_momentum(HepMC::FourVector(mom.px(), -mom.py(), -mom.pz(), mom.e()));
00023 }
00024 for (HepMC::GenEvent::vertex_iterator iv = ge.vertices_begin(); iv != ge.vertices_end(); ++iv) {
00025 const HepMC::FourVector& pos = (*iv)->position();
00026 (*iv)->set_position(HepMC::FourVector(pos.x(), -pos.y(), -pos.z(), pos.t()));
00027 }
00028 }
00029
00030
00031
00032
00033
00034
00035 void _geNormAlignment(GenEvent& ge) {
00036 if (!ge.valid_beam_particles()) return;
00037 typedef pair<HepMC::GenParticle*, HepMC::GenParticle*> GPPair;
00038 GPPair bps = ge.beam_particles();
00039 const BeamPair beamids = make_pdgid_pair(bps.first->pdg_id(), bps.second->pdg_id());
00040 Log::getLog("Rivet.Event") << Log::TRACE << "Beam IDs: " << beamids << endl;
00041 const HepMC::GenParticle* plusgp = 0;
00042 bool rot = false;
00043
00044
00045
00046
00047
00048
00049
00050 if (bps.first->pdg_id() != PROTON || bps.second->pdg_id() != PROTON) {
00051 if (bps.first->pdg_id() == PROTON) {
00052 plusgp = bps.first;
00053 } else if (bps.second->pdg_id() == PROTON) {
00054 plusgp = bps.second;
00055 }
00056 if (plusgp && plusgp->momentum().pz() < 0) {
00057 rot = true;
00058 }
00059 }
00060
00061
00062 if (rot) {
00063 if (Log::getLog("Rivet.Event").isActive(Log::TRACE)) {
00064 Log::getLog("Rivet.Event") << Log::TRACE << "Rotating event" << endl;
00065 Log::getLog("Rivet.Event") << Log::TRACE << "Before rotation: "
00066 << bps.first->pdg_id() << "@pz=" << bps.first->momentum().pz()/GeV << ", "
00067 << bps.second->pdg_id() << "@pz=" << bps.second->momentum().pz()/GeV << endl;
00068 }
00069 _geRot180x(ge);
00070 }
00071 }
00072
00073
00074 Event::Event(const GenEvent& ge)
00075 : _genEvent(ge), _weight(1.0)
00076 {
00077
00078 if (!_genEvent.weights().empty()) {
00079 _weight = ge.weights()[0];
00080 }
00081
00082
00083 _geNormUnits(_genEvent);
00084
00085
00086 _geNormAlignment(_genEvent);
00087
00088
00089
00090 }
00091
00092
00093 Event::Event(const Event& e)
00094 : _genEvent(e._genEvent),
00095 _weight(e._weight)
00096 {
00097
00098 }
00099
00100
00101 Event& Event::operator=(const Event& e) {
00102 _genEvent = e._genEvent;
00103 _weight = e._weight;
00104 return *this;
00105 }
00106
00107
00108 }