File indexing completed on 2025-08-06 08:10:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "DetUtils.h"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Digitization/CartesianSegmentation.hpp"
0013 #include "Acts/Digitization/DigitizationModule.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0016
0017 #include <cstddef>
0018
0019 #include <DD4hep/CartesianGridXZ.h>
0020 #include <DD4hep/Segmentations.h>
0021 #include <XML/XMLTags.h>
0022
0023 namespace det::utils {
0024
0025 std::shared_ptr<const Acts::DigitizationModule> rectangleDigiModuleXZ(
0026 double halflengthX, double halflengthZ, double thickness,
0027 const dd4hep::Segmentation& segmentation) {
0028
0029 double scalor = Acts::UnitConstants::cm;
0030 halflengthX *= scalor;
0031 halflengthZ *= scalor;
0032 thickness *= scalor;
0033 auto bounds =
0034 std::make_shared<const Acts::RectangleBounds>(halflengthX, halflengthZ);
0035 dd4hep::CartesianGridXZ cartesianGrid = segmentation;
0036 if (cartesianGrid.isValid()) {
0037
0038 double gridSizeX = cartesianGrid.gridSizeX() * scalor;
0039 double gridSizeZ = cartesianGrid.gridSizeZ() * scalor;
0040 std::size_t bins0 =
0041 (cartesianGrid.gridSizeX() != 0)
0042 ? static_cast<std::size_t>((2 * halflengthX) / gridSizeX)
0043 : 0;
0044 std::size_t bins1 =
0045 (cartesianGrid.gridSizeZ() != 0)
0046 ? static_cast<std::size_t>((2 * halflengthZ) / gridSizeZ)
0047 : 0;
0048
0049 std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
0050 std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0,
0051 bins1);
0052
0053
0054 return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
0055 thickness, 1, 0));
0056 }
0057 return nullptr;
0058 }
0059
0060 std::shared_ptr<const Acts::DigitizationModule> rectangleDigiModuleXZ(
0061 double halflengthX, double halflengthZ, double thickness, double gridSizeX,
0062 double gridSizeZ) {
0063
0064 double scalor = Acts::UnitConstants::cm;
0065 halflengthX *= scalor;
0066 halflengthZ *= scalor;
0067 thickness *= scalor;
0068 auto bounds =
0069 std::make_shared<const Acts::RectangleBounds>(halflengthX, halflengthZ);
0070
0071 std::size_t bins0 =
0072 (gridSizeX != 0)
0073 ? static_cast<std::size_t>((2 * halflengthX) / (gridSizeX * scalor))
0074 : 0;
0075 std::size_t bins1 =
0076 (gridSizeZ != 0)
0077 ? static_cast<std::size_t>((2 * halflengthZ) / (gridSizeZ * scalor))
0078 : 0;
0079
0080 std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
0081 std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0, bins1);
0082
0083
0084
0085 return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
0086 thickness, 1, 0));
0087 }
0088
0089 std::shared_ptr<const Acts::DigitizationModule> trapezoidalDigiModuleXZ(
0090 double minHalflengthX, double maxHalflengthX, double halflengthZ,
0091 double thickness, const dd4hep::Segmentation& segmentation) {
0092
0093 double scalor = Acts::UnitConstants::cm;
0094 minHalflengthX *= scalor;
0095 maxHalflengthX *= scalor;
0096 halflengthZ *= scalor;
0097 thickness *= scalor;
0098
0099 auto bounds = std::make_shared<const Acts::TrapezoidBounds>(
0100 minHalflengthX, maxHalflengthX, halflengthZ);
0101
0102 dd4hep::CartesianGridXZ cartesianGrid = segmentation;
0103 if (cartesianGrid.isValid()) {
0104
0105 double gridSizeX = cartesianGrid.gridSizeX() * scalor;
0106 double gridSizeZ = cartesianGrid.gridSizeZ() * scalor;
0107 std::size_t bins0 =
0108 (cartesianGrid.gridSizeX() != 0)
0109 ? static_cast<std::size_t>((2 * maxHalflengthX) / gridSizeX)
0110 : 0;
0111 std::size_t bins1 =
0112 (cartesianGrid.gridSizeZ() != 0)
0113 ? static_cast<std::size_t>((2 * halflengthZ) / gridSizeZ)
0114 : 0;
0115
0116 std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
0117 std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0,
0118 bins1);
0119
0120
0121 return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
0122 thickness, 1, 0));
0123 }
0124 return nullptr;
0125 }
0126
0127 std::shared_ptr<const Acts::DigitizationModule> trapezoidalDigiModuleXZ(
0128 double minHalflengthX, double maxHalflengthX, double halflengthZ,
0129 double thickness, double gridSizeX, double gridSizeZ) {
0130
0131 double scalor = Acts::UnitConstants::cm;
0132 minHalflengthX *= scalor;
0133 maxHalflengthX *= scalor;
0134 halflengthZ *= scalor;
0135 thickness *= scalor;
0136
0137 auto bounds = std::make_shared<const Acts::TrapezoidBounds>(
0138 minHalflengthX, maxHalflengthX, halflengthZ);
0139
0140
0141 std::size_t bins0 = (gridSizeX != 0)
0142 ? static_cast<std::size_t>((2 * maxHalflengthX) /
0143 (gridSizeX * scalor))
0144 : 0;
0145 std::size_t bins1 =
0146 (gridSizeZ != 0)
0147 ? static_cast<std::size_t>((2 * halflengthZ) / (gridSizeZ * scalor))
0148 : 0;
0149
0150 std::shared_ptr<const Acts::CartesianSegmentation> actsSegmentation =
0151 std::make_shared<const Acts::CartesianSegmentation>(bounds, bins0, bins1);
0152
0153
0154 return (std::make_shared<const Acts::DigitizationModule>(actsSegmentation,
0155 thickness, 1, 0));
0156 }
0157
0158 dd4hep::xml::Component getNodeByStrAttr(const dd4hep::xml::Handle_t& mother,
0159 const std::string& nodeName,
0160 const std::string& attrName,
0161 const std::string& attrValue) {
0162 for (dd4hep::xml::Collection_t xCompColl(mother, nodeName.c_str());
0163 nullptr != xCompColl; ++xCompColl) {
0164 if (xCompColl.attr<std::string>(attrName.c_str()) == attrValue) {
0165 return static_cast<dd4hep::xml::Component>(xCompColl);
0166 }
0167 }
0168
0169 return dd4hep::xml::Component(nullptr);
0170 }
0171
0172 double getAttrValueWithFallback(const dd4hep::xml::Component& node,
0173 const std::string& attrName,
0174 const double& defaultValue) {
0175 if (node.hasAttr(_Unicode(attrName.c_str()))) {
0176 return node.attr<double>(attrName.c_str());
0177 } else {
0178 return defaultValue;
0179 }
0180 }
0181 }