diff --git a/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp b/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp index 20a9960e613f482cd0540ebfeada23a470f42cda..6d772793a712e0afb9b273f458ec9f88a36345a9 100644 --- a/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp +++ b/DDExamples/CLICSiD/src/PolyhedraBarrel_VolMgrTest.cpp @@ -69,7 +69,7 @@ void VolIDTest::walk(DetElement e, VolIDs ids, size_t depth, size_t mx_depth) c } if ( pv.volume().isSensitive() ) { stringstream err, log; - VolumeManager::VolumeID vid = m_iddesc.encode(child_ids); + VolumeID vid = m_iddesc.encode(child_ids); try { DetElement det = m_mgr.lookupDetector(vid); DetElement det_elem = m_mgr.lookupDetElement(vid); diff --git a/DDExamples/CLICSiDSimu/src/SteppingAction.cpp b/DDExamples/CLICSiDSimu/src/SteppingAction.cpp index 07512d66bfd53eb963672f2aeb736fa42ed2aa7d..86ad2758452e2883c928a23657b7f621ee17036f 100644 --- a/DDExamples/CLICSiDSimu/src/SteppingAction.cpp +++ b/DDExamples/CLICSiDSimu/src/SteppingAction.cpp @@ -1,3 +1,5 @@ +#include "DD4hep/Detector.h" +#include "DD4hep/Readout.h" #include "DDG4/Geant4StepHandler.h" #include "DDG4/Geant4Converter.h" @@ -7,6 +9,8 @@ #include "G4PVPlacement.hh" #include "G4VSensitiveDetector.hh" +// C/C++ include files +#include <sstream> using namespace DD4hep; using namespace DD4hep::Simulation; @@ -19,10 +23,10 @@ SteppingAction::~SteppingAction() { } +#include "G4StepPoint.hh" void SteppingAction::UserSteppingAction(const G4Step* aStep) { Geant4StepHandler step(aStep); - Geant4Mapping& mapping = Geant4Mapping::instance(); SiMaterial = G4Material::GetMaterial("Silicon"); TPCGasMaterial = G4Material::GetMaterial("Argon"); @@ -57,22 +61,39 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) { edep/keV); } - ::printf(" Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f) Mom:%7.0f %7.0f %7.0f \n", - long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z()); - ::printf(" pre-Vol: %s Status:%s SD:%s\n", - step.volName(step.pre,"----"), step.preStepStatus(), step.sdName(step.pre,"----")); - ::printf(" post-Vol:%s Status:%s SD:%s\n", - step.volName(step.post,"----"), step.postStepStatus(), step.sdName(step.post,"----")); - - const G4VPhysicalVolume* pv = step.volume(step.post); - Geometry::PlacedVolume place = mapping.placement(pv); - if ( place.isValid() ) { - if ( place.volume().isSensitive() ) { - // Example code to access the physical vlume and the cell id - //Geometry::VolumeManager vm = mapping.lcdd().volumeManager(); - //Geometry::VolumeManager::VolumeID cell_id = vm.lookupID(place); - //const TGeoNode* tpv = pv.ptr(); - //printf(" Found Sensitive TGeoNode:%s CellID: %lld!\n",place.name(),cell_id); + if ( step.isSensitive(step.post) ) { + ::printf(" Track:%08ld Pos:(%8f %8f %8f) -> (%f %f %f) Mom:%7.0f %7.0f %7.0f \n", + long(step.track), pos1.X(), pos1.Y(), pos1.Z(), pos2.X(), pos2.Y(), pos2.Z(), mom.X(), mom.Y(), mom.Z()); + ::printf(" pre-Vol: %s Status:%s SD:%s\n", + step.volName(step.pre,"----"), step.preStepStatus(), step.sdName(step.pre,"----")); + ::printf(" post-Vol:%s Status:%s SD:%s\n", + step.volName(step.post,"----"), step.postStepStatus(), step.sdName(step.post,"----")); + } + Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager(); + const G4VPhysicalVolume* pv = step.volume(step.post); + Geometry::PlacedVolume place = volMgr.placement(pv); + if ( !place.isValid() ) { + ::printf(" --> Severe ERROR: incomplete placement map from Geant4 conversion.\n"); + } + else { + VolumeID id = volMgr.volumeID(step.postTouchable()); + if ( id == Geant4VolumeManager::InvalidPath ) { + ::printf(" --> Severe ERROR: Invalid placement path: touchable corrupted?\n"); + } + else if ( id == Geant4VolumeManager::Insensitive ) { + ::printf(" --> WARNING: Only sensitive volumes may be decoded.\n"); + } + else if ( id == Geant4VolumeManager::NonExisting ) { + ::printf(" --> WARNING: non existing placement path.\n"); + } + else { + std::stringstream str; + Geant4VolumeManager::VolIDDescriptor dsc; + Geant4VolumeManager::VolIDFields& fields = dsc.second; + volMgr.volumeDescriptor(step.postTouchable(),dsc); + for(Geant4VolumeManager::VolIDFields::iterator i=fields.begin(); i!=fields.end();++i) + str << (*i).first->name() << "=" << (*i).second << " "; + ::printf(" --> CellID: %X [%X] -> %s\n",id,dsc.first,str.str().c_str()); } } }