Skip to content
Snippets Groups Projects
Commit f5909157 authored by lintao@ihep.ac.cn's avatar lintao@ihep.ac.cn
Browse files

WIP: implement VolumeID and CellID.

parent 0f85604b
No related branches found
No related tags found
No related merge requests found
...@@ -12,6 +12,8 @@ find_package(DD4hep COMPONENTS DDG4 REQUIRED) ...@@ -12,6 +12,8 @@ find_package(DD4hep COMPONENTS DDG4 REQUIRED)
set(DetSimSD_srcs set(DetSimSD_srcs
src/CalorimeterSensDetTool.cpp src/CalorimeterSensDetTool.cpp
src/DDG4SensitiveDetector.cpp
) )
gaudi_add_module(DetSimSD ${DetSimSD_srcs} gaudi_add_module(DetSimSD ${DetSimSD_srcs}
......
...@@ -28,10 +28,9 @@ class DDG4SensitiveDetector: public G4VSensitiveDetector { ...@@ -28,10 +28,9 @@ class DDG4SensitiveDetector: public G4VSensitiveDetector {
public: public:
typedef G4THitsCollection<dd4hep::sim::Geant4Hit> HitCollection; typedef G4THitsCollection<dd4hep::sim::Geant4Hit> HitCollection;
typedef dd4hep::sim::Geant4Hit::Contribution HitContribution; typedef dd4hep::sim::Geant4Hit::Contribution HitContribution;
typedef dd4hep::sim::Geant4StepHandler StepHandler;
public: public:
DDG4SensitiveDetector(); DDG4SensitiveDetector(const std::string& name, dd4hep::Detector& description);
public: public:
// Geant4 interface // Geant4 interface
......
#include "DetSimSD/DDG4SensitiveDetector.h" #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 void
DDG4SensitiveDetector::Initialize(G4HCofThisEvent* HCE) { DDG4SensitiveDetector::Initialize(G4HCofThisEvent* HCE) {
...@@ -17,15 +49,29 @@ DDG4SensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) { ...@@ -17,15 +49,29 @@ DDG4SensitiveDetector::EndOfEvent(G4HCofThisEvent* HCE) {
} }
long long long long
DDG4SensitiveDetector::getVolumeID(G4Step* step) { DDG4SensitiveDetector::getVolumeID(G4Step* aStep) {
long long vid = 0;
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 long long
DDG4SensitiveDetector::getCellID(G4Step* step) { 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;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment