File indexing completed on 2025-01-18 09:14:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 namespace {
0060 struct UserData {
0061 int dimension ;
0062 double uvector[3];
0063 double vvector[3];
0064 double nvector[3];
0065 double ovector[3];
0066
0067 };
0068
0069 }
0070
0071
0072 #define SURFACEINSTALLER_DATA UserData
0073 #define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_GenericSurfaceInstallerPlugin
0074 #include "DD4hep/SurfaceInstaller.h"
0075
0076 namespace{
0077 template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
0078
0079
0080 data.dimension=0;
0081 data.uvector[0]=0.;
0082 data.uvector[1]=0.;
0083 data.uvector[2]=0.;
0084 data.vvector[0]=0.;
0085 data.vvector[1]=0.;
0086 data.vvector[2]=0.;
0087 data.nvector[0]=0.;
0088 data.nvector[1]=0.;
0089 data.nvector[2]=0.;
0090 data.ovector[0]=0.;
0091 data.ovector[1]=0.;
0092 data.ovector[2]=0.;
0093
0094 for(int i=0; i<argc; ++i) {
0095 double value = -1;
0096 char* ptr = ::strchr(argv[i],'=');
0097 if ( ptr ) {
0098 std::string name( argv[i] , ptr ) ;
0099 value = dd4hep::_toDouble(++ptr);
0100 std::cout << "DD4hep_GenericSurfaceInstallerPlugin: argument[" << i << "] = " << name
0101 << " = " << value << std::endl;
0102 if( name=="dimension" ) data.dimension = value ;
0103 if( name=="u_x" ) data.uvector[0]=value ;
0104 if( name=="u_y" ) data.uvector[1]=value ;
0105 if( name=="u_z" ) data.uvector[2]=value ;
0106 if( name=="v_x" ) data.vvector[0]=value ;
0107 if( name=="v_y" ) data.vvector[1]=value ;
0108 if( name=="v_z" ) data.vvector[2]=value ;
0109 if( name=="n_x" ) data.nvector[0]=value ;
0110 if( name=="n_y" ) data.nvector[1]=value ;
0111 if( name=="n_z" ) data.nvector[2]=value ;
0112 if( name=="o_x" ) data.ovector[0]=value ;
0113 if( name=="o_y" ) data.ovector[1]=value ;
0114 if( name=="o_z" ) data.ovector[2]=value ;
0115 }
0116 }
0117
0118 std::cout <<"DD4hep_GenericSurfaceInstallerPlugin: vectors: ";
0119 std::cout <<"u( "<<data.uvector[0]<<" , "<<data.uvector[1]<<" , "<<data.uvector[2]<<") ";
0120 std::cout <<"v( "<<data.vvector[0]<<" , "<<data.vvector[1]<<" , "<<data.vvector[2]<<") ";
0121 std::cout <<"n( "<<data.nvector[0]<<" , "<<data.nvector[1]<<" , "<<data.nvector[2]<<") ";
0122 std::cout <<"o( "<<data.ovector[0]<<" , "<<data.ovector[1]<<" , "<<data.ovector[2]<<") "<<std::endl;
0123
0124 }
0125
0126
0127 template <typename UserData>
0128 void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
0129 dd4hep::Volume comp_vol = pv.volume();
0130 if ( comp_vol.isSensitive() ) {
0131 dd4hep::Volume mod_vol = parentVolume(component);
0132
0133 dd4hep::Box mod_shape(mod_vol.solid()), comp_shape(comp_vol.solid());
0134
0135 if ( !comp_shape.isValid() || !mod_shape.isValid() ) {
0136 invalidInstaller("DD4hep_GenericSurfaceInstallerPlugin: Components and/or modules are not boxes -- invalid shapes");
0137
0138 }else if ( !handleUsingCache(component,comp_vol) ) {
0139 const double* trans = placementTranslation(component);
0140 double half_module_thickness = 0.;
0141 double sensitive_z_position = 0.;
0142
0143 if (data.nvector[0] !=0 && data.nvector[1] ==0 && data.nvector[2] ==0){
0144 half_module_thickness = mod_shape->GetDX();
0145 sensitive_z_position = data.nvector[0]>0 ? trans[0] : -trans[0];
0146 }else if (data.nvector[1] !=0 && data.nvector[0] ==0 && data.nvector[2] ==0){
0147 half_module_thickness = mod_shape->GetDY();
0148 sensitive_z_position = data.nvector[1]>0 ? trans[1] : -trans[1];
0149
0150 }else if (data.nvector[2] !=0 && data.nvector[0] ==0 && data.nvector[1] ==0){
0151 half_module_thickness = mod_shape->GetDZ();
0152 sensitive_z_position = data.nvector[2]>0 ? trans[2] : -trans[2];
0153
0154 } else {
0155 throw std::runtime_error("**** dd4hep_GenericSurfaceInstallerPlugin: normal vector unsupported! It has to be "
0156 "perpenidcular to one of the box sides, i.e. only one non-zero component.") ;
0157 }
0158
0159 double inner_thickness = half_module_thickness + sensitive_z_position;
0160 double outer_thickness = half_module_thickness - sensitive_z_position;
0161
0162
0163
0164 Vector3D u(data.uvector[0],data.uvector[1],data.uvector[2]);
0165 Vector3D v(data.vvector[0],data.vvector[1],data.vvector[2]);
0166 Vector3D n(data.nvector[0],data.nvector[1],data.nvector[2]);
0167 Vector3D o(data.ovector[0],data.ovector[1],data.ovector[2]);
0168 Type type( Type::Sensitive ) ;
0169
0170 if( data.dimension == 1 ) {
0171 type.setProperty( Type::Measurement1D , true ) ;
0172 } else if( data.dimension != 2 ) {
0173 throw std::runtime_error("**** dd4hep_GenericSurfaceInstallerPlugin: no or wrong "
0174 "'dimension' argument given - has to be 1 or 2") ;
0175 }
0176 VolPlane surf(comp_vol, type, inner_thickness, outer_thickness, u, v, n, o);
0177 addSurface(component,surf);
0178 }
0179 }
0180 }
0181 }