Warning, file /include/root/TGeoParallelWorld.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoParallelWorld
0013 #define ROOT_TGeoParallelWorld
0014
0015 #include "TNamed.h"
0016 #include "TGeoVoxelGrid.h"
0017
0018
0019 class TGeoManager;
0020 class TGeoPhysicalNode;
0021 class TGeoVolume;
0022
0023 class TGeoParallelWorld : public TNamed {
0024
0025 public:
0026
0027
0028 enum class AccelerationMode { kVoxelFinder, kBVH };
0029
0030
0031
0032 struct SafetyVoxelInfo {
0033 float min_safety{-1.f};
0034 int idx_start{-1};
0035
0036 unsigned int num_candidates{0};
0037 bool isInitialized() const { return idx_start >= 0; }
0038 };
0039
0040 protected:
0041 TGeoManager *fGeoManager;
0042 TObjArray *fPaths;
0043 Bool_t fUseOverlaps;
0044 Bool_t fIsClosed;
0045 TGeoVolume *fVolume;
0046 TGeoPhysicalNode *fLastState;
0047 TObjArray *fPhysical;
0048
0049 void *fBVH = nullptr;
0050 TGeoVoxelGrid<SafetyVoxelInfo> *fSafetyVoxelCache =
0051 nullptr;
0052 std::vector<unsigned int> fSafetyCandidateStore{};
0053
0054 void *fBoundingBoxes = nullptr;
0055 AccelerationMode fAccMode = AccelerationMode::kVoxelFinder;
0056
0057 TGeoParallelWorld(const TGeoParallelWorld &) = delete;
0058 TGeoParallelWorld &operator=(const TGeoParallelWorld &) = delete;
0059
0060 public:
0061
0062 TGeoParallelWorld()
0063 : TNamed(),
0064 fGeoManager(nullptr),
0065 fPaths(nullptr),
0066 fUseOverlaps(kFALSE),
0067 fIsClosed(kFALSE),
0068 fVolume(nullptr),
0069 fLastState(nullptr),
0070 fPhysical(nullptr)
0071 {
0072 }
0073 TGeoParallelWorld(const char *name, TGeoManager *mgr);
0074
0075
0076 ~TGeoParallelWorld() override;
0077
0078 void AddNode(const char *path);
0079
0080 void SetUseOverlaps(Bool_t flag) { fUseOverlaps = flag; }
0081 Bool_t IsUsingOverlaps() const { return fUseOverlaps; }
0082 void ResetOverlaps() const;
0083
0084 void AddOverlap(TGeoVolume *vol, Bool_t activate = kTRUE);
0085 void AddOverlap(const char *volname, Bool_t activate = kTRUE);
0086
0087 Int_t PrintDetectedOverlaps() const;
0088
0089
0090 Bool_t CloseGeometry();
0091
0092 void RefreshPhysicalNodes();
0093
0094
0095 void SetAccelerationMode(AccelerationMode const &mode) { fAccMode = mode; }
0096 AccelerationMode const &GetAccelerationMode() const { return fAccMode; }
0097
0098
0099 void BuildBVH();
0100 void PrintBVH() const;
0101 bool CheckBVH(void *, size_t) const;
0102
0103
0104
0105
0106 TGeoPhysicalNode *FindNode(Double_t point[3])
0107 {
0108 switch (fAccMode) {
0109 case AccelerationMode::kVoxelFinder: return FindNodeOrig(point);
0110 case AccelerationMode::kBVH:
0111 return FindNodeBVH(point);
0112
0113 }
0114 return nullptr;
0115 }
0116
0117
0118 Double_t Safety(Double_t point[3], Double_t safmax = 1.E30)
0119 {
0120 switch (fAccMode) {
0121 case AccelerationMode::kVoxelFinder: return SafetyOrig(point, safmax);
0122 case AccelerationMode::kBVH:
0123 return VoxelSafety(point, safmax);
0124
0125 }
0126 return 0;
0127 }
0128
0129
0130 TGeoPhysicalNode *FindNextBoundary(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30)
0131 {
0132 switch (fAccMode) {
0133 case AccelerationMode::kVoxelFinder: return FindNextBoundaryOrig(point, dir, step, stepmax);
0134 case AccelerationMode::kBVH:
0135 return FindNextBoundaryBVH(point, dir, step, stepmax);
0136
0137 }
0138 return nullptr;
0139 }
0140
0141
0142 TGeoManager *GetGeometry() const { return fGeoManager; }
0143 Bool_t IsClosed() const { return fIsClosed; }
0144 TGeoVolume *GetVolume() const { return fVolume; }
0145
0146
0147 void CheckOverlaps(Double_t ovlp = 0.001);
0148 void Draw(Option_t *option) override;
0149
0150 private:
0151
0152 TGeoPhysicalNode *FindNextBoundaryLoop(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
0153 TGeoPhysicalNode *FindNextBoundaryOrig(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
0154 TGeoPhysicalNode *FindNextBoundaryBVH(Double_t point[3], Double_t dir[3], Double_t &step, Double_t stepmax = 1.E30);
0155
0156
0157 TGeoPhysicalNode *FindNodeLoop(Double_t point[3]);
0158 TGeoPhysicalNode *FindNodeOrig(Double_t point[3]);
0159 TGeoPhysicalNode *FindNodeBVH(Double_t point[3]);
0160
0161
0162 Double_t SafetyLoop(Double_t point[3], Double_t safmax = 1.E30);
0163 Double_t SafetyBVH(Double_t point[3], Double_t safmax = 1.E30);
0164 Double_t SafetyOrig(Double_t point[3], Double_t safmax = 1.E30);
0165 Double_t VoxelSafety(Double_t point[3], Double_t safmax = 1.E30);
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175 std::pair<double, double>
0176 GetBVHSafetyCandidates(double point[3], std::vector<int> &candidates, double margin = 0.) const;
0177
0178 std::pair<double, double>
0179 GetLoopSafetyCandidates(double point[3], std::vector<int> &candidates, double margin = 0.) const;
0180
0181 void InitSafetyVoxel(TGeoVoxelGridIndex const &);
0182 void TestVoxelGrid();
0183
0184 ClassDefOverride(TGeoParallelWorld, 3)
0185 };
0186
0187 #endif