File indexing completed on 2025-01-18 09:15:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "DD4hep/DetFactoryHelper.h"
0011 #include "DD4hep/Printout.h"
0012 #include "TMath.h"
0013 #include <XML/Helper.h>
0014
0015 using namespace std;
0016 using namespace dd4hep;
0017
0018 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
0019
0020 using namespace ROOT::Math;
0021 xml_det_t x_det = e;
0022 string det_name = x_det.nameStr();
0023 int det_id = x_det.id();
0024 Material m_Vacuum = description.material("Vacuum");
0025 string vis_name = dd4hep::getAttrOrDefault<std::string>(x_det, _Unicode(vis), "BeamPipeVis");
0026
0027 sens.setType("tracker");
0028
0029 DetElement sdet(det_name, det_id);
0030 Assembly assembly(det_name + "_assembly");
0031
0032
0033 for (xml_coll_t slice_coll(x_det, _Unicode(slice)); slice_coll; slice_coll++) {
0034
0035 string grandmotherName = slice_coll.attr<string>(_Unicode(grandmother));
0036 string motherName = slice_coll.attr<string>(_Unicode(mother));
0037 bool detStart = getAttrOrDefault<bool>(slice_coll, _Unicode(end), true);
0038 int pipe_id = getAttrOrDefault<int>(slice_coll, _Unicode(pipe_id), 0);
0039 string slice_name = slice_coll.attr<string>(_Unicode(name));
0040 DetElement mother = description.detector(grandmotherName).child(motherName);
0041
0042
0043 Volume mother_vol = mother.volume();
0044
0045
0046 ConeSegment mother_shape = mother_vol.solid();
0047
0048
0049 double rOuter1 = mother_shape.rMax1();
0050 double rOuter2 = mother_shape.rMax2();
0051 double length = 2 * mother_shape.dZ();
0052
0053 double sensitive_thickness = 0.1 * mm;
0054
0055
0056
0057 double rEnd = rOuter2 - (rOuter2 - rOuter1) * sensitive_thickness / length;
0058 double zPos = length / 2.0 - sensitive_thickness / 2.0;
0059 if (detStart) {
0060 rEnd = rOuter1 - (rOuter1 - rOuter2) * sensitive_thickness / length;
0061 zPos = -length / 2.0 + sensitive_thickness / 2.0;
0062 }
0063
0064 ConeSegment s_start_disk(sensitive_thickness / 2, 0.0, rOuter2, 0.0, rEnd);
0065 Volume v_start_disk("v_start_disk_" + motherName, s_start_disk, m_Vacuum);
0066 v_start_disk.setSensitiveDetector(sens);
0067
0068 auto disk_placement = mother_vol.placeVolume(v_start_disk, Position(0.0, 0.0, zPos));
0069 disk_placement.addPhysVolID("end", detStart);
0070 disk_placement.addPhysVolID("pipe", pipe_id);
0071 disk_placement.addPhysVolID("system", det_id);
0072
0073 DetElement slice_element(sdet, slice_name, pipe_id);
0074
0075 slice_element.setPlacement(disk_placement);
0076 description.declareParent(slice_name, mother);
0077 }
0078
0079 auto pv_assembly = description.worldVolume().placeVolume(assembly, Position(0.0, 0.0, 0.0));
0080 pv_assembly.addPhysVolID("system", det_id);
0081 sdet.setPlacement(pv_assembly);
0082
0083 return sdet;
0084 }
0085
0086 DECLARE_DETELEMENT(BeamPipeTracking, create_detector)