Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-29 07:54:59

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