36 #include <initializer_list>
41 #include <boost/program_options.hpp>
42 #include <nlohmann/json.hpp>
44 #include "TGeoManager.h"
46 namespace ActsExamples {
56 std::vector<Acts::TGeoLayerBuilder::Config> makeLayerBuilderConfigs(
58 std::vector<Acts::TGeoLayerBuilder::Config> detLayerConfigs;
61 for (
const auto& volume : config.volumes) {
64 layerBuilderConfig.
unit = config.unitScalor;
68 std::vector<std::pair<double, double>> binTolerances(
70 binTolerances[
Acts::binR] = {volume.binToleranceR.lower.value_or(0.),
71 volume.binToleranceR.upper.value_or(0.)};
72 binTolerances[
Acts::binZ] = {volume.binToleranceZ.lower.value_or(0.),
73 volume.binToleranceZ.upper.value_or(0.)};
74 binTolerances[
Acts::binPhi] = {volume.binTolerancePhi.lower.value_or(0.),
75 volume.binTolerancePhi.upper.value_or(0.)};
87 if (!volume.layers.at(ncp)) {
92 lConfig.
volumeName = volume.subVolumeName.at(ncp);
93 lConfig.
sensorNames = volume.sensitiveNames.at(ncp);
94 lConfig.
localAxes = volume.sensitiveAxes.at(ncp);
95 lConfig.
envelope = {config.layerEnvelopeR, config.layerEnvelopeR};
97 auto rR = volume.rRange.at(ncp);
98 auto rMin = rR.lower.value_or(0.);
99 auto rMax = rR.upper.value_or(std::numeric_limits<double>::max());
100 auto zR = volume.zRange.at(ncp);
101 auto zMin = zR.lower.value_or(-std::numeric_limits<double>::max());
102 auto zMax = zR.upper.value_or(std::numeric_limits<double>::max());
109 auto str = volume.splitTolR.at(ncp);
110 auto stz = volume.splitTolZ.at(ncp);
117 lConfig.
binning0 = volume.binning0.at(ncp);
118 lConfig.
binning1 = volume.binning1.at(ncp);
124 if (volume.cylinderDiscSplit) {
131 std::make_shared<const Acts::TGeoCylinderDiscSplitter>(
133 logger.
clone(
"TGeoCylinderDiscSplitter", config.layerLogLevel));
134 }
else if (volume.itkModuleSplit) {
137 itkConfig.
discMap = volume.discMap;
140 std::make_shared<ActsExamples::TGeoITkModuleSplitter>(
142 logger.
clone(
"TGeoITkModuleSplitter", config.layerLogLevel));
145 detLayerConfigs.push_back(layerBuilderConfig);
148 return detLayerConfigs;
160 std::shared_ptr<const Acts::TrackingGeometry> buildTGeoDetector(
162 std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>&
164 std::shared_ptr<const Acts::IMaterialDecorator> mdecorator,
168 auto surfaceArrayCreator = std::make_shared<const Acts::SurfaceArrayCreator>(
169 sacConfig, logger.
clone(
"SurfaceArrayCreator", config.surfaceLogLevel));
172 auto protoLayerHelper = std::make_shared<const Acts::ProtoLayerHelper>(
173 plhConfig, logger.
clone(
"ProtoLayerHelper", config.layerLogLevel));
177 auto layerCreator = std::make_shared<const Acts::LayerCreator>(
178 lcConfig, logger.
clone(
"LayerCreator", config.layerLogLevel));
181 auto layerArrayCreator = std::make_shared<const Acts::LayerArrayCreator>(
182 lacConfig, logger.
clone(
"LayerArrayCreator", config.layerLogLevel));
185 auto tVolumeArrayCreator =
186 std::make_shared<const Acts::TrackingVolumeArrayCreator>(
188 logger.
clone(
"TrackingVolumeArrayCreator", config.volumeLogLevel));
192 cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator;
193 auto cylinderVolumeHelper =
194 std::make_shared<const Acts::CylinderVolumeHelper>(
196 logger.
clone(
"CylinderVolumeHelper", config.volumeLogLevel));
200 std::list<std::shared_ptr<const Acts::ITrackingVolumeBuilder>> volumeBuilders;
203 if (config.buildBeamPipe) {
210 auto beamPipeBuilder = std::make_shared<const Acts::PassiveLayerBuilder>(
211 bplConfig, logger.
clone(
"BeamPipeLayerBuilder", config.layerLogLevel));
215 bpvConfig.volumeName =
"BeamPipe";
216 bpvConfig.layerBuilder = beamPipeBuilder;
217 bpvConfig.layerEnvelopeR = {config.beamPipeEnvelopeR,
218 config.beamPipeEnvelopeR};
219 bpvConfig.buildToRadiusZero =
true;
220 auto beamPipeVolumeBuilder =
221 std::make_shared<const Acts::CylinderVolumeBuilder>(
223 logger.
clone(
"BeamPipeVolumeBuilder", config.volumeLogLevel));
225 volumeBuilders.push_back(beamPipeVolumeBuilder);
229 TGeoManager::Import(config.fileName.c_str());
231 auto layerBuilderConfigs = makeLayerBuilderConfigs(config, logger);
234 std::vector<std::shared_ptr<const Acts::TGeoLayerBuilder>> tgLayerBuilders;
236 for (
auto& lbc : layerBuilderConfigs) {
237 std::shared_ptr<const Acts::LayerCreator> layerCreatorLB =
nullptr;
239 if (lbc.autoSurfaceBinning) {
244 auto surfaceArrayCreatorLB =
245 std::make_shared<const Acts::SurfaceArrayCreator>(
247 logger.
clone(lbc.configurationName +
"SurfaceArrayCreator",
248 config.surfaceLogLevel));
252 layerCreatorLB = std::make_shared<const Acts::LayerCreator>(
253 lcConfigLB, logger.
clone(lbc.configurationName +
"LayerCreator",
254 config.layerLogLevel));
259 auto protoLayerHelperLB = std::make_shared<const Acts::ProtoLayerHelper>(
260 plhConfigLB, logger.
clone(lbc.configurationName +
"ProtoLayerHelper",
261 config.layerLogLevel));
265 (layerCreatorLB !=
nullptr) ? layerCreatorLB : layerCreator;
266 lbc.protoLayerHelper =
267 (protoLayerHelperLB !=
nullptr) ? protoLayerHelperLB : protoLayerHelper;
269 auto layerBuilder = std::make_shared<const Acts::TGeoLayerBuilder>(
270 lbc, logger.
clone(lbc.configurationName +
"LayerBuilder",
271 config.layerLogLevel));
273 tgLayerBuilders.push_back(layerBuilder);
278 volumeConfig.
volumeName = lbc.configurationName;
281 config.layerEnvelopeR};
282 auto ringLayoutConfiguration =
283 [&](
const std::vector<Acts::TGeoLayerBuilder::LayerConfig>& lConfigs)
285 for (
const auto& lcfg : lConfigs) {
286 for (
const auto& scfg : lcfg.splitConfigs) {
287 if (scfg.first ==
Acts::binR and scfg.second > 0.) {
295 ringLayoutConfiguration(lbc.layerConfigurations[0]);
296 ringLayoutConfiguration(lbc.layerConfigurations[2]);
299 auto volumeBuilder = std::make_shared<const Acts::CylinderVolumeBuilder>(
300 volumeConfig, logger.
clone(lbc.configurationName +
"VolumeBuilder",
301 config.volumeLogLevel));
303 volumeBuilders.push_back(volumeBuilder);
313 for (
auto& vb : volumeBuilders) {
315 [=](
const auto& gcontext,
const auto& inner,
const auto&) {
316 return vb->trackingVolume(gcontext, inner);
321 auto cylinderGeometryBuilder =
322 std::make_shared<const Acts::TrackingGeometryBuilder>(
324 logger.
clone(
"TrackerGeometryBuilder", config.volumeLogLevel));
328 for (
auto& lBuilder : tgLayerBuilders) {
329 auto detElements = lBuilder->detectorElements();
330 detElementStore.insert(detElementStore.begin(), detElements.begin(),
346 nlohmann::json djson;
350 config.
unitScalor = djson[
"geo-tgeo-unit-scalor"];
354 const auto beamPipeParameters =
355 djson[
"geo-tgeo-beampipe-parameters"].get<std::array<double, 3>>();
362 for (
const auto& volume : djson[
"Volumes"]) {
363 auto& vol = config.
volumes.emplace_back();
370 std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
371 -> std::pair<TrackingGeometryPtr, ContextDecorators> {
375 cfg, tGeoContext, detectorStore,
std::move(mdecorator), *logger);
379 return std::make_pair<TrackingGeometryPtr, ContextDecorators>(
384 readTGeoLayerBuilderConfigsFile(jsonFile, *
this);