Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:03:27

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/DD4hep/DD4hepBinningHelpers.hpp"
0010 
0011 #include <numbers>
0012 
0013 namespace Acts {
0014 
0015 std::vector<std::tuple<DirectedProtoAxis, std::size_t>>
0016 DD4hepBinningHelpers::convertBinning(const dd4hep::DetElement &dd4hepElement,
0017                                      const std::string &bname) {
0018   // Return proto binning vector
0019   std::vector<std::tuple<DirectedProtoAxis, std::size_t>> protoBinnings;
0020 
0021   for (const auto &[ab, axisDir] : allowedBinnings) {
0022     auto type =
0023         getParamOr<std::string>(bname + "_" + ab + "_type", dd4hepElement, "");
0024     if (!type.empty()) {
0025       // Default binning is bound
0026       auto bType = AxisBoundaryType::Bound;
0027       // Equidistant or variable binning
0028       AxisType aType =
0029           type == "equidistant" ? AxisType::Equidistant : AxisType::Variable;
0030       int nBins = getParamOr<int>(bname + "_" + ab + "_n", dd4hepElement, 0);
0031       int nExpansion =
0032           getParamOr<int>(bname + "_" + ab + "_exp", dd4hepElement, 0);
0033       // Indicate auto-range checking
0034       bool autoRange = getParamOr<bool>(bname + "_" + ab + "_autorange",
0035                                         dd4hepElement, false);
0036       // Equidistant binning
0037       if (aType == AxisType::Equidistant) {
0038         if (autoRange) {
0039           protoBinnings.emplace_back(DirectedProtoAxis(axisDir, bType, nBins),
0040                                      nExpansion);
0041         } else {
0042           // Equidistant binning
0043           double minDefault =
0044               axisDir == AxisDirection::AxisPhi ? -std::numbers::pi : 0.;
0045           double maxDefault =
0046               axisDir == AxisDirection::AxisPhi ? std::numbers::pi : 0.;
0047           auto min = getParamOr<double>(bname + "_" + ab + "_min",
0048                                         dd4hepElement, minDefault);
0049           auto max = getParamOr<double>(bname + "_" + ab + "_max",
0050                                         dd4hepElement, maxDefault);
0051           // Check for closed phi binning
0052           if (axisDir == AxisDirection::AxisPhi &&
0053               (max - min) > 1.9 * std::numbers::pi) {
0054             bType = AxisBoundaryType::Closed;
0055           }
0056           protoBinnings.emplace_back(
0057               DirectedProtoAxis(axisDir, bType, min, max, nBins), nExpansion);
0058         }
0059       } else {
0060         // Variable binning
0061         std::vector<double> edges;
0062         for (int ib = 0; ib <= nBins; ++ib) {
0063           edges.push_back(getParamOr<double>(
0064               bname + "_" + ab + "_b" + std::to_string(ib), dd4hepElement, 0.));
0065         }
0066         // Check for closed phi binning
0067         if (axisDir == AxisDirection::AxisPhi &&
0068             (edges.back() - edges.front()) > 1.9 * std::numbers::pi) {
0069           bType = AxisBoundaryType::Closed;
0070         }
0071         protoBinnings.emplace_back(DirectedProtoAxis(axisDir, bType, edges),
0072                                    nExpansion);
0073       }
0074     }
0075   }
0076   return protoBinnings;
0077 }
0078 
0079 }  // namespace Acts