Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:09:32

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file geocel/g4vg/Transformer.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <G4AffineTransform.hh>
0011 #include <G4RotationMatrix.hh>
0012 #include <G4ThreeVector.hh>
0013 #include <VecGeom/base/Transformation3D.h>
0014 
0015 #include "Scaler.hh"
0016 
0017 namespace celeritas
0018 {
0019 namespace g4vg
0020 {
0021 //---------------------------------------------------------------------------//
0022 /*!
0023  * Return a VecGeom transformation from a Geant4 transformation.
0024  */
0025 class Transformer
0026 {
0027   public:
0028     //!@{
0029     //! \name Type aliases
0030     using result_type = vecgeom::Transformation3D;
0031     //!@}
0032 
0033   public:
0034     // Construct with a scale
0035     inline explicit Transformer(Scaler const& convert_scale_);
0036 
0037     //! Convert a translation
0038     inline result_type operator()(G4ThreeVector const& t) const;
0039 
0040     //! Convert a translation + rotation
0041     inline result_type
0042     operator()(G4ThreeVector const& t, G4RotationMatrix const& rot) const;
0043 
0044     //! Convert a translation + optional rotation
0045     inline result_type
0046     operator()(G4ThreeVector const& t, G4RotationMatrix const* rot) const;
0047 
0048     //! Convert an affine transform
0049     inline result_type operator()(G4AffineTransform const& at) const;
0050 
0051   private:
0052     //// DATA ////
0053 
0054     Scaler const& convert_scale_;
0055 };
0056 
0057 //---------------------------------------------------------------------------//
0058 // INLINE DEFINITIONS
0059 //---------------------------------------------------------------------------//
0060 /*!
0061  * Construct with a scaling function.
0062  */
0063 Transformer::Transformer(Scaler const& convert_scale)
0064     : convert_scale_{convert_scale}
0065 {
0066 }
0067 
0068 //---------------------------------------------------------------------------//
0069 /*!
0070  * Create a transform from a translation.
0071  */
0072 auto Transformer::operator()(G4ThreeVector const& t) const -> result_type
0073 {
0074     return {convert_scale_(t[0]), convert_scale_(t[1]), convert_scale_(t[2])};
0075 }
0076 
0077 //---------------------------------------------------------------------------//
0078 /*!
0079  * Create a transform from a translation plus rotation.
0080  */
0081 auto Transformer::operator()(G4ThreeVector const& t,
0082                              G4RotationMatrix const& rot) const -> result_type
0083 {
0084     return {convert_scale_(t[0]),
0085             convert_scale_(t[1]),
0086             convert_scale_(t[2]),
0087             rot.xx(),
0088             rot.yx(),
0089             rot.zx(),
0090             rot.xy(),
0091             rot.yy(),
0092             rot.zy(),
0093             rot.xz(),
0094             rot.yz(),
0095             rot.zz()};
0096 }
0097 
0098 //---------------------------------------------------------------------------//
0099 /*!
0100  * Create a transform from a translation plus optional rotation.
0101  */
0102 auto Transformer::operator()(G4ThreeVector const& t,
0103                              G4RotationMatrix const* rot) const -> result_type
0104 {
0105     if (rot)
0106     {
0107         return (*this)(t, *rot);
0108     }
0109     else
0110     {
0111         return (*this)(t);
0112     }
0113 }
0114 
0115 //---------------------------------------------------------------------------//
0116 /*!
0117  * Create a transform from an affine transform.
0118  */
0119 auto Transformer::operator()(G4AffineTransform const& affine) const -> result_type
0120 {
0121     return (*this)(affine.NetTranslation(), affine.NetRotation());
0122 }
0123 
0124 //---------------------------------------------------------------------------//
0125 }  // namespace g4vg
0126 }  // namespace celeritas