Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMC3Particle.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMC3Particle.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 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 
13 
15  const HepMC3::ConstGenParticlePtr& particle) {
16  // TODO this is probably not quite right
17  ActsFatras::Barcode particleId;
18  particleId.setParticle(particle->id());
19  Acts::PdgParticle pdg = static_cast<Acts::PdgParticle>(particle->pid());
20  SimParticle fw(particleId, static_cast<Acts::PdgParticle>(particle->pid()),
21  Acts::findCharge(pdg).value_or(0), particle->generated_mass());
22  fw.setDirection(particle->momentum().x(), particle->momentum().y(),
23  particle->momentum().z());
24  fw.setAbsoluteMomentum(particle->momentum().p3mod());
25  return fw;
26 }
27 
29  const std::shared_ptr<HepMC3::GenParticle>& particle) {
30  return particle->id();
31 }
32 
33 std::unique_ptr<ActsExamples::SimVertex>
35  const std::shared_ptr<HepMC3::GenParticle>& particle) {
36  // Return the vertex if it exists
37  if (particle->production_vertex()) {
39  std::make_shared<HepMC3::GenVertex>(*particle->production_vertex()));
40  } else {
41  return nullptr;
42  }
43 }
44 
45 std::unique_ptr<ActsExamples::SimVertex>
47  const std::shared_ptr<HepMC3::GenParticle>& particle) {
48  // Return the vertex if it exists
49  if (particle->end_vertex()) {
51  std::make_shared<HepMC3::GenVertex>(*(particle->end_vertex())));
52  } else {
53  return nullptr;
54  }
55 }
56 
58  const std::shared_ptr<HepMC3::GenParticle>& particle) {
59  return particle->pid();
60 }
61 
63  const std::shared_ptr<HepMC3::GenParticle>& particle) {
64  Acts::Vector3 mom;
65  mom(0) = particle->momentum().x();
66  mom(1) = particle->momentum().y();
67  mom(2) = particle->momentum().z();
68  return mom;
69 }
70 
72  const std::shared_ptr<HepMC3::GenParticle>& particle) {
73  return particle->momentum().e();
74 }
75 
77  const std::shared_ptr<HepMC3::GenParticle>& particle) {
78  return particle->generated_mass();
79 }
80 
82  const std::shared_ptr<HepMC3::GenParticle>& particle) {
83  return Acts::findCharge(static_cast<Acts::PdgParticle>(particle->pid()))
84  .value_or(0);
85 }
86 
88  const std::shared_ptr<HepMC3::GenParticle>& particle, const int pid) {
89  particle->set_pid(pid);
90 }
91 
93  const std::shared_ptr<HepMC3::GenParticle>& particle,
94  const Acts::Vector3& mom) {
95  HepMC3::FourVector fVec(mom(0), mom(1), mom(2), particle->momentum().e());
96  particle->set_momentum(fVec);
97 }
98 
100  const std::shared_ptr<HepMC3::GenParticle>& particle, const double energy) {
101  HepMC3::FourVector fVec(particle->momentum().x(), particle->momentum().y(),
102  particle->momentum().z(), energy);
103  particle->set_momentum(fVec);
104 }
105 
107  const std::shared_ptr<HepMC3::GenParticle>& particle, const double mass) {
108  particle->set_generated_mass(mass);
109 }