G4NavigationHistory
Attempt to use NavigationHistory is lacking depth. Need to initiate the levels.
delta:geant4.10.00.p01 blyth$ find . -name '*.cc' -exec grep -H NewLevel {} \;
./source/geometry/navigation/src/G4Navigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kNormal,
./source/geometry/navigation/src/G4Navigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kReplica,
./source/geometry/navigation/src/G4Navigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kParameterised,
./source/geometry/navigation/src/G4ParameterisedNavigation.cc: history.NewLevel(pPhysical, kParameterised, replicaNo);
./source/geometry/navigation/src/G4RegularNavigation.cc: history.NewLevel(pPhysical, kParameterised, replicaNo );
./source/processes/electromagnetic/dna/management/src/G4ITNavigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kNormal,
./source/processes/electromagnetic/dna/management/src/G4ITNavigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kReplica,
./source/processes/electromagnetic/dna/management/src/G4ITNavigator.cc: fHistory.NewLevel(fBlockedPhysicalVolume, kParameterised,
./source/processes/hadronic/models/de_excitation/photon_evaporation/src/G4LevelReader.cc: if(0 < nLevels) { MakeNewLevel(levels); }
./source/processes/hadronic/models/de_excitation/photon_evaporation/src/G4LevelReader.cc: MakeNewLevel(levels);
./source/processes/hadronic/models/de_excitation/photon_evaporation/src/G4LevelReader.cc:void G4LevelReader::MakeNewLevel(std::vector<G4NucLevel*>* levels)
./source/processes/scoring/src/G4ScoreSplittingProcess.cc: ptrNavHistory->NewLevel( curPhysicalVol, kParameterised, newVoxelNum );
source/processes/electromagnetic/dna/management/src/G4ITNavigator.cc:
224 if ( fEntering )
225 {
226 switch (VolumeType(fBlockedPhysicalVolume))
227 {
228 case kNormal:
229 fHistory.NewLevel(fBlockedPhysicalVolume, kNormal,
230 fBlockedPhysicalVolume->GetCopyNo());
231 break;
232 case kReplica:
233 freplicaNav.ComputeTransformation(fBlockedReplicaNo,
234 fBlockedPhysicalVolume);
235 fHistory.NewLevel(fBlockedPhysicalVolume, kReplica,
236 fBlockedReplicaNo);
237 fBlockedPhysicalVolume->SetCopyNo(fBlockedReplicaNo);
238 break;
source/geometry/volumes/include/G4NavigationHistory.hh:
58 class G4NavigationHistory
59 {
60
61 public: // with description
62
63 friend std::ostream&
64 operator << (std::ostream &os, const G4NavigationHistory &h);
65
66 G4NavigationHistory();
67 // Constructor: sizes history lists & resets histories.
68
69 ~G4NavigationHistory();
70 // Destructor.
71
72 G4NavigationHistory(const G4NavigationHistory &h);
73 // Copy constructor.
74
75 G4NavigationHistory& operator=(const G4NavigationHistory &h);
76 // Assignment operator.
77
78 inline void Reset();
79 // Resets history. It now does clear most entries.
80 // Level 0 is preserved.
81
82 inline void Clear();
83 // Clears entries, zeroing transforms, matrices & negating
84 // replica history.
85
86 inline void SetFirstEntry(G4VPhysicalVolume* pVol);
87 // Setup initial entry in stack: copies through volume transform & matrix.
88 // The volume is assumed to be unrotated.
89
90 inline const G4AffineTransform& GetTopTransform() const;
91 // Returns topmost transform.
92
93 inline const G4AffineTransform* GetPtrTopTransform() const;
94 // Returns pointer to topmost transform.
95
96 inline G4int GetTopReplicaNo() const;
97 // Returns topmost replica no record.
98
99 inline EVolume GetTopVolumeType() const;
00 // Returns topmost volume type.
01
02 inline G4VPhysicalVolume* GetTopVolume() const;
03 // Returns topmost physical volume pointer.
04
05 inline G4int GetDepth() const;
..
07
08 inline G4int GetMaxDepth() const;
09 // Returns current maximum size of history.
10 // Note: MaxDepth of 16 mean history entries [0..15] inclusive.
11
12 inline const G4AffineTransform& GetTransform(G4int n) const;
13 // Returns specified transformation.
14
15 inline G4int GetReplicaNo(G4int n) const;
16 // Returns specified replica no record.
17
18 inline EVolume GetVolumeType(G4int n) const;
19 // Returns specified volume type.
20
21 inline G4VPhysicalVolume* GetVolume(G4int n) const;
22 // Returns specified physical volume pointer.
23
24 inline void NewLevel(G4VPhysicalVolume *pNewMother,
25 EVolume vType=kNormal,
26 G4int nReplica=-1);
27 // Changes navigation level to that of the new mother.
28
29 inline void BackLevel();
30 // Back up one level in history: from mother to grandmother.
31 // It does not erase history record of current mother.
32
33 inline void BackLevel(G4int n);
34 // Back up specified number of levels in history.
35
36 private:
37
38 inline void EnlargeHistory();
39 // Enlarge history if required: increase size by kHistoryStride.
40 // Note that additional history entries are `dirty' (non zero) apart
41 // from the volume history.
42
43 private:
44
45 #if defined(WIN32)
46 std::vector<G4NavigationLevel> fNavHistory;
47 #else
48 std::vector<G4NavigationLevel,
49 G4EnhancedVecAllocator<G4NavigationLevel> > fNavHistory;
50 // The geometrical tree; uses specialized allocator to optimize memory
51 // handling, reduce possible fragmentation and use of malloc in MT mode
52 #endif
53
54 G4int fStackDepth;
55 // Depth of stack: effectively depth in geometrical tree
56
57 };
58
59 #include "G4NavigationHistory.icc"
source/geometry/volumes/include/G4NavigationHistory.icc:
092 inline
093 const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const
094 {
095 return fNavHistory[fStackDepth].GetPtrTransform();
096 }
097
098 inline
099 const G4AffineTransform& G4NavigationHistory::GetTopTransform() const
100 {
101 return fNavHistory[fStackDepth].GetTransform();
102 }
103
104 inline
105 G4int G4NavigationHistory::GetTopReplicaNo() const
106 {
107 return fNavHistory[fStackDepth].GetReplicaNo();
108 }
109
110 inline
111 EVolume G4NavigationHistory::GetTopVolumeType() const
112 {
113 return fNavHistory[fStackDepth].GetVolumeType();
114 }
115
116 inline
117 G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const
118 {
119 return fNavHistory[fStackDepth].GetPhysicalVolume();
120 }
...
191 inline
192 void G4NavigationHistory::NewLevel( G4VPhysicalVolume *pNewMother,
193 EVolume vType,
194 G4int nReplica )
195 {
196 fStackDepth++;
197 EnlargeHistory(); // Enlarge if required
198 fNavHistory[fStackDepth] =
199 G4NavigationLevel( pNewMother,
200 fNavHistory[fStackDepth-1].GetTransform(),
201 G4AffineTransform(pNewMother->GetRotation(),
202 pNewMother->GetTranslation()),
203 vType,
204 nReplica );
205 // The constructor computes the new global->local transform
206 }
source/geometry/management/include/G4VTouchable.hh:
30 // class G4VTouchable
31 //
32 // Class description:
33 //
34 // Base class for `touchable' objects capable of maintaining an
35 // association between parts of the geometrical hierarchy (volumes
36 // &/or solids) and their resultant transformation.
37 //
38 // Utilisation:
39 // -----------
40 // A touchable is a geometrical volume (solid) which has a unique
41 // placement in a detector description. It is an abstract base class which
42 // can be implemented in a variety of ways. Each way must provide the
43 // capabilities of obtaining the transformation and solid that is described
44 // by the touchable.
45 //
46 // All G4VTouchable implementations must respond to the two following
47 // "requests":
48 //
49 // 1) GetTranslation and GetRotation that return the components of the
50 // volume's transformation.
51 //
52 // 2) GetSolid that gives the solid of this touchable.
53 //
54 //
55 // Additional capabilities are available from implementations with more
56 // information. These have a default implementation that causes an exception.
57 //
58 // Several capabilities are available from touchables with physical volumes:
59 //
60 // 3) GetVolume gives the physical volume.
61 //
62 // 4) GetReplicaNumber or GetCopyNumber gives the copy number of the
63 // physical volume, either if it is replicated or not.
64 //
65 // Touchables that store volume hierarchy (history) have the whole stack of
66 // parent volumes available. Thus it is possible to add a little more state
67 // in order to extend its functionality. We add a "pointer" to a level and a
68 // member function to move the level in this stack. Then calling the above
69 // member functions for another level, the information for that level can be
70 // retrieved.
71 //
72 // The top of the history tree is, by convention, the world volume.
73 //
74 // 5) GetHistoryDepth gives the depth of the history tree.
75 //
76 // 6) GetReplicaNumber/GetCopyNumber, GetVolume, GetTranslation and
77 // GetRotation each can be called with a depth argument.
78 // They return the value of the respective level of the touchable.
79 //
80 // 7) MoveUpHistory(num) moves the current pointer inside the touchable
81 // to point "num" levels up the history tree. Thus, eg, calling
82 // it with num=1 will cause the internal pointer to move to the mother
83 // of the current volume.
84 // NOTE: this method MODIFIES the touchable.
85 //
86 // An update method, with different arguments is available, so that the
87 // information in a touchable can be updated:
88 //
89 // 8) UpdateYourself takes a physical volume pointer and can additionally
90 // take a NavigationHistory.
91
92 // History:
93 // Created: Paul Kent, August 1996
107 class G4VTouchable
108 {
109
110 public: // with description
111
112 G4VTouchable();
113 virtual ~G4VTouchable();
114 // Constructor and destructor.
115
116 virtual const G4ThreeVector& GetTranslation(G4int depth=0) const = 0;
117 virtual const G4RotationMatrix* GetRotation(G4int depth=0) const = 0;
118 // Accessors for translation and rotation.
119 virtual G4VPhysicalVolume* GetVolume(G4int depth=0) const;
120 virtual G4VSolid* GetSolid(G4int depth=0) const;
121 // Accessors for physical volumes and solid.
122
123 virtual G4int GetReplicaNumber(G4int depth=0) const;
124 inline G4int GetCopyNumber(G4int depth=0) const;
125 virtual G4int GetHistoryDepth() const;
126 virtual G4int MoveUpHistory(G4int num_levels=1);
127 // Methods for touchables with history.
128
129 virtual void UpdateYourself(G4VPhysicalVolume* pPhysVol,
130 const G4NavigationHistory* history=0);
131 // Update method.
132
133 public: // without description
134
135 // virtual void ResetLevel();
136
137 virtual const G4NavigationHistory* GetHistory() const;
138 // Should this method be deprecated ? It is used in G4Navigator!
139 };
140
141 #include "G4VTouchable.icc"
142
143 #endif
delta:geant4.10.00.p01 blyth$ find . -name '*.cc' -exec grep -H UpdateYourself {} \;
./source/geometry/management/src/G4VTouchable.cc:void G4VTouchable::UpdateYourself(G4VPhysicalVolume*,
./source/geometry/management/src/G4VTouchable.cc: G4Exception("G4VTouchable::UpdateYourself()", "GeomMgt0001",
./source/geometry/navigation/src/G4MultiNavigator.cc: touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
./source/geometry/navigation/src/G4PathFinder.cc: touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
delta:geant4.10.00.p01 blyth$
461 G4TouchableHistoryHandle
462 G4MultiNavigator::CreateTouchableHistoryHandle() const
463 {
464 G4Exception( "G4MultiNavigator::CreateTouchableHistoryHandle()",
465 "GeomNav0001", FatalException,
466 "Getting a touchable from G4MultiNavigator is not defined.");
467
468 G4TouchableHistory* touchHist;
469 touchHist= fpNavigator[0] -> CreateTouchableHistory();
470
471 G4VPhysicalVolume* locatedVolume= fLocatedVolume[0];
472 if( locatedVolume == 0 )
473 {
474 // Workaround to ensure that the touchable is fixed !! // TODO: fix
475 //
476 touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
477 }
478
479 return G4TouchableHistoryHandle(touchHist);
480 }
481
764 G4TouchableHandle
765 G4PathFinder::CreateTouchableHandle( G4int navId ) const
766 {
767 #ifdef G4DEBUG_PATHFINDER
768 if( fVerboseLevel > 2 )
769 {
770 G4cout << "G4PathFinder::CreateTouchableHandle : navId = "
771 << navId << " -- " << GetNavigator(navId) << G4endl;
772 }
773 #endif
774
775 G4TouchableHistory* touchHist;
776 touchHist= GetNavigator(navId) -> CreateTouchableHistory();
777
778 G4VPhysicalVolume* locatedVolume= fLocatedVolume[navId];
779 if( locatedVolume == 0 )
780 {
781 // Workaround to ensure that the touchable is fixed !! // TODO: fix
782
783 touchHist->UpdateYourself( locatedVolume, touchHist->GetHistory() );
784 }
785
786 #ifdef G4DEBUG_PATHFINDER
787 if( fVerboseLevel > 2 )
788 {
789 G4String VolumeName("None");
790 if( locatedVolume ) { VolumeName= locatedVolume->GetName(); }
791 G4cout << " Touchable History created at address " << touchHist
792 << " volume = " << locatedVolume << " name= " << VolumeName
793 << G4endl;
794 }
795 #endif
796
797 return G4TouchableHandle(touchHist);
798 }
source/geometry/navigation/include/G4Navigator.hh:
073 class G4Navigator
074 {
075 public: // with description
...
085 virtual G4double ComputeStep(const G4ThreeVector &pGlobalPoint,
086 const G4ThreeVector &pDirection,
087 const G4double pCurrentProposedStepLength,
088 G4double &pNewSafety);
089 // Calculate the distance to the next boundary intersected
090 // along the specified NORMALISED vector direction and
091 // from the specified point in the global coordinate
092 // system. LocateGlobalPointAndSetup or LocateGlobalPointWithinVolume
093 // must have been called with the same global point prior to this call.
094 // The isotropic distance to the nearest boundary is also
095 // calculated (usually an underestimate). The current
096 // proposed Step length is used to avoid intersection
097 // calculations: if it can be determined that the nearest
098 // boundary is >pCurrentProposedStepLength away, kInfinity
099 // is returned together with the computed isotropic safety
100 // distance. Geometry must be closed.
...
153 inline void LocateGlobalPointAndUpdateTouchableHandle(
154 const G4ThreeVector& position,
155 const G4ThreeVector& direction,
156 G4TouchableHandle& oldTouchableToUpdate,
157 const G4bool RelativeSearch = true);
158 // First, search the geometrical hierarchy like the above method
159 // LocateGlobalPointAndSetup(). Then use the volume found and its
160 // navigation history to update the touchable.
161
162 inline void LocateGlobalPointAndUpdateTouchable(
163 const G4ThreeVector& position,
164 const G4ThreeVector& direction,
165 G4VTouchable* touchableToUpdate,
166 const G4bool RelativeSearch = true);
167 // First, search the geometrical hierarchy like the above method
168 // LocateGlobalPointAndSetup(). Then use the volume found and its
169 // navigation history to update the touchable.
170
171 inline void LocateGlobalPointAndUpdateTouchable(
172 const G4ThreeVector& position,
173 G4VTouchable* touchableToUpdate,
174 const G4bool RelativeSearch = true);
175 // Same as the method above but missing direction.
...
202 inline G4TouchableHistory* CreateTouchableHistory() const;
203 inline G4TouchableHistory* CreateTouchableHistory(const G4NavigationHistory*) const;
204 // `Touchable' creation methods: caller has deletion responsibility.
205
206 virtual G4TouchableHistoryHandle CreateTouchableHistoryHandle() const;
207 // Returns a reference counted handle to a touchable history.
...
344 protected: // without description
345
346 G4double kCarTolerance;
347 // Geometrical tolerance for surface thickness of shapes.
348
349 //
350 // BEGIN State information
351 //
352
353 G4NavigationHistory fHistory;
354 // Transformation and history of the current path
355 // through the geometrical hierarchy.
examples/extended/parameterisations/Par01/src/Par01PionShowerModel.cc:
199 void Par01PionShowerModel::FillFakeStep(const Par01EnergySpot &eSpot)
200 {
201 //-----------------------------------------------------------
202 // find in which volume the spot is.
203 //-----------------------------------------------------------
204 if (!fNaviSetup)
205 {
206 fpNavigator->
207 SetWorldVolume(G4TransportationManager::GetTransportationManager()->
208 GetNavigatorForTracking()->GetWorldVolume());
209 fpNavigator->
210 LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(),
211 G4ThreeVector(0.,0.,0.),
212 fTouchableHandle,
213 false);
214 fNaviSetup = true;
215 }
216 else
217 {
218 fpNavigator->
219 LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(),
220 G4ThreeVector(0.,0.,0.),
221 fTouchableHandle);
222 }
G4TouchableHistory to DetectorElement
...
...
231 const DetectorElement* DsPmtSensDet::SensDetElem(const G4TouchableHistory& hist)
232 {
233 const IDetectorElement* idetelem = 0;
234 int steps=0;
235
236 if (!hist.GetHistoryDepth()) {
237 error() << "DsPmtSensDet::SensDetElem given empty touchable history" << endreq;
238 return 0;
239 }
240
241 StatusCode sc =
242 m_t2de->GetBestDetectorElement(&hist,m_sensorStructures,idetelem,steps);
243 if (sc.isFailure()) { // verbose warning
244 warning() << "Failed to find detector element in:\n";
245 for (size_t ind=0; ind<m_sensorStructures.size(); ++ind) {
246 warning() << "\t\t" << m_sensorStructures[ind] << "\n";
247 }
248 warning() << "\tfor touchable history:\n";
249 for (int ind=0; ind < hist.GetHistoryDepth(); ++ind) {
250 warning() << "\t (" << ind << ") "
251 << hist.GetVolume(ind)->GetName() << "\n";
252 }
253 warning() << endreq;
254 return 0;
255 }
256
257 return dynamic_cast<const DetectorElement*>(idetelem);
258 }
...
... //