Project
Loading...
Searching...
No Matches
VecGeomG4Navigator.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef O2_SIMSETUP_VECGEOMG4NAVIGATOR_H_
13#define O2_SIMSETUP_VECGEOMG4NAVIGATOR_H_
14
16
17namespace o2::simsetup
18{
19
36{
37 public:
40 VecGeomG4Navigator(VecGeomG4Map const& map, double pushDepth, bool zeroSafety);
41 ~VecGeomG4Navigator() override;
42
43 G4double ComputeStep(const G4ThreeVector& globalPoint, const G4ThreeVector& direction,
44 const G4double proposedStepLength, G4double& newSafety) override;
45
46 G4VPhysicalVolume* ResetHierarchyAndLocate(const G4ThreeVector& point, const G4ThreeVector& direction,
47 const G4TouchableHistory& history) override;
48
49 G4VPhysicalVolume* LocateGlobalPointAndSetup(const G4ThreeVector& point, const G4ThreeVector* direction = nullptr,
50 const G4bool relativeSearch = true,
51 const G4bool ignoreDirection = true) override;
52
53 void LocateGlobalPointWithinVolume(const G4ThreeVector& position) override;
54
55 G4double ComputeSafety(const G4ThreeVector& globalPoint, const G4double proposedMaxLength = DBL_MAX,
56 const G4bool keepState = true) override;
57
58 // Both point out of the volume left; the local one is in the frame of the final volume.
59 G4ThreeVector GetLocalExitNormal(G4bool* valid) override;
60 G4ThreeVector GetGlobalExitNormal(const G4ThreeVector& point, G4bool* valid) override;
61
62 private:
64 G4VPhysicalVolume* updateG4History();
65 void locateFromWorld(const V3& point);
67 void leaveFlushVolumes(const V3& point, const V3& dir, int minLevel, vecgeom::VPlacedVolume const* avoid);
69 void updateCrossingFlags(bool entering);
70 void clearLastExited()
71 {
72 mCurState.SetLastExited(mEmptyState.GetLastExitedState());
73 mExitBlockPending = false;
74 }
76 void setExited(vecgeom::NavigationState const& st, bool normalFromPush)
77 {
78 mExitedState = st;
79 mExitBlockPending = true;
80 mExitNormalFromPush = normalFromPush && mPushNormalValid;
81 }
84 double boundaryPush(const V3& point, const V3& dir);
86 bool computeExitNormal(const G4ThreeVector& point, V3& globalNormal) const;
87
88 double mPushDepth = 1.e-9;
89 bool mZeroSafety = false;
90
91 vecgeom::NavigationState mCurState;
92 vecgeom::NavigationState mNextState;
93 vecgeom::NavigationState mStepState;
94 vecgeom::NavigationState mReloScratch;
95 vecgeom::NavigationState mPathScratch;
96 vecgeom::NavigationState mHistoryState;
97 vecgeom::NavigationState mEmptyState;
98 vecgeom::NavigationState mNormalState;
99 vecgeom::NavigationState mExitedState;
100 bool mExitBlockPending = false;
101 bool mExitNormalFromPush = false;
102 V3 mPushNormal;
103 bool mPushNormalValid = false;
104 bool mHistoryValid = false;
105
106 bool mWouldEnter = false;
107 bool mWouldExit = false;
108 G4ThreeVector mNextPoint{-1e8, -1e8, -1e8};
109 G4ThreeVector mLastLocatedPoint{-1e8, -1e8, -1e8};
110 bool mLocatedOnBoundary = false;
111 G4ThreeVector mSafetyOrig{-1e8, -1e8, -1e8};
112 double mLastSafety = 0.;
113 bool mNormalEnter = false;
114 bool mNormalValid = false;
115 G4ThreeVector mNormalPoint{-1e8, -1e8, -1e8};
116
118 static constexpr int kActionThresholdNoZeroSteps = 10;
119 static constexpr int kAbandonThresholdNoZeroSteps = 25;
120 int mNzeroSteps = 0;
121
122 // What the navigator had to work around, reported at the end.
123 long mZeroStepCount = 0;
124 long mStuckPushCount = 0;
125 long mAbandonCount = 0;
126 long mNegativeSafetyCount = 0;
127 long mUnmappableHistoryCount = 0;
128 long mRelocatedResumeCount = 0;
129 long mNoNormalCount = 0;
130};
131
132} // namespace o2::simsetup
133
134#endif
bool valid
benchmark::State & st
G4ThreeVector GetGlobalExitNormal(const G4ThreeVector &point, G4bool *valid) override
G4double ComputeSafety(const G4ThreeVector &globalPoint, const G4double proposedMaxLength=DBL_MAX, const G4bool keepState=true) override
G4double ComputeStep(const G4ThreeVector &globalPoint, const G4ThreeVector &direction, const G4double proposedStepLength, G4double &newSafety) override
G4VPhysicalVolume * ResetHierarchyAndLocate(const G4ThreeVector &point, const G4ThreeVector &direction, const G4TouchableHistory &history) override
G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=nullptr, const G4bool relativeSearch=true, const G4bool ignoreDirection=true) override
void LocateGlobalPointWithinVolume(const G4ThreeVector &position) override
G4ThreeVector GetLocalExitNormal(G4bool *valid) override