|
||||
File indexing completed on 2025-01-18 10:05:55
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 orange/g4org/Scaler.hh 0007 //---------------------------------------------------------------------------// 0008 #pragma once 0009 0010 #include <utility> 0011 #include <G4ThreeVector.hh> 0012 #include <G4TwoVector.hh> 0013 0014 #include "corecel/Assert.hh" 0015 #include "corecel/cont/Array.hh" 0016 #include "geocel/detail/LengthUnits.hh" 0017 0018 namespace celeritas 0019 { 0020 namespace g4org 0021 { 0022 //---------------------------------------------------------------------------// 0023 /*! 0024 * Convert a unit from Geant4 scale to another. 0025 * 0026 * The input is the length scale of the original input in the new units. 0027 */ 0028 class Scaler 0029 { 0030 public: 0031 //! Default scale to CLHEP units (mm) 0032 Scaler() : scale_{celeritas::lengthunits::millimeter} {} 0033 0034 //! Scale with an explicit factor, probably for testing 0035 explicit Scaler(double sc) : scale_{sc} { CELER_EXPECT(scale_ > 0); } 0036 0037 //! Multiply a value by the scale 0038 double operator()(double val) const { return val * scale_; } 0039 0040 //! Convert and scale a 2D point 0041 Array<double, 2> operator()(G4TwoVector const& vec) const 0042 { 0043 return this->to<Array<double, 2>>(vec.x(), vec.y()); 0044 } 0045 0046 //! Convert and scale a 3D point 0047 Array<double, 3> operator()(G4ThreeVector const& vec) const 0048 { 0049 return this->to<Array<double, 3>>(vec.x(), vec.y(), vec.z()); 0050 } 0051 0052 //! Create an array or other object by scaling each argument 0053 template<class S, class... Ts> 0054 S to(Ts&&... args) const 0055 { 0056 return S{(*this)(std::forward<Ts>(args))...}; 0057 } 0058 0059 private: 0060 double scale_; 0061 }; 0062 0063 //---------------------------------------------------------------------------// 0064 } // namespace g4org 0065 } // 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 |