16 #include "DD4hep/Detector.h"
17 #include "DD4hep/detail/VolumeManagerInterna.h"
19 #include "TGeoManager.h"
26 const VolumeManagerContext*
41 double l[3], e[3], g[3];
43 const VolumeManagerContext* context =
findContext( cell ) ;
48 DetElement
det = context->element ;
51 #if 0 // this uses the deprecated VolumeManagerContext::placement
53 PlacedVolume pv = context->placement ;
55 if( ! pv.volume().isSensitive() )
58 SensitiveDetector sd = pv.volume().sensitiveDetector();
59 Readout r = sd.readout() ;
69 Segmentation seg = r.segmentation() ;
70 Position local = seg.position(cell);
72 local.GetCoordinates(l);
74 const TGeoMatrix& volToElement = context->toElement();
75 volToElement.LocalToMaster(l, e);
77 const TGeoMatrix& elementToGlobal = det.nominal().worldTransformation();
78 elementToGlobal.LocalToMaster(e, g);
81 return Position(g[0], g[1], g[2]);
91 TGeoManager *geoManager =
_description->world().volume()->GetGeoManager() ;
93 PlacedVolume pv = geoManager->FindNode( global.x() , global.y() , global.z() ) ;
95 if( pv.isValid() && pv.volume().isSensitive() ) {
97 TGeoHMatrix* m = geoManager->GetCurrentMatrix() ;
100 global.GetCoordinates( g ) ;
101 m->MasterToLocal( g, l );
103 SensitiveDetector sd = pv.volume().sensitiveDetector();
104 Readout r = sd.readout() ;
107 PlacedVolume::VolIDs volIDs ;
110 TGeoPhysicalNode pN( geoManager->GetPath() ) ;
112 unsigned motherCount = 0 ;
114 while( pN.GetMother( motherCount ) != NULL ){
116 PlacedVolume mPv = pN.GetMother( motherCount++ ) ;
118 if( mPv.isValid() && pN.GetMother( motherCount ) != NULL )
122 VolumeID volIDPVs = r.idSpec().encode( volIDs ) ;
124 result = r.segmentation().cellID( Position( l[0], l[1], l[2] ) , global, volIDPVs );
192 bool containsPoint(
const DetElement&
det,
const Position& global ) {
194 if( det.volume().isValid() and det.volume().solid().isValid() ) {
197 global.GetCoordinates( g ) ;
199 det.nominal().worldTransformation().MasterToLocal( g, l );
201 return det.volume().solid()->Contains( l ) ;
210 const DetElement& d)
const {
212 DetElement det = ( d.isValid() ? d :
_description->world() ) ;
216 if( containsPoint( det, global ) ) {
218 if( det.children().empty() )
224 for(
auto it : det.children() ){
229 if( containsPoint( it.second , global ) ){
234 if( result.isValid() ){
236 if( result.children().empty() )
245 return DetElement() ;
252 pos.GetCoordinates( l ) ;
256 if( pv.volume().solid()->Contains( l ) ) {
261 int ndau = pv->GetNdaughters() ;
268 PlacedVolume result ;
269 for (
int i = 0 ; i < ndau; ++i) {
271 PlacedVolume pvDau = pv->GetDaughter( i );
272 pvDau->MasterToLocal( l , locPos ) ;
281 if( pvDau.volume().solid()->Contains( locPos ) ) {
288 if( result.isValid() ){
290 if( result->GetNdaughters() == 0 ){
293 return findPlacement( Position( locPos[0], locPos[1] , locPos[2] ), result , locPos , volIDs) ;
298 return PlacedVolume() ;
305 if (det.volume().isValid() and det.volume().isSensitive()) {
306 SensitiveDetector sd = det.volume().sensitiveDetector();
307 if (sd.isValid() and sd.readout().isValid()) {
324 if( pv.volume().isSensitive() ){
325 SensitiveDetector sd = pv.volume().sensitiveDetector();
326 if (sd.isValid() and sd.readout().isValid()) {
331 for (Int_t idau = 0, ndau = pv->GetNdaughters(); idau < ndau; ++idau) {
333 PlacedVolume dpv = pv->GetDaughter(idau);
344 if( context ==
nullptr )
return { };
345 dd4hep::Readout r =
findReadout( context->element ) ;
346 dd4hep::Segmentation seg = r.segmentation() ;
347 return seg.cellDimensions( cell );
const VolumeManagerContext * findContext(const CellID &cellID) const
Find the context with DetElement, placements etc for a given cellID of a sensitive volume...
VolumeManager _volumeManager
const Detector * _description
CellID cellID(const Position &global) const
Return the global cellID for the given global position.
PlacedVolume findPlacement(const Position &point, const PlacedVolume &mother, double locPos[3], PlacedVolume::VolIDs &volIDs) const
Find the lowest daughter Placement in the given Placement that contains the point (in the coordinate ...
DetElement findDetElement(const Position &global, const DetElement &det=DetElement()) const
Find the DetElement that contains the given point - if no DetElement is found, an invalid DetElement ...
std::vector< double > cellDimensions(const CellID &cell) const
Returns the segmentation.cellDimensions.
Position position(const CellID &cellID) const
Return the global position for a given cellID of a sensitive volume.
Readout findReadout(const DetElement &det) const
Find the readout object for the given DetElement.
Position positionNominal(const CellID &cellID) const
Return the nominal global position for a given cellID of a sensitive volume.
DDSegmentation::CellID CellID
DDSegmentation::VolumeID VolumeID