11 #include "DD4hep/DetFactoryHelper.h"
14 using namespace dd4hep;
21 static Ref_t
create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
22 xml_det_t x_det = xml;
23 string det_name = x_det.nameStr();
25 DetElement cylinderVolume(det_name, x_det.id());
28 detvolume->addType(
"barrel",
"detector");
31 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
32 Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
33 Volume tube_vol(det_name, tube_shape,
35 tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
38 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
39 xml_comp_t x_layer = j;
40 double l_rmin = x_layer.inner_r();
41 double l_rmax = x_layer.outer_r();
42 double l_length = x_layer.z();
44 string layer_name = det_name + _toString((
int)layer_num,
"layer%d");
45 Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
46 lcdd.material(x_layer.materialStr()));
47 DetElement lay_det(cylinderVolume, layer_name, layer_num);
49 layer_vol.setVisAttributes(lcdd, x_layer.visStr());
51 if (x_layer.hasChild(_U(module))) {
52 xml_comp_t x_module = x_layer.child(_U(module));
53 int repeat = x_module.repeat();
54 double deltaphi = 2. *
M_PI / repeat;
56 xml_comp_t x_slice = x_layer.child(_U(slice));
57 int zrepeat = x_slice.repeat();
58 double dz = x_slice.z();
59 double dr = x_slice.dr();
60 double offsetrz = x_slice.dz();
61 size_t module_num = 0;
65 Box(x_module.length(), x_module.width(), x_module.thickness()),
66 lcdd.material(x_module.materialStr()));
68 for (
int k = -zrepeat;
k <= zrepeat;
k++) {
69 double r = (l_rmax + l_rmin) * 0.5;
70 string zname = _toString((
int)
k,
"z%d");
74 for (
int i = 0; i < repeat; ++i) {
79 mod_vol.setVisAttributes(lcdd, x_module.visStr());
81 string module_name = zname + _toString((
int)i,
"module%d");
82 Position trans(radius *
cos(phi), radius * sin(phi), k * dz);
84 DetElement mod_det(lay_det, module_name, module_num);
89 if (x_module.isSensitive()) {
90 mod_vol.setSensitiveDetector(sens);
93 PlacedVolume placedmodule = layer_vol.placeVolume(
96 RotationX(phi - 0.5 *
M_PI),
98 placedmodule.addPhysVolID(
"module", module_num);
100 mod_det.setPlacement(placedmodule);
109 detlayer->
addType(
"sensitive cylinder",
"layer");
112 PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
113 placedLayer.addPhysVolID(
"layer", layer_num);
115 lay_det.setPlacement(placedLayer);
119 Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
120 PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
121 placedTube.addPhysVolID(
"system", cylinderVolume.id());
122 cylinderVolume.setPlacement(placedTube);
124 return cylinderVolume;