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_x = dims.x();
25 double dim_y = dims.y();
26 double dim_z = dims.z();
27 xml_dim_t apperture = x_det.child(_Unicode(apperture));
28 double app_x = apperture.x();
29 double app_y = apperture.y();
30 xml_dim_t coil = x_det.child(_Unicode(coil));
31 double coil_x = coil.dx();
32 double coil_y = coil.dy();
33 Material iron = dtor.material(
"Iron");
34 Material niobium = dtor.material(
"Niobium");
36 DetElement sdet(det_name, det_id);
37 Assembly assembly(det_name +
"_assembly");
39 string module_name =
"B0pFMag";
41 string vis0 = dd4hep::getAttrOrDefault(x_det, _Unicode(vis),
"BlueVis");
43 sdet.setAttributes(dtor, assembly, x_det.regionStr(), x_det.limitsStr(),
"OrangeVis");
46 Box yoke_outer(0.5 * dim_x, 0.5 * dim_y, 0.5 * dim_z);
47 Box app_hole(0.5 * app_x, 0.5 * app_y, 1 * dim_z);
48 SubtractionSolid yoke(yoke_outer, app_hole);
49 Volume yoke_vol(
"yoke_vol", yoke, iron);
50 auto yoke_pv = assembly.placeVolume(yoke_vol);
51 yoke_pv.addPhysVolID(
"element", 1);
52 DetElement yoke_de(sdet,
"yoke_de", 1);
53 yoke_de.setPlacement(yoke_pv);
54 yoke_de.setAttributes(dtor, yoke_vol, x_det.regionStr(), x_det.limitsStr(),
"BlueVis");
58 auto rod_pos_up = Transform3D(Translation3D(0.5 * (app_x - coil_y), 0.5 * (app_y - coil_x), 0.0));
59 auto rod_pos_down = Transform3D(RotationZ(M_PI) * Translation3D(0.5 * (app_x - coil_y), 0.5 * (app_y - coil_x), 0.0));
61 Box long_rod(0.5 * coil_y, 0.5 * coil_x, 0.5 * dim_z);
62 Box short_rod(0.5 * coil_y, coil_x, 0.5 * coil_x);
63 Box top_rod(0.5 * app_x, 0.5 * coil_y, 0.5 * coil_x);
64 UnionSolid half_rod1(long_rod, short_rod, Position(0.0, 0.5 * coil_x, -0.5 * (dim_z + coil_x)));
65 UnionSolid half_rod2(half_rod1, short_rod, Position(0.0, 0.5 * coil_x, 0.5 * (dim_z + coil_x)));
66 UnionSolid half_rod3(half_rod2, top_rod, Position(-0.5 * (app_x - coil_y), coil_x + 1.5*coil_y, -0.5 * (dim_z + coil_x)));
67 UnionSolid half_rod4(half_rod3, top_rod, Position(-0.5 * (app_x - coil_y), coil_x + 1.5*coil_y, 0.5 * (dim_z + coil_x)));
68 UnionSolid half_rod5(half_rod4, long_rod, Position(-app_x + coil_y, 0.0, 0.0));
69 UnionSolid half_rod6(half_rod5, short_rod, Position(-app_x + coil_y, 0.5 * coil_x, -0.5 * (dim_z + coil_x)));
70 UnionSolid half_rod7(half_rod6, short_rod, Position(-app_x + coil_y, 0.5 * coil_x, 0.5 * (dim_z + coil_x)));
71 Volume coil_up_vol(
"coil_up_vol", half_rod7, niobium);
72 Volume coil_down_vol(
"coil_down_vol", half_rod7, niobium);
75 auto rod_pv1 = assembly.placeVolume(coil_up_vol, rod_pos_up);
76 auto rod_pv2 = assembly.placeVolume(coil_down_vol, rod_pos_down);
77 DetElement coil1_de(sdet,
"coil1_de", 3);
78 DetElement coil2_de(sdet,
"coil2_de", 4);
79 coil1_de.setAttributes(dtor, coil_up_vol , x_det.regionStr(), x_det.limitsStr(),
"RedVis");
80 coil2_de.setAttributes(dtor, coil_down_vol, x_det.regionStr(), x_det.limitsStr(),
"RedVis");
81 coil1_de.setPlacement(rod_pv1);
82 coil2_de.setPlacement(rod_pv2);
87 auto pv = dtor.pickMotherVolume(sdet).placeVolume(assembly, Position(pos_x, pos_y, pos_z));
88 pv.addPhysVolID(
"system", det_id);
89 sdet.setPlacement(pv);
91 assembly->GetShape()->ComputeBBox();