Skip to content

Commit

Permalink
feat: introduce TGeoDetectorElementSplitter & splitted detector eleme…
Browse files Browse the repository at this point in the history
…nt constructors (#873)

This PR introduces a new interface in the TGeo plugin that allows splitting of TGeoDetectorElement objects and adds a necessary constructor for this to the TGeoDetectorElement.
  • Loading branch information
asalzburger committed Jul 16, 2021
1 parent 6e94ec0 commit b14a419
Show file tree
Hide file tree
Showing 13 changed files with 661 additions and 218 deletions.
2 changes: 2 additions & 0 deletions Examples/Detectors/TGeoDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_library(
ActsExamplesDetectorTGeo SHARED
src/BuildTGeoDetector.cpp
src/TGeoDetector.cpp
src/TGeoDetectorOptions.cpp)

target_include_directories(
ActsExamplesDetectorTGeo
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,14 @@

#pragma once

#include "Acts/Geometry/CylinderVolumeBuilder.hpp"
#include "Acts/Geometry/CylinderVolumeHelper.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/LayerArrayCreator.hpp"
#include "Acts/Geometry/LayerCreator.hpp"
#include "Acts/Geometry/PassiveLayerBuilder.hpp"
#include "Acts/Geometry/SurfaceArrayCreator.hpp"
#include "Acts/Geometry/SurfaceBinningMatcher.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingGeometryBuilder.hpp"
#include "Acts/Geometry/TrackingVolumeArrayCreator.hpp"
#include "Acts/Material/Material.hpp"
#include "Acts/Material/MaterialSlab.hpp"
#include "Acts/Plugins/TGeo/TGeoDetectorElement.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "ActsExamples/TGeoDetector/BuildTGeoDetector.hpp"
#include "Acts/Material/IMaterialDecorator.hpp"
#include "ActsExamples/TGeoDetector/TGeoDetectorOptions.hpp"
#include "ActsExamples/Utilities/Options.hpp"

#include <list>
#include <memory>
#include <vector>

#include <TGeoManager.h>
#include <boost/program_options.hpp>

namespace ActsExamples {
Expand All @@ -45,201 +30,12 @@ namespace TGeo {
/// @tparam variable_map_t is the variable map
///
/// @param vm is the variable map from the options
template <typename variable_maps_t>
std::shared_ptr<const Acts::TrackingGeometry> buildTGeoDetector(
variable_maps_t& vm, const Acts::GeometryContext& context,
const boost::program_options::variables_map& vm,
const Acts::GeometryContext& context,
std::vector<std::shared_ptr<const Acts::TGeoDetectorElement>>&
detElementStore,
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator) {
Acts::Logging::Level surfaceLogLevel =
Acts::Logging::Level(vm["geo-surface-loglevel"].template as<size_t>());
Acts::Logging::Level layerLogLevel =
Acts::Logging::Level(vm["geo-layer-loglevel"].template as<size_t>());
Acts::Logging::Level volumeLogLevel =
Acts::Logging::Level(vm["geo-volume-loglevel"].template as<size_t>());

// configure surface array creator
Acts::SurfaceArrayCreator::Config sacConfig;
auto surfaceArrayCreator = std::make_shared<const Acts::SurfaceArrayCreator>(
sacConfig,
Acts::getDefaultLogger("SurfaceArrayCreator", surfaceLogLevel));
// configure the proto layer helper
Acts::ProtoLayerHelper::Config plhConfig;
auto protoLayerHelper = std::make_shared<const Acts::ProtoLayerHelper>(
plhConfig, Acts::getDefaultLogger("ProtoLayerHelper", layerLogLevel));
// configure the layer creator that uses the surface array creator
Acts::LayerCreator::Config lcConfig;
lcConfig.surfaceArrayCreator = surfaceArrayCreator;
auto layerCreator = std::make_shared<const Acts::LayerCreator>(
lcConfig, Acts::getDefaultLogger("LayerCreator", layerLogLevel));
// configure the layer array creator
Acts::LayerArrayCreator::Config lacConfig;
auto layerArrayCreator = std::make_shared<const Acts::LayerArrayCreator>(
lacConfig, Acts::getDefaultLogger("LayerArrayCreator", layerLogLevel));
// tracking volume array creator
Acts::TrackingVolumeArrayCreator::Config tvacConfig;
auto tVolumeArrayCreator =
std::make_shared<const Acts::TrackingVolumeArrayCreator>(
tvacConfig,
Acts::getDefaultLogger("TrackingVolumeArrayCreator", volumeLogLevel));
// configure the cylinder volume helper
Acts::CylinderVolumeHelper::Config cvhConfig;
cvhConfig.layerArrayCreator = layerArrayCreator;
cvhConfig.trackingVolumeArrayCreator = tVolumeArrayCreator;
auto cylinderVolumeHelper =
std::make_shared<const Acts::CylinderVolumeHelper>(
cvhConfig,
Acts::getDefaultLogger("CylinderVolumeHelper", volumeLogLevel));

//-------------------------------------------------------------------------------------
// list the volume builders
std::list<std::shared_ptr<const Acts::ITrackingVolumeBuilder>> volumeBuilders;

std::string rootFileName = vm["geo-tgeo-filename"].template as<std::string>();

// Create a beam pipe if configured to do so
if (vm.count("geo-tgeo-beampipe-parameters")) {
auto beamPipeParameters =
vm["geo-tgeo-beampipe-parameters"].template as<Options::Reals<3>>();
/// configure the beam pipe layer builder
Acts::PassiveLayerBuilder::Config bplConfig;
bplConfig.layerIdentification = "BeamPipe";
bplConfig.centralLayerRadii = std::vector<double>(1, beamPipeParameters[0]);
bplConfig.centralLayerHalflengthZ =
std::vector<double>(1, beamPipeParameters[1]);
bplConfig.centralLayerThickness =
std::vector<double>(1, beamPipeParameters[2]);
auto beamPipeBuilder = std::make_shared<const Acts::PassiveLayerBuilder>(
bplConfig,
Acts::getDefaultLogger("BeamPipeLayerBuilder", layerLogLevel));
// create the volume for the beam pipe
Acts::CylinderVolumeBuilder::Config bpvConfig;
bpvConfig.trackingVolumeHelper = cylinderVolumeHelper;
bpvConfig.volumeName = "BeamPipe";
bpvConfig.layerBuilder = beamPipeBuilder;
bpvConfig.layerEnvelopeR = {1. * Acts::UnitConstants::mm,
1. * Acts::UnitConstants::mm};
bpvConfig.buildToRadiusZero = true;
auto beamPipeVolumeBuilder =
std::make_shared<const Acts::CylinderVolumeBuilder>(
bpvConfig,
Acts::getDefaultLogger("BeamPipeVolumeBuilder", volumeLogLevel));
// add to the list of builders
volumeBuilders.push_back(beamPipeVolumeBuilder);
}

// import the file from
TGeoManager::Import(rootFileName.c_str());

auto layerBuilderConfigs =
ActsExamples::Options::readTGeoLayerBuilderConfigs(vm);

// remember the layer builders to collect the detector elements
std::vector<std::shared_ptr<const Acts::TGeoLayerBuilder>> tgLayerBuilders;

for (auto& lbc : layerBuilderConfigs) {
std::shared_ptr<const Acts::LayerCreator> layerCreatorLB = nullptr;

if (lbc.autoSurfaceBinning) {
// Configure surface array creator (optionally) per layer builder
// (in order to configure them to work appropriately)
Acts::SurfaceArrayCreator::Config sacConfigLB;
sacConfigLB.surfaceMatcher = lbc.surfaceBinMatcher;
auto surfaceArrayCreatorLB =
std::make_shared<const Acts::SurfaceArrayCreator>(
sacConfigLB, Acts::getDefaultLogger(
lbc.configurationName + "SurfaceArrayCreator",
surfaceLogLevel));
// configure the layer creator that uses the surface array creator
Acts::LayerCreator::Config lcConfigLB;
lcConfigLB.surfaceArrayCreator = surfaceArrayCreatorLB;
layerCreatorLB = std::make_shared<const Acts::LayerCreator>(
lcConfigLB,
Acts::getDefaultLogger(lbc.configurationName + "LayerCreator",
layerLogLevel));
}

// Configure the proto layer helper
Acts::ProtoLayerHelper::Config plhConfigLB;
auto protoLayerHelperLB = std::make_shared<const Acts::ProtoLayerHelper>(
plhConfigLB,
Acts::getDefaultLogger(lbc.configurationName + "ProtoLayerHelper",
layerLogLevel));

//-------------------------------------------------------------------------------------
lbc.layerCreator =
(layerCreatorLB != nullptr) ? layerCreatorLB : layerCreator;
lbc.protoLayerHelper =
(protoLayerHelperLB != nullptr) ? protoLayerHelperLB : protoLayerHelper;

auto layerBuilder = std::make_shared<const Acts::TGeoLayerBuilder>(
lbc, Acts::getDefaultLogger(lbc.configurationName + "LayerBuilder",
layerLogLevel));
// remember the layer builder
tgLayerBuilders.push_back(layerBuilder);

// build the pixel volume
Acts::CylinderVolumeBuilder::Config volumeConfig;
volumeConfig.trackingVolumeHelper = cylinderVolumeHelper;
volumeConfig.volumeName = lbc.configurationName;
volumeConfig.buildToRadiusZero = (volumeBuilders.size() == 0);
volumeConfig.layerEnvelopeR = {1. * Acts::UnitConstants::mm,
5. * Acts::UnitConstants::mm};
auto ringLayoutConfiguration =
[&](const std::vector<Acts::TGeoLayerBuilder::LayerConfig>& lConfigs)
-> void {
for (const auto& lcfg : lConfigs) {
for (const auto& scfg : lcfg.splitConfigs) {
if (scfg.first == Acts::binR and scfg.second > 0.) {
volumeConfig.ringTolerance =
std::max(volumeConfig.ringTolerance, scfg.second);
volumeConfig.checkRingLayout = true;
}
}
}
};
ringLayoutConfiguration(lbc.layerConfigurations[0]);
ringLayoutConfiguration(lbc.layerConfigurations[2]);
volumeConfig.layerBuilder = layerBuilder;
volumeConfig.volumeSignature = 0;
auto volumeBuilder = std::make_shared<const Acts::CylinderVolumeBuilder>(
volumeConfig,
Acts::getDefaultLogger(lbc.configurationName + "VolumeBuilder",
volumeLogLevel));
// add to the list of builders
volumeBuilders.push_back(volumeBuilder);
}

//-------------------------------------------------------------------------------------
// create the tracking geometry
Acts::TrackingGeometryBuilder::Config tgConfig;
// Add the builders
tgConfig.materialDecorator = mdecorator;

for (auto& vb : volumeBuilders) {
tgConfig.trackingVolumeBuilders.push_back(
[=](const auto& gcontext, const auto& inner, const auto&) {
return vb->trackingVolume(gcontext, inner);
});
}
// Add the helper
tgConfig.trackingVolumeHelper = cylinderVolumeHelper;
auto cylinderGeometryBuilder =
std::make_shared<const Acts::TrackingGeometryBuilder>(
tgConfig,
Acts::getDefaultLogger("TrackerGeometryBuilder", volumeLogLevel));
// get the geometry
auto trackingGeometry = cylinderGeometryBuilder->trackingGeometry(context);
// collect the detector element store
for (auto& lBuilder : tgLayerBuilders) {
auto detElements = lBuilder->detectorElements();
detElementStore.insert(detElementStore.begin(), detElements.begin(),
detElements.end());
}

/// return the tracking geometry
return trackingGeometry;
}
std::shared_ptr<const Acts::IMaterialDecorator> mdecorator);

} // namespace TGeo
} // namespace ActsExamples

0 comments on commit b14a419

Please sign in to comment.