Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Some refactorings around the G4 simulation #3532

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ class Geant4Simulation final : public Geant4SimulationBase {
/// If a physics list has to be instantiated this one is chosen.
std::string physicsList = "FTFP_BERT";

std::vector<std::string> volumeMappings;

std::vector<std::string> materialMappings = {"Silicon"};

std::shared_ptr<const Acts::Volume> killVolume;
double killAfterTime = std::numeric_limits<double>::infinity();
bool killSecondaries = false;
Expand Down
10 changes: 8 additions & 2 deletions Examples/Algorithms/Geant4/src/Geant4Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ ActsExamples::Geant4Simulation::~Geant4Simulation() = default;

ActsExamples::ProcessCode ActsExamples::Geant4Simulation::execute(
const ActsExamples::AlgorithmContext& ctx) const {
Geant4SimulationBase::execute(ctx);
auto ret = Geant4SimulationBase::execute(ctx);
if (ret != ProcessCode::SUCCESS) {
return ret;
}

// Output handling: Simulation
m_outputParticlesInitial(
Expand Down Expand Up @@ -401,7 +404,10 @@ ActsExamples::Geant4MaterialRecording::~Geant4MaterialRecording() = default;

ActsExamples::ProcessCode ActsExamples::Geant4MaterialRecording::execute(
const ActsExamples::AlgorithmContext& ctx) const {
Geant4SimulationBase::execute(ctx);
const auto ret = Geant4SimulationBase::execute(ctx);
if (ret != ProcessCode::SUCCESS) {
return ret;
}

// Output handling: Material tracks
m_outputMaterialTracks(
Expand Down
3 changes: 1 addition & 2 deletions Examples/Algorithms/Geant4/src/SensitiveSteppingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ void ActsExamples::SensitiveSteppingAction::UserSteppingAction(
// Get the physical volume & check if it has the sensitive string name
const G4VPhysicalVolume* volume = track->GetVolume();
if (volume == nullptr) {
ACTS_ERROR("No volume found for track " << track->GetTrackID());
std::terminate();
benjaminhuth marked this conversation as resolved.
Show resolved Hide resolved
throw std::runtime_error("No volume found, terminate simulation");
}
std::string volumeName = volume->GetName();

Expand Down
3 changes: 3 additions & 0 deletions Examples/Io/Root/src/RootSimHitReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ RootSimHitReader::RootSimHitReader(const RootSimHitReader::Config& config,
m_inputChain->SetBranchStatus("event_id", true);

auto nEntries = static_cast<std::size_t>(m_inputChain->GetEntriesFast());
if (nEntries == 0) {
throw std::runtime_error("Did not find any entries in input file");
}

// Add the first entry
m_inputChain->GetEntry(0);
Expand Down
2 changes: 0 additions & 2 deletions Examples/Python/python/acts/examples/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,6 @@ def addGeant4(
sensitiveSurfaceMapper=sensitiveMapper,
magneticField=field,
physicsList=physicsList,
volumeMappings=volumeMappings,
materialMappings=materialMappings,
killVolume=killVolume,
killAfterTime=killAfterTime,
killSecondaries=killSecondaries,
Expand Down
2 changes: 0 additions & 2 deletions Examples/Python/src/Geant4Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ PYBIND11_MODULE(ActsPythonBindingsGeant4, mod) {
ACTS_PYTHON_MEMBER(sensitiveSurfaceMapper);
ACTS_PYTHON_MEMBER(magneticField);
ACTS_PYTHON_MEMBER(physicsList);
ACTS_PYTHON_MEMBER(volumeMappings);
ACTS_PYTHON_MEMBER(materialMappings);
ACTS_PYTHON_MEMBER(killVolume);
ACTS_PYTHON_MEMBER(killAfterTime);
ACTS_PYTHON_MEMBER(killSecondaries);
Expand Down
14 changes: 8 additions & 6 deletions Examples/Scripts/Python/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
from acts.examples.simulation import addParticleGun, addGeant4, EtaConfig
from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory

from acts.examples.dd4hep import (
DD4hepDetector,
DD4hepDetectorOptions,
DD4hepGeometryService,
)

u = acts.UnitConstants


Expand All @@ -22,6 +16,7 @@ def runGeant4(
trackingGeometry,
field,
outputDir,
materialMappings=["Silicon"],
s: acts.examples.Sequencer = None,
):
s = s or acts.examples.Sequencer(events=100, numThreads=1)
Expand All @@ -41,6 +36,7 @@ def runGeant4(
outputDirCsv=outputDir / "csv",
outputDirRoot=outputDir,
rnd=rnd,
materialMappings=materialMappings,
)
return s

Expand All @@ -59,6 +55,12 @@ def runGeant4(
field = acts.ConstantBField(acts.Vector3(0, 0, 2 * u.T))

if args.experimental:
from acts.examples.dd4hep import (
DD4hepDetector,
DD4hepDetectorOptions,
DD4hepGeometryService,
)

print(">>> Running experimental geometry <<<")
odd_xml = getOpenDataDetectorDirectory() / "xml" / "OpenDataDetector.xml"

Expand Down
33 changes: 23 additions & 10 deletions Examples/Scripts/Python/truth_tracking_kalman.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def runTruthTrackingKalman(
digiConfigFile: Path,
outputDir: Path,
inputParticlePath: Optional[Path] = None,
inputHitsPath: Optional[Path] = None,
decorators=[],
directNavigation=False,
reverseFilteringMomThreshold=0 * u.GeV,
Expand Down Expand Up @@ -46,6 +47,8 @@ def runTruthTrackingKalman(
rnd = acts.examples.RandomNumbers(seed=42)
outputDir = Path(outputDir)

logger = acts.logging.getLogger("Truth tracking example")

if inputParticlePath is None:
addParticleGun(
s,
Expand All @@ -61,9 +64,7 @@ def runTruthTrackingKalman(
rnd=rnd,
)
else:
acts.logging.getLogger("Truth tracking example").info(
"Reading particles from %s", inputParticlePath.resolve()
)
logger.info("Reading particles from %s", inputParticlePath.resolve())
assert inputParticlePath.exists()
s.addReader(
acts.examples.RootParticleReader(
Expand All @@ -72,14 +73,26 @@ def runTruthTrackingKalman(
outputParticles="particles_input",
)
)
s.addWhiteboardAlias("particles", "particles_input")

addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
enableInteractions=True,
)
if inputHitsPath is None:
addFatras(
s,
trackingGeometry,
field,
rnd=rnd,
enableInteractions=True,
)
else:
logger.info("Reading hits from %s", inputHitsPath.resolve())
assert inputHitsPath.exists()
s.addReader(
acts.examples.RootSimHitReader(
level=acts.logging.INFO,
filePath=str(inputHitsPath.resolve()),
outputSimHits="simhits",
)
)

addDigitization(
s,
Expand Down
Loading