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<ActsExamples::SimParticle>
15  const std::vector<HepMC3::GenParticlePtr>& genParticles) {
16  HepMC3Particle simPart;
17 
18  std::vector<SimParticle> actsParticles;
19  // Translate all particles
20  for (auto& genParticle : genParticles)
21  actsParticles.push_back(*(
22  simPart.particle(std::make_shared<HepMC3::GenParticle>(*genParticle))));
23  return actsParticles;
24 }
25 
26 std::unique_ptr<ActsExamples::SimVertex>
28  const std::shared_ptr<HepMC3::GenVertex> vertex) {
29  SimVertex vtx({vertex->position().x(), vertex->position().y(),
30  vertex->position().z(), vertex->position().t()});
31  vtx.incoming = genParticlesToActs(vertex->particles_in());
32  vtx.outgoing = genParticlesToActs(vertex->particles_out());
33  // Create Acts vertex
34  return std::make_unique<SimVertex>(std::move(vtx));
35 }
36 
38  const std::shared_ptr<HepMC3::GenVertex> vertex) {
39  return vertex->in_event();
40 }
41 
43  const std::shared_ptr<HepMC3::GenVertex> vertex) {
44  return vertex->id();
45 }
46 
47 std::vector<ActsExamples::SimParticle> ActsExamples::HepMC3Vertex::particlesIn(
48  const std::shared_ptr<HepMC3::GenVertex> vertex) {
49  return genParticlesToActs(vertex->particles_in());
50 }
51 
52 std::vector<ActsExamples::SimParticle> ActsExamples::HepMC3Vertex::particlesOut(
53  const std::shared_ptr<HepMC3::GenVertex> vertex) {
54  return genParticlesToActs(vertex->particles_out());
55 }
56 
58  const std::shared_ptr<HepMC3::GenVertex> vertex) {
59  Acts::Vector3D vec;
60  vec(0) = vertex->position().x();
61  vec(1) = vertex->position().y();
62  vec(2) = vertex->position().z();
63  return vec;
64 }
65 
67  const std::shared_ptr<HepMC3::GenVertex> vertex) {
68  return vertex->position().t();
69 }
70 
72  std::shared_ptr<SimParticle> actsParticle) {
73  // Extract momentum and energy from Acts particle for HepMC3::FourVector
74  const auto mom = actsParticle->momentum4();
75  const HepMC3::FourVector vec(mom[0], mom[1], mom[2], mom[3]);
76  // Create HepMC3::GenParticle
77  HepMC3::GenParticle genParticle(vec, actsParticle->pdg());
78  genParticle.set_generated_mass(actsParticle->mass());
79 
80  return std::shared_ptr<HepMC3::GenParticle>(&genParticle);
81 }
82 
84  std::shared_ptr<HepMC3::GenVertex> vertex,
85  std::shared_ptr<SimParticle> particle) {
86  vertex->add_particle_in(actsParticleToGen(particle));
87 }
88 
90  std::shared_ptr<HepMC3::GenVertex> vertex,
91  std::shared_ptr<SimParticle> particle) {
92  vertex->add_particle_out(actsParticleToGen(particle));
93 }
94 
96  const std::vector<HepMC3::GenParticlePtr>& genParticles,
97  std::shared_ptr<SimParticle> actsParticle) {
98  const auto id = actsParticle->particleId();
99  // Search HepMC3::GenParticle with the same id as the Acts particle
100  for (auto& genParticle : genParticles) {
101  if (genParticle->id() == id) {
102  // Return particle if found
103  return genParticle;
104  }
105  }
106  return nullptr;
107 }
108 
110  std::shared_ptr<HepMC3::GenVertex> vertex,
111  std::shared_ptr<SimParticle> particle) {
112  // Remove particle if it exists
113  if (HepMC3::GenParticlePtr genParticle =
114  matchParticles(vertex->particles_in(), particle))
115  vertex->remove_particle_in(genParticle);
116 }
117 
119  std::shared_ptr<HepMC3::GenVertex> vertex,
120  std::shared_ptr<SimParticle> particle) {
121  // Remove particle if it exists
122  if (HepMC3::GenParticlePtr genParticle =
123  matchParticles(vertex->particles_out(), particle))
124  vertex->remove_particle_out(genParticle);
125 }
126 
128  const std::shared_ptr<HepMC3::GenVertex> vertex, Acts::Vector3D pos) {
129  HepMC3::FourVector fVec(pos(0), pos(1), pos(2), vertex->position().t());
130  vertex->set_position(fVec);
131 }
132 
134  const std::shared_ptr<HepMC3::GenVertex> vertex, double time) {
135  HepMC3::FourVector fVec(vertex->position().x(), vertex->position().y(),
136  vertex->position().z(), time);
137  vertex->set_position(fVec);
138 }