10 #include "DD4hep/DetFactoryHelper.h"
13 using namespace dd4hep;
21 xml_det_t x_det = xml;
22 string det_name = x_det.nameStr();
24 DetElement cylinderVolume(det_name, x_det.id());
27 detvolume->addType(
"barrel",
"detector");
30 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
31 Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
32 Volume tube_vol(det_name, tube_shape,
34 tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
37 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
38 xml_comp_t x_layer = j;
39 double l_rmin = x_layer.inner_r();
40 double l_rmax = x_layer.outer_r();
41 double l_length = x_layer.z();
43 string layer_name = det_name + _toString((
int)layer_num,
"layer%d");
44 Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
45 lcdd.material(x_layer.materialStr()));
46 DetElement lay_det(cylinderVolume, layer_name, layer_num);
48 layer_vol.setVisAttributes(lcdd, x_layer.visStr());
50 if (x_layer.hasChild(_U(module))) {
51 xml_comp_t x_module = x_layer.child(_U(module));
52 int repeat = x_module.repeat();
53 double deltaphi = 2. *
M_PI / repeat;
55 xml_comp_t x_slice = x_layer.child(_U(slice));
56 int zrepeat = x_slice.repeat();
57 double dz = x_slice.z();
58 double dr = x_slice.dr();
59 double offsetrz = x_slice.dz();
60 size_t module_num = 0;
64 Box(x_module.length(), x_module.width(), x_module.thickness()),
65 lcdd.material(x_module.materialStr()));
67 for (
int k = -zrepeat;
k <= zrepeat;
k++) {
68 double r = (l_rmax + l_rmin) * 0.5;
69 string zname = _toString((
int)
k,
"z%d");
73 for (
int i = 0; i < repeat; ++i) {
78 mod_vol.setVisAttributes(lcdd, x_module.visStr());
80 string module_name = zname + _toString((
int)i,
"module%d");
81 Position trans(radius * cos(phi), radius * sin(phi), k * dz);
83 DetElement mod_det(lay_det, module_name, module_num);
88 if (x_module.isSensitive()) {
89 mod_vol.setSensitiveDetector(sens);
92 PlacedVolume placedmodule = layer_vol.placeVolume(
95 RotationX(phi - 0.5 *
M_PI),
97 placedmodule.addPhysVolID(
"module", module_num);
99 mod_det.setPlacement(placedmodule);
108 detlayer->
addType(
"sensitive cylinder",
"layer");
111 PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
112 placedLayer.addPhysVolID(
"layer", layer_num);
114 lay_det.setPlacement(placedLayer);
118 Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
119 PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
120 placedTube.addPhysVolID(
"system", cylinderVolume.id());
121 cylinderVolume.setPlacement(placedTube);
123 return cylinderVolume;