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

feat: add material conversion + test for TGeo #2496

Merged
27 changes: 20 additions & 7 deletions Plugins/TGeo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@

set(library_sources
src/TGeoCylinderDiscSplitter.cpp
src/TGeoDetectorElement.cpp
src/TGeoLayerBuilder.cpp
src/TGeoParser.cpp
src/TGeoPrimitivesHelper.cpp
src/TGeoSurfaceConverter.cpp)

# Internal system of units change, This behavior affected versions up to v6-25-01
# see: https://root.cern.ch/doc/v626/classTGeoMaterial.html
if (${ROOT_VERSION} VERSION_GREATER "6.25.01")
list(APPEND library_sources src/TGeoMaterialConverter.cpp)
else ()
message(INFO " Skipping TGeoMaterialConverter due to ROOT version ${ROOT_VERSION}")
endif()

add_library(
ActsPluginTGeo SHARED
src/TGeoCylinderDiscSplitter.cpp
src/TGeoDetectorElement.cpp
src/TGeoLayerBuilder.cpp
src/TGeoParser.cpp
src/TGeoPrimitivesHelper.cpp
src/TGeoSurfaceConverter.cpp)
ActsPluginTGeo SHARED ${library_sources})


target_include_directories(
ActsPluginTGeo
PUBLIC
Expand Down
46 changes: 46 additions & 0 deletions Plugins/TGeo/include/Acts/Plugins/TGeo/TGeoMaterialConverter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Definitions/Common.hpp"
#include "Acts/Material/Material.hpp"
#include "Acts/Material/MaterialSlab.hpp"

#include <memory>
#include <string>
#include <utility>
#include <vector>

class TGeoMaterial;

namespace Acts {
struct TGeoMaterialConverter {
/// @brief Nested options struct
/// to steer the conversion process
struct Options {
/// @brief Convert input TGeo unit to ACTS unit
ActsScalar unitLengthScalor = 10.;
/// @brief Convert input TGeo unit to ACTS unit
ActsScalar unitMassScalor = 1.;
};

/// @brief Helper method to convert a TGeoMaterial into Acts::MaterialSlab
///
/// @param tgMaterial The TGeoMaterial to be converted
/// @param thicknessIn The thickness of the ingoing material slab
/// @param thicknessOut The thickness of the outgoing material slab
/// @param options The conversion options with the unit scalors
///
/// @return a material slab object
static MaterialSlab materialSlab(const TGeoMaterial& tgMaterial,
ActsScalar thicknessIn,
ActsScalar thicknessOut,
const Options& options);
};
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ struct TGeoSurfaceConverter {
/// @param axes The axes definition
/// @param scalor The unit scalor between TGeo and Acts
///
/// @return shared pointer to a surface
static std::shared_ptr<Surface> toSurface(
/// @return shared pointer to a surface and the original thickness that
/// has been condensed to the surface
static std::tuple<std::shared_ptr<Surface>, ActsScalar> toSurface(
const TGeoShape& tgShape, const TGeoMatrix& tgMatrix,
const std::string& axes, double scalor = 10.) noexcept(false);

Expand Down
48 changes: 24 additions & 24 deletions Plugins/TGeo/src/TGeoDetectorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,39 @@ Acts::TGeoDetectorElement::TGeoDetectorElement(
auto sensor = m_detElement->GetVolume();
auto tgShape = sensor->GetShape();

auto cylinderComps = TGeoSurfaceConverter::cylinderComponents(
*tgShape, rotation, translation, axes, scalor);
auto cylinderBounds = std::get<0>(cylinderComps);
if (cylinderBounds != nullptr) {
m_transform = std::get<1>(cylinderComps);
m_bounds = cylinderBounds;
m_thickness = std::get<2>(cylinderComps);
m_surface = Surface::makeShared<CylinderSurface>(cylinderBounds, *this);
auto [cBounds, cTransform, cThickness] =
TGeoSurfaceConverter::cylinderComponents(*tgShape, rotation, translation,
axes, scalor);
if (cBounds != nullptr) {
m_transform = cTransform;
m_bounds = cBounds;
m_thickness = cThickness;
m_surface = Surface::makeShared<CylinderSurface>(cBounds, *this);
}

// Check next if you do not have a surface
if (m_surface == nullptr) {
auto discComps = TGeoSurfaceConverter::discComponents(
*tgShape, rotation, translation, axes, scalor);
auto discBounds = std::get<0>(discComps);
if (discBounds != nullptr) {
m_bounds = discBounds;
m_transform = std::get<1>(discComps);
m_thickness = std::get<2>(discComps);
m_surface = Surface::makeShared<DiscSurface>(discBounds, *this);
auto [dBounds, dTransform, dThickness] =
TGeoSurfaceConverter::discComponents(*tgShape, rotation, translation,
axes, scalor);
if (dBounds != nullptr) {
m_bounds = dBounds;
m_transform = dTransform;
m_thickness = dThickness;
m_surface = Surface::makeShared<DiscSurface>(dBounds, *this);
}
}

// Check next if you do not have a surface
if (m_surface == nullptr) {
auto planeComps = TGeoSurfaceConverter::planeComponents(
*tgShape, rotation, translation, axes, scalor);
auto planeBounds = std::get<0>(planeComps);
if (planeBounds != nullptr) {
m_bounds = planeBounds;
m_transform = std::get<1>(planeComps);
m_thickness = std::get<2>(planeComps);
m_surface = Surface::makeShared<PlaneSurface>(planeBounds, *this);
auto [pBounds, pTransform, pThickness] =
TGeoSurfaceConverter::planeComponents(*tgShape, rotation, translation,
axes, scalor);
if (pBounds != nullptr) {
m_bounds = pBounds;
m_transform = pTransform;
m_thickness = pThickness;
m_surface = Surface::makeShared<PlaneSurface>(pBounds, *this);
}
}

Expand Down
35 changes: 35 additions & 0 deletions Plugins/TGeo/src/TGeoMaterialConverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is part of the Acts project.
//
// Copyright (C) 2023 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/TGeo/TGeoMaterialConverter.hpp"

#include "Acts/Material/Material.hpp"

#include "TGeoMaterial.h"

Acts::MaterialSlab Acts::TGeoMaterialConverter::materialSlab(
const TGeoMaterial& tgMaterial, ActsScalar thicknessIn,
ActsScalar thicknessOut, const Options& options) {
ActsScalar matA = tgMaterial.GetA();
ActsScalar matZ = tgMaterial.GetZ();
ActsScalar matX0 = tgMaterial.GetRadLen();
ActsScalar matL0 = tgMaterial.GetIntLen();
// @todo TGeo to Acts density conversion missing
ActsScalar matRho = tgMaterial.GetDensity();

// X0, L0, rho scale with the thicknes
ActsScalar cFactor = thicknessIn / thicknessOut;
ActsScalar uScalor = options.unitLengthScalor;
ActsScalar rScalar =
options.unitMassScalor / pow(options.unitLengthScalor, 3);
auto material = Material::fromMassDensity(matX0 * uScalor / cFactor,
matL0 * uScalor / cFactor, matA,
matZ, matRho * rScalar * cFactor);

return MaterialSlab(std::move(material), thicknessOut);
}
Loading