|
||||
File indexing completed on 2025-01-18 09:59:33
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/g4/Convert.geant.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <G4ThreeVector.hh> 0011 0012 #include "corecel/Types.hh" 0013 #include "corecel/cont/Array.hh" 0014 #include "geocel/Types.hh" 0015 #include "geocel/detail/LengthUnits.hh" 0016 0017 namespace celeritas 0018 { 0019 //---------------------------------------------------------------------------// 0020 // CONSTANTS 0021 //---------------------------------------------------------------------------// 0022 //! Value of a unit Celeritas length in the CLHEP unit system 0023 inline constexpr real_type clhep_length = 1 / lengthunits::millimeter; 0024 0025 //---------------------------------------------------------------------------// 0026 // FREE FUNCTIONS 0027 //---------------------------------------------------------------------------// 0028 /*! 0029 * Convert a value from Geant4/CLHEP to Celeritas native units. 0030 */ 0031 template<class T> 0032 constexpr inline T convert_from_geant(T const& val, T units) 0033 { 0034 return val / units; 0035 } 0036 0037 //---------------------------------------------------------------------------// 0038 /*! 0039 * Convert a value from Geant4 with CLHEP units. 0040 */ 0041 constexpr inline double convert_from_geant(double val, double units) 0042 { 0043 return val / units; 0044 } 0045 0046 //---------------------------------------------------------------------------// 0047 /*! 0048 * Convert a 3-vector from Geant4/CLHEP to Celeritas native units. 0049 */ 0050 inline Real3 convert_from_geant(G4ThreeVector const& vec, double units) 0051 { 0052 return {static_cast<real_type>(vec[0] / units), 0053 static_cast<real_type>(vec[1] / units), 0054 static_cast<real_type>(vec[2] / units)}; 0055 } 0056 0057 //---------------------------------------------------------------------------// 0058 /*! 0059 * Convert a C array from Geant4/CLHEP to Celeritas native units. 0060 */ 0061 inline Real3 convert_from_geant(double const vec[3], double units) 0062 { 0063 return {static_cast<real_type>(vec[0] / units), 0064 static_cast<real_type>(vec[1] / units), 0065 static_cast<real_type>(vec[2] / units)}; 0066 } 0067 0068 //---------------------------------------------------------------------------// 0069 /*! 0070 * Convert a native Celeritas quantity to a Geant4 value with CLHEP units. 0071 */ 0072 template<class T> 0073 constexpr inline T convert_to_geant(T const& val, T units) 0074 { 0075 return val * units; 0076 } 0077 0078 //---------------------------------------------------------------------------// 0079 /*! 0080 * Convert a native Celeritas quantity to a Geant4 value. 0081 */ 0082 constexpr inline double convert_to_geant(real_type val, double units) 0083 { 0084 return double{val} * units; 0085 } 0086 0087 //---------------------------------------------------------------------------// 0088 /*! 0089 * Convert a native Celeritas 3-vector to a Geant4 equivalent. 0090 */ 0091 template<class T> 0092 inline G4ThreeVector convert_to_geant(Array<T, 3> const& arr, double units) 0093 { 0094 return {arr[0] * units, arr[1] * units, arr[2] * units}; 0095 } 0096 0097 //! \cond (CELERITAS_DOC_DEV) 0098 //---------------------------------------------------------------------------// 0099 /*! 0100 * Set y += a * x . 0101 */ 0102 inline void axpy(double a, G4ThreeVector const& x, G4ThreeVector* y) 0103 { 0104 CELER_EXPECT(y); 0105 for (int i = 0; i < 3; ++i) 0106 { 0107 (*y)[i] = a * x[i] + (*y)[i]; 0108 } 0109 } 0110 //! \endcond 0111 0112 //---------------------------------------------------------------------------// 0113 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |