Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Decay.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4Decay.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
15 
16 #include <cmath>
17 #include <limits>
18 #include <random>
19 #include <vector>
20 
21 #include "G4ParticleDefinition.hh"
22 
23 class G4RunManager;
24 
25 namespace ActsFatras {
26 
28 class Geant4Decay {
29  public:
31 
33  Geant4Decay();
34 
42  template <typename generator_t>
44  const Particle& particle) const;
45 
52  template <typename generator_t>
53  std::vector<Particle> run(generator_t& generator, Particle& particle) const;
54 
55  private:
61  std::vector<Particle> decayParticle(const Particle& parent) const;
62 
63  mutable G4RunManager* m_g4RunManager;
64 
67 };
68 
69 template <typename generator_t>
71  generator_t& generator, const Particle& particle) const {
72  // Get the particle properties
73  const Acts::PdgParticle pdgCode = particle.pdg();
74  // Keep muons stable
76  return std::numeric_limits<Scalar>::infinity();
77  }
78 
79  // Get the Geant4 particle
80  G4ParticleDefinition* pDef = m_pdgToG4Conv.getParticleDefinition(pdgCode);
81 
82  // Fast exit if the particle is stable
83  if (!pDef || pDef->GetPDGStable()) {
84  return std::numeric_limits<Scalar>::infinity();
85  }
86 
87  // Get average lifetime
88  constexpr Scalar convertTime = Acts::UnitConstants::mm / CLHEP::s;
89  const Scalar tau = pDef->GetPDGLifeTime() * convertTime;
90  // Sample & return the lifetime
91  std::uniform_real_distribution<Scalar> uniformDistribution{0., 1.};
92 
93  return -tau * std::log(uniformDistribution(generator));
94 }
95 
96 template <typename generator_t>
97 std::vector<Particle> Geant4Decay::run(generator_t& /*generator*/,
98  Particle& particle) const {
99  return decayParticle(particle);
100 }
101 } // namespace ActsFatras