Skip to content

Add o2-sim-geometry-doctor, a geometry against field audit - #15683

Merged
sawenzel merged 1 commit into
AliceO2Group:devfrom
sawenzel:geometry-doctor
Aug 18, 2026
Merged

Add o2-sim-geometry-doctor, a geometry against field audit#15683
sawenzel merged 1 commit into
AliceO2Group:devfrom
sawenzel:geometry-doctor

Conversation

@sawenzel

@sawenzel sawenzel commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

This commit provides a new tool o2-sim-geometry-doctor that reads a placed geometry and a magnetic field and reports where the two do not fit together: logical volumes placed both inside and outside the field, mothers whose own material straddles the boundary, daughter clusters that would need a container of their own, and media asking for straight-line transport while sitting in real field.

The tool was motivated from the idea to check the consistency of geometry and Geant4 media properties against the properties of the magnetic field, and to potentially optimize this assignment in a second step. It is related to these O2 JIRA tickets:

https://its.cern.ch/jira/browse/O2-174
https://its.cern.ch/jira/browse/O2-175
https://its.cern.ch/jira/browse/O2-181

In the future it can be extended to provide automatic repair PRs.

It:

  • builds an outer bound on the field support per threshold, phi sampled by arc length and every threshold crossing bisected, and checks the bound against the field before using it
  • concludes field-free from geometry only; sampling is used only to disprove
  • takes placement extents from the shapes, testing TGeoEltu before TGeoTube
  • verifies a field read from a file against stored reference vectors and repairs the polarity inversion re-initialisation introduces
  • reads the ifield and sensitivity flags from the geometry file itself, so it links no detector code and no simulation engine
  • ships the ALICE anchor verdicts for --verify-anchors

Example:

o2-sim-geometry-doctor --geometry-file o2sim_geometry.root --field-current -5

writes geometry-doctor-proposals.json (findings with suggested actions), geometry-doctor-placements.csv (one classified row per placement) and geometry-doctor-report.txt, and prints the report.

This commit provides a new tool o2-sim-geometry-doctor that reads a placed
geometry and a magnetic field and reports where the two do not fit together:
logical volumes placed both inside and outside the field, mothers whose own
material straddles the boundary, daughter clusters that would need a container
of their own, and media asking for straight-line transport while sitting in
real field.

The tool was motivated from the idea to check the consistency of geometry and
Geant4 media properties against the properties of the magnetic field, and to
potentially optimize this assignment in a second step. It is related to these
O2 JIRA tickets:

  https://its.cern.ch/jira/browse/O2-174
  https://its.cern.ch/jira/browse/O2-175
  https://its.cern.ch/jira/browse/O2-181

In the future it can be extended to provide automatic repair PRs.

It:
- builds an outer bound on the field support per threshold, phi sampled by
  arc length and every threshold crossing bisected, and checks the bound
  against the field before using it
- concludes field-free from geometry only; sampling is used only to disprove
- takes placement extents from the shapes, testing TGeoEltu before TGeoTube
- verifies a field read from a file against stored reference vectors and
  repairs the polarity inversion re-initialisation introduces
- reads the ifield and sensitivity flags from the geometry file itself, so it
  links no detector code and no simulation engine
- ships the ALICE anchor verdicts for --verify-anchors

Example:

  o2-sim-geometry-doctor --geometry-file o2sim_geometry.root --field-current -5

writes geometry-doctor-proposals.json (findings with suggested actions),
geometry-doctor-placements.csv (one classified row per placement) and
geometry-doctor-report.txt, and prints the report.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
@sawenzel
sawenzel requested a review from a team as a code owner August 16, 2026 18:53
@sawenzel
sawenzel requested a review from amorsch August 16, 2026 19:00
@alibuild

Copy link
Copy Markdown
Collaborator

Error while checking build/O2/fullCI_slc9 for 4a455a8 at 2026-08-17 08:56:

## sw/BUILD/o2codechecker-latest/log
100% tests passed, 0 tests failed out of 1


## sw/BUILD/ThePEG-latest/log
collect2: error: ld returned 1 exit status


## sw/BUILD/O2Physics-latest/log
c++: fatal error: Killed signal terminated program cc1plus
c++: fatal error: Killed signal terminated program cc1plus
ninja: build stopped: subcommand failed.

Full log here.

sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
A tracking medium belongs to a logical volume, but sitting inside the magnetic
field is a property of a placement. The beam pipe makes the conflict concrete:
the same warm module and the same bellow are installed inside the barrel, where
the solenoid fringe is still several kGauss, and again ten metres down the beam
line, where the field map returns exactly zero. One set of volumes cannot state
both, so a module author picks the answer that is right more often and the
remaining placements are transported either wrongly or expensively.

The bug fix in fix-nf-media-in-field settles that conflict in favour of
correctness and pays for it at the far end of the beam line, where a field that
is genuinely zero is now integrated rather than skipped. This series gives those
placements volumes of their own and takes the shortcut back for them alone.

This commit gives passive modules the second logical volume they need.
MaterialManager::cloneSubtreeWithMediumSuffix copies a subtree and remaps every
medium to a field-free variant.

- Shapes and placement matrices are shared with the original, so a clone is the
  same geometry differently flagged and adds no placements.
- fieldFreeVariantOf prefers the hand-written counterparts the passive modules
  already ship (PIPE_INOX_NF beside PIPE_INOX, PIPE_VACUUM_NFHC for the
  high-cut flavours) and derives one only where none exists.
- Clones are cached per volume and suffix, so a subtree reached twice yields one
  copy rather than two volumes of the same name.
- Cloning refuses outright if the subtree contains a sensitive volume: hits are
  recorded against geometry paths, and a second set of paths for the same
  detector would silently change what alignment and digitisation look at.

The placements that need this, and the media that are wrong without it, were
found with the o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Related tickets:
https://its.cern.ch/jira/browse/O2-174
https://its.cern.ch/jira/browse/O2-175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
… field

Not every case needs a second logical volume. The short RB24/2 tubes, the RB26/5
compensator with its flange, and the SAA2/SAA3 shielding each have a single
placement, or several placements that are all in the clear, so their media are
simply wrong wherever they are used rather than right in one place and wrong in
another.

This commit switches them to field-free media in place. The pipe modules have
hand-written counterparts to move to; the shielding does not, so SAA3 asks
MaterialManager to derive one -- same material, same cuts, no field -- which is
also the first exercise of that path, as the pipe changes never take it. RB26/4
sits partly inside the muon dipole and is deliberately untouched, as is the near
copy of every RB24 module. Field calls in the reassigned volumes go to zero.

Found with the o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
This commit provides a helper MaterialManager::cloneSubtreeWithMediumSuffix
for passive modules. A tracking medium belongs to a logical volume, but being
inside the magnetic field is a property of a placement. The beam pipe places
the same modules inside the solenoid fringe field and again ten metres down
the beam line where the field is zero. One logical volume cannot describe both
cases. The helper clones a subtree and remaps every medium to a field-free
variant, so that field-free placements can use the clone.

Details:
- shapes and placement matrices are shared with the original
- existing hand-written _NF media are preferred, new ones are derived only
  where none exists
- clones are cached per volume and suffix
- cloning refuses subtrees containing sensitive volumes, because hits are
  recorded against geometry paths

This builds on the bug fix in fix-nf-media-in-field and prepares restoring the
optimization it gave up. The affected placements were found with the
o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Related tickets:
https://its.cern.ch/jira/browse/O2-174
https://its.cern.ch/jira/browse/O2-175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
This switches modules whose placements are all outside the field to field-free
media in place. The short RB24/2 tubes, the RB26/5 compensator with its
flange, and the SAA2/SAA3 shielding need no second volume, because none of
their placements is in the field. The pipe modules move to their existing
hand-written counterparts. SAA3 has none, so a field-free medium is derived by
MaterialManager. RB26/4 reaches into the muon dipole and is left unchanged.
Field calls in the reassigned volumes go to zero.

Found with the o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
This fixes a problem in the beam pipe media assignment, diagnosed with the
o2-sim-geometry-doctor tool (AliceO2Group#15683).
22 volumes of the RB24 warm module, its ion pump and its B1 bellow, and the
air shell at r = 79-80 cm, carried media labelled out-of-field, whereas their
placements at z = 400-490 cm are inside the 4.2-4.6 kGauss solenoid fringe
field. Geant4 honours the label and moved particles through these volumes on
straight lines, about 171000 steps per min-bias event.

This is now fixed by assigning the in-field counterpart media at the
construction site of these volumes. After the change no step in a field-free
volume sees a non-zero field. The same volumes are also placed far down the
beam line where the field really is zero. These placements now integrate the
field too, which is correct but slower. A follow-up gives them cloned volumes
of their own and restores the shortcut.

Related tickets:
https://its.cern.ch/jira/browse/O2-174
https://its.cern.ch/jira/browse/O2-175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
This commit provides a helper MaterialManager::cloneSubtreeWithMediumSuffix
for passive modules. A tracking medium belongs to a logical volume, but being
inside the magnetic field is a property of a placement. The beam pipe places
the same modules inside the solenoid fringe field and again ten metres down
the beam line where the field is zero. One logical volume cannot describe both
cases. The helper clones a subtree and remaps every medium to a field-free
variant, so that field-free placements can use the clone.

Details:
- shapes and placement matrices are shared with the original
- existing hand-written _NF media are preferred, new ones are derived only
  where none exists
- clones are cached per volume and suffix
- cloning refuses subtrees containing sensitive volumes, because hits are
  recorded against geometry paths

This builds on the bug fix in fix-nf-media-in-field and prepares restoring the
optimization it gave up. The affected placements were found with the
o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Related tickets:
https://its.cern.ch/jira/browse/O2-174
https://its.cern.ch/jira/browse/O2-175

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 17, 2026
This switches modules whose placements are all outside the field to field-free
media in place. The short RB24/2 tubes, the RB26/5 compensator with its
flange, and the SAA2/SAA3 shielding need no second volume, because none of
their placements is in the field. The pipe modules move to their existing
hand-written counterparts. SAA3 has none, so a field-free medium is derived by
MaterialManager. RB26/4 reaches into the muon dipole and is left unchanged.
Field calls in the reassigned volumes go to zero.

Found with the o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
@sawenzel
sawenzel merged commit 7c7b0ae into AliceO2Group:dev Aug 18, 2026
9 of 10 checks passed
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 19, 2026
The L3 magnet structure, the compensator coils and their supports sit outside the
region the field map covers. They were built from media that declare a magnetic
field, so Geant4 integrates a field there that always evaluates to zero.
Compensator.cxx already declared a field-free flag for exactly this case and
never used it.

Seventeen volumes are now tracked without a field. Five media whose every
placement lies outside the field are switched in place. Three volumes share their
medium with volumes that do reach the field, so they get a field-free variant of
that medium instead: the horizontal compensator coil, the L3 yoke and the L3
crown.

A new medium also needs its own line in the module's simcuts file. Without one it
falls back to the global default cuts, and because Geant4 assigns production cuts
per material rather than per medium, the material's other medium falls back with
it. COMP 18 therefore repeats the cuts of COMP 17.

The volumes were found with the o2-sim-geometry-doctor tool
(AliceO2Group#15683).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0178JHAQ2biaX5ac9ThppBXi
sawenzel added a commit to sawenzel/AliceO2 that referenced this pull request Aug 19, 2026
This changes the media of volumes that sit outside the field map, diagnosed with
the geometry doctor. 17 volumes were built from media that declare a magnetic
field, whereas the field there is always zero. This is now fixed by switching
five media in place, and by giving a field-free variant to the three volumes
whose medium is shared with volumes that do reach the field.

The new copper medium also needs its own line in simcuts_COMP.dat, because
Geant4 assigns cuts per material and it would otherwise take the default ones.

AliceO2Group#15683

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants