DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ISurface.h
Go to the documentation of this file.
1 #ifndef DDSurfaces_ISurface_H
2 #define DDSurfaces_ISurface_H
3 
4 
5 #include "DDSurfaces/IMaterial.h"
6 #include "DDSurfaces/Vector2D.h"
7 #include "DDSurfaces/Vector3D.h"
8 
9 #include <bitset>
10 #include <cmath>
11 
12 namespace DDSurfaces {
13 
14  class SurfaceType ;
15 
16  typedef long long int long64 ;
17 
18 
27  class ISurface {
28 
29  public:
31  virtual ~ISurface() {}
32 
34  virtual const SurfaceType& type() const =0 ;
35 
37  virtual long64 id() const =0 ;
38 
40  virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const =0 ;
41 
43  virtual Vector3D u( const Vector3D& point = Vector3D() ) const =0 ;
44 
46  virtual Vector3D v(const Vector3D& point = Vector3D() ) const =0 ;
47 
49  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const =0 ;
50 
52  virtual Vector2D globalToLocal( const Vector3D& point) const=0 ;
53 
55  virtual Vector3D localToGlobal( const Vector2D& point) const=0 ;
56 
58  virtual const Vector3D& origin() const =0 ;
59 
61  virtual const IMaterial& innerMaterial() const =0 ;
62 
64  virtual const IMaterial& outerMaterial() const =0 ;
65 
67  virtual double innerThickness() const =0 ;
68 
70  virtual double outerThickness() const =0 ;
71 
73  virtual double distance(const Vector3D& point ) const =0 ;
74 
78  virtual double length_along_u() const=0 ;
79 
83  virtual double length_along_v() const=0 ;
84 
85  } ;
86 
87  //==============================================================================================
93  class ICylinder {
94 
95  public:
97  virtual ~ICylinder() {}
98  virtual double radius() const=0 ;
99  virtual Vector3D center() const=0 ;
100  };
101  //==============================================================================================
107  class ICone {
108 
109  public:
111  virtual ~ICone() {}
112  virtual double radius0() const=0 ;
113  virtual double radius1() const=0 ;
114  virtual double z0() const=0 ;
115  virtual double z1() const=0 ;
116  virtual Vector3D center() const=0 ;
117  };
118 
119  //==============================================================================================
120 
128  class SurfaceType{
129 
130  public:
133  Cylinder = 0,
142  } ;
143 
145  SurfaceType() : _bits(0) {}
146 
147  // c'tor that sets one property
148  SurfaceType( unsigned prop0 ) : _bits(0) {
149  _bits.set( prop0 ) ;
150  }
151 
152  // c'tor that sets two properties
153  SurfaceType( unsigned prop0 , unsigned prop1 ) : _bits(0) {
154  _bits.set( prop0 ) ;
155  _bits.set( prop1 ) ;
156  }
157 
158  // c'tor that sets three properties
159  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2 ) : _bits(0) {
160  _bits.set( prop0 ) ;
161  _bits.set( prop1 ) ;
162  _bits.set( prop2 ) ;
163  }
164 
165  // c'tor that sets four properties
166  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2, unsigned prop3 ) : _bits(0) {
167  _bits.set( prop0 ) ;
168  _bits.set( prop1 ) ;
169  _bits.set( prop2 ) ;
170  _bits.set( prop3 ) ;
171  }
172 
173  // c'tor that sets five properties
174  SurfaceType( unsigned prop0 , unsigned prop1 , unsigned prop2, unsigned prop3, unsigned prop4 ) : _bits(0) {
175  _bits.set( prop0 ) ;
176  _bits.set( prop1 ) ;
177  _bits.set( prop2 ) ;
178  _bits.set( prop3 ) ;
179  _bits.set( prop4 ) ;
180  }
181 
183  void setProperty( unsigned prop , bool val = true ) { _bits.set( prop , val ) ; }
184 
186  bool isSensitive() const { return _bits[ SurfaceType::Sensitive ] ; }
187 
189  bool isHelper() const { return _bits[ SurfaceType::Helper ] ; }
190 
192  bool isPlane() const { return _bits[ SurfaceType::Plane ] ; }
193 
195  bool isCylinder() const { return _bits[ SurfaceType::Cylinder ] ; }
196 
198  bool isCone() const { return _bits[ SurfaceType::Cone ] ; }
199 
201  bool isParallelToZ() const { return _bits[ SurfaceType::ParallelToZ ] ; }
202 
204  bool isOrthogonalToZ() const { return _bits[ SurfaceType::OrthogonalToZ ] ; }
205 
207  bool isVisible() const { return ! _bits[ SurfaceType::Invisible ] ; }
208 
210  bool isZCylinder() const { return ( _bits[ SurfaceType::Cylinder ] && _bits[ SurfaceType::ParallelToZ ] ) ; }
211 
213  bool isZCone() const { return ( _bits[ SurfaceType::Cone ] && _bits[ SurfaceType::ParallelToZ ] ) ; }
214 
216  bool isZPlane() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::ParallelToZ ] ) ;
217  }
218 
220  bool isZDisk() const { return ( _bits[ SurfaceType::Plane ] && _bits[ SurfaceType::OrthogonalToZ ] ) ; }
221 
223  bool isMeasurement1D() const { return _bits[ SurfaceType::Measurement1D ] ; }
224 
225 
227  bool isSimilar( const SurfaceType& otherType) const {
228  unsigned long otherBits = otherType._bits.to_ulong() ;
229  unsigned long theseBits = _bits.to_ulong() ;
230  // std::cout << " ** isSimilar : " << otherType._bits.to_string() << " - " << _bits.to_string() << " : " << (( otherBits & theseBits ) == otherBits) << std::endl ;
231  return ( otherBits & theseBits ) == otherBits ;
232  }
233 
234 
236  bool checkParallelToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
237 
238  // if ( _bits[ SurfaceType::ParallelToZ ] ) // set in specific implementation
239  // return true ;
240 
241  double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
242 
243  _bits.set( SurfaceType::ParallelToZ , ( proj < epsilon ) ) ;
244 
245  // std::cout << " ** checkParallelToZ() - normal : " << surf.normal() << " pojection : " << proj
246  // << " _bits[ SurfaceType::ParallelToZ ] = " << bool( _bits[ SurfaceType::ParallelToZ ] )
247  // << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( proj < epsilon ) << std::endl ;
248 
249  return _bits[ SurfaceType::ParallelToZ ] ;
250  }
251 
253  bool checkOrthogonalToZ( const ISurface& surf , double epsilon=1.e-6 ) const {
254 
255  // if ( _bits[ SurfaceType::OrthogonalToZ ] ) // set in specific implementation
256  // return true ;
257 
258  double proj = std::fabs( surf.normal() * Vector3D(0.,0.,1.) ) ;
259 
260  _bits.set( SurfaceType::OrthogonalToZ , ( std::fabs( proj - 1. ) < epsilon ) ) ;
261 
262  // std::cout << " ** checkOrthogonalToZ() - normal : " << surf.normal() << " pojection : " << proj
263  // << " _bits[ SurfaceType::OrthogonalToZ ] = " << bool( _bits[ SurfaceType::OrthogonalToZ ] )
264  // << " ( std::fabs( proj - 1. ) < epsilon ) ) = " << ( std::fabs( proj - 1. ) < epsilon ) << std::endl ;
265 
266 
268  }
269 
270 
271  protected:
272 
273  mutable std::bitset<32> _bits ;
274  } ;
275 
277  inline std::ostream& operator<<( std::ostream& os , const SurfaceType& t ) {
278 
279  os << "sensitive[" << t.isSensitive()
280  << "] helper[" << t.isHelper()
281  << "] plane[" << t.isPlane()
282  << "] cylinder[" << t.isCylinder()
283  << "] cone[" << t.isCone()
284  << "] parallelToZ[" << t.isParallelToZ()
285  << "] orthogonalToZ[" << t.isOrthogonalToZ()
286  << "] zCylinder[" << t.isZCylinder()
287  << "] zCone[" << t.isZCone()
288  << "] zPlane[" << t.isZPlane()
289  << "] zDisk[" << t.isZDisk() << "]" ;
290 
291  return os ;
292  }
293 
294 
295 
297  inline std::ostream& operator<<( std::ostream& os , const ISurface& s ) {
298 
299  os << " id: " << std::hex << s.id() << std::dec << " type : " << s.type() << std::endl
300  << " u : " << s.u() << " v : " << s.v() << " normal : " << s.normal() << " origin : " << s.origin() << std::endl ;
301  os << " inner material : " << s.innerMaterial() << " thickness: " << s.innerThickness() << std::endl
302  << " outerMaterial : " << s.outerMaterial() << " thickness: " << s.outerThickness() << std::endl ;
303 
304  const ICylinder* cyl = dynamic_cast< const ICylinder* > ( &s ) ;
305  if( cyl )
306  os << " cylinder radius : " << cyl->radius() << std::endl ;
307 
308  const ICone* cone = dynamic_cast< const ICone* > ( &s ) ;
309  if( cone )
310  os << " cone radius0: " << cone->radius0() << " cone radius1: " << cone->radius1() << std::endl ;
311 
312  return os ;
313  }
314 
315 
316 } /* namespace DDSurfaces */
317 
318 #endif /* DDSurfaces_ISurface_H */
virtual Vector3D center() const =0
virtual bool insideBounds(const Vector3D &point, double epsilon=1.e-4) const =0
Checks if the given point lies within the surface.
bool isOrthogonalToZ() const
true if surface is orthogonal to Z
Definition: ISurface.h:204
bool isZDisk() const
true if this is a plane orthogonal to Z
Definition: ISurface.h:220
std::bitset< 32 > _bits
Definition: ISurface.h:273
virtual double length_along_v() const =0
bool isVisible() const
true if surface is not invisble - for drawing only
Definition: ISurface.h:207
virtual const Vector3D & origin() const =0
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2, unsigned prop3, unsigned prop4)
Definition: ISurface.h:174
virtual double z0() const =0
bool isMeasurement1D() const
true if the measurement is only 1D, i.e. the second direction v is not used
Definition: ISurface.h:223
bool isParallelToZ() const
true if surface is parallel to Z
Definition: ISurface.h:201
bool isZCylinder() const
true if this is a cylinder parallel to Z
Definition: ISurface.h:210
SurfaceType(unsigned prop0, unsigned prop1)
Definition: ISurface.h:153
SurfaceType()
default c'tor
Definition: ISurface.h:145
bool isSensitive() const
true if surface is sensitive
Definition: ISurface.h:186
bool isCylinder() const
true if this a cylindrical surface
Definition: ISurface.h:195
TGeoShape * s
Definition: Volumes.cpp:294
return e
Definition: Volumes.cpp:297
virtual const IMaterial & outerMaterial() const =0
Access to the material in direction of the normal.
virtual double z1() const =0
virtual Vector2D globalToLocal(const Vector3D &point) const =0
long long int long64
Definition: ISurface.h:14
virtual double radius0() const =0
virtual double outerThickness() const =0
bool isZCone() const
true if this is a cone parallel to Z
Definition: ISurface.h:213
virtual double radius() const =0
bool isSimilar(const SurfaceType &otherType) const
true if all properties of otherType are also true for this type.
Definition: ISurface.h:227
virtual long64 id() const =0
The id of this surface - corresponds to DetElement id ( or'ed with the placement ids ) ...
virtual Vector3D v(const Vector3D &point=Vector3D()) const =0
virtual double radius1() const =0
bool checkParallelToZ(const ISurface &surf, double epsilon=1.e-6) const
Definition: ISurface.h:236
bool isHelper() const
true if surface is helper surface for navigation
Definition: ISurface.h:189
virtual double length_along_u() const =0
void setProperty(unsigned prop, bool val=true)
set the given peorperty
Definition: ISurface.h:183
virtual const IMaterial & innerMaterial() const =0
Access to the material in opposite direction of the normal.
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2)
Definition: ISurface.h:159
virtual Vector3D u(const Vector3D &point=Vector3D()) const =0
std::ostream & operator<<(std::ostream &os, const IMaterial &m)
dump IMaterial operator
Definition: IMaterial.h:48
virtual double distance(const Vector3D &point) const =0
SurfaceType(unsigned prop0)
Definition: ISurface.h:148
SurfaceTypes
enum for defining the bits used to decode the properties
Definition: ISurface.h:132
virtual ~ICylinder()
Destructor.
Definition: ISurface.h:97
virtual const SurfaceType & type() const =0
properties of the surface encoded in Type.
bool isPlane() const
true if this a planar surface
Definition: ISurface.h:192
virtual Vector3D localToGlobal(const Vector2D &point) const =0
virtual ~ICone()
Destructor.
Definition: ISurface.h:111
bool checkOrthogonalToZ(const ISurface &surf, double epsilon=1.e-6) const
Definition: ISurface.h:253
virtual ~ISurface()
Destructor.
Definition: ISurface.h:31
SurfaceType(unsigned prop0, unsigned prop1, unsigned prop2, unsigned prop3)
Definition: ISurface.h:166
virtual Vector3D center() const =0
virtual double innerThickness() const =0
bool isCone() const
true if this a conical surface
Definition: ISurface.h:198
bool isZPlane() const
true if this is a plane parallel to Z
Definition: ISurface.h:216
virtual Vector3D normal(const Vector3D &point=Vector3D()) const =0
Access to the normal direction at the given point.