14 #include "DD4hep/DetFactoryHelper.h"
16 using namespace dd4hep;
24 dd4hep::SensitiveDetector sens) {
25 xml_det_t x_det = xml;
26 std::string barrelName = x_det.nameStr();
28 dd4hep::DetElement barrelDetector(barrelName, x_det.id());
31 barrelExtension->addType(
"barrel",
"detector");
35 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
36 dd4hep::Tube barrelShape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
37 dd4hep::Volume barrelVolume(barrelName, barrelShape,
39 barrelVolume.setVisAttributes(lcdd, x_det.visStr());
42 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
44 xml_comp_t x_layer = j;
45 double rmin = x_layer.rmin();
46 double rmax = x_layer.rmax();
47 unsigned int layerNum = x_layer.id();
49 std::string layerName = barrelName + _toString((
int)layerNum,
"layer%d");
50 dd4hep::Volume layerVolume(layerName, Tube(rmin, rmax, x_layer.dz()),
51 lcdd.material(x_layer.materialStr()));
52 dd4hep::DetElement layerElement(barrelDetector, layerName, layerNum);
54 layerVolume.setVisAttributes(lcdd, x_layer.visStr());
56 unsigned int supportNum = 0;
58 if (x_layer.hasChild(_U(support))) {
59 xml_comp_t x_support = x_layer.child(_U(support));
62 dd4hep::Volume supportVolume(
64 Tube(x_support.rmin(), x_support.rmax(), x_support.dz()),
65 lcdd.material(x_support.materialStr()));
66 supportVolume.setVisAttributes(lcdd, x_support.visStr());
68 dd4hep::PlacedVolume placedSupport =
69 layerVolume.placeVolume(supportVolume);
70 placedSupport.addPhysVolID(
"support", supportNum++);
74 if (x_layer.hasChild(_U(module))) {
75 xml_comp_t x_module = x_layer.child(_U(module));
77 dd4hep::Assembly moduleAssembly(
"module");
79 moduleAssembly.setVisAttributes(lcdd, x_module.visStr());
80 if (x_module.isSensitive()) {
81 moduleAssembly.setSensitiveDetector(sens);
84 xml_comp_t x_mod_placement = x_module.child(_Unicode(placements));
85 unsigned int nphi = x_mod_placement.nphi();
86 double phi0 = x_mod_placement.phi0();
87 double phiTilt = x_mod_placement.phi_tilt();
88 double r = x_mod_placement.r();
89 double deltaPhi = 2 *
M_PI / nphi;
92 unsigned int compNum = 1;
94 std::vector<PlacedVolume> sensComponents;
96 for (xml_coll_t comp(x_module, _U(module_component)); comp;
98 xml_comp_t x_comp = comp;
100 std::string componentName = _toString((
int)compNum,
"component%d");
101 dd4hep::Volume componentVolume(
103 Box(0.5 * x_comp.dx(), 0.5 * x_comp.dy(), 0.5 * x_comp.dz()),
104 lcdd.material(x_comp.materialStr()));
105 if (x_comp.isSensitive()) {
106 componentVolume.setSensitiveDetector(sens);
110 componentVolume.setVisAttributes(lcdd, x_comp.visStr());
112 dd4hep::PlacedVolume placedComponent = moduleAssembly.placeVolume(
114 Position(x_comp.x_offset(), x_comp.y_offset(), x_comp.z_offset()));
115 placedComponent.addPhysVolID(
"component", compNum);
117 if (x_comp.isSensitive()) {
118 sensComponents.push_back(placedComponent);
123 if (x_module.hasChild(_U(tubs))) {
124 xml_comp_t x_tubs = x_module.child(_U(tubs));
125 dd4hep::Volume pipeVolume(
126 "CoolingPipe", Tube(x_tubs.rmin(), x_tubs.rmax(), x_tubs.length()),
127 lcdd.material(x_tubs.materialStr()));
128 pipeVolume.setVisAttributes(lcdd, x_tubs.visStr());
130 dd4hep::PlacedVolume placedPipe = moduleAssembly.placeVolume(
133 Position(x_tubs.x_offset(), x_tubs.y_offset(),
134 x_tubs.z_offset())));
135 placedPipe.addPhysVolID(
"support", supportNum++);
139 if (x_module.hasChild(_U(anchor))) {
140 xml_comp_t x_trd = x_module.child(_U(anchor));
142 dd4hep::Trapezoid mountShape(x_trd.x1(), x_trd.x2(), x_trd.length(),
143 x_trd.length(), x_trd.dz());
145 dd4hep::Volume mountVolume(
"ModuleMount", mountShape,
146 lcdd.material(x_trd.materialStr()));
149 dd4hep::PlacedVolume placedMount = moduleAssembly.placeVolume(
152 Position(x_trd.x_offset(), x_trd.y_offset(),
154 placedMount.addPhysVolID(
"support", supportNum++);
158 if (x_module.hasChild(_U(
box))) {
159 xml_comp_t x_cab = x_module.child(_U(
box));
160 dd4hep::Volume cableVolume(
161 "Cable",
Box(0.5 * x_cab.dx(), 0.5 * x_cab.dy(), 0.5 * x_cab.dz()),
162 lcdd.material(x_cab.materialStr()));
164 cableVolume.setVisAttributes(lcdd, x_cab.visStr());
166 dd4hep::PlacedVolume placedCable = moduleAssembly.placeVolume(
169 Position(x_cab.x_offset(), x_cab.y_offset(),
171 placedCable.addPhysVolID(
"support", supportNum++);
175 for (
unsigned int iphi = 0; iphi < nphi; ++iphi) {
176 double phi = phi0 + iphi * deltaPhi;
177 std::string moduleName = layerName + _toString((
int)iphi,
"module%d");
178 Position trans(r * cos(phi), r * sin(phi), 0.);
180 dd4hep::DetElement moduleElement(layerElement, moduleName, iphi);
182 unsigned int ccomp = 1;
183 for (
auto& sensComp : sensComponents) {
184 dd4hep::DetElement componentElement(moduleElement,
"component",
186 componentElement.setPlacement(sensComp);
189 sensorExtension->
addType(
"sensor",
"detector");
195 dd4hep::PlacedVolume placedModule = layerVolume.placeVolume(
199 placedModule.addPhysVolID(
"module", iphi + 1);
202 moduleElement.setPlacement(placedModule);
208 layerExtension->
addType(
"barrel",
"layer");
210 for (xml_coll_t lmat(x_layer, _Unicode(layer_material)); lmat; ++lmat) {
211 xml_comp_t x_layer_material = lmat;
218 dd4hep::PlacedVolume placedLayer = barrelVolume.placeVolume(layerVolume);
219 placedLayer.addPhysVolID(
"layer", layerNum);
221 layerElement.setPlacement(placedLayer);
225 dd4hep::Volume motherVolume = lcdd.pickMotherVolume(barrelDetector);
226 dd4hep::PlacedVolume placedBarrel = motherVolume.placeVolume(barrelVolume);
228 placedBarrel.addPhysVolID(
"system", barrelDetector.id());
229 barrelDetector.setPlacement(placedBarrel);
231 return barrelDetector;