Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-31 08:17:32

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 #include "ActsPlugins/GeoModel/detail/GeoModelBinningHelper.hpp"
0010 
0011 #include <numbers>
0012 
0013 #include <boost/algorithm/string.hpp>
0014 
0015 using namespace Acts;
0016 
0017 std::tuple<DirectedProtoAxis, std::size_t>
0018 ActsPlugins::detail::GeoModelBinningHelper::toProtoAxis(
0019     const std::string& binning, const std::optional<Extent>& extent) {
0020   std::vector<std::string> binningTokens;
0021   boost::split(binningTokens, binning, boost::is_any_of(","));
0022   AxisDirection axisDir = toAxisDirection(binningTokens[0]);
0023 
0024   std::vector<std::string> binningDetails = {binningTokens.begin() + 1,
0025                                              binningTokens.end()};
0026   if (binningDetails.size() < 2u) {
0027     throw std::invalid_argument(
0028         "GeoModelBinningHelper: Invalid number of binning details, at least "
0029         "the axis boundary type and the number of bins are needed.");
0030   }
0031   AxisBoundaryType boundaryType = AxisBoundaryType::Bound;
0032   std::string axisBoundaryToken = binningDetails[0];
0033   if (axisBoundaryToken == "closed") {
0034     boundaryType = AxisBoundaryType::Closed;
0035   } else if (axisBoundaryToken != "bound") {
0036     throw std::invalid_argument(
0037         "GeoModelBinningHelper: Axis boundary type needs to be closed or "
0038         "bound.'");
0039   }
0040   // The number of bins
0041   std::size_t nBins = std::stoul(binningDetails[1]);
0042   // The bin expansion
0043   std::size_t nExpansion = 0u;
0044   if (binningDetails.size() > 2u) {
0045     nExpansion = std::stoul(binningDetails[2]);
0046   }
0047   // Bool auto_range
0048   bool autoRange = true;
0049   // The Range
0050   double rangeMin = 0.;
0051   double rangeMax = 0.;
0052   if (axisDir == AxisDirection::AxisPhi &&
0053       boundaryType == AxisBoundaryType::Closed) {
0054     rangeMin = -std::numbers::pi;
0055     rangeMax = std::numbers::pi;
0056     autoRange = false;
0057   } else {
0058     if (binningDetails.size() > 3u && binningDetails[3] != "*") {
0059       autoRange = false;
0060       rangeMin = std::stod(binningDetails[3]);
0061     } else if (extent.has_value() && extent.value().constrains(axisDir)) {
0062       autoRange = false;
0063       rangeMin = extent.value().min(axisDir);
0064     } else if (binningDetails[3] != "*") {
0065       throw std::invalid_argument(
0066           "GeoModelBinningHelper: Range minimum is not defined.");
0067     }
0068 
0069     if (binningDetails.size() > 4u && binningDetails[4] != "*") {
0070       autoRange = false;
0071       rangeMax = std::stod(binningDetails[4]);
0072     } else if (extent.has_value() && extent.value().constrains(axisDir)) {
0073       autoRange = false;
0074       rangeMax = extent.value().max(axisDir);
0075     } else if (binningDetails[4] != "*") {
0076       throw std::invalid_argument(
0077           "GeoModelBinningHelper: Range maximum is not defined.");
0078     }
0079   }
0080   auto pAxis = autoRange ? DirectedProtoAxis(axisDir, boundaryType, nBins)
0081                          : DirectedProtoAxis(axisDir, boundaryType, rangeMin,
0082                                              rangeMax, nBins);
0083   return {pAxis, nExpansion};
0084 }