ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMC3Vertex.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMC3Vertex.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::vector<FW::SimParticle> FW::HepMC3Vertex::genParticlesToActs(
14  const std::vector<HepMC3::GenParticlePtr>& genParticles) {
15  HepMC3Particle simPart;
16 
17  std::vector<SimParticle> actsParticles;
18  // Translate all particles
19  for (auto& genParticle : genParticles)
20  actsParticles.push_back(*(
21  simPart.particle(std::make_shared<HepMC3::GenParticle>(*genParticle))));
22  return actsParticles;
23 }
24 
25 std::unique_ptr<FW::SimVertex> FW::HepMC3Vertex::processVertex(
26  const std::shared_ptr<HepMC3::GenVertex> vertex) {
27  SimVertex vtx({vertex->position().x(), vertex->position().y(),
28  vertex->position().z(), vertex->position().t()});
29  vtx.incoming = genParticlesToActs(vertex->particles_in());
30  vtx.outgoing = genParticlesToActs(vertex->particles_out());
31  // Create Acts vertex
32  return std::make_unique<SimVertex>(std::move(vtx));
33 }
34 
36  const std::shared_ptr<HepMC3::GenVertex> vertex) {
37  return vertex->in_event();
38 }
39 
40 int FW::HepMC3Vertex::id(const std::shared_ptr<HepMC3::GenVertex> vertex) {
41  return vertex->id();
42 }
43 
44 std::vector<FW::SimParticle> FW::HepMC3Vertex::particlesIn(
45  const std::shared_ptr<HepMC3::GenVertex> vertex) {
46  return genParticlesToActs(vertex->particles_in());
47 }
48 
49 std::vector<FW::SimParticle> FW::HepMC3Vertex::particlesOut(
50  const std::shared_ptr<HepMC3::GenVertex> vertex) {
51  return genParticlesToActs(vertex->particles_out());
52 }
53 
55  const std::shared_ptr<HepMC3::GenVertex> vertex) {
56  Acts::Vector3D vec;
57  vec(0) = vertex->position().x();
58  vec(1) = vertex->position().y();
59  vec(2) = vertex->position().z();
60  return vec;
61 }
62 
63 double FW::HepMC3Vertex::time(const std::shared_ptr<HepMC3::GenVertex> vertex) {
64  return vertex->position().t();
65 }
66 
67 HepMC3::GenParticlePtr FW::HepMC3Vertex::actsParticleToGen(
68  std::shared_ptr<SimParticle> actsParticle) {
69  // Extract momentum and energy from Acts particle for HepMC3::FourVector
70  const auto mom = actsParticle->momentum4();
71  const HepMC3::FourVector vec(mom[0], mom[1], mom[2], mom[3]);
72  // Create HepMC3::GenParticle
73  HepMC3::GenParticle genParticle(vec, actsParticle->pdg());
74  genParticle.set_generated_mass(actsParticle->mass());
75 
76  return std::shared_ptr<HepMC3::GenParticle>(&genParticle);
77 }
78 
79 void FW::HepMC3Vertex::addParticleIn(std::shared_ptr<HepMC3::GenVertex> vertex,
80  std::shared_ptr<SimParticle> particle) {
81  vertex->add_particle_in(actsParticleToGen(particle));
82 }
83 
84 void FW::HepMC3Vertex::addParticleOut(std::shared_ptr<HepMC3::GenVertex> vertex,
85  std::shared_ptr<SimParticle> particle) {
86  vertex->add_particle_out(actsParticleToGen(particle));
87 }
88 
89 HepMC3::GenParticlePtr FW::HepMC3Vertex::matchParticles(
90  const std::vector<HepMC3::GenParticlePtr>& genParticles,
91  std::shared_ptr<SimParticle> actsParticle) {
92  const auto id = actsParticle->particleId();
93  // Search HepMC3::GenParticle with the same id as the Acts particle
94  for (auto& genParticle : genParticles) {
95  if (genParticle->id() == id) {
96  // Return particle if found
97  return genParticle;
98  }
99  }
100  return nullptr;
101 }
102 
104  std::shared_ptr<HepMC3::GenVertex> vertex,
105  std::shared_ptr<SimParticle> particle) {
106  // Remove particle if it exists
107  if (HepMC3::GenParticlePtr genParticle =
108  matchParticles(vertex->particles_in(), particle))
109  vertex->remove_particle_in(genParticle);
110 }
111 
113  std::shared_ptr<HepMC3::GenVertex> vertex,
114  std::shared_ptr<SimParticle> particle) {
115  // Remove particle if it exists
116  if (HepMC3::GenParticlePtr genParticle =
117  matchParticles(vertex->particles_out(), particle))
118  vertex->remove_particle_out(genParticle);
119 }
120 
121 void FW::HepMC3Vertex::position(const std::shared_ptr<HepMC3::GenVertex> vertex,
123  HepMC3::FourVector fVec(pos(0), pos(1), pos(2), vertex->position().t());
124  vertex->set_position(fVec);
125 }
126 
127 void FW::HepMC3Vertex::time(const std::shared_ptr<HepMC3::GenVertex> vertex,
128  double time) {
129  HepMC3::FourVector fVec(vertex->position().x(), vertex->position().y(),
130  vertex->position().z(), time);
131  vertex->set_position(fVec);
132 }