File indexing completed on 2025-01-18 09:15:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "DD4hep/DetFactoryHelper.h"
0016 #include "DD4hep/Printout.h"
0017 #include "TMath.h"
0018 #include <XML/Helper.h>
0019
0020 using namespace std;
0021 using namespace dd4hep;
0022
0023 static Ref_t create_detector(Detector& det, xml_h e, SensitiveDetector ) {
0024
0025 using namespace ROOT::Math;
0026 xml_det_t x_det = e;
0027 string det_name = x_det.nameStr();
0028 DetElement sdet(det_name, x_det.id());
0029 Assembly assembly(det_name + "_assembly");
0030 Material m_Al = det.material("Aluminum");
0031 Material m_Vacuum = det.material("Vacuum");
0032 string vis_name = dd4hep::getAttrOrDefault<std::string>(x_det, _Unicode(vis), "BeamPipeVis");
0033
0034 xml::Component Pipe_c = x_det.child(_Unicode(Pipe));
0035
0036
0037 double thickness = Pipe_c.attr<double>(_Unicode(wall_thickness));
0038 double innerD1 = Pipe_c.hasAttr(_Unicode(innerD1))
0039 ? Pipe_c.attr<double>(_Unicode(innerD1))
0040 : Pipe_c.attr<double>(_Unicode(outerD1)) - 2 * thickness;
0041 double innerD2 = Pipe_c.hasAttr(_Unicode(innerD2))
0042 ? Pipe_c.attr<double>(_Unicode(innerD2))
0043 : Pipe_c.attr<double>(_Unicode(outerD2)) - 2 * thickness;
0044
0045 double end1z = Pipe_c.attr<double>(_Unicode(end1z));
0046 double end2z = Pipe_c.attr<double>(_Unicode(end2z));
0047 double end1x = dd4hep::getAttrOrDefault<double>(Pipe_c, _Unicode(end1x), 0.0);
0048 double end2x = dd4hep::getAttrOrDefault<double>(Pipe_c, _Unicode(end2x), 0.0);
0049
0050 double length = sqrt((end1z - end2z) * (end1z - end2z) + (end1x - end2x) * (end1x - end2x));
0051 double yrot = atan((end1x - end2x) / (end1z - end2z));
0052
0053
0054
0055 ConeSegment tube_vacuum(length / 2.0, 0.0, innerD1 / 2.0, 0.0, innerD2 / 2.0);
0056 ConeSegment tube_tube(length / 2.0, innerD1 / 2.0, innerD1 / 2.0 + thickness, innerD2 / 2.0,
0057 innerD2 / 2.0 + thickness);
0058
0059 Volume v_vacuum("v_vacuum", tube_vacuum, m_Vacuum);
0060 Volume v_tube("v_tube", tube_tube, m_Al);
0061
0062 sdet.setAttributes(det, v_tube, x_det.regionStr(), x_det.limitsStr(), vis_name);
0063
0064 assembly.placeVolume(v_vacuum, Position(0, 0, -length / 2.0));
0065 assembly.placeVolume(v_tube, Position(0, 0, -length / 2.0));
0066
0067
0068
0069 auto pv_assembly = det.pickMotherVolume(sdet).placeVolume(
0070 assembly, Transform3D(RotationY(yrot), Position(end1x, 0.0, end1z)));
0071 pv_assembly.addPhysVolID("system", sdet.id()).addPhysVolID("barrel", 1);
0072 sdet.setPlacement(pv_assembly);
0073 assembly->GetShape()->ComputeBBox();
0074 return sdet;
0075 }
0076
0077 DECLARE_DETELEMENT(BackwardsBeamPipe, create_detector)