Skip to content

Conversation

@agheata
Copy link
Member

@agheata agheata commented Jan 27, 2026

This Pull request:

Introduces an extensible color scheme mechanism for geometry visualization, improving the default coloring of imported geometries (notably GDML, which does not store color information).

Changes or fixes:

TGeoManager::DefaultColors() historically assigns colors based only on material effective Z, resulting in:

  • many volumes sharing the same gray color,
  • limited visual distinction,
  • little resemblance to “natural” material appearance in detector geometries.
tpc_none

Modern detector descriptions contain rich material names (e.g. Copper, FR4, Kapton, Steel, Carbon fiber, Gases), which can be exploited to produce clearer and more meaningful visualizations.

What’s new

  • A new runtime-only strategy class TGeoColorScheme that encapsulates color and transparency policies.
  • A default “natural” color scheme based on:
    • name-based material classification (metals, polymers, composites, gases, ceramics, etc.),
    • fallback to a Z-binned lookup when no name-based rule applies.
tpc_natural
  • Two additional built-in schemes:
    • Flashy – high-contrast, presentation-friendly colors.
tpc_flashy
  • High-contrast – darker, saturated colors suited for light backgrounds.
tpc_high_contrast
  • User extensibility:

    • users can inject custom logic via hooks (std::function) to override colors or transparency,
    • or subclass TGeoColorScheme for full control.
  • Backward compatibility:

    • calling TGeoManager::DefaultColors() with no arguments still works and now defaults to the natural scheme.

API overview

void TGeoManager::DefaultColors(const TGeoColorScheme *scheme = nullptr);

if scheme == nullptr a default TGeoColorScheme(EGeoColorSet::kNatural) is used internally.
The color set is selected via a global enum:

enum class EGeoColorSet {
   kNatural,
   kFlashy,
   kHighContrast
};

Examples

  • Default behavior (no code changes required):
gGeoManager->DefaultColors();   // uses natural, name-based scheme
  • Select a predefined scheme
TGeoColorScheme cs(EGeoColorSet::kFlashy);
gGeoManager->DefaultColors(&cs);
  • User override via hook (no subclassing)
TGeoColorScheme cs(EGeoColorSet::kNatural);
cs.SetColorHook([](const TGeoVolume *v) -> Int_t {
   const TGeoMaterial *m = TGeoColorScheme::GetMaterial(v);
   if (!m || !m->GetName()) return -1;
   if (std::string(m->GetName()).find("Copper") != std::string::npos)
      return TColor::GetColor(0.9f, 0.55f, 0.3f);
   return -1; // fallback to defaults
});
gGeoManager->DefaultColors(&cs);
  • Override Z-based fallback
cs.SetZFallbackHook([](Int_t Z, EGeoColorSet) -> Int_t {
   float g = std::min(1.f, Z / 100.f);
   return TColor::GetColor(g, g, g);
});

Checklist:

  • tested changes locally
  • updated the docs (if necessary)

This PR fixes #

Full description of the feature in geom/geom/src/TGeoColorScheme.cxx
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

Test Results

    22 files      22 suites   3d 11h 11m 56s ⏱️
 3 774 tests  3 774 ✅ 0 💤 0 ❌
75 059 runs  75 059 ✅ 0 💤 0 ❌

Results for commit 6a462da.

♻️ This comment has been updated with latest results.

Copy link
Member

@dpiparo dpiparo left a comment

Choose a reason for hiding this comment

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

Thanks for this solid work.

Besides the minor comments on the code, I see an opportunity for improvement, i.e. the possibility to add an example in the geometry tutorials and tests. Presently, the test coverage of the geometry package can be improved, and this seems like a perfect opportunity to kick off this process!

These changes are impactful and would also deserve some words (and a beautiful image, like "before and after") in the Release Notes.

@agheata
Copy link
Member Author

agheata commented Jan 28, 2026

Adding a tutorial for this, and release notes

@agheata agheata requested a review from couet as a code owner January 28, 2026 11:35
@agheata
Copy link
Member Author

agheata commented Jan 28, 2026

Thanks for this solid work.

Besides the minor comments on the code, I see an opportunity for improvement, i.e. the possibility to add an example in the geometry tutorials and tests. Presently, the test coverage of the geometry package can be improved, and this seems like a perfect opportunity to kick off this process!

These changes are impactful and would also deserve some words (and a beautiful image, like "before and after") in the Release Notes.

I added a nice tutorial and the entry in the release notes, w/o a picture (don't know where to put it) but a link to the PR. A coverage test for this is difficult to implement because it is pure visualization, but a working tutorial is more meaningful.

@dpiparo dpiparo self-requested a review January 28, 2026 16:00
Copy link
Member

@dpiparo dpiparo left a comment

Choose a reason for hiding this comment

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

Thanks! Just merge it at your convenience.

@agheata agheata merged commit 271cfd3 into root-project:master Jan 28, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants