ECCE @ EIC 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 
12 
13 std::unique_ptr<FW::SimParticle> FW::HepMC3Particle::particle(
14  const std::shared_ptr<HepMC3::GenParticle> particle) {
15  // TODO this is probably not quite right
16  ActsFatras::Barcode particleId;
17  particleId.setParticle(particle->id());
18  SimParticle fw(particleId, static_cast<Acts::PdgParticle>(particle->pid()),
19  HepPID::charge(particle->pid()), particle->generated_mass());
20  fw.setDirection(particle->momentum().x(), particle->momentum().y(),
21  particle->momentum().z());
22  fw.setAbsMomentum(particle->momentum().p3mod());
23  return std::make_unique<SimParticle>(std::move(fw));
24 }
25 
27  const std::shared_ptr<HepMC3::GenParticle> particle) {
28  return particle->id();
29 }
30 
31 std::unique_ptr<FW::SimVertex> FW::HepMC3Particle::productionVertex(
32  const std::shared_ptr<HepMC3::GenParticle> particle) {
33  HepMC3Vertex simVert;
34 
35  // Return the vertex if it exists
36  if (particle->production_vertex())
37  return std::move(simVert.processVertex(
38  std::make_shared<HepMC3::GenVertex>(*particle->production_vertex())));
39  else
40  return nullptr;
41 }
42 
43 std::unique_ptr<FW::SimVertex> FW::HepMC3Particle::endVertex(
44  const std::shared_ptr<HepMC3::GenParticle> particle) {
45  HepMC3Vertex simVert;
46 
47  // Return the vertex if it exists
48  if (particle->end_vertex())
49  return std::move(simVert.processVertex(
50  std::make_shared<HepMC3::GenVertex>(*(particle->end_vertex()))));
51  else
52  return nullptr;
53 }
54 
56  const std::shared_ptr<HepMC3::GenParticle> particle) {
57  return particle->pid();
58 }
59 
61  const std::shared_ptr<HepMC3::GenParticle> particle) {
63  mom(0) = particle->momentum().x();
64  mom(1) = particle->momentum().y();
65  mom(2) = particle->momentum().z();
66  return mom;
67 }
68 
70  const std::shared_ptr<HepMC3::GenParticle> particle) {
71  return particle->momentum().e();
72 }
73 
75  const std::shared_ptr<HepMC3::GenParticle> particle) {
76  return particle->generated_mass();
77 }
78 
80  const std::shared_ptr<HepMC3::GenParticle> particle) {
81  return HepPID::charge(particle->pid());
82 }
83 
84 void FW::HepMC3Particle::pdgID(std::shared_ptr<HepMC3::GenParticle> particle,
85  const int pid) {
86  particle->set_pid(pid);
87 }
88 
89 void FW::HepMC3Particle::momentum(std::shared_ptr<HepMC3::GenParticle> particle,
90  const Acts::Vector3D& mom) {
91  HepMC3::FourVector fVec(mom(0), mom(1), mom(2), particle->momentum().e());
92  particle->set_momentum(fVec);
93 }
94 
95 void FW::HepMC3Particle::energy(std::shared_ptr<HepMC3::GenParticle> particle,
96  const double energy) {
97  HepMC3::FourVector fVec(particle->momentum().x(), particle->momentum().y(),
98  particle->momentum().z(), energy);
99  particle->set_momentum(fVec);
100 }
101 
102 void FW::HepMC3Particle::mass(std::shared_ptr<HepMC3::GenParticle> particle,
103  const double mass) {
104  particle->set_generated_mass(mass);
105 }