Warning, file /acts/Examples/Io/HepMC3/src/HepMC3Vertex.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/HepMC3/HepMC3Vertex.hpp"
0010
0011 #include "ActsExamples/EventData/SimParticle.hpp"
0012 #include "ActsExamples/EventData/SimVertex.hpp"
0013 #include "ActsExamples/Io/HepMC3/HepMC3Particle.hpp"
0014
0015 namespace ActsExamples {
0016
0017 namespace {
0018
0019
0020
0021
0022 SimBarcodeContainer genBarcodeToActs(
0023 const std::vector<HepMC3::GenParticlePtr>& genParticles) {
0024 SimBarcodeContainer actsBarcodes;
0025
0026 for (auto& genParticle : genParticles) {
0027 actsBarcodes.insert(HepMC3Particle::barcode(
0028 std::make_shared<HepMC3::GenParticle>(*genParticle)));
0029 }
0030 return actsBarcodes;
0031 }
0032
0033
0034
0035
0036 std::vector<SimParticle> genParticlesToActs(
0037 const std::vector<HepMC3::GenParticlePtr>& genParticles) {
0038 std::vector<SimParticle> actsParticles;
0039
0040 for (auto& genParticle : genParticles) {
0041 actsParticles.push_back(HepMC3Particle::particle(
0042 std::make_shared<HepMC3::GenParticle>(*genParticle)));
0043 }
0044 return actsParticles;
0045 }
0046
0047
0048
0049
0050
0051 HepMC3::GenParticlePtr actsParticleToGen(
0052 const std::shared_ptr<SimParticle>& actsParticle) {
0053
0054 const auto mom = actsParticle->fourMomentum();
0055 const HepMC3::FourVector vec(mom[0], mom[1], mom[2], mom[3]);
0056
0057 auto genParticle =
0058 std::make_shared<HepMC3::GenParticle>(vec, actsParticle->pdg());
0059 genParticle->set_generated_mass(actsParticle->mass());
0060
0061 return genParticle;
0062 }
0063
0064
0065
0066
0067
0068
0069
0070 HepMC3::GenParticlePtr matchParticles(
0071 const std::vector<HepMC3::GenParticlePtr>& genParticles,
0072 const std::shared_ptr<SimParticle>& actsParticle) {
0073 const auto id = actsParticle->particleId();
0074
0075 for (auto& genParticle : genParticles) {
0076 if (genParticle->id() == id) {
0077
0078 return genParticle;
0079 }
0080 }
0081 return nullptr;
0082 }
0083
0084 }
0085
0086 std::unique_ptr<SimVertex> HepMC3Vertex::processVertex(
0087 const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0088 SimVertex vtx(SimVertexBarcode().setVertexPrimary(vertex->id()),
0089 {vertex->position().x(), vertex->position().y(),
0090 vertex->position().z(), vertex->position().t()});
0091 vtx.incoming = genBarcodeToActs(vertex->particles_in());
0092 vtx.outgoing = genBarcodeToActs(vertex->particles_out());
0093
0094 return std::make_unique<SimVertex>(std::move(vtx));
0095 }
0096
0097 bool HepMC3Vertex::inEvent(const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0098 return vertex->in_event();
0099 }
0100
0101 int HepMC3Vertex::id(const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0102 return vertex->id();
0103 }
0104
0105 std::vector<SimParticle> HepMC3Vertex::particlesIn(
0106 const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0107 return genParticlesToActs(vertex->particles_in());
0108 }
0109
0110 std::vector<SimParticle> HepMC3Vertex::particlesOut(
0111 const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0112 return genParticlesToActs(vertex->particles_out());
0113 }
0114
0115 Acts::Vector3 HepMC3Vertex::position(
0116 const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0117 Acts::Vector3 vec;
0118 vec(0) = vertex->position().x();
0119 vec(1) = vertex->position().y();
0120 vec(2) = vertex->position().z();
0121 return vec;
0122 }
0123
0124 double HepMC3Vertex::time(const std::shared_ptr<HepMC3::GenVertex>& vertex) {
0125 return vertex->position().t();
0126 }
0127
0128 void HepMC3Vertex::addParticleIn(
0129 const std::shared_ptr<HepMC3::GenVertex>& vertex,
0130 const std::shared_ptr<SimParticle>& particle) {
0131 vertex->add_particle_in(actsParticleToGen(particle));
0132 }
0133
0134 void HepMC3Vertex::addParticleOut(
0135 const std::shared_ptr<HepMC3::GenVertex>& vertex,
0136 const std::shared_ptr<SimParticle>& particle) {
0137 vertex->add_particle_out(actsParticleToGen(particle));
0138 }
0139
0140 void HepMC3Vertex::removeParticleIn(
0141 const std::shared_ptr<HepMC3::GenVertex>& vertex,
0142 const std::shared_ptr<SimParticle>& particle) {
0143
0144 if (HepMC3::GenParticlePtr genParticle =
0145 matchParticles(vertex->particles_in(), particle)) {
0146 vertex->remove_particle_in(genParticle);
0147 }
0148 }
0149
0150 void HepMC3Vertex::removeParticleOut(
0151 const std::shared_ptr<HepMC3::GenVertex>& vertex,
0152 const std::shared_ptr<SimParticle>& particle) {
0153
0154 if (HepMC3::GenParticlePtr genParticle =
0155 matchParticles(vertex->particles_out(), particle)) {
0156 vertex->remove_particle_out(genParticle);
0157 }
0158 }
0159
0160 void HepMC3Vertex::position(const std::shared_ptr<HepMC3::GenVertex>& vertex,
0161 const Acts::Vector3& pos) {
0162 HepMC3::FourVector fVec(pos(0), pos(1), pos(2), vertex->position().t());
0163 vertex->set_position(fVec);
0164 }
0165
0166 void HepMC3Vertex::time(const std::shared_ptr<HepMC3::GenVertex>& vertex,
0167 double time) {
0168 HepMC3::FourVector fVec(vertex->position().x(), vertex->position().y(),
0169 vertex->position().z(), time);
0170 vertex->set_position(fVec);
0171 }
0172
0173 }