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