24#include <TGeoManager.h>
26#include "Acts/Geometry/GeometryIdentifier.hpp"
27#include "Acts/Geometry/TrackingVolume.hpp"
28#include "Acts/Surfaces/Surface.hpp"
29#include "ActsPlugins/Json/JsonMaterialDecorator.hpp"
30#include "ActsPlugins/Json/MaterialMapJsonConverter.hpp"
44bool hasO2GeometryObject(std::string_view fileName)
46 TFile
file(std::string(fileName).c_str());
47 if (
file.IsZombie()) {
48 throw std::runtime_error(
"o2::acts::TrackingGeometryManager: cannot open '" + std::string(fileName) +
"'");
55TrackingGeometryManager::TrackingGeometryManager()
56 : mNominalContext(
Acts::GeometryContext::dangerouslyDefaultConstruct())
66void TrackingGeometryManager::setBuilder(std::unique_ptr<ITrackingGeometryBuilder> builder)
69 throw std::runtime_error(
70 "o2::acts::TrackingGeometryManager: cannot change the builder after the geometry was built. "
71 "Call clear() first if this is really intended.");
73 mBuilder = std::move(builder);
76void TrackingGeometryManager::clear()
81 mElementStore.clear();
84 mNDecoratedSurfaces = 0;
87void TrackingGeometryManager::build()
90 LOG(info) <<
"ACTS tracking geometry is already built, nothing to do";
94 throw std::runtime_error(
95 "o2::acts::TrackingGeometryManager: no TGeo geometry is loaded. Declare "
96 "o2::base::GRPGeomRequest::Aligned in the workflow's GRPGeomRequest and call "
97 "GRPGeomHelper::instance().checkUpdates(pc) before asking for the ACTS geometry, or use "
98 "buildFromFile() outside a workflow.");
103void TrackingGeometryManager::buildFromFile(std::string_view geomFileName)
106 LOG(info) <<
"ACTS tracking geometry is already built, nothing to do";
110 LOG(warn) <<
"A TGeo geometry is already loaded, ignoring the requested file and using it";
115 LOGP(info,
"Loading TGeo geometry from '{}'", geomFileName);
116 if (hasO2GeometryObject(geomFileName)) {
123 LOGP(warn,
"'{}' holds no '{}' or '{}' object: importing it as a plain TGeo file",
125 if (TGeoManager::Import(std::string(geomFileName).c_str()) ==
nullptr) {
126 throw std::runtime_error(
"o2::acts::TrackingGeometryManager: cannot import TGeo geometry from '" +
127 std::string(geomFileName) +
"'");
133void TrackingGeometryManager::doBuild()
135 if (mBuilder ==
nullptr) {
136 throw std::runtime_error(
137 "o2::acts::TrackingGeometryManager: no builder installed. Call setBuilder() with the "
138 "detector-specific ITrackingGeometryBuilder before requesting the geometry.");
141 LOGP(info,
"Building the ACTS tracking geometry with the '{}' builder", mBuilder->getName());
142 auto output = mBuilder->build(*gGeoManager, mNominalContext);
143 if (
output.geometry ==
nullptr) {
144 throw std::runtime_error(std::string(
"o2::acts::TrackingGeometryManager: builder '") +
145 mBuilder->getName() +
"' returned no geometry");
148 mElementStore = std::move(
output.elementStore);
149 mIndex = std::move(
output.index);
151 if (!mMaterialMapFile.empty()) {
154 applyMaterialMapImpl(*
output.geometry);
157 mGeometry = std::const_pointer_cast<const Acts::TrackingGeometry>(
output.geometry);
159 LOGP(info,
"ACTS tracking geometry ready: {} mapped sensors, {} surfaces with material",
160 mIndex.size(), mNDecoratedSurfaces);
163void TrackingGeometryManager::applyMaterialMapImpl(Acts::TrackingGeometry& geometry)
165 if (!std::filesystem::exists(mMaterialMapFile)) {
166 throw std::runtime_error(
"o2::acts::TrackingGeometryManager: material map '" + mMaterialMapFile +
170 Acts::MaterialMapJsonConverter::Config converterConfig;
171 converterConfig.context = mNominalContext;
172 const Acts::JsonMaterialDecorator decorator(converterConfig, mMaterialMapFile, mLogLevel);
174 mNDecoratedSurfaces = 0;
175 geometry.apply([&](Acts::Surface&
surface) {
177 if (
surface.surfaceMaterial() !=
nullptr) {
178 ++mNDecoratedSurfaces;
182 if (mNDecoratedSurfaces == 0) {
186 throw std::runtime_error(
187 "o2::acts::TrackingGeometryManager: material map '" + mMaterialMapFile +
188 "' matched no surface. It was produced for a different geometry structure and must be "
189 "regenerated for this one.");
193std::shared_ptr<const Acts::TrackingGeometry> TrackingGeometryManager::getShared()
201const Acts::TrackingGeometry& TrackingGeometryManager::get()
222 const auto it = mDetIndices.find(detID);
223 if (it != mDetIndices.end()) {
226 auto [inserted, ok] = mDetIndices.emplace(
227 detID,
makeSurfaceIndex(*mGeometry, mNominalContext, cache, toleranceCm, std::move(pathProvider)));
228 return inserted->second;
Definition of the GeometryManager class.
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Definition of the Names Generator class.
const Acts::Surface * surface
Process-wide provider of the ACTS tracking geometry.
static bool isGeometryLoaded()
static void loadGeometry(std::string_view geomFilePath="", bool applyMisalignment=false, bool preferAlignedFile=true)
static constexpr std::string_view CCDBOBJECT
static constexpr std::string_view GEOMOBJECTNAME_FAIR
const o2::detectors::DetID & getDetID() const
SurfaceIndexMap makeSurfaceIndex(const Acts::TrackingGeometry &geometry, const Acts::GeometryContext &gctx, const o2::detectors::DetMatrixCache &cache, double toleranceCm=1e-3, SensorPathProvider pathProvider={})
std::function< std::string(int sensorID)> SensorPathProvider
Full TGeo node path of one sensor, e.g. o2::trk::GeometryTGeo::getMatrixPath().
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"