Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:17

0001 // ********************************************************************
0002 // * License and Disclaimer                                           *
0003 // *                                                                  *
0004 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0005 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0006 // * conditions of the Geant4 Software License,  included in the file *
0007 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0008 // * include a list of copyright holders.                             *
0009 // *                                                                  *
0010 // * Neither the authors of this software system, nor their employing *
0011 // * institutes,nor the agencies providing financial support for this *
0012 // * work  make  any representation or  warranty, express or implied, *
0013 // * regarding  this  software system or assume any liability for its *
0014 // * use.  Please see the license in the file  LICENSE  and URL above *
0015 // * for the full disclaimer and the limitation of liability.         *
0016 // *                                                                  *
0017 // * This  code  implementation is the result of  the  scientific and *
0018 // * technical work of the GEANT4 collaboration.                      *
0019 // * By using,  copying,  modifying or  distributing the software (or *
0020 // * any work based  on the software)  you  agree  to acknowledge its *
0021 // * use  in  resulting  scientific  publications,  and indicate your *
0022 // * acceptance of all terms of the Geant4 Software license.          *
0023 // ********************************************************************
0024 //
0025 // Helper namespace field_utils inline implementation
0026 
0027 // Author: Dmitry Sorokin, Google Summer of Code 2017
0028 // Supervision: John Apostolakis, CERN
0029 // --------------------------------------------------------------------
0030 
0031 namespace field_utils {
0032 
0033 namespace internal
0034 {
0035   template<class T>
0036   std::size_t getFirstIndex(const T& value)
0037   {
0038     return static_cast<std::size_t>(value);
0039   }
0040 }
0041 
0042 template <typename ArrayType>
0043 inline G4double getValue(const ArrayType& array, Value1D value)
0044 {
0045     const auto begin = internal::getFirstIndex(value);
0046     return array[begin];
0047 }
0048 
0049 template <typename ArrayType>
0050 G4double getValue2(const ArrayType& array, Value1D value)
0051 {
0052     return sqr(getValue(array, value));
0053 }
0054 
0055 template <typename ArrayType>
0056 G4double getValue(const ArrayType& array, Value3D value)
0057 {
0058     return std::sqrt(getValue2(array, value));
0059 }
0060 
0061 template <typename ArrayType>
0062 G4double getValue2(const ArrayType& array, const Value3D value)
0063 {
0064     const auto begin = internal::getFirstIndex(value);
0065     return sqr(array[begin]) + sqr(array[begin+1]) + sqr(array[begin+2]);
0066 }
0067 
0068 template <typename ArrayType>
0069 G4ThreeVector makeVector(const ArrayType& array, Value3D value)
0070 {
0071     const auto begin = internal::getFirstIndex(value);
0072     return G4ThreeVector(array[begin], array[begin + 1], array[begin + 2]);
0073 }
0074 
0075 template <typename SourceArray, typename TargetArray>
0076 void setValue(const SourceArray& src, Value1D value, TargetArray& trg)
0077 {
0078     const auto begin = internal::getFirstIndex(value);
0079     trg[begin] = src[begin];
0080 }
0081 
0082 template <typename SourceArray, typename TargetArray, typename ...TargetArrays>
0083 void setValue(const SourceArray& src, Value1D value,
0084               TargetArray& trg, TargetArrays&... trgs)
0085 {
0086     const auto begin = internal::getFirstIndex(value);
0087     trg[begin] = src[begin];
0088     setValue(src, value, trgs...);
0089 }
0090 
0091 template <typename T>
0092 T clamp(T value, T lo, T hi)
0093 {
0094     return std::min(std::max(lo, value), hi);
0095 }
0096 
0097 } // field_utils