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;
123 double ref_angle = 0.0;
124 double ref_zpos = 1.0;
129 Volume motherVol = description.pickMotherVolume(endcap);
130 pv = motherVol.placeVolume(endcapVol,Transform3D(RotationZYX(M_PI/numsides,ref_angle,0),
131 Position(0,0,ref_zpos*z_pos)));
132 pv.addPhysVolID(
"system", det_id);
133 pv.addPhysVolID(
"barrel", 1);
134 endcap.setPlacement(pv);
135 Ref_t(endcap)->SetName(det_name.c_str());