Skip to content

Commit

Permalink
GeoAssembly bounding box after alignment: use ROOT expert patch
Browse files Browse the repository at this point in the history
- cf discussion in root-project/root#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
  • Loading branch information
PALoizeau committed Apr 11, 2023
1 parent 703ea46 commit b4b5f0e
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions fairroot/alignment/FairAlignmentHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <TGeoManager.h>
#include <TGeoPhysicalNode.h>
#include <TGeoShapeAssembly.h>
#include <TGeoVoxelFinder.h>
#include <fairlogger/Logger.h>

void FairAlignmentHandler::AlignGeometry() const
Expand All @@ -18,8 +19,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...";
Expand Down Expand Up @@ -100,15 +102,23 @@ void FairAlignmentHandler::AddAlignmentMatrices(const std::map<std::string, TGeo

void FairAlignmentHandler::RecomputePhysicalAssmbBbox() const
{
TObjArray* pPhysNodesArr = gGeoManager->GetListOfPhysicalNodes();

for (auto pPhysNode : TRangeDynCast<TGeoPhysicalNode>(pPhysNodesArr)) {
if (pPhysNode) {
auto pShapeAsb = dynamic_cast<TGeoShapeAssembly*>(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<TGeoVolume>(volumes)) {
if (!vol) {
continue;
}
if (vol->IsAssembly()) {
vol->GetShape()->ComputeBBox();
}
auto finder = vol->GetVoxels();
if (finder && finder->NeedRebuild()) {
finder->Voxelize();
vol->FindOverlaps();
}
}
}

0 comments on commit b4b5f0e

Please sign in to comment.