Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-18 08:25: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 #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 #include <nlohmann/json.hpp>
0022 
0023 // Namespace of the module splitters
0024 namespace Acts {
0025 
0026 /// Read config for cylinder/disc module splitter
0027 void from_json(const nlohmann::json& j,
0028                Acts::TGeoCylinderDiscSplitter::Config& cdc) {
0029   /// Number of segments in phi for a disc
0030   cdc.cylinderPhiSegments = j.at("geo-tgeo-cyl-nphi-segs");
0031   /// Number of segments in r for a disk
0032   cdc.cylinderLongitudinalSegments = j.at("geo-tgeo-cyl-nz-segs");
0033   /// Number of segments in phi for a disc
0034   cdc.discPhiSegments = j.at("geo-tgeo-disc-nphi-segs");
0035   /// Number of segments in r for a disk
0036   cdc.discRadialSegments = j.at("geo-tgeo-disc-nr-segs");
0037 }
0038 
0039 /// Write config for cylinder/disc module splitter
0040 void to_json(nlohmann::json& j,
0041              const Acts::TGeoCylinderDiscSplitter::Config& cdc) {
0042   j = nlohmann::json{{"geo-tgeo-cyl-nphi-segs", cdc.cylinderPhiSegments},
0043                      {"geo-tgeo-cyl-nz-segs", cdc.cylinderLongitudinalSegments},
0044                      {"geo-tgeo-disc-nphi-segs", cdc.discPhiSegments},
0045                      {"geo-tgeo-disc-nr-segs", cdc.discRadialSegments}};
0046 }
0047 
0048 // enum specialization by nlohman library
0049 NLOHMANN_JSON_SERIALIZE_ENUM(Acts::BinningType,
0050                              {
0051                                  {Acts::BinningType::equidistant,
0052                                   "equidistant"},
0053                                  {Acts::BinningType::arbitrary, "arbitrary"},
0054                              })
0055 
0056 }  // namespace Acts
0057 
0058 namespace ActsExamples::Options {
0059 
0060 /// Read config for options interval
0061 void from_json(const nlohmann::json& j, Interval& interval) {
0062   interval.lower = j.at("lower");
0063   interval.upper = j.at("upper");
0064 }
0065 
0066 /// Write config for options interval
0067 void to_json(nlohmann::json& j, const Interval& interval) {
0068   // no direct conversion from std::optional to json
0069   j = nlohmann::json{{"lower", interval.lower.value_or(0)},
0070                      {"upper", interval.upper.value_or(0)}};
0071 }
0072 
0073 }  // namespace ActsExamples::Options
0074 
0075 namespace ActsExamples {
0076 
0077 void from_json(const nlohmann::json& j, TGeoITkModuleSplitter::Config& msc) {
0078   msc.barrelMap =
0079       j["geo-tgeo-barrel-map"].get<std::map<std::string, unsigned int>>();
0080   msc.discMap =
0081       j["geo-tgeo-disc-map"]
0082           .get<std::map<std::string, std::vector<std::pair<double, double>>>>();
0083 }
0084 
0085 void to_json(nlohmann::json& j, const TGeoITkModuleSplitter::Config& msc) {
0086   j["geo-tgeo-barrel-map"] = msc.barrelMap;
0087   j["geo-tgeo-disc-map"] = msc.discMap;
0088 }
0089 
0090 /// Read layer configuration triplets
0091 template <typename T>
0092 void from_json(const nlohmann::json& j,
0093                TGeoDetector::Config::LayerTriplet<T>& ltr) {
0094   ltr.negative = j.at("negative").get<T>();
0095   ltr.central = j.at("central").get<T>();
0096   ltr.positive = j.at("positive").get<T>();
0097 }
0098 
0099 /// Write layer configuration triplets
0100 template <typename T>
0101 void to_json(nlohmann::json& j,
0102              const TGeoDetector::Config::LayerTriplet<T>& ltr) {
0103   j = nlohmann::json{{"negative", ltr.negative},
0104                      {"central", ltr.central},
0105                      {"positive", ltr.positive}};
0106 }
0107 
0108 /// Read volume struct
0109 void from_json(const nlohmann::json& j, TGeoDetector::Config::Volume& vol) {
0110   // subdetector selection
0111   vol.name = j.at("geo-tgeo-volume-name");
0112 
0113   // configure surface autobinning
0114   vol.binToleranceR = j.at("geo-tgeo-sfbin-r-tolerance");
0115   vol.binToleranceZ = j.at("geo-tgeo-sfbin-z-tolerance");
0116   vol.binTolerancePhi = j.at("geo-tgeo-sfbin-phi-tolerance");
0117 
0118   // Fill layer triplets
0119   vol.layers = j.at("geo-tgeo-volume-layers");
0120   vol.subVolumeName = j.at("geo-tgeo-subvolume-names");
0121   vol.sensitiveNames = j.at("geo-tgeo-sensitive-names");
0122   vol.sensitiveAxes = j.at("geo-tgeo-sensitive-axes");
0123   vol.rRange = j.at("geo-tgeo-layer-r-ranges");
0124   vol.zRange = j.at("geo-tgeo-layer-z-ranges");
0125   vol.splitTolR = j.at("geo-tgeo-layer-r-split");
0126   vol.splitTolZ = j.at("geo-tgeo-layer-z-split");
0127   // Set binning manually
0128   vol.binning0 = j.at("geo-tgeo-binning0");
0129   vol.binning1 = j.at("geo-tgeo-binning1");
0130 
0131   vol.cylinderDiscSplit = j.at("geo-tgeo-cyl-disc-split");
0132   if (vol.cylinderDiscSplit) {
0133     Acts::TGeoCylinderDiscSplitter::Config cdConfig =
0134         j.at("Splitters").at("CylinderDisk");
0135     vol.cylinderNZSegments = cdConfig.cylinderLongitudinalSegments;
0136     vol.cylinderNPhiSegments = cdConfig.cylinderPhiSegments;
0137     vol.discNRSegments = cdConfig.discRadialSegments;
0138     vol.discNPhiSegments = cdConfig.discPhiSegments;
0139   }
0140 
0141   // Don't require ITk module splitting to be present
0142   if (j.count("geo-tgeo-itk-module-split") != 0) {
0143     vol.itkModuleSplit = j.at("geo-tgeo-itk-module-split");
0144     if (vol.itkModuleSplit) {
0145       TGeoITkModuleSplitter::Config itkConfig = j.at("Splitters").at("ITk");
0146       vol.barrelMap = itkConfig.barrelMap;
0147       vol.discMap = itkConfig.discMap;
0148     }
0149   } else {
0150     vol.itkModuleSplit = false;
0151   }
0152 }
0153 
0154 /// Write volume struct
0155 void to_json(nlohmann::json& j, const TGeoDetector::Config::Volume& vol) {
0156   j["geo-tgeo-volume-name"] = vol.name;
0157 
0158   j["geo-tgeo-sfbin-r-tolerance"] = vol.binToleranceR;
0159   j["geo-tgeo-sfbin-z-tolerance"] = vol.binToleranceZ;
0160   j["geo-tgeo-sfbin-phi-tolerance"] = vol.binTolerancePhi;
0161 
0162   j["geo-tgeo-volume-layers"] = vol.layers;
0163   j["geo-tgeo-subvolume-names"] = vol.subVolumeName;
0164   j["geo-tgeo-sensitive-names"] = vol.sensitiveNames;
0165   j["geo-tgeo-sensitive-axes"] = vol.sensitiveAxes;
0166   j["geo-tgeo-layer-r-ranges"] = vol.rRange;
0167   j["geo-tgeo-layer-z-ranges"] = vol.zRange;
0168   j["geo-tgeo-layer-r-split"] = vol.splitTolR;
0169   j["geo-tgeo-layer-z-split"] = vol.splitTolZ;
0170   j["geo-tgeo-binning0"] = vol.binning0;
0171   j["geo-tgeo-binning1"] = vol.binning1;
0172 
0173   j["geo-tgeo-cyl-disc-split"] = vol.cylinderDiscSplit;
0174   j["geo-tgeo-itk-module-split"] = vol.itkModuleSplit;
0175 
0176   Acts::TGeoCylinderDiscSplitter::Config cdConfig;
0177   cdConfig.cylinderLongitudinalSegments = vol.cylinderNZSegments;
0178   cdConfig.cylinderPhiSegments = vol.cylinderNPhiSegments;
0179   cdConfig.discRadialSegments = vol.discNRSegments;
0180   cdConfig.discPhiSegments = vol.discNPhiSegments;
0181   j["Splitters"]["CylinderDisk"] = cdConfig;
0182 
0183   if (vol.itkModuleSplit) {
0184     TGeoITkModuleSplitter::Config itkConfig;
0185     itkConfig.barrelMap = vol.barrelMap;
0186     itkConfig.discMap = vol.discMap;
0187     j["Splitters"]["ITk"] = itkConfig;
0188   }
0189 }
0190 
0191 }  // namespace ActsExamples