Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
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     : F.Gaede DESY
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 // Framework include files
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   /// helper class for a planar surface placed into a polyhedral calorimeter endcap 
0039   class CaloEndcapPlaneImpl : public  dd4hep::rec::VolPlaneImpl{
0040     double  _r ;
0041     double  _phi0 ;
0042     unsigned _sym ;
0043   public:
0044     /// standard c'tor with all necessary arguments - origin is (0,0,0) if not given.
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     // overwrite to include points inside the inner radius of the endcap 
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     /// create outer bounding lines for the given symmetry of the polyhedron
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   /// Install measurement surfaces
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     //dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
0135 
0136     bf["system"] = data.systemID ;
0137     bf["side"]   =  1 ; 
0138     
0139 
0140     // shift position of origin of helper plane to pick up Air instead of vacuum 
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     // stop scanning the hierarchy any further
0159     stopScanning() ;
0160   }
0161   
0162 
0163 }// namespace