Back to home page

EIC code displayed by LXR

 
 

    


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

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 length ;
0019     float radius ;
0020     float phi0 ;
0021     int   symmetry ;
0022     int   systemID ;
0023     std::string encoding ;
0024 
0025   }; 
0026 }
0027 
0028 // Framework include files
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   /// helper class for a planar surface placed into a polyhedral calorimeter barrel 
0040   class CaloBarrelPlaneImpl : public  dd4hep::rec::VolPlaneImpl   {
0041     double _length, _width ;
0042 
0043   public:
0044     /// standard c'tor with all necessary arguments - origin is (0,0,0) if not given.
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     // overwrite to include points inside the inner radius of the barrel 
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     /// create outer bounding lines for the given symmetry of the polyhedron
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   /// Install measurement surfaces
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     //    if( symmetry ) radius /= cos( M_PI / symmetry ) ; 
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     // dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
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     // stop scanning the hierarchy any further
0159     stopScanning() ;
0160   }
0161   
0162 
0163 }// namespace