From e76bb5c87f52c68e1e2f0c402c0d38440d3cdade Mon Sep 17 00:00:00 2001 From: Frank Gaede <frank.gaede@desy.de> Date: Mon, 19 May 2014 12:26:55 +0000 Subject: [PATCH] - added methods A(),Z() and density() to Geometry::Material - use in DDRec::SurfaceMaterial - added explicit method double * const_array() to DDSurfaces::Vector3D in order to fix issue with conversion operator that is not recognized by some compilers --- DDCore/include/DD4hep/Objects.h | 6 +++ DDCore/src/Objects.cpp | 35 ++++++++++++++++ DDRec/include/DDRec/Surface.h | 23 +++++------ DDRec/src/Surface.cpp | 51 ++++++++++++------------ DDSurfaces/include/DDSurfaces/Vector3D.h | 4 ++ examples/ILDExDet/compact/ILDEx.xml | 2 + 6 files changed, 83 insertions(+), 38 deletions(-) diff --git a/DDCore/include/DD4hep/Objects.h b/DDCore/include/DD4hep/Objects.h index cfa68eab9..0463d8410 100644 --- a/DDCore/include/DD4hep/Objects.h +++ b/DDCore/include/DD4hep/Objects.h @@ -289,6 +289,12 @@ namespace DD4hep { Material(const Handle<Q>& e) : Handle<TGeoMedium>(e) { } + /// proton number of the underlying material + double Z() const ; + /// atomic number of the underlying material + double A() const ; + /// density of the underlying material + double density() const ; /// String representation of this object std::string toString() const; /// Access the radiation length of the underlying material diff --git a/DDCore/src/Objects.cpp b/DDCore/src/Objects.cpp index 0147bef54..13d3f701b 100644 --- a/DDCore/src/Objects.cpp +++ b/DDCore/src/Objects.cpp @@ -167,6 +167,41 @@ Atom::Atom(const string& name, const string& formula, int Z, int N, double densi m_element = e; } +/// proton number of the underlying material +double Material::Z() const { + Handle < TGeoMedium > val(*this); + if (val.isValid()) { + TGeoMaterial* m = val->GetMaterial(); + if (m) + return m->GetZ(); + throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!"); + } + throw runtime_error("DD4hep: Attempt to access proton number from invalid material handle!"); +} +/// atomic number of the underlying material +double Material::A() const { + Handle < TGeoMedium > val(*this); + if (val.isValid()) { + TGeoMaterial* m = val->GetMaterial(); + if (m) + return m->GetA(); + throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!"); + } + throw runtime_error("DD4hep: Attempt to access atomic number from invalid material handle!"); +} + +/// density of the underlying material +double Material::density() const { + Handle < TGeoMedium > val(*this); + if (val.isValid()) { + TGeoMaterial* m = val->GetMaterial(); + if (m) + return m->GetDensity(); + throw runtime_error("DD4hep: The medium " + string(val->GetName()) + " has an invalid material reference!"); + } + throw runtime_error("DD4hep: Attempt to access density from invalid material handle!"); +} + /// Access the radiation length of the underlying material double Material::radLength() const { Handle < TGeoMedium > val(*this); diff --git a/DDRec/include/DDRec/Surface.h b/DDRec/include/DDRec/Surface.h index 82454ff5f..7db071762 100644 --- a/DDRec/include/DDRec/Surface.h +++ b/DDRec/include/DDRec/Surface.h @@ -1,5 +1,5 @@ -#ifndef DD4Surfaces_Surface_H -#define DD4Surfaces_Surface_H +#ifndef DDRec_Surface_H +#define DDRec_Surface_H #include "DD4hep/Objects.h" #include "DD4hep/Volumes.h" @@ -17,6 +17,8 @@ namespace DD4hep { using namespace DDSurfaces ; + // typedef DDRec::Material SurfaceMaterial ; + /** Wrapper class to Geometry::Material that implements the DDSurfaces::IMaterial interface. * * @author F.Gaede, DESY @@ -26,26 +28,23 @@ namespace DD4hep { struct SurfaceMaterial : public virtual Geometry::Material , public IMaterial{ /** Copy c'tor - copies handle */ - SurfaceMaterial( Geometry::Material m ) ; // : Geometry::Material( m ) {} + SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} - SurfaceMaterial( const SurfaceMaterial& sm ) ; - // { - // (*this).Geometry::Material::m_element = sm.Geometry::Material::m_element ; - // } + SurfaceMaterial( const SurfaceMaterial& sm ) : Geometry::Material( sm ) {} - virtual ~SurfaceMaterial() ; //{} + virtual ~SurfaceMaterial() {} /// material name - virtual std::string name() const { return m_element->GetMaterial()->GetName() ; } + virtual std::string name() const { return Geometry::Material::name() ; } /// averaged proton number - virtual double Z() const { return m_element->GetMaterial()->GetZ() ; } + virtual double Z() const { return Geometry::Material::Z() ; } /// averaged atomic number - virtual double A() const { return m_element->GetMaterial()->GetA() ; } + virtual double A() const { return Geometry::Material::A() ; } /// density - units ? - virtual double density() const { return m_element->GetMaterial()->GetDensity() ; } + virtual double density() const { return Geometry::Material::density() ; } /// radiation length - tgeo units virtual double radiationLength() const { return Geometry::Material::radLength() ; } diff --git a/DDRec/src/Surface.cpp b/DDRec/src/Surface.cpp index 40b3bfafe..a386b8aa3 100644 --- a/DDRec/src/Surface.cpp +++ b/DDRec/src/Surface.cpp @@ -17,27 +17,26 @@ namespace DD4hep { //-------------------------------------------------------- - /** Copy c'tor - copies handle */ - SurfaceMaterial::SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} + // /** Copy c'tor - copies handle */ + // SurfaceMaterial::SurfaceMaterial( Geometry::Material m ) : Geometry::Material( m ) {} - SurfaceMaterial::SurfaceMaterial( const SurfaceMaterial& sm ) : Geometry::Material( sm ) { - // (*this).Geometry::Material::m_element = sm.Geometry::Material::m_element ; - } - - SurfaceMaterial:: ~SurfaceMaterial() {} + // 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() ) , - _n( Vector3D() ) , - _o( Vector3D() ) , - _th_i( 0. ), - _th_o( 0. ), - _innerMat( Material() ), - _outerMat( Material() ) { + _u( Vector3D() ) , + _v( Vector3D() ) , + _n( Vector3D() ) , + _o( Vector3D() ) , + _th_i( 0. ), + _th_o( 0. ), + _innerMat( Geometry::Material() ), + _outerMat( Geometry::Material() ) { } @@ -49,8 +48,8 @@ namespace DD4hep { _o( o ), _th_i( thickness_inner ), _th_o( thickness_outer ), - _innerMat( Material() ), - _outerMat( Material() ) { + _innerMat( Geometry::Material() ), + _outerMat( Geometry::Material() ) { } @@ -77,7 +76,7 @@ namespace DD4hep { #if 0 double dist = std::abs ( distance( point ) ) ; - bool inShape = volume()->GetShape()->Contains( point ) ; + bool inShape = volume()->GetShape()->Contains( point.const_array() ) ; std::cout << " ** Surface::insideBound( " << point << " ) - distance = " << dist << " origin = " << origin() << " normal = " << normal() @@ -87,7 +86,7 @@ namespace DD4hep { return dist < epsilon && inShape ; #else - return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point ) ; + return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point.const_array() ) ; #endif } @@ -104,7 +103,7 @@ namespace DD4hep { #if 0 double distR = std::abs( distance( point ) ) ; - bool inShapeT = volume()->GetShape()->Contains( point ) ; + bool inShapeT = volume()->GetShape()->Contains( point.const_array() ) ; std::cout << " ** Surface::insideBound( " << point << " ) - distance = " << distR << " origin = " << origin() @@ -113,7 +112,7 @@ namespace DD4hep { return distR < epsilon && inShapeT ; #else - return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point ) ; + return ( std::abs ( distance( point ) ) < epsilon ) && volume()->GetShape()->Contains( point.const_array() ) ; #endif } @@ -555,7 +554,7 @@ namespace DD4hep { DDSurfaces::Vector3D luRot ; luRot.fill( vecR ) ; - double dist = shape->DistFromInside( lo, luRot , 3, 0.1 ) ; + double dist = shape->DistFromInside( lo.const_array() , luRot.const_array() , 3, 0.1 ) ; // local point at volume boundary DDSurfaces::Vector3D lp = lo + dist * luRot ; @@ -565,9 +564,9 @@ namespace DD4hep { _wtM->LocalToMaster( lp , gp.array() ) ; // std::cout << " **** normal:" << ln << " lu:" << lu << " alpha:" << alpha << " luRot:" << luRot << " lp :" << lp << " gp:" << gp << " dist : " << dist - // << " is point " << gp << " inside : " << shape->Contains( gp ) - // << " dist from outside for lo,lu " << shape->DistFromOutside( lo , lu , 3 ) - // << " dist from inside for lo,ln " << shape->DistFromInside( lo , ln , 3 ) + // << " is point " << gp << " inside : " << shape->Contains( gp.const_array() ) + // << " dist from outside for lo,lu " << shape->DistFromOutside( lo.const_array() , lu.const_array() , 3 ) + // << " dist from inside for lo,ln " << shape->DistFromInside( lo.const_array() , ln.const_array() , 3 ) // << std::endl; // shape->Dump() ; @@ -735,7 +734,7 @@ namespace DD4hep { // DDSurfaces::Vector3D luRot ; // luRot.fill( vecR ) ; - // double dist = shape->DistFromInside( lo, luRot , 3, 0.1 ) ; + // double dist = shape->DistFromInside( lo.const_array() , luRot.const_array() , 3, 0.1 ) ; // // local point at volume boundary // DDSurfaces::Vector3D lp = lo + dist * luRot ; diff --git a/DDSurfaces/include/DDSurfaces/Vector3D.h b/DDSurfaces/include/DDSurfaces/Vector3D.h index 3f3f9a6c6..ea273e5d9 100644 --- a/DDSurfaces/include/DDSurfaces/Vector3D.h +++ b/DDSurfaces/include/DDSurfaces/Vector3D.h @@ -195,6 +195,10 @@ namespace DDSurfaces { inline operator const double*() const { return &_x ; } + /// direct access to data as const double* + inline const double* const_array() const { + return &_x ; + } /// direct access to data as double* - allows modification inline double* array() { diff --git a/examples/ILDExDet/compact/ILDEx.xml b/examples/ILDExDet/compact/ILDEx.xml index 6d4c1a54e..afecaf1b1 100644 --- a/examples/ILDExDet/compact/ILDEx.xml +++ b/examples/ILDExDet/compact/ILDEx.xml @@ -257,10 +257,12 @@ <readout name="HcalBarrelRegCollection"> <segmentation type="CartesianGridXZ" grid_size_x="30.0*mm" grid_size_z="30.0*mm" /> + <!-- <segmentation type="grid_xyz" grid_size_x="30.0*mm" grid_size_y="30.0*mm" grid_size_z="30.0*mm" /> --> <id>system:6,stave:3,module:4,layer:8,slice:5,x:32:-16,y:-16</id> </readout> <readout name="HcalEndcapHits"> <segmentation type="CartesianGridXY" grid_size_x="3.0*cm" grid_size_y="3.0*cm" /> + <!-- <segmentation type="grid_xyz" grid_size_x="30.0*mm" grid_size_y="30.0*mm" grid_size_z="30.0*mm" /> --> <id>system:6,stave:1,module:1,endcapID:5,layer:8,slice:5,x:32:-16,y:-16</id> </readout> -- GitLab