SimpleBeamlineMagnet_geo.cpp
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include "DD4hep/Shapes.h"
4 #include "TMath.h"
5 #include "DDRec/Surface.h"
6 #include "DDRec/DetectorData.h"
7 #include "XML/Layering.h"
8 
9 using namespace std;
10 using namespace dd4hep;
11 using namespace dd4hep::rec;
12 using namespace ROOT::Math;
13 
14 static Ref_t build_magnet(Detector& dtor, xml_h e, SensitiveDetector sens) {
15  xml_det_t x_det = e;
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 
31  //xml_dim_t coil = x_det.child(_Unicode(coil));
32  //double coil_x = coil.dx();
33  //double coil_y = coil.dy();
34 
35  Material iron = dtor.material("Air");
36  Material niobium = dtor.material("Air");
37 
38  DetElement sdet(det_name, det_id);
39  Assembly assembly(det_name + "_assembly");
40 
41  string module_name = "SimpleBeamlineMagnet";
42  string vis0 = dd4hep::getAttrOrDefault(x_det, _Unicode(vis), "BlueVis");
43 
44  sdet.setAttributes(dtor, assembly, x_det.regionStr(), x_det.limitsStr(), x_det.visStr());
45 
46  // -- yoke --
47  Box yoke_outer(0.5 * dim_x, 0.5 * dim_y, 0.5 * dim_z);
48  Box app_hole(0.5 * app_x, 0.5 * app_y, 0.5 * dim_z + 1.0 * m);
49  SubtractionSolid yoke(yoke_outer, app_hole);
50  Volume yoke_vol("yoke_vol", yoke, iron);
51  DetElement yoke_DE(sdet, "yoke1", 1);
52 
53  auto yoke_pv = assembly.placeVolume(yoke_vol, Transform3D(RotationY(-pos_theta)));
54  yoke_pv.addPhysVolID("element", 1);
55  yoke_vol.setVisAttributes("RedVis");
56  yoke_DE.setPlacement(yoke_pv);
57  yoke_DE.setAttributes(dtor, yoke_vol, x_det.regionStr(), x_det.limitsStr(), x_det.visStr());
58 
60  //auto rod_pos_up = Transform3D(Translation3D(0.5 * (app_x - coil_y), 0.5 * (app_y - coil_x), 0.0));
61  //auto rod_pos_down = Transform3D(RotationZ(M_PI) * Translation3D(0.5 * (app_x - coil_y), 0.5 * (app_y - coil_x), 0.0));
62 
63  //Box long_rod(0.5 * coil_y, 0.5 * coil_x, 0.5 * dim_z);
64  //Box short_rod(0.5 * coil_y, coil_x, 0.5 * coil_x);
65  //Box top_rod(0.5 * app_x, 0.5 * coil_y, 0.5 * coil_x);
66  //UnionSolid half_rod1(long_rod, short_rod, Position(0.0, 0.5 * coil_x, -0.5 * (dim_z + coil_x)));
67  //UnionSolid half_rod2(half_rod1, short_rod, Position(0.0, 0.5 * coil_x, 0.5 * (dim_z + coil_x)));
68  //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)));
69  //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)));
70  //UnionSolid half_rod5(half_rod4, long_rod, Position(-app_x + coil_y, 0.0, 0.0));
71  //UnionSolid half_rod6(half_rod5, short_rod, Position(-app_x + coil_y, 0.5 * coil_x, -0.5 * (dim_z + coil_x)));
72  //UnionSolid half_rod7(half_rod6, short_rod, Position(-app_x + coil_y, 0.5 * coil_x, 0.5 * (dim_z + coil_x)));
73  //Volume coil_up_vol("coil_up_vol", half_rod7, niobium);
74  //Volume coil_down_vol("coil_down_vol", half_rod7, niobium);
75  //coil_up_vol.setVisAttributes("BlueVis");
76  //coil_down_vol.setVisAttributes("BlueVis");
77  //auto rod_pv = yoke_vol.placeVolume(coil_up_vol, rod_pos_up);
78  //rod_pv = yoke_vol.placeVolume(coil_down_vol, rod_pos_down);
79 
80 
81  // -- finishing steps
82  auto pv = dtor.pickMotherVolume(sdet).placeVolume(assembly, Position(pos_x, pos_y, pos_z));
83  pv.addPhysVolID("system", det_id);
84  sdet.setPlacement(pv);
85 
86  assembly->GetShape()->ComputeBBox();
87  return sdet;
88 }
89 
90 DECLARE_DETELEMENT(SimpleBeamlineMagnet, build_magnet)
static Ref_t build_magnet(Detector &dtor, xml_h e, SensitiveDetector sens)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.