Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding G4Trap converter in Geant4Converters #3775

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Plugins/Geant4/include/Acts/Plugins/Geant4/Geant4Converters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <memory>
#include <tuple>


namespace CLHEP {
class Hep3Vector;
class HepRotation;
Expand All @@ -25,6 +26,11 @@ namespace HepGeom {
class Transform3D;
}

asalzburger marked this conversation as resolved.
Show resolved Hide resolved
#include "/home/cms/software/geant4/install_dir/include/Geant4/G4RotationMatrix.hh"
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
#include "/home/cms/software/geant4/install_dir/include/Geant4/G4ThreeVector.hh"
#include "/home/cms/software/geant4/install_dir/include/Geant4/G4Transform3D.hh"


class G4Box;
class G4Material;
class G4Trd;
Expand Down Expand Up @@ -133,6 +139,16 @@ struct Geant4ShapeConverter {
std::tuple<std::shared_ptr<TrapezoidBounds>, std::array<int, 2u>, ActsScalar>
trapezoidBounds(const G4Trd& g4Trd);

// *************************************************************************************
/// @brief Convert to trapezoid bounds - from Trap
///
/// @param g4Trd a Geant4 trapezoid shape
///
/// @return an ACTS Trapezoid bounds object, axis orientation, and thickness
std::tuple<std::shared_ptr<TrapezoidBounds>, std::array<int, 2u>, ActsScalar>
trapezoidBounds_g4Trap(const G4Trap& g4Trap);
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
// *************************************************************************************

/// @brief Convert to general solid into a planar shape
///
/// @param g4Solid a Geant4 solid shape
Expand Down
98 changes: 96 additions & 2 deletions Plugins/Geant4/src/Geant4Converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/Geant4/Geant4Converters.hpp"
//#include "Acts/Plugins/Geant4/Geant4Converters.hpp"
#include "/home/cms/software/ACTS_ODD/ACTS_Source/Plugins/Geant4/include/Acts/Plugins/Geant4/Geant4Converters.hpp"
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Geometry/CylinderVolumeBounds.hpp"
Expand All @@ -18,7 +19,8 @@
#include "Acts/Surfaces/DiscSurface.hpp"
#include "Acts/Surfaces/LineBounds.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/RadialBounds.hpp"
//#include "RadialBounds.hpp"
#include "/home/cms/software/ACTS_ODD/ACTS_Source/Core/include/Acts/Surfaces/RadialBounds.hpp"
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/StrawSurface.hpp"
#include "Acts/Surfaces/TrapezoidBounds.hpp"
Expand All @@ -30,6 +32,7 @@
#include <stdexcept>
#include <utility>
#include <vector>
#include <iostream>

#include "G4Box.hh"
#include "G4LogicalVolume.hh"
Expand All @@ -38,6 +41,7 @@
#include "G4ThreeVector.hh"
#include "G4Transform3D.hh"
#include "G4Trd.hh"
#include "G4Trap.hh"
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
#include "G4Tubs.hh"
#include "G4VPhysicalVolume.hh"
#include "G4VSolid.hh"
Expand Down Expand Up @@ -234,6 +238,75 @@ Acts::Geant4ShapeConverter::trapezoidBounds(const G4Trd& g4Trd) {
return std::make_tuple(std::move(tBounds), rAxes, thickness);
}

// *********************************************************************************************************

std::tuple<std::shared_ptr<Acts::TrapezoidBounds>, std::array<int, 2u>,
Acts::ActsScalar>
Acts::Geant4ShapeConverter::trapezoidBounds_g4Trap(const G4Trap& g4Trap) {
asalzburger marked this conversation as resolved.
Show resolved Hide resolved
// primary parameters
ActsScalar y1 = static_cast<ActsScalar>(g4Trap.GetYHalfLength1());
ActsScalar y2 = static_cast<ActsScalar>(g4Trap.GetYHalfLength2());
ActsScalar x1 = static_cast<ActsScalar>(g4Trap.GetXHalfLength1());
ActsScalar x2 = static_cast<ActsScalar>(g4Trap.GetXHalfLength2());
ActsScalar x3 = static_cast<ActsScalar>(g4Trap.GetXHalfLength3());
ActsScalar x4 = static_cast<ActsScalar>(g4Trap.GetXHalfLength4());
ActsScalar phi = static_cast<ActsScalar>(g4Trap.GetPhi());
ActsScalar theta = static_cast<ActsScalar>(g4Trap.GetTheta());
ActsScalar z = static_cast<ActsScalar>(g4Trap.GetZHalfLength());

ActsScalar hlX0 = (x1 + x2)*0.5;
ActsScalar hlX1 = 2*z*std::tan(theta)*std::cos(phi) + (x3+x4)*0.5;
ActsScalar hlY0 = y1;
ActsScalar hlY1 = y2 + 2*z*std::tan(theta)*std::sin(phi);
ActsScalar hlZ = z;

std::vector<ActsScalar> dXYZ = {(hlX0 + hlX1) * 0.5, (hlY0 + hlY1) * 0.5,
hlZ};

auto minAt = std::min_element(dXYZ.begin(), dXYZ.end());
std::size_t minPos = std::distance(dXYZ.begin(), minAt);
ActsScalar thickness = 2. * dXYZ[minPos];

ActsScalar halfLengthXminY = 0.;
ActsScalar halfLengthXmaxY = 0.;
ActsScalar halfLengthY = 0.;

std::array<int, 2u> rAxes = {};
switch (minPos) {
case 0: {
halfLengthXminY = std::min(hlY0,hlY1);
halfLengthXmaxY = std::max(hlY0,hlY1);
halfLengthY = hlZ;
rAxes = {1, 2};
} break;
case 1: {
halfLengthXminY = std::min(hlX0,hlX1);
halfLengthXmaxY = std::max(hlX0,hlX1);
halfLengthY = hlZ;
rAxes = {0, -2};
} break;
case 2: {
if (std::abs(hlY0 - hlY1) < std::abs(hlX0 - hlX1)) {
halfLengthXminY = std::min(hlX0,hlX1);
halfLengthXmaxY = std::max(hlX0,hlX1);
halfLengthY = (hlY0 + hlY1) * 0.5;
rAxes = {0, 1};
} else {
halfLengthXminY = std::min(hlY0,hlY1);
halfLengthXmaxY = std::max(hlY0,hlY1);
halfLengthY = (hlX0 + hlX1) * 0.5;
rAxes = {-1, 0};
}
} break;
}

auto tBounds = std::make_shared<TrapezoidBounds>(
halfLengthXminY, halfLengthXmaxY, halfLengthY);
return std::make_tuple(std::move(tBounds), rAxes, thickness);
}

// *********************************************************************************************************

std::tuple<std::shared_ptr<Acts::PlanarBounds>, std::array<int, 2u>,
Acts::ActsScalar>
Acts::Geant4ShapeConverter::planarBounds(const G4VSolid& g4Solid) {
Expand Down Expand Up @@ -332,6 +405,27 @@ std::shared_ptr<Acts::Surface> Acts::Geant4PhysicalVolumeConverter::surface(
}
}

// ***************************************************************************************
asalzburger marked this conversation as resolved.
Show resolved Hide resolved

// Into a Trapezoid (G4Trap)
auto g4Trap = dynamic_cast<const G4Trap*>(g4Solid);
if (g4Trap != nullptr) {
if (forcedType == Surface::SurfaceType::Other ||
forcedType == Surface::SurfaceType::Plane) {
auto [bounds, axes, original] =
Geant4ShapeConverter{}.trapezoidBounds_g4Trap(*g4Trap);
auto orientedToGlobal = axesOriented(toGlobal, axes);
surface = Acts::Surface::makeShared<PlaneSurface>(orientedToGlobal,
std::move(bounds));
assignMaterial(*surface.get(), original, compressed);
return surface;
} else {
throw std::runtime_error("Can not convert 'G4Trap' into forced shape.");
}
}

// ***************************************************************************************

// Into a Cylinder, disc or line
auto g4Tubs = dynamic_cast<const G4Tubs*>(g4Solid);
if (g4Tubs != nullptr) {
Expand Down
Loading