From e0a1514ca0bcf4dcbc62fd4f440b611fb75da0a4 Mon Sep 17 00:00:00 2001 From: Pierre-Alain Loizeau Date: Thu, 6 Apr 2023 16:25:42 +0200 Subject: [PATCH] GeoAssembly bounding box after alignment: use ROOT expert patch - cf discussion in https://github.com/root-project/root/issues/12242 - Improvement of PR #1244 - see also Issue #1243 - Solves new sub-case of Cbmroot issue https://redmine.cbm.gsi.de/issues/2620 More generic solution also catching edge case where only Nodes inside assembly are aligned but not assembly itself (cherry picked from commit b4b5f0edcffe3130d7c49ffb8a049c70d90a5664) --- alignment/FairAlignmentHandler.cxx | 42 ++++++++++++++++-------------- alignment/FairAlignmentHandler.h | 4 +-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/alignment/FairAlignmentHandler.cxx b/alignment/FairAlignmentHandler.cxx index cb63e623a4..b7cac4f761 100644 --- a/alignment/FairAlignmentHandler.cxx +++ b/alignment/FairAlignmentHandler.cxx @@ -5,10 +5,8 @@ #include #include #include - -FairAlignmentHandler::FairAlignmentHandler() {} - -FairAlignmentHandler::~FairAlignmentHandler() {} +#include +#include void FairAlignmentHandler::AlignGeometry() const { @@ -22,8 +20,9 @@ void FairAlignmentHandler::AlignGeometry() const AlignGeometryByFullPath(); } - // --- Force BoundingBox recomputation for AssemblyVolumes as they may have been corrupted by alignment - // FIXME: will hopefully be fixed in Root in near future, temp fix in meantime + // --- Force BoundingBox recomputation for volumes/nodes needing it after alignment + // FIXME: May be added to RefreshPhysicalNode step in Root in near future, temp fix needed here in meantime + /// cf https://github.com/root-project/root/issues/12242 RecomputePhysicalAssmbBbox(); LOG(info) << "Refreshing geometry..."; @@ -104,20 +103,23 @@ void FairAlignmentHandler::AddAlignmentMatrices(const std::mapGetListOfPhysicalNodes(); - - TGeoPhysicalNode* pPhysNode = nullptr; - TGeoShapeAssembly* pShapeAsb = nullptr; - - Int_t iNbNodes = pPhysNodesArr->GetEntriesFast(); - for (Int_t iInd = 0; iInd < iNbNodes; ++iInd) { - pPhysNode = dynamic_cast(pPhysNodesArr->At(iInd)); - if (pPhysNode) { - pShapeAsb = dynamic_cast(pPhysNode->GetShape()); - if (pShapeAsb) { - // Should reach here only if the original node was a TGeoShapeAssembly - pShapeAsb->ComputeBBox(); - } + /// After alignment, forces the recomputation of the bounding box of all volumesAssemblies and the rebuilding of + /// Nodes requiring it. + /// => Not done after each change to geometry in ROOT for perf reason + /// => to be called once all changes done + /// => original snippet proposed in https://github.com/root-project/root/issues/12242 by A. Gheata + TObjArray* volumes = gGeoManager->GetListOfVolumes(); + for (auto vol : TRangeDynCast(volumes)) { + if (!vol) { + continue; + } + if (vol->IsAssembly()) { + vol->GetShape()->ComputeBBox(); + } + auto finder = vol->GetVoxels(); + if (finder && finder->NeedRebuild()) { + finder->Voxelize(); + vol->FindOverlaps(); } } } diff --git a/alignment/FairAlignmentHandler.h b/alignment/FairAlignmentHandler.h index 3535ea5697..a9ca37181b 100644 --- a/alignment/FairAlignmentHandler.h +++ b/alignment/FairAlignmentHandler.h @@ -18,8 +18,8 @@ class FairAlignmentHandler void RecomputePhysicalAssmbBbox() const; public: - FairAlignmentHandler(); - virtual ~FairAlignmentHandler(); + FairAlignmentHandler() = default; + virtual ~FairAlignmentHandler() = default; }; #endif