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