File indexing completed on 2024-11-15 08:59:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "DD4hep/DetFactoryHelper.h"
0018
0019 using namespace std;
0020 using namespace dd4hep;
0021 using namespace dd4hep::detail;
0022
0023 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
0024 xml_det_t x_det = e;
0025 string det_name = x_det.nameStr();
0026 Material air = description.air();
0027 DetElement sdet (det_name,x_det.id());
0028 Assembly assembly (det_name+"_assembly");
0029 PlacedVolume pv;
0030 int n = 0;
0031 xml::Component pos = x_det.position();
0032
0033 for(xml_coll_t i(x_det,_U(layer)); i; ++i, ++n) {
0034 xml_comp_t x_layer = i;
0035 string l_name = det_name+_toString(n,"_layer%d");
0036 double outer_z = x_layer.outer_z();
0037 double rmin = x_layer.inner_r();
0038 double r = rmin;
0039 DetElement layer(sdet,_toString(n,"layer%d"),x_layer.id());
0040 Tube l_tub (rmin,2*rmin,outer_z);
0041 Volume l_vol(l_name,l_tub,air);
0042 int im = 0;
0043
0044 for(xml_coll_t j(x_layer,_U(slice)); j; ++j, ++im) {
0045
0046
0047 xml_comp_t x_slice = j;
0048 Material mat = description.material(x_slice.materialStr());
0049 string s_name= l_name+_toString(im,"_slice%d");
0050 double thickness = x_slice.thickness();
0051 double s_outer_z = dd4hep::getAttrOrDefault(x_slice, _Unicode(outer_z), outer_z);
0052 double s_inner_z = dd4hep::getAttrOrDefault(x_slice, _Unicode(inner_z), 0.0*dd4hep::cm);
0053 Tube s_tub(r,r+thickness,(s_inner_z > 0? 0.5*(s_outer_z-s_inner_z): s_outer_z),2*M_PI);
0054 Volume s_vol(s_name, s_tub, mat);
0055
0056 if ( x_slice.isSensitive() ) {
0057 sens.setType("tracker");
0058 s_vol.setSensitiveDetector(sens);
0059 }
0060
0061 s_vol.setAttributes(description,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
0062 if (s_inner_z > 0) {
0063
0064 Position s_pos(0, 0, 0.5*(s_outer_z+s_inner_z));
0065 pv = l_vol.placeVolume(s_vol, -s_pos);
0066 pv = l_vol.placeVolume(s_vol, +s_pos);
0067 } else {
0068 r += thickness;
0069 pv = l_vol.placeVolume(s_vol);
0070 }
0071
0072 pv.addPhysVolID("slice",im);
0073 }
0074 l_tub.setDimensions(rmin,r,outer_z);
0075
0076 l_vol.setVisAttributes(description,x_layer.visStr());
0077
0078 pv = assembly.placeVolume(l_vol);
0079 pv.addPhysVolID("layer",n);
0080 layer.setPlacement(pv);
0081 }
0082 if ( x_det.hasAttr(_U(combineHits)) ) {
0083 sdet.setCombineHits(x_det.combineHits(),sens);
0084 }
0085
0086 pv = description.pickMotherVolume(sdet).placeVolume(assembly,Position(pos.x(),pos.y(),pos.z()));
0087 pv.addPhysVolID("system",sdet.id()).addPhysVolID("barrel",0);
0088 sdet.setPlacement(pv);
0089 return sdet;
0090 }
0091
0092 DECLARE_DETELEMENT(athena_SolenoidCoil,create_detector)