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     : M.Frank
0011 //  Modified   : E.Pilicer ( tube + elliptical pipe layout )
0012 //             : P.Kostka   ( more refined version circ-ell )
0013 //
0014 //====================================================================
0015 #include "DD4hep/DetFactoryHelper.h"
0016 #include "DD4hep/DD4hepUnits.h"
0017 #include "DD4hep/DetType.h"
0018 #include "DD4hep/Printout.h"
0019 
0020 #include "DDRec/DetectorData.h"
0021 #include "DDRec/Surface.h"
0022 
0023 #include "XML/Utilities.h"
0024 
0025 #include <cmath>
0026 #include <map>
0027 #include <string>
0028 
0029 //using dd4hep::rec::Vector3D;
0030 //using dd4hep::rec::VolCylinder;
0031 //using dd4hep::rec::VolCone;
0032 //using dd4hep::rec::SurfaceType;
0033 
0034 namespace units = dd4hep;
0035 using namespace std;
0036 using namespace dd4hep;
0037 using namespace dd4hep::detail;
0038 
0039 /// helper class for a simple cylinder surface parallel to z with a given length - used as IP layer
0040 class SimpleCylinderImpl : public  dd4hep::rec::VolCylinderImpl{
0041   double _half_length ;
0042 public:
0043   /// standard c'tor with all necessary arguments - origin is (0,0,0) if not given.
0044   SimpleCylinderImpl( Volume vol, rec::SurfaceType type,
0045                       double thickness_inner ,double thickness_outer,  rec::Vector3D origin ) :
0046     rec::VolCylinderImpl( vol,  type, thickness_inner, thickness_outer,   origin ),
0047     _half_length(0){
0048   }
0049   void setHalfLength( double half_length){
0050     _half_length = half_length ;
0051   }
0052   void setID( dd4hep::CellID id ) { _id = id ;
0053   }
0054   // overwrite to include points inside the inner radius of the barrel
0055   bool insideBounds(const rec::Vector3D& point, double epsilon) const {
0056     return ( std::abs( point.rho() - origin().rho() ) < epsilon && std::abs( point.z() ) < _half_length ) ;
0057   }
0058 
0059   virtual std::vector< std::pair<rec::Vector3D, rec::Vector3D> > getLines(unsigned nMax=100){
0060 
0061     std::vector< std::pair<rec::Vector3D, rec::Vector3D> >  lines ;
0062 
0063     lines.reserve( nMax ) ;
0064 
0065     rec::Vector3D zv( 0. , 0. , _half_length ) ;
0066     double r = _o.rho() ;
0067 
0068     unsigned n = nMax / 4 ;
0069     double dPhi = 2.* ROOT::Math::Pi() / double( n ) ;
0070 
0071     for( unsigned i = 0 ; i < n ; ++i ) {
0072 
0073       rec::Vector3D rv0(  r*sin(  i   *dPhi ) , r*cos(  i   *dPhi )  , 0. ) ;
0074       rec::Vector3D rv1(  r*sin( (i+1)*dPhi ) , r*cos( (i+1)*dPhi )  , 0. ) ;
0075 
0076       rec::Vector3D pl0 =  zv + rv0 ;
0077       rec::Vector3D pl1 =  zv + rv1 ;
0078       rec::Vector3D pl2 = -zv + rv1  ;
0079       rec::Vector3D pl3 = -zv + rv0 ;
0080 
0081       lines.push_back( std::make_pair( pl0, pl1 ) ) ;
0082       lines.push_back( std::make_pair( pl1, pl2 ) ) ;
0083       lines.push_back( std::make_pair( pl2, pl3 ) ) ;
0084       lines.push_back( std::make_pair( pl3, pl0 ) ) ;
0085     }
0086     return lines;
0087   }
0088 };
0089 
0090 class SimpleCylinder : public rec::VolSurface{
0091 public:
0092   SimpleCylinder( Volume vol, rec::SurfaceType type, double thickness_inner ,
0093                   double thickness_outer,  rec::Vector3D origin ) :
0094     rec::VolSurface( new SimpleCylinderImpl(vol,  type,  thickness_inner , thickness_outer, origin ) ) {
0095   }
0096   SimpleCylinderImpl* operator->() { return static_cast<SimpleCylinderImpl*>( _surf ) ; }
0097 } ;
0098 
0099 
0100 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens)  {
0101   printout(dd4hep::DEBUG,"Lhe_Beampipe", "Creating Beampipe" ) ;
0102   
0103   //  typedef vector<PlacedVolume> Placements;
0104   xml_det_t  x_det = e;
0105   string     name  = x_det.nameStr();
0106   DetElement sdet (name,x_det.id());
0107   Material   mat  (description.material(x_det.materialStr()));
0108   //  vector<double> rmin,rmax,z,thickness;
0109   double rmin, rmax, thickness, z=0.0;
0110   //  PlacedVolume pv;
0111 
0112   // multiplication factor for ellipse major radius
0113   // rmin        ellipse short radius
0114   // rmax        ellipse long radius
0115   // thickness   BP thickness
0116   // z           z-length
0117   rmax = 1.;
0118   thickness = 1.;
0119   rmin = 1.;
0120 
0121   for(xml_coll_t c(e,_U(zplane)); c; ++c )   {
0122     xml_comp_t dim(c);
0123     rmin = dim.rmin();
0124     rmax = dim.rmax();
0125     thickness = dim.thickness();
0126     z = dim.z();
0127     //    rmin.push_back(dim.rmin());
0128     //    rmax.push_back(dim.rmax());
0129     //    z.push_back(dim.z());
0130     //    thickness.push_back(dim.thickness());
0131   }
0132 
0133   double ra    = rmax;         // ellipse long radius init
0134   double rb    = rmin;         // ellipse short radius init
0135   double thick = thickness;    // BP thickness
0136  
0137   EllipticalTube bpElTubeOut(ra+thick, rb+thick, z);
0138   EllipticalTube bpElTubeInn(ra, rb, z+thick);
0139   SubtractionSolid bpElTube(bpElTubeOut,bpElTubeInn);
0140 
0141   Tube bpTube1(rb, rb+thick, z+thick, 3*M_PI/2, M_PI/2);
0142   UnionSolid beamTube1(bpElTube,bpTube1);
0143 
0144   Tube bpTube2(rb+thick, ra+thick, z+thick, 3*M_PI/2, M_PI/2);
0145   SubtractionSolid beamTube(beamTube1,bpTube2);
0146   
0147   Volume  det_vol(name, beamTube, mat);
0148   PlacedVolume pv_det = description.pickMotherVolume(sdet).placeVolume(det_vol,Position(0,0,0));
0149   
0150   double z_offset = x_det.hasAttr(_U(z_offset)) ? x_det.z_offset() : 0.0;
0151   bool    reflect = x_det.hasAttr(_U(reflect)) ? x_det.reflect() : false;
0152 
0153   if ( z_offset >= 0 ) {
0154     if ( reflect) {
0155       PlacedVolume pv = description.pickMotherVolume(sdet).placeVolume(det_vol,Position(0,0,0));
0156       sdet.setPlacement(pv);
0157       det_vol.setVisAttributes(description, x_det.visStr());
0158       det_vol.setLimitSet(description, x_det.limitsStr());
0159       det_vol.setRegion(description, x_det.regionStr());
0160       if ( x_det.isSensitive() )   {
0161         SensitiveDetector sd = sens;
0162         xml_dim_t sd_typ = x_det.child(_U(sensitive));
0163         det_vol.setSensitiveDetector(sens);
0164         sd.setType(sd_typ.typeStr());
0165       }
0166     } else {
0167       PlacedVolume pv = description.pickMotherVolume(sdet).placeVolume(det_vol,Position(0,0,z_offset));
0168       sdet.setPlacement(pv);
0169       det_vol.setVisAttributes(description, x_det.visStr());
0170       det_vol.setLimitSet(description, x_det.limitsStr());
0171       det_vol.setRegion(description, x_det.regionStr());
0172       if ( x_det.isSensitive() )   {
0173         SensitiveDetector sd = sens;
0174         xml_dim_t sd_typ = x_det.child(_U(sensitive));
0175         det_vol.setSensitiveDetector(sens);
0176         sd.setType(sd_typ.typeStr());
0177       }
0178     }
0179   } else {
0180     PlacedVolume pv = description.pickMotherVolume(sdet).placeVolume(det_vol,Position(0,0,z_offset-z));
0181     sdet.setPlacement(pv);
0182     det_vol.setVisAttributes(description, x_det.visStr());
0183     det_vol.setLimitSet(description, x_det.limitsStr());
0184     det_vol.setRegion(description, x_det.regionStr());
0185     if ( x_det.isSensitive() )   {
0186       SensitiveDetector sd = sens;
0187       xml_dim_t sd_typ = x_det.child(_U(sensitive));
0188       det_vol.setSensitiveDetector(sens);
0189       sd.setType(sd_typ.typeStr());
0190     }
0191   }
0192  
0193   if ( x_det.hasAttr(_U(id)) )  {
0194     int det_id = x_det.id();
0195     pv_det.addPhysVolID("system",det_id);
0196   }
0197   return sdet;
0198 }
0199 
0200 DECLARE_DETELEMENT(Lhe_BeamPipe_Central,create_detector)
0201