File indexing completed on 2025-01-18 09:28:02
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Plugins/Json/ActsJson.hpp"
0012 #include "Acts/Plugins/TGeo/TGeoCylinderDiscSplitter.hpp"
0013 #include "Acts/Utilities/BinningType.hpp"
0014 #include "ActsExamples/TGeoDetector/TGeoDetector.hpp"
0015 #include "ActsExamples/TGeoDetector/TGeoITkModuleSplitter.hpp"
0016 #include "ActsExamples/Utilities/Options.hpp"
0017
0018 #include <map>
0019 #include <string>
0020
0021
0022 namespace Acts {
0023
0024
0025 void from_json(const nlohmann::json& j,
0026 Acts::TGeoCylinderDiscSplitter::Config& cdc) {
0027
0028 cdc.cylinderPhiSegments = j.at("geo-tgeo-cyl-nphi-segs");
0029
0030 cdc.cylinderLongitudinalSegments = j.at("geo-tgeo-cyl-nz-segs");
0031
0032 cdc.discPhiSegments = j.at("geo-tgeo-disc-nphi-segs");
0033
0034 cdc.discRadialSegments = j.at("geo-tgeo-disc-nr-segs");
0035 }
0036
0037
0038 void to_json(nlohmann::json& j,
0039 const Acts::TGeoCylinderDiscSplitter::Config& cdc) {
0040 j = nlohmann::json{{"geo-tgeo-cyl-nphi-segs", cdc.cylinderPhiSegments},
0041 {"geo-tgeo-cyl-nz-segs", cdc.cylinderLongitudinalSegments},
0042 {"geo-tgeo-disc-nphi-segs", cdc.discPhiSegments},
0043 {"geo-tgeo-disc-nr-segs", cdc.discRadialSegments}};
0044 }
0045
0046
0047 NLOHMANN_JSON_SERIALIZE_ENUM(Acts::BinningType,
0048 {
0049 {Acts::BinningType::equidistant,
0050 "equidistant"},
0051 {Acts::BinningType::arbitrary, "arbitrary"},
0052 })
0053
0054 }
0055
0056 namespace ActsExamples {
0057
0058 namespace Options {
0059
0060
0061 void from_json(const nlohmann::json& j,
0062 ActsExamples::Options::Interval& interval) {
0063 interval.lower = j.at("lower");
0064 interval.upper = j.at("upper");
0065 }
0066
0067
0068 void to_json(nlohmann::json& j,
0069 const ActsExamples::Options::Interval& interval) {
0070
0071 j = nlohmann::json{{"lower", interval.lower.value_or(0)},
0072 {"upper", interval.upper.value_or(0)}};
0073 }
0074
0075 }
0076
0077 void from_json(const nlohmann::json& j,
0078 ActsExamples::TGeoITkModuleSplitter::Config& msc) {
0079 msc.barrelMap =
0080 j["geo-tgeo-barrel-map"].get<std::map<std::string, unsigned int>>();
0081 msc.discMap =
0082 j["geo-tgeo-disc-map"]
0083 .get<std::map<std::string, std::vector<std::pair<double, double>>>>();
0084 }
0085
0086 void to_json(nlohmann::json& j,
0087 const ActsExamples::TGeoITkModuleSplitter::Config& msc) {
0088 j["geo-tgeo-barrel-map"] = msc.barrelMap;
0089 j["geo-tgeo-disc-map"] = msc.discMap;
0090 }
0091
0092
0093 template <typename T>
0094 void from_json(const nlohmann::json& j,
0095 ActsExamples::TGeoDetector::Config::LayerTriplet<T>& ltr) {
0096 ltr.negative = j.at("negative").get<T>();
0097 ltr.central = j.at("central").get<T>();
0098 ltr.positive = j.at("positive").get<T>();
0099 }
0100
0101
0102 template <typename T>
0103 void to_json(nlohmann::json& j,
0104 const ActsExamples::TGeoDetector::Config::LayerTriplet<T>& ltr) {
0105 j = nlohmann::json{{"negative", ltr.negative},
0106 {"central", ltr.central},
0107 {"positive", ltr.positive}};
0108 }
0109
0110
0111 void from_json(const nlohmann::json& j,
0112 ActsExamples::TGeoDetector::Config::Volume& vol) {
0113
0114 vol.name = j.at("geo-tgeo-volume-name");
0115
0116
0117 vol.binToleranceR = j.at("geo-tgeo-sfbin-r-tolerance");
0118 vol.binToleranceZ = j.at("geo-tgeo-sfbin-z-tolerance");
0119 vol.binTolerancePhi = j.at("geo-tgeo-sfbin-phi-tolerance");
0120
0121
0122 vol.layers = j.at("geo-tgeo-volume-layers");
0123 vol.subVolumeName = j.at("geo-tgeo-subvolume-names");
0124 vol.sensitiveNames = j.at("geo-tgeo-sensitive-names");
0125 vol.sensitiveAxes = j.at("geo-tgeo-sensitive-axes");
0126 vol.rRange = j.at("geo-tgeo-layer-r-ranges");
0127 vol.zRange = j.at("geo-tgeo-layer-z-ranges");
0128 vol.splitTolR = j.at("geo-tgeo-layer-r-split");
0129 vol.splitTolZ = j.at("geo-tgeo-layer-z-split");
0130
0131 vol.binning0 = j.at("geo-tgeo-binning0");
0132 vol.binning1 = j.at("geo-tgeo-binning1");
0133
0134 vol.cylinderDiscSplit = j.at("geo-tgeo-cyl-disc-split");
0135 if (vol.cylinderDiscSplit) {
0136 Acts::TGeoCylinderDiscSplitter::Config cdConfig =
0137 j.at("Splitters").at("CylinderDisk");
0138 vol.cylinderNZSegments = cdConfig.cylinderLongitudinalSegments;
0139 vol.cylinderNPhiSegments = cdConfig.cylinderPhiSegments;
0140 vol.discNRSegments = cdConfig.discRadialSegments;
0141 vol.discNPhiSegments = cdConfig.discPhiSegments;
0142 }
0143
0144
0145 if (j.count("geo-tgeo-itk-module-split") != 0) {
0146 vol.itkModuleSplit = j.at("geo-tgeo-itk-module-split");
0147 if (vol.itkModuleSplit) {
0148 ActsExamples::TGeoITkModuleSplitter::Config itkConfig =
0149 j.at("Splitters").at("ITk");
0150 vol.barrelMap = itkConfig.barrelMap;
0151 vol.discMap = itkConfig.discMap;
0152 }
0153 } else {
0154 vol.itkModuleSplit = false;
0155 }
0156 }
0157
0158
0159 void to_json(nlohmann::json& j, const TGeoDetector::Config::Volume& vol) {
0160 j["geo-tgeo-volume-name"] = vol.name;
0161
0162 j["geo-tgeo-sfbin-r-tolerance"] = vol.binToleranceR;
0163 j["geo-tgeo-sfbin-z-tolerance"] = vol.binToleranceZ;
0164 j["geo-tgeo-sfbin-phi-tolerance"] = vol.binTolerancePhi;
0165
0166 j["geo-tgeo-volume-layers"] = vol.layers;
0167 j["geo-tgeo-subvolume-names"] = vol.subVolumeName;
0168 j["geo-tgeo-sensitive-names"] = vol.sensitiveNames;
0169 j["geo-tgeo-sensitive-axes"] = vol.sensitiveAxes;
0170 j["geo-tgeo-layer-r-ranges"] = vol.rRange;
0171 j["geo-tgeo-layer-z-ranges"] = vol.zRange;
0172 j["geo-tgeo-layer-r-split"] = vol.splitTolR;
0173 j["geo-tgeo-layer-z-split"] = vol.splitTolZ;
0174 j["geo-tgeo-binning0"] = vol.binning0;
0175 j["geo-tgeo-binning1"] = vol.binning1;
0176
0177 j["geo-tgeo-cyl-disc-split"] = vol.cylinderDiscSplit;
0178 j["geo-tgeo-itk-module-split"] = vol.itkModuleSplit;
0179
0180 Acts::TGeoCylinderDiscSplitter::Config cdConfig;
0181 cdConfig.cylinderLongitudinalSegments = vol.cylinderNZSegments;
0182 cdConfig.cylinderPhiSegments = vol.cylinderNPhiSegments;
0183 cdConfig.discRadialSegments = vol.discNRSegments;
0184 cdConfig.discPhiSegments = vol.discNPhiSegments;
0185 j["Splitters"]["CylinderDisk"] = cdConfig;
0186
0187 if (vol.itkModuleSplit) {
0188 ActsExamples::TGeoITkModuleSplitter::Config itkConfig;
0189 itkConfig.barrelMap = vol.barrelMap;
0190 itkConfig.discMap = vol.discMap;
0191 j["Splitters"]["ITk"] = itkConfig;
0192 }
0193 }
0194
0195 }