File indexing completed on 2026-09-28 09:29:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoChecker
0013 #define ROOT_TGeoChecker
0014
0015 #include "TVirtualGeoChecker.h"
0016 #include "TGeoOverlapCandidate.h"
0017 #include <vector>
0018 #include <unordered_map>
0019 #include <shared_mutex>
0020
0021
0022 class TTree;
0023 class TGeoShape;
0024 class TGeoVolume;
0025 class TGeoVoxelFinder;
0026 class TGeoNode;
0027 class TGeoManager;
0028 class TGeoMatrix;
0029 class TGeoOverlap;
0030 class TBuffer3D;
0031 class TH2F;
0032 class TStopwatch;
0033
0034
0035
0036
0037
0038
0039
0040
0041 class TGeoChecker : public TVirtualGeoChecker {
0042
0043 public:
0044
0045 struct MeshPointsEntry {
0046 Int_t fNPoints{0};
0047 std::vector<Double_t> fPoints;
0048 };
0049
0050
0051 struct MeshPolicyStamp {
0052 Int_t fNmeshPoints{-1};
0053 Int_t fNsegments{-1};
0054 };
0055
0056 private:
0057
0058 TGeoManager *fGeoManager;
0059 TGeoVolume *fVsafe;
0060 Bool_t fFullCheck;
0061 Double_t *fVal1;
0062 Double_t *fVal2;
0063 Bool_t *fFlags;
0064 TStopwatch *fTimer;
0065 TGeoNode *fSelectedNode;
0066 Int_t fNchecks;
0067
0068 mutable std::shared_mutex fMeshCacheMutex;
0069 std::unordered_map<const TGeoShape *, MeshPointsEntry> fMeshPointsCache;
0070 MeshPolicyStamp fMeshPolicyStamp;
0071
0072
0073 void CleanPoints(Double_t *points, Int_t &numPoints) const;
0074 TGeoChecker::MeshPolicyStamp CurrentMeshPolicyStamp() const;
0075 const MeshPointsEntry &GetMeshPoints(const TGeoShape *s) const;
0076 Int_t FillMeshPoints(TBuffer3D &buff, const TGeoShape *shape, const TGeoShape *&lastShape, Int_t &cachedN,
0077 Int_t nMeshPoints, Double_t *&points) const;
0078 Int_t NChecksPerVolume(TGeoVolume *vol);
0079 inline bool PolicyChanged(const MeshPolicyStamp &a, const MeshPolicyStamp &b) const
0080 {
0081 return a.fNmeshPoints != b.fNmeshPoints || a.fNsegments != b.fNsegments;
0082 }
0083 Int_t PropagateInGeom(Double_t *, Double_t *);
0084 void Score(TGeoVolume *, Int_t, Double_t);
0085 Double_t TimingPerVolume(TGeoVolume *);
0086
0087 public:
0088
0089 TGeoChecker();
0090 TGeoChecker(TGeoManager *geom);
0091
0092 ~TGeoChecker() override;
0093
0094 void BuildMeshPointsCache(const std::vector<TGeoOverlapCandidate> &candidates) override;
0095 void CheckBoundaryErrors(Int_t ntracks = 1000000, Double_t radius = -1.) override;
0096 void CheckBoundaryReference(Int_t icheck = -1) override;
0097 void CheckGeometryFull(Bool_t checkoverlaps = kTRUE, Bool_t checkcrossings = kTRUE, Int_t nrays = 10000,
0098 const Double_t *vertex = nullptr) override;
0099 void CheckGeometry(Int_t nrays, Double_t startx, Double_t starty, Double_t startz) const override;
0100 void CheckOverlapsBySampling(const TGeoVolume *vol, Double_t ovlp = 0.1, Int_t npoints = 1000000) const override;
0101 void
0102 CheckPoint(Double_t x = 0, Double_t y = 0, Double_t z = 0, Option_t *option = "", Double_t safety = 0.) override;
0103 void CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option) override;
0104 Double_t CheckVoxels(TGeoVolume *vol, TGeoVoxelFinder *voxels, Double_t *xyz, Int_t npoints);
0105 Bool_t ComputeOverlap(const TGeoOverlapCandidate &c, TGeoOverlapResult &out) const override;
0106 Int_t EnumerateOverlapCandidates(const TGeoVolume *vol, Double_t ovlp, Option_t *option,
0107 std::vector<TGeoOverlapCandidate> &out) override;
0108 TH2F *LegoPlot(Int_t ntheta = 60, Double_t themin = 0., Double_t themax = 180., Int_t nphi = 90,
0109 Double_t phimin = 0., Double_t phimax = 360., Double_t rmin = 0., Double_t rmax = 9999999,
0110 Option_t *option = "") override;
0111 void MaterializeOverlap(const TGeoOverlapResult &r) override;
0112 void PrintOverlaps() const override;
0113 void RandomPoints(TGeoVolume *vol, Int_t npoints, Option_t *option) override;
0114 void RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz, const char *target_vol = nullptr,
0115 Bool_t check_norm = kFALSE) override;
0116 void OpProgress(const char *opname, Long64_t current, Long64_t size, TStopwatch *watch = nullptr,
0117 Bool_t last = kFALSE, Bool_t refresh = kFALSE, const char *msg = "") override;
0118 inline void PushCandidate(std::vector<TGeoOverlapCandidate> &out, const TString &name, TGeoVolume *vol1,
0119 TGeoVolume *vol2, const TGeoMatrix *mat1, const TGeoMatrix *mat2, Bool_t isovlp,
0120 Double_t ovlp) const;
0121 TGeoNode *SamplePoints(Int_t npoints, Double_t &dist, Double_t epsil, const char *g3path) override;
0122 void ShapeDistances(TGeoShape *shape, Int_t nsamples, Option_t *option);
0123 void ShapeSafety(TGeoShape *shape, Int_t nsamples, Option_t *option);
0124 void ShapeNormal(TGeoShape *shape, Int_t nsamples, Option_t *option);
0125 Double_t *ShootRay(Double_t *start, Double_t dirx, Double_t diry, Double_t dirz, Double_t *array, Int_t &nelem,
0126 Int_t &dim, Double_t *enpoint = nullptr) const;
0127 void SetSelectedNode(TGeoNode *node) override { fSelectedNode = node; }
0128 void Test(Int_t npoints, Option_t *option) override;
0129 void TestOverlaps(const char *path) override;
0130 Bool_t TestVoxels(TGeoVolume *vol, Int_t npoints = 1000000) override;
0131 Double_t Weight(Double_t precision = 0.01, Option_t *option = "v") override;
0132
0133 ClassDefOverride(TGeoChecker, 3)
0134 };
0135
0136 #endif