Skip to content

Commit

Permalink
fix: geant4 transform conversion (#3038)
Browse files Browse the repository at this point in the history
When translating the `NA60+` gdml file, we notices a sign flip between Geant4 physical volume and Acts translated volume in global space.

This PR introuces a unit test that reproduces the NA60+ setup in a very limited number, and fixes the transform translation in the `Geant4Converter` to Acts.

@ssdetlab - I attached this test to your Gdml based Surface Provider test and made sure all your tests run through appropriately, however, might be good to have another look.
  • Loading branch information
asalzburger authored Mar 18, 2024
1 parent 49e815c commit 44dd2ab
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Plugins/Geant4/src/Geant4Converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ Acts::Transform3 Acts::Geant4AlgebraConverter::transform(
rotation << g4Rot.xx(), g4Rot.yx(), g4Rot.zx(), g4Rot.xy(), g4Rot.yy(),
g4Rot.zy(), g4Rot.xz(), g4Rot.yz(), g4Rot.zz();
Transform3 transform = Transform3::Identity();
transform.matrix().block(0, 0, 3, 1) = rotation.col(0);
transform.matrix().block(0, 1, 3, 1) = rotation.col(1);
transform.matrix().block(0, 2, 3, 1) = rotation.col(2);
transform.matrix().block(0, 3, 3, 1) = translation;
transform.pretranslate(translation);
transform.prerotate(rotation);
return transform;
}

Expand Down
1 change: 1 addition & 0 deletions Plugins/Geant4/src/Geant4DetectorSurfaceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Acts/Plugins/Geant4/Geant4DetectorElement.hpp"
#include "Acts/Plugins/Geant4/Geant4PhysicalVolumeSelectors.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Utilities/StringHelpers.hpp"

#include <utility>

Expand Down
76 changes: 76 additions & 0 deletions Tests/UnitTests/Plugins/Geant4/Geant4SurfaceProviderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "Acts/Detector/LayerStructureBuilder.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Plugins/Geant4/Geant4SurfaceProvider.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/BinningType.hpp"
#include "Acts/Utilities/StringHelpers.hpp"

#include <filesystem>
#include <memory>
Expand Down Expand Up @@ -293,4 +295,78 @@ BOOST_AUTO_TEST_CASE(Geant4SurfaceProviderRanges) {
}
}

const char* gdml_head_xml =
R"""(<?xml version="1.0" ?>
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">)""";

BOOST_AUTO_TEST_CASE(Geant4RectangleFromGDML) {
std::ofstream bgdml;
bgdml.open("Plane.gdml");
bgdml << gdml_head_xml;
bgdml << "<solids>" << '\n';
bgdml << "<box name=\"wb\" x=\"100\" y=\"100\" z=\"500\" lunit=\"mm\"/>"
<< '\n';
bgdml << "<box name=\"c\" x=\"35\" y=\"55\" z=\"90\" lunit=\"mm\"/>" << '\n';
bgdml << "<box name=\"b\" x=\"25\" y=\"50\" z=\"1\" lunit=\"mm\"/>" << '\n';
bgdml << "</solids>" << '\n';
bgdml << "<structure>" << '\n';
bgdml << " <volume name=\"b\">" << '\n';
bgdml << " <materialref ref=\"G4_Fe\"/>" << '\n';
bgdml << " <solidref ref=\"b\"/>" << '\n';
bgdml << " </volume>" << '\n';
bgdml << " <volume name=\"cl\">" << '\n';
bgdml << " <materialref ref=\"G4_Galactic\"/>" << '\n';
bgdml << " <solidref ref=\"c\"/>" << '\n';
bgdml << " <physvol name=\"b_pv\">" << '\n';
bgdml << " <volumeref ref=\"b\"/>" << '\n';
bgdml << " <position name=\"b_pv_pos\" unit=\"mm\" "
"x=\"0\" y=\"5.\" z=\"0\"/>"
<< '\n';
bgdml << " <rotation name=\"b_pv_rot\" unit=\"deg\" "
"x=\"-90\" y=\"0\" z=\"0\"/>"
<< '\n';
bgdml << " </physvol>" << '\n';
bgdml << " </volume>" << '\n';
bgdml << " <volume name=\"wl\">" << '\n';
bgdml << " <materialref ref=\"G4_Galactic\"/>" << '\n';
bgdml << " <solidref ref=\"wb\"/>" << '\n';
bgdml << " <physvol name=\"cl_pv\">" << '\n';
bgdml << " <volumeref ref=\"cl\"/>" << '\n';
bgdml << " <rotation name=\"cl_pv_rot\" unit=\"deg\" "
"x=\"-90\" y=\"0\" z=\"0\"/>"
<< '\n';
bgdml << " </physvol>" << '\n';
bgdml << " </volume>" << '\n';
bgdml << "</structure>" << '\n';
bgdml << "<setup name=\"Default\" version=\"1.0\">" << '\n';
bgdml << " <world ref=\"wl\"/>" << '\n';
bgdml << "</setup>" << '\n';
bgdml << "</gdml>" << '\n';

bgdml.close();

// 1D selection -- select only the second row
auto planeFromGDMLCfg =
Acts::Experimental::Geant4SurfaceProvider<1>::Config();
planeFromGDMLCfg.gdmlPath = "Plane.gdml";
planeFromGDMLCfg.surfacePreselector =
std::make_shared<Acts::Geant4PhysicalVolumeSelectors::NameSelector>(
std::vector<std::string>{"b_pv"}, true);

auto kdt1DOpt = Acts::Experimental::Geant4SurfaceProvider<1>::kdtOptions();
kdt1DOpt.range = Acts::RangeXD<1, Acts::ActsScalar>();
kdt1DOpt.range[0].set(-100, 100);
kdt1DOpt.binningValues = {Acts::BinningValue::binZ};

auto tContext = Acts::GeometryContext();

auto planeProvider =
std::make_shared<Acts::Experimental::Geant4SurfaceProvider<1>>(
planeFromGDMLCfg, kdt1DOpt, false);

auto planes = planeProvider->surfaces(tContext);
BOOST_CHECK_EQUAL(planes.size(), 1u);
CHECK_CLOSE_ABS(planes.front()->center(tContext).z(), 5., 1e-6);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 44dd2ab

Please sign in to comment.