Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:16

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include "Acts/Plugins/DD4hep/DD4hepBinningHelpers.hpp"
0010 
0011 std::vector<Acts::Experimental::ProtoBinning>
0012 Acts::DD4hepBinningHelpers::convertBinning(
0013     const dd4hep::DetElement &dd4hepElement, const std::string &bname) {
0014   // Return proto binning vector
0015   std::vector<Experimental::ProtoBinning> protoBinnings;
0016 
0017   for (const auto &[ab, bVal] : allowedBinnings) {
0018     auto type =
0019         getParamOr<std::string>(bname + "_" + ab + "_type", dd4hepElement, "");
0020     if (!type.empty()) {
0021       // Default binning is bound
0022       auto bType = Acts::detail::AxisBoundaryType::Bound;
0023       // Equidistant or variable binning
0024       detail::AxisType aType = type == "equidistant"
0025                                    ? detail::AxisType::Equidistant
0026                                    : detail::AxisType::Variable;
0027       int nBins = getParamOr<int>(bname + "_" + ab + "_n", dd4hepElement, 0);
0028       int nExpansion =
0029           getParamOr<int>(bname + "_" + ab + "_exp", dd4hepElement, 0);
0030       // Indicate auto-range checking
0031       bool autoRange = getParamOr<bool>(bname + "_" + ab + "_autorange",
0032                                         dd4hepElement, false);
0033       // Equidistant binning
0034       if (aType == detail::AxisType::Equidistant) {
0035         if (autoRange) {
0036           protoBinnings.push_back(
0037               Experimental::ProtoBinning(bVal, bType, nBins, nExpansion));
0038         } else {
0039           // Equidistant binning
0040           ActsScalar minDefault = bVal == binPhi ? -M_PI : 0.;
0041           ActsScalar maxDefault = bVal == binPhi ? M_PI : 0.;
0042           auto min = getParamOr<ActsScalar>(bname + "_" + ab + "_min",
0043                                             dd4hepElement, minDefault);
0044           auto max = getParamOr<ActsScalar>(bname + "_" + ab + "_max",
0045                                             dd4hepElement, maxDefault);
0046           // Check for closed phi binning
0047           if (bVal == binPhi && (max - min) > 1.9 * M_PI) {
0048             bType = Acts::detail::AxisBoundaryType::Closed;
0049           }
0050           protoBinnings.push_back(Experimental::ProtoBinning(
0051               bVal, bType, min, max, nBins, nExpansion));
0052         }
0053       } else {
0054         // Variable binning
0055         std::vector<ActsScalar> edges;
0056         for (int ib = 0; ib <= nBins; ++ib) {
0057           edges.push_back(getParamOr<ActsScalar>(
0058               bname + "_" + ab + "_b" + std::to_string(ib), dd4hepElement, 0.));
0059         }
0060         // Check for closed phi binning
0061         if (bVal == binPhi && (edges.back() - edges.front()) > 1.9 * M_PI) {
0062           bType = Acts::detail::AxisBoundaryType::Closed;
0063         }
0064         protoBinnings.push_back(
0065             Experimental::ProtoBinning(bVal, bType, edges, nExpansion));
0066       }
0067     }
0068   }
0069   return protoBinnings;
0070 }