Skip to content

Support Multithreaded DD4hep Simulation #2397

Draft
rahmans1 wants to merge 7 commits into
celeritas-project:developfrom
rahmans1:mt-dd4hep-on-develop
Draft

Support Multithreaded DD4hep Simulation #2397
rahmans1 wants to merge 7 commits into
celeritas-project:developfrom
rahmans1:mt-dd4hep-on-develop

Conversation

@rahmans1

Copy link
Copy Markdown
Contributor

Title

Support Multithreaded DD4hep Simulation

Summary

This branch adds the multithreaded DD4hep support for tracks offloaded to Celeritas, including partial truth info propagation

  • Add step-death record plumbing through StepInterface, StepParams, StepStateData, DetectorSteps, and host/device copyout so terminal track state can
    be captured independently of detector hit filtering.
  • Extend GeantTrackReconstruction to preserve initial offload state, restore event-scoped primaries, expose particle IDs, and support replay of acquired
    tracks without changing the existing primary-ID model.
  • Accumulate death records in HitProcessor and replay PreUserTrackingAction/PostUserTrackingAction from LocalTransporter::Flush, applying terminal
    Celeritas state before post-tracking callbacks when available.
  • Replace the DD4hep run-action plugin path with StateDependent lifecycle hooks registered from CelerPhysics, including worker initialization for MT runs.
  • Update the DD4hep preshower example inputs for the external EIC HepMC3 workflow and add tracker-region constants needed for MC-truth linking.

Testing

  • Updated GeantTrackReconstruction unit coverage for the acquisition signature and event-scoped replay behavior.

Sakib Rahman added 5 commits May 11, 2026 11:34
Add the low-level step data needed to record terminal track states for the MT
DD4hep port. Wire the StepInterface track_death filter through StepParams,
add death record storage to StepStateData and StepStateDataImpl, and teach the
step gathering/copyout path to capture killed tracks into compact death
records.

Enable GeantSd to request primary IDs and death records so downstream replay
code can reconstruct the terminal state without changing the existing
event-scoped primary propagation model.

Prompt: "Implement the core step/death-record plumbing for the MT DD4hep port without changing the existing event-scoped primary-ID model. Add a StepInterface filter for track_death, propagate that flag through StepParams, extend StepStateDataImpl and StepStateData with death_track_id, death_primary_id, death_particle, death_pos, death_dir, death_energy, death_time, and death_valid_id, and update the resize/assignment/bool logic accordingly. Add TrackDeathRecord and death output storage to DetectorSteps, implement copy_deaths on host and device, and update StepGatherExecutor to clear stale death slots and capture terminal state for killed tracks independently of detector filtering. Update GeantSd so the step selection includes primary_id and track_death, and add or adjust tests as needed for the new fields and copyout behavior."
Assisted-by: Codex (GPT-5.5)
Extend GeantTrackReconstruction so it can preserve and restore the initial
handover state of offloaded tracks while keeping the existing event-scoped
PrimaryId model. Capture the particle ID and initial kinematics when a track
is acquired, restore the full track state for downstream processing, and add
the helper methods needed by replay.

Update the GeantTrackReconstruction unit tests to cover the new acquisition
signature and the event-scoped replay behavior.

Prompt: "Implement the GeantTrackReconstruction part of the MT DD4hep port while preserving the existing event-scoped primary propagation model. Change acquire(G4Track&) to acquire(G4Track&, ParticleId), store the particle ID and initial kinematics in AcquiredData, add restore_initial(), view_initial(), is_generator_primary(), and particle_id() support, and keep start_/init_event()-based event-scoped indexing internally. Update the GeantTrackReconstruction tests so they pass ParticleId explicitly and still verify multi-flush/event-scoped behavior."
Assisted-by: Codex (GPT-5.5)
Wire the tracking replay path that reconstitutes offloaded primaries and fires
Pre/PostUserTrackingAction callbacks during Flush. Accumulate death records in
the hit processor, replay tracking callbacks using the reconstructed
event-scoped PrimaryIds, and apply terminal death state to
PostUserTrackingAction when a matching death record exists.

Prompt: "Implement the core tracking replay path for the MT DD4hep port without changing the existing primary-ID model. Add death accumulation to HitProcessor, replay Pre/PostUserTrackingAction from LocalTransporter::Flush using the reconstructed event-scoped PrimaryIds, apply death records to the post-state before firing PostUserTrackingAction, and add the IsTrackOffloadedToCeleritas helper. Keep the DD4hep initialization changes out of this commit."
Assisted-by: Codex (GPT-5.5)
Replace the DD4hep run-action path with the StateDependent-based lifecycle
hook in CelerPhysics, remove the separate CelerRun plugin, and wire the DD4hep
build to the new initialization path.

Prompt: "Implement the DD4hep integration layer for the MT port using the Geant4 StateDependent mechanism instead of a dedicated run action. Update CelerPhysics to register the state-dependent hooks, remove the CelerRun plugin and its CMake wiring, and keep the DD4hep-specific changes isolated from the core library commits."
Assisted-by: Codex (GPT-5.5)
Update the DD4hep preshower example so it runs against the external EIC
input file instead of the particle gun, and add the tracker-region constants
required by the Geant4 particle handler for MC-truth linking.

Prompt: "Update the DD4hep example configuration so it uses the external EIC HepMC3 input file instead of the particle gun, keeps the revised EDM4HEP output configuration, and adds the tracker_region_rmax and tracker_region_zmax constants to the Preshower XML so the Geant4 particle handler can build MC-truth links without errors."
Assisted-by: Codex (GPT-5.5)
@github-actions

github-actions Bot commented May 11, 2026

Copy link
Copy Markdown

Test summary

 5 334 files   8 641 suites   6m 55s ⏱️
 1 828 tests  1 818 ✅  10 💤 0 ❌
28 633 runs  28 466 ✅ 167 💤 0 ❌

Results for commit 2ed8d77.

♻️ This comment has been updated with latest results.

Sakib Rahman added 2 commits May 11, 2026 15:49
Reconstruct Geant4 touchable state for synthetic tracks used when replaying
DD4hep tracking callbacks after Celeritas transport. The DD4hep particle
handler queries `G4Track::GetVolume()` during begin/end tracking callbacks,
but reconstructed tracks only restored identity, user information, creator
process, position, direction, time, and energy. Without a touchable,
`GetVolume()` returns null and DD4hep can dereference it while building
MC-truth state, causing the observed SIGSEGV during the multithreaded
preshower run.

Use the Geant4 tracking navigator to locate the restored track position and
attach a fresh touchable before invoking DD4hep callbacks. This is done for
the initial handoff state used by `PreUserTrackingAction` and again after
applying the Celeritas terminal state used by `PostUserTrackingAction`.
Terminal Celeritas states can legitimately be on the world boundary or just
outside the world, so failure to locate the terminal state is non-fatal and
keeps the initial touchable for DD4hep bookkeeping. This avoids copying
original `G4TouchableHandle` values, which may be null or unsafe for
handed-over tracks, while preserving the callback replay path needed for
DD4hep MC-truth bookkeeping and future Celeritas-owned secondaries.

Prompt: "Fix the DD4hep preshower crash in multithreaded Celeritas offload by making reconstructed Geant4 tracks used for DD4hep tracking callback replay provide valid touchable/volume state, while handling terminal Celeritas states that land on or outside the world boundary without aborting."

Assisted-by: Codex (GPT-5.5)
Install the DD4hep worker state-dependent initializer only when Geant4 is
running as a multithreaded application. In single-threaded runs the master
thread also transports tracks, so registering both the master and worker hooks
on that thread calls Celeritas BeginOfRunAction twice.

Prompt: "Fix the DD4hep -j 1 crash caused by duplicate StateDependent begin-run hooks calling Celeritas BeginOfRunAction twice."
Assisted-by: Codex (GPT-5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant