diff --git a/Simulation/DetSimSD/CMakeLists.txt b/Simulation/DetSimSD/CMakeLists.txt index fff9acdf13864e6b6350562b75d99bd02b1819f6..12ca028212dac74b7a247f685b4f962a1285b4bb 100644 --- a/Simulation/DetSimSD/CMakeLists.txt +++ b/Simulation/DetSimSD/CMakeLists.txt @@ -12,6 +12,8 @@ find_package(DD4hep COMPONENTS DDG4 REQUIRED) set(DetSimSD_srcs src/CalorimeterSensDetTool.cpp + + src/DDG4SensitiveDetector.cpp ) gaudi_add_module(DetSimSD ${DetSimSD_srcs} diff --git a/Simulation/DetSimSD/DetSimSD/DDG4SensitiveDetector.h b/Simulation/DetSimSD/DetSimSD/DDG4SensitiveDetector.h index e86ea10faa5336bf3d8d3444f23546d903b584fa..846044b953e10913b6768c4e66a7a117b33ca38a 100644 --- a/Simulation/DetSimSD/DetSimSD/DDG4SensitiveDetector.h +++ b/Simulation/DetSimSD/DetSimSD/DDG4SensitiveDetector.h @@ -28,10 +28,9 @@ class DDG4SensitiveDetector: public G4VSensitiveDetector { public: typedef G4THitsCollection<dd4hep::sim::Geant4Hit> HitCollection; typedef dd4hep::sim::Geant4Hit::Contribution HitContribution; - typedef dd4hep::sim::Geant4StepHandler StepHandler; public: - DDG4SensitiveDetector(); + DDG4SensitiveDetector(const std::string& name, dd4hep::Detector& description); public: // Geant4 interface diff --git a/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp b/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp index ed293b02c3561e755fc728f83c2d087ce9fd5899..e4b86aa9f4a4d2df3ac82c5319021146dc7cf7cf 100644 --- a/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp +++ b/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp @@ -1,5 +1,37 @@ #include "DetSimSD/DDG4SensitiveDetector.h" +#include "DDG4/Geant4SensitiveDetector.h" +#include "DDG4/Geant4Converter.h" +#include "DDG4/Geant4Hits.h" +#include "DD4hep/Segmentations.h" + +#include "DD4hep/Printout.h" +#include "DD4hep/Detector.h" + +// Geant4 include files +#include "G4Step.hh" +#include "G4PVPlacement.hh" + +// ROOT include files +#include "TGeoNode.h" + +#include "DD4hep/DD4hepUnits.h" +#include "CLHEP/Units/SystemOfUnits.h" + +// convert from CLHEP to DD4hep +static const double MM_2_CM = (dd4hep::millimeter/CLHEP::millimeter); + + +DDG4SensitiveDetector::DDG4SensitiveDetector(const std::string& name, dd4hep::Detector& description) + : G4VSensitiveDetector(name), m_detDesc(description), + m_detector(), m_sensitive(), m_readout(), + m_hce(nullptr) { + m_detector = description.detector(name); + m_sensitive = description.sensitiveDetector(name); + m_readout = m_sensitive.readout(); + +} + void DDG4SensitiveDetector::Initialize(G4HCofThisEvent* HCE) { @@ -17,15 +49,29 @@ DDG4SensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) { } long long -DDG4SensitiveDetector::getVolumeID(G4Step* step) { - long long vid = 0; +DDG4SensitiveDetector::getVolumeID(G4Step* aStep) { + + dd4hep::sim::Geant4StepHandler step(aStep); + dd4hep::sim::Geant4VolumeManager volMgr = dd4hep::sim::Geant4Mapping::instance().volumeManager(); + dd4hep::VolumeID id = volMgr.volumeID(step.preTouchable()); - return vid; + return id; } long long DDG4SensitiveDetector::getCellID(G4Step* step) { - long long vid = 0; + dd4hep::sim::Geant4StepHandler h(step); + dd4hep::sim::Geant4VolumeManager volMgr = dd4hep::sim::Geant4Mapping::instance().volumeManager(); + dd4hep::VolumeID volID = volMgr.volumeID(h.preTouchable()); - return vid; + dd4hep::Segmentation seg = m_readout.segmentation(); + if ( seg.isValid() ) { + G4ThreeVector global = 0.5 * ( h.prePosG4()+h.postPosG4()); + G4ThreeVector local = h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global); + dd4hep::Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM); + dd4hep::Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM); + dd4hep::VolumeID cID = seg.cellID(loc,glob,volID); + return cID; + } + return volID; }