Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoNavigator.h
Go to the documentation of this file.
1// @(#)root/geom:$Id$
2// Author: Mihaela Gheata 30/05/07
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_TGeoNavigator
13#define ROOT_TGeoNavigator
14
15#include "TObject.h"
16
17#include "TGeoCache.h"
18
19#include <cmath>
20
21////////////////////////////////////////////////////////////////////////////
22// //
23// TGeoNavigator - Class containing the implementation of all navigation //
24// methods.
25// //
26////////////////////////////////////////////////////////////////////////////
27
28class TGeoManager;
29class TGeoNode;
30class TGeoVolume;
31class TGeoMatrix;
32class TGeoHMatrix;
33
34class TGeoNavigator : public TObject {
35
36protected:
37 TGeoNavigator(const TGeoNavigator &) = delete;
42 void SafetyOverlaps();
43
44private:
45 Double_t fStep; //! step to be done from current point and direction
46 Double_t fSafety; //! safety radius from current point
47 Double_t fLastSafety; //! last computed safety radius
48 Double_t fNormal[3]; //! cosine of incident angle on current checked surface
49 Double_t fCldir[3]; //! unit vector to current closest shape
50 Double_t fCldirChecked[3]; //! unit vector to current checked shape
51 Double_t fPoint[3]; //! current point
52 Double_t fDirection[3]; //! current direction
53 Double_t fLastPoint[3]; //! last point for which safety was computed
54 Double_t fLastPWSaftyPnt[3]; //! last point for which parallel world safety was "evaluated"
55 Double_t fLastPWSafety{-1}; //! last safety returned from parallel world (negative if invalid)
56 Int_t fThreadId; //! thread id for this navigator
57 Int_t fLevel; //! current geometry level;
58 Int_t fNmany; //! number of overlapping nodes on current branch
59 Int_t fNextDaughterIndex; //! next daughter index after FindNextBoundary
60 Int_t fOverlapSize; //! current size of fOverlapClusters
61 Int_t fOverlapMark; //! current recursive position in fOverlapClusters
62 Int_t *fOverlapClusters; //! internal array for overlaps
63 Bool_t fSearchOverlaps; //! flag set when an overlapping cluster is searched
64 Bool_t fCurrentOverlapping; //! flags the type of the current node
65 Bool_t fStartSafe; //! flag a safe start for point classification
66 Bool_t fIsEntering; //! flag if current step just got into a new node
67 Bool_t fIsExiting; //! flag that current track is about to leave current node
68 Bool_t fIsStepEntering; //! flag that next geometric step will enter new volume
69 Bool_t fIsStepExiting; //! flag that next geometric step will exit current volume
70 Bool_t fIsOutside; //! flag that current point is outside geometry
71 Bool_t fIsOnBoundary; //! flag that current point is on some boundary
72 Bool_t fIsSameLocation; //! flag that a new point is in the same node as previous
73 Bool_t fIsNullStep; //! flag that last geometric step was null
74 TGeoManager *fGeometry; //! current geometry
75 TGeoNodeCache *fCache; //! cache of states
76 TGeoVolume *fCurrentVolume; //! current volume
77 TGeoNode *fCurrentNode; //! current node
78 TGeoNode *fTopNode; //! top physical node
79 TGeoNode *fLastNode; //! last searched node
80 TGeoNode *fNextNode; //! next node that will be crossed
81 TGeoNode *fForcedNode; //! current point is supposed to be inside this node
82 TGeoCacheState *fBackupState; //! backup state
83 TGeoHMatrix *fCurrentMatrix; //! current stored global matrix
84 TGeoHMatrix *fGlobalMatrix; //! current pointer to cached global matrix
85 TGeoHMatrix *fDivMatrix; //! current local matrix of the selected division cell
86 TString fPath; //! path to current node
87
88 static Bool_t fgUsePWSafetyCaching; //! global mode is caching enabled for parallel world safety calls
89
90public:
93 ~TGeoNavigator() override;
94
95 void BuildCache(Bool_t dummy = kFALSE, Bool_t nodeid = kFALSE);
96 Bool_t cd(const char *path = "");
97 Bool_t CheckPath(const char *path) const;
98 void CdNode(Int_t nodeid);
99 void CdDown(Int_t index);
100 void CdDown(TGeoNode *node);
101 void CdUp();
102 void CdTop();
103 void CdNext();
104 void GetBranchNames(Int_t *names) const;
106 void GetBranchOnlys(Int_t *isonly) const;
107 Int_t GetNmany() const { return fNmany; }
108 //--- geometry queries
115 Double_t *FindNormal(Bool_t forward = kTRUE);
117 TGeoNode *InitTrack(const Double_t *point, const Double_t *dir);
119 void ResetState();
120 void ResetAll();
121 Double_t Safety(Bool_t inside = kFALSE);
124 const Double_t *GetLastPoint() const { return fLastPoint; }
127 Int_t GetSafeLevel() const;
128 Double_t GetSafeDistance() const { return fSafety; }
130 Double_t GetStep() const { return fStep; }
131 Int_t GetThreadId() const { return fThreadId; }
132 void InspectState() const;
137 Bool_t IsStartSafe() const { return fStartSafe; }
139 void SetStep(Double_t step) { fStep = step; }
142 Bool_t IsEntering() const { return fIsEntering; }
143 Bool_t IsExiting() const { return fIsExiting; }
146 Bool_t IsOutside() const { return fIsOutside; }
148 Bool_t IsNullStep() const { return fIsNullStep; }
151 //--- modeler state getters/setters
152 void DoBackupState();
153 void DoRestoreState();
154 Int_t GetNodeId() const { return fCache->GetNodeId(); }
156 TGeoNode *GetNextNode() const { return fNextNode; }
157 TGeoNode *GetMother(Int_t up = 1) const { return fCache->GetMother(up); }
163 const Double_t *GetCurrentPoint() const { return fPoint; }
164 const Double_t *GetCurrentDirection() const { return fDirection; }
166 const Double_t *GetCldirChecked() const { return fCldirChecked; }
167 const Double_t *GetCldir() const { return fCldir; }
169 // Double_t GetNormalChecked() const {return fNormalChecked;}
170 const Double_t *GetNormal() const { return fNormal; }
171 Int_t GetLevel() const { return fLevel; }
172 const char *GetPath() const;
174 void SetCurrentPoint(const Double_t *point) { memcpy(fPoint, point, 3 * sizeof(Double_t)); }
176 {
177 fPoint[0] = x;
178 fPoint[1] = y;
179 fPoint[2] = z;
180 }
182 {
183 fLastPoint[0] = x;
184 fLastPoint[1] = y;
185 fLastPoint[2] = z;
186 }
187 void SetCurrentDirection(const Double_t *dir) { memcpy(fDirection, dir, 3 * sizeof(Double_t)); }
189 {
190 fDirection[0] = nx;
191 fDirection[1] = ny;
192 fDirection[2] = nz;
193 }
194 // void SetNormalChecked(Double_t norm) {fNormalChecked=norm;}
195 void SetCldirChecked(Double_t *dir) { memcpy(fCldirChecked, dir, 3 * sizeof(Double_t)); }
197 {
199 memcpy(fLastPoint, point, 3 * sizeof(Double_t));
200 }
202 {
204 fLastPoint[0] = x;
205 fLastPoint[1] = y, fLastPoint[2] = z;
206 }
207
208 // Check if we have a cached safety value from parallel world, and if this can still be used.
209 // Return negative value if no cache available.
211 {
212 // disregard too small or invalid safeties
214 return -1.;
215 }
216 const auto d0 = fLastPWSaftyPnt[0] - cpoint[0];
217 const auto d1 = fLastPWSaftyPnt[1] - cpoint[1];
218 const auto d2 = fLastPWSaftyPnt[2] - cpoint[2];
219 const auto d_sq = d0 * d0 + d1 * d1 + d2 * d2;
220 // if we have moved too much return -1 as "invalid"
221 if (d_sq >= (fLastPWSafety * fLastPWSafety)) {
222 return -1.;
223 }
224 // or return a reasonable cache estimate for safety
225 return fLastPWSafety - std::sqrt(d_sq);
226 }
227
228 // Wrapper for getting the safety from the parallel world.
229 // Takes care of caching mechanics and talking to the Safety function of parallel world.
231
232 // enable/disable parallel world safety caching
235
236 //--- point/vector reference frame conversion
243 void MasterToTop(const Double_t *master, Double_t *top) const;
244 void TopToMaster(const Double_t *top, Double_t *master) const;
245 TGeoNodeCache *GetCache() const { return fCache; }
246 // void SetCache(const TGeoNodeCache *cache) {fCache = (TGeoNodeCache*)cache;}
247 //--- stack manipulation
282 void PopDummy(Int_t ipop = 9999) { fCache->PopDummy(ipop); }
283
284 ClassDefOverride(TGeoNavigator, 0) // geometry navigator class
285};
286
287#include "TObjArray.h"
288
289////////////////////////////////////////////////////////////////////////////
290// //
291// TGeoNavigatorArray - Class representing an array of navigators working //
292// in a single thread. //
293// //
294////////////////////////////////////////////////////////////////////////////
295
315#endif
#define b(i)
Definition RSha256.hxx:100
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
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
#define ClassDefOverride(name, id)
Definition Rtypes.h:348
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
Class storing the state of the cache at a given moment.
Definition TGeoCache.h:28
Matrix class used for computing global transformations Should NOT be used for node definition.
Definition TGeoMatrix.h:458
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
Geometrical transformation package.
Definition TGeoMatrix.h:38
TGeoNavigatorArray(const TGeoNavigatorArray &)=delete
TGeoNavigatorArray(TGeoManager *mgr)
TGeoNavigator * fCurrentNavigator
TGeoNavigator * AddNavigator()
Add a new navigator to the array.
TGeoNavigator * GetCurrentNavigator() const
TGeoNavigatorArray & operator=(const TGeoNavigatorArray &)=delete
TGeoManager * fGeoManager
TGeoNavigator * SetCurrentNavigator(Int_t inav)
~TGeoNavigatorArray() override
Class providing navigation API for TGeo geometries.
void CdUp()
Go one level up in geometry.
void DoBackupState()
Backup the current state without affecting the cache stack.
TGeoNode * GetMother(Int_t up=1) const
void SetCurrentPoint(Double_t x, Double_t y, Double_t z)
Double_t fLastPWSaftyPnt[3]
last point for which safety was computed
void DoRestoreState()
Restore a backed-up state without affecting the cache stack.
Double_t fPoint[3]
unit vector to current checked shape
Bool_t IsStepExiting() const
Bool_t fSearchOverlaps
internal array for overlaps
Bool_t fIsExiting
flag if current step just got into a new node
TString fPath
current local matrix of the selected division cell
TGeoHMatrix * fDivMatrix
current pointer to cached global matrix
TGeoNode * CrossBoundaryAndLocate(Bool_t downwards, TGeoNode *skipnode)
Cross next boundary and locate within current node The current point must be on the boundary of fCurr...
Double_t fLastPWSafety
last point for which parallel world safety was "evaluated"
TGeoHMatrix * GetHMatrix()
Return stored current matrix (global matrix of the next touched node).
Bool_t IsCheckingOverlaps() const
void LocalToMaster(const Double_t *local, Double_t *master) const
TGeoNodeCache * fCache
current geometry
Bool_t fStartSafe
flags the type of the current node
void CdNext()
Do a cd to the node found next by FindNextBoundary.
TGeoNode * GetNextNode() const
Double_t Safety(Bool_t inside=kFALSE)
Compute safe distance from the current point.
const Double_t * GetCldirChecked() const
Bool_t GotoSafeLevel()
Go upwards the tree until a non-overlapping node.
Double_t fNormal[3]
last computed safety radius
Double_t GetLastSafety() const
Bool_t PopPoint(Int_t index)
Bool_t cd(const char *path="")
Browse the tree of nodes starting from top node according to pathname.
Double_t fLastPoint[3]
current direction
Double_t GetStep() const
Bool_t IsSameLocation() const
Double_t fCldir[3]
cosine of incident angle on current checked surface
Bool_t fIsStepEntering
flag that current track is about to leave current node
void SetLastPoint(Double_t x, Double_t y, Double_t z)
Int_t GetNodeId() const
void MasterToLocal(const Double_t *master, Double_t *local) const
Int_t GetVirtualLevel()
Find level of virtuality of current overlapping node (number of levels up having the same tracking me...
Bool_t PopPoint()
Int_t fOverlapSize
next daughter index after FindNextBoundary
TGeoNode * InitTrack(const Double_t *point, const Double_t *dir)
Initialize current point and current direction vector (normalized) in MARS.
const Double_t * GetLastPoint() const
void InspectState() const
Inspects path and all flags for the current state.
Int_t PushPoint(Int_t startlevel=0)
TGeoNode * Step(Bool_t is_geom=kTRUE, Bool_t cross=kTRUE)
Make a rectiliniar step of length fStep from current point (fPoint) on current direction (fDirection)...
TGeoNode * FindInCluster(Int_t *cluster, Int_t nc)
Find a node inside a cluster of overlapping nodes.
TGeoNavigator(const TGeoNavigator &)=delete
Bool_t IsNullStep() const
TGeoVolume * GetCurrentVolume() const
Int_t GetNextDaughterIndex() const
void SafetyOverlaps()
Compute safe distance from the current point within an overlapping node.
TGeoHMatrix * GetCurrentMatrix() const
TGeoNode * CrossDivisionCell()
Cross a division cell.
void ResetState()
Reset current state flags.
static Bool_t IsPWSafetyCaching()
Double_t GetSafeDistance() const
TGeoNode * FindNextDaughterBoundary(Double_t *point, Double_t *dir, Int_t &idaughter, Bool_t compmatrix=kFALSE)
Computes as fStep the distance to next daughter of the current volume.
Bool_t fIsSameLocation
flag that current point is on some boundary
void SetCheckingOverlaps(Bool_t flag=kTRUE)
void GetBranchNumbers(Int_t *copyNumbers, Int_t *volumeNumbers) const
Fill node copy numbers of current branch into an array.
Bool_t CheckPath(const char *path) const
Check if a geometry path is valid without changing the state of the navigator.
void SetOutside(Bool_t flag=kTRUE)
void SetStartSafe(Bool_t flag=kTRUE)
Bool_t IsEntering() const
TGeoHMatrix * GetMotherMatrix(Int_t up=1) const
TGeoVolume * fCurrentVolume
cache of states
TGeoNode * fLastNode
top physical node
void SetCldirChecked(Double_t *dir)
Int_t fThreadId
last safety returned from parallel world (negative if invalid)
void LocalToMasterBomb(const Double_t *local, Double_t *master) const
static void SetPWSafetyCaching(Bool_t b)
Double_t GetPWSafetyEstimateFromCache(Double_t cpoint[3]) const
Double_t fDirection[3]
current point
void PopDummy(Int_t ipop=9999)
Int_t GetTouchedCluster(Int_t start, Double_t *point, Int_t *check_list, Int_t ncheck, Int_t *result)
Make the cluster of overlapping nodes in a voxel, containing point in reference of the mother.
TGeoNode * FindNextBoundary(Double_t stepmax=TGeoShape::Big(), const char *path="", Bool_t frombdr=kFALSE)
Find distance to next boundary and store it in fStep.
TGeoNode * GetCurrentNode() const
TGeoNode * FindNode(Bool_t safe_start=kTRUE)
Returns deepest node containing current point.
Int_t fOverlapMark
current size of fOverlapClusters
TGeoNode * FindNextBoundaryAndStep(Double_t stepmax=TGeoShape::Big(), Bool_t compsafe=kFALSE)
Compute distance to next boundary within STEPMAX.
Bool_t IsOutside() const
Int_t GetThreadId() const
void CdTop()
Make top level node the current node.
void SetStep(Double_t step)
Int_t fNmany
current geometry level;
TGeoManager * fGeometry
flag that last geometric step was null
TGeoHMatrix * fGlobalMatrix
current stored global matrix
void MasterToTop(const Double_t *master, Double_t *top) const
Convert coordinates from master volume frame to top.
Int_t GetCurrentNodeId() const
Double_t * FindNormalFast()
Computes fast normal to next crossed boundary, assuming that the current point is close enough to the...
const Double_t * GetCurrentDirection() const
Bool_t IsExiting() const
Int_t PushPath(Int_t startlevel=0)
Bool_t fIsStepExiting
flag that next geometric step will enter new volume
Bool_t fIsOnBoundary
flag that current point is outside geometry
static Bool_t fgUsePWSafetyCaching
path to current node
void GetBranchOnlys(Int_t *isonly) const
Fill node copy numbers of current branch into an array.
void SetCurrentDirection(Double_t nx, Double_t ny, Double_t nz)
Int_t GetStackLevel() const
const Double_t * GetNormal() const
void TopToMaster(const Double_t *top, Double_t *master) const
Convert coordinates from top volume frame to master.
void SetCurrentPoint(const Double_t *point)
TGeoHMatrix * fCurrentMatrix
backup state
Int_t * fOverlapClusters
current recursive position in fOverlapClusters
const Double_t * GetCldir() const
TGeoNode * fTopNode
current node
void LocalToMasterVect(const Double_t *local, Double_t *master) const
Bool_t IsSafeStep(Double_t proposed, Double_t &newsafety) const
In case a previous safety value was computed, check if the safety region is still safe for the curren...
TGeoNode * SearchNode(Bool_t downwards=kFALSE, const TGeoNode *skipnode=nullptr)
Returns the deepest node containing fPoint, which must be set a priori.
Double_t fLastSafety
safety radius from current point
~TGeoNavigator() override
Destructor.
TGeoNavigator()
global mode is caching enabled for parallel world safety calls
void SetCurrentDirection(const Double_t *dir)
void BuildCache(Bool_t dummy=kFALSE, Bool_t nodeid=kFALSE)
Builds the cache for physical nodes and global matrices.
Int_t fNextDaughterIndex
number of overlapping nodes on current branch
Bool_t PopPath(Int_t index)
Bool_t fIsNullStep
flag that a new point is in the same node as previous
void SetLastSafetyForPoint(Double_t safe, const Double_t *point)
void CdNode(Int_t nodeid)
Change current path to point to the node having this id.
Bool_t IsCurrentOverlapping() const
TGeoNavigator & operator=(const TGeoNavigator &)=delete
Int_t GetNmany() const
TGeoNodeCache * GetCache() const
TGeoNode * fNextNode
last searched node
Double_t fCldirChecked[3]
unit vector to current closest shape
void SetLastSafetyForPoint(Double_t safe, Double_t x, Double_t y, Double_t z)
Int_t fLevel
thread id for this navigator
Double_t GetPWSafety(Double_t cpoint[3], Double_t saf_max)
Wrapper for getting the safety from the parallel world.
void ResetAll()
Reset the navigator.
TGeoCacheState * fBackupState
current point is supposed to be inside this node
Int_t GetLevel() const
Bool_t IsSamePoint(Double_t x, Double_t y, Double_t z) const
Check if a new point with given coordinates is the same as the last located one.
Bool_t fCurrentOverlapping
flag set when an overlapping cluster is searched
Bool_t IsOnBoundary() const
Bool_t fIsOutside
flag that next geometric step will exit current volume
void CdDown(Int_t index)
Make a daughter of current node current.
Bool_t fIsEntering
flag a safe start for point classification
const Double_t * GetCurrentPoint() const
Bool_t IsStartSafe() const
TGeoNode * fForcedNode
next node that will be crossed
TGeoHMatrix * GetDivMatrix() const
void MasterToLocalVect(const Double_t *master, Double_t *local) const
void MasterToLocalBomb(const Double_t *master, Double_t *local) const
const char * GetPath() const
Get path to the current node in the form /node0/node1/...
Bool_t IsStepEntering() const
Int_t GetSafeLevel() const
Go upwards the tree until a non-overlapping node.
TGeoNode * fCurrentNode
current volume
Double_t fSafety
step to be done from current point and direction
Double_t * FindNormal(Bool_t forward=kTRUE)
Computes normal vector to the next surface that will be or was already crossed when propagating on a ...
void GetBranchNames(Int_t *names) const
Fill volume names of current branch into an array.
Special pool of reusable nodes.
Definition TGeoCache.h:56
TGeoNode * GetNode() const
Definition TGeoCache.h:116
Bool_t PopState(Int_t &nmany, Double_t *point=nullptr)
Pop next state/point from heap.
void MasterToLocal(const Double_t *master, Double_t *local) const
Point in master frame defined by current matrix converted to local one.
Int_t PushState(Bool_t ovlp, Int_t ntmany=0, Int_t startlevel=0, Double_t *point=nullptr)
Push current state into heap.
void PopDummy(Int_t ipop=9999)
Definition TGeoCache.h:137
Int_t GetNodeId() const
Get unique node id.
TGeoHMatrix * GetMotherMatrix(Int_t up=1) const
Definition TGeoCache.h:112
void MasterToLocalVect(const Double_t *master, Double_t *local) const
Vector in master frame defined by current matrix converted to local one.
void MasterToLocalBomb(const Double_t *master, Double_t *local) const
Point in master frame defined by current matrix converted to local one and rescaled with bomb factor.
void LocalToMaster(const Double_t *local, Double_t *master) const
Local point converted to master frame defined by current matrix.
void LocalToMasterVect(const Double_t *local, Double_t *master) const
Local vector converted to master frame defined by current matrix.
Int_t GetCurrentNodeId() const
Returns a fixed ID for current physical node.
void LocalToMasterBomb(const Double_t *local, Double_t *master) const
Local point converted to master frame defined by current matrix and rescaled with bomb factor.
Int_t GetStackLevel() const
Definition TGeoCache.h:123
TGeoHMatrix * GetCurrentMatrix() const
Definition TGeoCache.h:109
TGeoNode * GetMother(Int_t up=1) const
Definition TGeoCache.h:111
Int_t GetLevel() const
Definition TGeoCache.h:121
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
TGeoVolume * GetVolume() const
Definition TGeoNode.h:99
static Double_t Big()
Definition TGeoShape.h:94
static Double_t Tolerance()
Definition TGeoShape.h:97
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
An array of TObjects.
Definition TObjArray.h:31
TObject * At(Int_t idx) const override
Definition TObjArray.h:164
Mother of all ROOT objects.
Definition TObject.h:41
Basic string class.
Definition TString.h:138
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17