Skip to content

Commit 1354f47

Browse files
sawenzelclaude
andcommitted
Let VecGeom turn large Boolean solids into MultiUnions
This lets VecGeom's BooleanFactory rewrite Boolean solids of at least 8 components into MultiUnions in the kVecGeom mode. - In the ALICE geometry 170 composite shapes are rewritten, among them the MFT disk supports and the ITS end wheels. - G4.vecgeomBooleanThreshold sets the threshold; 0 keeps the solids as converted. - Other users of buildVecGeomGeometry keep the solids as converted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 150990b commit 1354f47

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎Common/SimConfig/include/SimConfig/G4Params.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ struct G4Params : public o2::conf::ConfigurableParamHelper<G4Params> {
6565
// shortens steps and so changes the random history
6666
bool vecgeomFlattenAssemblies = true; // dissolve TGeo assemblies into their content when converting
6767
// to VecGeom; the Geant4 touchable keeps the assembly levels
68+
int vecgeomBooleanThreshold = 8; // Boolean solids with at least this many components become
69+
// VecGeom MultiUnions; 0 keeps them as converted
6870
int vecgeomCheckRays = 0; // if > 0, step this many rays out of the interaction point with
6971
// TGeo and VecGeom and report the volumes they enter differently
7072
int vecgeomCheckLocation = 0; // if > 0, locate this many random points with both and report

‎Detectors/Base/include/DetectorsBase/GeometryManager.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ class GeometryManager : public TObject
139139
/// locator and a safety estimator to every logical volume. Does the work once per process; later
140140
/// calls, whatever they ask for, return the geometry already built, so a caller that needs a
141141
/// particular assembly treatment must come first. \param flattenAssemblies dissolves TGeo
142-
/// assemblies into their content.
143-
static void buildVecGeomGeometry(bool flattenAssemblies);
142+
/// assemblies into their content. \param booleanThreshold lets VecGeom turn Boolean solids with at
143+
/// least this many components into MultiUnions; 0 keeps them as converted.
144+
static void buildVecGeomGeometry(bool flattenAssemblies, int booleanThreshold = 0);
144145
#else
145146
static constexpr bool isVecGeomAvailable() { return false; }
146147
#endif

‎Detectors/Base/src/GeometryManager.cxx‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,17 +587,26 @@ void ensureVecGeomWorldBuilt()
587587
}
588588
} // namespace
589589

590-
void GeometryManager::buildVecGeomGeometry(bool flattenAssemblies)
590+
void GeometryManager::buildVecGeomGeometry(bool flattenAssemblies, int booleanThreshold)
591591
{
592592
static std::once_flag onceFlag;
593-
std::call_once(onceFlag, [flattenAssemblies]() {
593+
std::call_once(onceFlag, [flattenAssemblies, booleanThreshold]() {
594594
if (!gGeoManager) {
595595
LOG(fatal) << "Cannot build VecGeom geometry: no TGeo geometry loaded (call GeometryManager::loadGeometry() first)";
596596
}
597597
// Translate geometry and material pointers, then build acceleration structures.
598598
tgeo2vecgeom::RootGeoManager::Instance().SetMaterialConversionHook([](TGeoMaterial const* m) { return (void*)m; });
599599
LOG(info) << "VecGeom conversion: flattenAssemblies=" << flattenAssemblies;
600600
tgeo2vecgeom::RootGeoManager::Instance().SetFlattenAssemblies(flattenAssemblies);
601+
#if __has_include(<VecGeom/management/BooleanFactory.h>)
602+
// Applied when the conversion closes the geometry.
603+
LOG(info) << "VecGeom conversion: booleanThreshold=" << booleanThreshold;
604+
vecgeom::GeoManager::Instance().SetBooleanOptimizationThreshold(booleanThreshold > 0 ? booleanThreshold : 0);
605+
#else
606+
if (booleanThreshold > 0) {
607+
LOG(warning) << "VecGeom without BooleanFactory: Boolean solids are kept as converted";
608+
}
609+
#endif
601610
tgeo2vecgeom::RootGeoManager::Instance().LoadRootGeometry();
602611

603612
// Acceleration structures must be built before the navigators/locators reference them.

‎Detectors/gconfig/src/VecGeomNavigation.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void installVecGeomNavigator()
8080

8181
TStopwatch timer;
8282
timer.Start();
83-
o2::base::GeometryManager::buildVecGeomGeometry(g4Params.vecgeomFlattenAssemblies);
83+
o2::base::GeometryManager::buildVecGeomGeometry(g4Params.vecgeomFlattenAssemblies, g4Params.vecgeomBooleanThreshold);
8484
timer.Stop();
8585
LOG(info) << "VecGeom geometry built in " << timer.RealTime() << " s";
8686

0 commit comments

Comments
 (0)