1 #include "DD4hep/DetFactoryHelper.h"
3 #include "DDRec/Surface.h"
4 #include "DDRec/DetectorData.h"
8 using namespace dd4hep::rec ;
30 std::string name = x_det.nameStr();
32 Assembly assembly( name+
"_assembly" );
35 DetElement tracker( name, x_det.id() ) ;
40 for(xml_coll_t c(e, _U(layer) ); c; ++c) {
42 xml_comp_t alayer( c );
47 xml_comp_t z_sensitive( alayer.child( _U(sensitive) ));
48 xml_comp_t z_module( alayer.child( _U(module) ));
50 int layer_id = alayer.id();
51 double zoffset = alayer.attr<
double>( _Unicode(z_offset) ) ;
53 double supp_x_half = z_module.attr<
double>( _Unicode(x_half) );
54 double supp_y_half = z_module.attr<
double>( _Unicode(y_half));
55 double supp_thickness = z_module.attr<
double>( _Unicode(thickness));
56 double sens_thickness = z_sensitive.attr<
double>( _Unicode(thickness));
58 double supp_gap_half_width = 1.5;
60 std::string supp_matS = z_module.materialStr() ;
61 std::string sens_matS = z_sensitive.materialStr() ;
63 Material supp_mat = lcdd.material( supp_matS ) ;
64 Material sens_mat = lcdd.material( sens_matS ) ;
66 std::cout << supp_matS << std::endl;
67 std::cout << sens_matS << std::endl;
69 std::string layername = name + _toString(layer_id,
"_layer%d");
71 DetElement layerDE( tracker , _toString(layer_id,
"layer_%d"), x_det.id() );
75 Box supp_box( supp_x_half, supp_y_half, supp_thickness/2.0 );
77 Box sens_box( supp_x_half/2.0-supp_gap_half_width, supp_y_half/2.0-supp_gap_half_width, sens_thickness/2.0 );
79 Volume support_vol( layername+
"_supp", supp_box, supp_mat );
80 Volume sensor_vol( layername+
"_sens", sens_box, sens_mat );
82 std::string supp_vis = z_module.visStr() ;
83 std::string sens_vis = z_sensitive.visStr() ;
86 Vector3D u( 1. , 0. , 0. ) ;
87 Vector3D v( 0. , 1. , 0. ) ;
88 Vector3D n( 0. , 0. , 1. ) ;
95 double inner_thickness = supp_thickness/2.0;
96 double outer_thickness = supp_thickness/2.0;
98 SurfaceType type( SurfaceType::Sensitive ) ;
99 VolPlane surf( sensor_vol, type, inner_thickness , outer_thickness , u,v,n ) ;
103 sens.setType(
"tracker");
104 sensor_vol.setSensitiveDetector(sens);
106 sensor_vol.setAttributes( lcdd, x_det.regionStr(), x_det.limitsStr(), sens_vis );
107 support_vol.setAttributes( lcdd, x_det.regionStr(), x_det.limitsStr(), supp_vis );
116 PlacedVolume support_pv = assembly.placeVolume( support_vol, Position(0,0, zoffset) );
117 support_pv.addPhysVolID(
"layer", layer_id );
118 layerDE.setPlacement( support_pv ) ;
120 for(
int i_module=0; i_module<4; i_module++) {
122 DetElement sensDE( layerDE , _toString(i_module,
"module_%d"), i_module );
123 double xsign = (i_module%2==0 ? -1.0 : 1.0);
124 double ysign = (i_module/2==0 ? -1.0 : 1.0);
125 Position module_postion(xsign*supp_x_half/2.0, ysign*supp_y_half/2.0, 0.0);
128 PlacedVolume pv = support_vol.placeVolume(sensor_vol, module_postion);
129 pv.addPhysVolID(
"module", i_module );
130 sensDE.setPlacement( pv );
131 for(
const auto&
id : pv.volIDs()){
132 std::cout <<
" id : " <<
id.second << std::endl;
139 Volume mother = lcdd.pickMotherVolume( tracker ) ;
140 PlacedVolume mother_pv = mother.placeVolume(assembly);
141 mother_pv.addPhysVolID(
"system", x_det.id() );
142 tracker.setPlacement(mother_pv);
144 assembly->GetShape()->ComputeBBox() ;