DD4hep  1.38.0
Detector Description Toolkit for High Energy Physics
CaloFaceBarrel_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 length ;
19  float radius ;
20  float phi0 ;
21  int symmetry ;
22  int systemID ;
23  std::string encoding ;
24 
25  };
26 }
27 
28 // Framework include files
29 #define SURFACEINSTALLER_DATA UserData
30 #define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_CaloFaceBarrelSurfacePlugin
33 #include "DDRec/DetectorData.h"
34 #include "DDRec/Surface.h"
36 
37 namespace{
38 
40  class CaloBarrelPlaneImpl : public dd4hep::rec::VolPlaneImpl {
41  double _length, _width ;
42 
43  public:
45  CaloBarrelPlaneImpl( 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  _length(0),_width(0) {}
52 
53  void setData( double length, double width){
54  _length = length ;
55  _width = width ;
56  }
57 
58  void setID( dd4hep::CellID id_val ) { _id = id_val ; }
59 
60  // overwrite to include points inside the inner radius of the barrel
61  bool insideBounds(const dd4hep::rec::Vector3D& point, double epsilon) const {
62  dd4hep::rec::Vector2D uvVec = globalToLocal( point ) ;
63 
64  return ( std::abs ( distance( point ) ) < epsilon ) &&
65  std::abs( uvVec[0] ) < _width/2. && std::abs( uvVec[1] ) < _length/2. ;
66  }
67 
69  virtual std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > getLines(unsigned){
70 
71  std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > lines ;
72 
73  lines.push_back( std::make_pair( origin()+_width/2.*u()+_length/2.*v(), origin()-_width/2.*u()+_length/2.*v() ) ) ;
74  lines.push_back( std::make_pair( origin()-_width/2.*u()+_length/2.*v(), origin()-_width/2.*u()-_length/2.*v() ) ) ;
75  lines.push_back( std::make_pair( origin()-_width/2.*u()-_length/2.*v(), origin()+_width/2.*u()-_length/2.*v() ) ) ;
76  lines.push_back( std::make_pair( origin()+_width/2.*u()-_length/2.*v(), origin()+_width/2.*u()+_length/2.*v() ) ) ;
77 
78  return lines;
79  }
80  };
81 
83 
84 
86  class CaloBarrelCylinderImpl : public dd4hep::rec::VolCylinderImpl {
87  double _length ;
88 
89  public:
91  CaloBarrelCylinderImpl( dd4hep::Volume vol, dd4hep::rec::SurfaceType typ,
92  double thickness_inner ,double thickness_outer,
93  dd4hep::rec::Vector3D o_val ) :
94  dd4hep::rec::VolCylinderImpl( vol, typ, thickness_inner, thickness_outer, o_val ),
95  _length(0) {}
96 
97  void setData( double length){
98  _length = length ;
99  }
100 
101  void setID( dd4hep::CellID id_val ) { _id = id_val ; }
102 
103  // overwrite to bound the cylinder in z by the given length instead of the volume shape
104  bool insideBounds(const dd4hep::rec::Vector3D& point, double epsilon) const {
105  return ( std::abs ( distance( point ) ) < epsilon ) &&
106  std::abs( point.z() - origin().z() ) < _length/2. ;
107  }
108 
109  virtual double length_along_u() const { return 2. * M_PI * origin().rho() ; }
110  virtual double length_along_v() const { return _length ; }
111 
113  virtual std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > getLines(unsigned nMax){
114 
115  std::vector< std::pair<dd4hep::rec::Vector3D, dd4hep::rec::Vector3D> > lines ;
116 
117  const unsigned n = ( nMax > 32 ? nMax/2 : 16 ) ;
118  const double r = origin().rho() ;
119  const double z0 = origin().z() ;
120 
121  for(unsigned i=0 ; i < n ; ++i){
122  double gam0 = 2.* M_PI * i / n ;
123  double gam1 = 2.* M_PI * (i+1) / n ;
124  for( double z : { z0 - _length/2. , z0 + _length/2. } ){
125  lines.push_back( std::make_pair( dd4hep::rec::Vector3D( r*cos(gam0), r*sin(gam0), z ),
126  dd4hep::rec::Vector3D( r*cos(gam1), r*sin(gam1), z ) ) ) ;
127  }
128  if( i % (n/4) == 0 ){
129  lines.push_back( std::make_pair( dd4hep::rec::Vector3D( r*cos(gam0), r*sin(gam0), z0 - _length/2. ),
130  dd4hep::rec::Vector3D( r*cos(gam0), r*sin(gam0), z0 + _length/2. ) ) ) ;
131  }
132  }
133  return lines;
134  }
135  };
136 
138  class CaloBarrelCylinder : public dd4hep::rec::VolSurface {
139  public:
140  CaloBarrelCylinder( dd4hep::Volume vol, dd4hep::rec::SurfaceType typ,
141  double thickness_inner ,double thickness_outer, dd4hep::rec::Vector3D o_val ) :
142  dd4hep::rec::VolSurface( new CaloBarrelCylinderImpl( vol, typ, thickness_inner, thickness_outer, o_val ) ) {}
143 
144  CaloBarrelCylinderImpl* operator->() { return static_cast<CaloBarrelCylinderImpl*>( _surf ) ; }
145  };
146 
147 
148  template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
149  for(int i=0; i<argc; ++i) {
150  char* ptr = ::strchr(argv[i],'=');
151  if ( ptr ) {
152  std::string name( argv[i] , ptr ) ;
153  double value = dd4hep::_toDouble(++ptr);
154 
155  printout(dd4hep::DEBUG,"DD4hep_CaloFaceBarrelSurfacePlugin", "argument[%d] = %s = %f" , i, name.c_str() , value ) ;
156 
157  if( name=="length" ) data.length = value ;
158  else if( name=="radius" ) data.radius = value ;
159  else if( name=="phi0" ) data.phi0 = value ;
160  else if( name=="symmetry") data.symmetry = value ;
161  else if( name=="systemID") data.systemID = value ;
162  else if( name=="encoding") data.encoding = ptr ;
163  else {
164  printout(dd4hep::WARNING,"DD4hep_CaloFaceBarrelSurfacePlugin", "unknown parameter: %s ", name.c_str() ) ;
165  }
166  }
167  }
168  }
169 
171  template <typename UserData>
172  void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
173 
174  dd4hep::Volume comp_vol = pv.volume();
175 
176  double length = data.length ;
177  double symmetry = data.symmetry ;
178  double radius = data.radius ;
179  double phi0 = data.phi0 ;
180 
181  // if( symmetry ) radius /= cos( M_PI / symmetry ) ;
182 
183 
184  double inner_thickness = 1e-6 ;
185  double outer_thickness = 1e-6 ;
186 
187  printout(dd4hep::INFO,"DD4hep_CaloFaceBarrelSurfacePlugin", "install tracking surfaces for : %s ", component.name() ) ;
188 
189 
190  dd4hep::DDSegmentation::BitField64 bf( "system:5,side:-2,layer:9,module:8,sensor:8" ) ;
191  // dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
192 
193  bf["system"] = data.systemID ;
194 
195 
196  // symmetry=0: cylindrical calorimeter, install a single cylindrical surface
197  if( symmetry == 0 ){
198 
199  bf["module"] = 0 ;
200 
201  dd4hep::rec::Vector3D o( radius , 0. , 0. );
202 
203  CaloBarrelCylinder surf(comp_vol,Type(Type::Cylinder,Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, o);
204 
205  surf->setData( length ) ;
206  surf->setID( bf.getValue() ) ;
207 
208  addSurface(component,surf);
209 
210  stopScanning() ;
211  return ;
212  }
213 
214  double width = 2. * radius * tan( M_PI / symmetry ) ;
215 
216  double alpha = ( symmetry ? 2.* M_PI / symmetry : 0. ) ;
217 
218  for(unsigned i=0 ; i < symmetry ; ++i){
219 
220  bf["module"] = i ;
221 
222  double gam = phi0 + alpha/2. + i*alpha;
223 
225  u( cos(gam+M_PI/2.), sin(gam+M_PI/2.), 0. ),
226  v( 0. , 0. , 1. ),
227  n( cos(gam) , sin(gam) , 0. ),
228  o( radius*cos(gam) , radius*sin(gam) , 0. );
229 
230  CaloBarrelPlane surf(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, o);
231 
232  surf->setData( length, width ) ;
233  surf->setID( bf.getValue() ) ;
234 
235  addSurface(component,surf);
236 
237  }
238 
239  // stop scanning the hierarchy any further
240  stopScanning() ;
241  }
242 
243 
244 }// namespace
SurfaceInstaller.h
DetectorData.h
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::rec::VolSurfaceBase::u
virtual Vector3D u(const Vector3D &point=Vector3D()) const override
Definition: Surface.cpp:44
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:164
dd4hep::rec::VolSurface::_surf
VolSurfaceBase * _surf
Definition: Surface.h:185
dd4hep::rec::VolCylinderImpl
Definition: Surface.h:359
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
dd4hep::rec::VolSurfaceBase::globalToLocal
virtual Vector2D globalToLocal(const Vector3D &point) const override
Definition: Surface.cpp:49
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::VolSurface
Definition: Surface.h:181
dd4hep::rec::VolSurfaceBase::length_along_v
virtual double length_along_v() const override
Definition: Surface.cpp:141
dd4hep::rec::Vector2D
Definition: Vector2D.h:24
dd4hep::rec::SurfaceType
Definition: ISurface.h:140
dd4hep::DDSegmentation::BitField64::getValue
CellID getValue() const
Definition: BitField64.h:146
dd4hep::rec::VolSurfaceBase::v
virtual Vector3D v(const Vector3D &point=Vector3D()) const override
Definition: Surface.cpp:45
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::rec::VolSurfaceBase::length_along_u
virtual double length_along_u() const override
Definition: Surface.cpp:78
dd4hep::sim::Setup::Sensitive
Geant4Handle< Geant4Sensitive > Sensitive
Definition: Geant4Config.h:73
dd4hep::rec::VolCylinderImpl::distance
virtual double distance(const Vector3D &point) const override
Definition: Surface.cpp:334
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