Skip to content

Commit

Permalink
feat: update OpenDataDetector, refine DD4hep material handling (#895)
Browse files Browse the repository at this point in the history
This PR combines two features that are coupled:

updates the OpenDataDetector description (with boundary material)
refines the way boundary material is handled (e.g. ODDCylinderLayerBuilder)
With this, quite remarkable agreement between G4 and ACTS in terms of material budget can be achieved.
  • Loading branch information
asalzburger committed Jul 26, 2021
1 parent bb4ba16 commit 0e83c06
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 25 deletions.
11 changes: 6 additions & 5 deletions Plugins/DD4hep/include/Acts/Plugins/DD4hep/ActsExtension.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
// This file is part of the Acts project.
//
// Copyright (C) 2017-2019 CERN for the benefit of the Acts project
// Copyright (C) 2017-2021 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

///////////////////////////////////////////////////////////////////
// ActsExtension.hpp, Acts project, DD4hepDetector plugin
///////////////////////////////////////////////////////////////////

#pragma once

#include <string>
Expand Down Expand Up @@ -78,6 +74,11 @@ class ActsExtension {
/// @param category the (optional) category in the flag store
bool hasType(const std::string& type, const std::string& category = "") const;

/// Check if the ActsExtension has a category
///
/// @param category the category in the flag store
bool hasCategory(const std::string& category) const;

/// Add the characteristics
///
/// @param type the primary identifier in the flag store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ void collectLayers_dd4hep(dd4hep::DetElement& detElement,
/// detElement
void collectVolumes_dd4hep(dd4hep::DetElement& detElement,
std::vector<dd4hep::DetElement>& volumes);
} // namespace Acts
} // namespace Acts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ inline DD4hepVolumeBuilder::Config DD4hepVolumeBuilder::getConfiguration()
return m_cfg;
}

} // namespace Acts
} // namespace Acts
9 changes: 9 additions & 0 deletions Plugins/DD4hep/src/ActsExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ void Acts::ActsExtension::addValue(double value, const std::string& tag,
addT(m_values, value, tag, category, 0.0);
}

bool Acts::ActsExtension::hasCategory(const std::string& category) const {
for (auto [key, value] : m_values) {
if (key.find(category) != std::string::npos) {
return true;
}
}
return false;
}

bool Acts::ActsExtension::hasValue(const std::string& tag,
const std::string& category) const {
return hasT(m_values, tag, category);
Expand Down
28 changes: 28 additions & 0 deletions Plugins/DD4hep/src/ConvertDD4hepDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ std::shared_ptr<const CylinderVolumeBuilder> volumeBuilder_dd4hep(
collectLayers_dd4hep(volumeDetElement, negativeLayers);
// Fill the volume material for barrel case
if (volumeExtension->hasType("boundary_material")) {
ACTS_VERBOSE(
" -> boundary_material flag detected, creating proto "
"material.");
if (volumeExtension->hasValue("boundary_material_negative")) {
cvbConfig.boundaryMaterial[2] = Acts::createProtoMaterial(
*volumeExtension, "boundary_material_negative",
Expand All @@ -233,6 +236,9 @@ std::shared_ptr<const CylinderVolumeBuilder> volumeBuilder_dd4hep(
collectLayers_dd4hep(volumeDetElement, positiveLayers);
// Fill the volume material for barrel case
if (volumeExtension->hasType("boundary_material")) {
ACTS_VERBOSE(
" -> boundary_material flag detected, creating proto "
"material.");
if (volumeExtension->hasValue("boundary_material_negative")) {
cvbConfig.boundaryMaterial[4] = Acts::createProtoMaterial(
*volumeExtension, "boundary_material_negative",
Expand Down Expand Up @@ -260,6 +266,9 @@ std::shared_ptr<const CylinderVolumeBuilder> volumeBuilder_dd4hep(
collectLayers_dd4hep(volumeDetElement, centralLayers);
// Fill the volume material for barrel case
if (volumeExtension->hasType("boundary_material")) {
ACTS_VERBOSE(
" -> boundary_material flag detected, creating proto "
"material.");
if (volumeExtension->hasValue("boundary_material_negative")) {
cvbConfig.boundaryMaterial[3] = Acts::createProtoMaterial(
*volumeExtension, "boundary_material_negative",
Expand All @@ -282,6 +291,9 @@ std::shared_ptr<const CylinderVolumeBuilder> volumeBuilder_dd4hep(

// Fill the volume material for the inner / outer cover
if (volumeExtension->hasType("boundary_material")) {
ACTS_VERBOSE(
" -> boundary_material flag detected, creating proto "
"material.");
if (volumeExtension->hasValue("boundary_material_inner")) {
cvbConfig.boundaryMaterial[0] = Acts::createProtoMaterial(
*volumeExtension, "boundary_material_inner",
Expand Down Expand Up @@ -400,6 +412,22 @@ std::shared_ptr<const CylinderVolumeBuilder> volumeBuilder_dd4hep(
cvbConfig.layerEnvelopeZ = layerEnvelopeZ;
cvbConfig.buildToRadiusZero = subDetExtension->hasType("beampipe", "layer");

// Fill the volume material for the inner / outer cover
if (subDetExtension->hasType("boundary_material")) {
ACTS_VERBOSE(
" -> boundary_material flag detected, creating proto material.");
if (subDetExtension->hasValue("boundary_material_inner")) {
cvbConfig.boundaryMaterial[0] = Acts::createProtoMaterial(
*subDetExtension, "boundary_material_inner",
{{"binPhi", Acts::closed}, {"binZ", Acts::open}});
}
if (subDetExtension->hasValue("boundary_material_outer")) {
cvbConfig.boundaryMaterial[1] = Acts::createProtoMaterial(
*subDetExtension, "boundary_material_outer",
{{"binPhi", Acts::closed}, {"binZ", Acts::open}});
}
}

// beam pipe / passive cylinder volume builder
auto pcVolumeBuilder = std::make_shared<const Acts::CylinderVolumeBuilder>(
cvbConfig,
Expand Down
22 changes: 22 additions & 0 deletions Plugins/DD4hep/src/DD4hepLayerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ const Acts::LayerVector Acts::DD4hepLayerBuilder::endcapLayers(
}

std::shared_ptr<Layer> endcapLayer = nullptr;

// Check if DD4hep pre-defines the surface binning
bool hasSurfaceBinning = detExtension->hasCategory("surface_binning");
size_t nPhi = 1;
size_t nR = 1;
if (hasSurfaceBinning) {
if (detExtension->hasValue("n_phi", "surface_binning")) {
nPhi = static_cast<size_t>(
detExtension->getValue("n_phi", "surface_binning"));
}
if (detExtension->hasValue("n_r", "surface_binning")) {
nR = static_cast<size_t>(
detExtension->getValue("n_r", "surface_binning"));
}
hasSurfaceBinning = nR * nPhi > 1;
}

// In case the layer is sensitive
if (detElement.volume().isSensitive()) {
// Create the sensitive surface
Expand All @@ -155,7 +172,12 @@ const Acts::LayerVector Acts::DD4hepLayerBuilder::endcapLayers(
endcapLayer = DiscLayer::create(transform, dBounds, std::move(sArray),
thickness, nullptr, Acts::active);

} else if (hasSurfaceBinning) {
// This method uses the binning from DD4hep/xml
endcapLayer = m_cfg.layerCreator->discLayer(
gctx, layerSurfaces, nR, nPhi, pl, transform, nullptr);
} else {
// This method determines the binning automatically
endcapLayer = m_cfg.layerCreator->discLayer(
gctx, layerSurfaces, m_cfg.bTypeR, m_cfg.bTypePhi, pl, transform,
nullptr);
Expand Down
9 changes: 9 additions & 0 deletions thirdparty/OpenDataDetector/factory/ODDCylinder_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ static Ref_t create_element(Detector& oddd, xml_h xml,

// add Extension to Detlement for the RecoGeometry
Acts::ActsExtension* pcExtension = new Acts::ActsExtension();

// Add the proto boundary material
for (xml_coll_t bmat(x_det, _Unicode(boundary_material)); bmat; ++bmat) {
xml_comp_t x_boundary_material = bmat;
xmlToProtoSurfaceMaterial(x_boundary_material, *pcExtension,
"boundary_material");
}

bool isBeamPipe = x_det.hasChild(_U(beampipe));
pcExtension->addType("passive cylinder", "layer");
if (isBeamPipe) {
Expand All @@ -37,6 +45,7 @@ static Ref_t create_element(Detector& oddd, xml_h xml,
xml_comp_t x_layer_material = lmat;
xmlToProtoSurfaceMaterial(x_layer_material, *pcExtension, "layer_material");
}

cylinderElement.addExtension<Acts::ActsExtension>(pcExtension);

string shapeName = x_det_tubs.nameStr();
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/OpenDataDetector/factory/ODDPixelBarrel_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ static Ref_t create_element(Detector& oddd, xml_h xml, SensitiveDetector sens) {
Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
layerExtension->addType("sensitive cylinder", "layer");
layerExtension->addValue(1., "r_min", "envelope");
layerExtension->addValue(5., "r_max", "envelope");
layerExtension->addValue(5., "r_max", "envelope");
layerExtension->addValue(5., "z_min", "envelope");
layerExtension->addValue(5., "z_max", "envelope");
layerExtension->addValue(5., "z_max", "envelope");
// Add the proto layer material
for (xml_coll_t lmat(x_layer, _Unicode(layer_material)); lmat; ++lmat) {
xml_comp_t x_layer_material = lmat;
Expand Down
13 changes: 7 additions & 6 deletions thirdparty/OpenDataDetector/factory/ODDPixelEndcap_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,21 @@ static Ref_t create_element(Detector& oddd, xml_h xml, SensitiveDetector sens) {
endcapVolume.placeVolume(layerVolume, Position(0., 0., zeff));
placedLayer.addPhysVolID("layer", layNum);


// Place the layer with appropriate Acts::Extension
// Configure the ACTS extension
Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
layerExtension->addType("sensitive disk", "layer");
layerExtension->addValue(10., "r_min", "envelope");
layerExtension->addValue(10., "r_max", "envelope");
layerExtension->addValue(10., "r_max", "envelope");
layerExtension->addValue(10., "z_min", "envelope");
layerExtension->addValue(10., "z_max", "envelope");
layerExtension->addValue(10., "z_max", "envelope");
// Check if the disk has a surface binning instruction
if (x_layer.hasChild(_Unicode(surface_binning))){
if (x_layer.hasChild(_Unicode(surface_binning))) {
xml_comp_t sfBinning = x_layer.child(_Unicode(surface_binning));
layerExtension->addValue(sfBinning.attr<int>("nr"), "n_r", "surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nphi"), "n_phi", "surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nr"), "n_r",
"surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nphi"), "n_phi",
"surface_binning");
}

layerElement.addExtension<Acts::ActsExtension>(layerExtension);
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/OpenDataDetector/factory/ODDStripBarrel_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ static Ref_t create_element(Detector& oddd, xml_h xml, SensitiveDetector sens) {
Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
layerExtension->addType("sensitive cylinder", "layer");
layerExtension->addValue(10., "r_min", "envelope");
layerExtension->addValue(25., "r_max", "envelope");
layerExtension->addValue(25., "r_max", "envelope");
layerExtension->addValue(10., "z_min", "envelope");
layerExtension->addValue(10., "z_max", "envelope");
layerExtension->addValue(10., "z_max", "envelope");
layerElement.addExtension<Acts::ActsExtension>(layerExtension);
// Add the proto layer material
for (xml_coll_t lmat(x_layer, _Unicode(layer_material)); lmat; ++lmat) {
Expand Down
8 changes: 5 additions & 3 deletions thirdparty/OpenDataDetector/factory/ODDStripEndcap_geo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ static Ref_t create_element(Detector& oddd, xml_h xml, SensitiveDetector sens) {
layerExtension->addValue(10, "z_max", "envelope");

// Check if the disk has a surface binning instruction
if (x_layer.hasChild(_Unicode(surface_binning))){
if (x_layer.hasChild(_Unicode(surface_binning))) {
xml_comp_t sfBinning = x_layer.child(_Unicode(surface_binning));
layerExtension->addValue(sfBinning.attr<int>("nr"), "n_r", "surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nphi"), "n_phi", "surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nr"), "n_r",
"surface_binning");
layerExtension->addValue(sfBinning.attr<int>("nphi"), "n_phi",
"surface_binning");
}

layerElement.addExtension<Acts::ActsExtension>(layerExtension);
Expand Down
22 changes: 17 additions & 5 deletions thirdparty/OpenDataDetector/xml/OpenDataDetector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<constant name="pix_e_pz" value="1.480*m"/>
<constant name="pix_e_dz" value="0.9*m"/>
<!--Dimensions of the Pixel Support tube -->
<constant name="pst_rmin" value="200.*mm"/>
<constant name="pst_rmin" value="202.*mm"/>
<constant name="pst_rmax" value="204.*mm"/>
<constant name="pst_length" value="2.0*m"/>
<!--Dimensions of the Short Strips volume & sub volumes -->
Expand All @@ -55,7 +55,7 @@
<constant name="ls_e_pz" value="2.175*m"/>
<constant name="ls_e_dz" value="0.975*m"/>
<!--Dimensions of the Solenoid -->
<constant name="sol_rmin" value="1140.*mm"/>
<constant name="sol_rmin" value="1160.*mm"/>
<constant name="sol_rmax" value="1200.*mm"/>
<constant name="sol_hlength" value="3.0*m"/>
<!-- Material binning section -->
Expand All @@ -71,6 +71,9 @@
<constant name="mat_pix_outer_bZ" value="250"/>
<constant name="mat_pix_inter_bR" value="50"/>
<constant name="mat_pix_inter_bPhi" value="72"/>
<!-- PST section -->
<constant name="mat_pst_bPhi" value="1"/>
<constant name="mat_pst_bZ" value="100"/>
<!-- short strip section -->
<constant name="mat_sst_barrel_bPhi" value="72"/>
<constant name="mat_sst_barrel_bZ" value="150"/>
Expand All @@ -89,6 +92,9 @@
<constant name="mat_lst_outer_bPhi" value="72"/>
<constant name="mat_lst_inter_bR" value="100"/>
<constant name="mat_lst_inter_bPhi" value="72"/>
<!-- Solenoid section -->
<constant name="mat_sol_bPhi" value="1"/>
<constant name="mat_sol_bZ" value="100"/>
</define>

<display>
Expand All @@ -97,6 +103,7 @@
<vis name="Kapton" r="0.1328125" g="0.55859375" b="0.02734375" alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="CarbonFiber" r="0.4" g="0.4" b="0.4" alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="CarbonFoam" r="0.5" g="0.5" b="0.5" alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="Aluminum" r="0.7" g="0.7" b="0.7" alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="violet" r="0.4" g="0." b="0.4" alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="red" r="0.6" g="0." b="0." alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
<vis name="yellow" r="0.65" g="0.65" b="0." alpha="1" showDaugthers="true" visible="true" drawingStyle="solid"/>
Expand Down Expand Up @@ -150,7 +157,9 @@
<composite name="PixelEndcapP"/>
</detector>
<detector id="2" name="PST" type="ODDCylinder" beampipe="false" vis="CarbonFiber">
<tubs name="PixelSupportCylinder" rmin="pst_rmin" rmax="pst_rmax" dz="pst_length" material="CarbonFiber"/>
<tubs name="PixelSupportCylinder" rmin="pst_rmin" rmax="pst_rmax" dz="pst_length" material="CarbonFiber">
<layer_material surface="representing" binning="binPhi,binZ" bins0="mat_pst_bPhi" bins1="mat_pst_bZ"/>
</tubs>
</detector>
<detector id="3" name="ShortStrips" type="DD4hep_SubdetectorAssembly" vis="invisible">
<shape name="ShortStripVolume" type="Tube" rmin="ss_env_rmin" rmax="ss_env_rmax" dz="ss_env_dz" material="Air"/>
Expand All @@ -164,8 +173,11 @@
<composite name="LongStripBarrel"/>
<composite name="LongStripEndcapP"/>
</detector>
<detector id="5" name="Solenoid" type="ODDCylinder" beampipe="false" vis="grey">
<tubs name="Solenoid" rmin="sol_rmin" rmax="sol_rmax" dz="sol_hlength" material="CarbonFiber"/>
<detector id="5" name="Solenoid" type="ODDCylinder" beampipe="false" vis="Aluminum">
<boundary_material surface="inner" binning="binPhi,binZ" bins0="mat_sol_bPhi" bins1="mat_sol_bZ"/>
<tubs name="Solenoid" rmin="sol_rmin" rmax="sol_rmax" dz="sol_hlength" material="Aluminum">
<layer_material surface="representing" binning="binPhi,binZ" bins0="mat_sol_bPhi" bins1="mat_sol_bZ"/>
</tubs>
</detector>
</detectors>
</lccdd>

0 comments on commit 0e83c06

Please sign in to comment.