File indexing completed on 2025-10-23 08:24:43
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/DD4hep/DD4hepConversionHelpers.hpp"
0010
0011 #include <DD4hep/DetFactoryHelper.h>
0012 #include <DD4hep/Objects.h>
0013 #include <XML/Utilities.h>
0014
0015 #include "DD4hepTestsHelper.hpp"
0016
0017 using namespace dd4hep;
0018 using namespace Acts;
0019 using namespace ActsPlugins;
0020 using namespace ActsTests;
0021
0022
0023
0024
0025
0026
0027
0028
0029 static Ref_t create_cylinder(Detector &dd, xml_h xml,
0030 SensitiveDetector ) {
0031 xml_det_t x_det = xml;
0032 std::string detName = x_det.nameStr();
0033
0034
0035 xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0036
0037
0038 DetElement cylinderElement(detName, x_det.id());
0039 dd4hep::xml::setDetectorTypeFlag(xml, cylinderElement);
0040
0041 std::string shapeName = x_det_tubs.nameStr();
0042 double phiMin = getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0043 double phiMax = getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0044 Tube tubeShape(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0045 x_det_tubs.dz(), phiMin, phiMax);
0046 Volume tubeVolume(detName, tubeShape, dd.material(x_det_tubs.materialStr()));
0047 tubeVolume.setVisAttributes(dd, x_det.visStr());
0048
0049
0050 Volume motherVolume = dd.pickMotherVolume(cylinderElement);
0051 PlacedVolume placedTube = motherVolume.placeVolume(
0052 tubeVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0053 placedTube.addPhysVolID(detName, cylinderElement.id());
0054 cylinderElement.setPlacement(placedTube);
0055
0056
0057 return cylinderElement;
0058 }
0059
0060 DECLARE_DETELEMENT(Cylinder, create_cylinder)
0061
0062
0063
0064
0065
0066
0067
0068
0069 static Ref_t create_disc(Detector &dd, xml_h xml, SensitiveDetector ) {
0070 xml_det_t x_det = xml;
0071 std::string detName = x_det.nameStr();
0072
0073
0074 xml_comp_t x_det_tubs = x_det.child(_U(tubs));
0075
0076
0077 DetElement discElement(detName, x_det.id());
0078 dd4hep::xml::setDetectorTypeFlag(xml, discElement);
0079
0080 std::string shapeName = x_det_tubs.nameStr();
0081 double phiMin = getAttrValueOr<double>(x_det_tubs, "phimin", 0.);
0082 double phiMax = getAttrValueOr<double>(x_det_tubs, "phimax", 360.);
0083
0084 Tube discShape = Tube(shapeName, x_det_tubs.rmin(), x_det_tubs.rmax(),
0085 x_det_tubs.dz(), phiMin, phiMax);
0086
0087 Volume discVolume(detName, discShape, dd.material(x_det_tubs.materialStr()));
0088 discVolume.setVisAttributes(dd, x_det.visStr());
0089
0090
0091 Volume motherVolume = dd.pickMotherVolume(discElement);
0092 PlacedVolume placedTube = motherVolume.placeVolume(
0093 discVolume, DD4hepTestsHelper::createTransform(x_det_tubs));
0094 placedTube.addPhysVolID(detName, discElement.id());
0095 discElement.setPlacement(placedTube);
0096
0097
0098 return discElement;
0099 }
0100
0101 DECLARE_DETELEMENT(Disc, create_disc)
0102
0103
0104
0105
0106
0107
0108
0109
0110 static Ref_t create_rectangle(Detector &dd, xml_h xml,
0111 SensitiveDetector ) {
0112 xml_det_t x_det = xml;
0113 std::string detName = x_det.nameStr();
0114
0115
0116 xml_comp_t x_det_box = x_det.child(_U(box));
0117
0118
0119 DetElement rectElement(detName, x_det.id());
0120 dd4hep::xml::setDetectorTypeFlag(xml, rectElement);
0121
0122 std::string shapeName = x_det_box.nameStr();
0123 Box rectShape(shapeName, 0.5 * x_det_box.dx(), 0.5 * x_det_box.dy(),
0124 0.5 * x_det_box.dz());
0125
0126 Volume rectVolume(detName, rectShape, dd.material(x_det_box.materialStr()));
0127 rectVolume.setVisAttributes(dd, x_det.visStr());
0128
0129
0130 Volume motherVolume = dd.pickMotherVolume(rectElement);
0131 PlacedVolume placedRect = motherVolume.placeVolume(
0132 rectVolume, DD4hepTestsHelper::createTransform(x_det_box));
0133 placedRect.addPhysVolID(detName, rectElement.id());
0134 rectElement.setPlacement(placedRect);
0135
0136
0137 return rectElement;
0138 }
0139
0140 DECLARE_DETELEMENT(Rectangle, create_rectangle)
0141
0142
0143
0144
0145
0146
0147
0148
0149 static Ref_t create_trapezoid(Detector &dd, xml_h xml,
0150 SensitiveDetector ) {
0151 xml_det_t x_det = xml;
0152 std::string detName = x_det.nameStr();
0153
0154
0155 xml_comp_t x_det_trap = x_det.child(_U(trap));
0156
0157
0158 DetElement trapElement(detName, x_det.id());
0159 dd4hep::xml::setDetectorTypeFlag(xml, trapElement);
0160
0161 std::string shapeName = x_det_trap.nameStr();
0162
0163
0164 Trapezoid trapShape(x_det_trap.x1(), x_det_trap.x2(), 0.5 * x_det_trap.dz(),
0165 0.5 * x_det_trap.dz(), 0.5 * x_det_trap.dy());
0166
0167 Volume trapVolume(detName, trapShape, dd.material(x_det_trap.materialStr()));
0168 trapVolume.setVisAttributes(dd, x_det.visStr());
0169
0170
0171 Volume motherVolume = dd.pickMotherVolume(trapElement);
0172 PlacedVolume placedTrap = motherVolume.placeVolume(
0173 trapVolume, DD4hepTestsHelper::createTransform(x_det_trap));
0174 placedTrap.addPhysVolID(detName, trapElement.id());
0175 trapElement.setPlacement(placedTrap);
0176
0177
0178 return trapElement;
0179 }
0180
0181 DECLARE_DETELEMENT(Trapezoid, create_trapezoid)