Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 08:20:18

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
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 /// Default constructor. Takes the step's pre-touchable
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 /// Default constructor. Takes the step's pre-touchable
0030 Geant4TouchableHandler::Geant4TouchableHandler(const G4Step* step)  {
0031   touchable = step->GetPreStepPoint()->GetTouchable();
0032 }
0033 
0034 /// Touchable history depth
0035 int Geant4TouchableHandler::depth() const   {
0036   return touchable->GetHistoryDepth();
0037 }
0038 
0039 /// Helper: Generate placement path from touchable object
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 /// Assemble Geant4 volume path
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 /// Helper: Access the placement path of a Geant4 touchable object as a string
0074 std::string Geant4TouchableHandler::path()  const   {
0075   return Geant4TouchableHandler::placementPath(this->placementPath());
0076 }
0077