Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4Decay.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Geant4Decay.cpp
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 
10 
16 
17 #include <cstdint>
18 #include <utility>
19 
20 #include "G4DecayProducts.hh"
21 #include "G4DecayTable.hh"
22 
24  : m_g4RunManager(ensureGeant4RunManager()) {}
25 
26 std::vector<ActsFatras::Particle> ActsFatras::Geant4Decay::decayParticle(
27  const ActsFatras::Particle& parent) const {
28  std::vector<Particle> children;
29 
30  // Find the particle type that will decay
31  G4ParticleDefinition* pDef =
32  m_pdgToG4Conv.getParticleDefinition(parent.pdg());
33  if (pDef == nullptr) {
34  return children;
35  }
36  // Get the particles decay table
37  G4DecayTable* dt = pDef->GetDecayTable();
38  if (dt == nullptr) {
39  return children;
40  }
41  // Select a decay channel
42  G4VDecayChannel* channel = dt->SelectADecayChannel();
43  if (channel == nullptr) {
44  return children;
45  }
46  // Get the decay products from the selected channel
47  G4DecayProducts* products = channel->DecayIt();
48  if (products == nullptr) {
49  return children;
50  }
51 
52  // Boost the decay products using the parents four-momentum
53  const Particle::Vector4 mom4 = parent.fourMomentum();
54  products->Boost(mom4[Acts::eMom0] / mom4[Acts::eEnergy],
55  mom4[Acts::eMom1] / mom4[Acts::eEnergy],
56  mom4[Acts::eMom2] / mom4[Acts::eEnergy]);
57 
58  G4int nProducts = products->entries();
59  for (G4int i = 0; i < nProducts; i++) {
60  G4DynamicParticle* prod = products->PopProducts();
61  if (prod == nullptr) {
62  continue;
63  }
64 
65  // Convert the decay product from Geant4 to Acts
66  const G4ThreeVector& mom = prod->GetMomentum();
67  constexpr Scalar convertEnergy = Acts::UnitConstants::GeV / CLHEP::GeV;
68  Acts::Vector3 amgMom(mom.x(), mom.y(), mom.z());
69  amgMom *= convertEnergy;
70  const int32_t pdg = prod->GetPDGcode();
71 
72  Particle childParticle(parent.particleId().makeDescendant(i),
73  static_cast<Acts::PdgParticle>(pdg));
74  childParticle.setPosition4(parent.fourPosition())
75  .setAbsoluteMomentum(amgMom.norm())
76  .setDirection(amgMom)
77  .setProcess(ProcessType::eDecay);
78 
79  // Store the particle
80  children.push_back(std::move(childParticle));
81  }
82  return children;
83 }