Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:20:34

0001 #include "TGeoDetectorWithOptions.h"
0002 
0003 #include <Acts/Geometry/CylinderVolumeBuilder.hpp>
0004 #include <Acts/Geometry/CylinderVolumeHelper.hpp>
0005 #include <Acts/Geometry/GeometryContext.hpp>
0006 #include <Acts/Geometry/LayerArrayCreator.hpp>
0007 #include <Acts/Geometry/LayerCreator.hpp>
0008 #include <Acts/Geometry/PassiveLayerBuilder.hpp>
0009 #include <Acts/Geometry/SurfaceArrayCreator.hpp>
0010 #include <Acts/Geometry/TrackingGeometry.hpp>
0011 #include <Acts/Geometry/TrackingGeometryBuilder.hpp>
0012 #include <Acts/Geometry/TrackingVolumeArrayCreator.hpp>
0013 #include <Acts/Plugins/TGeo/TGeoCylinderDiscSplitter.hpp>
0014 #include <Acts/Plugins/TGeo/TGeoDetectorElement.hpp>
0015 #include <Acts/Plugins/TGeo/TGeoLayerBuilder.hpp>
0016 #include <Acts/Utilities/Logger.hpp>
0017 #include <ActsExamples/Framework/IContextDecorator.hpp>
0018 #include <ActsExamples/TGeoDetector/JsonTGeoDetectorConfig.hpp>
0019 #include <ActsExamples/Utilities/Options.hpp>
0020 
0021 #include <cstdlib>
0022 #include <fstream>
0023 #include <list>
0024 
0025 #include <boost/program_options.hpp>
0026 
0027 namespace ActsExamples {
0028 using namespace Options;
0029 
0030 namespace {
0031 
0032 /// Read the TGeo layer builder configurations from the user configuration
0033 /// specified with --geo-tgeo-jsonconfig.
0034 void readTGeoLayerBuilderConfigs(const Variables& vm,
0035                                  TGeoDetector::Config& config) {
0036   const auto path = vm["geo-tgeo-jsonconfig"].template as<std::string>();
0037   TGeoDetector::readTGeoLayerBuilderConfigsFile(path, config);
0038 }
0039 
0040 /// Dump TGeo Detector config to file.
0041 void writeTGeoDetectorConfig(const Variables& vm,
0042                              TGeoDetector::Config& config) {
0043   const auto path = vm["geo-tgeo-dump-jsonconfig"].template as<std::string>();
0044   nlohmann::json djson;
0045   if (path.empty()) {
0046     return;
0047   }
0048   std::ofstream outfile(path, std::ofstream::out | std::ofstream::binary);
0049 
0050   djson["geo-tgeo-unit-scalor"] = config.unitScalor;
0051   djson["geo-tgeo-build-beampipe"] = config.buildBeamPipe;
0052   djson["geo-tgeo-beampipe-parameters"] =
0053       std::array<double, 3>{config.beamPipeRadius, config.beamPipeHalflengthZ,
0054                             config.beamPipeLayerThickness};
0055 
0056   // Enable empty volume dump
0057   if (config.volumes.empty()) {
0058     config.volumes.emplace_back();
0059   }
0060   djson["Volumes"] = config.volumes;
0061 
0062   outfile << djson.dump(2) << std::endl;
0063 }
0064 
0065 }  // namespace
0066 
0067 void TGeoDetectorWithOptions::addOptions(
0068     boost::program_options::options_description& opt) const {
0069   using boost::program_options::value;
0070 
0071   auto tmp = opt.add_options();
0072   // required global options
0073   tmp("geo-tgeo-filename", value<std::string>()->default_value(""),
0074       "Root file name.");
0075   tmp("geo-tgeo-jsonconfig", value<std::string>()->default_value(""),
0076       "Json config file name.");
0077   tmp("geo-tgeo-dump-jsonconfig",
0078       value<std::string>()->default_value("tgeo_empty_config.json"),
0079       "Json file to dump empty config into.");
0080 }
0081 
0082 auto TGeoDetectorWithOptions::finalize(
0083     const boost::program_options::variables_map& vm,
0084     std::shared_ptr<const Acts::IMaterialDecorator> mdecorator)
0085     -> std::pair<TrackingGeometryPtr, ContextDecorators> {
0086   TGeoDetector::Config config;
0087 
0088   config.fileName = vm["geo-tgeo-filename"].as<std::string>();
0089 
0090   config.surfaceLogLevel =
0091       Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
0092   config.layerLogLevel =
0093       Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
0094   config.volumeLogLevel =
0095       Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());
0096 
0097   // No valid geometry configuration. Stop
0098   if (vm["geo-tgeo-jsonconfig"].as<std::string>().empty()) {
0099     writeTGeoDetectorConfig(vm, config);
0100     std::exit(EXIT_SUCCESS);
0101   }
0102   // Enable dump from full config
0103   else if (!(vm["geo-tgeo-dump-jsonconfig"].as<std::string>().compare(
0104                    "tgeo_empty_cofig.json") == 0)) {
0105     readTGeoLayerBuilderConfigs(vm, config);
0106     writeTGeoDetectorConfig(vm, config);
0107   } else {
0108     readTGeoLayerBuilderConfigs(vm, config);
0109   }
0110 
0111   return m_detector.finalize(config, std::move(mdecorator));
0112 }
0113 
0114 }  // namespace ActsExamples