Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  * HypeStruct.h
0003  *
0004  *  Created on: Feb 22, 2017
0005  *      Author: rsehgal
0006  */
0007 
0008 #ifndef VOLUMES_HYPESTRUCT_H_
0009 #define VOLUMES_HYPESTRUCT_H_
0010 
0011 #include "VecGeom/base/Global.h"
0012 
0013 namespace vecgeom {
0014 
0015 inline namespace VECGEOM_IMPL_NAMESPACE {
0016 
0017 // An Hype struct without member functions to encapsulate just the parameters
0018 template <typename T = double>
0019 struct HypeStruct {
0020   T fRmin;  // Inner radius
0021   T fRmax;  // Outer radius
0022   T fStIn;  // Stereo angle for inner surface
0023   T fStOut; // Stereo angle for outer surface
0024   T fDz;    // z-coordinate of the cutting planes
0025 
0026   // Precomputed Values
0027   Precision fTIn;      // Tangent of the Inner stereo angle
0028   Precision fTOut;     // Tangent of the Outer stereo angle
0029   Precision fTIn2;     // Squared value of fTIn
0030   Precision fTOut2;    // Squared value of fTOut
0031   Precision fTIn2Inv;  // Inverse of fTIn2
0032   Precision fTOut2Inv; // Inverse of fTOut2
0033   Precision fRmin2;    // Squared Inner radius
0034   Precision fRmax2;    // Squared Outer radius
0035   Precision fDz2;      // Squared z-coordinate
0036 
0037   Precision fEndInnerRadius2; // Squared endcap Inner Radius
0038   Precision fEndOuterRadius2; // Squared endcap Outer Radius
0039   Precision fEndInnerRadius;  // Endcap Inner Radius
0040   Precision fEndOuterRadius;  // Endcap Outer Radius
0041 
0042   Precision fInSqSide; // side of the square inscribed in the inner circle
0043 
0044   // Volume and Surface Area
0045   Precision fCubicVolume, fSurfaceArea;
0046   Precision zToleranceLevel;
0047   Precision innerRadToleranceLevel, outerRadToleranceLevel;
0048 
0049   VECCORE_ATT_HOST_DEVICE
0050   HypeStruct() : fRmin(0.), fRmax(0.), fStIn(0.), fStOut(0.), fDz(0.) {}
0051 
0052   VECCORE_ATT_HOST_DEVICE
0053   HypeStruct(const Precision rMin, const Precision rMax, const Precision stIn, const Precision stOut,
0054              const Precision dz)
0055       : fRmin(rMin), fRmax(rMax), fStIn(stIn), fStOut(stOut), fDz(dz)
0056   {
0057     CalculateCached();
0058   }
0059 
0060   VECCORE_ATT_HOST_DEVICE
0061   void CalculateCached()
0062   {
0063 
0064     fTIn   = vecCore::math::Tan(fStIn);    // Tangent of the Inner stereo angle  (*kDegToRad);
0065     fTOut  = vecCore::math::Tan(fStOut);   // Tangent of the Outer stereo angle
0066     fTIn2  = fTIn * fTIn;   // squared value of fTIn
0067     fTOut2 = fTOut * fTOut; // squared value of fTOut
0068 
0069     fTIn2Inv  = 1. / fTIn2;
0070     fTOut2Inv = 1. / fTOut2;
0071 
0072     fRmin2 = fRmin * fRmin;
0073     fRmax2 = fRmax * fRmax;
0074     fDz2   = fDz * fDz;
0075 
0076     fEndInnerRadius2       = fTIn2 * fDz2 + fRmin2;
0077     fEndOuterRadius2       = fTOut2 * fDz2 + fRmax2;
0078     fEndInnerRadius        = vecCore::math::Sqrt(fEndInnerRadius2);
0079     fEndOuterRadius        = vecCore::math::Sqrt(fEndOuterRadius2);
0080     fInSqSide              = vecCore::math::Sqrt(2.) * fRmin;
0081     zToleranceLevel        = kTolerance * fDz;
0082     innerRadToleranceLevel = kTolerance * fEndInnerRadius; // GetEndInnerRadius();
0083     outerRadToleranceLevel = kTolerance * fEndOuterRadius; // GetEndOuterRadius();
0084     CalcCapacity();
0085     CalcSurfaceArea();
0086     // DetectConvexity();
0087   }
0088 
0089   VECCORE_ATT_HOST_DEVICE
0090   bool InnerSurfaceExists() const { return (fRmin > 0.) || (fStIn != 0.); }
0091 
0092   VECCORE_ATT_HOST_DEVICE
0093   void CalcCapacity() { fCubicVolume = Volume(true) - Volume(false); }
0094 
0095   VECCORE_ATT_HOST_DEVICE
0096   Precision Volume(bool outer)
0097   {
0098     if (outer)
0099       return 2 * kPi * fDz * ((fRmax) * (fRmax) + (fDz2 * fTOut2 / 3.));
0100     else
0101       return 2 * kPi * fDz * ((fRmin) * (fRmin) + (fDz2 * fTIn2 / 3.));
0102   }
0103 
0104   VECCORE_ATT_HOST_DEVICE
0105   void CalcSurfaceArea() { fSurfaceArea = Area(true) + Area(false) + AreaEndCaps(); }
0106 
0107   VECCORE_ATT_HOST_DEVICE
0108   Precision Area(bool outer)
0109   {
0110     Precision fT = 0., fR = 0.;
0111     if (outer) {
0112       fT = fTOut;
0113       fR = fRmax;
0114     } else {
0115       fT = fTIn;
0116       fR = fRmin;
0117     }
0118 
0119     Precision ar = 0.;
0120 
0121     if (fT == 0)
0122       ar = 4 * kPi * fR * fDz;
0123     else {
0124       Precision p = fT * std::sqrt(fT * fT);
0125       Precision q = p * fDz * std::sqrt(fR * fR + (std::pow(fT, 2.) + std::pow(fT, 4.)) * std::pow(fDz, 2.));
0126       Precision r = fR * fR * std::asinh(p * fDz / fR);
0127       ar          = ((q + r) / (2 * p)) * 4 * kPi;
0128     }
0129     return ar;
0130   }
0131 
0132   VECCORE_ATT_HOST_DEVICE
0133   Precision AreaEndCaps() { return 2 * kPi * (fEndOuterRadius2 - fEndInnerRadius2); }
0134 
0135   VECCORE_ATT_HOST_DEVICE
0136   void SetParameters(const Precision rMin, const Precision rMax, const Precision stIn, const Precision stOut,
0137                      const Precision dz)
0138   {
0139     fRmin  = rMin;
0140     fStIn  = stIn;
0141     fRmax  = rMax;
0142     fStOut = stOut;
0143     fDz    = dz;
0144     CalculateCached();
0145   }
0146 };
0147 }
0148 }
0149 #endif /* VOLUMES_HYPESTRUCT_H_ */