Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:14:08

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// Declaration of a struct with data members for the UnplacedParallelepiped class
0006 /// @file volumes/ParallelepipedStruct.h
0007 /// @author First version created by Mihaela Gheata
0008 
0009 #ifndef VECGEOM_VOLUMES_PARALLELEPIPEDSTRUCT_H_
0010 #define VECGEOM_VOLUMES_PARALLELEPIPEDSTRUCT_H_
0011 #include "VecGeom/base/Global.h"
0012 
0013 namespace vecgeom {
0014 
0015 inline namespace VECGEOM_IMPL_NAMESPACE {
0016 
0017 /// Struct encapsulating data members of the unplaced parallelepiped
0018 template <typename T = double>
0019 struct ParallelepipedStruct {
0020   Vector3D<T> fDimensions; ///< Dimensions dx, dy, dx
0021   T fAlpha;                ///< Angle dx versus dy
0022   T fTheta;                ///< Theta angle of parallelepiped axis
0023   T fPhi;                  ///< Phi angle of parallelepiped axis
0024   T fCtx;                  ///< Scale factor for safety distances in X
0025   T fCty;                  ///< Scale factor for safety distances in Y
0026   T fAreas[3];             ///< Facet areas
0027   Vector3D<T> fNormals[3]; ///< Precomputed normals
0028 
0029   // Precomputed values computed from parameters
0030   T fTanAlpha;       ///< Tangent of alpha angle
0031   T fTanThetaSinPhi; ///< tan(theta)*sin(phi)
0032   T fTanThetaCosPhi; ///< tan(theta)*cos(phi)
0033   T fCosTheta;       ///< cos(theta)
0034 
0035   /// Constructor from a vector of dimensions and three angles
0036   /// @param dim 3D vector with dx, dy, dz
0037   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0038   /// @param theta Polar angle
0039   /// @param phi Azimuthal angle
0040   VECCORE_ATT_HOST_DEVICE
0041   ParallelepipedStruct(Vector3D<T> const &dim, const T alpha, const T theta, const T phi)
0042       : fDimensions(dim), fAlpha(0), fTheta(0), fPhi(0), fCtx(0), fCty(0), fTanAlpha(0), fTanThetaSinPhi(0),
0043         fTanThetaCosPhi(0)
0044   {
0045     SetAlpha(alpha);
0046     SetThetaAndPhi(theta, phi);
0047   }
0048 
0049   /// Constructor from three dimensions and three angles
0050   /// @param dx Half length in x
0051   /// @param dy Half length in y
0052   /// @param dz Half length in z
0053   /// @param alpha Angle between y-axis and the line joining centres of the faces at +/- dy
0054   /// @param theta Polar angle
0055   /// @param phi Azimuthal angle
0056   VECCORE_ATT_HOST_DEVICE
0057   ParallelepipedStruct(const T dx, const T dy, const T dz, const T alpha, const T theta, const T phi)
0058       : fDimensions(dx, dy, dz), fAlpha(0), fTheta(0), fPhi(0), fCtx(0), fCty(0), fTanAlpha(0), fTanThetaSinPhi(0),
0059         fTanThetaCosPhi(0)
0060   {
0061     SetAlpha(alpha);
0062     SetThetaAndPhi(theta, phi);
0063   }
0064 
0065   /// Setter for alpha angle
0066   /// @param alpha angle between Y and the axis of symmetry of the base
0067   VECCORE_ATT_HOST_DEVICE
0068   void SetAlpha(const T alpha)
0069   {
0070     fAlpha    = alpha;
0071     fTanAlpha = vecCore::math::Tan(alpha);
0072     ComputeNormals();
0073   }
0074 
0075   /// Setter for theta angle
0076   /// @param theta Polar angle
0077   VECCORE_ATT_HOST_DEVICE
0078   void SetTheta(const T theta) { SetThetaAndPhi(theta, fPhi); }
0079 
0080   /// Setter for phi angle
0081   /// @param phi Azimuthal angle
0082   VECCORE_ATT_HOST_DEVICE
0083   void SetPhi(const T phi) { SetThetaAndPhi(fTheta, phi); }
0084 
0085   /// Setter for theta and phi
0086   /// @param theta Polar angle
0087   /// @param phi Azimuthal angle
0088   VECCORE_ATT_HOST_DEVICE
0089   void SetThetaAndPhi(const T theta, const T phi)
0090   {
0091     fTheta          = theta;
0092     fPhi            = phi;
0093     fTanThetaCosPhi = vecCore::math::Tan(fTheta) * vecCore::math::Cos(fPhi);
0094     fTanThetaSinPhi = vecCore::math::Tan(fTheta) * vecCore::math::Sin(fPhi);
0095     fCosTheta       = vecCore::math::Cos(fTheta);
0096     ComputeNormals();
0097   }
0098 
0099   /// Compute auxiliary data members: normals, areas, scale factors
0100   VECCORE_ATT_HOST_DEVICE
0101   void ComputeNormals()
0102   {
0103     Vector3D<T> vx(1., 0., 0.);
0104     Vector3D<T> vy(fTanAlpha, 1., 0.);
0105     Vector3D<T> vz(fTanThetaCosPhi, fTanThetaSinPhi, 1.);
0106     fNormals[0] = vy.Cross(vz);
0107     fNormals[1] = vz.Cross(vx);
0108     fNormals[2].Set(0., 0., 1.);
0109     fAreas[0] = 4. * fDimensions.y() * fDimensions.z() * fNormals[0].Mag();
0110     fAreas[1] = 4. * fDimensions.z() * fDimensions.x() * fNormals[1].Mag();
0111     fAreas[2] = 4. * fDimensions.x() * fDimensions.y();
0112     fNormals[0].Normalize();
0113     fNormals[1].Normalize();
0114     fCtx = vecCore::math::Abs(fNormals[0].x());
0115     fCty = vecCore::math::Abs(fNormals[1].y());
0116   }
0117 };
0118 } // namespace VECGEOM_IMPL_NAMESPACE
0119 } // namespace vecgeom
0120 
0121 #endif