DD4hep  1.38.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  // symmetry=0: cylindrical calorimeter, the surface is a disk of radius _r
64  if( _sym == 0 )
65  return ( std::abs ( distance( point ) ) < epsilon ) && point.rho() < _r ;
66 
67  // otherwise: polyhedron with n=_sym sides
68  double ri = _r * cos( 2.* M_PI / _sym ) ;
69 
70  return ( std::abs ( distance( point ) ) < epsilon ) &&
71  ( (point.rho() < ri ) ||
72  ( volume()->GetShape()->Contains( const_cast<double*> (point.const_array() ) ) ) ) ;
73  }
74 
76  virtual std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > getLines(unsigned nMax){
77 
78  std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > lines ;
79 
80  // symmetry=0: cylindrical calorimeter, approximate the outer circle with a polygon with at least 16 sides
81  const unsigned n = ( _sym ? _sym : ( nMax > 16 ? nMax : 16 ) ) ;
82 
83  double alpha = 2.* M_PI / n ;
84 
85  for(unsigned i=0 ; i < n ; ++i){
86  double gam0 = i * alpha + _phi0 ;
87  double gam1 = (i+1) * alpha + _phi0 ;
88  lines.push_back( std::make_pair( dd4hep::rec::Vector3D( _r*cos(gam0), _r*sin(gam0), origin().z() ),
89  dd4hep::rec::Vector3D( _r*cos(gam1), _r*sin(gam1), origin().z() ) ) ) ;
90  }
91  return lines;
92  }
93  };
94 
96 
97 
98  template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
99  for(int i=0; i<argc; ++i) {
100  char* ptr = ::strchr(argv[i],'=');
101  if ( ptr ) {
102  std::string name( argv[i] , ptr ) ;
103  double value = dd4hep::_toDouble(++ptr);
104 
105  printout(dd4hep::DEBUG,"DD4hep_CaloFaceEndcapSurfacePlugin", "argument[%d] = %s = %f" , i, name.c_str() , value ) ;
106 
107  if( name=="zpos" ) data.zpos = value ;
108  else if( name=="radius" ) data.radius = value ;
109  else if( name=="phi0" ) data.phi0 = value ;
110  else if( name=="symmetry") data.symmetry = value ;
111  else if( name=="systemID") data.systemID = value ;
112  else if( name=="encoding") data.encoding = ptr ;
113  else {
114  printout(dd4hep::WARNING,"DD4hep_CaloFaceEndcapSurfacePlugin", "unknown parameter: %s ", name.c_str() ) ;
115  }
116  }
117  }
118  }
119 
121  template <typename UserData>
122  void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
123 
124  dd4hep::Volume comp_vol = pv.volume();
125 
126 
127  double zpos = data.zpos ;
128  double symmetry = data.symmetry ;
129  double radius = data.radius ;
130  double phi0 = data.phi0 ;
131 
132  if( symmetry ) radius /= cos( M_PI / symmetry ) ;
133 
134 
135  double inner_thickness = 1e-6 ;
136  double outer_thickness = 1e-6 ;
137 
138  printout(dd4hep::INFO,"DD4hep_CaloFaceEndcapSurfacePlugin", "install tracking surfaces for : %s ", component.name() ) ;
139 
140 
141  dd4hep::DDSegmentation::BitField64 bf( "system:5,side:-2,layer:9,module:8,sensor:8" ) ;
142  //dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
143 
144  bf["system"] = data.systemID ;
145  bf["side"] = 1 ;
146 
147 
148  // shift position of origin of helper plane to pick up Air instead of vacuum
149  dd4hep::rec::Vector3D u(1.,0.,0.), v(0.,1.,0.), n(0.,0.,1.), o(0., 0.5*radius , zpos );
150 
151  CaloEndcapPlane surf_pz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, o);
152 
153  surf_pz->setData( radius, phi0, symmetry ) ;
154  surf_pz->setID( bf.getValue() ) ;
155 
156  addSurface(component,surf_pz);
157 
158  CaloEndcapPlane surf_nz(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, -1*o );
159 
160  bf["side"] = -1 ;
161  surf_nz->setData( radius, phi0, symmetry ) ;
162  surf_nz->setID( bf.getValue() ) ;
163 
164  addSurface(component,surf_nz);
165 
166  // stop scanning the hierarchy any further
167  stopScanning() ;
168  }
169 
170 
171 }// 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
dd4hep::rec::Vector3D::z
double z() const
Definition: Vector3D.h:109
v
View * v
Definition: MultiView.cpp:28
dd4hep::rec::Vector3D
Definition: Vector3D.h:32
M_PI
#define M_PI
Definition: Handle.h:31
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:164
dd4hep::DDSegmentation::BitField64
A bit field of 64bits that allows convenient declaration.
Definition: BitField64.h:107
dd4hep::rec::VolPlaneImpl
Definition: Surface.h:329
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::rec::VolSurfaceBase::origin
virtual const Vector3D & origin() const override
Definition: Surface.cpp:47
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:187
dd4hep::rec::VolSurfaceHandle
Definition: Surface.h:459
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:371
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:146
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:237
dd4hep::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:468
dd4hep::sim::Setup::Sensitive
Geant4Handle< Geant4Sensitive > Sensitive
Definition: Geant4Config.h:73
dd4hep::rec::VolPlaneImpl::distance
virtual double distance(const Vector3D &point) const override
Definition: Surface.cpp:271
Printout.h
dd4hep::rec::VolSurfaceBase::insideBounds
virtual bool insideBounds(const Vector3D &point, double epsilon=1e-4) const override
Checks if the given point lies within the surface.
Definition: Surface.cpp:207
CellID
dd4hep::DDSegmentation::CellID CellID
Definition: SegmentationDictionary.h:51