Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:02

0001 //==========================================================================
0002 //  Surface installer plugin for generic sliced detector drivers
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : N. Nikiforou, adapted from dd4hep/SiTrackerBarrel_surfaces.cpp
0011 //              by M. Frank. Originally part of the lcgeo package
0012 //==========================================================================
0013 
0014 /** \addtogroup SurfacePlugin
0015  * @{
0016  * \package dd4hep_GenericSurfaceInstallerPlugin
0017  * \brief Plugin to install measurement surfaces on a generic sliced detector
0018  * 
0019  * Takes up to 13 arguments:
0020  * - \c dimension: A property of the surface that determines whether the resulting
0021  *   measurement is 1-D, e.g. strips (\c dimension=1) or 2-D, e.g. pixels (\c dimension=2).
0022  * - \c u_x, \c u_y, and \c u_z: The x, y, and z components of the u vector, usually associated
0023  *   with the "good" (i.e. best resolution) measurement direction.
0024  * - \c v_x, \c v_y, and \c v_z: The x, y, and z components of the v vector, usually associated
0025  *   with the "bad" (i.e. worst resolution) measurement direction.
0026  * - \c n_x, \c n_y, and \c n_z: The x, y, and z components of the vector perpendicular to the surface
0027  *   plane and usually pointing outwards of the detector. 
0028  * - \c o_x, \c o_y, and \c o_z: The x, y, and z components of the origin vector, used to shift the origin
0029  *   of the surface from where it is placed within the volume (usually in the center
0030  *   of a sensitive volume.
0031  * 
0032  * All the arguments are conveniently initialized to zero by default, 
0033  * therefore only the non-zero components need to be provided. For example, to use this
0034  * plugin for the VertexEndcap detector, put this snippet in the relevant compact file:
0035  * \verbatim 
0036 <plugins>
0037       <plugin name="DD4hep_GenericSurfaceInstallerPlugin">
0038           <argument value="VertexEndcap"/>
0039           <argument value="dimension=2"/>
0040           <argument value="u_x=-1."/>
0041           <argument value="v_z=1."/>
0042           <argument value="n_y=1."/>
0043       </plugin>
0044 </plugins>
0045 \endverbatim
0046  * The plugin assumes boxes are stacked along one of the primary axes, x,y or z 
0047  * The normal vector (n) must be along one of the axes (i.e. only one non-zero 
0048  * component). The inner/outer thicknesses are calculated according to n.
0049  * 
0050  * Note: Assumes module and component volumes are boxes. For Trapezoids,
0051  * a fitting box is built around the trapezoid which means dx1=dx2=dx1 and
0052  * dy1=dy2=dy. This is in principle fine, since we only access the thicknesses
0053  * (DY in the TrackerEncapSurfacePlugin example) which is supposed to be the same.
0054  *
0055  * For more information, please consult with GenericSurfaceInstaller.cpp
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 // Framework include files
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         //Initialize defaults to zero
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     /// Install measurement surfaces
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             //FIXME: WHAT IF TRAPEZOID? Should work if trapezoid since it will fit minimal box and dy1=dy2=dy
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                 //Surface is placed at the center of the volume, no need to shift origin
0163                 //Make sure u,v,n form a right-handed coordinate system, v along the final z
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 }// namespace