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

(cherry picked from commit b4b5f0e)
  • Loading branch information
PALoizeau authored and ChristianTackeGSI committed Nov 16, 2023
1 parent db27083 commit e0a1514
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
42 changes: 22 additions & 20 deletions alignment/FairAlignmentHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include <TGeoManager.h>
#include <TGeoPhysicalNode.h>
#include <TGeoShapeAssembly.h>

FairAlignmentHandler::FairAlignmentHandler() {}

FairAlignmentHandler::~FairAlignmentHandler() {}
#include <TGeoVoxelFinder.h>
#include <fairlogger/Logger.h>

void FairAlignmentHandler::AlignGeometry() const
{
Expand All @@ -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...";
Expand Down Expand Up @@ -104,20 +103,23 @@ void FairAlignmentHandler::AddAlignmentMatrices(const std::map<std::string, TGeo

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

TGeoPhysicalNode* pPhysNode = nullptr;
TGeoShapeAssembly* pShapeAsb = nullptr;

Int_t iNbNodes = pPhysNodesArr->GetEntriesFast();
for (Int_t iInd = 0; iInd < iNbNodes; ++iInd) {
pPhysNode = dynamic_cast<TGeoPhysicalNode*>(pPhysNodesArr->At(iInd));
if (pPhysNode) {
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();
}
}
}
4 changes: 2 additions & 2 deletions alignment/FairAlignmentHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class FairAlignmentHandler
void RecomputePhysicalAssmbBbox() const;

public:
FairAlignmentHandler();
virtual ~FairAlignmentHandler();
FairAlignmentHandler() = default;
virtual ~FairAlignmentHandler() = default;
};

#endif

0 comments on commit e0a1514

Please sign in to comment.