File indexing completed on 2025-01-18 09:14:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <string>
0015
0016 namespace {
0017 struct UserData {
0018 float zpos ;
0019 float radius ;
0020 float phi0 ;
0021 int symmetry ;
0022 int systemID ;
0023 std::string encoding ;
0024 };
0025 }
0026
0027
0028 #define SURFACEINSTALLER_DATA UserData
0029 #define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_CaloFaceEndcapSurfacePlugin
0030 #include "DD4hep/Printout.h"
0031 #include "DD4hep/SurfaceInstaller.h"
0032 #include "DDRec/DetectorData.h"
0033 #include "DDRec/Surface.h"
0034 #include "DDSegmentation/BitField64.h"
0035
0036 namespace{
0037
0038
0039 class CaloEndcapPlaneImpl : public dd4hep::rec::VolPlaneImpl{
0040 double _r ;
0041 double _phi0 ;
0042 unsigned _sym ;
0043 public:
0044
0045 CaloEndcapPlaneImpl( dd4hep::rec::SurfaceType typ,
0046 double thickness_inner ,double thickness_outer,
0047 dd4hep::rec::Vector3D u_val ,dd4hep::rec::Vector3D v_val ,
0048 dd4hep::rec::Vector3D n_val , dd4hep::rec::Vector3D o_val,
0049 dd4hep::Volume vol, int id_val ) :
0050 dd4hep::rec::VolPlaneImpl( typ, thickness_inner,thickness_outer, u_val, v_val, n_val, o_val, vol, id_val),
0051 _r(0),_phi0(0),_sym(0) {}
0052
0053 void setData( double radius, double phi0, unsigned symmetry){
0054 _r = radius ;
0055 _phi0 = phi0 ;
0056 _sym = symmetry ;
0057 }
0058 void setID( dd4hep::CellID id_val ) { _id = id_val; }
0059
0060
0061 bool insideBounds(const dd4hep::rec::Vector3D& point, double epsilon) const {
0062
0063 double ri = _r * cos( 2.* M_PI / _sym ) ;
0064
0065 return ( std::abs ( distance( point ) ) < epsilon ) &&
0066 ( (point.rho() < ri ) ||
0067 ( volume()->GetShape()->Contains( const_cast<double*> (point.const_array() ) ) ) ) ;
0068 }
0069
0070
0071 virtual std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > getLines(unsigned){
0072
0073 std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > lines ;
0074
0075 double alpha = ( _sym ? 2.* M_PI / _sym : 0. ) ;
0076
0077 for(unsigned i=0 ; i < _sym ; ++i){
0078 double gam0 = i * alpha + _phi0 ;
0079 double gam1 = (i+1) * alpha + _phi0 ;
0080 lines.push_back( std::make_pair( dd4hep::rec::Vector3D( _r*cos(gam0), _r*sin(gam0), origin().z() ),
0081 dd4hep::rec::Vector3D( _r*cos(gam1), _r*sin(gam1), origin().z() ) ) ) ;
0082 }
0083 return lines;
0084 }
0085 };
0086
0087 typedef dd4hep::rec::VolSurfaceHandle<CaloEndcapPlaneImpl> CaloEndcapPlane ;
0088
0089
0090 template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
0091 for(int i=0; i<argc; ++i) {
0092 char* ptr = ::strchr(argv[i],'=');
0093 if ( ptr ) {
0094 std::string name( argv[i] , ptr ) ;
0095 double value = dd4hep::_toDouble(++ptr);
0096
0097 printout(dd4hep::DEBUG,"DD4hep_CaloFaceEndcapSurfacePlugin", "argument[%d] = %s = %f" , i, name.c_str() , value ) ;
0098
0099 if( name=="zpos" ) data.zpos = value ;
0100 else if( name=="radius" ) data.radius = value ;
0101 else if( name=="phi0" ) data.phi0 = value ;
0102 else if( name=="symmetry") data.symmetry = value ;
0103 else if( name=="systemID") data.systemID = value ;
0104 else if( name=="encoding") data.encoding = ptr ;
0105 else {
0106 printout(dd4hep::WARNING,"DD4hep_CaloFaceEndcapSurfacePlugin", "unknown parameter: %s ", name.c_str() ) ;
0107 }
0108 }
0109 }
0110 }
0111
0112
0113 template <typename UserData>
0114 void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
0115
0116 dd4hep::Volume comp_vol = pv.volume();
0117
0118
0119 double zpos = data.zpos ;
0120 double symmetry = data.symmetry ;
0121 double radius = data.radius ;
0122 double phi0 = data.phi0 ;
0123
0124 if( symmetry ) radius /= cos( M_PI / symmetry ) ;
0125
0126
0127 double inner_thickness = 1e-6 ;
0128 double outer_thickness = 1e-6 ;
0129
0130 printout(dd4hep::INFO,"DD4hep_CaloFaceEndcapSurfacePlugin", "install tracking surfaces for : %s ", component.name() ) ;
0131
0132
0133 dd4hep::DDSegmentation::BitField64 bf( "system:5,side:-2,layer:9,module:8,sensor:8" ) ;
0134
0135
0136 bf["system"] = data.systemID ;
0137 bf["side"] = 1 ;
0138
0139
0140
0141 dd4hep::rec::Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(0., 0.5*radius , zpos );
0142
0143 CaloEndcapPlane surf_pz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, o);
0144
0145 surf_pz->setData( radius, phi0, symmetry ) ;
0146 surf_pz->setID( bf.getValue() ) ;
0147
0148 addSurface(component,surf_pz);
0149
0150 CaloEndcapPlane surf_nz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, -1*o );
0151
0152 bf["side"] = -1 ;
0153 surf_nz->setData( radius, phi0, symmetry ) ;
0154 surf_nz->setID( bf.getValue() ) ;
0155
0156 addSurface(component,surf_nz);
0157
0158
0159 stopScanning() ;
0160 }
0161
0162
0163 }