File indexing completed on 2025-08-05 08:09:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geant4/RegionCreator.hpp"
0010
0011 #include <G4LogicalVolume.hh>
0012 #include <G4LogicalVolumeStore.hh>
0013 #include <G4ProductionCuts.hh>
0014 #include <G4Region.hh>
0015
0016 namespace ActsExamples {
0017
0018 RegionCreator::RegionCreator(const Config& cfg, std::string name,
0019 Acts::Logging::Level level)
0020 : m_name(std::move(name)),
0021 m_cfg(cfg),
0022 m_logger(Acts::getDefaultLogger(m_name, level)) {}
0023
0024 void RegionCreator::Construct() {
0025
0026 G4Region* region = new G4Region(m_name);
0027
0028
0029 std::size_t nVolumes{0};
0030 G4LogicalVolumeStore* logStore = G4LogicalVolumeStore::GetInstance();
0031 for (const std::string& volumeName : m_cfg.volumes) {
0032 std::size_t nVolumesCurrent{0};
0033 for (auto* it : *logStore) {
0034 ACTS_DEBUG("Checking volume " << it->GetName() << " against "
0035 << volumeName);
0036 if (volumeName == static_cast<const std::string&>(it->GetName())) {
0037 nVolumesCurrent++;
0038 it->SetRegion(region);
0039 region->AddRootLogicalVolume(it);
0040 ACTS_DEBUG("Volume " << it->GetName() << " added to region");
0041 }
0042 }
0043 if (nVolumesCurrent == 0) {
0044 ACTS_WARNING("No volumes matching \""
0045 << volumeName << "\" found in G4 LogicalVolumeStore. "
0046 << m_name << " G4PhysicsRegion may not behave as intended.");
0047 }
0048 nVolumes += nVolumesCurrent;
0049 }
0050
0051 ACTS_INFO("Created region " << m_name);
0052 ACTS_INFO("A total of " << nVolumes << " volumes were assigned");
0053
0054
0055 G4ProductionCuts* cuts = new G4ProductionCuts();
0056 cuts->SetProductionCut(m_cfg.gammaCut, "gamma");
0057 cuts->SetProductionCut(m_cfg.electronCut, "e-");
0058 cuts->SetProductionCut(m_cfg.positronCut, "e+");
0059 cuts->SetProductionCut(m_cfg.protonCut, "proton");
0060
0061 ACTS_INFO("Setting production cuts to");
0062 ACTS_INFO(" gamma: " << m_cfg.gammaCut);
0063 ACTS_INFO(" e-: " << m_cfg.electronCut);
0064 ACTS_INFO(" e+: " << m_cfg.positronCut);
0065 ACTS_INFO(" proton: " << m_cfg.protonCut);
0066
0067
0068 region->SetProductionCuts(cuts);
0069 }
0070
0071 }