18 #include "DD4hep/DetFactoryHelper.h"
19 #include "DD4hep/Printout.h"
20 #include "XML/Layering.h"
27 xml_dim_t dim = x_det.dimensions();
28 Material air = lcdd.air();
29 string det_name = x_det.nameStr();
30 bool reflect = x_det.reflect();
31 double zmin = dim.inner_z();
32 double rmin = dim.inner_r();
33 double rmax = dim.outer_r();
34 double totWidth = Layering(x_det).totalThickness();
36 Tube envelope (rmin,rmax,totWidth/2);
37 Volume envelopeVol(det_name+
"_envelope",envelope,air);
42 for(xml_coll_t c(x_det,_U(layer)); c; ++c) {
43 xml_comp_t x_layer = c;
44 double layerWidth = 0;
45 for(xml_coll_t l(x_layer,_U(slice)); l; ++l)
46 layerWidth += xml_comp_t(l).thickness();
47 for(
int i=0, m=0, repeat=x_layer.repeat(); i<repeat; ++i) {
49 string layer_name = det_name + _toString(layer_num,
"_layer%d");
50 Volume layer_vol(layer_name,Tube(rmin,rmax,layerWidth),air);
52 for(xml_coll_t l(x_layer,_U(slice)); l; ++l, ++m) {
53 xml_comp_t x_slice = l;
54 double w = x_slice.thickness();
55 string slice_name = layer_name + _toString(m+1,
"slice%d");
56 Material slice_mat = lcdd.material(x_slice.materialStr());
57 Volume slice_vol (slice_name,Tube(rmin,rmax,w),slice_mat);
59 if ( x_slice.isSensitive() ) {
60 sens.setType(
"calorimeter");
61 slice_vol.setSensitiveDetector(sens);
63 slice_vol.setAttributes(lcdd,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
64 pv = layer_vol.placeVolume(slice_vol,Position(0,0,z-zlayer-layerWidth/2+w/2));
65 pv.addPhysVolID(
"slice",m+1);
68 layer_vol.setVisAttributes(lcdd,x_layer.visStr());
70 Position layer_pos(0,0,zlayer-zmin-totWidth/2+layerWidth/2);
71 pv = envelopeVol.placeVolume(layer_vol,layer_pos);
72 pv.addPhysVolID(
"layer",layer_num);
73 printout(DEBUG,
"Calo",
"CylindricalEndcapCalorimeter: built layer %d -> %s",layer_num,layer_name.c_str());
77 envelope.setDimensions(rmin,rmax,totWidth/2);
79 envelopeVol.setAttributes(lcdd,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
81 DetElement sdet(det_name,x_det.id());
82 Assembly assembly(det_name+
"_assembly");
83 Volume motherVol = lcdd.pickMotherVolume(sdet);
84 PlacedVolume phv = motherVol.placeVolume(assembly);
85 phv.addPhysVolID(
"system",sdet.id());
86 sdet.setPlacement(phv);
88 DetElement sdetA(sdet,det_name+(reflect ?
"_A" :
""),x_det.id());
89 phv = assembly.placeVolume(envelopeVol,Position(0,0,zmin+totWidth/2));
90 phv.addPhysVolID(
"barrel",1);
91 sdetA.setPlacement(phv);
94 phv=assembly.placeVolume(envelopeVol,Transform3D(RotationZ(M_PI),Position(0,0,-zmin-totWidth/2)));
95 phv.addPhysVolID(
"barrel",2);
97 DetElement sdetB(sdet,det_name+
"_B",x_det.id());
98 sdetB.setPlacement(phv);
103 DECLARE_DETELEMENT(DD4hep_CylindricalEndcapCalorimeter,
create_detector)