Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:15:34

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