File indexing completed on 2026-05-05 08:51:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGeoNavigator
0013 #define ROOT_TGeoNavigator
0014
0015 #include "TObject.h"
0016
0017 #include "TGeoCache.h"
0018
0019 #include <cmath>
0020
0021
0022
0023
0024
0025
0026
0027
0028 class TGeoManager;
0029 class TGeoNode;
0030 class TGeoVolume;
0031 class TGeoMatrix;
0032 class TGeoHMatrix;
0033
0034 class TGeoNavigator : public TObject {
0035
0036 protected:
0037 TGeoNavigator(const TGeoNavigator &) = delete;
0038 TGeoNavigator &operator=(const TGeoNavigator &) = delete;
0039 TGeoNode *FindInCluster(Int_t *cluster, Int_t nc);
0040 Int_t GetTouchedCluster(Int_t start, Double_t *point, Int_t *check_list, Int_t ncheck, Int_t *result);
0041 TGeoNode *CrossDivisionCell();
0042 void SafetyOverlaps();
0043
0044 private:
0045 Double_t fStep;
0046 Double_t fSafety;
0047 Double_t fLastSafety;
0048 Double_t fNormal[3];
0049 Double_t fCldir[3];
0050 Double_t fCldirChecked[3];
0051 Double_t fPoint[3];
0052 Double_t fDirection[3];
0053 Double_t fLastPoint[3];
0054 Double_t fLastPWSaftyPnt[3];
0055 Double_t fLastPWSafety{-1};
0056 Int_t fThreadId;
0057 Int_t fLevel;
0058 Int_t fNmany;
0059 Int_t fNextDaughterIndex;
0060 Int_t fOverlapSize;
0061 Int_t fOverlapMark;
0062 Int_t *fOverlapClusters;
0063 Bool_t fSearchOverlaps;
0064 Bool_t fCurrentOverlapping;
0065 Bool_t fStartSafe;
0066 Bool_t fIsEntering;
0067 Bool_t fIsExiting;
0068 Bool_t fIsStepEntering;
0069 Bool_t fIsStepExiting;
0070 Bool_t fIsOutside;
0071 Bool_t fIsOnBoundary;
0072 Bool_t fIsSameLocation;
0073 Bool_t fIsNullStep;
0074 TGeoManager *fGeometry;
0075 TGeoNodeCache *fCache;
0076 TGeoVolume *fCurrentVolume;
0077 TGeoNode *fCurrentNode;
0078 TGeoNode *fTopNode;
0079 TGeoNode *fLastNode;
0080 TGeoNode *fNextNode;
0081 TGeoNode *fForcedNode;
0082 TGeoCacheState *fBackupState;
0083 TGeoHMatrix *fCurrentMatrix;
0084 TGeoHMatrix *fGlobalMatrix;
0085 TGeoHMatrix *fDivMatrix;
0086 TString fPath;
0087
0088 static Bool_t fgUsePWSafetyCaching;
0089
0090 public:
0091 TGeoNavigator();
0092 TGeoNavigator(TGeoManager *geom);
0093 ~TGeoNavigator() override;
0094
0095 void BuildCache(Bool_t dummy = kFALSE, Bool_t nodeid = kFALSE);
0096 Bool_t cd(const char *path = "");
0097 Bool_t CheckPath(const char *path) const;
0098 void CdNode(Int_t nodeid);
0099 void CdDown(Int_t index);
0100 void CdDown(TGeoNode *node);
0101 void CdUp();
0102 void CdTop();
0103 void CdNext();
0104 void GetBranchNames(Int_t *names) const;
0105 void GetBranchNumbers(Int_t *copyNumbers, Int_t *volumeNumbers) const;
0106 void GetBranchOnlys(Int_t *isonly) const;
0107 Int_t GetNmany() const { return fNmany; }
0108
0109 TGeoNode *CrossBoundaryAndLocate(Bool_t downwards, TGeoNode *skipnode);
0110 TGeoNode *FindNextBoundary(Double_t stepmax = TGeoShape::Big(), const char *path = "", Bool_t frombdr = kFALSE);
0111 TGeoNode *FindNextDaughterBoundary(Double_t *point, Double_t *dir, Int_t &idaughter, Bool_t compmatrix = kFALSE);
0112 TGeoNode *FindNextBoundaryAndStep(Double_t stepmax = TGeoShape::Big(), Bool_t compsafe = kFALSE);
0113 TGeoNode *FindNode(Bool_t safe_start = kTRUE);
0114 TGeoNode *FindNode(Double_t x, Double_t y, Double_t z);
0115 Double_t *FindNormal(Bool_t forward = kTRUE);
0116 Double_t *FindNormalFast();
0117 TGeoNode *InitTrack(const Double_t *point, const Double_t *dir);
0118 TGeoNode *InitTrack(Double_t x, Double_t y, Double_t z, Double_t nx, Double_t ny, Double_t nz);
0119 void ResetState();
0120 void ResetAll();
0121 Double_t Safety(Bool_t inside = kFALSE);
0122 TGeoNode *SearchNode(Bool_t downwards = kFALSE, const TGeoNode *skipnode = nullptr);
0123 TGeoNode *Step(Bool_t is_geom = kTRUE, Bool_t cross = kTRUE);
0124 const Double_t *GetLastPoint() const { return fLastPoint; }
0125 Int_t GetVirtualLevel();
0126 Bool_t GotoSafeLevel();
0127 Int_t GetSafeLevel() const;
0128 Double_t GetSafeDistance() const { return fSafety; }
0129 Double_t GetLastSafety() const { return fLastSafety; }
0130 Double_t GetStep() const { return fStep; }
0131 Int_t GetThreadId() const { return fThreadId; }
0132 void InspectState() const;
0133 Bool_t IsSafeStep(Double_t proposed, Double_t &newsafety) const;
0134 Bool_t IsSameLocation(Double_t x, Double_t y, Double_t z, Bool_t change = kFALSE);
0135 Bool_t IsSameLocation() const { return fIsSameLocation; }
0136 Bool_t IsSamePoint(Double_t x, Double_t y, Double_t z) const;
0137 Bool_t IsStartSafe() const { return fStartSafe; }
0138 void SetStartSafe(Bool_t flag = kTRUE) { fStartSafe = flag; }
0139 void SetStep(Double_t step) { fStep = step; }
0140 Bool_t IsCheckingOverlaps() const { return fSearchOverlaps; }
0141 Bool_t IsCurrentOverlapping() const { return fCurrentOverlapping; }
0142 Bool_t IsEntering() const { return fIsEntering; }
0143 Bool_t IsExiting() const { return fIsExiting; }
0144 Bool_t IsStepEntering() const { return fIsStepEntering; }
0145 Bool_t IsStepExiting() const { return fIsStepExiting; }
0146 Bool_t IsOutside() const { return fIsOutside; }
0147 Bool_t IsOnBoundary() const { return fIsOnBoundary; }
0148 Bool_t IsNullStep() const { return fIsNullStep; }
0149 void SetCheckingOverlaps(Bool_t flag = kTRUE) { fSearchOverlaps = flag; }
0150 void SetOutside(Bool_t flag = kTRUE) { fIsOutside = flag; }
0151
0152 void DoBackupState();
0153 void DoRestoreState();
0154 Int_t GetNodeId() const { return fCache->GetNodeId(); }
0155 Int_t GetNextDaughterIndex() const { return fNextDaughterIndex; }
0156 TGeoNode *GetNextNode() const { return fNextNode; }
0157 TGeoNode *GetMother(Int_t up = 1) const { return fCache->GetMother(up); }
0158 TGeoHMatrix *GetMotherMatrix(Int_t up = 1) const { return fCache->GetMotherMatrix(up); }
0159 TGeoHMatrix *GetHMatrix();
0160 TGeoHMatrix *GetCurrentMatrix() const { return fCache->GetCurrentMatrix(); }
0161 TGeoNode *GetCurrentNode() const { return fCurrentNode; }
0162 Int_t GetCurrentNodeId() const { return fCache->GetCurrentNodeId(); }
0163 const Double_t *GetCurrentPoint() const { return fPoint; }
0164 const Double_t *GetCurrentDirection() const { return fDirection; }
0165 TGeoVolume *GetCurrentVolume() const { return fCurrentNode->GetVolume(); }
0166 const Double_t *GetCldirChecked() const { return fCldirChecked; }
0167 const Double_t *GetCldir() const { return fCldir; }
0168 TGeoHMatrix *GetDivMatrix() const { return fDivMatrix; }
0169
0170 const Double_t *GetNormal() const { return fNormal; }
0171 Int_t GetLevel() const { return fLevel; }
0172 const char *GetPath() const;
0173 Int_t GetStackLevel() const { return fCache->GetStackLevel(); }
0174 void SetCurrentPoint(const Double_t *point) { memcpy(fPoint, point, 3 * sizeof(Double_t)); }
0175 void SetCurrentPoint(Double_t x, Double_t y, Double_t z)
0176 {
0177 fPoint[0] = x;
0178 fPoint[1] = y;
0179 fPoint[2] = z;
0180 }
0181 void SetLastPoint(Double_t x, Double_t y, Double_t z)
0182 {
0183 fLastPoint[0] = x;
0184 fLastPoint[1] = y;
0185 fLastPoint[2] = z;
0186 }
0187 void SetCurrentDirection(const Double_t *dir) { memcpy(fDirection, dir, 3 * sizeof(Double_t)); }
0188 void SetCurrentDirection(Double_t nx, Double_t ny, Double_t nz)
0189 {
0190 fDirection[0] = nx;
0191 fDirection[1] = ny;
0192 fDirection[2] = nz;
0193 }
0194
0195 void SetCldirChecked(Double_t *dir) { memcpy(fCldirChecked, dir, 3 * sizeof(Double_t)); }
0196 void SetLastSafetyForPoint(Double_t safe, const Double_t *point)
0197 {
0198 fLastSafety = safe;
0199 memcpy(fLastPoint, point, 3 * sizeof(Double_t));
0200 }
0201 void SetLastSafetyForPoint(Double_t safe, Double_t x, Double_t y, Double_t z)
0202 {
0203 fLastSafety = safe;
0204 fLastPoint[0] = x;
0205 fLastPoint[1] = y, fLastPoint[2] = z;
0206 }
0207
0208
0209
0210 Double_t GetPWSafetyEstimateFromCache(Double_t cpoint[3]) const
0211 {
0212
0213 if (fLastPWSafety < TGeoShape::Tolerance()) {
0214 return -1.;
0215 }
0216 const auto d0 = fLastPWSaftyPnt[0] - cpoint[0];
0217 const auto d1 = fLastPWSaftyPnt[1] - cpoint[1];
0218 const auto d2 = fLastPWSaftyPnt[2] - cpoint[2];
0219 const auto d_sq = d0 * d0 + d1 * d1 + d2 * d2;
0220
0221 if (d_sq >= (fLastPWSafety * fLastPWSafety)) {
0222 return -1.;
0223 }
0224
0225 return fLastPWSafety - std::sqrt(d_sq);
0226 }
0227
0228
0229
0230 Double_t GetPWSafety(Double_t cpoint[3], Double_t saf_max);
0231
0232
0233 static void SetPWSafetyCaching(Bool_t b) { fgUsePWSafetyCaching = b; }
0234 static Bool_t IsPWSafetyCaching() { return fgUsePWSafetyCaching; }
0235
0236
0237 void LocalToMaster(const Double_t *local, Double_t *master) const { fCache->LocalToMaster(local, master); }
0238 void LocalToMasterVect(const Double_t *local, Double_t *master) const { fCache->LocalToMasterVect(local, master); }
0239 void LocalToMasterBomb(const Double_t *local, Double_t *master) const { fCache->LocalToMasterBomb(local, master); }
0240 void MasterToLocal(const Double_t *master, Double_t *local) const { fCache->MasterToLocal(master, local); }
0241 void MasterToLocalVect(const Double_t *master, Double_t *local) const { fCache->MasterToLocalVect(master, local); }
0242 void MasterToLocalBomb(const Double_t *master, Double_t *local) const { fCache->MasterToLocalBomb(master, local); }
0243 void MasterToTop(const Double_t *master, Double_t *top) const;
0244 void TopToMaster(const Double_t *top, Double_t *master) const;
0245 TGeoNodeCache *GetCache() const { return fCache; }
0246
0247
0248 Int_t PushPath(Int_t startlevel = 0) { return fCache->PushState(fCurrentOverlapping, startlevel, fNmany); }
0249 Bool_t PopPath()
0250 {
0251 fCurrentOverlapping = fCache->PopState(fNmany);
0252 fCurrentNode = fCache->GetNode();
0253 fLevel = fCache->GetLevel();
0254 fGlobalMatrix = fCache->GetCurrentMatrix();
0255 return fCurrentOverlapping;
0256 }
0257 Bool_t PopPath(Int_t index)
0258 {
0259 fCurrentOverlapping = fCache->PopState(fNmany, index);
0260 fCurrentNode = fCache->GetNode();
0261 fLevel = fCache->GetLevel();
0262 fGlobalMatrix = fCache->GetCurrentMatrix();
0263 return fCurrentOverlapping;
0264 }
0265 Int_t PushPoint(Int_t startlevel = 0) { return fCache->PushState(fCurrentOverlapping, startlevel, fNmany, fPoint); }
0266 Bool_t PopPoint()
0267 {
0268 fCurrentOverlapping = fCache->PopState(fNmany, fPoint);
0269 fCurrentNode = fCache->GetNode();
0270 fLevel = fCache->GetLevel();
0271 fGlobalMatrix = fCache->GetCurrentMatrix();
0272 return fCurrentOverlapping;
0273 }
0274 Bool_t PopPoint(Int_t index)
0275 {
0276 fCurrentOverlapping = fCache->PopState(fNmany, index, fPoint);
0277 fCurrentNode = fCache->GetNode();
0278 fLevel = fCache->GetLevel();
0279 fGlobalMatrix = fCache->GetCurrentMatrix();
0280 return fCurrentOverlapping;
0281 }
0282 void PopDummy(Int_t ipop = 9999) { fCache->PopDummy(ipop); }
0283
0284 ClassDefOverride(TGeoNavigator, 0)
0285 };
0286
0287 #include "TObjArray.h"
0288
0289
0290
0291
0292
0293
0294
0295
0296 class TGeoNavigatorArray : public TObjArray {
0297 private:
0298 TGeoNavigator *fCurrentNavigator;
0299 TGeoManager *fGeoManager;
0300
0301 TGeoNavigatorArray(const TGeoNavigatorArray &) = delete;
0302 TGeoNavigatorArray &operator=(const TGeoNavigatorArray &) = delete;
0303
0304 public:
0305 TGeoNavigatorArray() : TObjArray(), fCurrentNavigator(nullptr), fGeoManager(nullptr) {}
0306 TGeoNavigatorArray(TGeoManager *mgr) : TObjArray(), fCurrentNavigator(nullptr), fGeoManager(mgr) { SetOwner(); }
0307 ~TGeoNavigatorArray() override {}
0308
0309 TGeoNavigator *AddNavigator();
0310 inline TGeoNavigator *GetCurrentNavigator() const { return fCurrentNavigator; }
0311 TGeoNavigator *SetCurrentNavigator(Int_t inav) { return (fCurrentNavigator = (TGeoNavigator *)At(inav)); }
0312
0313 ClassDefOverride(TGeoNavigatorArray, 0)
0314 };
0315 #endif