File indexing completed on 2025-01-30 09:17:07
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
0032 for(xml_coll_t i(x_det,_U(layer)); i; ++i, ++n) {
0033 xml_comp_t x_layer = i;
0034 string l_name = det_name+_toString(n,"_layer%d");
0035 double z = x_layer.outer_z();
0036 double rmin = x_layer.inner_r();
0037 double r = rmin;
0038 DetElement layer(sdet,_toString(n,"layer%d"),x_layer.id());
0039 Tube l_tub (rmin,2*rmin,z);
0040 Volume l_vol(l_name,l_tub,air);
0041 int im = 0;
0042
0043 for(xml_coll_t j(x_layer,_U(slice)); j; ++j, ++im) {
0044 xml_comp_t x_slice = j;
0045 Material mat = description.material(x_slice.materialStr());
0046 string s_name= l_name+_toString(im,"_slice%d");
0047 double thickness = x_slice.thickness();
0048 Tube s_tub(r,r+thickness,z,2*M_PI);
0049 Volume s_vol(s_name, s_tub, mat);
0050
0051 r += thickness;
0052 if ( x_slice.isSensitive() ) {
0053 sens.setType("tracker");
0054 s_vol.setSensitiveDetector(sens);
0055 }
0056
0057 s_vol.setAttributes(description,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
0058 pv = l_vol.placeVolume(s_vol);
0059
0060 pv.addPhysVolID("slice",im);
0061 }
0062 l_tub.setDimensions(rmin,r,z);
0063
0064 l_vol.setVisAttributes(description,x_layer.visStr());
0065
0066 pv = assembly.placeVolume(l_vol);
0067 pv.addPhysVolID("layer",n);
0068 layer.setPlacement(pv);
0069 }
0070 if ( x_det.hasAttr(_U(combineHits)) ) {
0071 sdet.setCombineHits(x_det.combineHits(),sens);
0072 }
0073
0074 pv = description.pickMotherVolume(sdet).placeVolume(assembly);
0075 pv.addPhysVolID("system",sdet.id()).addPhysVolID("barrel",0);
0076 sdet.setPlacement(pv);
0077 return sdet;
0078 }
0079
0080 DECLARE_DETELEMENT(DD4hep_MultiLayerTracker,create_detector)
0081