Skip to content
Snippets Groups Projects
Commit cb264201 authored by FU Chengdong's avatar FU Chengdong
Browse files

change position from first contribution to cell center

parent e64bd50b
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ public:
// from the current sensitive volume to the world volume
virtual long long getCellID(const G4Step* step);
// Returns the position of center of cell
virtual dd4hep::Position getNominalPosition(const G4Step* step, const long long cellID=0);
protected:
/// Reference to the detector description object
......
......@@ -48,7 +48,12 @@ CaloSensitiveDetector::ProcessHits(G4Step* step, G4TouchableHistory*) {
}
// G4cout << "----------- Geant4GenericSD<Calorimeter>::buildHits : position : " << pos << G4endl;
if ( !hit ) {
hit = new CalorimeterHit(pos);
// not applicable for segmentation case
//G4ThreeVector local(0,0,0);
//G4ThreeVector global = h.preTouchable()->GetHistory()->GetTopTransform().InverseTransformPoint(local);
//hit = new CalorimeterHit(dd4hep::Position(global.x(), global.y(), global.z()));
dd4hep::Position posCellCenter = getNominalPosition(step, id);
hit = new CalorimeterHit(posCellCenter);
hit->cellID = id; //getCellID( step );
m_hc->insert(hit);
if(m_isMergeEnabled) m_hitMap[id] = hit;
......
......@@ -19,7 +19,8 @@
// convert from CLHEP to DD4hep
static const double MM_2_CM = (dd4hep::millimeter/CLHEP::millimeter);
// convert from DD4hep to CLHEP
static const double CM_2_MM = (CLHEP::millimeter/dd4hep::millimeter);
DDG4SensitiveDetector::DDG4SensitiveDetector(const std::string& name, dd4hep::Detector& description)
: G4VSensitiveDetector(name), m_detDesc(description),
......@@ -73,3 +74,15 @@ DDG4SensitiveDetector::getCellID(const G4Step* step) {
}
return volID;
}
dd4hep::Position
DDG4SensitiveDetector::getNominalPosition(const G4Step* step, long long cellID) {
if(cellID==0) cellID = getCellID(step);
dd4hep::sim::Geant4StepHandler h(step);
dd4hep::Segmentation seg = m_readout.segmentation();
dd4hep::Position loc(0,0,0);
if ( seg.isValid() ) loc = seg.position(cellID);
G4ThreeVector local(loc.x()*CM_2_MM, loc.y()*CM_2_MM, loc.z()*CM_2_MM);
G4ThreeVector global = h.preTouchable()->GetHistory()->GetTopTransform().InverseTransformPoint(local);
return dd4hep::Position(global.x(), global.y(), global.z());
}
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