DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
CaloFaceEndcap_surfaces.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : F.Gaede DESY
11 //
12 //==========================================================================
13 
14 #include <string>
15 
16 namespace {
17  struct UserData {
18  float zpos ;
19  float radius ;
20  float phi0 ;
21  int symmetry ;
22  int systemID ;
23  std::string encoding ;
24  };
25 }
26 
27 // Framework include files
28 #define SURFACEINSTALLER_DATA UserData
29 #define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_CaloFaceEndcapSurfacePlugin
32 #include "DDRec/DetectorData.h"
33 #include "DDRec/Surface.h"
35 
36 namespace{
37 
39  class CaloEndcapPlaneImpl : public dd4hep::rec::VolPlaneImpl{
40  double _r ;
41  double _phi0 ;
42  unsigned _sym ;
43  public:
45  CaloEndcapPlaneImpl( dd4hep::rec::SurfaceType typ,
46  double thickness_inner ,double thickness_outer,
49  dd4hep::Volume vol, int id_val ) :
50  dd4hep::rec::VolPlaneImpl( typ, thickness_inner,thickness_outer, u_val, v_val, n_val, o_val, vol, id_val),
51  _r(0),_phi0(0),_sym(0) {}
52 
53  void setData( double radius, double phi0, unsigned symmetry){
54  _r = radius ;
55  _phi0 = phi0 ;
56  _sym = symmetry ;
57  }
58  void setID( dd4hep::CellID id_val ) { _id = id_val; }
59 
60  // overwrite to include points inside the inner radius of the endcap
61  bool insideBounds(const dd4hep::rec::Vector3D& point, double epsilon) const {
62 
63  double ri = _r * cos( 2.* M_PI / _sym ) ;
64 
65  return ( std::abs ( distance( point ) ) < epsilon ) &&
66  ( (point.rho() < ri ) ||
67  ( volume()->GetShape()->Contains( const_cast<double*> (point.const_array() ) ) ) ) ;
68  }
69 
71  virtual std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > getLines(unsigned){
72 
73  std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > lines ;
74 
75  double alpha = ( _sym ? 2.* M_PI / _sym : 0. ) ;
76 
77  for(unsigned i=0 ; i < _sym ; ++i){
78  double gam0 = i * alpha + _phi0 ;
79  double gam1 = (i+1) * alpha + _phi0 ;
80  lines.push_back( std::make_pair( dd4hep::rec::Vector3D( _r*cos(gam0), _r*sin(gam0), origin().z() ),
81  dd4hep::rec::Vector3D( _r*cos(gam1), _r*sin(gam1), origin().z() ) ) ) ;
82  }
83  return lines;
84  }
85  };
86 
88 
89 
90  template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
91  for(int i=0; i<argc; ++i) {
92  char* ptr = ::strchr(argv[i],'=');
93  if ( ptr ) {
94  std::string name( argv[i] , ptr ) ;
95  double value = dd4hep::_toDouble(++ptr);
96 
97  printout(dd4hep::DEBUG,"DD4hep_CaloFaceEndcapSurfacePlugin", "argument[%d] = %s = %f" , i, name.c_str() , value ) ;
98 
99  if( name=="zpos" ) data.zpos = value ;
100  else if( name=="radius" ) data.radius = value ;
101  else if( name=="phi0" ) data.phi0 = value ;
102  else if( name=="symmetry") data.symmetry = value ;
103  else if( name=="systemID") data.systemID = value ;
104  else if( name=="encoding") data.encoding = ptr ;
105  else {
106  printout(dd4hep::WARNING,"DD4hep_CaloFaceEndcapSurfacePlugin", "unknown parameter: %s ", name.c_str() ) ;
107  }
108  }
109  }
110  }
111 
113  template <typename UserData>
114  void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
115 
116  dd4hep::Volume comp_vol = pv.volume();
117 
118 
119  double zpos = data.zpos ;
120  double symmetry = data.symmetry ;
121  double radius = data.radius ;
122  double phi0 = data.phi0 ;
123 
124  if( symmetry ) radius /= cos( M_PI / symmetry ) ;
125 
126 
127  double inner_thickness = 1e-6 ;
128  double outer_thickness = 1e-6 ;
129 
130  printout(dd4hep::INFO,"DD4hep_CaloFaceEndcapSurfacePlugin", "install tracking surfaces for : %s ", component.name() ) ;
131 
132 
133  dd4hep::DDSegmentation::BitField64 bf( "system:5,side:-2,layer:9,module:8,sensor:8" ) ;
134  //dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
135 
136  bf["system"] = data.systemID ;
137  bf["side"] = 1 ;
138 
139 
140  // shift position of origin of helper plane to pick up Air instead of vacuum
141  dd4hep::rec::Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(0., 0.5*radius , zpos );
142 
143  CaloEndcapPlane surf_pz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, o);
144 
145  surf_pz->setData( radius, phi0, symmetry ) ;
146  surf_pz->setID( bf.getValue() ) ;
147 
148  addSurface(component,surf_pz);
149 
150  CaloEndcapPlane surf_nz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, -1*o );
151 
152  bf["side"] = -1 ;
153  surf_nz->setData( radius, phi0, symmetry ) ;
154  surf_nz->setID( bf.getValue() ) ;
155 
156  addSurface(component,surf_nz);
157 
158  // stop scanning the hierarchy any further
159  stopScanning() ;
160  }
161 
162 
163 }// namespace
SurfaceInstaller.h
DetectorData.h
dd4hep::rec::VolSurfaceBase::volume
Volume volume() const
the volume to which this surface is attached.
Definition: Surface.h:103
dd4hep::rec::Vector3D::rho
double rho() const
Definition: Vector3D.h:148
v
View * v
Definition: MultiView.cpp:28
dd4hep::rec::Vector3D
Definition: Vector3D.h:32
M_PI
#define M_PI
Definition: Handle.h:33
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::DDSegmentation::BitField64
A bit field of 64bits that allows convenient declaration.
Definition: BitField64.h:110
dd4hep::rec::VolPlaneImpl
Definition: Surface.h:331
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
epsilon
const double epsilon
Definition: test_cellid_position_converter.cpp:41
Surface.h
BitField64.h
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::rec::VolSurfaceHandle
Definition: Surface.h:461
dd4hep::rec::VolSurfaceBase::insideBounds
virtual bool insideBounds(const Vector3D &point, double epsilon=1e-4) const
Checks if the given point lies within the surface.
Definition: Surface.cpp:208
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:378
dd4hep::rec::VolSurfaceBase::origin
virtual const Vector3D & origin() const
Definition: Surface.cpp:48
dd4hep::rec::SurfaceType
Definition: ISurface.h:140
dd4hep::rec::Vector3D::const_array
const double * const_array() const
direct access to data as const double*
Definition: Vector3D.h:211
dd4hep::DDSegmentation::BitField64::getValue
CellID getValue() const
Definition: BitField64.h:149
dd4hep::_toDouble
double _toDouble(const std::string &value)
String conversions: string to double value.
Definition: Handle.cpp:116
dd4hep::rec::VolSurfaceBase::getLines
virtual std::vector< std::pair< Vector3D, Vector3D > > getLines(unsigned nMax=100)
Definition: Surface.cpp:238
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:452
dd4hep::sim::Setup::Sensitive
Geant4Handle< Geant4Sensitive > Sensitive
Definition: Geant4Config.h:73
Printout.h
dd4hep::rec::VolPlaneImpl::distance
virtual double distance(const Vector3D &point) const
Definition: Surface.cpp:272
CellID
dd4hep::DDSegmentation::CellID CellID
Definition: SegmentationDictionary.h:50