1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include "DD4hep/Shapes.h"
5 #include "DDRec/Surface.h"
6 #include "DDRec/DetectorData.h"
7 #include "XML/Layering.h"
11 using namespace dd4hep::rec;
12 using namespace ROOT::Math;
16 int det_id = x_det.id();
17 string det_name = x_det.nameStr();
18 xml_dim_t pos = x_det.child(_U(placement));
19 double pos_x = pos.x();
20 double pos_y = pos.y();
21 double pos_z = pos.z();
22 double pos_theta = pos.attr<
double>(_U(theta));
23 xml_dim_t dims = x_det.dimensions();
24 double dim_r = dims.r();
25 double dim_z = dims.z();
26 xml_dim_t apperture = x_det.child(_Unicode(apperture));
27 double app_r = apperture.r();
28 xml_dim_t coil = x_det.child(_Unicode(coil));
29 double coil_x = coil.dx();
30 double coil_y = coil.dy();
31 Material iron = dtor.material(
"Iron");
32 Material niobium = dtor.material(
"Niobium");
34 DetElement sdet(det_name, det_id);
35 Assembly assembly(det_name +
"_assembly");
37 string module_name =
"Quad_magnet";
39 string vis0 = dd4hep::getAttrOrDefault(x_det, _Unicode(vis),
"BlueVis");
41 sdet.setAttributes(dtor, assembly, x_det.regionStr(), x_det.limitsStr(),
"OrangeVis");
44 Tube yoke_tube(app_r + coil_y, dim_r, 0.5*dim_z);
45 Volume yoke_vol(
"yoke_vol", yoke_tube, iron);
46 auto yoke_pv = assembly.placeVolume(yoke_vol);
47 yoke_pv.addPhysVolID(
"element", 1);
48 DetElement yoke_de(sdet,
"yoke_de", 1);
49 yoke_de.setPlacement(yoke_pv);
50 yoke_de.setAttributes(dtor, yoke_vol, x_det.regionStr(), x_det.limitsStr(),
"BlueVis");
53 double offset = 1.5 * coil_x;
54 double appc_r = app_r + 0.5 * coil_y;
55 double offset_angle = atan(offset / appc_r);
57 Tube longrod(app_r, app_r + coil_y, 0.5*dim_z, atan(coil_x / app_r));
58 Tube connector(app_r, app_r + coil_y , coil_y, 0.5*M_PI - offset_angle);
60 UnionSolid coil1(longrod, longrod, Transform3D(RotationZ(-offset_angle)));
61 UnionSolid coil2(coil1, longrod, Transform3D(RotationZ(0.5*M_PI)));
62 UnionSolid coil3(coil2, longrod, Transform3D(RotationZ(M_PI)));
63 UnionSolid coil4(coil3, longrod, Transform3D(RotationZ(1.5*M_PI)));
65 UnionSolid coil5(coil4, longrod, Transform3D(RotationZ(0.5*M_PI - offset_angle)));
66 UnionSolid coil6(coil5, longrod, Transform3D(RotationZ(M_PI - offset_angle)));
67 UnionSolid coil7(coil6, longrod, Transform3D(RotationZ(1.5*M_PI - offset_angle)));
69 UnionSolid coil8(coil7, connector, Transform3D(Translation3D(0.0, 0.0, -0.5*dim_z + coil_y)));
70 UnionSolid coil9(coil8, connector, Transform3D(Translation3D(0.0, 0.0, -0.5*dim_z + coil_y) * RotationZ(0.5*M_PI)));
71 UnionSolid coil10(coil9, connector, Transform3D(Translation3D(0.0, 0.0, -0.5*dim_z + coil_y) * RotationZ(M_PI)));
72 UnionSolid coil11(coil10, connector, Transform3D(Translation3D(0.0, 0.0, -0.5*dim_z + coil_y) * RotationZ(1.5*M_PI)));
73 UnionSolid coil12(coil11, connector, Transform3D(Translation3D(0.0, 0.0, 0.5*dim_z - coil_y)));
74 UnionSolid coil13(coil12, connector, Transform3D(Translation3D(0.0, 0.0, 0.5*dim_z - coil_y) * RotationZ(0.5*M_PI)));
75 UnionSolid coil14(coil13, connector, Transform3D(Translation3D(0.0, 0.0, 0.5*dim_z - coil_y) * RotationZ(M_PI)));
76 UnionSolid coil15(coil14, connector, Transform3D(Translation3D(0.0, 0.0, 0.5*dim_z - coil_y) * RotationZ(1.5*M_PI)));
78 Volume coil_vol(
"coil_vol", coil14, niobium);
80 auto coil_pos = Transform3D(RotationZ(0.5*M_PI - offset_angle));
81 auto coil_pv = assembly.placeVolume(coil_vol, coil_pos);
82 DetElement coil_de(sdet,
"coil_de", 2);
83 coil_de.setAttributes(dtor, coil_vol, x_det.regionStr(), x_det.limitsStr(),
"RedVis");
84 coil_de.setPlacement(coil_pv);
87 auto final_pos = Transform3D(Translation3D(pos_x, pos_y, pos_z) * RotationY(pos_theta));
88 auto pv = dtor.pickMotherVolume(sdet).placeVolume(assembly, final_pos);
89 pv.addPhysVolID(
"system", det_id);
90 sdet.setPlacement(pv);
92 assembly->GetShape()->ComputeBBox();