Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:41:48

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