File indexing completed on 2025-12-16 10:12:44
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef DDREC_SURFACE_H
0014 #define DDREC_SURFACE_H
0015
0016 #include "DD4hep/Objects.h"
0017 #include "DD4hep/Volumes.h"
0018 #include "DD4hep/DetElement.h"
0019
0020 #include "DDRec/ISurface.h"
0021 #include "DDRec/Material.h"
0022
0023 #include <list>
0024 #include <memory>
0025
0026 class TGeoMatrix ;
0027
0028 namespace dd4hep {
0029 namespace rec {
0030
0031
0032
0033 class VolSurface ;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 class VolSurfaceBase : public ISurface {
0044
0045 friend class VolSurface ;
0046
0047 protected:
0048 SurfaceType _type {};
0049 Vector3D _u {};
0050 Vector3D _v {};
0051 Vector3D _n {};
0052 Vector3D _o {};
0053 double _th_i {0};
0054 double _th_o {0};
0055 MaterialData _innerMat {};
0056 MaterialData _outerMat {};
0057 Volume _vol {};
0058 long64 _id {0};
0059 unsigned _refCount {0};
0060
0061
0062 virtual void setU(const Vector3D& u) ;
0063
0064 virtual void setV(const Vector3D& v) ;
0065
0066 virtual void setNormal(const Vector3D& n) ;
0067
0068 virtual void setOrigin(const Vector3D& o) ;
0069
0070 public:
0071
0072 virtual ~VolSurfaceBase() = default;
0073
0074
0075
0076 VolSurfaceBase() = default;
0077
0078 VolSurfaceBase( SurfaceType typ,
0079 double thickness_inner ,double thickness_outer,
0080 Vector3D u_val ,Vector3D v_val ,
0081 Vector3D n ,Vector3D o, Volume vol,int identifier ) :
0082 _type(typ ) ,
0083 _u( u_val ) ,
0084 _v( v_val ) ,
0085 _n( n ) ,
0086 _o( o ),
0087 _th_i( thickness_inner ),
0088 _th_o( thickness_outer ),
0089 _vol(vol) ,
0090 _id( identifier ) {
0091 }
0092
0093
0094
0095 VolSurfaceBase(const VolSurfaceBase& c)
0096 : _type(c._type), _u(c._u), _v(c._v), _n(c._n), _o(c._o),
0097 _th_i(c._th_i), _th_o(c._th_o), _innerMat(c._innerMat),
0098 _outerMat(c._innerMat), _vol(c._vol), _id(c._id)
0099 {
0100 }
0101
0102
0103 Volume volume() const { return _vol ; }
0104
0105
0106 virtual long64 id() const ;
0107
0108
0109
0110
0111 virtual const SurfaceType& type() const ;
0112
0113
0114
0115
0116 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0117
0118
0119 virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
0120
0121
0122 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0123
0124
0125 virtual const Vector3D& origin() const ;
0126
0127
0128 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0129
0130
0131 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0132
0133
0134 virtual const IMaterial& innerMaterial() const ;
0135
0136
0137 virtual const IMaterial& outerMaterial() const ;
0138
0139
0140 virtual double innerThickness() const ;
0141
0142
0143 virtual double outerThickness() const ;
0144
0145
0146
0147
0148
0149 virtual double length_along_u() const ;
0150
0151
0152
0153
0154 virtual double length_along_v() const ;
0155
0156
0157
0158 virtual double distance(const Vector3D& point ) const ;
0159
0160
0161 virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const ;
0162
0163
0164 virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
0165
0166
0167 void setInnerMaterial( const IMaterial& mat ){ _innerMat = mat ; }
0168
0169
0170 void setOuterMaterial( const IMaterial& mat ){ _outerMat = mat ; }
0171
0172 };
0173
0174
0175
0176
0177
0178
0179
0180
0181 class VolSurface : public ISurface {
0182
0183 protected:
0184
0185 VolSurfaceBase* _surf ;
0186
0187 public:
0188
0189 virtual ~VolSurface(){
0190 if( _surf ) {
0191 -- _surf->_refCount ;
0192 if( _surf->_refCount == 0 ) delete _surf ;
0193 }
0194 }
0195
0196 VolSurface() : _surf(0) { }
0197
0198
0199 VolSurface(VolSurfaceBase* p) : _surf( p ) { ++ _surf->_refCount ; }
0200
0201
0202 VolSurface(const VolSurface& vsurf) : _surf( vsurf._surf ) {
0203 ++ _surf->_refCount ;
0204 }
0205
0206 VolSurface& operator=(const VolSurface& vsurf) {
0207 _surf = vsurf._surf ;
0208 ++ _surf->_refCount ;
0209 return *this ;
0210 }
0211
0212
0213
0214 Volume volume() const { return _surf->volume() ; }
0215
0216
0217 VolSurfaceBase* ptr() const { return _surf ; }
0218
0219
0220 virtual long64 id() const ;
0221
0222
0223
0224
0225 virtual const SurfaceType& type() const ;
0226
0227
0228
0229
0230 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0231
0232
0233 virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
0234
0235
0236 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0237
0238
0239 virtual const Vector3D& origin() const ;
0240
0241
0242 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0243
0244
0245 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0246
0247
0248 virtual const IMaterial& innerMaterial() const ;
0249
0250
0251 virtual const IMaterial& outerMaterial() const ;
0252
0253
0254 virtual double innerThickness() const ;
0255
0256
0257 virtual double outerThickness() const ;
0258
0259
0260
0261
0262
0263 virtual double length_along_u() const ;
0264
0265
0266
0267
0268 virtual double length_along_v() const ;
0269
0270
0271 virtual double distance(const Vector3D& point ) const ;
0272
0273
0274 virtual bool insideBounds(const Vector3D& point, double epsilon=1e-4 ) const ;
0275
0276 virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
0277
0278
0279 void setInnerMaterial( const IMaterial& mat ){ _surf->setInnerMaterial( mat ) ; }
0280
0281
0282 void setOuterMaterial( const IMaterial& mat ){ _surf->setOuterMaterial( mat ) ; }
0283
0284 };
0285
0286
0287
0288
0289 struct VolSurfaceList ;
0290
0291
0292
0293 VolSurfaceList* volSurfaceList( DetElement& det) ;
0294
0295
0296
0297
0298
0299
0300 struct VolSurfaceList : std::list< VolSurface > {
0301
0302 VolSurfaceList() {}
0303
0304
0305 VolSurfaceList(DetElement& det){
0306
0307 VolSurfaceList* sL = volSurfaceList( det ) ;
0308
0309 std::copy( this->end() , sL->begin() , sL->end() ) ;
0310 }
0311
0312
0313
0314 VolSurfaceList(const VolSurfaceList& vsl, DetElement& ){
0315
0316 this->insert( this->end() , vsl.begin() , vsl.end() ) ;
0317 }
0318
0319 virtual ~VolSurfaceList() ;
0320
0321 } ;
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331 class VolPlaneImpl : public VolSurfaceBase {
0332
0333 public:
0334
0335
0336 VolPlaneImpl() : VolSurfaceBase() { }
0337
0338
0339 VolPlaneImpl( SurfaceType typ, double thickness_inner ,double thickness_outer,
0340 Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val, Volume vol, int id_val ) :
0341
0342 VolSurfaceBase( typ, thickness_inner, thickness_outer, u_val,v_val, n_val, o_val, vol, id_val ) {
0343
0344 _type.setProperty( SurfaceType::Plane , true ) ;
0345 _type.setProperty( SurfaceType::Cylinder , false ) ;
0346 _type.setProperty( SurfaceType::Cone , false ) ;
0347 _type.checkParallelToZ( *this ) ;
0348 _type.checkOrthogonalToZ( *this ) ;
0349 }
0350
0351
0352 virtual double distance(const Vector3D& point ) const ;
0353 } ;
0354
0355
0356
0357
0358
0359
0360
0361 class VolCylinderImpl : public VolSurfaceBase {
0362
0363 public:
0364
0365
0366 VolCylinderImpl() : VolSurfaceBase() { }
0367
0368
0369
0370
0371
0372
0373 VolCylinderImpl( Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer, Vector3D origin ) ;
0374
0375
0376
0377
0378 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0379
0380
0381
0382
0383 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0384
0385
0386 virtual double distance(const Vector3D& point ) const ;
0387
0388
0389 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0390
0391
0392 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0393 } ;
0394
0395
0396
0397
0398
0399
0400
0401 class VolConeImpl : public VolSurfaceBase {
0402
0403
0404 double _ztip { 0.0 };
0405 double _zt0 { 0.0 };
0406 double _zt1 { 0.0 };
0407 double _tanTheta { 0.0 };
0408
0409 public:
0410
0411
0412 VolConeImpl() : VolSurfaceBase() { }
0413
0414
0415
0416
0417
0418
0419
0420 VolConeImpl( Volume vol, SurfaceType type, double thickness_inner ,double thickness_outer,
0421 Vector3D v, Vector3D origin ) ;
0422
0423
0424
0425
0426 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0427
0428
0429
0430
0431 virtual Vector3D v( const Vector3D& point = Vector3D() ) const ;
0432
0433
0434
0435
0436 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0437
0438
0439 virtual double distance(const Vector3D& point ) const ;
0440
0441
0442 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0443
0444
0445 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0446
0447 virtual std::vector< std::pair<Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
0448 } ;
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459
0460 template <class T>
0461 class VolSurfaceHandle : public VolSurface {
0462
0463 public:
0464 VolSurfaceHandle( Volume vol, SurfaceType typ, double thickness_inner ,double thickness_outer,
0465 Vector3D u_val ,Vector3D v_val ,Vector3D n_val , Vector3D o_val = Vector3D(0.,0.,0.) ) :
0466
0467 VolSurface( new T( typ, thickness_inner, thickness_outer, u_val, v_val, n_val, o_val, vol , 0 ) ){
0468 }
0469
0470 T* operator->() { return static_cast<T*>( _surf ) ; }
0471 } ;
0472
0473
0474 typedef VolSurfaceHandle< VolPlaneImpl > VolPlane ;
0475
0476
0477 class VolCylinder : public VolSurface{
0478 public:
0479 VolCylinder( Volume vol, SurfaceType typ_val, double thickness_inner ,double thickness_outer, Vector3D origin_val ) :
0480 VolSurface( new VolCylinderImpl( vol, typ_val, thickness_inner , thickness_outer, origin_val ) ) {}
0481 } ;
0482
0483 class VolCone : public VolSurface{
0484 public:
0485 VolCone( Volume vol, SurfaceType typ_val, double thickness_inner ,double thickness_outer, Vector3D v_val, Vector3D origin_val ) :
0486 VolSurface( new VolConeImpl( vol, typ_val, thickness_inner , thickness_outer, v_val, origin_val ) ) {}
0487 } ;
0488
0489
0490
0491
0492
0493
0494
0495
0496
0497
0498 class Surface: public ISurface {
0499
0500 protected:
0501
0502 DetElement _det ;
0503 mutable VolSurface _volSurf ;
0504 std::unique_ptr<TGeoMatrix> _wtM ;
0505
0506 long64 _id {0};
0507
0508 SurfaceType _type {};
0509 Vector3D _u {};
0510 Vector3D _v {};
0511 Vector3D _n {};
0512 Vector3D _o {};
0513
0514
0515 Surface() = delete;
0516 Surface( Surface const& ) = delete;
0517 Surface& operator=( Surface const& ) = delete;
0518
0519 public:
0520
0521 virtual ~Surface() {}
0522
0523
0524
0525
0526 Surface( DetElement det, VolSurface volSurf ) ;
0527
0528
0529 virtual long64 id() const ;
0530
0531
0532
0533
0534 virtual const SurfaceType& type() const ;
0535
0536
0537 Volume volume() const { return _volSurf.volume() ; }
0538
0539
0540 VolSurface volSurface() const { return _volSurf ; }
0541
0542
0543 DetElement detElement() const { return _det; }
0544
0545
0546
0547
0548
0549 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0550
0551
0552 virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
0553
0554
0555 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0556
0557
0558 virtual const Vector3D& origin() const ;
0559
0560
0561 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0562
0563
0564 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0565
0566
0567 virtual double innerThickness() const ;
0568
0569
0570 virtual double outerThickness() const ;
0571
0572
0573 virtual const IMaterial& innerMaterial() const ;
0574
0575
0576 virtual const IMaterial& outerMaterial() const ;
0577
0578
0579 virtual double distance(const Vector3D& point ) const ;
0580
0581
0582 virtual bool insideBounds(const Vector3D& point, double epsilon=1.e-4) const ;
0583
0584
0585 virtual Vector3D volumeOrigin() const ;
0586
0587
0588
0589
0590 virtual double length_along_u() const ;
0591
0592
0593
0594
0595 virtual double length_along_v() const ;
0596
0597
0598
0599
0600 virtual std::vector< std::pair< Vector3D, Vector3D> > getLines(unsigned nMax=100) ;
0601
0602 protected:
0603 void initialize() ;
0604
0605 };
0606
0607
0608
0609
0610
0611
0612
0613
0614 class CylinderSurface: public Surface, public ICylinder {
0615
0616 public:
0617
0618
0619 CylinderSurface( DetElement det, VolSurface volSurf ) : Surface( det, volSurf ) { }
0620
0621
0622
0623
0624 virtual Vector3D u( const Vector3D& point = Vector3D() ) const ;
0625
0626
0627
0628
0629 virtual Vector3D v(const Vector3D& point = Vector3D() ) const ;
0630
0631
0632
0633
0634 virtual Vector3D normal(const Vector3D& point = Vector3D() ) const ;
0635
0636
0637 virtual Vector2D globalToLocal( const Vector3D& point) const ;
0638
0639
0640 virtual Vector3D localToGlobal( const Vector2D& point) const ;
0641
0642
0643 virtual double radius() const ;
0644
0645
0646 virtual Vector3D center() const ;
0647
0648 } ;
0649
0650
0651
0652
0653
0654
0655 class ConeSurface : public CylinderSurface, public ICone {
0656 public:
0657 ConeSurface( DetElement det, VolSurface volSurf ) : CylinderSurface( det, volSurf ) { }
0658
0659
0660 virtual double radius0() const ;
0661
0662
0663 virtual double radius1() const ;
0664
0665
0666 virtual double z0() const ;
0667
0668
0669 virtual double z1() const ;
0670
0671
0672 virtual Vector3D center() const ;
0673
0674 };
0675
0676
0677
0678
0679
0680
0681 class SurfaceList : public std::list< ISurface* > {
0682
0683 protected:
0684 bool _isOwner {false};
0685
0686 public:
0687
0688 SurfaceList() = default;
0689
0690 SurfaceList(bool isOwner ) : _isOwner( isOwner ) {}
0691
0692 SurfaceList(const SurfaceList& other ) = default;
0693
0694 SurfaceList(const DetElement& ) {}
0695
0696 SurfaceList(const SurfaceList& ,const DetElement& ) {}
0697
0698 virtual ~SurfaceList();
0699 };
0700
0701
0702
0703
0704
0705
0706 }
0707 }
0708
0709
0710
0711 #endif