Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve geometry state after alignment #1244

Merged
merged 2 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 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>

FairAlignmentHandler::FairAlignmentHandler() {}

Expand All @@ -21,6 +22,13 @@ 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
RecomputePhysicalAssmbBbox();

LOG(info) << "Refreshing geometry...";
gGeoManager->RefreshPhysicalNodes(kFALSE);

LOG(info) << "alignment finished!";
}
}
Expand Down Expand Up @@ -93,3 +101,23 @@ void FairAlignmentHandler::AddAlignmentMatrices(const std::map<std::string, TGeo
fAlignmentMatrices[m.first] *= m.second;
}
}

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();
}
}
}
}
2 changes: 2 additions & 0 deletions alignment/FairAlignmentHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FairAlignmentHandler

void AddAlignmentMatrices(const std::map<std::string, TGeoHMatrix>& alignmentMatrices, bool invertMatrices);

void RecomputePhysicalAssmbBbox() const;

public:
FairAlignmentHandler();
virtual ~FairAlignmentHandler();
Expand Down
14 changes: 10 additions & 4 deletions examples/simulation/Tutorial4/macros/plots.C
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,13 @@ int plots(Int_t nEvents = 1000, Int_t iout = 1, TString mcEngine = "align_TGeant
} // event loop end

auto pullx_Ent = pullx->GetEntries();
auto pullx_Mea = pullx->GetMean();
auto pully_Mea = pully->GetMean();
auto pullz_Mea = pullz->GetMean();
auto pullx_Dev = pullx->GetStdDev();
auto pully_Dev = pully->GetStdDev();
auto pullz_Dev = pullz->GetStdDev();
cout << "Mean (" << pullx_Mea << ", " << pully_Mea << ", " << pullz_Mea << ") " << endl;

// save histos to file
// TFile *fHist = TFile::Open("data/auaumbias.hst.root","RECREATE");
Expand Down Expand Up @@ -164,13 +170,13 @@ int plots(Int_t nEvents = 1000, Int_t iout = 1, TString mcEngine = "align_TGeant
cout << "Parameter file is " << ParFile << endl;
cout << "Real time " << rtime << " s, CPU time " << ctime << "s" << endl << endl;

if (nevent >= 10 && pullx_Ent > nevent * 35 && abs(pullx_Dev - 0.1) < 0.03)
if (nevent >= 10 && pullx_Ent > nevent * 35 && abs(pullx_Dev - 0.1) < 0.03 && abs(pully_Dev - 0.1) < 0.04)
cout << "Macro finished successfully. Number of events (" << nevent << "), hist entries (" << pullx_Ent
<< ") and deviation (" << pullx_Dev << ") inside limits." << endl;
<< ") and deviation (" << pullx_Dev << ", " << pully_Dev << ", " << pullz_Dev << ") inside limits."
<< endl;
else
cout << "Macro failed. Number of events (" << nevent << "), hist entries (" << pullx_Ent << ") or deviation ("
<< pullx_Dev << ") too far off." << endl;

<< pullx_Dev << ", " << pully_Dev << ", " << pullz_Dev << ") too far off." << endl;
// ------------------------------------------------------------------------

return 0;
Expand Down