//============================================================================= // Smearing function //============================================================================= StatusCode FlatSmearVertex::smearVertex( HepMC::GenEvent * theEvent ) { double dx , dy , dz , dt ; dx = m_xmin + m_flatDist( ) * ( m_xmax - m_xmin ) ; dy = m_ymin + m_flatDist( ) * ( m_ymax - m_ymin ) ; dz = m_zmin + m_flatDist( ) * ( m_zmax - m_zmin ) ; dt = m_zDir * dz/Gaudi::Units::c_light ; Gaudi::LorentzVector dpos( dx , dy , dz , dt ) ; debug() << "Smearing vertices by " << dpos << endmsg; for (auto vit = theEvent->vertices_begin(); vit != theEvent->vertices_end(); ++vit ) { Gaudi::LorentzVector pos ( (*vit) -> position() ) ; pos += dpos ; (*vit)->set_position( HepMC::FourVector(pos.x(), pos.y(), pos.z(), pos.t() ) ) ; } return StatusCode::SUCCESS ; }
//============================================================================= // Main execution //============================================================================= StatusCode ParticleGunAlg::execute() { StatusCode sc = StatusCode::SUCCESS ; Gaudi::LorentzVector theFourMomentum ; Gaudi::LorentzVector origin ; int thePdgId ; // prepare a new HepMC event HepMC::GenEvent * theEvent = new HepMC::GenEvent() ; m_particleGunTool->generateParticle( theFourMomentum , origin , thePdgId ); // create HepMC Vertex HepMC::GenVertex * v = new HepMC::GenVertex( HepMC::FourVector( origin.X() , origin.Y() , origin.Z() , origin.T() ) ) ; // create HepMC particle HepMC::GenParticle * p = new HepMC::GenParticle( HepMC::FourVector( theFourMomentum.Px() , theFourMomentum.Py() , theFourMomentum.Pz() , theFourMomentum.E() ) , thePdgId , 3 ) ; v -> add_particle_out( p ) ; theEvent -> add_vertex( v ) ; theEvent -> set_signal_process_id( 0 ) ; theEvent -> set_signal_process_vertex( v ) ; if(m_vertexSmearTool != nullptr) m_vertexSmearTool->smearVertex(theEvent); HepMCEntry * entry = new HepMCEntry(); entry->setEvent(theEvent); m_hepmchandle.put(entry); return sc ; }
/// Generate the particles void ConstPtParticleGun::generateParticle(Gaudi::LorentzVector& momentum, Gaudi::LorentzVector& origin, int& pdgId) { origin.SetCoordinates(0., 0., 0., 0.); double px(0.), py(0.), pz(0.); // Generate values for eta and phi double phi = m_minPhi + m_flatGenerator() * (m_deltaPhi); double eta = m_minEta + m_flatGenerator() * (m_deltaEta); // Transform to x,y,z coordinates double pt = 0; if (m_ptList.size() > 0) { int randIndex = m_flatGenerator() * m_ptList.size(); pt = m_ptList[randIndex]; } else { if (m_logSpacedPt) { double logPtMin = std::log10(m_minPt); double logPtMax = std::log10(m_maxPt); pt = pow(10, logPtMin + (logPtMax - logPtMin) * m_flatGenerator()); } else { pt = m_minPt + m_flatGenerator() * (m_maxPt - m_minPt); } } px = pt * cos(phi); py = pt * sin(phi); pz = pt * sinh(eta); // randomly choose a particle type unsigned int currentType = (unsigned int)(m_pdgCodes.size() * m_flatGenerator()); // protect against funnies if (currentType >= m_pdgCodes.size()) currentType = 0; momentum.SetPx(px); momentum.SetPy(py); momentum.SetPz(pz); momentum.SetE(std::sqrt(m_masses[currentType] * m_masses[currentType] + momentum.P2())); pdgId = m_pdgCodes[currentType]; debug() << " -> " << pdgId << endmsg << " P = " << momentum << endmsg; }
StatusCode ConstPtParticleGun::getNextEvent(HepMC::GenEvent& theEvent) { Gaudi::LorentzVector theFourMomentum; Gaudi::LorentzVector origin; // note: pgdid is set in function generateParticle int thePdgId; generateParticle(theFourMomentum, origin, thePdgId); // create HepMC Vertex -- // by calling add_vertex(), the hepmc event is given ownership of the vertex HepMC::GenVertex* v = new HepMC::GenVertex(HepMC::FourVector(origin.X(), origin.Y(), origin.Z(), origin.T())); // create HepMC particle -- // by calling add_particle_out(), the hepmc vertex is given ownership of the particle HepMC::GenParticle* p = new HepMC::GenParticle( HepMC::FourVector(theFourMomentum.Px(), theFourMomentum.Py(), theFourMomentum.Pz(), theFourMomentum.E()), thePdgId, 1); // hepmc status code for final state particle v->add_particle_out(p); theEvent.add_vertex(v); theEvent.set_signal_process_vertex(v); return StatusCode::SUCCESS; }