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 barrelExtension->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());
39 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
40 xml_comp_t x_layer = j;
41 double l_rmin = x_layer.inner_r();
42 double l_rmax = x_layer.outer_r();
44 string layer_name = det_name + _toString((
int)layer_num,
"layer%d");
45 Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, x_layer.z()),
46 lcdd.material(x_layer.materialStr()));
47 DetElement lay_det(cylinderVolume, layer_name, layer_num);
49 layer_vol.setVisAttributes(lcdd, x_layer.visStr());
52 if (x_layer.hasChild(_U(module))) {
53 xml_comp_t x_module = x_layer.child(_U(module));
54 int repeat = x_module.repeat();
55 double deltaphi = 2. *
M_PI / repeat;
57 xml_comp_t x_slice = x_layer.child(_U(slice));
58 int zrepeat = x_slice.repeat();
59 double dz = x_slice.z();
60 double dr = x_slice.dr();
63 size_t module_num = 0;
67 Box(x_module.length(), x_module.width(), x_module.thickness()),
68 lcdd.material(x_module.materialStr()));
70 mod_vol.setVisAttributes(lcdd, x_module.visStr());
73 std::vector<PlacedVolume> sensComponents;
76 for (xml_coll_t comp(x_module, _U(module_component)); comp; ++comp) {
77 string component_name = _toString((
int)comp_num,
"component%d");
78 xml_comp_t x_component = comp;
79 Volume comp_vol(component_name,
80 Box(x_component.length(), x_component.width(),
81 x_component.thickness()),
82 lcdd.material(x_component.materialStr()));
83 comp_vol.setVisAttributes(lcdd, x_component.visStr());
86 if (x_component.isSensitive())
87 comp_vol.setSensitiveDetector(sens);
90 Position trans(x_component.x(), 0., x_component.z());
91 PlacedVolume placedcomponent = mod_vol.placeVolume(comp_vol, trans);
92 placedcomponent.addPhysVolID(
"component", comp_num);
93 if (x_component.isSensitive())
94 sensComponents.push_back(placedcomponent);
98 if (x_module.hasChild(_U(subtraction))) {
99 xml_comp_t x_sub = x_module.child(_U(subtraction));
100 xml_comp_t x_trd = x_sub.child(_U(trd));
101 xml_comp_t x_tubs = x_sub.child(_U(tubs));
102 string component_name = _toString((
int)comp_num,
"component%d");
104 Trapezoid trap_shape(x_trd.x1(), x_trd.x2(), x_trd.length(),
105 x_trd.length(), x_trd.thickness());
106 Tube tubs_shape(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz());
108 Volume sub_vol(
"subtraction_components",
109 SubtractionSolid(trap_shape, tubs_shape,
111 lcdd.material(x_sub.materialStr()));
112 sub_vol.setVisAttributes(lcdd, x_sub.visStr());
114 PlacedVolume placedSub = mod_vol.placeVolume(
116 Position(0., 0., x_sub.z())));
117 placedSub.addPhysVolID(
"component", comp_num);
121 if (x_module.hasChild(_U(tubs))) {
122 xml_comp_t x_tubs = x_module.child(_U(tubs));
123 string component_name = _toString((
int)comp_num,
"component%d");
124 Volume pipe_vol(
"CoolingPipe",
125 Tube(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz()),
126 lcdd.material(x_tubs.materialStr()));
127 pipe_vol.setVisAttributes(lcdd, x_tubs.visStr());
129 PlacedVolume placedPipe = mod_vol.placeVolume(
131 Position(0., 0., x_tubs.z())));
132 placedPipe.addPhysVolID(
"component", comp_num);
136 for (
int k = -zrepeat;
k <= zrepeat;
k++) {
137 double r = (l_rmax + l_rmin) * 0.5;
141 for (
int i = 0; i < repeat; ++i) {
144 layer_name + _toString((
int)module_num,
"module%d");
145 Position trans(r *
cos(phi), r * sin(phi),
k * dz);
147 DetElement mod_det(lay_det, module_name, module_num);
149 if (x_module.isSensitive()) {
150 mod_vol.setSensitiveDetector(sens);
152 int sens_comp_num = 0;
153 for (
auto& sensComp : sensComponents) {
154 DetElement component_det(mod_det,
"component", sens_comp_num);
155 component_det.setPlacement(sensComp);
159 PlacedVolume placedmodule = layer_vol.placeVolume(
162 RotationX(phi - 0.6 *
M_PI),
164 placedmodule.addPhysVolID(
"module", module_num);
166 mod_det.setPlacement(placedmodule);
172 if (x_layer.hasChild(_U(tubs))) {
173 xml_comp_t x_support = x_layer.child(_U(tubs));
174 double srmin = l_rmin + x_support.offset();
175 double srmax = srmin + x_support.thickness();
177 Volume support_vol(
"SupportStructure", Tube(srmin, srmax, x_support.dz()),
178 lcdd.material(x_support.materialStr()));
179 support_vol.setVisAttributes(lcdd, x_support.visStr());
181 PlacedVolume placedSupport = layer_vol.placeVolume(support_vol);
182 placedSupport.addPhysVolID(
"support", 1);
189 layerExtension->
addType(
"sensitive cylinder",
"layer");
192 PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
193 placedLayer.addPhysVolID(
"layer", layer_num);
195 lay_det.setPlacement(placedLayer);
199 Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
200 PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
201 placedTube.addPhysVolID(
"system", cylinderVolume.id());
202 cylinderVolume.setPlacement(placedTube);
204 return cylinderVolume;