CbmRoot
Loading...
Searching...
No Matches
CbmRecoSetupUtils.cxx
Go to the documentation of this file.
1/* Copyright (C) 2025 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "CbmRecoSetupUtils.h"
11
12#include <Logger.h>
13
14#include <TGeoArb8.h>
15#include <TGeoManager.h>
16#include <TGeoNode.h>
17#include <TString.h>
18
19#include <iomanip>
20#include <limits>
21
22#include <fmt/format.h>
24
25// ---------------------------------------------------------------------------------------------------------------------
26//
28{
29 if (!gGeoManager->cd(path)) {
30 std::stringstream msg;
31 msg << "Node with path " << path << " is not found in the geo manager";
32 throw std::runtime_error(msg.str());
33 }
34
35 // Get a shape of the bounding box
36 const auto* bBox = dynamic_cast<const TGeoBBox*>(gGeoManager->GetCurrentVolume()->GetShape());
37 if (!bBox) {
38 throw std::runtime_error(fmt::format("The shape of the volume under path {} is not a TGeoBBox", path.Data()));
39 }
40
41 std::array<std::array<double, 3>, 8> locBoxVertices = {
42 {// Vertex coordinates in the local frame of the box
43 {bBox->GetOrigin()[0] + bBox->GetDX(), bBox->GetOrigin()[1] + bBox->GetDY(), bBox->GetOrigin()[2] + bBox->GetDZ()},
44 {bBox->GetOrigin()[0] + bBox->GetDX(), bBox->GetOrigin()[1] + bBox->GetDY(), bBox->GetOrigin()[2] - bBox->GetDZ()},
45 {bBox->GetOrigin()[0] + bBox->GetDX(), bBox->GetOrigin()[1] - bBox->GetDY(), bBox->GetOrigin()[2] + bBox->GetDZ()},
46 {bBox->GetOrigin()[0] + bBox->GetDX(), bBox->GetOrigin()[1] - bBox->GetDY(), bBox->GetOrigin()[2] - bBox->GetDZ()},
47 {bBox->GetOrigin()[0] - bBox->GetDX(), bBox->GetOrigin()[1] + bBox->GetDY(), bBox->GetOrigin()[2] + bBox->GetDZ()},
48 {bBox->GetOrigin()[0] - bBox->GetDX(), bBox->GetOrigin()[1] + bBox->GetDY(), bBox->GetOrigin()[2] - bBox->GetDZ()},
49 {bBox->GetOrigin()[0] - bBox->GetDX(), bBox->GetOrigin()[1] - bBox->GetDY(), bBox->GetOrigin()[2] + bBox->GetDZ()},
50 {bBox->GetOrigin()[0] - bBox->GetDX(), bBox->GetOrigin()[1] - bBox->GetDY(),
51 bBox->GetOrigin()[2] - bBox->GetDZ()}}};
52
53 std::array<std::pair<double, double>, 3> bounds = {
54 {// Bounds of the algo::GeoVolume
55 {+std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()},
56 {+std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()},
57 {+std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()}}}; // min/max for a dimension
58
59 const auto* matrix{gGeoManager->GetCurrentMatrix()};
60 for (int iVertex = 0; iVertex < 8; ++iVertex) {
61 std::array<double, 3> glbVertex;
62 matrix->LocalToMaster(locBoxVertices[iVertex].data(), glbVertex.data());
63 for (int iDim = 0; iDim < 3; ++iDim) {
64 bounds[iDim].first = std::min(bounds[iDim].first, glbVertex[iDim]);
65 bounds[iDim].second = std::max(bounds[iDim].second, glbVertex[iDim]);
66 }
67 }
68
69 gGeoManager->cd();
70 return algo::GeoVolume(bounds[0], bounds[1], bounds[2]);
71}
72
73
74// ---------------------------------------------------------------------------------------------------------------------
75//
76cbm::algo::GeoVolume RecoSetupUtils::ReadVolume(const std::string& path) { return ReadVolume(TString(path)); }
Different utilities for the CbmOfflineRecoSetup library (source)
bool first
A representation of a geometrical volume of different tracking stations.
Definition GeoVolume.h:25
static algo::GeoVolume ReadVolume(const TString &path)
Creates a volume info from a geo node, provided by path.
Different utilities for the CbmOfflineRecoSetup library.
static algo::GeoVolume ReadVolume(const TString &path)
Creates a volume info from a geo node, provided by path.