Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TGeoDetectorWithOptions.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TGeoDetectorWithOptions.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 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 
10 
29 
30 #include <cstdlib>
31 #include <fstream>
32 #include <list>
33 
34 #include <boost/program_options.hpp>
35 
36 namespace ActsExamples {
37 using namespace Options;
38 
39 namespace {
40 
43 void readTGeoLayerBuilderConfigs(const Variables& vm,
45  const auto path = vm["geo-tgeo-jsonconfig"].template as<std::string>();
47 }
48 
50 void writeTGeoDetectorConfig(const Variables& vm,
52  const auto path = vm["geo-tgeo-dump-jsonconfig"].template as<std::string>();
53  nlohmann::json djson;
54  if (path.empty()) {
55  return;
56  }
57  std::ofstream outfile(path, std::ofstream::out | std::ofstream::binary);
58 
59  djson["geo-tgeo-unit-scalor"] = config.unitScalor;
60  djson["geo-tgeo-build-beampipe"] = config.buildBeamPipe;
61  djson["geo-tgeo-beampipe-parameters"] =
62  std::array<double, 3>{config.beamPipeRadius, config.beamPipeHalflengthZ,
63  config.beamPipeLayerThickness};
64 
65  // Enable empty volume dump
66  if (config.volumes.empty()) {
67  config.volumes.emplace_back();
68  }
69  djson["Volumes"] = config.volumes;
70 
71  outfile << djson.dump(2) << std::endl;
72 }
73 
74 } // namespace
75 
77  boost::program_options::options_description& opt) const {
79 
80  auto tmp = opt.add_options();
81  // required global options
82  tmp("geo-tgeo-filename", value<std::string>()->default_value(""),
83  "Root file name.");
84  tmp("geo-tgeo-jsonconfig", value<std::string>()->default_value(""),
85  "Json config file name.");
86  tmp("geo-tgeo-dump-jsonconfig",
87  value<std::string>()->default_value("tgeo_empty_config.json"),
88  "Json file to dump empty config into.");
89 }
90 
92  const boost::program_options::variables_map& vm,
93  std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
94  -> std::pair<TrackingGeometryPtr, ContextDecorators> {
96 
97  config.fileName = vm["geo-tgeo-filename"].as<std::string>();
98 
99  config.surfaceLogLevel =
100  Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
101  config.layerLogLevel =
102  Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
103  config.volumeLogLevel =
104  Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());
105 
106  // No valid geometry configuration. Stop
107  if (vm["geo-tgeo-jsonconfig"].as<std::string>().empty()) {
108  writeTGeoDetectorConfig(vm, config);
109  std::exit(EXIT_SUCCESS);
110  }
111  // Enable dump from full config
112  else if (not(vm["geo-tgeo-dump-jsonconfig"].as<std::string>().compare(
113  "tgeo_empty_cofig.json") == 0)) {
114  readTGeoLayerBuilderConfigs(vm, config);
115  writeTGeoDetectorConfig(vm, config);
116  } else {
117  readTGeoLayerBuilderConfigs(vm, config);
118  }
119 
120  return m_detector.finalize(config, std::move(mdecorator));
121 }
122 
123 } // namespace ActsExamples