Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 09:16:12

0001 /*
0002  * UnplacedPolycone.h
0003  *
0004  *  Created on: Dec 8, 2014
0005  *      Author: swenzel
0006  */
0007 
0008 #ifndef VECGEOM_VOLUMES_UNPLACEDPOLYCONE_H_
0009 #define VECGEOM_VOLUMES_UNPLACEDPOLYCONE_H_
0010 
0011 #include "VecGeom/base/Cuda.h"
0012 #include "VecGeom/base/Global.h"
0013 #include "VecGeom/base/AlignedBase.h"
0014 #include "VecGeom/volumes/UnplacedVolume.h"
0015 #include "VecGeom/volumes/PolyconeStruct.h"
0016 #include "VecGeom/volumes/kernel/PolyconeImplementation.h"
0017 #include "VecGeom/volumes/UnplacedVolumeImplHelper.h"
0018 #include "VecGeom/volumes/kernel/shapetypes/ConeTypes.h"
0019 
0020 namespace vecgeom {
0021 
0022 VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedPolycone;);
0023 VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedPolycone);
0024 VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE(class, SUnplacedPolycone, typename);
0025 
0026 inline namespace VECGEOM_IMPL_NAMESPACE {
0027 
0028 class UnplacedPolycone : public VUnplacedVolume {
0029 
0030 private:
0031   PolyconeStruct<Precision> *fPolycone{nullptr};
0032   bool fAllocated{false};
0033   const void *fBuffer{nullptr};
0034 
0035 public:
0036   // Constructor needed by specialization when Polycone becomes Cone
0037   UnplacedPolycone(Precision rmin1, Precision rmax1, Precision rmin2, Precision rmax2, Precision dz, Precision phistart,
0038                    Precision deltaphi)
0039       : fPolycone(new PolyconeStruct<Precision>)
0040   {
0041     int Nz = 2;
0042     Precision rMin[2];
0043     Precision rMax[2];
0044     Precision z[2];
0045     rMin[0]                       = rmin1;
0046     rMin[1]                       = rmin2;
0047     rMax[0]                       = rmax1;
0048     rMax[1]                       = rmax2;
0049     z[0]                          = -dz;
0050     z[1]                          = dz;
0051     fPolycone->fContinuityOverAll = true;
0052     fPolycone->fConvexityPossible = true;
0053     fPolycone->fEqualRmax         = true;
0054     fPolycone->Init(phistart, deltaphi, Nz, z, rMin, rMax);
0055     DetectConvexity();
0056     ComputeBBox();
0057   }
0058 
0059   // Constructor needed by specialization when Polycone becomes Tube
0060   UnplacedPolycone(Precision rmin, Precision rmax, Precision dz, Precision phistart, Precision deltaphi)
0061       : fPolycone(new PolyconeStruct<Precision>)
0062   {
0063     int Nz = 2;
0064     Precision rMin[2];
0065     Precision rMax[2];
0066     Precision z[2];
0067     rMin[0]                       = rmin;
0068     rMin[1]                       = rmin;
0069     rMax[0]                       = rmax;
0070     rMax[1]                       = rmax;
0071     z[0]                          = -dz;
0072     z[1]                          = dz;
0073     fPolycone->fContinuityOverAll = true;
0074     fPolycone->fConvexityPossible = true;
0075     fPolycone->fEqualRmax         = true;
0076     fPolycone->Init(phistart, deltaphi, Nz, z, rMin, rMax);
0077     DetectConvexity();
0078     ComputeBBox();
0079   }
0080 
0081   // the constructor
0082   VECCORE_ATT_HOST_DEVICE
0083   UnplacedPolycone(Precision phistart, Precision deltaphi, int Nz, Precision const *z, Precision const *rmin,
0084                    Precision const *rmax)
0085       : fPolycone(new PolyconeStruct<Precision>)
0086   {
0087     // init internal members
0088     fPolycone->fContinuityOverAll = true;
0089     fPolycone->fConvexityPossible = true;
0090     fPolycone->fEqualRmax         = true;
0091     fPolycone->Init(phistart, deltaphi, Nz, z, rmin, rmax);
0092     DetectConvexity();
0093     ComputeBBox();
0094   }
0095 
0096   // GPU constructor
0097   VECCORE_ATT_HOST_DEVICE
0098   UnplacedPolycone(bool continuityOverAll, bool convexityPossible, bool equalRmax, Precision phistart,
0099                    Precision deltaphi, int nsections, int nz, Precision const *z, Precision const *rmin,
0100                    Precision const *rmax, size_t const buff_size, void const *buffer)
0101   {
0102     fAllocated = (buffer == nullptr);
0103     fBuffer    = fAllocated ? new char[buff_size] : buffer;
0104     AlignedAllocator a((void *)fBuffer, buff_size);
0105     fPolycone = a.aligned_alloc<PolyconeStruct<Precision>>(1, 0, continuityOverAll, convexityPossible, equalRmax,
0106                                                            phistart, deltaphi, nsections, nz, z, rmin, rmax, a);
0107 
0108     DetectConvexity();
0109     ComputeBBox();
0110   }
0111 
0112   // alternative constructor, required for integration with Geant4
0113   VECCORE_ATT_HOST_DEVICE
0114   UnplacedPolycone(Precision phiStart,  // initial phi starting angle
0115                    Precision phiTotal,  // total phi angle
0116                    int numRZ,           // number corners in r,z space
0117                    Precision const *r,  // r coordinate of these corners
0118                    Precision const *z); // z coordinate of these corners
0119 
0120   VECCORE_ATT_HOST_DEVICE
0121   void DetectConvexity();
0122 
0123   VECCORE_ATT_HOST_DEVICE
0124   void Reset();
0125 
0126   VECCORE_ATT_HOST_DEVICE
0127   PolyconeHistorical *GetOriginalParameters() const { return fPolycone->GetOriginalParameters(); }
0128 
0129   VECCORE_ATT_HOST_DEVICE
0130   VECGEOM_FORCE_INLINE
0131   virtual ESolidType GetType() const override { return ESolidType::polycone; }
0132 
0133   VECCORE_ATT_HOST_DEVICE
0134   PolyconeStruct<Precision> const &GetStruct() const { return *fPolycone; }
0135   VECCORE_ATT_HOST_DEVICE
0136   unsigned int GetNz() const { return fPolycone->fNz; }
0137   VECCORE_ATT_HOST_DEVICE
0138   int GetNSections() const { return fPolycone->fSections.size(); }
0139   VECCORE_ATT_HOST_DEVICE
0140   Precision GetStartPhi() const { return fPolycone->fStartPhi; }
0141   VECCORE_ATT_HOST_DEVICE
0142   Precision GetDeltaPhi() const { return fPolycone->fDeltaPhi; }
0143   VECCORE_ATT_HOST_DEVICE
0144   Precision GetEndPhi() const { return fPolycone->fStartPhi + fPolycone->fDeltaPhi; }
0145   VECCORE_ATT_HOST_DEVICE
0146   evolution::Wedge const &GetWedge() const { return fPolycone->fPhiWedge; }
0147 
0148   VECCORE_ATT_HOST_DEVICE
0149   int GetSectionIndex(Precision zposition) const { return fPolycone->GetSectionIndex(zposition); }
0150 
0151   VECCORE_ATT_HOST_DEVICE
0152   PolyconeSection const &GetSection(Precision zposition) const { return fPolycone->GetSection(zposition); }
0153 
0154   VECCORE_ATT_HOST_DEVICE
0155   // GetSection if index is known
0156   PolyconeSection const &GetSection(int index) const { return fPolycone->fSections[index]; }
0157 
0158   VECCORE_ATT_HOST_DEVICE
0159   Precision GetRminAtPlane(int index) const { return fPolycone->GetRminAtPlane(index); }
0160 
0161   VECCORE_ATT_HOST_DEVICE
0162   Precision GetRmaxAtPlane(int index) const { return fPolycone->GetRmaxAtPlane(index); }
0163 
0164   VECCORE_ATT_HOST_DEVICE
0165   Precision GetZAtPlane(int index) const { return fPolycone->GetZAtPlane(index); }
0166 
0167   VECCORE_ATT_HOST_DEVICE
0168   Precision GetRmin1AtSection(int index) const { return fPolycone->GetRmin1AtSection(index); }
0169 
0170   VECCORE_ATT_HOST_DEVICE
0171   Precision GetRmax1AtSection(int index) const { return fPolycone->GetRmax1AtSection(index); }
0172 
0173   VECCORE_ATT_HOST_DEVICE
0174   Precision GetRmin2AtSection(int index) const { return fPolycone->GetRmin2AtSection(index); }
0175 
0176   VECCORE_ATT_HOST_DEVICE
0177   Precision GetRmax2AtSection(int index) const { return fPolycone->GetRmax2AtSection(index); }
0178 
0179   Precision Capacity() const override
0180   {
0181     Precision cubicVolume = 0.;
0182     for (int i = 0; i < GetNSections(); i++) {
0183       PolyconeSection const &section = fPolycone->fSections[i];
0184       cubicVolume += section.fSolid.Capacity();
0185     }
0186     return cubicVolume;
0187   }
0188 
0189   Precision SurfaceArea() const override;
0190 
0191   VECCORE_ATT_HOST_DEVICE
0192   bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &norm) const override;
0193 
0194   VECCORE_ATT_HOST_DEVICE
0195   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override;
0196 
0197 #if !defined(VECCORE_CUDA)
0198 
0199   Vector3D<Precision> SamplePointOnSurface() const override;
0200 
0201   // Methods for random point generation
0202   Vector3D<Precision> GetPointOnCone(Precision fRmin1, Precision fRmax1, Precision fRmin2, Precision fRmax2,
0203                                      Precision zOne, Precision zTwo, Precision &totArea) const;
0204 
0205   Vector3D<Precision> GetPointOnTubs(Precision fRMin, Precision fRMax, Precision zOne, Precision zTwo,
0206                                      Precision &totArea) const;
0207 
0208   Vector3D<Precision> GetPointOnCut(Precision fRMin1, Precision fRMax1, Precision fRMin2, Precision fRMax2,
0209                                     Precision zOne, Precision zTwo, Precision &totArea) const;
0210 
0211   Vector3D<Precision> GetPointOnRing(Precision fRMin, Precision fRMax, Precision fRMin2, Precision fRMax2,
0212                                      Precision zOne) const;
0213 
0214 #endif // !VECCORE_CUDA
0215 
0216   // these methods are required by VUnplacedVolume
0217   //
0218 public:
0219   virtual int MemorySize() const override { return sizeof(*this); }
0220 
0221   VECCORE_ATT_HOST_DEVICE
0222   virtual void Print() const final;
0223   virtual void Print(std::ostream &os) const final;
0224 
0225 #ifndef VECCORE_CUDA
0226   virtual SolidMesh *CreateMesh3D(Transformation3D const &trans, size_t nSegments) const override;
0227 #endif
0228 
0229   std::ostream &StreamInfo(std::ostream &os) const;
0230   std::string GetEntityType() const { return "Polycone"; }
0231 
0232 #ifdef VECGEOM_CUDA_INTERFACE
0233   virtual size_t DeviceSizeOf() const override
0234   {
0235     return DevicePtr<cuda::SUnplacedPolycone<cuda::ConeTypes::UniversalCone>>::SizeOf();
0236   }
0237   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
0238   virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
0239   static void CopyToGpu(std::vector<VUnplacedVolume const *> const &volumes,
0240                         std::vector<DevicePtr<cuda::VUnplacedVolume>> const &devicePointers);
0241 #endif
0242 
0243 #ifndef VECCORE_CUDA
0244 #ifdef VECGEOM_ROOT
0245   TGeoShape const *ConvertToRoot(char const *label) const;
0246 #endif
0247 
0248 #ifdef VECGEOM_GEANT4
0249   G4VSolid const *ConvertToGeant4(char const *label) const;
0250 #endif
0251 #endif
0252 
0253 }; // end class UnplacedPolycone
0254 
0255 template <>
0256 struct Maker<UnplacedPolycone> {
0257   template <typename... ArgTypes>
0258   static UnplacedPolycone *MakeInstance(Precision phistart, Precision deltaphi, int Nz, Precision const *z,
0259                                         Precision const *rmin, Precision const *rmax);
0260   template <typename... ArgTypes>
0261   static UnplacedPolycone *MakeInstance(Precision phistart, Precision deltaphi, int Nz, Precision const *r,
0262                                         Precision const *z);
0263 };
0264 
0265 template <typename PolyconeType = ConeTypes::UniversalCone>
0266 class SUnplacedPolycone : public UnplacedVolumeImplHelper<PolyconeImplementation<PolyconeType>, UnplacedPolycone>,
0267                           public AlignedBase {
0268 public:
0269   using BaseType_t = UnplacedVolumeImplHelper<PolyconeImplementation<PolyconeType>, UnplacedPolycone>;
0270   using BaseType_t::BaseType_t;
0271 
0272   VECCORE_ATT_DEVICE
0273   static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
0274 #ifdef VECCORE_CUDA
0275                                const int id, const int copy_no, const int child_id,
0276 #endif
0277                                VPlacedVolume *const placement = NULL);
0278 
0279 #ifndef VECCORE_CUDA
0280   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0281                                            Transformation3D const *const transformation,
0282                                            VPlacedVolume *const placement = NULL) const override
0283   {
0284     return VolumeFactory::CreateByTransformation<SUnplacedPolycone<PolyconeType>>(volume, transformation, placement);
0285   }
0286 
0287 #else
0288   VECCORE_ATT_DEVICE
0289   virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0290                                            Transformation3D const *const transformation, const int id,
0291                                            const int copy_no, const int child_id,
0292                                            VPlacedVolume *const placement = NULL) const override
0293   {
0294     return VolumeFactory::CreateByTransformation<SUnplacedPolycone<PolyconeType>>(volume, transformation, id, copy_no,
0295                                                                                   child_id, placement);
0296   }
0297 #endif
0298 };
0299 
0300 using GenericUnplacedPolycone = SUnplacedPolycone<ConeTypes::UniversalCone>;
0301 
0302 } // namespace VECGEOM_IMPL_NAMESPACE
0303 
0304 } // namespace vecgeom
0305 
0306 #include "VecGeom/volumes/SpecializedPolycone.h"
0307 
0308 #endif /* VECGEOM_VOLUMES_UNPLACEDPOLYCONE_H_ */