diff --git a/DDRec/include/DDRec/SurfaceManager.h b/DDRec/include/DDRec/SurfaceManager.h index 7a7150d566602114ca7c30e2ffc3a69de59f6ce3..7700e4c20daded37f207c11ae288abaac3716a8b 100644 --- a/DDRec/include/DDRec/SurfaceManager.h +++ b/DDRec/include/DDRec/SurfaceManager.h @@ -6,33 +6,40 @@ namespace DD4hep { namespace DDRec { - /** Surface manager class that allows to access all surfaces - * assigned to a DetElement and all its daughters. - * + /// typedef for surface maps, keyed by the cellID + typedef std::map< unsigned long, DD4hep::DDRec::Surface*> SurfaceMap ; + + /** Surface manager class that holds maps of surfaces for all known + * sensitive detector types and individual sub detectors. + * Maps can be retrieved via detector name. + * * @author F.Gaede, DESY - * @date Apr, 11 2014 + * @date May, 11 2015 * @version $Id$ */ class SurfaceManager { + typedef std::map< std::string, SurfaceMap > SurfaceMapsMap ; + public: SurfaceManager(); ~SurfaceManager(); - /** Get the list of all surfaces added to this DetElement and all its daughters - - * instantiate SurfaceManager with lcdd.world() to get all surfaces. + /** Get the maps of all surfaces associated to the given detector or + * type of detectors, e.g. map("tracker") returns a map with all surfaces + * assigned to tracking detectors. Returns 0 if no map exists. */ - // const SurfaceList& surfaceList() { return _sL ; } + const SurfaceMap* map( const std::string name ) const ; protected : - // SurfaceList _sL ; - // const Geometry::DetElement& _det ; - // /// initializes surfaces from VolSurfaces assigned to this DetElement in detector construction - // void initialize() ; + /// initialize all known surface maps + void initialize() ; + + SurfaceMapsMap _map ; }; } /* namespace DDRec */ diff --git a/DDRec/src/SurfaceManager.cpp b/DDRec/src/SurfaceManager.cpp index 2d8470380f71be8669f5ab8d185be39b1b98ebcb..3bcb5983806bb1d6779fe9436d413e2f27002549 100644 --- a/DDRec/src/SurfaceManager.cpp +++ b/DDRec/src/SurfaceManager.cpp @@ -1,9 +1,10 @@ #include "DDRec/SurfaceManager.h" -#include "DDRec/DetectorSurfaces.h" -#include "DD4hep/Detector.h" +#include "DDRec/SurfaceHelper.h" +//#include "DDRec/DetectorSurfaces.h" +//#include "DD4hep/Detector.h" #include "DD4hep/LCDD.h" -#include "DD4hep/VolumeManager.h" +//#include "DD4hep/VolumeManager.h" namespace DD4hep { @@ -12,82 +13,62 @@ namespace DD4hep { namespace DDRec { - // SurfaceManager::SurfaceManager(DD4hep::Geometry::DetElement const& e) : _det(e) { + SurfaceManager::SurfaceManager(){ - // initialize() ; - // } + initialize() ; + } - // SurfaceManager::~SurfaceManager(){ - // // nothing to do - // } + SurfaceManager::~SurfaceManager(){ + // nothing to do + } - // void SurfaceManager::initialize() { - - // // have to populate the volume manager once in order to have - // // the volumeIDs attached to the DetElements - // LCDD& lcdd = LCDD::getInstance(); - // static VolumeManager volMgr( lcdd , "volMan" , lcdd.world() ) ; - - - // //------------------ breadth first tree traversal --------- - // std::list< DetElement > dets ; - // std::list< DetElement > daugs ; - // std::list< DetElement > gdaugs ; - - // daugs.push_back( _det ) ; - - // while( ! daugs.empty() ) { - - // for( std::list< DetElement >::iterator li=daugs.begin() ; li != daugs.end() ; ++li ){ - // DetElement dau = *li ; - // DetElement::Children chMap = dau.children() ; - // for ( DetElement::Children::const_iterator it=chMap.begin() ; it != chMap.end() ; ++it ){ - // DetElement de = (*it).second ; - // gdaugs.push_back( de ) ; - // } - // } - // dets.splice( dets.end() , daugs ) ; - // daugs.splice( daugs.end() , gdaugs ) ; - // } - // //------------------ end tree traversal --------- - - // // std::cout << " **** SurfaceManager::initialize() : # DetElements found " << dets.size() << std::endl ; - - // for( std::list< DetElement >::iterator li=dets.begin() ; li != dets.end() ; ++li ) { - - // DetElement det = (*li) ; - - - - // // create surfaces - // DetectorSurfaces ds( det ) ; - - // const SurfaceList& detSL = ds.surfaceList() ; - - - // // // ---------------------- debug printout - // // std::cout << " ---- DetElement id: " << det.volumeID() << " name : " << det.name() << " #surfaces : " << detSL.size() << std::endl ; - // // PlacedVolume pv = det.placement() ; - // // if( pv.isValid() ) { - // // try{ // needed as above is also true for world whcih has invalid placment ... - // // PlacedVolume::VolIDs volIDs = pv.volIDs() ; - // // for(unsigned i=0,n=volIDs.size(); i<n ; ++i){ - // // std::cout << " " << volIDs[i].first << " : " << volIDs[i].second << std::endl ; - // // } - // // }catch(...){} - // // }else{ - // // std::cout << " invalid placement for DetElement ??? !! " << std::endl ; - // // } - // // // ------------------------- end debug printout - - - // // and add copy them to this list - // _sL.insert( _sL.end(), detSL.begin(), detSL.end() ); - // } + const SurfaceMap* SurfaceManager::map( const std::string name ) const { + + SurfaceMapsMap::const_iterator it = _map.find( name ) ; + + if( it != _map.end() ){ + + return & it->second ; + } + + return 0 ; + } + + void SurfaceManager::initialize() { - // } - + LCDD& lcdd = LCDD::getInstance(); + + std::vector<std::string> types = lcdd.detectorTypes() ; + + for(unsigned i=0,N=types.size();i<N;++i){ + + const std::vector<DetElement>& dets = lcdd.detectors( types[i] ) ; + + for(unsigned j=0,M=dets.size();j<M;++j){ + + std::string name = dets[j].name() ; + + SurfaceHelper surfH( dets[j] ) ; + + const SurfaceList& detSL = surfH.surfaceList() ; + + for( SurfaceList::const_iterator it = detSL.begin() ; it != detSL.end() ; ++it ){ + Surface* surf = *it ; + + // enter surface into map for detector type + _map[ types[i] ].insert( std::make_pair( surf->id() , surf ) ) ; + + // enter surface into map for this detector + _map[ name ].insert( std::make_pair( surf->id() , surf ) ) ; + + } + } + } + + } + + } // namespace