Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoParallelWorld.h
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
3 * All rights reserved. *
4 * *
5 * For the licensing terms see $ROOTSYS/LICENSE. *
6 * For the list of contributors see $ROOTSYS/README/CREDITS. *
7 *************************************************************************/
8
9// Authors: Andrei Gheata 30/06/14
10// Sandro Wenzel 01/09/24
11
12#ifndef ROOT_TGeoParallelWorld
13#define ROOT_TGeoParallelWorld
14
15#include "TNamed.h"
16#include "TGeoVoxelGrid.h"
17
18// forward declarations
19class TGeoManager;
21class TGeoVolume;
22
23class TGeoParallelWorld : public TNamed {
24
25public:
26 // internal enum letting choose between
27 // VoxelFinder or BVH-based algorithms
29
30 // a structure for safety evaluation (caching) purpose
31 // to be stored per 3D grid voxel
33 float min_safety{-1.f}; // the minimum safety from the mid-point of this voxel to any leaf bounding box
34 int idx_start{-1}; // the index into an external storage, where candidate bounding boxes to search for this voxel
35 // are stored (if -1) --> VoxelInfo not yet initialized
36 unsigned int num_candidates{0}; // the number of candidate bounding boxes to search
37 bool isInitialized() const { return idx_start >= 0; }
38 };
39
40protected:
41 TGeoManager *fGeoManager; // base geometry
42 TObjArray *fPaths; // array of paths
43 Bool_t fUseOverlaps; // Activated if user defined overlapping candidates
44 Bool_t fIsClosed; //! Closed flag
45 TGeoVolume *fVolume; //! helper volume
46 TGeoPhysicalNode *fLastState; //! Last PN touched
47 TObjArray *fPhysical; //! array of physical nodes
48
49 void *fBVH = nullptr; //! BVH helper structure for safety and navigation
51 nullptr; //! A regular 3D cache layer for fast point-based safety lookups
52 std::vector<unsigned int> fSafetyCandidateStore{}; //! stores bounding boxes serving a quick safety candidates (to be
53 //! used with the VoxelGrid and SafetyVoxelInfo)
54 void *fBoundingBoxes = nullptr; //! to keep the vector of primitive axis aligned bounding boxes
55 AccelerationMode fAccMode = AccelerationMode::kVoxelFinder; //! switch between different algorithm implementations
56
59
60public:
61 // constructors
63 : TNamed(),
64 fGeoManager(nullptr),
65 fPaths(nullptr),
68 fVolume(nullptr),
69 fLastState(nullptr),
70 fPhysical(nullptr)
71 {
72 }
73 TGeoParallelWorld(const char *name, TGeoManager *mgr);
74
75 // destructor
76 ~TGeoParallelWorld() override;
77 // API for adding components nodes
78 void AddNode(const char *path);
79 // Activate/deactivate overlap usage
80 void SetUseOverlaps(Bool_t flag) { fUseOverlaps = flag; }
82 void ResetOverlaps() const;
83 // Adding overlap candidates can highly improve performance.
84 void AddOverlap(TGeoVolume *vol, Bool_t activate = kTRUE);
85 void AddOverlap(const char *volname, Bool_t activate = kTRUE);
86 // The normal PW mode (without declaring overlaps) does detect them
88
89 // Closing a parallel geometry is mandatory
91 // Refresh structures in case of re-alignment
93
94 // ability to choose algorithm implementation; should be called before CloseGeometry
97
98 // BVH related functions for building, printing, checking
99 void BuildBVH();
100 void PrintBVH() const;
101 bool CheckBVH(void *, size_t) const;
102
103 // --- main navigation interfaces ----
104
105 // FindNode
107 {
108 switch (fAccMode) {
111 return FindNodeBVH(point);
112 // case AccelerationMode::kLoop : return FindNodeLoop(point);
113 }
114 return nullptr;
115 }
116
117 // main interface for Safety
118 Double_t Safety(Double_t point[3], Double_t safmax = 1.E30)
119 {
120 switch (fAccMode) {
121 case AccelerationMode::kVoxelFinder: return SafetyOrig(point, safmax);
123 return VoxelSafety(point, safmax);
124 // case AccelerationMode::kLoop : return SafetyLoop(point, safmax);
125 }
126 return 0;
127 }
128
129 // main interface for FindNextBoundary
130 TGeoPhysicalNode *FindNextBoundary(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30)
131 {
132 switch (fAccMode) {
133 case AccelerationMode::kVoxelFinder: return FindNextBoundaryOrig(point, dir, step, stepmax);
135 return FindNextBoundaryBVH(point, dir, step, stepmax);
136 // case AccelerationMode::kLoop : return FindNextBoundaryLoop(point, dir, step, stepmax);
137 }
138 return nullptr;
139 }
140
141 // Getters
143 Bool_t IsClosed() const { return fIsClosed; }
144 TGeoVolume *GetVolume() const { return fVolume; }
145
146 // Utilities
147 void CheckOverlaps(Double_t ovlp = 0.001); // default 10 microns
148 void Draw(Option_t *option) override;
149
150private:
151 // various implementations for FindNextBoundary
152 TGeoPhysicalNode *FindNextBoundaryLoop(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
153 TGeoPhysicalNode *FindNextBoundaryOrig(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
154 TGeoPhysicalNode *FindNextBoundaryBVH(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
155
156 // various implementations for FindNode
160
161 // various implementations for Safety
162 Double_t SafetyLoop(Double_t point[3], Double_t safmax = 1.E30);
163 Double_t SafetyBVH(Double_t point[3], Double_t safmax = 1.E30);
164 Double_t SafetyOrig(Double_t point[3], Double_t safmax = 1.E30);
165 Double_t VoxelSafety(Double_t point[3], Double_t safmax = 1.E30);
166
167 // helper functions related to local safety caching (3D voxel grid)
168
169 // Given a 3D point, returns the
170 // a) the min radius R such that there is at least one leaf bounding box fully enclosed
171 // in the sphere of radius R around point
172 // b) the set of leaf bounding boxes who partially lie within radius + margin
173
174 // ... using BVH
175 std::pair<double, double>
176 GetBVHSafetyCandidates(double point[3], std::vector<int> &candidates, double margin = 0.) const;
177 // .... same with a simpler, slower algorithm
178 std::pair<double, double>
179 GetLoopSafetyCandidates(double point[3], std::vector<int> &candidates, double margin = 0.) const;
180
182 void TestVoxelGrid(); // a debug method to play with the voxel grid
183
184 ClassDefOverride(TGeoParallelWorld, 3) // parallel world base class
185};
186
187#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
Base class for a flat parallel geometry.
TGeoManager * fGeoManager
Double_t SafetyBVH(Double_t point[3], Double_t safmax=1.E30)
Compute safety for the parallel world (using pure BVH traversal, mainly for debugging/fallback since ...
std::pair< double, double > GetBVHSafetyCandidates(double point[3], std::vector< int > &candidates, double margin=0.) const
Method to find potentially relevant candidate bounding boxes for safety calculation given a point.
void SetUseOverlaps(Bool_t flag)
Double_t Safety(Double_t point[3], Double_t safmax=1.E30)
TObjArray * fPhysical
Last PN touched.
TGeoVolume * GetVolume() const
TGeoPhysicalNode * FindNodeOrig(Double_t point[3])
Finds physical node containing the point (original version based on TGeoVoxelFinder)
Bool_t CloseGeometry()
The main geometry must be closed.
void AddNode(const char *path)
Add a node normally to this world. Overlapping nodes not allowed.
TGeoPhysicalNode * FindNextBoundary(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax=1.E30)
void ResetOverlaps() const
Reset overlapflag for all volumes in geometry.
std::vector< unsigned int > fSafetyCandidateStore
A regular 3D cache layer for fast point-based safety lookups.
TGeoManager * GetGeometry() const
TGeoPhysicalNode * FindNodeBVH(Double_t point[3])
Finds physical node containing the point.
Bool_t IsUsingOverlaps() const
void * fBoundingBoxes
stores bounding boxes serving a quick safety candidates (to be used with the VoxelGrid and SafetyVoxe...
TGeoPhysicalNode * FindNode(Double_t point[3])
TGeoPhysicalNode * FindNextBoundaryLoop(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax=1.E30)
Same functionality as TGeoNavigator::FindNextDaughterBoundary for the parallel world in a trivial loo...
TGeoVoxelGrid< SafetyVoxelInfo > * fSafetyVoxelCache
BVH helper structure for safety and navigation.
void SetAccelerationMode(AccelerationMode const &mode)
bool CheckBVH(void *, size_t) const
Check/validate the BVH acceleration structure.
~TGeoParallelWorld() override
Destructor.
TGeoVolume * fVolume
Closed flag.
Double_t SafetyLoop(Double_t point[3], Double_t safmax=1.E30)
Compute safety for the parallel world (trivial loop version for comparison/debugging)
Int_t PrintDetectedOverlaps() const
Print the overlaps which were detected during real tracking.
TGeoPhysicalNode * FindNextBoundaryBVH(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax=1.E30)
Same functionality as TGeoNavigator::FindNextDaughterBoundary for the parallel world.
void CheckOverlaps(Double_t ovlp=0.001)
Check overlaps within a tolerance value.
std::pair< double, double > GetLoopSafetyCandidates(double point[3], std::vector< int > &candidates, double margin=0.) const
Method to find potentially relevant candidate bounding boxes for safety calculation given a point.
TGeoPhysicalNode * fLastState
helper volume
Double_t SafetyOrig(Double_t point[3], Double_t safmax=1.E30)
Compute safety for the parallel world (original version based on TGeoVoxelFinder)
void AddOverlap(TGeoVolume *vol, Bool_t activate=kTRUE)
To use this optimization, the user should declare the full list of volumes which may overlap with any...
void RefreshPhysicalNodes()
Refresh the node pointers and re-voxelize.
TGeoPhysicalNode * FindNodeLoop(Double_t point[3])
Finds physical node containing the point using simple algorithm (for debugging)
TGeoParallelWorld & operator=(const TGeoParallelWorld &)=delete
AccelerationMode fAccMode
to keep the vector of primitive axis aligned bounding boxes
TGeoParallelWorld(const TGeoParallelWorld &)=delete
switch between different algorithm implementations
AccelerationMode const & GetAccelerationMode() const
void InitSafetyVoxel(TGeoVoxelGridIndex const &)
Method to initialize the safety voxel at a specific 3D voxel (grid) index.
void * fBVH
array of physical nodes
void BuildBVH()
Build the BVH acceleration structure.
Double_t VoxelSafety(Double_t point[3], Double_t safmax=1.E30)
Compute safety for the parallel world used BVH structure with addiditional on-the-fly 3D grid/voxel c...
TGeoPhysicalNode * FindNextBoundaryOrig(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax=1.E30)
Same functionality as TGeoNavigator::FindNextDaughterBoundary for the parallel world.
Bool_t IsClosed() const
void PrintBVH() const
Prints the BVH.
Physical nodes are the actual 'touchable' objects in the geometry, representing a path of positioned ...
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
A finite 3D grid structure, mapping/binning arbitrary 3D cartesian points onto discrete "voxels".
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
An array of TObjects.
Definition TObjArray.h:31
th1 Draw()