Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-14 08:25:11

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://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/AxisFwd.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, BinningValue>> allowedBinnings = {
0029     {"x", BinningValue::binX},
0030     {"y", BinningValue::binY},
0031     {"z", BinningValue::binZ},
0032     {"phi", BinningValue::binPhi},
0033     {"r", BinningValue::binR}};
0034 
0035 /// Helper method to convert the string to binning value
0036 ///
0037 /// @param binningString
0038 ///
0039 /// @return a binningValue
0040 inline BinningValue stringToBinningValue(const std::string &binningString) {
0041   if (binningString == "x") {
0042     return BinningValue::binX;
0043   } else if (binningString == "y") {
0044     return BinningValue::binY;
0045   } else if (binningString == "z") {
0046     return BinningValue::binZ;
0047   } else if (binningString == "phi") {
0048     return BinningValue::binPhi;
0049   } else if (binningString == "r") {
0050     return BinningValue::binR;
0051   } else {
0052     throw std::invalid_argument("DD4hepBinningHelpers: Binning value " +
0053                                 binningString + " not allowed.");
0054   }
0055 }
0056 
0057 /// Helper method to cenvert a binning list string to a vector of binning values
0058 /// e.g. "r,z" -> {binR, binZ}
0059 ///
0060 /// @param binningString
0061 /// @param del the delimiter for the splitting
0062 ///
0063 /// @return a vector of binninng values
0064 inline std::vector<BinningValue> stringToBinningValues(
0065     const std::string &binningString, const char &del = ',') {
0066   if (binningString.empty()) {
0067     return {};
0068   }
0069   std::vector<BinningValue> bBinning;
0070   std::stringstream s(binningString);
0071   std::string b = "";
0072   while (getline(s, b, del)) {
0073     bBinning.push_back(stringToBinningValue(b));
0074   }
0075   return bBinning;
0076 }
0077 
0078 namespace DD4hepBinningHelpers {
0079 
0080 /// @brief This method converts the DD4hep binning into the Acts ProtoBinning
0081 ///
0082 /// @param dd4hepElement the element which has a binning description attached
0083 /// @param bname the binning base name, e.g. surface_binning, material_binning
0084 ///
0085 /// @return a vector of proto binning descriptions
0086 std::vector<Acts::Experimental::ProtoBinning> convertBinning(
0087     const dd4hep::DetElement &dd4hepElement, const std::string &bname);
0088 
0089 }  // namespace DD4hepBinningHelpers
0090 }  // namespace Acts