Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-25 08:23:06

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/DD4hep/DD4hepBinningHelpers.hpp"
0010 
0011 #include <numbers>
0012 
0013 using namespace Acts;
0014 
0015 namespace ActsPlugins {
0016 
0017 std::vector<std::tuple<AxisSpec, std::size_t>>
0018 DD4hepBinningHelpers::convertAxisSpecs(const dd4hep::DetElement &dd4hepElement,
0019                                        const std::string &bname) {
0020   std::vector<std::tuple<AxisSpec, std::size_t>> axisSpecs;
0021 
0022   for (const auto &[ab, axisDir] : allowedBinnings) {
0023     auto type =
0024         getParamOr<std::string>(bname + "_" + ab + "_type", dd4hepElement, "");
0025     if (!type.empty()) {
0026       // Equidistant or variable binning
0027       AxisType aType =
0028           type == "equidistant" ? AxisType::Equidistant : AxisType::Variable;
0029       int nBins = getParamOr<int>(bname + "_" + ab + "_n", dd4hepElement, 0);
0030       int nExpansion =
0031           getParamOr<int>(bname + "_" + ab + "_exp", dd4hepElement, 0);
0032       // Indicate auto-range checking
0033       bool autoRange = getParamOr<bool>(bname + "_" + ab + "_autorange",
0034                                         dd4hepElement, false);
0035       if (aType == AxisType::Equidistant) {
0036         if (autoRange) {
0037           // Deferred binning: the consumer determines range and boundary type
0038           axisSpecs.emplace_back(AxisSpec::DeferredEquidistant(nBins, axisDir),
0039                                  nExpansion);
0040         } else {
0041           // Equidistant binning
0042           double minDefault =
0043               axisDir == AxisDirection::AxisPhi ? -std::numbers::pi : 0.;
0044           double maxDefault =
0045               axisDir == AxisDirection::AxisPhi ? std::numbers::pi : 0.;
0046           auto min = getParamOr<double>(bname + "_" + ab + "_min",
0047                                         dd4hepElement, minDefault);
0048           auto max = getParamOr<double>(bname + "_" + ab + "_max",
0049                                         dd4hepElement, maxDefault);
0050           // The boundary type is not expressible in DD4hep, the consumer
0051           // determines it from the surface
0052           axisSpecs.emplace_back(
0053               AxisSpec::Equidistant(nBins, min, max, std::nullopt, axisDir),
0054               nExpansion);
0055         }
0056       } else {
0057         // Variable binning
0058         std::vector<double> edges;
0059         for (int ib = 0; ib <= nBins; ++ib) {
0060           edges.push_back(getParamOr<double>(
0061               bname + "_" + ab + "_b" + std::to_string(ib), dd4hepElement, 0.));
0062         }
0063         axisSpecs.emplace_back(
0064             AxisSpec::Variable(std::move(edges), std::nullopt, axisDir),
0065             nExpansion);
0066       }
0067     }
0068   }
0069   return axisSpecs;
0070 }
0071 
0072 // The definition does not carry the deprecation attribute, so it needs the
0073 // suppression
0074 ACTS_PUSH_IGNORE_DEPRECATED()
0075 
0076 std::vector<std::tuple<DirectedProtoAxis, std::size_t>>
0077 DD4hepBinningHelpers::convertBinning(const dd4hep::DetElement &dd4hepElement,
0078                                      const std::string &bname) {
0079   // Return proto binning vector
0080   std::vector<std::tuple<DirectedProtoAxis, std::size_t>> protoBinnings;
0081 
0082   for (const auto &[ab, axisDir] : allowedBinnings) {
0083     auto type =
0084         getParamOr<std::string>(bname + "_" + ab + "_type", dd4hepElement, "");
0085     if (!type.empty()) {
0086       // Default binning is bound
0087       auto bType = AxisBoundaryType::Bound;
0088       // Equidistant or variable binning
0089       AxisType aType =
0090           type == "equidistant" ? AxisType::Equidistant : AxisType::Variable;
0091       int nBins = getParamOr<int>(bname + "_" + ab + "_n", dd4hepElement, 0);
0092       int nExpansion =
0093           getParamOr<int>(bname + "_" + ab + "_exp", dd4hepElement, 0);
0094       // Indicate auto-range checking
0095       bool autoRange = getParamOr<bool>(bname + "_" + ab + "_autorange",
0096                                         dd4hepElement, false);
0097       // Equidistant binning
0098       if (aType == AxisType::Equidistant) {
0099         if (autoRange) {
0100           protoBinnings.emplace_back(DirectedProtoAxis(axisDir, bType, nBins),
0101                                      nExpansion);
0102         } else {
0103           // Equidistant binning
0104           double minDefault =
0105               axisDir == AxisDirection::AxisPhi ? -std::numbers::pi : 0.;
0106           double maxDefault =
0107               axisDir == AxisDirection::AxisPhi ? std::numbers::pi : 0.;
0108           auto min = getParamOr<double>(bname + "_" + ab + "_min",
0109                                         dd4hepElement, minDefault);
0110           auto max = getParamOr<double>(bname + "_" + ab + "_max",
0111                                         dd4hepElement, maxDefault);
0112           // Check for closed phi binning
0113           if (axisDir == AxisDirection::AxisPhi &&
0114               (max - min) > 1.9 * std::numbers::pi) {
0115             bType = AxisBoundaryType::Closed;
0116           }
0117           protoBinnings.emplace_back(
0118               DirectedProtoAxis(axisDir, bType, min, max, nBins), nExpansion);
0119         }
0120       } else {
0121         // Variable binning
0122         std::vector<double> edges;
0123         for (int ib = 0; ib <= nBins; ++ib) {
0124           edges.push_back(getParamOr<double>(
0125               bname + "_" + ab + "_b" + std::to_string(ib), dd4hepElement, 0.));
0126         }
0127         // Check for closed phi binning
0128         if (axisDir == AxisDirection::AxisPhi &&
0129             (edges.back() - edges.front()) > 1.9 * std::numbers::pi) {
0130           bType = AxisBoundaryType::Closed;
0131         }
0132         protoBinnings.emplace_back(DirectedProtoAxis(axisDir, bType, edges),
0133                                    nExpansion);
0134       }
0135     }
0136   }
0137   return protoBinnings;
0138 }
0139 
0140 ACTS_POP_IGNORE_DEPRECATED()
0141 
0142 }  // namespace ActsPlugins