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