DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ISurface.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : F.Gaede
11 //
12 //==========================================================================
13 #ifndef DDREC_ISURFACE_H
14 #define DDREC_ISURFACE_H
15 
16 
17 #include "DDRec/IMaterial.h"
18 #include "DDRec/Vector2D.h"
19 #include "DDRec/Vector3D.h"
20 
21 #include <bitset>
22 #include <cmath>
23 
24 namespace dd4hep { namespace rec {
25 
26  class SurfaceType ;
27 
28  typedef long long int long64 ;
29 
30 
39  class ISurface {
40 
41  public:
43  virtual ~ISurface() {}
44 
46  virtual const SurfaceType& type() const =0 ;
47 
49  virtual long64 id() const =0 ;
50 
52  virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const =0 ;
53 
55  virtual Vector3D u( const Vector3D& point = Vector3D() ) const =0 ;
56 
58  virtual Vector3D v(const Vector3D& point = Vector3D() ) const =0 ;
59 
61  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const =0 ;
62 
64  virtual Vector2D globalToLocal( const Vector3D& point) const=0 ;
65 
67  virtual Vector3D localToGlobal( const Vector2D& point) const=0 ;
68 
70  virtual const Vector3D& origin() const =0 ;
71 
73  virtual const IMaterial& innerMaterial() const =0 ;
74 
76  virtual const IMaterial& outerMaterial() const =0 ;
77 
79  virtual double innerThickness() const =0 ;
80 
82  virtual double outerThickness() const =0 ;
83 
85  virtual double distance(const Vector3D& point ) const =0 ;
86 
90  virtual double length_along_u() const=0 ;
91 
95  virtual double length_along_v() const=0 ;
96 
97  } ;
98 
99  //==============================================================================================
105  class ICylinder {
106 
107  public:
109  virtual ~ICylinder() {}
110  virtual double radius() const=0 ;
111  virtual Vector3D center() const=0 ;
112  };
113  //==============================================================================================
119  class ICone {
120 
121  public:
123  virtual ~ICone() {}
124  virtual double radius0() const=0 ;
125  virtual double radius1() const=0 ;
126  virtual double z0() const=0 ;
127  virtual double z1() const=0 ;
128  virtual Vector3D center() const=0 ;
129  };
130 
131  //==============================================================================================
132 
140  class SurfaceType{
141 
142  public:
145  Cylinder = 0,
154  Unbounded
155  } ;
156 
158  SurfaceType() : _bits(0) {}
159 
160  // c'tor that sets one property
161  SurfaceType( unsigned prop0 ) : _bits(0) {
162  _bits.set( prop0 ) ;
163  }
164 
165  // c'tor that sets two properties
166  SurfaceType( unsigned prop0 , unsigned prop1 ) : _bits(0) {
167  _bits.set( prop0 ) ;
168  _bits.set( prop1 ) ;
169  }
170 
171  // c'tor that sets three properties
172  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2 ) : _bits(0) {
173  _bits.set( prop0 ) ;
174  _bits.set( prop1 ) ;
175  _bits.set( prop2 ) ;
176  }
177 
178  // c'tor that sets four properties
179  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2, unsigned prop3 ) : _bits(0) {
180  _bits.set( prop0 ) ;
181  _bits.set( prop1 ) ;
182  _bits.set( prop2 ) ;
183  _bits.set( prop3 ) ;
184  }
185 
186  // c'tor that sets five properties
187  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2, unsigned prop3, unsigned prop4 ) : _bits(0) {
188  _bits.set( prop0 ) ;
189  _bits.set( prop1 ) ;
190  _bits.set( prop2 ) ;
191  _bits.set( prop3 ) ;
192  _bits.set( prop4 ) ;
193  }
194 
196  void setProperty( unsigned prop , bool val = true ) { _bits.set( prop , val ) ; }
197 
199  bool isSensitive() const { return _bits[ SurfaceType::Sensitive ] ; }
200 
202  bool isHelper() const { return _bits[ SurfaceType::Helper ] ; }
203 
205  bool isPlane() const { return _bits[ SurfaceType::Plane ] ; }
206 
208  bool isCylinder() const { return _bits[ SurfaceType::Cylinder ] ; }
209 
211  bool isCone() const { return _bits[ SurfaceType::Cone ] ; }
212 
214  bool isParallelToZ() const { return _bits[ SurfaceType::ParallelToZ ] ; }
215 
217  bool isOrthogonalToZ() const { return _bits[ SurfaceType::OrthogonalToZ ] ; }
218 
220  bool isVisible() const { return ! _bits[ SurfaceType::Invisible ] ; }
221 
223  bool isZCylinder() const { return ( _bits[ SurfaceType::Cylinder ] && _bits[ SurfaceType::ParallelToZ ] ) ; }
224 
226  bool isZCone() const { return ( _bits[ SurfaceType::Cone ] && _bits[ SurfaceType::ParallelToZ ] ) ; }
227 
229  bool isZPlane() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::ParallelToZ ] ) ;
230  }
231 
233  bool isZDisk() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::OrthogonalToZ ] ) ; }
234 
236  bool isMeasurement1D() const { return _bits[ SurfaceType::Measurement1D ] ; }
237 
239 
240  bool isUnbounded() const { return _bits[ SurfaceType::Unbounded ] ; }
241 
243  bool isSimilar( const SurfaceType& otherType) const {
244  unsigned long otherBits = otherType._bits.to_ulong() ;
245  unsigned long theseBits = _bits.to_ulong() ;
246  // std::cout << " ** isSimilar : " << otherType._bits.to_string() << " - " << _bits.to_string() << " : " << (( otherBits & theseBits ) == otherBits) << std::endl ;
247  return ( otherBits & theseBits ) == otherBits ;
248  }
249 
250 
252  bool checkParallelToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
253 
254  // if ( _bits[ SurfaceType::ParallelToZ ] ) // set in specific implementation
255  // return true ;
256 
257  double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
258 
259  _bits.set( SurfaceType::ParallelToZ , ( proj < epsilon ) ) ;
260 
261  // std::cout << " ** checkParallelToZ() - normal : " << surf.normal() << " pojection : " << proj
262  // << " _bits[ SurfaceType::ParallelToZ ] = " << bool( _bits[ SurfaceType::ParallelToZ ] )
263  // << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( proj < epsilon ) << std::endl ;
264 
265  return _bits[ SurfaceType::ParallelToZ ] ;
266  }
267 
269  bool checkOrthogonalToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
270 
271  // if ( _bits[ SurfaceType::OrthogonalToZ ] ) // set in specific implementation
272  // return true ;
273 
274  double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
275 
276  _bits.set( SurfaceType::OrthogonalToZ , ( std::fabs( proj - 1. ) < epsilon ) ) ;
277 
278  // std::cout << " ** checkOrthogonalToZ() - normal : " << surf.normal() << " pojection : " << proj
279  // << " _bits[ SurfaceType::OrthogonalToZ ] = " << bool( _bits[ SurfaceType::OrthogonalToZ ] )
280  // << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( std::fabs( proj - 1. ) < epsilon ) << std::endl ;
281 
282 
284  }
285 
286 
287  protected:
288 
289  mutable std::bitset<32> _bits ;
290  } ;
291 
293  inline std::ostream& operator<<( std::ostream& os , const SurfaceType& t ) {
294 
295  os << "sensitive[" << t.isSensitive()
296  << "] helper[" << t.isHelper()
297  << "] plane[" << t.isPlane()
298  << "] cylinder[" << t.isCylinder()
299  << "] cone[" << t.isCone()
300  << "] parallelToZ[" << t.isParallelToZ()
301  << "] orthogonalToZ[" << t.isOrthogonalToZ()
302  << "] zCylinder[" << t.isZCylinder()
303  << "] zCone[" << t.isZCone()
304  << "] zPlane[" << t.isZPlane()
305  << "] zDisk[" << t.isZDisk()
306  << "] unbounded[" << t.isUnbounded()
307  << "]" ;
308 
309  return os ;
310  }
311 
312 
313 
315  inline std::ostream& operator<<( std::ostream& os , const ISurface& s ) {
316 
317  os << " id: " << std::hex << s.id() << std::dec << " type : " << s.type() << std::endl
318  << " u : " << s.u() << " v : " << s.v() << " normal : " << s.normal() << " origin : " << s.origin() << std::endl ;
319  os << " inner material : " << s.innerMaterial() << " thickness: " << s.innerThickness() << std::endl
320  << " outerMaterial : " << s.outerMaterial() << " thickness: " << s.outerThickness() << std::endl ;
321 
322  const ICylinder* cyl = dynamic_cast< const ICylinder* > ( &s ) ;
323  if( cyl )
324  os << " cylinder radius : " << cyl->radius() << std::endl ;
325 
326  const ICone* cone = dynamic_cast< const ICone* > ( &s ) ;
327  if( cone )
328  os << " cone radius0: " << cone->radius0() << " cone radius1: " << cone->radius1() << std::endl ;
329 
330  return os ;
331  }
332 
333 
334 } } /* namespace rec */
335 
336 
337 
338 #endif // DDREC_ISURFACE_H
dd4hep::rec::SurfaceType::isSimilar
bool isSimilar(const SurfaceType &otherType) const
true if all properties of otherType are also true for this type.
Definition: ISurface.h:243
dd4hep::rec::ISurface::outerMaterial
virtual const IMaterial & outerMaterial() const =0
Access to the material in direction of the normal.
dd4hep::rec::SurfaceType::checkOrthogonalToZ
bool checkOrthogonalToZ(const ISurface &surf, double epsilon=1.e-6) const
Definition: ISurface.h:269
dd4hep::rec::ISurface::normal
virtual Vector3D normal(const Vector3D &point=Vector3D()) const =0
Access to the normal direction at the given point.
dd4hep::rec::SurfaceType::OrthogonalToZ
@ OrthogonalToZ
Definition: ISurface.h:150
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType(unsigned prop0, unsigned prop1)
Definition: ISurface.h:166
dd4hep::rec::ICone::z0
virtual double z0() const =0
dd4hep::rec::Vector3D
Definition: Vector3D.h:32
dd4hep::rec::ISurface
Definition: ISurface.h:39
dd4hep::rec::SurfaceType::Plane
@ Plane
Definition: ISurface.h:146
dd4hep::rec::ISurface::distance
virtual double distance(const Vector3D &point) const =0
dd4hep::rec::SurfaceType::isZDisk
bool isZDisk() const
true if this is a plane orthogonal to Z
Definition: ISurface.h:233
dd4hep::rec::ICone
Definition: ISurface.h:119
dd4hep::rec::SurfaceType::isZCone
bool isZCone() const
true if this is a cone parallel to Z
Definition: ISurface.h:226
dd4hep::rec::ISurface::~ISurface
virtual ~ISurface()
Destructor.
Definition: ISurface.h:43
dd4hep::rec::ISurface::innerThickness
virtual double innerThickness() const =0
dd4hep::rec::ISurface::origin
virtual const Vector3D & origin() const =0
dd4hep::rec::ISurface::v
virtual Vector3D v(const Vector3D &point=Vector3D()) const =0
dd4hep::rec::ICone::radius0
virtual double radius0() const =0
dd4hep::rec::SurfaceType::isOrthogonalToZ
bool isOrthogonalToZ() const
true if surface is orthogonal to Z
Definition: ISurface.h:217
dd4hep::rec::ICylinder::radius
virtual double radius() const =0
dd4hep::rec::SurfaceType::isZPlane
bool isZPlane() const
true if this is a plane parallel to Z
Definition: ISurface.h:229
dd4hep::rec::SurfaceType::checkParallelToZ
bool checkParallelToZ(const ISurface &surf, double epsilon=1.e-6) const
Definition: ISurface.h:252
IMaterial.h
Vector2D.h
epsilon
const double epsilon
Definition: test_cellid_position_converter.cpp:41
dd4hep::rec::ICylinder::~ICylinder
virtual ~ICylinder()
Destructor.
Definition: ISurface.h:109
dd4hep::rec::ISurface::insideBounds
virtual bool insideBounds(const Vector3D &point, double epsilon=1.e-4) const =0
Checks if the given point lies within the surface.
dd4hep::rec::ISurface::innerMaterial
virtual const IMaterial & innerMaterial() const =0
Access to the material in opposite direction of the normal.
dd4hep::rec::SurfaceType::isCone
bool isCone() const
true if this a conical surface
Definition: ISurface.h:211
dd4hep::rec::SurfaceType::isZCylinder
bool isZCylinder() const
true if this is a cylinder parallel to Z
Definition: ISurface.h:223
dd4hep::rec::SurfaceType::SurfaceTypes
SurfaceTypes
enum for defining the bits used to decode the properties
Definition: ISurface.h:144
dd4hep::rec::ISurface::globalToLocal
virtual Vector2D globalToLocal(const Vector3D &point) const =0
dd4hep::rec::SurfaceType::isHelper
bool isHelper() const
true if surface is helper surface for navigation
Definition: ISurface.h:202
dd4hep::rec::SurfaceType::Invisible
@ Invisible
Definition: ISurface.h:151
dd4hep::rec::SurfaceType::Sensitive
@ Sensitive
Definition: ISurface.h:147
dd4hep::rec::ISurface::id
virtual long64 id() const =0
The id of this surface - corresponds to DetElement id ( or'ed with the placement ids )
dd4hep::rec::ICone::z1
virtual double z1() const =0
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType()
default c'tor
Definition: ISurface.h:158
dd4hep::rec::long64
long long int long64
Definition: ISurface.h:26
dd4hep::rec::ICylinder
Definition: ISurface.h:105
dd4hep::rec::ISurface::outerThickness
virtual double outerThickness() const =0
dd4hep::rec::ICone::~ICone
virtual ~ICone()
Destructor.
Definition: ISurface.h:123
dd4hep::rec::SurfaceType::ParallelToZ
@ ParallelToZ
Definition: ISurface.h:149
dd4hep::rec::ICone::radius1
virtual double radius1() const =0
dd4hep::rec::Vector2D
Definition: Vector2D.h:24
dd4hep::rec::SurfaceType::Helper
@ Helper
Definition: ISurface.h:148
dd4hep::rec::SurfaceType::Unbounded
@ Unbounded
Definition: ISurface.h:154
dd4hep::rec::ISurface::length_along_u
virtual double length_along_u() const =0
dd4hep::rec::SurfaceType
Definition: ISurface.h:140
dd4hep::rec::SurfaceType::isVisible
bool isVisible() const
true if surface is not invisble - for drawing only
Definition: ISurface.h:220
dd4hep::rec::ICone::center
virtual Vector3D center() const =0
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType(unsigned prop0)
Definition: ISurface.h:161
dd4hep::rec::SurfaceType::Cylinder
@ Cylinder
Definition: ISurface.h:145
dd4hep::rec::SurfaceType::isUnbounded
bool isUnbounded() const
true if the surface is unbounded ( ISurface::insideBounds() does not check volume boundaries)
Definition: ISurface.h:240
dd4hep::rec::SurfaceType::isSensitive
bool isSensitive() const
true if surface is sensitive
Definition: ISurface.h:199
dd4hep::rec::ISurface::localToGlobal
virtual Vector3D localToGlobal(const Vector2D &point) const =0
dd4hep::rec::SurfaceType::isPlane
bool isPlane() const
true if this a planar surface
Definition: ISurface.h:205
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2, unsigned prop3)
Definition: ISurface.h:179
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::rec::operator<<
std::ostream & operator<<(std::ostream &io, const DCH_info &d)
Definition: DCH_info.h:197
dd4hep::rec::ICylinder::center
virtual Vector3D center() const =0
dd4hep::rec::SurfaceType::Measurement1D
@ Measurement1D
Definition: ISurface.h:152
dd4hep::rec::SurfaceType::isMeasurement1D
bool isMeasurement1D() const
true if the measurement is only 1D, i.e. the second direction v is not used
Definition: ISurface.h:236
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2, unsigned prop3, unsigned prop4)
Definition: ISurface.h:187
dd4hep::rec::SurfaceType::setProperty
void setProperty(unsigned prop, bool val=true)
set the given peorperty
Definition: ISurface.h:196
dd4hep::rec::SurfaceType::_bits
std::bitset< 32 > _bits
Definition: ISurface.h:289
dd4hep::rec::IMaterial
Definition: IMaterial.h:28
dd4hep::rec::SurfaceType::isCylinder
bool isCylinder() const
true if this a cylindrical surface
Definition: ISurface.h:208
Vector3D.h
dd4hep::rec::ISurface::type
virtual const SurfaceType & type() const =0
properties of the surface encoded in Type.
dd4hep::rec::ISurface::u
virtual Vector3D u(const Vector3D &point=Vector3D()) const =0
dd4hep::rec::ISurface::length_along_v
virtual double length_along_v() const =0
dd4hep::rec::SurfaceType::Cone
@ Cone
Definition: ISurface.h:153
dd4hep::rec::SurfaceType::isParallelToZ
bool isParallelToZ() const
true if surface is parallel to Z
Definition: ISurface.h:214
dd4hep::rec::SurfaceType::SurfaceType
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2)
Definition: ISurface.h:172