File indexing completed on 2025-04-03 08:03:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <DD4hep/DetFactoryHelper.h>
0015 #include <DD4hep/Printout.h>
0016
0017
0018 #include <iomanip>
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 constexpr double tol = 1e-4;
0026 xml_det_t x_det = e;
0027
0028
0029 int det_id = x_det.id();
0030 string det_name = x_det.nameStr();
0031 DetElement sdet(det_name, det_id);
0032
0033
0034
0035 xml_comp_t x_dim = x_det.dimensions();
0036 double cyl_rmin = x_dim.rmin();
0037 double cyl_rmax = x_dim.rmax();
0038 double cyl_dz = x_dim.dz();
0039 double layer_cnt = x_dim.layers();
0040
0041 xml_comp_t x_wire = x_det.child(_Unicode(wire));
0042 size_t wire_cnt = x_wire.count();
0043 double wire_thick = x_wire.thickness();
0044
0045 double layer_thickness = (cyl_rmax - cyl_rmin)/double(layer_cnt+1);
0046 double delta_phi = 2.0 * M_PI / double(wire_cnt);
0047 double phi_start = 0e0;
0048
0049 Solid sdet_cyl = Tube(cyl_rmin-tol,cyl_rmax+tol,cyl_dz+tol);
0050 Volume sdet_vol(det_name+"_vol", sdet_cyl, description.air());
0051
0052 Material wire_mat(description.material(x_wire.materialStr()));
0053 Tube wire_cyl(0e0, wire_thick, cyl_dz-1.0*dd4hep::cm);
0054 Volume wire_vol("Wire_vol", wire_cyl, wire_mat);
0055 PlacedVolume pv;
0056
0057
0058 if ( x_dim.hasAttr(_U(option)) ) {
0059 int value = x_dim.attr<int>(_U(option));
0060 printout(ALWAYS, "DriftChamber", "+++ Setting smartlessValue to %d for %s",
0061 value, sdet_vol.name());
0062 sdet_vol.setSmartlessValue(value);
0063 }
0064
0065 sdet_vol.setAttributes(description, x_det.regionStr(), x_det.limitsStr(), x_det.visStr());
0066 wire_vol.setVisAttributes(description.visAttributes(x_wire.visStr()));
0067
0068 for( std::size_t l=0; l<layer_cnt; ++l ) {
0069 double radius = cyl_rmin + (0.5+double(l)) * layer_thickness;
0070 double phi_s = phi_start + delta_phi * 0.5 * ((l%2) - 1.0);
0071 for( std::size_t i=0; i<wire_cnt; ++i ) {
0072 double rho = phi_s + delta_phi * i;
0073 double x = std::cos(rho) * radius;
0074 double y = std::sin(rho) * radius;
0075
0076 wire_vol.setSensitiveDetector(sens);
0077 pv = sdet_vol.placeVolume(wire_vol, Position(x, y, 0e0));
0078 pv.addPhysVolID("layer", l);
0079 pv.addPhysVolID("phi", i);
0080 }
0081 }
0082
0083 Volume motherVol = description.pickMotherVolume(sdet);
0084 pv = motherVol.placeVolume(sdet_vol, Position(0e0, 0e0, 0e0));
0085 pv.addPhysVolID("system", det_id);
0086 sdet.setPlacement(pv);
0087 return sdet;
0088 }
0089
0090 DECLARE_DETELEMENT(DD4hep_DriftChamber,create_detector)