Loading src/modules/DepositionGenerator/PrimariesGeneratorAction.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <G4Event.hh> #include <G4ParticleTable.hh> #include <G4TransportationManager.hh> #include "core/config/exceptions.h" #include "core/utils/log.h" Loading @@ -30,6 +31,15 @@ PrimariesGeneratorAction::PrimariesGeneratorAction(const Configuration&, std::sh LOG(DEBUG) << "Setting up Geant4 generator action"; } bool PrimariesGeneratorAction::check_vertex_inside_world(const G4ThreeVector& pos) const { auto* solid = G4TransportationManager::GetTransportationManager() ->GetNavigatorForTracking() ->GetWorldVolume() ->GetLogicalVolume() ->GetSolid(); return solid->Inside(pos) == kInside; } /** * Called automatically for every event */ Loading @@ -42,6 +52,12 @@ void PrimariesGeneratorAction::GeneratePrimaries(G4Event* event) { // Dispatch them to the Geant4 particle gun LOG(DEBUG) << "Primary particles generated:"; for(const auto& particle : particles) { // Check world boundary of primary vertex if(!check_vertex_inside_world(particle.position())) { LOG(WARNING) << "Vertex at " << particle.position() << " outside world volume, skipping."; continue; } auto* pdg_table = G4ParticleTable::GetParticleTable(); particle_gun_->SetParticleDefinition(pdg_table->FindParticle(particle.pdg())); particle_gun_->SetParticleEnergy(particle.energy()); Loading src/modules/DepositionGenerator/PrimariesGeneratorAction.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,13 @@ namespace allpix { void GeneratePrimaries(G4Event*) override; private: /** * @brief helper method to check if particle is to be dispateched within the defined world volume * @param pos Initial position of the primary particle * @return True if within the world volume, false otherwise */ bool check_vertex_inside_world(const G4ThreeVector& pos) const; std::unique_ptr<G4ParticleGun> particle_gun_; std::shared_ptr<PrimariesReader> reader_; }; Loading src/modules/DepositionGenerator/PrimariesReaderHepMC.cpp +2 −18 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ #include "core/module/exceptions.h" #include "core/utils/log.h" #include <G4TransportationManager.hh> #include <HepMC3/Print.h> #include <HepMC3/ReaderAscii.h> #include <HepMC3/ReaderAsciiHepMC2.h> Loading Loading @@ -48,15 +46,6 @@ PrimariesReaderHepMC::PrimariesReaderHepMC(const Configuration& config) { LOG(INFO) << "Successfully opened data file " << file_path; } bool PrimariesReaderHepMC::check_vertex_inside_world(const G4ThreeVector& pos) const { auto* solid = G4TransportationManager::GetTransportationManager() ->GetNavigatorForTracking() ->GetWorldVolume() ->GetLogicalVolume() ->GetSolid(); return solid->Inside(pos) == kInside; } std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { // Read event from input file Loading Loading @@ -91,13 +80,7 @@ std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { std::vector<Particle> particles; for(const auto& v : evt.vertices()) { // Check world boundary of primary vertex auto pos = v->position(); G4ThreeVector vertex_pos(pos.x(), pos.y(), pos.z()); if(!check_vertex_inside_world(vertex_pos)) { LOG(WARNING) << "Vertex at " << vertex_pos << " outside world volume, skipping."; continue; } // Loop over all outgoing particles of this vertex: for(const auto& p : v->particles_out()) { Loading @@ -111,7 +94,8 @@ std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { // Store particle auto momentum = G4ThreeVector(p->momentum().px(), p->momentum().py(), p->momentum().pz()); particles.emplace_back(p->pdg_id(), p->momentum().e(), momentum, vertex_pos, pos.t()); particles.emplace_back( p->pdg_id(), p->momentum().e(), momentum, G4ThreeVector(pos.x(), pos.y(), pos.z()), pos.t()); LOG(DEBUG) << "Adding particle with ID " << p->pdg_id() << " energy " << p->momentum().e(); } } Loading src/modules/DepositionGenerator/PrimariesReaderHepMC.hpp +0 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ namespace allpix { std::vector<Particle> getParticles() override; private: bool check_vertex_inside_world(const G4ThreeVector& pos) const; std::shared_ptr<HepMC3::Reader> reader_; }; } // namespace allpix Loading Loading
src/modules/DepositionGenerator/PrimariesGeneratorAction.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include <G4Event.hh> #include <G4ParticleTable.hh> #include <G4TransportationManager.hh> #include "core/config/exceptions.h" #include "core/utils/log.h" Loading @@ -30,6 +31,15 @@ PrimariesGeneratorAction::PrimariesGeneratorAction(const Configuration&, std::sh LOG(DEBUG) << "Setting up Geant4 generator action"; } bool PrimariesGeneratorAction::check_vertex_inside_world(const G4ThreeVector& pos) const { auto* solid = G4TransportationManager::GetTransportationManager() ->GetNavigatorForTracking() ->GetWorldVolume() ->GetLogicalVolume() ->GetSolid(); return solid->Inside(pos) == kInside; } /** * Called automatically for every event */ Loading @@ -42,6 +52,12 @@ void PrimariesGeneratorAction::GeneratePrimaries(G4Event* event) { // Dispatch them to the Geant4 particle gun LOG(DEBUG) << "Primary particles generated:"; for(const auto& particle : particles) { // Check world boundary of primary vertex if(!check_vertex_inside_world(particle.position())) { LOG(WARNING) << "Vertex at " << particle.position() << " outside world volume, skipping."; continue; } auto* pdg_table = G4ParticleTable::GetParticleTable(); particle_gun_->SetParticleDefinition(pdg_table->FindParticle(particle.pdg())); particle_gun_->SetParticleEnergy(particle.energy()); Loading
src/modules/DepositionGenerator/PrimariesGeneratorAction.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,13 @@ namespace allpix { void GeneratePrimaries(G4Event*) override; private: /** * @brief helper method to check if particle is to be dispateched within the defined world volume * @param pos Initial position of the primary particle * @return True if within the world volume, false otherwise */ bool check_vertex_inside_world(const G4ThreeVector& pos) const; std::unique_ptr<G4ParticleGun> particle_gun_; std::shared_ptr<PrimariesReader> reader_; }; Loading
src/modules/DepositionGenerator/PrimariesReaderHepMC.cpp +2 −18 Original line number Diff line number Diff line Loading @@ -14,8 +14,6 @@ #include "core/module/exceptions.h" #include "core/utils/log.h" #include <G4TransportationManager.hh> #include <HepMC3/Print.h> #include <HepMC3/ReaderAscii.h> #include <HepMC3/ReaderAsciiHepMC2.h> Loading Loading @@ -48,15 +46,6 @@ PrimariesReaderHepMC::PrimariesReaderHepMC(const Configuration& config) { LOG(INFO) << "Successfully opened data file " << file_path; } bool PrimariesReaderHepMC::check_vertex_inside_world(const G4ThreeVector& pos) const { auto* solid = G4TransportationManager::GetTransportationManager() ->GetNavigatorForTracking() ->GetWorldVolume() ->GetLogicalVolume() ->GetSolid(); return solid->Inside(pos) == kInside; } std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { // Read event from input file Loading Loading @@ -91,13 +80,7 @@ std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { std::vector<Particle> particles; for(const auto& v : evt.vertices()) { // Check world boundary of primary vertex auto pos = v->position(); G4ThreeVector vertex_pos(pos.x(), pos.y(), pos.z()); if(!check_vertex_inside_world(vertex_pos)) { LOG(WARNING) << "Vertex at " << vertex_pos << " outside world volume, skipping."; continue; } // Loop over all outgoing particles of this vertex: for(const auto& p : v->particles_out()) { Loading @@ -111,7 +94,8 @@ std::vector<PrimariesReader::Particle> PrimariesReaderHepMC::getParticles() { // Store particle auto momentum = G4ThreeVector(p->momentum().px(), p->momentum().py(), p->momentum().pz()); particles.emplace_back(p->pdg_id(), p->momentum().e(), momentum, vertex_pos, pos.t()); particles.emplace_back( p->pdg_id(), p->momentum().e(), momentum, G4ThreeVector(pos.x(), pos.y(), pos.z()), pos.t()); LOG(DEBUG) << "Adding particle with ID " << p->pdg_id() << " energy " << p->momentum().e(); } } Loading
src/modules/DepositionGenerator/PrimariesReaderHepMC.hpp +0 −2 Original line number Diff line number Diff line Loading @@ -37,8 +37,6 @@ namespace allpix { std::vector<Particle> getParticles() override; private: bool check_vertex_inside_world(const G4ThreeVector& pos) const; std::shared_ptr<HepMC3::Reader> reader_; }; } // namespace allpix Loading