11 #include "DD4hep/DetFactoryHelper.h"
16 using namespace dd4hep;
19 xml_det_t x_det = xml;
20 string detName = x_det.nameStr();
23 DetElement barrelDetector(detName, x_det.id());
27 barrelExtension->addType(
"barrel",
"detector");
29 for (xml_coll_t bmat(x_det, _Unicode(boundary_material)); bmat; ++bmat) {
30 xml_comp_t x_boundary_material = bmat;
37 dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
38 string barrelShapeName = x_det_dim.nameStr();
40 Tube barrelShape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
41 Volume barrelVolume(detName, barrelShape, oddd.air());
42 barrelVolume.setVisAttributes(oddd, x_det.visStr());
45 xml_comp_t x_stave = x_det.child(_U(stave));
46 Assembly staveAssembly(
"stave");
48 staveAssembly.setVisAttributes(oddd, x_stave.visStr());
50 DetElement staveElementTemplate(
"StaveElementTemplate", 0);
53 xml_comp_t x_module = x_det.child(_U(module));
59 double gap = x_stave.gap();
60 unsigned int nModules = x_stave.nmodules();
61 double ystep = length +
gap;
63 double staveHlength = ymin + 0.5 *
length;
66 for (
unsigned int moduleNum = 0; moduleNum < nModules; ++moduleNum) {
67 double positionY = -ymin + moduleNum * ystep;
69 if (x_stave.hasChild(_U(eltube))) {
71 xml_comp_t x_cable = x_stave.child(_U(eltube));
73 double rMin = x_cable.rmin();
74 double rMax = x_cable.rmax();
78 double rStep = (rMax - rMin) / (0.5 * nModules);
79 double rCable = rMin +
abs(moduleNum - 0.5 * nModules) * rStep;
81 Tube cable(0., rCable, 0.495 * ystep);
83 Volume cableVolume(
"Cable", cable, oddd.material(x_cable.materialStr()));
84 cableVolume.setVisAttributes(oddd, x_cable.visStr());
87 staveAssembly.placeVolume(
89 Position(x_cable.x_offset(), positionY,
90 x_cable.z_offset())));
94 PlacedVolume placedModule =
95 staveAssembly.placeVolume(module.first, Position(0., positionY, 0.));
96 placedModule.addPhysVolID(
"module", moduleNum);
98 string moduleName = _toString((
int)moduleNum,
"module%d");
100 auto moduleElement = module.second.clone(moduleName, moduleNum);
101 moduleElement.setPlacement(placedModule);
103 staveElementTemplate.add(moduleElement);
107 std::vector<double> layerR;
111 for (xml_coll_t lay(xml, _U(
layer)); lay; ++lay, ++layerNum) {
112 xml_comp_t x_layer = lay;
118 Tube(x_layer.rmin(), x_layer.rmax(), staveHlength + x_layer.outer_z()),
121 layerVolume.setVisAttributes(oddd, x_layer.visStr());
124 DetElement layerElement(barrelDetector, layerName, layerNum);
127 unsigned int nStaves = x_layer.nphi();
128 double phiStep = 2. *
M_PI / nStaves;
129 double phiTilt = x_layer.phi_tilt();
130 double phi0 = x_layer.phi0();
131 double r = x_layer.r();
135 for (
unsigned int staveNum = 0; staveNum < nStaves; ++staveNum) {
136 string staveName = _toString((
int)staveNum,
"stave%d");
138 double phi = phi0 + staveNum * phiStep;
139 double x = r * cos(phi);
140 double y = r * sin(phi);
142 PlacedVolume placedStave = layerVolume.placeVolume(
145 RotationY(phi + phiTilt),
146 Position(x, y, 0.)));
147 placedStave.addPhysVolID(
"stave", staveNum);
150 DetElement staveElement = staveElementTemplate.clone(staveName, staveNum);
151 staveElement.setPlacement(placedStave);
153 layerElement.add(staveElement);
157 std::vector<double> dummyR;
163 layerExtension->
addType(
"sensitive cylinder",
"layer");
166 for (xml_coll_t lmat(x_layer, _Unicode(layer_material)); lmat; ++lmat) {
167 xml_comp_t x_layer_material = lmat;
171 PlacedVolume placedLayer = barrelVolume.placeVolume(layerVolume);
172 placedLayer.addPhysVolID(
"layer", layerNum);
175 layerElement.setPlacement(placedLayer);
183 if (x_det.hasChild(_Unicode(services))) {
185 xml_comp_t x_services = x_det.child(_Unicode(services));
186 if (x_services.hasChild(_Unicode(cable_routing))) {
187 xml_comp_t x_cable_routing = x_services.child(_Unicode(cable_routing));
190 if (x_services.hasChild(_Unicode(cooling_routing))) {
191 xml_comp_t x_cooling_routing =
192 x_services.child(_Unicode(cooling_routing));
198 Volume motherVolume = oddd.pickMotherVolume(barrelDetector);
199 Position translation(0., 0., x_det_dim.z());
200 PlacedVolume placedBarrel =
201 motherVolume.placeVolume(barrelVolume, translation);
203 placedBarrel.addPhysVolID(
"system", barrelDetector.id());
204 barrelDetector.setPlacement(placedBarrel);
207 return barrelDetector;