DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
GenericSurfaceInstaller.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // Surface installer plugin for generic sliced detector drivers
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 : N. Nikiforou, adapted from dd4hep/SiTrackerBarrel_surfaces.cpp
11 // by M. Frank. Originally part of the lcgeo package
12 //==========================================================================
13 
59 namespace {
60  struct UserData {
61  int dimension ;
62  double uvector[3];
63  double vvector[3];
64  double nvector[3];
65  double ovector[3];
66 
67  };
68 
69 }
70 
71 // Framework include files
72 #define SURFACEINSTALLER_DATA UserData
73 #define DD4HEP_USE_SURFACEINSTALL_HELPER DD4hep_GenericSurfaceInstallerPlugin
75 
76 namespace{
77  template <> void Installer<UserData>::handle_arguments(int argc, char** argv) {
78 
79  //Initialize defaults to zero
80  data.dimension=0;
81  data.uvector[0]=0.;
82  data.uvector[1]=0.;
83  data.uvector[2]=0.;
84  data.vvector[0]=0.;
85  data.vvector[1]=0.;
86  data.vvector[2]=0.;
87  data.nvector[0]=0.;
88  data.nvector[1]=0.;
89  data.nvector[2]=0.;
90  data.ovector[0]=0.;
91  data.ovector[1]=0.;
92  data.ovector[2]=0.;
93 
94  for(int i=0; i<argc; ++i) {
95  double value = -1;
96  char* ptr = ::strchr(argv[i],'=');
97  if ( ptr ) {
98  std::string name( argv[i] , ptr ) ;
99  value = dd4hep::_toDouble(++ptr);
100  std::cout << "DD4hep_GenericSurfaceInstallerPlugin: argument[" << i << "] = " << name
101  << " = " << value << std::endl;
102  if( name=="dimension" ) data.dimension = value ;
103  if( name=="u_x" ) data.uvector[0]=value ;
104  if( name=="u_y" ) data.uvector[1]=value ;
105  if( name=="u_z" ) data.uvector[2]=value ;
106  if( name=="v_x" ) data.vvector[0]=value ;
107  if( name=="v_y" ) data.vvector[1]=value ;
108  if( name=="v_z" ) data.vvector[2]=value ;
109  if( name=="n_x" ) data.nvector[0]=value ;
110  if( name=="n_y" ) data.nvector[1]=value ;
111  if( name=="n_z" ) data.nvector[2]=value ;
112  if( name=="o_x" ) data.ovector[0]=value ;
113  if( name=="o_y" ) data.ovector[1]=value ;
114  if( name=="o_z" ) data.ovector[2]=value ;
115  }
116  }
117 
118  std::cout <<"DD4hep_GenericSurfaceInstallerPlugin: vectors: ";
119  std::cout <<"u( "<<data.uvector[0]<<" , "<<data.uvector[1]<<" , "<<data.uvector[2]<<") ";
120  std::cout <<"v( "<<data.vvector[0]<<" , "<<data.vvector[1]<<" , "<<data.vvector[2]<<") ";
121  std::cout <<"n( "<<data.nvector[0]<<" , "<<data.nvector[1]<<" , "<<data.nvector[2]<<") ";
122  std::cout <<"o( "<<data.ovector[0]<<" , "<<data.ovector[1]<<" , "<<data.ovector[2]<<") "<<std::endl;
123 
124  }
125 
127  template <typename UserData>
128  void Installer<UserData>::install(dd4hep::DetElement component, dd4hep::PlacedVolume pv) {
129  dd4hep::Volume comp_vol = pv.volume();
130  if ( comp_vol.isSensitive() ) {
131  dd4hep::Volume mod_vol = parentVolume(component);
132  //FIXME: WHAT IF TRAPEZOID? Should work if trapezoid since it will fit minimal box and dy1=dy2=dy
133  dd4hep::Box mod_shape(mod_vol.solid()), comp_shape(comp_vol.solid());
134 
135  if ( !comp_shape.isValid() || !mod_shape.isValid() ) {
136  invalidInstaller("DD4hep_GenericSurfaceInstallerPlugin: Components and/or modules are not boxes -- invalid shapes");
137 
138  }else if ( !handleUsingCache(component,comp_vol) ) {
139  const double* trans = placementTranslation(component);
140  double half_module_thickness = 0.;
141  double sensitive_z_position = 0.;
142 
143  if (data.nvector[0] !=0 && data.nvector[1] ==0 && data.nvector[2] ==0){
144  half_module_thickness = mod_shape->GetDX();
145  sensitive_z_position = data.nvector[0]>0 ? trans[0] : -trans[0];
146  }else if (data.nvector[1] !=0 && data.nvector[0] ==0 && data.nvector[2] ==0){
147  half_module_thickness = mod_shape->GetDY();
148  sensitive_z_position = data.nvector[1]>0 ? trans[1] : -trans[1];
149 
150  }else if (data.nvector[2] !=0 && data.nvector[0] ==0 && data.nvector[1] ==0){
151  half_module_thickness = mod_shape->GetDZ();
152  sensitive_z_position = data.nvector[2]>0 ? trans[2] : -trans[2];
153 
154  } else {
155  throw std::runtime_error("**** dd4hep_GenericSurfaceInstallerPlugin: normal vector unsupported! It has to be "
156  "perpenidcular to one of the box sides, i.e. only one non-zero component.") ;
157  }
158 
159  double inner_thickness = half_module_thickness + sensitive_z_position;
160  double outer_thickness = half_module_thickness - sensitive_z_position;
161 
162  //Surface is placed at the center of the volume, no need to shift origin
163  //Make sure u,v,n form a right-handed coordinate system, v along the final z
164  Vector3D u(data.uvector[0],data.uvector[1],data.uvector[2]);
165  Vector3D v(data.vvector[0],data.vvector[1],data.vvector[2]);
166  Vector3D n(data.nvector[0],data.nvector[1],data.nvector[2]);
167  Vector3D o(data.ovector[0],data.ovector[1],data.ovector[2]);
168  Type type( Type::Sensitive ) ;
169 
170  if( data.dimension == 1 ) {
171  type.setProperty( Type::Measurement1D , true ) ;
172  } else if( data.dimension != 2 ) {
173  throw std::runtime_error("**** dd4hep_GenericSurfaceInstallerPlugin: no or wrong "
174  "'dimension' argument given - has to be 1 or 2") ;
175  }
176  VolPlane surf(comp_vol, type, inner_thickness, outer_thickness, u, v, n, o);
177  addSurface(component,surf);
178  }
179  }
180  }
181 }// namespace
SurfaceInstaller.h
v
View * v
Definition: MultiView.cpp:28
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::Volume::solid
Solid solid() const
Access to Solid (Shape)
Definition: Volumes.cpp:1223
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Volume::isSensitive
bool isSensitive() const
Accessor if volume is sensitive (ie. is attached to a sensitive detector)
Definition: Volumes.cpp:1293
dd4hep::rec::VolPlane
VolSurfaceHandle< VolPlaneImpl > VolPlane
Definition: Surface.h:474
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:378
dd4hep::_toDouble
double _toDouble(const std::string &value)
String conversions: string to double value.
Definition: Handle.cpp:116
dd4hep::Box
Class describing a box shape.
Definition: Shapes.h:294
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