Back to home page

EIC code displayed by LXR

 
 

    


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

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