File indexing completed on 2025-01-18 09:14:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "DD4hep/DetFactoryHelper.h"
0020 #include <map>
0021
0022 using namespace std;
0023 using namespace dd4hep;
0024 using namespace dd4hep::detail;
0025
0026 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
0027 typedef vector<PlacedVolume> Placements;
0028 xml_det_t x_det = e;
0029 Material vacuum = description.vacuum();
0030 int det_id = x_det.id();
0031 string det_name = x_det.nameStr();
0032 bool reflect = x_det.reflect(false);
0033 DetElement sdet (det_name,det_id);
0034 Assembly assembly (det_name);
0035
0036 Volume motherVol = description.pickMotherVolume(sdet);
0037 int m_id=0, c_id=0, n_sensor=0;
0038 map<string,Volume> modules;
0039 map<string, Placements> sensitives;
0040 PlacedVolume pv;
0041
0042 assembly.setVisAttributes(description.invisible());
0043 sens.setType("tracker");
0044
0045 for(xml_coll_t mi(x_det,_U(module)); mi; ++mi, ++m_id) {
0046 xml_comp_t x_mod = mi;
0047 string m_nam = x_mod.nameStr();
0048 xml_comp_t trd = x_mod.trd();
0049 double posY;
0050 double x1 = trd.x1();
0051 double x2 = trd.x2();
0052 double z = trd.z();
0053 double y1, y2, total_thickness=0.;
0054 xml_coll_t ci(x_mod,_U(module_component));
0055 for(ci.reset(), total_thickness=0.0; ci; ++ci)
0056 total_thickness += xml_comp_t(ci).thickness();
0057
0058 y1 = y2 = total_thickness / 2;
0059 Volume m_volume(m_nam, Trapezoid(x1, x2, y1, y2, z), vacuum);
0060 m_volume.setVisAttributes(description.visAttributes(x_mod.visStr()));
0061
0062 for(ci.reset(), n_sensor=1, c_id=0, posY=-y1; ci; ++ci, ++c_id) {
0063 xml_comp_t c = ci;
0064 double c_thick = c.thickness();
0065 Material c_mat = description.material(c.materialStr());
0066 string c_name = _toString(c_id,"component%d");
0067 Volume c_vol(c_name, Trapezoid(x1,x2,c_thick/2e0,c_thick/2e0,z), c_mat);
0068
0069 c_vol.setVisAttributes(description.visAttributes(c.visStr()));
0070 pv = m_volume.placeVolume(c_vol,Position(0,posY+c_thick/2,0));
0071 if ( c.isSensitive() ) {
0072 sdet.check(n_sensor > 2,"SiTrackerEndcap2::fromCompact: "+c_name+" Max of 2 modules allowed!");
0073 pv.addPhysVolID("sensor",n_sensor);
0074 c_vol.setSensitiveDetector(sens);
0075 sensitives[m_nam].push_back(pv);
0076 ++n_sensor;
0077 }
0078 posY += c_thick;
0079 }
0080 modules[m_nam] = m_volume;
0081 }
0082
0083 for(xml_coll_t li(x_det,_U(layer)); li; ++li) {
0084 xml_comp_t x_layer(li);
0085 int l_id = x_layer.id();
0086 int mod_num = 1;
0087 for(xml_coll_t ri(x_layer,_U(ring)); ri; ++ri) {
0088 xml_comp_t x_ring = ri;
0089 double r = x_ring.r();
0090 double phi0 = x_ring.phi0(0);
0091 double zstart = x_ring.zstart();
0092 double dz = x_ring.dz(0);
0093 int nmodules = x_ring.nmodules();
0094 string m_nam = x_ring.moduleStr();
0095 Volume m_vol = modules[m_nam];
0096 double iphi = 2*M_PI/nmodules;
0097 double phi = phi0;
0098 Placements& sensVols = sensitives[m_nam];
0099
0100 for(int k=0; k<nmodules; ++k) {
0101 string m_base = _toString(l_id,"layer%d") + _toString(mod_num,"_module%d");
0102 double x = -r*std::cos(phi);
0103 double y = -r*std::sin(phi);
0104 if ( zstart >= 0 ) {
0105 DetElement module(sdet,m_base+"_pos",det_id);
0106 pv = assembly.placeVolume(m_vol,Transform3D(RotationZYX(0,-M_PI/2-phi,-M_PI/2),Position(x,y,zstart+dz)));
0107 pv.addPhysVolID("barrel",1).addPhysVolID("layer", l_id).addPhysVolID("module",mod_num);
0108 module.setPlacement(pv);
0109 for(size_t ic=0; ic<sensVols.size(); ++ic) {
0110 PlacedVolume sens_pv = sensVols[ic];
0111 DetElement comp_elt(module,sens_pv.volume().name(),mod_num);
0112 comp_elt.setPlacement(sens_pv);
0113 }
0114
0115 if ( reflect ) {
0116 pv = assembly.placeVolume(m_vol,Transform3D(RotationZYX(M_PI,-M_PI/2-phi,-M_PI/2),Position(x,y,-zstart-dz)));
0117 pv.addPhysVolID("barrel",2).addPhysVolID("layer",l_id).addPhysVolID("module",mod_num);
0118 DetElement r_module(sdet,m_base+"_neg",det_id);
0119 r_module.setPlacement(pv);
0120 for(size_t ic=0; ic<sensVols.size(); ++ic) {
0121 PlacedVolume sens_pv = sensVols[ic];
0122 DetElement comp_elt(r_module,sens_pv.volume().name(),mod_num);
0123 comp_elt.setPlacement(sens_pv);
0124 }
0125 }
0126 } else
0127 {
0128 pv = assembly.placeVolume(m_vol,Transform3D(RotationZYX(0,-M_PI/2-phi,-M_PI/2),Position(x,y,zstart-dz)));
0129 pv.addPhysVolID("barrel",3).addPhysVolID("layer", l_id).addPhysVolID("module",mod_num);
0130 DetElement r_module(sdet,m_base+"_neg-z",det_id);
0131 r_module.setPlacement(pv);
0132 for(size_t ic=0; ic<sensVols.size(); ++ic) {
0133 PlacedVolume sens_pv = sensVols[ic];
0134 DetElement comp_elt(r_module,sens_pv.volume().name(),mod_num);
0135 comp_elt.setPlacement(sens_pv);
0136 }
0137 }
0138 dz = -dz;
0139 phi += iphi;
0140 ++mod_num;
0141 }
0142 }
0143 }
0144 pv = motherVol.placeVolume(assembly);
0145 pv.addPhysVolID("system",det_id);
0146 sdet.setPlacement(pv);
0147 return sdet;
0148 }
0149
0150 DECLARE_DETELEMENT(Lhe_SiTrackerEndcap2,create_detector)