diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index d16f53a7f35c32f918d4ce0e07b48433c7a828fa..650a527cdd64073b80dcd0ba17bf1f1daa9f82dc 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -17,44 +17,45 @@ namespace DD4hep { using namespace DDSurfaces ; -#if 1 +#define use_materialdata 1 +#if use_materialdata typedef MaterialData SurfaceMaterial ; #else /** Wrapper class to Geometry::Material that implements the DDSurfaces::IMaterial interface. - * - * @author F.Gaede, DESY - * @date Apr, 6 2014 - * @version $Id$ - */ - struct SurfaceMaterial : public virtual Geometry::Material , public IMaterial{ + * + * @author F.Gaede, DESY + * @date Apr, 6 2014 + * @version $Id$ + */ + struct SurfaceMaterial : public virtual Geometry::Material , public IMaterial{ - /** Copy c'tor - copies handle */ - SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} + /** Copy c'tor - copies handle */ + SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} - SurfaceMaterial( const SurfaceMaterial& sm ) : Geometry::Material( sm ) {} + SurfaceMaterial( const SurfaceMaterial& sm ) : Geometry::Material( sm ) {} - virtual ~SurfaceMaterial() {} + virtual ~SurfaceMaterial() {} - /// material name - virtual std::string name() const { return Geometry::Material::name() ; } + /// material name + virtual std::string name() const ; - /// averaged proton number - virtual double Z() const { return Geometry::Material::Z() ; } + /// averaged proton number + virtual double Z() const ; - /// averaged atomic number - virtual double A() const { return Geometry::Material::A() ; } + /// averaged atomic number + virtual double A() const ; - /// density - units ? - virtual double density() const { return Geometry::Material::density() ; } + /// density - units ? + virtual double density() const ; - /// radiation length - tgeo units - virtual double radiationLength() const { return Geometry::Material::radLength() ; } + /// radiation length - tgeo units + virtual double radiationLength() const ; - /// interaction length - tgeo units - virtual double interactionLength() const { return Geometry::Material::intLength() ; } + /// interaction length - tgeo units + virtual double interactionLength() const ; - }; + }; #endif @@ -112,16 +113,15 @@ namespace DD4hep { class VolSurface : public Geometry::Handle< SurfaceData > , public ISurface { protected: - + /// setter for daughter classes - virtual void setU(const Vector3D& u) { object<SurfaceData>()._u = u ; } + virtual void setU(const Vector3D& u) ; /// setter for daughter classes - virtual void setV(const Vector3D& v) { object<SurfaceData>()._v = v ; } + virtual void setV(const Vector3D& v) ; /// setter for daughter classes - virtual void setNormal(const Vector3D& n) { object<SurfaceData>()._n = n ; } - + virtual void setNormal(const Vector3D& n) ; public: @@ -132,63 +132,64 @@ namespace DD4hep { /// Constructor to be used with an existing object VolSurface(SurfaceData* p) - : Geometry::Handle< SurfaceData >(p) { + : Geometry::Handle< SurfaceData >(p) { } - /// Constructor to be used with an existing object + /// Constructor to be used with an existing object VolSurface(const VolSurface& e) : Geometry::Handle< SurfaceData >(e) { } /// Constructor to be used with an existing object template <typename Q> VolSurface(const Geometry::Handle<Q>& e) - : Geometry::Handle< SurfaceData >(e) { + : Geometry::Handle< SurfaceData >(e) { } /// Standrad c'tor for initialization. VolSurface( Geometry::Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D u ,Vector3D v ,Vector3D n , Vector3D o = Vector3D(0.,0.,0.) ) ; + /// the volume to which this surface is attached. Geometry::Volume volume() const { return ptr()->_vol; } /// The id of this surface - always 0 for VolSurfaces - virtual long64 id() const { return 0 ; } + virtual long64 id() const ; - /** properties of the surface encoded in Type. + /** properties of the surface encoded in Type. * @see SurfaceType */ - virtual const SurfaceType& type() const { return object<SurfaceData>()._type ; } + virtual const SurfaceType& type() const ; //==== geometry ==== /** First direction of measurement U */ - virtual Vector3D u( const Vector3D& point = Vector3D() ) const { point.x() ; return object<SurfaceData>()._u ; } + virtual Vector3D u( const Vector3D& point = Vector3D() ) const ; /** Second direction of measurement V */ - virtual Vector3D v(const Vector3D& point = Vector3D() ) const { point.x() ; return object<SurfaceData>()._v ; } + virtual Vector3D v(const Vector3D& point = Vector3D() ) const ; /// Access to the normal direction at the given point - virtual Vector3D normal(const Vector3D& point = Vector3D() ) const { point.x() ; return object<SurfaceData>()._n ; } + virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ; /** Get Origin of local coordinate system on surface */ - virtual const Vector3D& origin() const { return object<SurfaceData>()._o ;} - + virtual const Vector3D& origin() const ; + /** Convert the global position to the local position (u,v) on the surface */ virtual Vector2D globalToLocal( const Vector3D& point) const ; /** Convert the local position (u,v) on the surface to the global position */ virtual Vector3D localToGlobal( const Vector2D& point) const ; - + /// Access to the material in opposite direction of the normal - virtual const IMaterial& innerMaterial() const{ return object<SurfaceData>()._innerMat ; } + virtual const IMaterial& innerMaterial() const ; /// Access to the material in direction of the normal - virtual const IMaterial& outerMaterial() const { return object<SurfaceData>()._outerMat ; } + virtual const IMaterial& outerMaterial() const ; /** Thickness of inner material */ - virtual double innerThickness() const { return object<SurfaceData>()._th_i ; } + virtual double innerThickness() const ; /** Thickness of outer material */ - virtual double outerThickness() const { return object<SurfaceData>()._th_o ; } + virtual double outerThickness() const ; /** The length of the surface along direction u at the origin. For 'regular' boundaries, like rectangles, @@ -206,10 +207,10 @@ namespace DD4hep { // need default implementations for putting it in list.... /** Distance to surface */ - virtual double distance(const Vector3D& point ) const { point.x() ; return 1.e99 ; } + virtual double distance(const Vector3D& point ) const ; /// Checks if the given point lies within the surface - virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const { point.x() ; (void) epsilon ; return false ; } + virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const ; //fixme: protected: + friend declaration ? @@ -229,7 +230,7 @@ namespace DD4hep { /** Helper function for accessing the list assigned to a DetElement - attaches * empty list if needed. */ - VolSurfaceList* volSurfaceList( Geometry::DetElement& det ) ; + VolSurfaceList* volSurfaceList( Geometry::DetElement& det) ; /** std::list of VolSurfaces that takes ownership. * @author F.Gaede, DESY @@ -252,25 +253,11 @@ namespace DD4hep { // required c'tor for extension mechanism VolSurfaceList(const VolSurfaceList& vsl, Geometry::DetElement& det ){ - // std::cout << " VolSurfaceList(const VolSurfaceList& vsl, Geometry::DetElement& det ) - vsl.size() " << vsl.size() - // << " own size: " << this->size() << " detelem : " ; - // if( det.isValid() ) - // std::cout << det.name() << std::endl ; //<< " path : " << det.placementPath() << std::endl ; - // else - // std::cout << " INVALID " << std::endl ; - - this->insert( this->end() , vsl.begin() , vsl.end() ) ; } - virtual ~VolSurfaceList(){ + virtual ~VolSurfaceList() ; - // delete all surfaces attached to this volume - for( VolSurfaceList::iterator i=begin(), n=end() ; i !=n ; ++i ) { - i->clear() ; - } - - } } ; @@ -373,7 +360,7 @@ namespace DD4hep { /** Convert the local position (u,v) on the surface to the global position - u runs along the axis of the cylinder, v is r*phi*/ virtual Vector3D localToGlobal( const Vector2D& point) const ; - } ; + } ; //====================================================================================================== @@ -413,12 +400,12 @@ namespace DD4hep { Surface( Geometry::DetElement det, VolSurface volSurf ) ; /// The id of this surface - corresponds to DetElement id. - virtual long64 id() const { return _id ; } + virtual long64 id() const ; /** properties of the surface encoded in Type. * @see SurfaceType */ - virtual const SurfaceType& type() const { return _type ; } + virtual const SurfaceType& type() const ; /// The volume that has the surface attached. Geometry::Volume volume() const { return _volSurf.volume() ; } @@ -430,16 +417,16 @@ namespace DD4hep { //==== geometry ==== /** First direction of measurement U */ - virtual Vector3D u( const Vector3D& point = Vector3D() ) const { point.x() ; return _u ; } + virtual Vector3D u( const Vector3D& point = Vector3D() ) const ; /** Second direction of measurement V */ - virtual Vector3D v(const Vector3D& point = Vector3D() ) const { point.x() ; return _v ; } + virtual Vector3D v(const Vector3D& point = Vector3D() ) const ; /// Access to the normal direction at the given point - virtual Vector3D normal(const Vector3D& point = Vector3D() ) const { point.x() ; return _n ; } + virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ; /** Get Origin of local coordinate system on surface */ - virtual const Vector3D& origin() const { return _o ;} + virtual const Vector3D& origin() const ; /** Convert the global position to the local position (u,v) on the surface */ virtual Vector2D globalToLocal( const Vector3D& point) const ; @@ -448,10 +435,10 @@ namespace DD4hep { virtual Vector3D localToGlobal( const Vector2D& point) const ; /** Thickness of inner material */ - virtual double innerThickness() const { return _volSurf.innerThickness() ; } + virtual double innerThickness() const ; /** Thickness of outer material */ - virtual double outerThickness() const { return _volSurf.outerThickness() ; } + virtual double outerThickness() const ; /// Access to the material in opposite direction of the normal virtual const IMaterial& innerMaterial() const ; @@ -520,9 +507,10 @@ namespace DD4hep { virtual Vector3D localToGlobal( const Vector2D& point) const ; /// the radius of the cylinder (rho of the origin vector) - virtual double radius() const { - return _volSurf.origin().rho() ; - } + virtual double radius() const ; + + /// the center of the cylinder + virtual Vector3D center() const ; } ; @@ -554,15 +542,7 @@ namespace DD4hep { } /// d'tor deletes all owned surfaces - virtual ~SurfaceList(){ - - if( _isOwner ) { - // delete all surfaces attached to this volume - for( SurfaceList::iterator i=begin(), n=end() ; i !=n ; ++i ) { - delete (*i) ; - } - } - } + virtual ~SurfaceList() ; } ; diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index 00523163fa20a6a529433f317766dbd431d0ac5f..9b467cc2cdca4437a6058f646cc5806d4f26f080 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -17,19 +17,23 @@ namespace DD4hep { using namespace Geometry ; - //-------------------------------------------------------- - // /** Copy c'tor - copies handle */ - // SurfaceMaterial::SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} + //====================================================================================================== + +#if !use_materialdata + + std::string SurfaceMaterial::name() const { return Geometry::Material::name() ; } + double SurfaceMaterial::Z() const { return Geometry::Material::Z() ; } + double SurfaceMaterial::A() const { return Geometry::Material::A() ; } + double SurfaceMaterial::density() const { return Geometry::Material::density() ; } + double SurfaceMaterial::radiationLength() const { return Geometry::Material::radLength() ; } + double SurfaceMaterial::interactionLength() const { return Geometry::Material::intLength() ; } + +#endif + //====================================================================================================== + + - // SurfaceMaterial::SurfaceMaterial( const SurfaceMaterial& sm ) : Geometry::Material( sm ) { - // // (*this).Geometry::Material::m_element = sm.Geometry::Material::m_element ; - // } - // SurfaceMaterial:: ~SurfaceMaterial() {} - - //-------------------------------------------------------- - - SurfaceData::SurfaceData() : _type( SurfaceType() ) , _u( Vector3D() ) , _v( Vector3D() ) , @@ -46,20 +50,21 @@ namespace DD4hep { SurfaceData::SurfaceData( SurfaceType type , double thickness_inner ,double thickness_outer, Vector3D u ,Vector3D v ,Vector3D n ,Vector3D o, Volume vol ) : _type(type ) , - _u( u ) , - _v( v ) , - _n( n ) , - _o( o ), - _th_i( thickness_inner ), - _th_o( thickness_outer ), - _innerMat( MaterialData() ), - _outerMat( MaterialData() ), - _vol(vol) + _u( u ) , + _v( v ) , + _n( n ) , + _o( o ), + _th_i( thickness_inner ), + _th_o( thickness_outer ), + _innerMat( MaterialData() ), + _outerMat( MaterialData() ), + _vol(vol) { } - + //====================================================================================================== + VolSurface::VolSurface( Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D u ,Vector3D v ,Vector3D n ,Vector3D o ) : @@ -68,6 +73,18 @@ namespace DD4hep { } + void VolSurface::setU(const Vector3D& u) { object<SurfaceData>()._u = u ; } + void VolSurface::setV(const Vector3D& v) { object<SurfaceData>()._v = v ; } + void VolSurface::setNormal(const Vector3D& n) { object<SurfaceData>()._n = n ; } + + long64 VolSurface::id() const { return 0 ; } + + const SurfaceType& VolSurface::type() const { return object<SurfaceData>()._type ; } + Vector3D VolSurface::u( const Vector3D& point ) const { point.x() ; return object<SurfaceData>()._u ; } + Vector3D VolSurface::v(const Vector3D& point ) const { point.x() ; return object<SurfaceData>()._v ; } + Vector3D VolSurface::normal(const Vector3D& point ) const { point.x() ; return object<SurfaceData>()._n ; } + const Vector3D& VolSurface::origin() const { return object<SurfaceData>()._o ;} + ISurface::Vector2D VolSurface::globalToLocal( const Vector3D& point) const { Vector3D p = point - origin() ; @@ -91,6 +108,12 @@ namespace DD4hep { return g ; } + const IMaterial& VolSurface::innerMaterial() const{ return object<SurfaceData>()._innerMat ; } + const IMaterial& VolSurface::outerMaterial() const { return object<SurfaceData>()._outerMat ; } + double VolSurface::innerThickness() const { return object<SurfaceData>()._th_i ; } + double VolSurface::outerThickness() const { return object<SurfaceData>()._th_o ; } + + double VolSurface::length_along_u() const { const DDSurfaces::Vector3D& o = this->origin() ; @@ -118,8 +141,13 @@ namespace DD4hep { } + double VolSurface::distance(const Vector3D& point ) const { point.x() ; return 1.e99 ; } + + bool VolSurface::insideBounds(const Vector3D& point, double epsilon) const { + point.x() ; (void) epsilon ; return false ; + } - + //====================================================================================================== /** Distance to surface */ @@ -142,11 +170,11 @@ namespace DD4hep { << " isInShape : " << inShape << std::endl ; return dist < epsilon && inShape ; - #else +#else //fixme: older versions of ROOT (~<5.34.10 ) take a non const pointer as argument - therefore use a const cast here for the time being ... return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( const_cast<double*> (point.const_array() ) ) ; - #endif +#endif } @@ -176,7 +204,7 @@ namespace DD4hep { object<SurfaceData>()._type.checkParallelToZ( *this ) ; object<SurfaceData>()._type.checkOrthogonalToZ( *this ) ; - } + } Vector3D VolCylinder::v( const Vector3D& point ) const { @@ -198,7 +226,7 @@ namespace DD4hep { // normal is just given by phi of the point return Vector3D( 1. , point.phi() , 0. , Vector3D::cylindrical ) ; - } + } @@ -241,14 +269,14 @@ namespace DD4hep { bool inShapeT = volume()->GetShape()->Contains( const_cast<double*> ( point.const_array() ) ) ; - std::cout << " ** Surface::insideBound( " << point << " ) - distance = " << distR - << " origin = " << origin() - << " isInShape : " << inShapeT << std::endl ; + std::cout << " ** Surface::insideBound( " << point << " ) - distance = " << distR + << " origin = " << origin() + << " isInShape : " << inShapeT << std::endl ; - return distR < epsilon && inShapeT ; + return distR < epsilon && inShapeT ; #else - return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( const_cast<double*> (point.const_array()) ) ; + return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( const_cast<double*> (point.const_array()) ) ; #endif } @@ -259,6 +287,28 @@ namespace DD4hep { //================================================================================================================ + VolSurfaceList::~VolSurfaceList(){ + + // delete all surfaces attached to this volume + for( VolSurfaceList::iterator i=begin(), n=end() ; i !=n ; ++i ) { + i->clear() ; + } + + } + //======================================================= + + SurfaceList::~SurfaceList(){ + + if( _isOwner ) { + // delete all surfaces attached to this volume + for( SurfaceList::iterator i=begin(), n=end() ; i !=n ; ++i ) { + delete (*i) ; + } + } + } + + //================================================================================================================ + VolSurfaceList* volSurfaceList( DetElement& det ) { @@ -284,13 +334,13 @@ namespace DD4hep { volList.push_back( pv ) ; - // unsigned count = volList.size() ; - // for(unsigned i=0 ; i < count ; ++i) { - // std::cout << " **" ; - // } - // std::cout << " searching for volume: " << theVol.name() << " " << std::hex << theVol.ptr() << " <-> pv.volume : " << pv.name() << " " << pv.volume().ptr() - // << " pv.volume().ptr() == theVol.ptr() " << (pv.volume().ptr() == theVol.ptr() ) - // << std::endl ; + // unsigned count = volList.size() ; + // for(unsigned i=0 ; i < count ; ++i) { + // std::cout << " **" ; + // } + // std::cout << " searching for volume: " << theVol.name() << " " << std::hex << theVol.ptr() << " <-> pv.volume : " << pv.name() << " " << pv.volume().ptr() + // << " pv.volume().ptr() == theVol.ptr() " << (pv.volume().ptr() == theVol.ptr() ) + // << std::endl ; if( pv.volume().ptr() == theVol.ptr() ) { @@ -343,6 +393,7 @@ namespace DD4hep { } } + //====================================================================================================================== Surface::Surface( Geometry::DetElement det, VolSurface volSurf ) : _det( det) , _volSurf( volSurf ), _wtM(0) , _id( 0) , _type( _volSurf.type() ) { @@ -350,7 +401,19 @@ namespace DD4hep { initialize() ; } + long64 Surface::id() const { return _id ; } + + const SurfaceType& Surface::type() const { return _type ; } + Vector3D Surface::u( const Vector3D& point ) const { point.x() ; return _u ; } + Vector3D Surface::v(const Vector3D& point ) const { point.x() ; return _v ; } + Vector3D Surface::normal(const Vector3D& point ) const { point.x() ; return _n ; } + const Vector3D& Surface::origin() const { return _o ;} + double Surface::innerThickness() const { return _volSurf.innerThickness() ; } + double Surface::outerThickness() const { return _volSurf.outerThickness() ; } + + + /** Thickness of outer material */ const IMaterial& Surface::innerMaterial() const { @@ -403,7 +466,7 @@ namespace DD4hep { ISurface::Vector2D Surface::globalToLocal( const Vector3D& point) const { - Vector3D p = point - origin() ; + Vector3D p = point - origin() ; // create new orthogonal unit vectors // FIXME: these vectors should be cached really ... @@ -480,10 +543,10 @@ namespace DD4hep { #if 0 // debug wm.Print() ; for( std::list<PlacedVolume>::iterator it= pVList.begin(), n = pVList.end() ; it != n ; ++it ){ - PlacedVolume pv = *it ; - TGeoMatrix* m = pv->GetMatrix(); - std::cout << " +++ matrix for placed volume : " << std::endl ; - m->Print() ; + PlacedVolume pv = *it ; + TGeoMatrix* m = pv->GetMatrix(); + std::cout << " +++ matrix for placed volume : " << std::endl ; + m->Print() ; } #endif @@ -533,11 +596,11 @@ namespace DD4hep { _n.fill( na ) ; _o.fill( oa ) ; - // std::cout << " --- local and global surface vectors : ------- " << std::endl - // << " u : " << _volSurf.u() << " - " << _u << std::endl - // << " v : " << _volSurf.v() << " - " << _v << std::endl - // << " n : " << _volSurf.normal() << " - " << _n << std::endl - // << " o : " << _volSurf.origin() << " - " << _o << std::endl ; + // std::cout << " --- local and global surface vectors : ------- " << std::endl + // << " u : " << _volSurf.u() << " - " << _u << std::endl + // << " v : " << _volSurf.v() << " - " << _v << std::endl + // << " n : " << _volSurf.normal() << " - " << _n << std::endl + // << " o : " << _volSurf.origin() << " - " << _o << std::endl ; // =========== check parallel and orthogonal to Z =================== @@ -547,7 +610,7 @@ namespace DD4hep { _type.checkOrthogonalToZ( *this ) ; - //======== set the unique surface ID from the DetElement ( and placements below ? ) + //======== set the unique surface ID from the DetElement ( and placements below ? ) // just use the DetElement ID for now ... _id = _det.volumeID() ; @@ -867,6 +930,10 @@ namespace DD4hep { return p ; } + double CylinderSurface::radius() const { return _volSurf.origin().rho() ; } + + Vector3D CylinderSurface::center() const { return volumeOrigin() ; } + //================================================================================================================ diff --git a/DDSurfaces/include/DDSurfaces/ISurface.h b/DDSurfaces/include/DDSurfaces/ISurface.h index 729170ba969670290ea34bf6914cf2f972799a4e..58ba448df6a6908097eea5344f6b03befef4e15d 100644 --- a/DDSurfaces/include/DDSurfaces/ISurface.h +++ b/DDSurfaces/include/DDSurfaces/ISurface.h @@ -96,6 +96,7 @@ namespace DDSurfaces { /// Destructor virtual ~ICylinder() {} virtual double radius() const=0 ; + virtual Vector3D center() const=0 ; }; //==============================================================================================