diff --git a/DDG4/include/DDG4/Geant4SensitiveDetector.h b/DDG4/include/DDG4/Geant4SensitiveDetector.h index c80ee4743928e8390a05f1901dd40cfe3cf8ab26..2eaba755e99967c313c8943ada9d0fb096c827fe 100644 --- a/DDG4/include/DDG4/Geant4SensitiveDetector.h +++ b/DDG4/include/DDG4/Geant4SensitiveDetector.h @@ -104,7 +104,12 @@ namespace DD4hep { /// Returns the volumeID of the sensitive volume corresponding to the step - /// combining the VolIDS of the complete geometry path (Geant4TouchableHistory) // from the current sensitive volume to the world volume - long long getVolumeID(G4Step* step ) ; + long long getVolumeID(G4Step* step); + + /// Returns the volumeID of the sensitive volume corresponding to the step - + /// combining the VolIDS of the complete geometry path (Geant4TouchableHistory) + // from the current sensitive volume to the world volume + long long getCellID(G4Step* step); /** G4VSensitiveDetector interface: Method invoked at the begining of each event. * The hits collection(s) created by this sensitive detector must diff --git a/DDG4/legacy/Geant4CalorimeterSD.cpp b/DDG4/legacy/Geant4CalorimeterSD.cpp index 7ebef11c4b327a5f74ee1b04a865c031bba8c4d3..31185c4d00514d658229731292f05e8497f1f65a 100644 --- a/DDG4/legacy/Geant4CalorimeterSD.cpp +++ b/DDG4/legacy/Geant4CalorimeterSD.cpp @@ -39,15 +39,11 @@ namespace DD4hep { namespace Simulation { HitContribution contrib = Geant4Hit::extractContribution(step); Geant4CalorimeterHit* hit=find(collection(0),HitPositionCompare<Geant4CalorimeterHit>(pos)); - // G4cout << "----------- Geant4GenericSD<Calorimeter>::buildHits : position : " << pos << G4endl ; - + // G4cout << "----------- Geant4GenericSD<Calorimeter>::buildHits : position : " << pos << G4endl; if ( !hit ) { - - hit = new Geant4CalorimeterHit(pos) ; - - hit->cellID = getVolumeID( step ) ; - - collection(0)->insert(hit) ; + hit = new Geant4CalorimeterHit(pos); + hit->cellID = getCellID( step ); + collection(0)->insert(hit); } hit->truth.push_back(contrib); hit->energyDeposit += contrib.deposit; diff --git a/DDG4/src/Geant4SensitiveDetector.cpp b/DDG4/src/Geant4SensitiveDetector.cpp index bbf4e3042f90cdf93299917eab7aa49d7a6af517..3ac6a52fe246c9f98ca7d536271a15f91c1aa4ba 100644 --- a/DDG4/src/Geant4SensitiveDetector.cpp +++ b/DDG4/src/Geant4SensitiveDetector.cpp @@ -16,6 +16,7 @@ #include "DDG4/Geant4SensitiveDetector.h" #include "DDG4/Geant4Converter.h" #include "DDG4/Geant4Hits.h" +#include "DD4hep/Segmentations.h" #include "DD4hep/Printout.h" #include "DD4hep/LCDD.h" @@ -184,13 +185,8 @@ void Geant4SensitiveDetector::dumpStep(G4Step* st, G4TouchableHistory* /* histor } long long Geant4SensitiveDetector::getVolumeID(G4Step* aStep) { - - //Geant4Mapping& mapping = Geant4Mapping::instance(); - Geant4StepHandler step(aStep); - Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager(); - VolumeID id = volMgr.volumeID(step.preTouchable()); #if 0 // additional checks ... @@ -220,3 +216,19 @@ long long Geant4SensitiveDetector::getVolumeID(G4Step* aStep) { return id; } + +long long Geant4SensitiveDetector::getCellID(G4Step* s) { + StepHandler h(s); + Geant4VolumeManager volMgr = Geant4Mapping::instance().volumeManager(); + VolumeID volID = volMgr.volumeID(h.preTouchable()); + Geometry::Segmentation seg = m_readout.segmentation(); + if ( seg.isValid() ) { + G4ThreeVector global = 0.5 * ( h.prePosG4()+h.postPosG4()); + G4ThreeVector local = h.preTouchable()->GetHistory()->GetTopTransform().TransformPoint(global); + Position loc(local.x()*MM_2_CM, local.y()*MM_2_CM, local.z()*MM_2_CM); + Position glob(global.x()*MM_2_CM, global.y()*MM_2_CM, global.z()*MM_2_CM); + VolumeID cID = seg.cellID(loc,glob,volID); + return cID; + } + return volID; +}