Event.cc

Go to the documentation of this file.
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   // Convert the GenEvent to use conventional alignment
00023   // (proton or electron on +ve z-axis?)
00024   // For example, FHerwig only produces DIS events in the
00025   // unconventional orientation and has to be corrected
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     //Log::getLog("Rivet.Event") << Log::TRACE << "Beam IDs: " << beamids << endl;
00032     const HepMC::GenParticle* plusgp = 0;
00033     bool rot = false;
00034 
00035     // Rotate e+- p and ppbar to put p along +z
00036     /// @todo e+ e- convention? B-factories different from LEP?
00037     // if (compatible(beamids, make_pdgid_pair(ELECTRON, PROTON)) ||
00038     //     compatible(beamids, make_pdgid_pair(POSITRON, PROTON)) ||
00039     //     compatible(beamids, make_pdgid_pair(ANTIPROTON, PROTON)) ) {
00040     //   Log::getLog("Rivet.Event") << Log::TRACE << "May need to rotate event..." << endl;
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     // Do the rotation
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     // Set the weight if there is one, otherwise default to 1.0
00070     if (!_genEvent.weights().empty()) {
00071       _weight = ge.weights()[0];
00072     }
00073 
00074     // Use Rivet's preferred units if possible
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     // Use the conventional alignment
00084     _geNormAlignment();
00085 
00086     // Debug printout to check that copying/magling has worked
00087     //_genEvent.print();
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 }