Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JsonTGeoDetectorConfig.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file JsonTGeoDetectorConfig.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
17 
18 #include <map>
19 #include <string>
20 
21 // Namespace of the module splitters
22 namespace Acts {
23 
25 void from_json(const nlohmann::json& j,
28  cdc.cylinderPhiSegments = j.at("geo-tgeo-cyl-nphi-segs");
30  cdc.cylinderLongitudinalSegments = j.at("geo-tgeo-cyl-nz-segs");
32  cdc.discPhiSegments = j.at("geo-tgeo-disc-nphi-segs");
34  cdc.discRadialSegments = j.at("geo-tgeo-disc-nr-segs");
35 }
36 
38 void to_json(nlohmann::json& j,
40  j = nlohmann::json{{"geo-tgeo-cyl-nphi-segs", cdc.cylinderPhiSegments},
41  {"geo-tgeo-cyl-nz-segs", cdc.cylinderLongitudinalSegments},
42  {"geo-tgeo-disc-nphi-segs", cdc.discPhiSegments},
43  {"geo-tgeo-disc-nr-segs", cdc.discRadialSegments}};
44 }
45 
46 // enum specialization by nlohman library
47 NLOHMANN_JSON_SERIALIZE_ENUM(Acts::BinningType,
48  {
50  "equidistant"},
51  {Acts::BinningType::arbitrary, "arbitrary"},
52  })
53 
54 } // namespace Acts
55 
56 namespace ActsExamples {
57 
58 namespace Options {
59 
61 void from_json(const nlohmann::json& j,
63  interval.lower = j.at("lower");
64  interval.upper = j.at("upper");
65 }
66 
68 void to_json(nlohmann::json& j,
70  // no direct conversion from std::optional to json
71  j = nlohmann::json{{"lower", interval.lower.value_or(0)},
72  {"upper", interval.upper.value_or(0)}};
73 }
74 
75 } // namespace Options
76 
77 void from_json(const nlohmann::json& j,
79  msc.barrelMap =
80  j["geo-tgeo-barrel-map"].get<std::map<std::string, unsigned int>>();
81  msc.discMap =
82  j["geo-tgeo-disc-map"]
83  .get<std::map<std::string, std::vector<std::pair<double, double>>>>();
84 }
85 
86 void to_json(nlohmann::json& j,
88  j["geo-tgeo-barrel-map"] = msc.barrelMap;
89  j["geo-tgeo-disc-map"] = msc.discMap;
90 }
91 
93 template <typename T>
94 void from_json(const nlohmann::json& j,
96  ltr.negative = j.at("negative").get<T>();
97  ltr.central = j.at("central").get<T>();
98  ltr.positive = j.at("positive").get<T>();
99 }
100 
102 template <typename T>
103 void to_json(nlohmann::json& j,
105  j = nlohmann::json{{"negative", ltr.negative},
106  {"central", ltr.central},
107  {"positive", ltr.positive}};
108 }
109 
111 void from_json(const nlohmann::json& j,
113  // subdetector selection
114  vol.name = j.at("geo-tgeo-volume-name");
115 
116  // configure surface autobinning
117  vol.binToleranceR = j.at("geo-tgeo-sfbin-r-tolerance");
118  vol.binToleranceZ = j.at("geo-tgeo-sfbin-z-tolerance");
119  vol.binTolerancePhi = j.at("geo-tgeo-sfbin-phi-tolerance");
120 
121  // Fill layer triplets
122  vol.layers = j.at("geo-tgeo-volume-layers");
123  vol.subVolumeName = j.at("geo-tgeo-subvolume-names");
124  vol.sensitiveNames = j.at("geo-tgeo-sensitive-names");
125  vol.sensitiveAxes = j.at("geo-tgeo-sensitive-axes");
126  vol.rRange = j.at("geo-tgeo-layer-r-ranges");
127  vol.zRange = j.at("geo-tgeo-layer-z-ranges");
128  vol.splitTolR = j.at("geo-tgeo-layer-r-split");
129  vol.splitTolZ = j.at("geo-tgeo-layer-z-split");
130  // Set binning manually
131  vol.binning0 = j.at("geo-tgeo-binning0");
132  vol.binning1 = j.at("geo-tgeo-binning1");
133 
134  vol.cylinderDiscSplit = j.at("geo-tgeo-cyl-disc-split");
135  if (vol.cylinderDiscSplit) {
137  j.at("Splitters").at("CylinderDisk");
140  vol.discNRSegments = cdConfig.discRadialSegments;
141  vol.discNPhiSegments = cdConfig.discPhiSegments;
142  }
143 
144  // Don't require ITk module splitting to be present
145  if (j.count("geo-tgeo-itk-module-split") != 0) {
146  vol.itkModuleSplit = j.at("geo-tgeo-itk-module-split");
147  if (vol.itkModuleSplit) {
149  j.at("Splitters").at("ITk");
150  vol.barrelMap = itkConfig.barrelMap;
151  vol.discMap = itkConfig.discMap;
152  }
153  } else {
154  vol.itkModuleSplit = false;
155  }
156 }
157 
159 void to_json(nlohmann::json& j, const TGeoDetector::Config::Volume& vol) {
160  j["geo-tgeo-volume-name"] = vol.name;
161 
162  j["geo-tgeo-sfbin-r-tolerance"] = vol.binToleranceR;
163  j["geo-tgeo-sfbin-z-tolerance"] = vol.binToleranceZ;
164  j["geo-tgeo-sfbin-phi-tolerance"] = vol.binTolerancePhi;
165 
166  j["geo-tgeo-volume-layers"] = vol.layers;
167  j["geo-tgeo-subvolume-names"] = vol.subVolumeName;
168  j["geo-tgeo-sensitive-names"] = vol.sensitiveNames;
169  j["geo-tgeo-sensitive-axes"] = vol.sensitiveAxes;
170  j["geo-tgeo-layer-r-ranges"] = vol.rRange;
171  j["geo-tgeo-layer-z-ranges"] = vol.zRange;
172  j["geo-tgeo-layer-r-split"] = vol.splitTolR;
173  j["geo-tgeo-layer-z-split"] = vol.splitTolZ;
174  j["geo-tgeo-binning0"] = vol.binning0;
175  j["geo-tgeo-binning1"] = vol.binning1;
176 
177  j["geo-tgeo-cyl-disc-split"] = vol.cylinderDiscSplit;
178  j["geo-tgeo-itk-module-split"] = vol.itkModuleSplit;
179 
183  cdConfig.discRadialSegments = vol.discNRSegments;
184  cdConfig.discPhiSegments = vol.discNPhiSegments;
185  j["Splitters"]["CylinderDisk"] = cdConfig;
186 
187  if (vol.itkModuleSplit) {
189  itkConfig.barrelMap = vol.barrelMap;
190  itkConfig.discMap = vol.discMap;
191  j["Splitters"]["ITk"] = itkConfig;
192  }
193 }
194 
195 } // namespace ActsExamples