Skip to content

Conversation

@ahmedbilal9
Copy link

Fixes #20342

Changes or fixes:

When exporting GDML files, matrix values were being written with the default C++ ostream precision (6 significant digits) instead of using the configured fFltPrecision setting. This caused loss of precision in geometry data.

Applied the same precision formatting pattern used in CreateConstantN to ensure consistent precision across all GDML exports.

Checklist:

  • Tested changes locally
  • Updated the docs (if necessary)

@ahmedbilal9 ahmedbilal9 requested a review from agheata as a code owner November 8, 2025 08:41
@dpiparo
Copy link
Member

dpiparo commented Nov 8, 2025

Thanks! I started the tests waiting for @agheata to review.
Would it be feasible to reduce the setup that led you to identify this bug to a test?

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

Test Results

    21 files      21 suites   3d 19h 45m 49s ⏱️
 3 738 tests  3 737 ✅ 0 💤 1 ❌
76 649 runs  76 648 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit b3788ce.

♻️ This comment has been updated with latest results.

@ahmedbilal9
Copy link
Author

Thanks! I started the tests waiting for @agheata to review. Would it be feasible to reduce the setup that led you to identify this bug to a test?

Hi! I've added a test case for the precision fix in commit e3ea518.

The test verifies that matrix values in GDML exports use the configured fFltPrecision setting instead of the default C++ ostream precision (6 digits).

Test details:

  • Location: roottest/root/io/geo/testMatrixPrecision.cxx
  • Creates a geometry with rotation matrices containing high-precision values
  • Exports to GDML and verifies the output maintains sufficient decimal precision
  • Only runs when GDML support is enabled

The test follows the existing pattern used in the geo test suite and integrates with the CMake build system.

@KoljaFrahm
Copy link
Contributor

This works as well in case you like this more than #20343

@ahmedbilal9
Copy link
Author

Hi! I've added a test case for the precision fix in commit e3ea518.

The test verifies that matrix values in GDML exports use the configured fFltPrecision setting instead of the default C++ ostream precision (6 digits).

Test details:

  • Location: roottest/root/io/geo/testMatrixPrecision.cxx
  • Creates a geometry with rotation matrices containing high-precision values
  • Exports to GDML and verifies the output maintains sufficient decimal precision
  • Only runs when GDML support is enabled

The test follows the existing pattern used in the geo test suite and integrates with the CMake build system.

I've also applied clang-format to fix the code style issues.

Copy link
Member

@agheata agheata left a comment

Choose a reason for hiding this comment

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

Thanks @ahmedbilal9 for catching this! The fix is OK, but not the unit test. The method actually does not apply (in TGeo) to rotation matrices but rather to the more general "matrix" GDML tag. ROOT only reads that tag with TGDMLParse if the GDML is produced externally and contains it; then, it stores the data temporarily in TGeoManager in case it needs to be exported as GDML. So your test does not find the "matrix" tag in the exported file, since ROOT generates "rotation" instead. Besides that, the feature is small and not likely to change after fixing, so I would prefer not adding a unit test anyway. So, could you either rebase your branch and keep a single commit with the fix, or if you prefer make a new PR with that commit, closing the 2 PR's?

…atrixN

Fixes root-project#20342

Apply fFltPrecision setting to matrix value exports instead of using
default C++ ostream precision (6 digits).
@ahmedbilal9 ahmedbilal9 force-pushed the fix-gdml-matrix-precision branch from fc759a5 to b3788ce Compare November 10, 2025 12:05
@ahmedbilal9
Copy link
Author

Thanks @ahmedbilal9 for catching this! The fix is OK, but not the unit test. The method actually does not apply (in TGeo) to rotation matrices but rather to the more general "matrix" GDML tag. ROOT only reads that tag with TGDMLParse if the GDML is produced externally and contains it; then, it stores the data temporarily in TGeoManager in case it needs to be exported as GDML. So your test does not find the "matrix" tag in the exported file, since ROOT generates "rotation" instead. Besides that, the feature is small and not likely to change after fixing, so I would prefer not adding a unit test anyway. So, could you either rebase your branch and keep a single commit with the fix, or if you prefer make a new PR with that commit, closing the 2 PR's?

I've rebased the PR to a single commit and removed the test as requested.
The PR now contains only the precision fix for matrix values in GDML exports.

Copy link
Member

@agheata agheata left a comment

Choose a reason for hiding this comment

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

Thanks @ahmedbilal9 for the fix!

@ahmedbilal9
Copy link
Author

Thanks @ahmedbilal9 for the fix!

Hi @agheata,

Thank you for approving the fix! I see some CI tests are failing, but they appear to be unrelated infrastructure issues (mac-beta ARM64, ubuntu2510). The core test suite shows 3,737 passing tests.

Should I do anything, or will you merge it as-is?

Thanks!

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.

Precision not set for matrix values when writing gdml

4 participants