Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /// @file: TrapezoidStruct.h
0002 /// @author Guilherme Lima (lima@fnal.gov)
0003 //
0004 //  2016-07-22 Guilherme Lima  Created
0005 //
0006 
0007 #ifndef VECGEOM_VOLUMES_TRAPEZOIDSTRUCT_H_
0008 #define VECGEOM_VOLUMES_TRAPEZOIDSTRUCT_H_
0009 #include "VecGeom/base/Global.h"
0010 #include "VecGeom/base/PlaneShell.h"
0011 #include "VecCore/VecMath.h"
0012 
0013 namespace vecgeom {
0014 
0015 // using namespace vecCore::math;
0016 
0017 inline namespace VECGEOM_IMPL_NAMESPACE {
0018 
0019 /*
0020  * A Trapezoid struct to encapsulate the parameters and some other cached values
0021  * related to Trapezoid that are required in Implementation
0022  */
0023 template <typename T = double>
0024 struct TrapezoidStruct {
0025 
0026   struct TrapSidePlane {
0027     Precision fA, fB, fC, fD;
0028     // Plane equation: Ax+By+Cz+D=0, where
0029     // normal unit vector nvec=(A,B,C)  and offset=D is the distance from origin to plane
0030 
0031     VECCORE_ATT_HOST_DEVICE
0032     TrapSidePlane() : fA(0.0), fB(0.0), fC(0.0), fD(0.0) {}
0033 
0034     VECCORE_ATT_HOST_DEVICE
0035     TrapSidePlane(Precision a, Precision b, Precision c, Precision d) : fA(a), fB(b), fC(c), fD(d) {}
0036 
0037     VECCORE_ATT_HOST_DEVICE
0038     TrapSidePlane(TrapSidePlane const &oth) : fA(oth.fA), fB(oth.fB), fC(oth.fC), fD(oth.fD) {}
0039   };
0040 
0041   T fDz;
0042   T fTheta;
0043   T fPhi;
0044   T fDy1;
0045   T fDx1;
0046   T fDx2;
0047   T fTanAlpha1;
0048   T fDy2;
0049   T fDx3;
0050   T fDx4;
0051   T fTanAlpha2;
0052 
0053   // Values computed from parameters, to be cached
0054   T fTthetaCphi;
0055   T fTthetaSphi;
0056 
0057 #ifndef VECGEOM_PLANESHELL_DISABLE
0058   typedef PlaneShell<4, Precision> Planes;
0059   Planes fPlanes;
0060 #else
0061   TrapSidePlane fPlanes[4];
0062 #endif
0063 
0064   T sideAreas[6]; // including z-planes
0065   Vector3D<T> normals[6];
0066 
0067 public:
0068   /// \brief Constructors
0069   /// @{
0070   // \brief General constructor.  All other constructors should delegate to it
0071   VECCORE_ATT_HOST_DEVICE
0072   TrapezoidStruct(const T pDz, const T pTheta, const T pPhi, const T pDy1, const T pDx1, const T pDx2,
0073                   const T pTanAlpha1, const T pDy2, const T pDx3, const T pDx4, const T pTanAlpha2)
0074       : fDz(pDz), fTheta(pTheta), fPhi(pPhi), fDy1(pDy1), fDx1(pDx1), fDx2(pDx2), fTanAlpha1(pTanAlpha1), fDy2(pDy2),
0075         fDx3(pDx3), fDx4(pDx4), fTanAlpha2(pTanAlpha2)
0076   {
0077     CalculateCached();
0078   }
0079 
0080   /// \brief Constructor for a "default" trapezoid whose parameters are to be set later
0081   VECCORE_ATT_HOST_DEVICE
0082   TrapezoidStruct() : TrapezoidStruct(0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.) {}
0083   /// @}
0084 
0085   /// \brief Destructor
0086   VECCORE_ATT_HOST_DEVICE
0087   virtual ~TrapezoidStruct() {}
0088 
0089   VECCORE_ATT_HOST_DEVICE
0090   void CalculateCached()
0091   {
0092     fTthetaCphi = vecCore::math::Tan(fTheta) * vecCore::math::Cos(fPhi);
0093     fTthetaSphi = vecCore::math::Tan(fTheta) * vecCore::math::Sin(fPhi);
0094     // Recalculate theta and phi for consistency with Geant4
0095     fTheta = vecCore::math::ATan(vecCore::math::Abs(vecCore::math::Tan(fTheta)));
0096     fPhi = vecCore::math::ATan2(fTthetaSphi, fTthetaCphi);
0097   }
0098 
0099 public:
0100 #ifndef VECGEOM_PLANESHELL_DISABLE
0101 
0102   VECCORE_ATT_HOST_DEVICE
0103   VECGEOM_FORCE_INLINE
0104   Planes const *GetPlanes() const { return &fPlanes; }
0105 
0106   VECCORE_ATT_HOST_DEVICE
0107   VECGEOM_FORCE_INLINE
0108   TrapSidePlane GetPlane(unsigned int i) const
0109   {
0110     return TrapSidePlane(fPlanes.fA[i], fPlanes.fB[i], fPlanes.fC[i], fPlanes.fD[i]);
0111   }
0112 
0113   VECCORE_ATT_HOST_DEVICE
0114   VECGEOM_FORCE_INLINE
0115   void SetPlane(unsigned int i, Precision a, Precision b, Precision c, Precision d)
0116   {
0117     fPlanes.fA[i] = a;
0118     fPlanes.fB[i] = b;
0119     fPlanes.fC[i] = c;
0120     fPlanes.fD[i] = d;
0121   }
0122 
0123 #else
0124 
0125   VECCORE_ATT_HOST_DEVICE
0126   VECGEOM_FORCE_INLINE
0127   TrapSidePlane const *GetPlanes() const { return fPlanes; }
0128 
0129   VECCORE_ATT_HOST_DEVICE
0130   VECGEOM_FORCE_INLINE
0131   TrapSidePlane GetPlane(unsigned int i) const { return fPlanes[i]; }
0132 
0133   VECCORE_ATT_HOST_DEVICE
0134   VECGEOM_FORCE_INLINE
0135   void SetPlane(unsigned int i, Precision a, Precision b, Precision c, Precision d)
0136   {
0137     fPlanes[i].fA = a;
0138     fPlanes[i].fB = b;
0139     fPlanes[i].fC = c;
0140     fPlanes[i].fD = d;
0141   }
0142 #endif
0143 };
0144 
0145 } // namespace VECGEOM_IMPL_NAMESPACE
0146 } // namespace vecgeom
0147 
0148 #endif