Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:48

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/HepMC3/HepMC3Particle.hpp"
0010 
0011 #include "Acts/Definitions/ParticleData.hpp"
0012 #include "ActsExamples/Io/HepMC3/HepMC3Vertex.hpp"
0013 
0014 namespace ActsExamples {
0015 
0016 SimBarcode HepMC3Particle::barcode(
0017     const HepMC3::ConstGenParticlePtr& particle) {
0018   // TODO this is probably not quite right
0019   return particle->id();
0020 }
0021 
0022 SimParticle HepMC3Particle::particle(
0023     const HepMC3::ConstGenParticlePtr& particle) {
0024   SimBarcode particleId = barcode(particle);
0025   Acts::PdgParticle pdg = static_cast<Acts::PdgParticle>(particle->pid());
0026   SimParticle fw(particleId, pdg, Acts::findCharge(pdg).value_or(0),
0027                  particle->generated_mass());
0028   fw.setDirection(particle->momentum().x(), particle->momentum().y(),
0029                   particle->momentum().z());
0030   fw.setAbsoluteMomentum(particle->momentum().p3mod());
0031   return fw;
0032 }
0033 
0034 int HepMC3Particle::id(const std::shared_ptr<HepMC3::GenParticle>& particle) {
0035   return particle->id();
0036 }
0037 
0038 std::unique_ptr<SimVertex> HepMC3Particle::productionVertex(
0039     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0040   // Return the vertex if it exists
0041   if (particle->production_vertex()) {
0042     return HepMC3Vertex::processVertex(
0043         std::make_shared<HepMC3::GenVertex>(*particle->production_vertex()));
0044   } else {
0045     return nullptr;
0046   }
0047 }
0048 
0049 std::unique_ptr<SimVertex> HepMC3Particle::endVertex(
0050     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0051   // Return the vertex if it exists
0052   if (particle->end_vertex()) {
0053     return HepMC3Vertex::processVertex(
0054         std::make_shared<HepMC3::GenVertex>(*(particle->end_vertex())));
0055   } else {
0056     return nullptr;
0057   }
0058 }
0059 
0060 int HepMC3Particle::pdgID(
0061     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0062   return particle->pid();
0063 }
0064 
0065 Acts::Vector3 HepMC3Particle::momentum(
0066     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0067   Acts::Vector3 mom;
0068   mom(0) = particle->momentum().x();
0069   mom(1) = particle->momentum().y();
0070   mom(2) = particle->momentum().z();
0071   return mom;
0072 }
0073 
0074 double HepMC3Particle::energy(
0075     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0076   return particle->momentum().e();
0077 }
0078 
0079 double HepMC3Particle::mass(
0080     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0081   return particle->generated_mass();
0082 }
0083 
0084 double HepMC3Particle::charge(
0085     const std::shared_ptr<HepMC3::GenParticle>& particle) {
0086   return Acts::findCharge(static_cast<Acts::PdgParticle>(particle->pid()))
0087       .value_or(0);
0088 }
0089 
0090 void HepMC3Particle::pdgID(const std::shared_ptr<HepMC3::GenParticle>& particle,
0091                            const int pid) {
0092   particle->set_pid(pid);
0093 }
0094 
0095 void HepMC3Particle::momentum(
0096     const std::shared_ptr<HepMC3::GenParticle>& particle,
0097     const Acts::Vector3& mom) {
0098   HepMC3::FourVector fVec(mom(0), mom(1), mom(2), particle->momentum().e());
0099   particle->set_momentum(fVec);
0100 }
0101 
0102 void HepMC3Particle::energy(
0103     const std::shared_ptr<HepMC3::GenParticle>& particle, const double energy) {
0104   HepMC3::FourVector fVec(particle->momentum().x(), particle->momentum().y(),
0105                           particle->momentum().z(), energy);
0106   particle->set_momentum(fVec);
0107 }
0108 
0109 void HepMC3Particle::mass(const std::shared_ptr<HepMC3::GenParticle>& particle,
0110                           const double mass) {
0111   particle->set_generated_mass(mass);
0112 }
0113 
0114 }  // namespace ActsExamples