Skip to content

Commit

Permalink
Add material grids as material maps and add the relevant types to the
Browse files Browse the repository at this point in the history
detector metadata. The material maps of different shapes are tested
in a dedicated unittest.

Mapeterial maps are added to the toy detector and wire chamber via
the detector helper. The material is a silicon and aluminium mixture
that is mapped in configurable binning onto the disc and cylinder
portals.
  • Loading branch information
niermann999 committed Oct 11, 2023
1 parent c79e73b commit 7fe1c2e
Show file tree
Hide file tree
Showing 30 changed files with 1,134 additions and 288 deletions.
2 changes: 1 addition & 1 deletion core/include/detray/core/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class detector {

/// Forward mask types that are present in this detector
using material_container =
typename metadata::template material_store<tuple_type, vector_type>;
typename metadata::template material_store<tuple_type, container_t>;
using materials = typename material_container::value_types;
using material_link = typename material_container::single_link;

Expand Down
63 changes: 53 additions & 10 deletions core/include/detray/core/detector_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "detray/masks/masks.hpp"
#include "detray/masks/unbounded.hpp"
#include "detray/masks/unmasked.hpp"
#include "detray/materials/material_map.hpp"
#include "detray/materials/material_rod.hpp"
#include "detray/materials/material_slab.hpp"
#include "detray/surface_finders/accelerator_grid.hpp"
Expand Down Expand Up @@ -61,9 +62,34 @@ struct default_metadata {
using slab = material_slab<detray::scalar>;
using rod = material_rod<detray::scalar>;

/// @TODO material grids
/// Material grid types (default: closed bounds, regular binning)
/// @{
/// ...

// Disc material grid
template <typename container_t>
using disc_map_t =
material_map<ring2D<>::axes<>, detray::scalar, container_t>;

// Cylindrical material grid
template <typename container_t>
using cylinder2_map_t =
material_map<cylinder2D<>::axes<>, detray::scalar, container_t>;

// Rectangular material grid
template <typename container_t>
using rectangular_map_t =
material_map<rectangle2D<>::axes<>, detray::scalar, container_t>;

// Cuboid volume material grid
template <typename container_t>
using cuboid_map_t =
material_map<cuboid3D<>::axes<>, detray::scalar, container_t>;

// Cylindrical volume material grid
template <typename container_t>
using cylinder3_map_t =
material_map<cylinder3D::axes<>, detray::scalar, container_t>;

/// @}

/// surface grid types (default boundaries: closed binning)
Expand Down Expand Up @@ -162,19 +188,36 @@ unbounded_cell, unmasked_plane*/>;

/// Give your material types a name (needs to be consecutive and has to
/// match the types position in the mask store!)
/// @TODO: Add the material grid types for every surface shape
enum class material_ids {
e_slab = 0,
e_rod = 1,
// ... material map types
e_none = 2,
// Material texture (grid) shapes
e_disc2_map = 0u,
e_cylinder2_map = 1u,
e_rectangle2_map = 2u,
e_trapezoid2_map = 2u,
e_annulus2_map = 0u,
e_cell_wire_map = 6u,
e_straw_wire_map = 6u,
// Volume material
e_cuboid3_map = 3u,
e_cylinder3_map = 4u,
// Homogeneous mapetrial
e_slab = 5u,
e_rod = 6u,
e_none = 7u,
};

/// How to store materials
template <template <typename...> class tuple_t = dtuple,
template <typename...> class vector_t = dvector>
using material_store = regular_multi_store<material_ids, empty_context,
tuple_t, vector_t, slab, rod>;
typename container_t = host_container_types>
using material_store =
multi_store<material_ids, empty_context, tuple_t,
grid_collection<disc_map_t<container_t>>,
grid_collection<cylinder2_map_t<container_t>>,
grid_collection<rectangular_map_t<container_t>>,
grid_collection<cuboid_map_t<container_t>>,
grid_collection<cylinder3_map_t<container_t>>,
typename container_t::template vector_type<slab>,
typename container_t::template vector_type<rod>>;

/// How to link to the entries in the data stores
using transform_link = typename transform_store<>::link_type;
Expand Down
3 changes: 2 additions & 1 deletion core/include/detray/geometry/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ class surface {
}
// Only check, if there is material in the detector
if (not m_detector.material_store().all_empty()) {
if (is_invalid_value(m_desc.material())) {
if (m_desc.material().id() != detector_t::materials::id::e_none and
m_desc.material().is_invalid_index()) {
os << "ERROR: Surface does not have valid material:\n"
<< *this << std::endl;
return false;
Expand Down
57 changes: 51 additions & 6 deletions core/include/detray/materials/material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include "detray/definitions/math.hpp"
#include "detray/definitions/qualifiers.hpp"
#include "detray/definitions/units.hpp"
#include "detray/utils/invalid_values.hpp"

// System include(s)
#include <limits>
#include <ratio>
#include <sstream>

namespace detray {

Expand All @@ -26,7 +27,12 @@ struct homogeneous_material_tag {};
} // namespace detail

/// Material State
enum class material_state { e_solid = 0, e_liquid = 1, e_gas = 2 };
enum class material_state {
e_solid = 0,
e_liquid = 1,
e_gas = 2,
e_unknown = 3
};

template <typename scalar_t, typename R = std::ratio<1, 1>>
struct material {
Expand All @@ -53,7 +59,7 @@ struct material {
///
/// @param rhs is the right hand side to be compared to
DETRAY_HOST_DEVICE
constexpr bool operator==(const material<scalar_t>& rhs) const {
constexpr bool operator==(const material<scalar_t> &rhs) const {
return (m_x0 == rhs.X0() && m_l0 == rhs.L0() && m_ar == rhs.Ar() &&
m_z == rhs.Z());
}
Expand Down Expand Up @@ -105,6 +111,45 @@ struct material {
}
}

/// @returns a string that contains the material details
DETRAY_HOST
std::string to_string() const {
std::stringstream strm;
strm << "material: ";
strm << " X0: " << m_x0;
strm << " | L0: " << m_l0;
strm << " | Z: " << m_z;

strm << " | state: ";
switch (m_state) {
case material_state::e_solid: {
strm << "solid";
break;
}
case material_state::e_liquid: {
strm << "liquid";
break;
}
case material_state::e_gas: {
strm << "gaseous";
break;
}
default: {
strm << "unknown";
break;
}
};

return strm.str();
}

/// @returns a string stream that prints the material details
DETRAY_HOST
friend std::ostream &operator<<(std::ostream &os, const material &mat) {
os << mat.to_string();
return os;
}

protected:
DETRAY_HOST_DEVICE
constexpr scalar_type mass_to_molar_density(double ar, double mass_rho) {
Expand All @@ -119,13 +164,13 @@ struct material {
}

// Material properties
scalar_type m_x0 = std::numeric_limits<scalar_type>::infinity();
scalar_type m_l0 = std::numeric_limits<scalar_type>::infinity();
scalar_type m_x0 = detail::invalid_value<scalar_type>();
scalar_type m_l0 = detail::invalid_value<scalar_type>();
scalar_type m_ar = 0.f;
scalar_type m_z = 0.f;
scalar_type m_mass_rho = 0.f;
scalar_type m_molar_rho = 0.f;
material_state m_state = material_state::e_solid;
material_state m_state = material_state::e_unknown;
};

// Macro for declaring the predefined materials (with Density effect data)
Expand Down
30 changes: 30 additions & 0 deletions core/include/detray/materials/material_map.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2023 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

// Detray include(s)
#include "detray/definitions/containers.hpp"
#include "detray/materials/material_slab.hpp"
#include "detray/surface_finders/grid/grid.hpp"
#include "detray/tools/grid_factory.hpp"

namespace detray {

/// Definition of binned material
template <typename axes_shape, typename scalar_t,
typename container_t = host_container_types, bool owning = false>
using material_map = grid<coordinate_axes<axes_shape, owning, container_t>,
material_slab<scalar_t>, simple_serializer, replacer>;

/// How to build material maps of various shapes
// TODO: Move to material_map_builder once available
template <typename scalar_t = detray::scalar>
using material_map_factory =
grid_factory<material_slab<scalar_t>, simple_serializer, replacer>;

} // namespace detray
21 changes: 18 additions & 3 deletions core/include/detray/materials/material_rod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
#pragma once

// Project include(s)
#include "detray/definitions/math.hpp"
#include "detray/definitions/qualifiers.hpp"
#include "detray/materials/material.hpp"
#include "detray/materials/predefined_materials.hpp"

// System include(s)
#include <limits>
#include <ostream>

namespace detray {

// Rod structure to be mapped on the line mask
Expand Down Expand Up @@ -66,14 +71,14 @@ struct material_rod : public detail::homogeneous_material_tag {
DETRAY_HOST_DEVICE constexpr scalar_type path_segment(
const scalar_type cos_inc_angle, const scalar_type approach) const {
// Assume that is.local[0] is radial distance of line intersector
if (std::abs(approach) > m_radius) {
if (math_ns::abs(approach) > m_radius) {
return 0.f;
}

const scalar_type sin_inc_angle_2{1.f - cos_inc_angle * cos_inc_angle};

return 2.f * std::sqrt((m_radius * m_radius - approach * approach) /
sin_inc_angle_2);
return 2.f * math_ns::sqrt((m_radius * m_radius - approach * approach) /
sin_inc_angle_2);
}

/// @returns the path segment through the material in X0
Expand All @@ -94,6 +99,16 @@ struct material_rod : public detail::homogeneous_material_tag {
return this->path_segment(cos_inc_angle, approach) / m_material.L0();
}

/// @returns a string stream that prints the material details
DETRAY_HOST
friend std::ostream& operator<<(std::ostream& os, const material_rod& mat) {
os << "rod: ";
os << mat.get_material().to_string();
os << " | radius: " << mat.radius() << "mm";

return os;
}

private:
material_type m_material = {};
scalar_type m_radius = std::numeric_limits<scalar>::epsilon();
Expand Down
12 changes: 12 additions & 0 deletions core/include/detray/materials/material_slab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// System include(s)
#include <limits>
#include <ostream>

namespace detray {

Expand Down Expand Up @@ -92,6 +93,17 @@ struct material_slab : public detail::homogeneous_material_tag {
return m_thickness_in_L0 / cos_inc_angle;
}

/// @returns a string stream that prints the material details
DETRAY_HOST
friend std::ostream& operator<<(std::ostream& os,
const material_slab& mat) {
os << "slab: ";
os << mat.get_material().to_string();
os << " | thickness: " << mat.thickness() << "mm";

return os;
}

private:
material_type m_material = {};
scalar_type m_thickness = std::numeric_limits<scalar>::epsilon();
Expand Down
Loading

0 comments on commit 7fe1c2e

Please sign in to comment.