Skip to content

Change element name to fix ROOT parser#51

Closed
antonioiuliano2 wants to merge 2 commits into
mainfrom
fix_ROOT_import
Closed

Change element name to fix ROOT parser#51
antonioiuliano2 wants to merge 2 commits into
mainfrom
fix_ROOT_import

Conversation

@antonioiuliano2

@antonioiuliano2 antonioiuliano2 commented Jul 1, 2026

Copy link
Copy Markdown

Hello,
The ROOT GDML parser does not read correctly the materials having the same names as the elements. I see empty mixtures, without any element.

gGeoManager->GetListOfMaterials()->Print()
------
 Mixture Tungsten    Aeff=0 Zeff=0 rho=19.3 radlen=0 intlen=0 index=1
------

This makes the material transparent when gevgen_fnal uses ROOT to import our geometry.
By changing the element name (here I just added a _E to all elements, but any naming convention can be used), the issue is fixed:

root [1] gGeoManager->GetListOfMaterials()->Print()
------
 Mixture Tungsten    Aeff=183.842 Zeff=74 rho=19.3 radlen=0.350697 intlen=10.3097 index=1
   Element #0 : Tungsten_E  Z= 74.00 A=183.84 w= 1.000
------

I link also the reference to GDML parser used in ROOT, since it may guide us in understanding what causes the issue in the first place: https://root.cern/doc/master/classTGDMLParse.html#a0cc936290c83a556baf53f0478bbf794

All the best,
Antonio

Summary by CodeRabbit

  • Bug Fixes

    • Fixed material import by aligning element naming consistently, improving ROOT compatibility.
    • Updated built-in element and material definitions to use the matching element keys (including air, concrete, vacuum, metals, and composites).
    • Corrected ingredient references for compound materials and mixtures such as PVT, Polystyrene, Mylar, and ArCO2 70/30.
  • Documentation

    • Updated Doxygen examples for element-name parameters to reflect the corrected naming format.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 977b82c6-8be1-43c4-96c9-5014e675f41c

📥 Commits

Reviewing files that changed from the base of the PR and between a2f55c3 and 72751d7.

📒 Files selected for processing (1)
  • include/SHiPGeometry/SHiPMaterials.h
✅ Files skipped from review due to trivial changes (1)
  • include/SHiPGeometry/SHiPMaterials.h

📝 Walkthrough

Walkthrough

Element keys in SHiPMaterials.cpp are renamed with an _E suffix, and all corresponding material ingredient lookups are updated to use the new names. The changelog and getElement documentation are updated to match.

Changes

Element Key Renaming Fix

Layer / File(s) Summary
Element definitions with _E suffix
src/SHiPMaterials.cpp
createElements() now creates GeoElement entries using *_E-suffixed keys instead of unsuffixed names.
Core material lookups updated
src/SHiPMaterials.cpp
createMaterials() updates ingredient lookups for Air, Concrete, Vacuum, metals/alloys, LAB, Scintillator, and Lead to use *_E keys.
Polymer and gas compound lookups
src/SHiPMaterials.cpp
PVT, Polystyrene, Mylar, and ArCO2_70_30 ingredient additions switch to *_E element names, with mass-fraction math unchanged.
Changelog and API docs
CHANGELOG.md, include/SHiPGeometry/SHiPMaterials.h
The 0.2.1 changelog note and getElement examples are updated to reference the _E naming.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: renaming elements to fix ROOT parsing issues.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix_ROOT_import

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

❌ prek hooks failed

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...............................................................Passed
check for added large files..............................................Passed
check for merge conflicts................................................Passed
check for case conflicts.................................................Passed
mixed line ending........................................................Passed
clang-format.............................................................Failed
- hook id: clang-format
- files were modified by this hook
cpplint..................................................................Passed
codespell................................................................Passed
cmakelint................................................................Passed
gersemi..................................................................Passed

hint: Some hooks made changes to the files.
If you are seeing this message in CI, reproduce locally with: `prek run --all-files`
To run prek as part of Git workflow, use `prek install` to set up Git shims.

All changes made by hooks:
diff --git a/src/SHiPMaterials.cpp b/src/SHiPMaterials.cpp
index bbe4b7c..4d8143f 100644
--- a/src/SHiPMaterials.cpp
+++ b/src/SHiPMaterials.cpp
@@ -78,8 +78,8 @@ void SHiPMaterials::createElements() {
         "Aluminium_E", "Al", 13.0, 26.982 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
 
     // Lead
-    m_elements["Lead_E"] = new GeoElement("Lead_E", "Pb", 82.0,
-                                        207.2 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
+    m_elements["Lead_E"] = new GeoElement(
+        "Lead_E", "Pb", 82.0, 207.2 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
 }
 
 void SHiPMaterials::createMaterials() {

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/SHiPMaterials.cpp`:
- Around line 39-83: `createElements()` in `SHiPMaterials` now registers only
the suffixed `_E` keys, but `getElement()` is still documented and likely used
with unsuffixed names such as “Nitrogen” and “Oxygen”. Add compatibility aliases
in `createElements()` (or otherwise normalize lookups in `getElement()`) so both
the old documented names and the new `_E` names resolve to the same
`GeoElement`, and keep the public contract consistent with existing consumers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aeed46f5-a5ea-42b4-9507-3b275bb34718

📥 Commits

Reviewing files that changed from the base of the PR and between 203b9d2 and a2f55c3.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/SHiPMaterials.cpp

Comment thread src/SHiPMaterials.cpp
Comment on lines +39 to 83
m_elements["Hydrogen_E"] = new GeoElement(
"Hydrogen_E", "H", 1, 1.008 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Helium_E"] = new GeoElement(
"Helium_E", "He", 2, 4.003 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Carbon_E"] = new GeoElement(
"Carbon_E", "C", 6, 12.011 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Nitrogen_E"] = new GeoElement(
"Nitrogen_E", "N", 7, 14.007 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Oxygen_E"] = new GeoElement(
"Oxygen_E", "O", 8, 15.999 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Silicon_E"] = new GeoElement(
"Silicon_E", "Si", 14, 28.085 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Argon_E"] = new GeoElement(
"Argon_E", "Ar", 18, 39.948 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Calcium_E"] = new GeoElement(
"Calcium_E", "Ca", 20, 40.078 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Titanium_E"] = new GeoElement(
"Titanium_E", "Ti", 22, 47.867 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Chromium_E"] = new GeoElement(
"Chromium_E", "Cr", 24, 51.996 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Manganese_E"] = new GeoElement(
"Manganese_E", "Mn", 25, 54.938 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Iron_E"] = new GeoElement(
"Iron_E", "Fe", 26, 55.845 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Nickel_E"] = new GeoElement(
"Nickel_E", "Ni", 28, 58.693 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Copper_E"] = new GeoElement(
"Copper_E", "Cu", 29, 63.546 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Niobium_E"] = new GeoElement(
"Niobium_E", "Nb", 41, 92.906 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Molybdenum_E"] = new GeoElement(
"Molybdenum_E", "Mo", 42, 95.95 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Tantalum_E"] = new GeoElement(
"Tantalum_E", "Ta", 73, 180.948 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Tungsten_E"] = new GeoElement(
"Tungsten_E", "W", 74, 183.84 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);

// Aluminium
m_elements["Aluminium"] = new GeoElement(
"Aluminium", "Al", 13.0, 26.982 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
m_elements["Aluminium_E"] = new GeoElement(
"Aluminium_E", "Al", 13.0, 26.982 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);

// Lead
m_elements["Lead"] = new GeoElement("Lead", "Pb", 82.0,
m_elements["Lead_E"] = new GeoElement("Lead_E", "Pb", 82.0,
207.2 * GeoModelKernelUnits::g / GeoModelKernelUnits::mole);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Verify direct callers still using documented unsuffixed element names.
rg -n -P '\bgetElement\s*\(\s*"(Hydrogen|Helium|Carbon|Nitrogen|Oxygen|Silicon|Argon|Calcium|Titanium|Chromium|Manganese|Iron|Nickel|Copper|Niobium|Molybdenum|Tantalum|Tungsten|Aluminium|Lead)"\s*\)' . || true

# Verify public docs/examples were updated with the new element naming contract.
rg -n 'Element name \(e\.g\., "Nitrogen", "Oxygen"\)|getElement\(.*Nitrogen' include/SHiPGeometry/SHiPMaterials.h || true

Repository: ShipSoft/Geometry

Length of output: 219


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the public API and nearby implementation.
ast-grep outline include/SHiPGeometry/SHiPMaterials.h --view expanded || true
ast-grep outline src/SHiPMaterials.cpp --view expanded || true

# Find all getElement call sites and the element keys used in this module.
rg -n '\bgetElement\s*\(' . || true
rg -n '"[A-Za-z]+(_E)?"' src/SHiPMaterials.cpp include/SHiPGeometry/SHiPMaterials.h || true

Repository: ShipSoft/Geometry

Length of output: 10584


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find explicit unsuffixed element lookups and any compatibility layer.
rg -n '"(Hydrogen|Helium|Carbon|Nitrogen|Oxygen|Silicon|Argon|Calcium|Titanium|Chromium|Manganese|Iron|Nickel|Copper|Niobium|Molybdenum|Tantalum|Tungsten|Aluminium|Lead)"' . || true
rg -n 'm_elements\.find|m_elements\[' src/SHiPMaterials.cpp include/SHiPGeometry/SHiPMaterials.h || true

Repository: ShipSoft/Geometry

Length of output: 9667


Keep getElement() compatible with the documented names

createElements() now stores only _E keys, but include/SHiPGeometry/SHiPMaterials.h still documents unsuffixed lookups like getElement("Nitrogen") and getElement("Oxygen"). Keep aliases for the old names or update the contract and all consumers together.

🧰 Tools
🪛 GitHub Actions: Lint / 0_prek _ prek.txt

[error] 78-80: Prek hook 'clang-format' failed. Files were modified by this hook. Run 'prek run --all-files' locally to apply clang-format changes.

🪛 GitHub Actions: Lint / prek _ prek

[error] 78-81: pre-commit hook 'clang-format' failed: files were modified by this hook. The CI run did not include formatted changes. Diff indicates clang-format reflowed the GeoElement construction for m_elements["Lead_E"].

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/SHiPMaterials.cpp` around lines 39 - 83, `createElements()` in
`SHiPMaterials` now registers only the suffixed `_E` keys, but `getElement()` is
still documented and likely used with unsuffixed names such as “Nitrogen” and
“Oxygen”. Add compatibility aliases in `createElements()` (or otherwise
normalize lookups in `getElement()`) so both the old documented names and the
new `_E` names resolve to the same `GeoElement`, and keep the public contract
consistent with existing consumers.

@olantwin

olantwin commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

No need to update the change log manually, for all the new repos we generate the change log automatically from the commit messages (which is why it's even more important to write proper commit messages!)

@olantwin

olantwin commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@olantwin

Copy link
Copy Markdown
Contributor

This will be fixed upstream: root-project/root#22834

We have at least two documented workarounds, I'd prefer not to change our software here.

@olantwin olantwin closed this Jul 16, 2026
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.

2 participants