Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:09:46

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2024 CERN for the benefit of the Acts project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
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   // create a new G4Region
0026   G4Region* region = new G4Region(m_name);
0027 
0028   // loop over volumes and find the ones in the list
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   // create a G4ProductionCuts object and set appropriate values
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   // assign cuts to the region
0068   region->SetProductionCuts(cuts);
0069 }
0070 
0071 }  // namespace ActsExamples