Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 09:40:21

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Geometry/Extent.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014 #include "Acts/Utilities/BinningData.hpp"
0015 #include "Acts/Utilities/ProtoAxis.hpp"
0016 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0017 
0018 #include <optional>
0019 #include <sstream>
0020 #include <string>
0021 #include <tuple>
0022 #include <vector>
0023 
0024 #include <DDRec/DetectorData.h>
0025 
0026 namespace ActsPlugins {
0027 
0028 static const std::vector<std::tuple<std::string, Acts::AxisDirection>>
0029     allowedBinnings = {{"x", Acts::AxisDirection::AxisX},
0030                        {"y", Acts::AxisDirection::AxisY},
0031                        {"z", Acts::AxisDirection::AxisZ},
0032                        {"phi", Acts::AxisDirection::AxisPhi},
0033                        {"r", Acts::AxisDirection::AxisR}};
0034 
0035 /// Helper method to convert the string to binning value
0036 ///
0037 /// @param binningString
0038 ///
0039 /// @return a binningValue
0040 inline Acts::AxisDirection stringToAxisDirection(
0041     const std::string &binningString) {
0042   using enum Acts::AxisDirection;
0043   if (binningString == "x") {
0044     return AxisX;
0045   } else if (binningString == "y") {
0046     return AxisY;
0047   } else if (binningString == "z") {
0048     return AxisZ;
0049   } else if (binningString == "phi") {
0050     return AxisPhi;
0051   } else if (binningString == "r") {
0052     return AxisR;
0053   } else {
0054     throw std::invalid_argument("DD4hepBinningHelpers: Binning value " +
0055                                 binningString + " not allowed.");
0056   }
0057 }
0058 
0059 /// Helper method to cenvert a binning list string to a vector of binning values
0060 /// e.g. "r,z" -> {AxisR, AxisZ}
0061 ///
0062 /// @param binningString
0063 /// @param del the delimiter for the splitting
0064 ///
0065 /// @return a vector of binninng values
0066 inline std::vector<Acts::AxisDirection> stringToAxisDirections(
0067     const std::string &binningString, const char &del = ',') {
0068   if (binningString.empty()) {
0069     return {};
0070   }
0071   std::vector<Acts::AxisDirection> bBinning;
0072   std::stringstream s(binningString);
0073   std::string b = "";
0074   while (getline(s, b, del)) {
0075     bBinning.push_back(stringToAxisDirection(b));
0076   }
0077   return bBinning;
0078 }
0079 
0080 namespace DD4hepBinningHelpers {
0081 
0082 /// @brief This method converts the DD4hep binning into the Acts ProtoAxis
0083 ///
0084 /// @param dd4hepElement the element which has a binning description attached
0085 /// @param bname the binning base name, e.g. surface_binning, material_binning
0086 ///
0087 /// @return a vector of proto binning descriptions
0088 std::vector<std::tuple<Acts::DirectedProtoAxis, std::size_t>> convertBinning(
0089     const dd4hep::DetElement &dd4hepElement, const std::string &bname);
0090 
0091 }  // namespace DD4hepBinningHelpers
0092 }  // namespace ActsPlugins