File indexing completed on 2024-06-26 07:06:13
0001
0002
0003
0004 #pragma once
0005
0006 #include <DD4hep/DetElement.h>
0007 #include <DDRec/DetectorData.h>
0008 #include <boost/foreach.hpp>
0009 #include <boost/tokenizer.hpp>
0010
0011 #include "DD4hep/DetFactoryHelper.h"
0012
0013 namespace DD4hepDetectorHelper {
0014
0015 template <typename T> T& ensureExtension(dd4hep::DetElement& elt) {
0016 T* ext = elt.extension<T>(false);
0017 if (ext == nullptr) {
0018 ext = new T();
0019 }
0020 elt.addExtension<T>(ext);
0021 return *ext;
0022 }
0023
0024 inline void xmlToProtoSurfaceMaterial(const xml_comp_t& x_material,
0025 dd4hep::rec::VariantParameters& params,
0026 const std::string& baseTag) {
0027 using namespace std::string_literals;
0028 using namespace dd4hep;
0029
0030
0031 params.set(baseTag, true);
0032
0033 std::string mSurface = x_material.attr<std::string>("surface");
0034 std::string mBinning = x_material.attr<std::string>("binning");
0035 boost::char_separator<char> sep(",");
0036 boost::tokenizer binTokens(mBinning, sep);
0037 const auto n = std::distance(binTokens.begin(), binTokens.end());
0038 if (n == 2) {
0039
0040 auto bin = binTokens.begin();
0041 std::string bin0 = *(bin);
0042 std::string bin1 = *(++bin);
0043 size_t nBins0 = x_material.attr<int>("bins0");
0044 size_t nBins1 = x_material.attr<int>("bins1");
0045
0046 std::string btmSurface = baseTag + "_"s + mSurface;
0047 params.set<bool>(btmSurface, true);
0048 params.set<int>(btmSurface + "_"s + bin0, nBins0);
0049 params.set<int>(btmSurface + "_"s + bin1, nBins1);
0050 }
0051 }
0052
0053 }