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