17 #include "DD4hep/DetFactoryHelper.h"
18 #include "XML/Layering.h"
22 using namespace dd4hep::detail;
26 xml_dim_t dim = x_det.dimensions();
27 int det_id = x_det.id();
28 bool reflect = x_det.reflect(
true);
29 string det_name = x_det.nameStr();
30 Material air = description.air();
31 int numsides = dim.numsides();
32 double rmin = dim.rmin();
33 double rmax = dim.rmax()*std::cos(M_PI/numsides);
34 double zmin = dim.zmin();
35 Layering layering(x_det);
36 double totalThickness = layering.totalThickness();
37 Volume endcapVol(
"endcap",PolyhedraRegular(numsides,rmin,rmax,totalThickness),air);
38 DetElement endcap(
"endcap",det_id);
42 double layerZ = -totalThickness/2;
44 endcapVol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
46 for(xml_coll_t xc(x_det,_U(layer)); xc; ++xc) {
47 xml_comp_t x_layer = xc;
48 double l_thick = layering.layer(l_num-1)->thickness();
49 string l_name = _toString(layerType,
"layer%d");
50 int l_repeat = x_layer.repeat();
51 Volume l_vol(l_name,PolyhedraRegular(numsides,rmin,rmax,l_thick),air);
52 vector<PlacedVolume> sensitives;
55 double sliceZ = -l_thick/2;
56 for(xml_coll_t xs(x_layer,_U(slice)); xs; ++xs) {
57 xml_comp_t x_slice = xs;
58 string s_name = _toString(s_num,
"slice%d");
59 double s_thick = x_slice.thickness();
60 Material s_mat = description.material(x_slice.materialStr());
61 Volume s_vol(s_name,PolyhedraRegular(numsides,rmin,rmax,s_thick),s_mat);
63 s_vol.setVisAttributes(description.visAttributes(x_slice.visStr()));
65 PlacedVolume s_phv = l_vol.placeVolume(s_vol,Position(0,0,sliceZ));
66 s_phv.addPhysVolID(
"slice",s_num);
67 if ( x_slice.isSensitive() ) {
68 sens.setType(
"calorimeter");
69 s_vol.setSensitiveDetector(sens);
70 sensitives.push_back(s_phv);
75 l_vol.setVisAttributes(description.visAttributes(x_layer.visStr()));
76 if ( l_repeat <= 0 )
throw std::runtime_error(x_det.nameStr()+
"> Invalid repeat value");
77 for(
int j=0; j<l_repeat; ++j) {
78 string phys_lay = _toString(l_num,
"layer%d");
80 DetElement layer_elt(endcap, phys_lay, l_num);
81 PlacedVolume pv = endcapVol.placeVolume(l_vol,Position(0,0,layerZ));
82 pv.addPhysVolID(
"layer", l_num);
83 layer_elt.setPlacement(pv);
84 for(
size_t ic=0; ic<sensitives.size(); ++ic) {
85 PlacedVolume sens_pv = sensitives[ic];
86 DetElement comp_elt(layer_elt,sens_pv.volume().name(),l_num);
87 comp_elt.setPlacement(sens_pv);
95 double z_pos = zmin+totalThickness/2;
99 Assembly assembly(det_name);
100 DetElement both_endcaps(det_name,det_id);
101 Volume motherVol = description.pickMotherVolume(both_endcaps);
102 DetElement sdetA = endcap;
103 Ref_t(sdetA)->SetName((det_name+
"_A").c_str());
104 DetElement sdetB = endcap.clone(det_name+
"_B",x_det.id());
106 pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
107 Position(0,0,z_pos)));
108 pv.addPhysVolID(
"barrel", 1);
109 sdetA.setPlacement(pv);
111 pv = assembly.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,M_PI,0),
112 Position(0,0,-z_pos)));
113 pv.addPhysVolID(
"barrel", 2);
114 sdetB.setPlacement(pv);
116 pv = motherVol.placeVolume(assembly);
117 pv.addPhysVolID(
"system", det_id);
118 both_endcaps.setPlacement(pv);
119 both_endcaps.add(sdetA);
120 both_endcaps.add(sdetB);
123 Volume motherVol = description.pickMotherVolume(endcap);
124 pv = motherVol.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,0,0),
125 Position(0,0,z_pos)));
126 pv.addPhysVolID(
"system", det_id);
127 pv.addPhysVolID(
"barrel", 1);
128 endcap.setPlacement(pv);
129 Ref_t(endcap)->SetName(det_name.c_str());
134 DECLARE_DEPRECATED_DETELEMENT(PolyhedraEndcapCalorimeter2,
create_detector)