Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:41

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