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 barrelExtension->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());
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();
43 string layer_name = det_name + _toString((
int)layer_num,
"layer%d");
44 Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, x_layer.z()),
45 lcdd.material(x_layer.materialStr()));
46 DetElement lay_det(cylinderVolume, layer_name, layer_num);
48 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();
62 size_t module_num = 0;
66 Box(x_module.length(), x_module.width(), x_module.thickness()),
67 lcdd.material(x_module.materialStr()));
69 mod_vol.setVisAttributes(lcdd, x_module.visStr());
72 std::vector<PlacedVolume> sensComponents;
75 for (xml_coll_t comp(x_module, _U(module_component)); comp; ++comp) {
76 string component_name = _toString((
int)comp_num,
"component%d");
77 xml_comp_t x_component = comp;
78 Volume comp_vol(component_name,
79 Box(x_component.length(), x_component.width(),
80 x_component.thickness()),
81 lcdd.material(x_component.materialStr()));
82 comp_vol.setVisAttributes(lcdd, x_component.visStr());
85 if (x_component.isSensitive())
86 comp_vol.setSensitiveDetector(sens);
89 Position trans(x_component.x(), 0., x_component.z());
90 PlacedVolume placedcomponent = mod_vol.placeVolume(comp_vol, trans);
91 placedcomponent.addPhysVolID(
"component", comp_num);
92 if (x_component.isSensitive())
93 sensComponents.push_back(placedcomponent);
97 if (x_module.hasChild(_U(subtraction))) {
98 xml_comp_t x_sub = x_module.child(_U(subtraction));
99 xml_comp_t x_trd = x_sub.child(_U(trd));
100 xml_comp_t x_tubs = x_sub.child(_U(tubs));
101 string component_name = _toString((
int)comp_num,
"component%d");
103 Trapezoid trap_shape(x_trd.x1(), x_trd.x2(), x_trd.length(),
104 x_trd.length(), x_trd.thickness());
105 Tube tubs_shape(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz());
107 Volume sub_vol(
"subtraction_components",
108 SubtractionSolid(trap_shape, tubs_shape,
110 lcdd.material(x_sub.materialStr()));
111 sub_vol.setVisAttributes(lcdd, x_sub.visStr());
113 PlacedVolume placedSub = mod_vol.placeVolume(
115 Position(0., 0., x_sub.z())));
116 placedSub.addPhysVolID(
"component", comp_num);
120 if (x_module.hasChild(_U(tubs))) {
121 xml_comp_t x_tubs = x_module.child(_U(tubs));
122 string component_name = _toString((
int)comp_num,
"component%d");
123 Volume pipe_vol(
"CoolingPipe",
124 Tube(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz()),
125 lcdd.material(x_tubs.materialStr()));
126 pipe_vol.setVisAttributes(lcdd, x_tubs.visStr());
128 PlacedVolume placedPipe = mod_vol.placeVolume(
130 Position(0., 0., x_tubs.z())));
131 placedPipe.addPhysVolID(
"component", comp_num);
135 for (
int k = -zrepeat;
k <= zrepeat;
k++) {
136 double r = (l_rmax + l_rmin) * 0.5;
140 for (
int i = 0; i < repeat; ++i) {
143 layer_name + _toString((
int)module_num,
"module%d");
144 Position trans(r * cos(phi), r * sin(phi),
k * dz);
146 DetElement mod_det(lay_det, module_name, module_num);
148 if (x_module.isSensitive()) {
149 mod_vol.setSensitiveDetector(sens);
151 int sens_comp_num = 0;
152 for (
auto& sensComp : sensComponents) {
153 DetElement component_det(mod_det,
"component", sens_comp_num);
154 component_det.setPlacement(sensComp);
158 PlacedVolume placedmodule = layer_vol.placeVolume(
161 RotationX(phi - 0.6 *
M_PI),
163 placedmodule.addPhysVolID(
"module", module_num);
165 mod_det.setPlacement(placedmodule);
171 if (x_layer.hasChild(_U(tubs))) {
172 xml_comp_t x_support = x_layer.child(_U(tubs));
173 double srmin = l_rmin + x_support.offset();
174 double srmax = srmin + x_support.thickness();
176 Volume support_vol(
"SupportStructure", Tube(srmin, srmax, x_support.dz()),
177 lcdd.material(x_support.materialStr()));
178 support_vol.setVisAttributes(lcdd, x_support.visStr());
180 PlacedVolume placedSupport = layer_vol.placeVolume(support_vol);
181 placedSupport.addPhysVolID(
"support", 1);
188 layerExtension->
addType(
"sensitive cylinder",
"layer");
191 PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
192 placedLayer.addPhysVolID(
"layer", layer_num);
194 lay_det.setPlacement(placedLayer);
198 Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
199 PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
200 placedTube.addPhysVolID(
"system", cylinderVolume.id());
201 cylinderVolume.setPlacement(placedTube);
203 return cylinderVolume;