crab_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_cavity(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_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 x_cavity = x_det.child(_Unicode(cavity));
29  double r1 = x_cavity.attr<double>(_Unicode(r1));
30  double r2 = x_cavity.attr<double>(_Unicode(r2));
31  double z1 = x_cavity.attr<double>(_Unicode(z1));
32  double z2 = x_cavity.attr<double>(_Unicode(z2));
33  Material niobium = dtor.material("Niobium");
34  Material titanium = dtor.material("Titanium");
35  Material helium = dtor.material("Helium");
36  Material vacuum = dtor.material("Vacuum");
37 
38  DetElement sdet(det_name, det_id);
39  Assembly assembly(det_name + "_assembly");
40 
41  string module_name = "Crab_Cavity";
42 
43  string vis0 = dd4hep::getAttrOrDefault(x_det, _Unicode(vis), "BlueVis");
44 
45  sdet.setAttributes(dtor, assembly, x_det.regionStr(), x_det.limitsStr(), "OrangeVis");
46 
47  double shell_thickness = 10.0 * dd4hep::mm;
48  double cryostat_thickness = 20.0 * dd4hep::mm;
49 
50  // -- Cavity insides
51  Tube beampipe_vacuum(0.0, app_r, 1.2 * dim_r);
52  Tube cavity1(0.0, r1, 0.5*z1);
53  Tube cavity2(0.0, r2, 0.5*(z1 - z2));
54  UnionSolid cavity_vacuum1(beampipe_vacuum, cavity1, Transform3D( RotationX(0.5*M_PI) ));
55  SubtractionSolid cavity_vacuum2(cavity_vacuum1, cavity2, Transform3D( RotationX(0.5*M_PI) * Translation3D(0.0, 0.0, 0.5*z1) ));
56  SubtractionSolid cavity_vacuum3(cavity_vacuum2, cavity2, Transform3D( RotationX(-0.5*M_PI) * Translation3D(0.0, 0.0, 0.5*z1) ));
57 
58  Volume vacuum_vol("vacuum_vol", cavity_vacuum3, vacuum);
59  auto cavity_vacuum_pv = assembly.placeVolume(vacuum_vol);
60  DetElement cavity_vacuum_de(sdet, "vacuum_de", 1);
61  cavity_vacuum_de.setPlacement(cavity_vacuum_pv);
62  cavity_vacuum_de.setAttributes(dtor, vacuum_vol, x_det.regionStr(), x_det.limitsStr(), "GreenVis");
63 
64  // -- Cavity shell
65  Tube beampipe(0.0, app_r + 0.5*shell_thickness, 1.2 * dim_r);
66  Tube shell1(0.0, r1 + 0.5*shell_thickness, 0.5*(z1 + shell_thickness));
67  Tube shell2(0.0, r2 - 0.5*shell_thickness, 0.5*(z1 - z2 - shell_thickness));
68  UnionSolid cavity_shell1(beampipe, shell1, Transform3D( RotationX(0.5*M_PI) ));
69  SubtractionSolid cavity_shell2(cavity_shell1, shell2, Transform3D( RotationX(0.5*M_PI) * Translation3D(0.0, 0.0, 0.5*z1) ));
70  SubtractionSolid cavity_shell3(cavity_shell2, shell2, Transform3D( RotationX(-0.5*M_PI) * Translation3D(0.0, 0.0, 0.5*z1) ));
71  SubtractionSolid cavity_shell4(cavity_shell3, cavity_vacuum3);
72 
73  Volume shell_vol("shell_vol", cavity_shell4, niobium);
74  auto shell_pv = assembly.placeVolume(shell_vol);
75  DetElement shell_de(sdet, "shell_de", 2);
76  shell_de.setPlacement(shell_pv);
77  shell_de.setAttributes(dtor, shell_vol, x_det.regionStr(), x_det.limitsStr(), "RedVis");
78 
79  // -- LHe volume
80  Tube heliumfill1(0.0, dim_r - 0.5*cryostat_thickness, 0.5 * (dim_z - cryostat_thickness));
81  UnionSolid heliumfill2(Box(0.1*dim_r, 0.1*dim_r, 0.1*dim_z), heliumfill1, Transform3D( RotationX(0.5*M_PI) )); // A workaround for boolean shape of boolean shapes not working with tranforms.
82  SubtractionSolid heliumfill3(heliumfill2, cavity_shell3);
83 
84  Volume helium_vol1("heliumvol", heliumfill3, helium);
85  auto helium_pv = assembly.placeVolume(helium_vol1);
86  DetElement helium_de(sdet, "helium_de", 3);
87  helium_de.setPlacement(helium_pv);
88  helium_de.setAttributes(dtor, shell_vol, x_det.regionStr(), x_det.limitsStr(), "GrayVis");
89 
90  // -- Cryostat shell
91  Tube cryoshell1(0.0, dim_r, 0.5*dim_z);
92  UnionSolid cryoshell2(Box(0.1*dim_r, 0.1*dim_r, 0.1*dim_z), cryoshell1, Transform3D( RotationX(0.5*M_PI) ));
93  SubtractionSolid cryoshell3(cryoshell2, heliumfill2);
94  SubtractionSolid cryoshell4(cryoshell3, cavity_shell3);
95 
96  Volume cryo_vol("cryovol", cryoshell4, titanium);
97  auto cryo_pv = assembly.placeVolume(cryo_vol);
98  DetElement cryo_de(sdet, "cryo_de", 4);
99  cryo_de.setPlacement(cryo_pv);
100  cryo_de.setAttributes(dtor, cryo_vol, x_det.regionStr(), x_det.limitsStr(), "BlueVis");
101 
102  // -- finishing steps
103  auto final_pos = Transform3D(Translation3D(pos_x, pos_y, pos_z) * RotationY(pos_theta));
104  auto pv = dtor.pickMotherVolume(sdet).placeVolume(assembly, final_pos);
105  pv.addPhysVolID("system", det_id);
106  sdet.setPlacement(pv);
107 
108  assembly->GetShape()->ComputeBBox();
109  return sdet;
110 }
111 
112 DECLARE_DETELEMENT(CrabCavity, build_cavity)
static Ref_t build_cavity(Detector &dtor, xml_h e, SensitiveDetector sens)
Definition: crab_geo.cpp:14
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.