File indexing completed on 2025-01-30 09:15:18
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/Json/ProtoAxisJsonConverter.hpp"
0010
0011 #include "Acts/Plugins/Json/GridJsonConverter.hpp"
0012 #include "Acts/Plugins/Json/UtilitiesJsonConverter.hpp"
0013 #include "Acts/Utilities/AxisDefinitions.hpp"
0014
0015 nlohmann::json Acts::ProtoAxisJsonConverter::toJson(const Acts::ProtoAxis& pa) {
0016 nlohmann::json j;
0017 j["axis_dir"] = pa.getAxisDirection();
0018 j["axis"] = AxisJsonConverter::toJson(pa.getAxis());
0019 j["autorange"] = pa.isAutorange();
0020 return j;
0021 }
0022
0023 Acts::ProtoAxis Acts::ProtoAxisJsonConverter::fromJson(
0024 const nlohmann::json& j) {
0025 auto axisDir = j.at("axis_dir").get<Acts::AxisDirection>();
0026 auto axisBoundaryType =
0027 j.at("axis").at("boundary_type").get<Acts::AxisBoundaryType>();
0028 if (auto axisType = j.at("axis").at("type").get<Acts::AxisType>();
0029 axisType == AxisType::Equidistant) {
0030 auto nbins = j.at("axis").at("bins").get<std::size_t>();
0031 if (nbins == 0) {
0032 throw std::invalid_argument("Number of bins must be positive");
0033 }
0034
0035 if (j.at("autorange").get<bool>()) {
0036 return ProtoAxis(axisDir, axisBoundaryType, nbins);
0037 }
0038 auto min = j.at("axis").at("range").at(0).get<double>();
0039 auto max = j.at("axis").at("range").at(1).get<double>();
0040 if (min >= max) {
0041 throw std::invalid_argument("Invalid range: min must be less than max");
0042 }
0043 return ProtoAxis(axisDir, axisBoundaryType, min, max, nbins);
0044 }
0045 auto binEdges = j.at("axis").at("boundaries").get<std::vector<double>>();
0046 if (binEdges.size() < 2) {
0047 throw std::invalid_argument("At least two bin edges required");
0048 }
0049 if (!std::ranges::is_sorted(binEdges)) {
0050 throw std::invalid_argument("Bin edges must be sorted in ascending order");
0051 }
0052 return ProtoAxis(axisDir, axisBoundaryType, binEdges);
0053 }