14 #include <DD4hep/DetFactoryHelper.h>
15 #include <DD4hep/Objects.h>
16 #include <DDRec/DetectorData.h>
17 #include <XML/Utilities.h>
22 using namespace dd4hep;
32 const xml_comp_t &x_layer, SensitiveDetector sens,
35 auto layerName = x_layer.nameStr();
36 DetElement layerElement(layerName, layerID);
39 DD4hepTestsHelper::ensureExtension<dd4hep::rec::VariantParameters>(
44 layerAssembly.setVisAttributes(dd, x_layer.visStr());
46 if (x_layer.hasChild(_Unicode(acts_volume))) {
47 xml_comp_t acts_volume = x_layer.child(_Unicode(acts_volume));
48 layerParams.set<
bool>(
"acts_volume",
true);
49 if (acts_volume.hasChild(_U(tubs))) {
50 xml_comp_t acts_tubs = acts_volume.child(_Unicode(tubs));
51 layerParams.set<
int>(
"acts_volume_type",
52 int(Acts::VolumeBounds::BoundsType::eCylinder));
53 layerParams.set<
int>(
"acts_volume_bvalues_n", 3);
54 layerParams.set<
double>(
"acts_volume_bvalues_0", acts_tubs.rmin());
55 layerParams.set<
double>(
"acts_volume_bvalues_1", acts_tubs.rmax());
56 layerParams.set<
double>(
"acts_volume_bvalues_2", 0.5 * acts_tubs.dz());
58 std::vector<std::string> posKeys = {
"x",
"y",
"z"};
59 for (
const auto &pk : posKeys) {
60 layerParams.set<
double>(
61 "acts_volume_pos_" + pk,
62 Acts::getAttrValueOr<double>(acts_tubs, pk, 0.));
68 if (x_layer.hasChild(_Unicode(modules))) {
70 if (x_layer.hasChild(_Unicode(acts_surface_binning))) {
71 xml_comp_t sfBinning = x_layer.child(_Unicode(acts_surface_binning));
76 unsigned int sensorID = 1
u;
77 xml_comp_t x_det_modules = x_layer.child(_Unicode(modules));
78 for (xml_coll_t bmodule(x_det_modules, _U(
box)); bmodule !=
nullptr;
80 xml_comp_t x_det_box = bmodule;
83 Box boxShape(0.5 * x_det_box.dx(), 0.5 * x_det_box.dy(),
84 0.5 * x_det_box.dz());
87 DetElement boxElement(layerName +
"_module" +
std::to_string(sensorID),
90 Volume boxVolume(layerName, boxShape,
91 dd.material(x_det_box.materialStr()));
92 boxVolume.setVisAttributes(dd, x_det_box.visStr());
93 boxVolume.setSensitiveDetector(sens);
95 PlacedVolume placedBox = layerAssembly.placeVolume(
98 placedBox.addPhysVolID(
"sensor", sensorID++);
99 boxElement.setPlacement(placedBox);
101 layerElement.add(boxElement);
105 for (xml_coll_t psurface(x_layer, _Unicode(acts_passive_surface));
106 psurface !=
nullptr; ++psurface) {
107 xml_comp_t x_passive_xml = psurface;
109 if (x_passive_xml.hasChild(_Unicode(tubs))) {
110 xml_comp_t x_tubs_t = x_passive_xml.child(_Unicode(tubs));
112 DetElement passiveElement(layerName +
"_passiveEl", x_layer.id());
113 Tube passiveShape(layerName +
"_shape", x_tubs_t.rmin(), x_tubs_t.rmax(),
115 Volume passiveVolume(layerName +
"_volume", passiveShape,
116 dd.material(x_tubs_t.materialStr()));
117 passiveVolume.setVisAttributes(dd, x_layer.visStr());
119 PlacedVolume placedPassive = layerAssembly.placeVolume(
123 DD4hepTestsHelper::ensureExtension<dd4hep::rec::VariantParameters>(
125 params.set<
bool>(
"acts_passive_surface",
true);
127 passiveElement.setPlacement(placedPassive);
129 layerElement.add(passiveElement);
133 auto placedLayer = dAssembly.placeVolume(layerAssembly);
134 placedLayer.addPhysVolID(
"layer", layerID);
135 layerElement.setPlacement(placedLayer);
149 SensitiveDetector sens) {
150 xml_det_t x_det = xml;
151 string detName = x_det.nameStr();
154 DetElement detectorElement(detName, x_det.id());
155 dd4hep::xml::setDetectorTypeFlag(xml, detectorElement);
158 Assembly detectorAssembly(detName);
159 detectorAssembly.setVisAttributes(dd, x_det.visStr());
162 if (x_det.hasChild(_Unicode(layers))) {
163 xml_comp_t x_det_layers = x_det.child(_Unicode(layers));
165 for (xml_coll_t
layer(x_det_layers, _Unicode(
layer));
layer !=
nullptr;
167 xml_comp_t x_det_layer =
layer;
171 detectorElement.add(layerElement);
175 Volume motherVolume = dd.pickMotherVolume(detectorElement);
177 PlacedVolume placedDetector =
178 motherVolume.placeVolume(detectorAssembly, translation);
180 placedDetector.addPhysVolID(
"system", x_det.id());
181 detectorElement.setPlacement(placedDetector);
184 return detectorElement;
197 SensitiveDetector sens) {
198 xml_det_t x_det = xml;
199 string detName = x_det.nameStr();
201 xml_comp_t x_det_env = x_det.child(_Unicode(envelope));
204 DetElement discLayerElement(detName, x_det.id());
205 dd4hep::xml::setDetectorTypeFlag(xml, discLayerElement);
208 DD4hepTestsHelper::ensureExtension<dd4hep::rec::VariantParameters>(
212 if (x_det.hasChild(_Unicode(acts_surface_binning))) {
213 xml_comp_t sfBinning = x_det.child(_Unicode(acts_surface_binning));
219 DetElement envelopeElement(detName +
"_envelope", x_det.id());
220 Tube envelopeShape(detName +
"_shape", x_det_env.rmin(), x_det_env.rmax(),
222 Volume envelopeVolume(detName, envelopeShape,
223 dd.material(x_det_env.materialStr()));
224 envelopeVolume.setVisAttributes(dd, x_det.visStr());
229 if (x_det.hasChild(_Unicode(modules))) {
230 unsigned int sensorID = 1
u;
231 xml_comp_t x_det_modules = x_det.child(_Unicode(modules));
233 for (xml_coll_t bmodule(x_det_modules, _U(trap)); bmodule !=
nullptr;
235 xml_comp_t x_det_trap = bmodule;
238 Trapezoid trapShape(0.5 * x_det_trap.dz(), 0.5 * x_det_trap.dz(),
239 x_det_trap.x1(), x_det_trap.x2(),
240 0.5 * x_det_trap.dy());
243 DetElement trapElement(detName +
"_module" +
std::to_string(sensorID),
246 DD4hepTestsHelper::ensureExtension<dd4hep::rec::VariantParameters>(
250 Volume trapVolume(detName, trapShape,
251 dd.material(x_det_trap.materialStr()));
252 trapVolume.setVisAttributes(dd, x_det.visStr());
253 trapVolume.setSensitiveDetector(sens);
255 PlacedVolume placedTrap = envelopeVolume.placeVolume(
258 placedTrap.addPhysVolID(
"sensor", sensorID++);
259 trapElement.setPlacement(placedTrap);
261 discLayerElement.add(trapElement);
266 Volume motherVolume = dd.pickMotherVolume(discLayerElement);
267 PlacedVolume placedEnvelope = motherVolume.placeVolume(
269 placedEnvelope.addPhysVolID(
"system", discLayerElement.id());
270 discLayerElement.setPlacement(placedEnvelope);
272 return discLayerElement;