12 #include "DD4hep/DetFactoryHelper.h"
15 using namespace dd4hep;
22 static Ref_t
create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
23 xml_det_t x_det = xml;
24 string det_name = x_det.nameStr();
26 DetElement cylinderVolume(det_name, x_det.id());
29 barrelExtension->addType(
"barrel",
"detector");
32 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
33 Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
34 Volume tube_vol(det_name, tube_shape,
36 tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
40 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
41 xml_comp_t x_layer = j;
42 double l_rmin = x_layer.inner_r();
43 double l_rmax = x_layer.outer_r();
44 double l_length = x_layer.z();
46 string layer_name = det_name + _toString((
int)layer_num,
"layer%d");
47 Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
48 lcdd.material(x_layer.materialStr()));
49 DetElement lay_det(cylinderVolume, layer_name, layer_num);
51 layer_vol.setVisAttributes(lcdd, x_layer.visStr());
53 if (x_layer.hasChild(_U(module))) {
54 xml_comp_t x_module = x_layer.child(_U(module));
55 int repeat = x_module.repeat();
56 double deltaphi = 2. *
M_PI / repeat;
58 xml_comp_t x_slice = x_layer.child(_U(slice));
59 int zrepeat = x_slice.repeat();
60 double dz = x_slice.z();
61 double dr = x_slice.dr();
65 Box(x_module.width(), x_module.length(), x_module.thickness()),
66 lcdd.material(x_module.materialStr()));
72 x_module.length(), x_module.width(), x_module.thickness(),
73 sens.readout().segmentation());
76 mod_vol.setVisAttributes(lcdd, x_module.visStr());
77 size_t module_num = 0;
79 for (
int k = -zrepeat;
k <= zrepeat;
k++) {
80 double r = (l_rmax + l_rmin) * 0.5;
81 string zname = _toString((
int)
k,
"z%d");
85 for (
int i = 0; i < repeat; ++i) {
87 string module_name = zname + _toString((
int)i,
"module%d");
88 Position trans(r *
cos(phi), r * sin(phi), k * dz);
90 DetElement mod_det(lay_det, module_name, module_num);
92 if (x_module.isSensitive()) {
93 mod_vol.setSensitiveDetector(sens);
99 PlacedVolume placedmodule = layer_vol.placeVolume(
103 placedmodule.addPhysVolID(
"module", module_num);
105 mod_det.setPlacement(placedmodule);
114 layerExtension->
addType(
"active cylinder",
"layer");
115 layerExtension->
addType(
"axes",
"definitions",
"YxZ");
118 PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
119 placedLayer.addPhysVolID(
"layer", layer_num);
121 lay_det.setPlacement(placedLayer);
125 Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
126 PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
127 placedTube.addPhysVolID(
"system", cylinderVolume.id());
128 cylinderVolume.setPlacement(placedTube);
130 return cylinderVolume;