Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:28:12

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/Detector/ProtoBinning.hpp"
0013 #include "Acts/Geometry/Extent.hpp"
0014 #include "Acts/Plugins/DD4hep/DD4hepConversionHelpers.hpp"
0015 #include "Acts/Utilities/AxisDefinitions.hpp"
0016 #include "Acts/Utilities/BinningData.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 Acts {
0027 
0028 static std::vector<std::tuple<std::string, AxisDirection>> allowedBinnings = {
0029     {"x", AxisDirection::AxisX},
0030     {"y", AxisDirection::AxisY},
0031     {"z", AxisDirection::AxisZ},
0032     {"phi", AxisDirection::AxisPhi},
0033     {"r", AxisDirection::AxisR}};
0034 
0035 /// Helper method to convert the string to binning value
0036 ///
0037 /// @param binningString
0038 ///
0039 /// @return a binningValue
0040 inline AxisDirection stringToAxisDirection(const std::string &binningString) {
0041   using enum AxisDirection;
0042   if (binningString == "x") {
0043     return AxisX;
0044   } else if (binningString == "y") {
0045     return AxisY;
0046   } else if (binningString == "z") {
0047     return AxisZ;
0048   } else if (binningString == "phi") {
0049     return AxisPhi;
0050   } else if (binningString == "r") {
0051     return AxisR;
0052   } else {
0053     throw std::invalid_argument("DD4hepBinningHelpers: Binning value " +
0054                                 binningString + " not allowed.");
0055   }
0056 }
0057 
0058 /// Helper method to cenvert a binning list string to a vector of binning values
0059 /// e.g. "r,z" -> {AxisR, AxisZ}
0060 ///
0061 /// @param binningString
0062 /// @param del the delimiter for the splitting
0063 ///
0064 /// @return a vector of binninng values
0065 inline std::vector<AxisDirection> stringToAxisDirections(
0066     const std::string &binningString, const char &del = ',') {
0067   if (binningString.empty()) {
0068     return {};
0069   }
0070   std::vector<AxisDirection> bBinning;
0071   std::stringstream s(binningString);
0072   std::string b = "";
0073   while (getline(s, b, del)) {
0074     bBinning.push_back(stringToAxisDirection(b));
0075   }
0076   return bBinning;
0077 }
0078 
0079 namespace DD4hepBinningHelpers {
0080 
0081 /// @brief This method converts the DD4hep binning into the Acts ProtoBinning
0082 ///
0083 /// @param dd4hepElement the element which has a binning description attached
0084 /// @param bname the binning base name, e.g. surface_binning, material_binning
0085 ///
0086 /// @return a vector of proto binning descriptions
0087 std::vector<Acts::Experimental::ProtoBinning> convertBinning(
0088     const dd4hep::DetElement &dd4hepElement, const std::string &bname);
0089 
0090 }  // namespace DD4hepBinningHelpers
0091 }  // namespace Acts