File indexing completed on 2025-01-30 09:17:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "DD4hep/Printout.h"
0018 #include "DD4hep/DD4hepUnits.h"
0019 #include "DD4hep/MatrixHelpers.h"
0020 #include "DD4hep/DetFactoryHelper.h"
0021
0022 using namespace std;
0023 using namespace dd4hep;
0024 using namespace dd4hep::detail;
0025
0026 static Ref_t create_element(Detector& description, xml_h e, Ref_t sens) {
0027 xml_det_t x_det (e);
0028 SensitiveDetector sd = sens;
0029 xml_dim_t x_pos = x_det.child(_U(position),false);
0030 xml_dim_t x_rot = x_det.child(_U(rotation),false);
0031 xml_dim_t x_refl = x_det.child(_U(reflect),false);
0032 string ref_nam = x_det.attr<string>(_U(sdref));
0033 DetElement ref_det = description.detector(ref_nam);
0034 auto refl = ref_det.reflect(x_det.nameStr(), x_det.id(), sd);
0035 Volume vol = refl.second;
0036 DetElement sdet = refl.first;
0037
0038 if ( !x_det.visStr().empty() )
0039 vol.setVisAttributes(description, x_det.visStr());
0040 if ( !x_det.limitsStr().empty() )
0041 vol.setLimitSet(description, x_det.limitsStr());
0042 if ( !x_det.regionStr().empty() )
0043 vol.setRegion(description, x_det.regionStr());
0044 if ( x_det.isSensitive() ) {
0045 xml_dim_t sd_typ = x_det.child(_U(sensitive));
0046 sd.setType(sd_typ.typeStr());
0047 }
0048 PlacedVolume pv;
0049 RotationZYX rot3D;
0050 Position tr3D;
0051 Transform3D transform3D;
0052 Volume mother = description.pickMotherVolume(sdet);
0053 if ( x_pos ) {
0054 tr3D = Position(x_pos.x(0),x_pos.y(0),x_pos.z(0));
0055 }
0056 if ( x_rot ) {
0057 rot3D = RotationZYX(x_rot.z(0),x_rot.y(0),x_rot.x(0));
0058 }
0059 if ( !x_pos && !x_rot ) {
0060 auto ref_pv = ref_det.placement();
0061 matrix::_decompose(ref_pv.matrix(), tr3D, rot3D);
0062 tr3D = tr3D * (-1.0 / dd4hep::mm);
0063 }
0064 char refl_type = 'Z';
0065 if ( x_refl.hasAttr(_U(type)) ) refl_type = ::toupper(x_refl.attr<string>(_U(type))[0]);
0066 if ( x_refl && refl_type == 'X' )
0067 transform3D = Transform3D(Rotation3D(-1., 0., 0., 0., 1., 0., 0., 0., 1.) * rot3D, tr3D);
0068 else if ( x_refl && refl_type == 'Y' )
0069 transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., -1., 0., 0., 0., 1.) * rot3D, tr3D);
0070 else if ( x_refl && refl_type == 'Z' )
0071 transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D, tr3D);
0072 else
0073 transform3D = Transform3D(Rotation3D( 1., 0., 0., 0., 1., 0., 0., 0., -1.) * rot3D, tr3D);
0074 pv = mother.placeVolume(vol, transform3D);
0075 printout(INFO,"ReflectedDet","Transform3D placement at pos: %f %f %f rot: %f %f %f",
0076 tr3D.X(),tr3D.Y(),tr3D.Z(), rot3D.Phi(),rot3D.Theta(),rot3D.Psi());
0077
0078 if ( x_det.hasAttr(_U(id)) ) {
0079 pv.addPhysVolID("system",x_det.id());
0080 }
0081 sdet.setPlacement(pv);
0082 return sdet;
0083 }
0084
0085 DECLARE_DETELEMENT(DD4hep_ReflectedDetector,create_element)