SimpleRomanPot_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 
8 using namespace std;
9 using namespace dd4hep;
10 using namespace dd4hep::rec;
11 
12 static Ref_t build_detector(Detector& dtor, xml_h e, SensitiveDetector sens)
13 {
14  xml_det_t x_det = e;
15  Material air = dtor.air();
16  Material carbon = dtor.material("CarbonFiber");
17  Material silicon = dtor.material("SiliconOxide");
18  Material aluminum = dtor.material("Aluminum");
19  Material vacuum = dtor.material("Vacuum");
20  Material supp_mat = carbon;
21  Material sens_mat = silicon;
22 
23  int det_id = x_det.id();
24  string det_name = x_det.nameStr();
25  PlacedVolume pv;
26 
27  DetElement sdet( det_name, det_id);
28  Assembly assembly(det_name + "_assembly");
29 
30  sens.setType("tracker");
31  string module_name = "RomanPot";
32 
33  //sdet.setAttributes(dtor, assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
34  //assembly.setVisAttributes(dtor.invisible());
35 
36  std::string vis0 = dd4hep::getAttrOrDefault(x_det, _Unicode(vis), "BlueVis");
37 
38  double z_offset = dd4hep::getAttrOrDefault(x_det, _Unicode(zoffset), 0.0);
39  //double z_offset = (x_det.hasAttr(_Unicode(zoffset))) ? x_det.attr<double>(_Unicode(zoffset)) : 0.0;
40  double thickness = (x_det.hasAttr(_Unicode(thickness))) ? x_det.attr<double>(_Unicode(thickness)) : 0.01*dd4hep::cm;
41 
42  double rp_chamber_thickness = 5.0*dd4hep::mm;
43  double rp_chamber_radius = 5.0*dd4hep::cm;
44  double rp_chamber_length = 50.0*dd4hep::cm;
45  Tube rp_beam_pipe_tube(rp_chamber_radius, rp_chamber_radius+rp_chamber_thickness, rp_chamber_length/2.0);
46  Tube rp_beam_vacuum_tube(0.0, rp_chamber_radius+rp_chamber_thickness, rp_chamber_length/2.0);
47  Tube rp_beam_vacuum_tube2(0.0, rp_chamber_radius, rp_chamber_length/2.0);
48 
49  double rp_detector_tube_radius = 2.5*dd4hep::cm;
50  double rp_detector_tube_length = 20.0*dd4hep::cm;
51  Tube rp_detector_tube(rp_detector_tube_radius, rp_detector_tube_radius+rp_chamber_thickness, rp_detector_tube_length/2.0);
52  Tube rp_detector_vacuum_tube(0.0, rp_detector_tube_radius+rp_chamber_thickness, rp_detector_tube_length/2.0);
53  Tube rp_detector_vacuum_tube2(0.0, rp_detector_tube_radius, rp_detector_tube_length/2.0);
54 
55  //ROOT::Math::RotationX rX(M_PI);
56  ROOT::Math::Rotation3D rot_X( ROOT::Math::RotationX(M_PI/2.0) );
57  ROOT::Math::Rotation3D rot_Y( ROOT::Math::RotationY(M_PI/2.0) );
58 
59  UnionSolid rp_chamber_tee1(rp_beam_vacuum_tube, rp_detector_vacuum_tube, rot_X);
60  UnionSolid rp_chamber_tee12(rp_chamber_tee1, rp_detector_vacuum_tube, rot_Y);
61 
62  UnionSolid rp_chamber_tee2(rp_beam_vacuum_tube2, rp_detector_vacuum_tube2, rot_X);
63  UnionSolid rp_chamber_tee22(rp_chamber_tee2, rp_detector_vacuum_tube2, rot_Y);
64 
65  SubtractionSolid sub1(rp_chamber_tee12,rp_chamber_tee22);
66  Volume rp_chamber_vol("rp_chamber_walls_vol", sub1, aluminum);
67 
68  Volume rp_vacuum_vol("rp_chamber_vacuum_vol", rp_chamber_tee22, vacuum);
69 
70  pv = assembly.placeVolume( rp_chamber_vol );//, Transform3D(RotationZ(phi0_offset),Position(0.0,0.0,z)) );
71 
72  auto vacuum_pv = assembly.placeVolume( rp_vacuum_vol );//, Transform3D(RotationZ(phi0_offset),Position(0.0,0.0,z)) );
73  vacuum_pv.addPhysVolID( "element", 1 );
74 
75  rp_chamber_vol.setVisAttributes(vis0.c_str());
76  rp_vacuum_vol.setVisAttributes(dtor.invisible());
77  //chamber_DE.setAttributes(dtor, rp_vacuum_vol, "", "", "BlueVis");
78  //chamber_DE.setAttributes(dtor, layer_assembly, "", "", "SiVertexLayerVis");
79 
80  double supp_x_half = 1.0*dd4hep::cm;
81  double supp_y_half = 1.0*dd4hep::cm;
82  double supp_thickness = 1.0*dd4hep::mm;
83  double supp_gap_half_width = 1.0*dd4hep::mm;
84  double sens_thickness = 0.1*dd4hep::mm;
85 
86  Box supp_box( supp_x_half, supp_y_half, supp_thickness/2.0 );
87  Box sens_box( supp_x_half-supp_gap_half_width, supp_y_half-supp_gap_half_width, sens_thickness/2.0 );
88 
89  // create a measurement plane for the tracking surface attched to the sensitive volume
90  Vector3D u( 1. , 0. , 0. ) ;
91  Vector3D v( 0. , 1. , 0. ) ;
92  Vector3D n( 0. , 0. , 1. ) ;
93  //Vector3D o( 0. , 0. , 0. ) ;
94 
95  // compute the inner and outer thicknesses that need to be assigned to the tracking surface
96  // depending on wether the support is above or below the sensor
97  // The tracking surface is used in reconstruction. It provides material thickness
98  // and radation lengths needed for various algorithms, routines, etc.
99  double inner_thickness = supp_thickness/2.0;
100  double outer_thickness = supp_thickness/2.0;
101 
102  double z_shift = 5.0*dd4hep::mm;
103  double xy_shift = 15.0*dd4hep::mm;
104 
105  SurfaceType type( SurfaceType::Sensitive ) ;
106 
107  // --- x1 ---
108  Volume support1_vol( "xsenseor_supp", supp_box, supp_mat );
109  Volume sensor1_vol( "xsenseor_sens", sens_box, sens_mat );
110  VolPlane surf1( sensor1_vol, type, inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;
111  sensor1_vol.setSensitiveDetector(sens);
112 
113  DetElement layer1_DE( sdet, "layer1_DE", 1 );
114  pv = rp_vacuum_vol.placeVolume( support1_vol, Position(xy_shift,0, -z_shift) );
115  pv.addPhysVolID("layer", 1 );
116  layer1_DE.setPlacement( pv ) ;
117 
118  DetElement mod1( layer1_DE , "module_1", 1 );
119  pv = support1_vol.placeVolume(sensor1_vol, Position(0,0,0));
120  pv.addPhysVolID("module", 1 );
121  mod1.setPlacement( pv );
122 
123  // ------------- x2
124  Volume support2_vol( "xsenseor_supp", supp_box, supp_mat );
125  Volume sensor2_vol( "xsenseor_sens", sens_box, sens_mat );
126  VolPlane surf2( sensor2_vol, type, inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;
127  sensor2_vol.setSensitiveDetector(sens);
128 
129  DetElement layer2_DE( sdet, "layer2_DE", 2 );
130  pv = rp_vacuum_vol.placeVolume( support2_vol, Position(-xy_shift,0, -z_shift) );
131  pv.addPhysVolID("layer", 2 );
132  layer2_DE.setPlacement( pv ) ;
133 
134  DetElement mod2( layer2_DE , "module_2", 2 );
135  pv = support2_vol.placeVolume(sensor2_vol, Position(0,0,0));
136  pv.addPhysVolID("module", 2 );
137  mod2.setPlacement( pv );
138 
139  // -------------x3
140  Volume support3_vol( "xsenseor_supp", supp_box, supp_mat );
141  Volume sensor3_vol( "xsenseor_sens", sens_box, sens_mat );
142  VolPlane surf3( sensor3_vol, type, inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;
143  sensor3_vol.setSensitiveDetector(sens);
144 
145  DetElement layer3_DE( sdet, "layer3_DE", 3 );
146  pv = rp_vacuum_vol.placeVolume( support3_vol, Position(0,xy_shift, z_shift) );
147  pv.addPhysVolID("layer", 3 );
148  layer3_DE.setPlacement( pv ) ;
149 
150  DetElement mod3( layer3_DE , "module_3", 3 );
151  pv = support3_vol.placeVolume(sensor3_vol, Position(0,0,0));
152  pv.addPhysVolID("module", 3 );
153  mod3.setPlacement( pv );
154 
155  // -------------x4
156  Volume support4_vol( "xsenseor_supp", supp_box, supp_mat );
157  Volume sensor4_vol( "xsenseor_sens", sens_box, sens_mat );
158  VolPlane surf4( sensor4_vol, type, inner_thickness , outer_thickness , u,v,n ) ; //,o ) ;
159  sensor4_vol.setSensitiveDetector(sens);
160 
161  DetElement layer4_DE( sdet, "layer4_DE", 4 );
162  pv = rp_vacuum_vol.placeVolume( support4_vol, Position(0,-xy_shift, z_shift) );
163  pv.addPhysVolID("layer", 4 );
164  layer4_DE.setPlacement( pv ) ;
165 
166  DetElement mod4( layer4_DE , "module_4", 4 );
167  pv = support4_vol.placeVolume(sensor4_vol, Position(0,0,0));
168  pv.addPhysVolID("module", 4 );
169  mod4.setPlacement( pv );
170 
171  //sdet.setAttributes(dtor, assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
172  //assembly.setVisAttributes(dtor.invisible());
173 
174  pv = dtor.pickMotherVolume(sdet).placeVolume(assembly, Position(0,0,z_offset));
175  pv.addPhysVolID("system", det_id); // Set the subdetector system ID.
176  sdet.setPlacement(pv);
177 
178  assembly->GetShape()->ComputeBBox() ;
179  return sdet;
180 }
181 
182 DECLARE_DETELEMENT(SimpleRomanPot, build_detector)
static Ref_t build_detector(Detector &dtor, xml_h e, SensitiveDetector sens)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.