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
Surface.h
Go to the documentation of this file.
1 #ifndef DDRec_Surface_H
2 #define DDRec_Surface_H
3 
4 #include "DD4hep/Objects.h"
5 #include "DD4hep/Volumes.h"
6 #include "DD4hep/Detector.h"
7 
8 #include "DDSurfaces/ISurface.h"
9 #include "DDRec/Material.h"
10 
11 #include <list>
12 
13 class TGeoMatrix ;
14 
15 namespace DD4hep {
16  namespace DDRec {
17 
18  using namespace DDSurfaces ;
19 
20  //-------------------------------------------------------------------------------------------
21 
22  class VolSurface ;
23 
32  class VolSurfaceBase : public ISurface {
33 
34  friend class VolSurface ;
35 
36  protected:
42  double _th_i ;
43  double _th_o ;
48  unsigned _refCount ;
49 
51  virtual void setU(const Vector3D& u) ;
53  virtual void setV(const Vector3D& v) ;
55  virtual void setNormal(const Vector3D& n) ;
57  virtual void setOrigin(const Vector3D& o) ;
58 
59  public:
60 
61  virtual ~VolSurfaceBase() {}
62 
64 
66  _type( SurfaceType() ) ,
67  _u( Vector3D() ) ,
68  _v( Vector3D() ) ,
69  _n( Vector3D() ) ,
70  _o( Vector3D() ) ,
71  _th_i( 0. ),
72  _th_o( 0. ),
73  _innerMat( MaterialData() ),
74  _outerMat( MaterialData() ),
75  _vol(),
76  _id(0),_refCount(0) {
77  }
78 
79 
81  double thickness_inner ,double thickness_outer,
82  Vector3D u_val ,Vector3D v_val ,
83  Vector3D n ,Vector3D o, Geometry::Volume vol,int identifier ) :
84  _type(typ ) ,
85  _u( u_val ) ,
86  _v( v_val ) ,
87  _n( n ) ,
88  _o( o ),
89  _th_i( thickness_inner ),
90  _th_o( thickness_outer ),
91  _innerMat( MaterialData() ),
92  _outerMat( MaterialData() ),
93  _vol(vol) ,
94  _id( identifier ), _refCount(0) {
95  }
96 
97 
100  _type = c._type ;
101  _u = c._u ;
102  _v = c._v ;
103  _n = c._n ;
104  _o = c._o;
105  _th_i = c._th_i ;
106  _th_o = c._th_o ;
107  _innerMat = c._innerMat ;
108  _outerMat = c._innerMat ;
109  _vol = c._vol;
110  _id = c._id ;
111  _refCount = 0 ; // new instance
112  }
113 
114 
116  Geometry::Volume volume() const { return _vol ; }
117 
119  virtual long64 id() const ;
120 
124  virtual const SurfaceType& type() const ;
125 
126  //==== geometry ====
127 
129  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
130 
132  virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
133 
135  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
136 
138  virtual const Vector3D& origin() const ;
139 
141  virtual Vector2D globalToLocal( const Vector3D& point) const ;
142 
144  virtual Vector3D localToGlobal( const Vector2D& point) const ;
145 
147  virtual const IMaterial& innerMaterial() const ;
148 
150  virtual const IMaterial& outerMaterial() const ;
151 
153  virtual double innerThickness() const ;
154 
156  virtual double outerThickness() const ;
157 
158 
162  virtual double length_along_u() const ;
163 
167  virtual double length_along_v() const ;
168 
169 
171  virtual double distance(const Vector3D& point ) const ;
172 
174  virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const ;
175 
176 
177  virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
178 
180  void setInnerMaterial( const IMaterial& mat ){ _innerMat = mat ; }
181 
183  void setOuterMaterial( const IMaterial& mat ){ _outerMat = mat ; }
184 
185  };
186 
187  //---------------------------------------------------------------------------------------------
194  class VolSurface : public ISurface {
195 
196  protected:
197 
199 
200  public:
201 
202  virtual ~VolSurface(){
203  if( _surf ) {
204  -- _surf->_refCount ;
205  if( _surf->_refCount == 0 ) delete _surf ;
206  }
207  }
209  VolSurface() : _surf(0) { }
210 
212  VolSurface(VolSurfaceBase* p) : _surf( p ) { ++ _surf->_refCount ; }
213 
215  VolSurface(const VolSurface& vsurf) : _surf( vsurf._surf ) {
216  ++ _surf->_refCount ;
217  }
218 
219  VolSurface& operator=(const VolSurface& vsurf) {
220  _surf = vsurf._surf ;
221  ++ _surf->_refCount ;
222  return *this ;
223  }
224 
225 
227  Geometry::Volume volume() const { return _surf->volume() ; }
228 
230  VolSurfaceBase* ptr() const { return _surf ; }
231 
233  virtual long64 id() const ;
234 
238  virtual const SurfaceType& type() const ;
239 
240  //==== geometry ====
241 
243  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
244 
246  virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
247 
249  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
250 
252  virtual const Vector3D& origin() const ;
253 
255  virtual Vector2D globalToLocal( const Vector3D& point) const ;
256 
258  virtual Vector3D localToGlobal( const Vector2D& point) const ;
259 
261  virtual const IMaterial& innerMaterial() const ;
262 
264  virtual const IMaterial& outerMaterial() const ;
265 
267  virtual double innerThickness() const ;
268 
270  virtual double outerThickness() const ;
271 
272 
276  virtual double length_along_u() const ;
277 
281  virtual double length_along_v() const ;
282 
284  virtual double distance(const Vector3D& point ) const ;
285 
287  virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const ;
288 
289  virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
290 
292  void setInnerMaterial( const IMaterial& mat ){ _surf->setInnerMaterial( mat ) ; }
293 
295  void setOuterMaterial( const IMaterial& mat ){ _surf->setOuterMaterial( mat ) ; }
296 
297  };
298 
299  //======================================================================================================
300 
301 
302  struct VolSurfaceList ;
306  VolSurfaceList* volSurfaceList( Geometry::DetElement& det) ;
307 
313  struct VolSurfaceList : std::list< VolSurface > {
314 
316 
317  // required c'tor for extension mechanism
319 
320  VolSurfaceList* sL = volSurfaceList( det ) ;
321 
322  std::copy( this->end() , sL->begin() , sL->end() ) ;
323  }
324 
325 
326  // required c'tor for extension mechanism
328 
329  this->insert( this->end() , vsl.begin() , vsl.end() ) ;
330  }
331 
332  virtual ~VolSurfaceList() ;
333 
334  } ;
335 
336 
337  //======================================================================================================
338 
344  class VolPlaneImpl : public VolSurfaceBase {
345 
346  public:
347 
350 
352  VolPlaneImpl( SurfaceType typ, double thickness_inner ,double thickness_outer,
353  Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val, Geometry::Volume vol, int id_val ) :
354 
355  VolSurfaceBase( typ, thickness_inner, thickness_outer, u_val,v_val, n_val, o_val, vol, id_val ) {
356 
357  _type.setProperty( SurfaceType::Plane , true ) ;
358  _type.setProperty( SurfaceType::Cylinder , false ) ;
359  _type.setProperty( SurfaceType::Cone , false ) ;
360  _type.checkParallelToZ( *this ) ;
361  _type.checkOrthogonalToZ( *this ) ;
362  }
363 
365  virtual double distance(const Vector3D& point ) const ;
366  } ;
367 
368  //======================================================================================================
375 
376  public:
377 
380 
381 
386  VolCylinderImpl( Geometry::Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D origin ) ;
387 
391  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
392 
396  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
397 
399  virtual double distance(const Vector3D& point ) const ;
400 
402  virtual Vector2D globalToLocal( const Vector3D& point) const ;
403 
405  virtual Vector3D localToGlobal( const Vector2D& point) const ;
406  } ;
407 
408  //======================================================================================================
414  class VolConeImpl : public VolSurfaceBase {
415 
416  //internal helper variables
417  double _ztip ; // z position of the tip in the volume coordinate system
418  double _zt0 ; // z distance of the front face from the tip
419  double _zt1 ; // z distance of the back face from the tip
420  double _tanTheta ; // tan of half the openeing angle
421 
422  public:
423 
426 
427 
433  VolConeImpl( Geometry::Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer,
434  Vector3D v, Vector3D origin ) ;
435 
439  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
440 
444  virtual Vector3D v( const Vector3D& point = Vector3D() ) const ;
445 
449  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
450 
452  virtual double distance(const Vector3D& point ) const ;
453 
455  virtual Vector2D globalToLocal( const Vector3D& point) const ;
456 
458  virtual Vector3D localToGlobal( const Vector2D& point) const ;
459 
460  virtual std::vector< std::pair<DDSurfaces::Vector3D, DDSurfaces::Vector3D> > getLines(unsigned nMax=100) ;
461  } ;
462 
463 
464 
465  //======================================================================================================
466 
473  template <class T>
474  class VolSurfaceHandle : public VolSurface {
475 
476  public:
477  VolSurfaceHandle( Geometry::Volume vol, SurfaceType typ, double thickness_inner ,double thickness_outer,
478  Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val = Vector3D(0.,0.,0.) ) :
479 
480  VolSurface( new T( typ, thickness_inner, thickness_outer, u_val, v_val, n_val, o_val, vol , 0 ) ){
481  }
482 
483  T* operator->() { return static_cast<T*>( _surf ) ; }
484  } ;
485 
486  //---------------------------------------------------------------------------------------------
488  //---------------------------------------------------------------------------------------------
489 
490  class VolCylinder : public VolSurface{
491  public:
492  VolCylinder( Geometry::Volume vol, SurfaceType typ_val, double thickness_inner ,double thickness_outer, Vector3D origin_val ) :
493  VolSurface( new VolCylinderImpl( vol, typ_val, thickness_inner , thickness_outer, origin_val ) ) {}
494  } ;
495 
496  class VolCone : public VolSurface{
497  public:
498  VolCone( Geometry::Volume vol, SurfaceType typ_val, double thickness_inner ,double thickness_outer, Vector3D v_val, Vector3D origin_val ) :
499  VolSurface( new VolConeImpl( vol, typ_val, thickness_inner , thickness_outer, v_val, origin_val ) ) {}
500  } ;
501 
502  //======================================================================================================
503 
511  class Surface: public ISurface {
512 
513  protected:
514 
517  TGeoMatrix* _wtM ; // matrix for world transformation of surface
518 
520 
526 
528  Surface() :_det( Geometry::DetElement() ), _volSurf( VolSurface() ), _wtM( 0 ) , _id( 0) { }
529 
530  public:
531 
532  virtual ~Surface() {}
533 
537  Surface( Geometry::DetElement det, VolSurface volSurf ) ;
538 
540  virtual long64 id() const ;
541 
545  virtual const SurfaceType& type() const ;
546 
548  Geometry::Volume volume() const { return _volSurf.volume() ; }
549 
551  VolSurface volSurface() const { return _volSurf ; }
552 
553 
554  //==== geometry ====
555 
557  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
558 
560  virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
561 
563  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
564 
566  virtual const Vector3D& origin() const ;
567 
569  virtual Vector2D globalToLocal( const Vector3D& point) const ;
570 
572  virtual Vector3D localToGlobal( const Vector2D& point) const ;
573 
575  virtual double innerThickness() const ;
576 
578  virtual double outerThickness() const ;
579 
581  virtual const IMaterial& innerMaterial() const ;
582 
584  virtual const IMaterial& outerMaterial() const ;
585 
587  virtual double distance(const Vector3D& point ) const ;
588 
590  virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const ;
591 
593  virtual Vector3D volumeOrigin() const ;
594 
598  virtual double length_along_u() const ;
599 
603  virtual double length_along_v() const ;
604 
608  virtual std::vector< std::pair< Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
609 
610  protected:
611  void initialize() ;
612 
613  };
614 
615  //======================================================================================================
616 
622  class CylinderSurface: public Surface, public ICylinder {
623 
624  public:
625 
627  CylinderSurface( Geometry::DetElement det, VolSurface volSurf ) : Surface( det, volSurf ) { }
628 
632  virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
633 
637  virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
638 
642  virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
643 
645  virtual Vector2D globalToLocal( const Vector3D& point) const ;
646 
648  virtual Vector3D localToGlobal( const Vector2D& point) const ;
649 
651  virtual double radius() const ;
652 
654  virtual Vector3D center() const ;
655 
656  } ;
657  //======================================================================================================
658 
663  class ConeSurface : public CylinderSurface, public ICone {
664  public:
665  ConeSurface( Geometry::DetElement det, VolSurface volSurf ) : CylinderSurface( det, volSurf ) { }
666 
668  virtual double radius0() const ;
669 
671  virtual double radius1() const ;
672 
674  virtual double z0() const ;
675 
677  virtual double z1() const ;
678 
680  virtual Vector3D center() const ;
681 
682  };
683  //======================================================================================================
689  class SurfaceList : public std::list< ISurface* > {
690 
691  protected:
692  bool _isOwner ;
693 
694  public:
696  SurfaceList(bool isOwner=false ) : _isOwner( isOwner ) {}
697 
699  SurfaceList(const SurfaceList& other ) : std::list< ISurface* >( other ), _isOwner( false ){}
700 
703  // anything to do here ?
704  }
707  // anything to do here ?
708  }
709 
711  virtual ~SurfaceList() ;
712 
713  } ;
714 
715  // SurfaceList* surfaceList( Geometry::DetElement& det ) ;
716 
717  //======================================================================================================
718 
719 
720  } /* namespace */
721 } /* namespace */
722 
723 #endif /* Surface */
VolSurface()
default c'tor
Definition: Surface.h:209
VolSurface(VolSurfaceBase *p)
Constructor to be used with an existing object.
Definition: Surface.h:212
Geometry::Volume volume() const
the volume to which this surface is attached.
Definition: Surface.h:116
CylinderSurface(Geometry::DetElement det, VolSurface volSurf)
Standard c'tor.
Definition: Surface.h:627
VolCylinderImpl()
default c'tor
Definition: Surface.h:379
VolPlaneImpl(SurfaceType typ, double thickness_inner, double thickness_outer, Vector3D u_val, Vector3D v_val, Vector3D n_val, Vector3D o_val, Geometry::Volume vol, int id_val)
standard c'tor with all necessary arguments - origin is (0,0,0) if not given.
Definition: Surface.h:352
TGeoMatrix * _wtM
Definition: Surface.h:517
VolCylinder(Geometry::Volume vol, SurfaceType typ_val, double thickness_inner, double thickness_outer, Vector3D origin_val)
Definition: Surface.h:492
virtual ~Surface()
Definition: Surface.h:532
Geometry::DetElement _det
Definition: Surface.h:515
VolPlaneImpl()
default c'tor
Definition: Surface.h:349
VolSurface _volSurf
Definition: Surface.h:516
VolSurfaceBase()
default c'tor
Definition: Surface.h:65
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
return e
Definition: Volumes.cpp:297
VolSurfaceBase * _surf
Definition: Surface.h:198
VolCone(Geometry::Volume vol, SurfaceType typ_val, double thickness_inner, double thickness_outer, Vector3D v_val, Vector3D origin_val)
Definition: Surface.h:498
long long int long64
Definition: ISurface.h:14
VolSurface volSurface() const
The VolSurface attched to the volume.
Definition: Surface.h:551
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:237
VolSurfaceBase(const VolSurfaceBase &c)
Copy the from object.
Definition: Surface.h:99
SurfaceList(const SurfaceList &, const Geometry::DetElement &)
required c'tor for extension mechanism
Definition: Surface.h:706
SurfaceList(const Geometry::DetElement &)
required c'tor for extension mechanism
Definition: Surface.h:702
VolSurface & operator=(const VolSurface &vsurf)
Definition: Surface.h:219
VolConeImpl()
default c'tor
Definition: Surface.h:425
SurfaceList(bool isOwner=false)
defaul c'tor - allow to set ownership for surfaces
Definition: Surface.h:696
VolSurfaceList(Geometry::DetElement &det)
Definition: Surface.h:318
void setOuterMaterial(const IMaterial &mat)
set the outer Materal
Definition: Surface.h:183
SurfaceList(const SurfaceList &other)
copy c'tor
Definition: Surface.h:699
void setOuterMaterial(const IMaterial &mat)
set the outer Materal
Definition: Surface.h:295
VolSurfaceHandle< VolPlaneImpl > VolPlane
Definition: Surface.h:487
VolSurface(const VolSurface &vsurf)
Constructor to be used with an existing object.
Definition: Surface.h:215
Surface()
default c'tor
Definition: Surface.h:528
VolSurfaceBase * ptr() const
pointer to underlying object
Definition: Surface.h:230
VolSurfaceList(const VolSurfaceList &vsl, Geometry::DetElement &)
Definition: Surface.h:327
Geometry::Volume volume() const
the volume to which this surface is attached.
Definition: Surface.h:227
ConeSurface(Geometry::DetElement det, VolSurface volSurf)
Definition: Surface.h:665
Handle class describing a detector element.
Definition: Detector.h:172
VolSurfaceList * volSurfaceList(DetElement &det)
Definition: Surface.cpp:511
SurfaceType _type
Definition: Surface.h:521
void setInnerMaterial(const IMaterial &mat)
set the inner Material
Definition: Surface.h:180
View * v
Definition: MultiView.cpp:30
VolSurfaceBase(SurfaceType typ, double thickness_inner, double thickness_outer, Vector3D u_val, Vector3D v_val, Vector3D n, Vector3D o, Geometry::Volume vol, int identifier)
Definition: Surface.h:80
void setInnerMaterial(const IMaterial &mat)
set the innerMaterial
Definition: Surface.h:292
Geometry::Volume _vol
Definition: Surface.h:46
Geometry::Volume volume() const
The volume that has the surface attached.
Definition: Surface.h:548
VolSurfaceHandle(Geometry::Volume vol, SurfaceType typ, double thickness_inner, double thickness_outer, Vector3D u_val, Vector3D v_val, Vector3D n_val, Vector3D o_val=Vector3D(0., 0., 0.))
Definition: Surface.h:477