Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoChecker.h
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Andrei Gheata 01/11/01
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGeoChecker
13#define ROOT_TGeoChecker
14
15#include "TVirtualGeoChecker.h"
17#include <vector>
18#include <unordered_map>
19#include <shared_mutex>
20
21// forward declarations
22class TTree;
23class TGeoShape;
24class TGeoVolume;
25class TGeoVoxelFinder;
26class TGeoNode;
27class TGeoManager;
28class TGeoMatrix;
29class TGeoOverlap;
30class TBuffer3D;
31class TH2F;
32class TStopwatch;
33
34///////////////////////////////////////////////////////////////////////////
35// TGeoChecker - A simple checker generating random points inside a //
36// geometry. Generates a tree of points on the surfaces corresponding //
37// to the safety of each generated point //
38// //
39///////////////////////////////////////////////////////////////////////////
40
42
43public:
44 /// @brief Simple internal structure keeping a cache of mesh points per shape
46 Int_t fNPoints{0}; ///< number of 3D points
47 std::vector<Double_t> fPoints; ///< points components (size = 3*fNPoints)
48 };
49
50 /// @brief Policy stamp: when this changes, cached point *values* may be wrong -> clear.
55
56private:
57 // data members
58 TGeoManager *fGeoManager; // pointer to geometry manager
59 TGeoVolume *fVsafe; // volume to which a safety sphere node was added
60 Bool_t fFullCheck; // Full overlap checking
61 Double_t *fVal1; //! Array of number of crossings per volume.
62 Double_t *fVal2; //! Array of timing per volume.
63 Bool_t *fFlags; //! Array of flags per volume.
64 TStopwatch *fTimer; //! Timer
65 TGeoNode *fSelectedNode; //! Selected node for overlap checking
66 Int_t fNchecks; //! Number of checks for current volume
67
68 mutable std::shared_mutex fMeshCacheMutex;
69 std::unordered_map<const TGeoShape *, MeshPointsEntry> fMeshPointsCache; //! Internal map shape->mesh points
70 MeshPolicyStamp fMeshPolicyStamp; //! policy stamp for points cache invalidation
71
72 // methods
73 void CleanPoints(Double_t *points, Int_t &numPoints) const;
75 const MeshPointsEntry &GetMeshPoints(const TGeoShape *s) const;
79 inline bool PolicyChanged(const MeshPolicyStamp &a, const MeshPolicyStamp &b) const
80 {
81 return a.fNmeshPoints != b.fNmeshPoints || a.fNsegments != b.fNsegments;
82 }
86
87public:
88 // constructors
91 // destructor
92 ~TGeoChecker() override;
93 // methods
94 void BuildMeshPointsCache(const std::vector<TGeoOverlapCandidate> &candidates) override;
95 void CheckBoundaryErrors(Int_t ntracks = 1000000, Double_t radius = -1.) override;
96 void CheckBoundaryReference(Int_t icheck = -1) override;
98 const Double_t *vertex = nullptr) override;
100 void CheckOverlapsBySampling(const TGeoVolume *vol, Double_t ovlp = 0.1, Int_t npoints = 1000000) const override;
101 void
102 CheckPoint(Double_t x = 0, Double_t y = 0, Double_t z = 0, Option_t *option = "", Double_t safety = 0.) override;
103 void CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option) override;
105 Bool_t ComputeOverlap(const TGeoOverlapCandidate &c, TGeoOverlapResult &out) const override;
107 std::vector<TGeoOverlapCandidate> &out) override;
108 TH2F *LegoPlot(Int_t ntheta = 60, Double_t themin = 0., Double_t themax = 180., Int_t nphi = 90,
109 Double_t phimin = 0., Double_t phimax = 360., Double_t rmin = 0., Double_t rmax = 9999999,
110 Option_t *option = "") override;
111 void MaterializeOverlap(const TGeoOverlapResult &r) override;
112 void PrintOverlaps() const override;
113 void RandomPoints(TGeoVolume *vol, Int_t npoints, Option_t *option) override;
115 Bool_t check_norm = kFALSE) override;
116 void OpProgress(const char *opname, Long64_t current, Long64_t size, TStopwatch *watch = nullptr,
117 Bool_t last = kFALSE, Bool_t refresh = kFALSE, const char *msg = "") override;
118 inline void PushCandidate(std::vector<TGeoOverlapCandidate> &out, const TString &name, TGeoVolume *vol1,
120 Double_t ovlp) const;
121 TGeoNode *SamplePoints(Int_t npoints, Double_t &dist, Double_t epsil, const char *g3path) override;
126 Int_t &dim, Double_t *enpoint = nullptr) const;
127 void SetSelectedNode(TGeoNode *node) override { fSelectedNode = node; }
128 void Test(Int_t npoints, Option_t *option) override;
129 void TestOverlaps(const char *path) override;
130 Bool_t TestVoxels(TGeoVolume *vol, Int_t npoints = 1000000) override;
131 Double_t Weight(Double_t precision = 0.01, Option_t *option = "v") override;
132
133 ClassDefOverride(TGeoChecker, 3) // a simple geometry checker
134};
135
136#endif
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
char name[80]
Definition TGX11.cxx:110
Generic 3D primitive description class.
Definition TBuffer3D.h:18
Geometry checking package.
Definition TGeoChecker.h:41
Int_t FillMeshPoints(TBuffer3D &buff, const TGeoShape *shape, const TGeoShape *&lastShape, Int_t &cachedN, Int_t nMeshPoints, Double_t *&points) const
Int_t PropagateInGeom(Double_t *, Double_t *)
Propagate from START along DIR from boundary to boundary until exiting geometry.
Int_t fNchecks
Selected node for overlap checking.
Definition TGeoChecker.h:66
Bool_t * fFlags
Array of timing per volume.
Definition TGeoChecker.h:63
TStopwatch * fTimer
Array of flags per volume.
Definition TGeoChecker.h:64
void CheckShape(TGeoShape *shape, Int_t testNo, Int_t nsamples, Option_t *option) override
Test for shape navigation methods.
TGeoVolume * fVsafe
Definition TGeoChecker.h:59
std::unordered_map< const TGeoShape *, MeshPointsEntry > fMeshPointsCache
Definition TGeoChecker.h:69
TGeoChecker()
Default constructor.
void OpProgress(const char *opname, Long64_t current, Long64_t size, TStopwatch *watch=nullptr, Bool_t last=kFALSE, Bool_t refresh=kFALSE, const char *msg="") override
Print current operation progress.
TGeoNode * SamplePoints(Int_t npoints, Double_t &dist, Double_t epsil, const char *g3path) override
shoot npoints randomly in a box of 1E-5 around current point.
void CheckPoint(Double_t x=0, Double_t y=0, Double_t z=0, Option_t *option="", Double_t safety=0.) override
Draw point (x,y,z) over the picture of the daughters of the volume containing this point.
Double_t Weight(Double_t precision=0.01, Option_t *option="v") override
Estimate weight of top level volume with a precision SIGMA(W)/W better than PRECISION.
void ShapeNormal(TGeoShape *shape, Int_t nsamples, Option_t *option)
Check of validity of the normal for a given shape.
MeshPolicyStamp fMeshPolicyStamp
Internal map shape->mesh points.
Definition TGeoChecker.h:70
void CheckBoundaryReference(Int_t icheck=-1) override
Check the boundary errors reference file created by CheckBoundaryErrors method.
void MaterializeOverlap(const TGeoOverlapResult &r) override
Materialize a TGeoOverlapResult into a TGeoOverlap.
Double_t * fVal2
Array of number of crossings per volume.
Definition TGeoChecker.h:62
const MeshPointsEntry & GetMeshPoints(const TGeoShape *s) const
Bool_t TestVoxels(TGeoVolume *vol, Int_t npoints=1000000) override
Returns optimal voxelization type for volume vol.
void CheckOverlapsBySampling(const TGeoVolume *vol, Double_t ovlp=0.1, Int_t npoints=1000000) const override
Check illegal overlaps for volume VOL within a limit OVLP by sampling npoints inside the volume shape...
void BuildMeshPointsCache(const std::vector< TGeoOverlapCandidate > &candidates) override
TGeoManager * fGeoManager
Definition TGeoChecker.h:58
void ShapeDistances(TGeoShape *shape, Int_t nsamples, Option_t *option)
Test TGeoShape::DistFromInside/Outside.
Int_t NChecksPerVolume(TGeoVolume *vol)
Compute number of overlaps combinations to check per volume.
void ShapeSafety(TGeoShape *shape, Int_t nsamples, Option_t *option)
Check of validity of safe distance for a given shape.
TH2F * LegoPlot(Int_t ntheta=60, Double_t themin=0., Double_t themax=180., Int_t nphi=90, Double_t phimin=0., Double_t phimax=360., Double_t rmin=0., Double_t rmax=9999999, Option_t *option="") override
Generate a lego plot fot the top volume, according to option.
void CheckGeometry(Int_t nrays, Double_t startx, Double_t starty, Double_t startz) const override
Shoot nrays with random directions from starting point (startx, starty, startz) in the reference fram...
void Score(TGeoVolume *, Int_t, Double_t)
Score a hit for VOL.
Double_t * ShootRay(Double_t *start, Double_t dirx, Double_t diry, Double_t dirz, Double_t *array, Int_t &nelem, Int_t &dim, Double_t *enpoint=nullptr) const
Shoot one ray from start point with direction (dirx,diry,dirz).
void CleanPoints(Double_t *points, Int_t &numPoints) const
policy stamp for points cache invalidation
bool PolicyChanged(const MeshPolicyStamp &a, const MeshPolicyStamp &b) const
Definition TGeoChecker.h:79
void PrintOverlaps() const override
Print the current list of overlaps held by the manager class.
TGeoNode * fSelectedNode
Timer.
Definition TGeoChecker.h:65
void CheckGeometryFull(Bool_t checkoverlaps=kTRUE, Bool_t checkcrossings=kTRUE, Int_t nrays=10000, const Double_t *vertex=nullptr) override
Geometry checking.
void CheckBoundaryErrors(Int_t ntracks=1000000, Double_t radius=-1.) override
Check pushes and pulls needed to cross the next boundary with respect to the position given by FindNe...
~TGeoChecker() override
Destructor.
Bool_t ComputeOverlap(const TGeoOverlapCandidate &c, TGeoOverlapResult &out) const override
Compute overlap/extrusion for given candidate using mesh points of the shapes.
TGeoChecker::MeshPolicyStamp CurrentMeshPolicyStamp() const
Create a policy stamp for overlap checking.
void TestOverlaps(const char *path) override
Geometry overlap checker based on sampling.
void Test(Int_t npoints, Option_t *option) override
Check time of finding "Where am I" for n points.
std::shared_mutex fMeshCacheMutex
Number of checks for current volume.
Definition TGeoChecker.h:68
Int_t EnumerateOverlapCandidates(const TGeoVolume *vol, Double_t ovlp, Option_t *option, std::vector< TGeoOverlapCandidate > &out) override
Stage1: Enumerate all overlap candidates for volume VOL within a limit OVLP.
Double_t TimingPerVolume(TGeoVolume *)
Compute timing per "FindNextBoundary" + "Safety" call.
void RandomRays(Int_t nrays, Double_t startx, Double_t starty, Double_t startz, const char *target_vol=nullptr, Bool_t check_norm=kFALSE) override
Randomly shoot nrays from point (startx,starty,startz) and plot intersections with surfaces for curre...
Double_t * fVal1
Definition TGeoChecker.h:61
void SetSelectedNode(TGeoNode *node) override
Bool_t fFullCheck
Definition TGeoChecker.h:60
void RandomPoints(TGeoVolume *vol, Int_t npoints, Option_t *option) override
Draw random points in the bounding box of a volume.
Double_t CheckVoxels(TGeoVolume *vol, TGeoVoxelFinder *voxels, Double_t *xyz, Int_t npoints)
count voxel timing
void PushCandidate(std::vector< TGeoOverlapCandidate > &out, const TString &name, TGeoVolume *vol1, TGeoVolume *vol2, const TGeoMatrix *mat1, const TGeoMatrix *mat2, Bool_t isovlp, Double_t ovlp) const
Helper to fill candidates list.
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
Geometrical transformation package.
Definition TGeoMatrix.h:39
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
Base class describing geometry overlaps.
Definition TGeoOverlap.h:37
Base abstract class for all shapes.
Definition TGeoShape.h:25
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
Finder class handling voxels.
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:345
Stopwatch class.
Definition TStopwatch.h:28
Basic string class.
Definition TString.h:138
A TTree represents a columnar dataset.
Definition TTree.h:89
Abstract class for geometry checkers.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Simple internal structure keeping a cache of mesh points per shape.
Definition TGeoChecker.h:45
Int_t fNPoints
number of 3D points
Definition TGeoChecker.h:46
std::vector< Double_t > fPoints
points components (size = 3*fNPoints)
Definition TGeoChecker.h:47
Policy stamp: when this changes, cached point values may be wrong -> clear.
Definition TGeoChecker.h:51