1#ifndef BMNGEOTEMPLATE_H
2#define BMNGEOTEMPLATE_H
9#include "TGeoManager.h"
10#include "TGeoNavigator.h"
12#include "TGeoVolume.h"
18#include <unordered_map>
24template<
class Derived>
35 LOG(error) <<
Name() <<
": no GeoManager!";
38 gGeoManager->GetCache()->BuildIdArray();
39 auto* saveTop = gGeoManager->GetTopVolume();
40 if (!getGlobalPosition) {
42 if (gGeoManager->CheckPath(Derived::PathBeforeLocalSystem())) {
43 gGeoManager->cd(Derived::PathBeforeLocalSystem());
44 gGeoManager->SetTopVolume(gGeoManager->GetCurrentNode()->GetVolume());
46 LOG(error) <<
Name() <<
": wrong path " << Derived::PathBeforeLocalSystem();
52 if (!getGlobalPosition) {
53 gGeoManager->SetTopVolume(saveTop);
61 TString full = Form(
"%s/geometry/%s", getenv(
"VMCWORKDIR"), path.c_str());
62 LOG(info) <<
Name() <<
": ReadGeometryFromFile " << full;
64 LOG(warn) <<
Name() <<
": GeoManager exists. Delegating to GeoManager";
67 TFile
f(full.Data(),
"READONLY");
68 auto* top =
dynamic_cast<TGeoVolume*
>(
f.Get(Derived::TopVolumeName()));
70 LOG(error) <<
Name() <<
": no TOP volume in file " << full;
73 gGeoManager->SetTopVolume(top);
74 gGeoManager->CloseGeometry();
77 gGeoManager =
nullptr;
88 LOG(error) <<
Name() <<
": ListNodes called without a GeoManager";
94 if (FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug)) {
96 uint32_t address = kv.first;
97 const auto& pos = kv.second.first;
98 const auto& err = kv.second.second;
99 LOG(debug) << Form(
"%s: addr=0x%08X pos=(%.2f, %.2f, %.2f) err=(%.2f, %.2f, %.2f)",
Name(), address,
100 pos.X(), pos.Y(), pos.Z(), err.X(), err.Y(), err.Z());
110 auto* nav = gGeoManager->GetCurrentNavigator();
113 nav->SetCurrentPoint(p.X(), p.Y(), p.Z());
115 return TString(nav->GetPath()).Contains(Derived::DetectorVolumeName());
123 const char*
Name()
const {
return static_cast<Derived*
>(
const_cast<BmnGeoTemplate*
>(
this))->GetName(); }
128 int n = gGeoManager->CountNodes();
129 for (
int i = 0;
i < n; ++
i) {
130 gGeoManager->CdNode(
i);
131 auto* node = gGeoManager->GetCurrentNode();
134 if (!Derived::CheckIfSensitive(node->GetVolume()->GetName()))
138 uint32_t addr =
static_cast<Derived*
>(
this)->GetAddressFromPath(gGeoManager->GetPath());
141 double loc[3] = {0}, glb[3];
142 gGeoManager->LocalToMaster(loc, glb);
144 std::make_pair(TVector3(glb[0], glb[1], glb[2]),
static_cast<Derived*
>(
this)->
GetPosError(node));
151 if (
auto* box =
dynamic_cast<TGeoBBox*
>(node->GetVolume()->GetShape())) {
152 return TVector3(box->GetDX(), box->GetDY(), box->GetDZ());
154 return TVector3(0, 0, 0);
bool IsPointInside(const TVector3 &p) const
BmnStatus ReadGeometryFromFile(const std::string &path, bool getGlobalPosition=true)
TVector3 GetPosError(TGeoNode *node) const
by default: box‐half‐sizes
const char * Name() const
Helper to call the FairGeoSet::GetName() on the actual object.
const auto & GetPositionMap() const
BmnStatus ReadGeometryFromGeoManager(bool getGlobalPosition=true)
virtual ~BmnGeoTemplate()=default
std::map< uint32_t, std::pair< TVector3, TVector3 > > fPositionMap