19 HepMC3::GenParticlePtr actsParticleToGen(
20 const std::shared_ptr<ActsExamples::SimParticle>& actsParticle) {
22 const auto mom4 = actsParticle->fourMomentum();
23 const HepMC3::FourVector
vec(mom4[0], mom4[1], mom4[2], mom4[3]);
26 std::make_shared<HepMC3::GenParticle>(
vec, actsParticle->pdg());
27 genParticle->set_generated_mass(actsParticle->mass());
36 HepMC3::GenVertexPtr createGenVertex(
37 const std::shared_ptr<ActsExamples::SimVertex>& actsVertex) {
38 const HepMC3::FourVector
vec(
39 actsVertex->position4[0], actsVertex->position4[1],
40 actsVertex->position4[2], actsVertex->position4[3]);
43 auto genVertex = std::make_shared<HepMC3::GenVertex>(
vec);
46 for (
auto&
particle : actsVertex->incoming) {
47 HepMC3::GenParticlePtr genParticle = actsParticleToGen(
48 std::make_shared<ActsExamples::SimParticle>(
particle));
49 genVertex->add_particle_in(genParticle);
52 for (
auto&
particle : actsVertex->outgoing) {
53 HepMC3::GenParticlePtr genParticle = actsParticleToGen(
54 std::make_shared<ActsExamples::SimParticle>(
particle));
55 genVertex->add_particle_out(genParticle);
70 bool compareVertices(
const std::shared_ptr<ActsExamples::SimVertex>& actsVertex,
71 const HepMC3::GenVertexPtr& genVertex) {
74 HepMC3::FourVector genVec = genVertex->position();
75 if (actsVertex->position4[0] != genVec.x()) {
78 if (actsVertex->position4[1] != genVec.y()) {
81 if (actsVertex->position4[2] != genVec.z()) {
84 if (actsVertex->position4[3] != genVec.t()) {
87 if (actsVertex->incoming.size() != genVertex->particles_in().size()) {
90 if (actsVertex->outgoing.size() != genVertex->particles_out().size()) {
104 HepMC3::Units::MomentumUnit mom = HepMC3::Units::MomentumUnit::GEV;
106 mom = HepMC3::Units::MomentumUnit::MEV;
108 mom = HepMC3::Units::MomentumUnit::GEV;
111 std::cout <<
"Invalid unit of momentum: " << momentumUnit << std::endl;
112 std::cout <<
"Momentum unit [GeV] will be used instead" << std::endl;
115 event.set_units(mom, event.length_unit());
121 HepMC3::Units::LengthUnit len = HepMC3::Units::LengthUnit::MM;
123 len = HepMC3::Units::LengthUnit::MM;
125 len = HepMC3::Units::LengthUnit::CM;
128 std::cout <<
"Invalid unit of length: " << lengthUnit << std::endl;
129 std::cout <<
"Length unit [mm] will be used instead" << std::endl;
133 event.set_units(event.momentum_unit(), len);
138 const double deltaTime) {
140 const HepMC3::FourVector
vec(deltaPos(0), deltaPos(1), deltaPos(2),
142 event.shift_position_by(vec);
149 const HepMC3::FourVector
vec(
pos(0),
pos(1),
pos(2), time);
150 event.shift_position_to(vec);
156 const HepMC3::FourVector
vec(
pos(0),
pos(1),
pos(2), event.event_pos().t());
157 event.shift_position_to(vec);
163 const HepMC3::FourVector
vec(event.event_pos().x(),
event.event_pos().y(),
164 event.event_pos().z(),
time);
165 event.shift_position_to(vec);
173 HepMC3::GenEvent&
event,
const std::shared_ptr<SimParticle>&
particle) {
175 event.add_particle(actsParticleToGen(particle));
179 HepMC3::GenEvent&
event,
const std::shared_ptr<SimVertex>&
vertex) {
181 event.add_vertex(createGenVertex(vertex));
189 HepMC3::GenEvent&
event,
const std::shared_ptr<SimParticle>&
particle) {
190 const std::vector<HepMC3::GenParticlePtr> genParticles =
event.particles();
191 const auto id = particle->particleId();
193 for (
auto& genParticle : genParticles) {
194 if (genParticle->id() ==
id) {
196 event.remove_particle(genParticle);
203 HepMC3::GenEvent&
event,
const std::shared_ptr<SimVertex>&
vertex) {
204 const std::vector<HepMC3::GenVertexPtr> genVertices =
event.vertices();
206 for (
auto& genVertex : genVertices) {
207 if (compareVertices(vertex, genVertex)) {
209 event.remove_vertex(genVertex);
221 return (event.momentum_unit() == HepMC3::Units::MomentumUnit::MEV
228 return (event.length_unit() == HepMC3::Units::LengthUnit::MM
234 const HepMC3::GenEvent&
event) {
237 vec(0) =
event.event_pos().x();
238 vec(1) =
event.event_pos().y();
239 vec(2) =
event.event_pos().z();
245 return event.event_pos().t();
249 const HepMC3::GenEvent&
event) {
250 std::vector<SimParticle> actsParticles;
251 const std::vector<HepMC3::ConstGenParticlePtr> genParticles =
255 for (
auto& genParticle : genParticles) {
257 std::make_shared<HepMC3::GenParticle>(*genParticle)));
260 return actsParticles;
263 std::vector<std::unique_ptr<ActsExamples::SimVertex>>
265 std::vector<std::unique_ptr<SimVertex>> actsVertices;
266 const std::vector<HepMC3::ConstGenVertexPtr> genVertices =
event.vertices();
269 for (
auto& genVertex : genVertices) {
271 std::make_shared<HepMC3::GenVertex>(*genVertex)));
277 const HepMC3::GenEvent&
event) {
278 std::vector<SimParticle> actsBeams;
279 const std::vector<HepMC3::ConstGenParticlePtr> genBeams =
event.beams();
282 for (
auto& genBeam : genBeams) {
284 std::make_shared<HepMC3::GenParticle>(*genBeam)));
290 const HepMC3::GenEvent&
event) {
291 std::vector<HepMC3::ConstGenParticlePtr>
particles =
event.particles();
292 std::vector<SimParticle> fState;
299 std::make_shared<HepMC3::GenParticle>(*
particle)));