diff --git a/Simulation/DetSimSD/include/DetSimSD/DDG4SensitiveDetector.h b/Simulation/DetSimSD/include/DetSimSD/DDG4SensitiveDetector.h index cee8826ee89012deb132843baa924dffef193a20..687771e344b9f12ae553e56888b1222288fefbaf 100644 --- a/Simulation/DetSimSD/include/DetSimSD/DDG4SensitiveDetector.h +++ b/Simulation/DetSimSD/include/DetSimSD/DDG4SensitiveDetector.h @@ -52,6 +52,10 @@ public: // from the current sensitive volume to the world volume virtual long long getCellID(const G4Step* step); + // Returns the position of center of cell, according cell ID + // if cellID not set, getCellID(step) will be invoke + // unit mm + virtual dd4hep::Position getNominalPosition(const G4Step* step, const long long cellID=0); protected: /// Reference to the detector description object diff --git a/Simulation/DetSimSD/src/CaloSensitiveDetector.cpp b/Simulation/DetSimSD/src/CaloSensitiveDetector.cpp index 4a7e5c930c1a35832931c9e82a4d60d722e5634d..11fb8cddabccf91713e068f0a4396772079ce2c1 100644 --- a/Simulation/DetSimSD/src/CaloSensitiveDetector.cpp +++ b/Simulation/DetSimSD/src/CaloSensitiveDetector.cpp @@ -48,10 +48,18 @@ 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())); + if(m_isMergeEnabled){ + dd4hep::Position posCellCenter = getNominalPosition(step, id); + hit = new CalorimeterHit(posCellCenter); + m_hitMap[id] = hit; + } + else hit = new CalorimeterHit(pos); hit->cellID = id; //getCellID( step ); m_hc->insert(hit); - if(m_isMergeEnabled) m_hitMap[id] = hit; } hit->truth.push_back(contrib); hit->energyDeposit += contrib.deposit; diff --git a/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp b/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp index 4300de813cb9adc29b3be2ac3da555d5eafb2118..a1698ee3cd3cbe43b6ae856112a2edb2f9f20ed0 100644 --- a/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp +++ b/Simulation/DetSimSD/src/DDG4SensitiveDetector.cpp @@ -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()); +}