File indexing completed on 2025-01-18 10:14:00
0001
0002
0003
0004 #ifndef VECGEOM_VOLUMES_KERNEL_COAXIALCONESIMPLEMENTATION_H_
0005 #define VECGEOM_VOLUMES_KERNEL_COAXIALCONESIMPLEMENTATION_H_
0006
0007 #include "VecGeom/base/Vector3D.h"
0008 #include "VecGeom/volumes/CoaxialConesStruct.h"
0009 #include "VecGeom/volumes/kernel/ConeImplementation.h"
0010 #include "VecGeom/volumes/kernel/GenericKernels.h"
0011 #include <VecCore/VecCore>
0012
0013 #include <cstdio>
0014
0015 namespace vecgeom {
0016
0017 VECGEOM_DEVICE_FORWARD_DECLARE(struct CoaxialConesImplementation;);
0018 VECGEOM_DEVICE_DECLARE_CONV(struct, CoaxialConesImplementation);
0019
0020 inline namespace VECGEOM_IMPL_NAMESPACE {
0021
0022 class PlacedCoaxialCones;
0023 template <typename T>
0024 struct CoaxialConesStruct;
0025 class UnplacedCoaxialCones;
0026
0027 struct CoaxialConesImplementation {
0028
0029 using PlacedShape_t = PlacedCoaxialCones;
0030 using UnplacedStruct_t = CoaxialConesStruct<Precision>;
0031 using UnplacedVolume_t = UnplacedCoaxialCones;
0032
0033 VECCORE_ATT_HOST_DEVICE
0034 static void PrintType()
0035 {
0036
0037 }
0038
0039 template <typename Stream>
0040 static void PrintType(Stream &st, int transCodeT = translation::kGeneric, int rotCodeT = rotation::kGeneric)
0041 {
0042 st << "SpecializedCoaxialCones<" << transCodeT << "," << rotCodeT << ">";
0043 }
0044
0045 template <typename Stream>
0046 static void PrintImplementationType(Stream &st)
0047 {
0048 (void)st;
0049
0050 }
0051
0052 template <typename Stream>
0053 static void PrintUnplacedType(Stream &st)
0054 {
0055 (void)st;
0056
0057
0058 }
0059
0060 template <typename Real_v, bool ForLowerZ>
0061 VECGEOM_FORCE_INLINE
0062 VECCORE_ATT_HOST_DEVICE
0063 static typename vecCore::Mask_v<Real_v> IsOnRing(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point)
0064 {
0065
0066 using Bool_v = typename vecCore::Mask_v<Real_v>;
0067 Bool_v onRing(false);
0068 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0069 onRing |= (ConeImplementation<ConeTypes::UniversalCone>::template IsOnRing<Real_v, true, ForLowerZ>(
0070 *coaxialcones.fConeStructVector[i], point) ||
0071 ConeImplementation<ConeTypes::UniversalCone>::template IsOnRing<Real_v, false, ForLowerZ>(
0072 *coaxialcones.fConeStructVector[i], point));
0073 }
0074
0075 return onRing;
0076 }
0077
0078 template <typename Real_v, typename Bool_v>
0079 VECGEOM_FORCE_INLINE
0080 VECCORE_ATT_HOST_DEVICE
0081 static void Contains(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Bool_v &inside)
0082 {
0083 Bool_v unused, outside;
0084 GenericKernelForContainsAndInside<Real_v, Bool_v, false>(coaxialcones, point, unused, outside);
0085 inside = !outside;
0086 }
0087
0088
0089
0090 template <typename Real_v, typename Inside_t>
0091 VECGEOM_FORCE_INLINE
0092 VECCORE_ATT_HOST_DEVICE
0093 static void Inside(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Inside_t &inside)
0094 {
0095
0096 using Bool_v = vecCore::Mask_v<Real_v>;
0097 using InsideBool_v = vecCore::Mask_v<Inside_t>;
0098 Bool_v completelyinside, completelyoutside;
0099 GenericKernelForContainsAndInside<Real_v, Bool_v, true>(coaxialcones, point, completelyinside, completelyoutside);
0100 inside = EInside::kSurface;
0101 vecCore::MaskedAssign(inside, (InsideBool_v)completelyoutside, Inside_t(EInside::kOutside));
0102 vecCore::MaskedAssign(inside, (InsideBool_v)completelyinside, Inside_t(EInside::kInside));
0103 }
0104
0105 template <typename Real_v, typename Bool_v, bool ForInside>
0106 VECGEOM_FORCE_INLINE
0107 VECCORE_ATT_HOST_DEVICE
0108 static void GenericKernelForContainsAndInside(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
0109 Bool_v &completelyinside, Bool_v &completelyoutside)
0110 {
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 completelyinside = Bool_v(false);
0121 completelyoutside = Bool_v(true);
0122 Bool_v onSurf(false);
0123
0124 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0125 Bool_v compIn(false);
0126 Bool_v compOut(false);
0127
0128 ConeHelpers<Real_v, ConeTypes::UniversalCone>::template GenericKernelForContainsAndInside<ForInside>(
0129 *coaxialcones.fConeStructVector[i], point, compIn, compOut);
0130 if (ForInside) {
0131 completelyinside |= compIn;
0132 if (vecCore::MaskFull(completelyinside)) {
0133 completelyoutside = !completelyinside;
0134 return;
0135 }
0136
0137 onSurf |= (!compIn && !compOut);
0138 if (vecCore::MaskFull(onSurf)) {
0139 completelyoutside = !onSurf;
0140 return;
0141 }
0142 } else {
0143
0144 completelyoutside &= compOut;
0145 }
0146 }
0147 }
0148
0149 template <typename Real_v>
0150 VECGEOM_FORCE_INLINE
0151 VECCORE_ATT_HOST_DEVICE
0152 static void DistanceToIn(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
0153 Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
0154 {
0155
0156
0157 distance = kInfLength;
0158 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0159 Real_v dist(kInfLength);
0160 ConeImplementation<ConeTypes::UniversalCone>::template DistanceToIn<Real_v>(*coaxialcones.fConeStructVector[i],
0161 point, direction, stepMax, dist);
0162
0163 vecCore::MaskedAssign(distance, dist < distance, dist);
0164 }
0165 }
0166
0167 template <typename Real_v>
0168 VECGEOM_FORCE_INLINE
0169 VECCORE_ATT_HOST_DEVICE
0170 static void DistanceToOut(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point,
0171 Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
0172 {
0173
0174 distance = -1.;
0175 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0176 Real_v dist(kInfLength);
0177 ConeImplementation<ConeTypes::UniversalCone>::template DistanceToOut<Real_v>(*coaxialcones.fConeStructVector[i],
0178 point, direction, stepMax, dist);
0179
0180 vecCore::MaskedAssign(distance, dist > distance, dist);
0181 }
0182 }
0183
0184 template <typename Real_v>
0185 VECGEOM_FORCE_INLINE
0186 VECCORE_ATT_HOST_DEVICE
0187 static void SafetyToIn(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Real_v &safety)
0188 {
0189
0190 safety = kInfLength;
0191 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0192 Real_v safeDist(kInfLength);
0193 ConeImplementation<ConeTypes::UniversalCone>::template SafetyToIn<Real_v>(*coaxialcones.fConeStructVector[i],
0194 point, safeDist);
0195
0196 vecCore::MaskedAssign(safety, safeDist < safety, safeDist);
0197 }
0198 }
0199
0200 template <typename Real_v>
0201 VECGEOM_FORCE_INLINE
0202 VECCORE_ATT_HOST_DEVICE
0203 static void SafetyToOut(UnplacedStruct_t const &coaxialcones, Vector3D<Real_v> const &point, Real_v &safety)
0204 {
0205
0206 safety = Real_v(-1.);
0207 for (unsigned int i = 0; i < coaxialcones.fConeStructVector.size(); i++) {
0208 Real_v safeDist(kInfLength);
0209 ConeImplementation<ConeTypes::UniversalCone>::template SafetyToOut<Real_v>(*coaxialcones.fConeStructVector[i],
0210 point, safeDist);
0211
0212 vecCore::MaskedAssign(safety, safeDist > safety, safeDist);
0213 }
0214 }
0215 };
0216 }
0217 }
0218
0219 #endif