Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:26:24

0001 #ifndef VECGEOM_TUBESTRUCT_H_
0002 #define VECGEOM_TUBESTRUCT_H_
0003 
0004 #include "VecGeom/base/Global.h"
0005 #include "VecGeom/volumes/Wedge_Evolution.h"
0006 
0007 namespace vecgeom {
0008 // VECGEOM_DEVICE_FORWARD_DECLARE( struct TubeStruct; )
0009 // VECGEOM_DEVICE_DECLARE_BoxStruct )
0010 
0011 inline namespace VECGEOM_IMPL_NAMESPACE {
0012 
0013 // a plain and lightweight struct to encapsulate data members of a tube
0014 template <typename T = double>
0015 struct TubeStruct {
0016   // tube defining parameters
0017   T fRmin; //< inner radius
0018   T fRmax; //< outer radius
0019   T fZ;    //< half-length in +z and -z direction
0020   T fSphi; //< starting phi value (in radians)
0021   T fDphi; //< delta phi value of tube segment (in radians)
0022 
0023   // cached complex values (to avoid recomputation during usage)
0024   T fRmin2;
0025   T fRmax2;
0026   T fAlongPhi1x;
0027   T fAlongPhi1y;
0028   T fAlongPhi2x;
0029   T fAlongPhi2y;
0030   T fTolIrmin2;
0031   T fTolOrmin2;
0032   T fTolIrmax2;
0033   T fTolOrmax2;
0034   T fTolIz;
0035   T fTolOz;
0036   T fTolIrmin;
0037   T fTolOrmin;
0038   T fTolIrmax;
0039   T fTolOrmax;
0040   T fMaxVal;
0041   evolution::Wedge fPhiWedge;
0042 
0043   VECCORE_ATT_HOST_DEVICE
0044   void UpdatedZ()
0045   {
0046     fTolIz  = fZ - kHalfTolerance;
0047     fTolOz  = fZ + kHalfTolerance;
0048     fMaxVal = vecCore::math::Max(fRmax, fZ);
0049   }
0050 
0051   VECCORE_ATT_HOST_DEVICE
0052   void UpdatedRMin()
0053   {
0054     fRmin2     = fRmin * fRmin;
0055     fTolOrmin  = (fRmin - kHalfTolerance);
0056     fTolIrmin  = (fRmin + kHalfTolerance);
0057     fTolOrmin2 = fTolOrmin * fTolOrmin;
0058     fTolIrmin2 = fTolIrmin * fTolIrmin;
0059   }
0060 
0061   VECCORE_ATT_HOST_DEVICE
0062   void UpdatedRMax()
0063   {
0064     fRmax2     = fRmax * fRmax;
0065     fTolOrmax  = (fRmax + kHalfTolerance);
0066     fTolIrmax  = (fRmax - kHalfTolerance);
0067     fTolOrmax2 = fTolOrmax * fTolOrmax;
0068     fTolIrmax2 = fTolIrmax * fTolIrmax;
0069     fMaxVal    = vecCore::math::Max(fRmax, fZ);
0070   }
0071 
0072 public:
0073   VECCORE_ATT_HOST_DEVICE
0074   T rmin() const { return fRmin; }
0075   VECCORE_ATT_HOST_DEVICE
0076   T z() const { return fZ; }
0077 
0078 private:
0079   // can go into source
0080   VECCORE_ATT_HOST_DEVICE
0081   static void GetAlongVectorToPhiSector(Precision phi, Precision &x, Precision &y)
0082   {
0083     x = std::cos(phi);
0084     y = std::sin(phi);
0085   }
0086 
0087 public:
0088   VECCORE_ATT_HOST_DEVICE
0089   void SetRMin(Precision const &_rmin)
0090   {
0091     fRmin = _rmin;
0092     // Update cached values;
0093     UpdatedRMin();
0094   }
0095 
0096   VECCORE_ATT_HOST_DEVICE
0097   void SetRMax(Precision const &_rmax)
0098   {
0099     fRmax = _rmax;
0100     // Update cached values;
0101     UpdatedRMax();
0102   }
0103 
0104   VECCORE_ATT_HOST_DEVICE
0105   void SetDz(Precision const &_z)
0106   {
0107     fZ = _z;
0108     // Update cached values;
0109     UpdatedZ();
0110   }
0111 
0112   // can go into source
0113   VECCORE_ATT_HOST_DEVICE
0114   void SetAndCheckSPhiAngle(T sPhi)
0115   {
0116     // Ensure fSphi in 0-2PI or -2PI-0 range if shape crosses 0
0117     if (sPhi < 0) {
0118       fSphi = kTwoPi - std::fmod(std::fabs(sPhi), kTwoPi);
0119     } else {
0120       fSphi = std::fmod(sPhi, kTwoPi);
0121     }
0122     if (fSphi + fDphi > kTwoPi) {
0123       fSphi -= kTwoPi;
0124     }
0125     // Update cached values.
0126     GetAlongVectorToPhiSector(fSphi, fAlongPhi1x, fAlongPhi1y);
0127     GetAlongVectorToPhiSector(fSphi + fDphi, fAlongPhi2x, fAlongPhi2y);
0128   }
0129 
0130   // can go into source
0131   VECCORE_ATT_HOST_DEVICE
0132   void SetAndCheckDPhiAngle(T dPhi)
0133   {
0134     if (dPhi >= kTwoPi - 0.5 * kAngTolerance) {
0135       fDphi = kTwoPi;
0136       fSphi = 0;
0137     } else {
0138       if (dPhi > 0) {
0139         fDphi = dPhi;
0140       } else {
0141         //        std::ostringstream message;
0142         //        message << "Invalid dphi.\n"
0143         //                << "Negative or zero delta-Phi (" << dPhi << ")\n";
0144         //        std::cout<<"UnplacedTube::CheckDPhiAngle(): Fatal error: "<< message.str().c_str() <<"\n";
0145       }
0146     }
0147     // Update cached values.
0148     GetAlongVectorToPhiSector(fSphi + fDphi, fAlongPhi2x, fAlongPhi2y);
0149   }
0150 
0151   // can go into source
0152   VECCORE_ATT_HOST_DEVICE
0153   void CalculateCached()
0154   {
0155     UpdatedZ();
0156     UpdatedRMin();
0157     UpdatedRMax();
0158 
0159     GetAlongVectorToPhiSector(fSphi, fAlongPhi1x, fAlongPhi1y);
0160     GetAlongVectorToPhiSector(fSphi + fDphi, fAlongPhi2x, fAlongPhi2y);
0161 
0162     fMaxVal = vecCore::math::Max(fRmax, fZ);
0163   }
0164 
0165 public:
0166   // constructors
0167   VECCORE_ATT_HOST_DEVICE
0168   TubeStruct(T const &_rmin, T const &_rmax, T const &_z, T const &_sphi, T const &_dphi)
0169       : fRmin(_rmin < 0.0 ? 0.0 : _rmin), fRmax(_rmax), fZ(_z), fSphi(_sphi), fDphi(_dphi), fRmin2(0), fRmax2(0),
0170         fAlongPhi1x(0), fAlongPhi1y(0), fAlongPhi2x(0), fAlongPhi2y(0), fTolIrmin2(0), fTolOrmin2(0), fTolIrmax2(0),
0171         fTolOrmax2(0), fTolIz(0), fTolOz(0), fPhiWedge(_dphi, _sphi)
0172   {
0173     CalculateCached();
0174     // DetectConvexity();
0175   }
0176 };
0177 } // namespace VECGEOM_IMPL_NAMESPACE
0178 } // namespace vecgeom
0179 
0180 #endif