15 #include "DD4hep/DetFactoryHelper.h"
17 using namespace dd4hep;
25 dd4hep::SensitiveDetector sens) {
26 xml_det_t x_det = xml;
27 std::string barrelName = x_det.nameStr();
29 dd4hep::DetElement barrelDetector(barrelName, x_det.id());
32 barrelExtension->addType(
"barrel",
"detector");
36 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
37 dd4hep::Tube barrelShape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
38 dd4hep::Volume barrelVolume(barrelName, barrelShape,
40 barrelVolume.setVisAttributes(lcdd, x_det.visStr());
43 for (xml_coll_t j(xml, _U(
layer)); j; ++j) {
45 xml_comp_t x_layer = j;
46 double rmin = x_layer.rmin();
47 double rmax = x_layer.rmax();
48 unsigned int layerNum = x_layer.id();
50 std::string layerName = barrelName + _toString((
int)layerNum,
"layer%d");
51 dd4hep::Volume layerVolume(layerName, Tube(rmin, rmax, x_layer.dz()),
52 lcdd.material(x_layer.materialStr()));
53 dd4hep::DetElement layerElement(barrelDetector, layerName, layerNum);
55 layerVolume.setVisAttributes(lcdd, x_layer.visStr());
57 unsigned int supportNum = 0;
59 if (x_layer.hasChild(_U(support))) {
60 xml_comp_t x_support = x_layer.child(_U(support));
63 dd4hep::Volume supportVolume(
65 Tube(x_support.rmin(), x_support.rmax(), x_support.dz()),
66 lcdd.material(x_support.materialStr()));
67 supportVolume.setVisAttributes(lcdd, x_support.visStr());
69 dd4hep::PlacedVolume placedSupport =
70 layerVolume.placeVolume(supportVolume);
71 placedSupport.addPhysVolID(
"support", supportNum++);
75 if (x_layer.hasChild(_U(module))) {
76 xml_comp_t x_module = x_layer.child(_U(module));
78 dd4hep::Assembly moduleAssembly(
"module");
80 moduleAssembly.setVisAttributes(lcdd, x_module.visStr());
81 if (x_module.isSensitive()) {
82 moduleAssembly.setSensitiveDetector(sens);
85 xml_comp_t x_mod_placement = x_module.child(_Unicode(placements));
86 unsigned int nphi = x_mod_placement.nphi();
87 double phi0 = x_mod_placement.phi0();
88 double phiTilt = x_mod_placement.phi_tilt();
89 double r = x_mod_placement.r();
90 double deltaPhi = 2 *
M_PI / nphi;
93 unsigned int compNum = 1;
95 std::vector<PlacedVolume> sensComponents;
97 for (xml_coll_t comp(x_module, _U(module_component)); comp;
99 xml_comp_t x_comp = comp;
101 std::string componentName = _toString((
int)compNum,
"component%d");
102 dd4hep::Volume componentVolume(
104 Box(0.5 * x_comp.dx(), 0.5 * x_comp.dy(), 0.5 * x_comp.dz()),
105 lcdd.material(x_comp.materialStr()));
106 if (x_comp.isSensitive()) {
107 componentVolume.setSensitiveDetector(sens);
111 componentVolume.setVisAttributes(lcdd, x_comp.visStr());
113 dd4hep::PlacedVolume placedComponent = moduleAssembly.placeVolume(
115 Position(x_comp.x_offset(), x_comp.y_offset(), x_comp.z_offset()));
116 placedComponent.addPhysVolID(
"component", compNum);
118 if (x_comp.isSensitive()) {
119 sensComponents.push_back(placedComponent);
124 if (x_module.hasChild(_U(tubs))) {
125 xml_comp_t x_tubs = x_module.child(_U(tubs));
126 dd4hep::Volume pipeVolume(
127 "CoolingPipe", Tube(x_tubs.rmin(), x_tubs.rmax(), x_tubs.length()),
128 lcdd.material(x_tubs.materialStr()));
129 pipeVolume.setVisAttributes(lcdd, x_tubs.visStr());
131 dd4hep::PlacedVolume placedPipe = moduleAssembly.placeVolume(
134 Position(x_tubs.x_offset(), x_tubs.y_offset(),
135 x_tubs.z_offset())));
136 placedPipe.addPhysVolID(
"support", supportNum++);
140 if (x_module.hasChild(_U(anchor))) {
141 xml_comp_t x_trd = x_module.child(_U(anchor));
143 dd4hep::Trapezoid mountShape(x_trd.x1(), x_trd.x2(), x_trd.length(),
144 x_trd.length(), x_trd.dz());
146 dd4hep::Volume mountVolume(
"ModuleMount", mountShape,
147 lcdd.material(x_trd.materialStr()));
150 dd4hep::PlacedVolume placedMount = moduleAssembly.placeVolume(
153 Position(x_trd.x_offset(), x_trd.y_offset(),
155 placedMount.addPhysVolID(
"support", supportNum++);
159 if (x_module.hasChild(_U(
box))) {
160 xml_comp_t x_cab = x_module.child(_U(
box));
161 dd4hep::Volume cableVolume(
162 "Cable",
Box(0.5 * x_cab.dx(), 0.5 * x_cab.dy(), 0.5 * x_cab.dz()),
163 lcdd.material(x_cab.materialStr()));
165 cableVolume.setVisAttributes(lcdd, x_cab.visStr());
167 dd4hep::PlacedVolume placedCable = moduleAssembly.placeVolume(
170 Position(x_cab.x_offset(), x_cab.y_offset(),
172 placedCable.addPhysVolID(
"support", supportNum++);
176 for (
unsigned int iphi = 0; iphi < nphi; ++iphi) {
177 double phi = phi0 + iphi * deltaPhi;
178 std::string moduleName = layerName + _toString((
int)iphi,
"module%d");
179 Position trans(r *
cos(phi), r * sin(phi), 0.);
181 dd4hep::DetElement moduleElement(layerElement, moduleName, iphi);
183 unsigned int ccomp = 1;
184 for (
auto& sensComp : sensComponents) {
185 dd4hep::DetElement componentElement(moduleElement,
"component",
187 componentElement.setPlacement(sensComp);
190 sensorExtension->
addType(
"sensor",
"detector");
196 dd4hep::PlacedVolume placedModule = layerVolume.placeVolume(
200 placedModule.addPhysVolID(
"module", iphi + 1);
203 moduleElement.setPlacement(placedModule);
209 layerExtension->
addType(
"barrel",
"layer");
211 for (xml_coll_t lmat(x_layer, _Unicode(layer_material)); lmat; ++lmat) {
212 xml_comp_t x_layer_material = lmat;
219 dd4hep::PlacedVolume placedLayer = barrelVolume.placeVolume(layerVolume);
220 placedLayer.addPhysVolID(
"layer", layerNum);
222 layerElement.setPlacement(placedLayer);
226 dd4hep::Volume motherVolume = lcdd.pickMotherVolume(barrelDetector);
227 dd4hep::PlacedVolume placedBarrel = motherVolume.placeVolume(barrelVolume);
229 placedBarrel.addPhysVolID(
"system", barrelDetector.id());
230 barrelDetector.setPlacement(placedBarrel);
232 return barrelDetector;