File indexing completed on 2025-01-18 09:27:41
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013
0014 #include <DD4hep/DetElement.h>
0015 #include <DD4hep/DetFactoryHelper.h>
0016 #include <DD4hep/Objects.h>
0017 #include <DDRec/DetectorData.h>
0018
0019 namespace Acts {
0020
0021
0022
0023
0024
0025
0026
0027 template <typename T>
0028 T getParam(const std::string& key, dd4hep::DetElement& elt) {
0029 auto* params = elt.extension<dd4hep::rec::VariantParameters>(false);
0030 if (params == nullptr) {
0031 throw std::runtime_error{"Detector Element has no VariantParameters"};
0032 }
0033 return params->get<T>(key);
0034 }
0035
0036
0037
0038
0039 inline dd4hep::rec::VariantParameters& getParams(dd4hep::DetElement& elt) {
0040 auto* params = elt.extension<dd4hep::rec::VariantParameters>(false);
0041 if (params == nullptr) {
0042 throw std::runtime_error{"Detector Element has no VariantParameters"};
0043 }
0044 return *params;
0045 }
0046
0047
0048
0049
0050 inline const dd4hep::rec::VariantParameters& getParams(
0051 const dd4hep::DetElement& elt) {
0052 const auto* params = elt.extension<dd4hep::rec::VariantParameters>(false);
0053 if (params == nullptr) {
0054 throw std::runtime_error{"Detector Element has no VariantParameters"};
0055 }
0056 return *params;
0057 }
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 template <typename T>
0068 T getParamOr(const std::string& key, const dd4hep::DetElement& elt,
0069 T alternative) {
0070 auto* params = elt.extension<dd4hep::rec::VariantParameters>(false);
0071 if (params == nullptr) {
0072 return alternative;
0073 }
0074 return params->value_or<T>(key, alternative);
0075 }
0076
0077
0078
0079
0080
0081
0082 inline bool hasParam(const std::string& key, dd4hep::DetElement& elt) {
0083 auto* params = elt.extension<dd4hep::rec::VariantParameters>(false);
0084 if (params == nullptr) {
0085 return false;
0086 }
0087 return params->contains(key);
0088 }
0089
0090
0091
0092
0093 inline bool hasParams(dd4hep::DetElement& elt) {
0094 return elt.extension<dd4hep::rec::VariantParameters>(false) != nullptr;
0095 }
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 template <typename value_type>
0109 value_type getAttrValueOr(const dd4hep::xml::Component& node,
0110 const std::string& attrName,
0111 const value_type& fallbackValue) {
0112 if (node.hasAttr(dd4hep::xml::Strng_t(attrName.c_str()))) {
0113 return node.attr<value_type>(attrName.c_str());
0114 } else {
0115 return fallbackValue;
0116 }
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128 template <typename value_type>
0129 std::vector<value_type> extractSeries(const dd4hep::DetElement& dd4hepElement,
0130 const std::string& bname,
0131 const value_type& unitConversion = 1) {
0132 std::vector<value_type> series = {};
0133
0134 int fallBack = 0;
0135 int nVals = getParamOr<int>(bname + "_n", dd4hepElement, fallBack);
0136 series.reserve(nVals);
0137 for (auto ib = 0; ib < nVals; ++ib) {
0138 auto val = unitConversion *
0139 getParamOr<value_type>(bname + "_" + std::to_string(ib),
0140 dd4hepElement, 0.);
0141 series.push_back(val);
0142 }
0143 return series;
0144 }
0145
0146
0147
0148
0149
0150
0151
0152
0153 inline Transform3 extractTransform(const dd4hep::DetElement& dd4hepElement,
0154 const std::string& bname,
0155 const ActsScalar unitConversion = 1.) {
0156 Transform3 transform = Transform3::Identity();
0157 ActsScalar x =
0158 unitConversion * getParamOr<ActsScalar>(bname + "_x", dd4hepElement, 0.);
0159 ActsScalar y =
0160 unitConversion * getParamOr<ActsScalar>(bname + "_y", dd4hepElement, 0.);
0161 ActsScalar z =
0162 unitConversion * getParamOr<ActsScalar>(bname + "_z", dd4hepElement, 0.);
0163 transform.pretranslate(Vector3(x, y, z));
0164 return transform;
0165 }
0166
0167 }