File indexing completed on 2025-03-13 08:20:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DDG4/Geant4TouchableHandler.h>
0016 #include <DDG4/Geant4GeometryInfo.h>
0017
0018 #include <G4Step.hh>
0019 #include <G4VTouchable.hh>
0020
0021 using namespace dd4hep::sim;
0022
0023
0024 Geant4TouchableHandler::Geant4TouchableHandler(const G4Step* step, bool use_post_step_point) {
0025 const G4StepPoint* p = use_post_step_point ? step->GetPostStepPoint() : step->GetPreStepPoint();
0026 touchable = p->GetTouchable();
0027 }
0028
0029
0030 Geant4TouchableHandler::Geant4TouchableHandler(const G4Step* step) {
0031 touchable = step->GetPreStepPoint()->GetTouchable();
0032 }
0033
0034
0035 int Geant4TouchableHandler::depth() const {
0036 return touchable->GetHistoryDepth();
0037 }
0038
0039
0040 Geant4TouchableHandler::Geant4PlacementPath Geant4TouchableHandler::placementPath(bool exception) const {
0041 Geant4PlacementPath path_val;
0042 if ( touchable ) {
0043 int i, n=touchable->GetHistoryDepth();
0044 path_val.reserve(n);
0045 for (i=0; i < n; ++i) {
0046 G4VPhysicalVolume* pv = touchable->GetVolume(i);
0047 path_val.emplace_back(pv);
0048 }
0049 return path_val;
0050 }
0051 if ( exception ) {
0052 except("Geant4TouchableHandler", "Attempt to access invalid G4 touchable object.");
0053 }
0054 return path_val;
0055 }
0056
0057
0058 std::string Geant4TouchableHandler::placementPath(const Geant4PlacementPath& path, bool reverse) {
0059 std::string path_name;
0060 if ( reverse ) {
0061 for (Geant4PlacementPath::const_reverse_iterator pIt = path.rbegin(); pIt != path.rend(); ++pIt) {
0062 path_name += "/"; path_name += (*pIt)->GetName();
0063 }
0064 }
0065 else {
0066 for (Geant4PlacementPath::const_iterator pIt = path.begin(); pIt != path.end(); ++pIt) {
0067 path_name += "/"; path_name += (*pIt)->GetName();
0068 }
0069 }
0070 return path_name;
0071 }
0072
0073
0074 std::string Geant4TouchableHandler::path() const {
0075 return Geant4TouchableHandler::placementPath(this->placementPath());
0076 }
0077