DD4hep  1.30.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 
85  template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
86  for(int i=0; i<argc; ++i) {
87  char* ptr = ::strchr(argv[i],'=');
88  if ( ptr ) {
89  std::string name( argv[i] , ptr ) ;
90  double value = dd4hep::_toDouble(++ptr);
91 
92  printout(dd4hep::DEBUG,"DD4hep_CaloFaceBarrelSurfacePlugin", "argument[%d] = %s = %f" , i, name.c_str() , value ) ;
93 
94  if( name=="length" ) data.length = value ;
95  else if( name=="radius" ) data.radius = value ;
96  else if( name=="phi0" ) data.phi0 = value ;
97  else if( name=="symmetry") data.symmetry = value ;
98  else if( name=="systemID") data.systemID = value ;
99  else if( name=="encoding") data.encoding = ptr ;
100  else {
101  printout(dd4hep::WARNING,"DD4hep_CaloFaceBarrelSurfacePlugin", "unknown parameter: %s ", name.c_str() ) ;
102  }
103  }
104  }
105  }
106 
108  template <typename UserData>
109  void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
110 
111  dd4hep::Volume comp_vol = pv.volume();
112 
113  double length = data.length ;
114  double symmetry = data.symmetry ;
115  double radius = data.radius ;
116  double phi0 = data.phi0 ;
117 
118  // if( symmetry ) radius /= cos( M_PI / symmetry ) ;
119 
120 
121  double width = 2. * radius * tan( M_PI / symmetry ) ;
122 
123  double inner_thickness = 1e-6 ;
124  double outer_thickness = 1e-6 ;
125 
126  printout(dd4hep::INFO,"DD4hep_CaloFaceBarrelSurfacePlugin", "install tracking surfaces for : %s ", component.name() ) ;
127 
128 
129  dd4hep::DDSegmentation::BitField64 bf( "system:5,side:-2,layer:9,module:8,sensor:8" ) ;
130  // dd4hep::DDSegmentation::BitField64 bf( data.encoding ) ;
131 
132  bf["system"] = data.systemID ;
133 
134 
135  double alpha = ( symmetry ? 2.* M_PI / symmetry : 0. ) ;
136 
137  for(unsigned i=0 ; i < symmetry ; ++i){
138 
139  bf["module"] = i ;
140 
141  double gam = phi0 + alpha/2. + i*alpha;
142 
144  u( cos(gam+M_PI/2.), sin(gam+M_PI/2.), 0. ),
145  v( 0. , 0. , 1. ),
146  n( cos(gam) , sin(gam) , 0. ),
147  o( radius*cos(gam) , radius*sin(gam) , 0. );
148 
149  CaloBarrelPlane surf(comp_vol,Type(Type::Helper,Type::Sensitive), inner_thickness, outer_thickness, u, v, n, o);
150 
151  surf->setData( length, width ) ;
152  surf->setID( bf.getValue() ) ;
153 
154  addSurface(component,surf);
155 
156  }
157 
158  // stop scanning the hierarchy any further
159  stopScanning() ;
160  }
161 
162 
163 }// namespace
SurfaceInstaller.h
DetectorData.h
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)
dd4hep::rec::VolSurfaceBase::u
virtual Vector3D u(const Vector3D &point=Vector3D()) const
Definition: Surface.cpp:45
epsilon
const double epsilon
Definition: test_cellid_position_converter.cpp:41
Surface.h
dd4hep::rec::VolSurfaceBase::v
virtual Vector3D v(const Vector3D &point=Vector3D()) const
Definition: Surface.cpp:46
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::globalToLocal
virtual Vector2D globalToLocal(const Vector3D &point) const
Definition: Surface.cpp:50
dd4hep::rec::Vector2D
Definition: Vector2D.h:24
dd4hep::rec::VolSurfaceBase::origin
virtual const Vector3D & origin() const
Definition: Surface.cpp:48
dd4hep::rec::SurfaceType
Definition: ISurface.h:140
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