Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /// @file ScaledShapeImplementation.h
0002 /// @author Mihaela Gheata (mihaela.gheata@cern.ch)
0003 
0004 #ifndef VECGEOM_VOLUMES_KERNEL_SCALEDSHAPEIMPLEMENTATION_H_
0005 #define VECGEOM_VOLUMES_KERNEL_SCALEDSHAPEIMPLEMENTATION_H_
0006 
0007 #include "VecGeom/volumes/kernel/GenericKernels.h"
0008 #include "VecGeom/base/Vector3D.h"
0009 #include "VecGeom/volumes/ScaledShapeStruct.h"
0010 
0011 #include <cstdio>
0012 
0013 namespace vecgeom {
0014 
0015 VECGEOM_DEVICE_FORWARD_DECLARE(struct ScaledShapeImplementation;);
0016 VECGEOM_DEVICE_DECLARE_CONV(struct, ScaledShapeImplementation);
0017 
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019 
0020 class PlacedScaledShape;
0021 class UnplacedScaledShape;
0022 
0023 // template <typename T>
0024 // struct ScaledShapeStruct;
0025 
0026 struct ScaledShapeImplementation {
0027 
0028   using PlacedShape_t    = PlacedScaledShape;
0029   using UnplacedStruct_t = ScaledShapeStruct<Precision>;
0030   using UnplacedVolume_t = UnplacedScaledShape;
0031 
0032   VECCORE_ATT_HOST_DEVICE
0033   static void PrintType()
0034   {
0035     // printf("SpecializedScaledShape<%i, %i>", transCodeT, rotCodeT);
0036   }
0037 
0038   template <typename Stream>
0039   static void PrintType(Stream &s, int transCodeT = translation::kGeneric, int rotCodeT = rotation::kGeneric)
0040   {
0041     s << "SpecializedScaledShape<" << transCodeT << "," << rotCodeT << ","
0042       << ">";
0043   }
0044 
0045   template <typename Stream>
0046   static void PrintImplementationType(Stream & /*s*/)
0047   {
0048     // s << "SpecializedScaledShape<" << transCodeT << "," << rotCodeT << ">";
0049   }
0050 
0051   template <typename Stream>
0052   static void PrintUnplacedType(Stream & /*s*/)
0053   {
0054     // s << "UnplacedScaledShape";
0055   }
0056 
0057   template <typename Real_v, typename Bool_v>
0058   VECGEOM_FORCE_INLINE
0059   VECCORE_ATT_HOST_DEVICE
0060   static void Contains(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Bool_v &inside);
0061 
0062   template <typename Real_v, typename Inside_t>
0063   VECGEOM_FORCE_INLINE
0064   VECCORE_ATT_HOST_DEVICE
0065   static void Inside(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Inside_t &inside);
0066 
0067   template <typename Real_v>
0068   VECGEOM_FORCE_INLINE
0069   VECCORE_ATT_HOST_DEVICE
0070   static void DistanceToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0071                            Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance);
0072 
0073   template <typename Real_v>
0074   VECGEOM_FORCE_INLINE
0075   VECCORE_ATT_HOST_DEVICE
0076   static void DistanceToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0077                             Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance);
0078 
0079   template <typename Real_v>
0080   VECGEOM_FORCE_INLINE
0081   VECCORE_ATT_HOST_DEVICE
0082   static void SafetyToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Real_v &safety);
0083 
0084   template <typename Real_v>
0085   VECGEOM_FORCE_INLINE
0086   VECCORE_ATT_HOST_DEVICE
0087   static void SafetyToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Real_v &safety);
0088 
0089   template <typename Real_v>
0090   VECGEOM_FORCE_INLINE
0091   VECCORE_ATT_HOST_DEVICE
0092   static void NormalKernel(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Vector3D<Real_v> &normal,
0093                            vecCore::Mask_v<Real_v> &valid);
0094 
0095 }; // End struct ScaledShapeImplementation
0096 
0097 // Implementations start here
0098 
0099 template <typename Real_v, typename Bool_v>
0100 VECCORE_ATT_HOST_DEVICE
0101 void ScaledShapeImplementation::Contains(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0102                                          Bool_v &inside)
0103 {
0104 
0105   // Transform local point to unscaled shape frame
0106   Vector3D<Real_v> ulocalPoint;
0107   unplaced.fScale.Transform(point, ulocalPoint);
0108 
0109   // Now call Contains for the unscaled shape
0110   inside = unplaced.fPlaced->Contains(ulocalPoint);
0111 }
0112 
0113 template <typename Real_v, typename Inside_t>
0114 VECCORE_ATT_HOST_DEVICE
0115 void ScaledShapeImplementation::Inside(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0116                                        Inside_t &inside)
0117 {
0118 
0119   // Transform local point to unscaled shape frame
0120   Vector3D<Real_v> ulocalPoint;
0121   unplaced.fScale.Transform(point, ulocalPoint);
0122 
0123   // Now call Inside for the unscaled shape
0124   inside = unplaced.fPlaced->Inside(ulocalPoint);
0125 }
0126 
0127 template <typename Real_v>
0128 VECCORE_ATT_HOST_DEVICE
0129 void ScaledShapeImplementation::DistanceToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0130                                              Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
0131 {
0132 
0133   // Transform point, direction and stepMax to unscaled shape frame
0134   Vector3D<Real_v> ulocalPoint;
0135   unplaced.fScale.Transform(point, ulocalPoint);
0136 
0137   // Direction is un-normalized after scale transformation
0138   Vector3D<Real_v> ulocalDir;
0139   unplaced.fScale.Transform(direction, ulocalDir);
0140   ulocalDir.Normalize();
0141 
0142   auto ustepMax = unplaced.fScale.TransformDistance(stepMax, direction);
0143 
0144   // Compute distance in unscaled system
0145   distance = unplaced.fPlaced->DistanceToIn(ulocalPoint, ulocalDir, ustepMax);
0146 
0147   // Convert distance back to master (leave unchanged if it was infinity)
0148   vecCore__MaskedAssignFunc(distance, distance < InfinityLength<Real_v>(),
0149                             unplaced.fScale.InverseTransformDistance(distance, ulocalDir));
0150 }
0151 
0152 template <typename Real_v>
0153 VECCORE_ATT_HOST_DEVICE
0154 void ScaledShapeImplementation::DistanceToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0155                                               Vector3D<Real_v> const &direction, Real_v const &stepMax,
0156                                               Real_v &distance)
0157 {
0158 
0159   // Transform point, direction and stepMax to unscaled shape frame
0160   Vector3D<Real_v> ulocalPoint;
0161   unplaced.fScale.Transform(point, ulocalPoint);
0162 
0163   // Direction is un-normalized after scale transformation
0164   Vector3D<Real_v> ulocalDir;
0165   unplaced.fScale.Transform(direction, ulocalDir);
0166   ulocalDir.Normalize();
0167 
0168   auto ustepMax = unplaced.fScale.TransformDistance(stepMax, direction);
0169 
0170   // Compute distance in unscaled system
0171   distance = unplaced.fPlaced->DistanceToOut(ulocalPoint, ulocalDir, ustepMax);
0172 
0173   // Convert distance back to master (leave unchanged if it was infinity)
0174   vecCore__MaskedAssignFunc(distance, distance < InfinityLength<Real_v>(),
0175                             unplaced.fScale.InverseTransformDistance(distance, ulocalDir));
0176 }
0177 
0178 template <typename Real_v>
0179 VECCORE_ATT_HOST_DEVICE
0180 void ScaledShapeImplementation::SafetyToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0181                                            Real_v &safety)
0182 {
0183 
0184   // Transform point to unscaled shape frame
0185   Vector3D<Real_v> ulocalPoint;
0186   unplaced.fScale.Transform(point, ulocalPoint);
0187 
0188   // Compute unscaled safety, then scale it.
0189   safety = unplaced.fPlaced->SafetyToIn(ulocalPoint);
0190   safety = unplaced.fScale.InverseTransformSafety(safety);
0191 }
0192 
0193 template <typename Real_v>
0194 VECCORE_ATT_HOST_DEVICE
0195 void ScaledShapeImplementation::SafetyToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0196                                             Real_v &safety)
0197 {
0198 
0199   // Transform point to unscaled shape frame
0200   Vector3D<Real_v> ulocalPoint;
0201   unplaced.fScale.Transform(point, ulocalPoint);
0202 
0203   // Compute unscaled safety, then scale it.
0204   safety = unplaced.fPlaced->SafetyToOut(ulocalPoint);
0205   safety = unplaced.fScale.InverseTransformSafety(safety);
0206 }
0207 
0208 template <typename Real_v>
0209 VECCORE_ATT_HOST_DEVICE
0210 void ScaledShapeImplementation::NormalKernel(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0211                                              Vector3D<Real_v> &normal, vecCore::Mask_v<Real_v> & /* valid */)
0212 {
0213 
0214   // Transform point to unscaled shape frame
0215   Vector3D<Real_v> ulocalPoint;
0216   unplaced.fScale.Transform(point, ulocalPoint);
0217 
0218   // Compute normal in unscaled frame
0219   Vector3D<Real_v> ulocalNorm;
0220   unplaced.fPlaced->Normal(ulocalPoint, ulocalNorm /*, valid*/);
0221 
0222   // Convert normal to scaled frame
0223   unplaced.fScale.InverseTransformNormal(ulocalNorm, normal);
0224   normal.Normalize();
0225 }
0226 } // namespace VECGEOM_IMPL_NAMESPACE
0227 } // namespace vecgeom
0228 
0229 #endif // VECGEOM_VOLUMES_KERNEL_SCALEDSHAPEIMPLEMENTATION_H_