Skip to content

Commit

Permalink
Add conversion of Geant4 transforms and basic solids to ORANGE (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Apr 8, 2024
1 parent 08d31d6 commit 1842033
Show file tree
Hide file tree
Showing 13 changed files with 1,475 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/geocel/g4vg/Scaler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <utility>
#include <G4ThreeVector.hh>
#include <G4TwoVector.hh>

#include "geocel/detail/LengthUnits.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/geocel/g4vg/SolidConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace
[[maybe_unused]] auto calculate_theta_phi(G4ThreeVector const& axis)
-> std::pair<double, double>
{
// The components of the symmetry axis for G4Para/Trap are alway encoded
// The components of the symmetry axis for G4Para/Trap are always encoded
// as a vector (A.tan(theta)cos(phi), A.tan(theta)sin(phi), A).
double const tan_theta_cos_phi = axis.x() / axis.z();
double const tan_theta_sin_phi = axis.y() / axis.z();
Expand Down
14 changes: 14 additions & 0 deletions src/orange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ if(CELERITAS_USE_JSON)
list(APPEND PRIVATE_DEPS nlohmann_json::nlohmann_json)
endif()

if(CELERITAS_USE_Geant4 AND CELERITAS_REAL_TYPE STREQUAL "double")
set( _cg4org_sources
g4org/SolidConverter.cc
)
celeritas_get_g4libs(_cg4org_libs geometry)
list(APPEND _cg4org_libs Celeritas::corecel Celeritas::geocel)

celeritas_add_object_library(geocel_g4org ${_cg4org_sources})
celeritas_target_link_libraries(geocel_g4org PRIVATE ${_cg4org_libs})

list(APPEND SOURCES $<TARGET_OBJECTS:geocel_g4org>)
list(APPEND PRIVATE_DEPS geocel_g4org)
endif()

#-----------------------------------------------------------------------------#
# Create library
#-----------------------------------------------------------------------------#
Expand Down
65 changes: 65 additions & 0 deletions src/orange/g4org/Scaler.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file orange/g4org/Scaler.hh
//---------------------------------------------------------------------------//
#pragma once

#include <utility>
#include <G4ThreeVector.hh>
#include <G4TwoVector.hh>

#include "corecel/Assert.hh"
#include "corecel/cont/Array.hh"
#include "geocel/detail/LengthUnits.hh"

namespace celeritas
{
namespace g4org
{
//---------------------------------------------------------------------------//
/*!
* Convert a unit from Geant4 scale to another.
*
* The input is the length scale of the original input in the new units.
*/
class Scaler
{
public:
//! Default scale to CLHEP units (mm)
Scaler() : scale_{celeritas::lengthunits::millimeter} {}

//! Scale with an explicit factor, probably for testing
explicit Scaler(double sc) : scale_{sc} { CELER_EXPECT(scale_ > 0); }

//! Multiply a value by the scale
double operator()(double val) const { return val * scale_; }

//! Convert and scale a 2D point
Array<double, 2> operator()(G4TwoVector const& vec) const
{
return this->to<Array<double, 2>>(vec.x(), vec.y());
}

//! Convert and scale a 3D point
Array<double, 3> operator()(G4ThreeVector const& vec) const
{
return this->to<Array<double, 3>>(vec.x(), vec.y(), vec.z());
}

//! Create an array or other object by scaling each argument
template<class S, class... Ts>
S to(Ts&&... args) const
{
return S{(*this)(std::forward<Ts>(args))...};
}

private:
double scale_;
};

//---------------------------------------------------------------------------//
} // namespace g4org
} // namespace celeritas

0 comments on commit 1842033

Please sign in to comment.