19 #include <FTFP_BERT.hh>
20 #include <G4RunManager.hh>
21 #include <G4VUserDetectorConstruction.hh>
22 #include <HepMC3/GenParticle.h>
36 : ActsExamples::
IAlgorithm(
"EventRecording", level),
38 m_runManager(std::make_unique<G4RunManager>()) {
40 throw std::invalid_argument(
"Missing input particle collection");
43 throw std::invalid_argument(
"Missing output event collection");
46 throw std::invalid_argument(
"Missing detector construction object");
72 std::lock_guard<std::mutex> guard(m_runManagerLock);
75 const auto initialParticles = m_inputParticles(context);
78 std::vector<HepMC3::GenEvent>
events;
79 events.reserve(initialParticles.size());
81 for (
const auto& part : initialParticles) {
87 m_runManager->BeamOn(1);
95 HepMC3::GenEvent
event =
98 event.shift_position_by(shift);
103 HepMC3::FourVector beamMom4(momentum4[0], momentum4[1], momentum4[2],
105 auto beamParticle =
event.particles()[0];
106 beamParticle->set_momentum(beamMom4);
107 beamParticle->set_pid(part.pdg());
109 if (
m_cfg.processSelect.empty()) {
113 bool storeEvent =
false;
117 vertex->add_particle_in(beamParticle);
119 const std::vector<std::string> vertexAttributes =
120 vertex->attribute_names();
121 for (
const auto& att : vertexAttributes) {
122 if ((
vertex->attribute_as_string(att).find(
m_cfg.processSelect) !=
123 std::string::npos) &&
124 !
vertex->particles_in().empty() &&
125 vertex->particles_in()[0]->attribute<HepMC3::IntAttribute>(
128 ->attribute<HepMC3::IntAttribute>(
"TrackID")
144 for (
const auto&
v :
event.vertices()) {
148 if (
v->particles_out().empty()) {
149 event.remove_vertex(
v);
153 for (
const auto&
p :
event.particles()) {
157 if (!
p->production_vertex()) {
158 event.remove_particle(
p);
171 ACTS_INFO(initialParticles.size() <<
" initial particles provided");
172 ACTS_INFO(events.size() <<
" tracks generated");
175 m_outputEvents(context,
std::move(events));