Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:28

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 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 celeritas/phys/FourVector.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/cont/Array.hh"
0011 #include "corecel/math/ArrayOperators.hh"
0012 #include "corecel/math/ArrayUtils.hh"
0013 #include "geocel/Types.hh"
0014 #include "celeritas/Types.hh"
0015 
0016 namespace celeritas
0017 {
0018 //---------------------------------------------------------------------------//
0019 // STRUCTS
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * The momentum-energy four-vector (Lorentz vector).
0023  */
0024 struct FourVector
0025 {
0026     //// DATA ////
0027 
0028     Real3 mom{0, 0, 0};  //!< Particle momentum
0029     real_type energy{0};  //!< Particle energy
0030 
0031     // Assignment operator (+=)
0032     inline CELER_FUNCTION FourVector& operator+=(FourVector const& v)
0033     {
0034         mom += v.mom;
0035         energy += v.energy;
0036         return *this;
0037     }
0038 };
0039 
0040 //---------------------------------------------------------------------------//
0041 // INLINE UTILITY FUNCTIONS
0042 //---------------------------------------------------------------------------//
0043 /*!
0044  * Add two four-vectors.
0045  */
0046 inline CELER_FUNCTION FourVector operator+(FourVector const& lhs,
0047                                            FourVector const& rhs)
0048 {
0049     FourVector result = lhs;
0050     return result += rhs;
0051 }
0052 
0053 //---------------------------------------------------------------------------//
0054 /*!
0055  * Get the boost vector (\f$ \frac{\vec{mom}}/{energy} \f$) of a four-vector.
0056  */
0057 inline CELER_FUNCTION Real3 boost_vector(FourVector const& p)
0058 {
0059     CELER_EXPECT(p.energy > 0);
0060     return (real_type{1} / p.energy) * p.mom;
0061 }
0062 
0063 //---------------------------------------------------------------------------//
0064 /*!
0065  * Perform the Lorentz transformation (\f$ \Lambda^{\alpha}_{\beta} \f$) along
0066  * the boost vector (\f$ \vec{v} \f$) for a four-vector \f$ p^{\beta} \f$:
0067  *
0068  * \f$ p^{\prime \beta} = \Lambda^{\alpha}_{\beta} (\vec{v}) p^{\beta} \f$.
0069  *
0070  */
0071 inline CELER_FUNCTION void boost(Real3 const& v, FourVector* p)
0072 {
0073     real_type const v_sq = dot_product(v, v);
0074     CELER_EXPECT(v_sq < real_type{1});
0075 
0076     real_type const vp = dot_product(v, p->mom);
0077     real_type const gamma = real_type{1} / std::sqrt(1 - v_sq);
0078     real_type const lambda = (v_sq > 0 ? (gamma - 1) * vp / v_sq : 0)
0079                              + gamma * p->energy;
0080 
0081     axpy(lambda, v, &(p->mom));
0082     p->energy = gamma * (p->energy + vp);
0083 }
0084 
0085 //---------------------------------------------------------------------------//
0086 /*!
0087  * Calculate the magnitude of a four vector.
0088  */
0089 inline CELER_FUNCTION real_type norm(FourVector const& a)
0090 {
0091     return std::sqrt(std::fabs(ipow<2>(a.energy) - dot_product(a.mom, a.mom)));
0092 }
0093 
0094 }  // namespace celeritas