File indexing completed on 2025-01-18 09:14:41
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "DD4hep/Printout.h"
0016 #include "DD4hep/DetFactoryHelper.h"
0017
0018 using namespace dd4hep;
0019 using namespace dd4hep::detail;
0020
0021 namespace {
0022 Transform3D get_trafo(xml_dim_t elt) {
0023 xml_dim_t x_pos = elt.position();
0024 xml_dim_t x_rot = elt.rotation();
0025 return Transform3D(RotationZYX(x_rot.x(), x_rot.y(), x_rot.z()),
0026 Position(x_pos.x(), x_pos.y(), x_pos.z()));
0027 }
0028 }
0029
0030 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
0031
0032 xml_dim_t x_det = e;
0033
0034 DetElement det(x_det.nameStr(),x_det.id());
0035
0036
0037 xml_dim_t x_box(x_det.child(_U(box)));
0038 Volume envelope_vol(x_det.nameStr()+"_envelope",
0039 Box(x_box.x(), x_box.y(), x_box.z()),
0040 description.material(x_box.attr<std::string>(_U(material))));
0041
0042
0043 envelope_vol.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0044
0045 xml_comp_t x_param = x_det.child(_U(param));
0046 Box box (x_param.x(), x_param.y(), x_param.z());
0047 Volume box_vol (x_det.nameStr()+"_param", box, description.material(x_param.materialStr()));
0048 PlacedVolume pv;
0049
0050 if ( x_param.hasChild(_U(replicate)) ) {
0051 xml_dim_t x_repl = x_param.child(_U(replicate));
0052 std::string ax = x_repl.attr<std::string>(_U(axis));
0053 Volume::ReplicationAxis axis = Volume::Undefined;
0054 ax[0] = ::toupper(ax[0]);
0055 if ( ax[0] == 'X' ) axis = Volume::X_axis;
0056 if ( ax[0] == 'Y' ) axis = Volume::Y_axis;
0057 if ( ax[0] == 'Z' ) axis = Volume::Z_axis;
0058 if ( ax[0] == 'R' ) axis = Volume::Rho_axis;
0059 if ( ax[0] == 'P' ) axis = Volume::Phi_axis;
0060 pv = envelope_vol.replicate(box_vol, axis,
0061 x_repl.count(),
0062 x_repl.distance(),
0063 x_repl.start());
0064 printout(INFO,"ReplicateVolume","Axis: %s Count: %d offset:%f width:%f",
0065 ax.c_str(), x_repl.count(), x_repl.start(), x_repl.distance());
0066 }
0067 else if ( x_param.hasChild(_U(transformation)) ) {
0068 xml_dim_t x_dim_x, x_dim_y, x_dim_z, x_trafo = x_param.transformation();
0069 Transform3D start, trafo1, trafo2, trafo3;
0070
0071 if ( x_param.hasChild(_U(start)) ) {
0072 start = get_trafo(x_param.child(_U(start)));
0073 }
0074 if ( x_trafo.hasChild(_U(dim_x)) ) {
0075 x_dim_x = x_trafo.child(_U(dim_x));
0076 trafo1 = get_trafo(x_dim_x);
0077 }
0078 if ( x_trafo.hasChild(_U(dim_y)) ) {
0079 x_dim_y = x_trafo.child(_U(dim_y));
0080 trafo2 = get_trafo(x_dim_y);
0081 }
0082 if ( x_trafo.hasChild(_U(dim_z)) ) {
0083 x_dim_z = x_trafo.child(_U(dim_z));
0084 trafo3 = get_trafo(x_dim_z);
0085 }
0086
0087 if ( x_trafo.hasChild(_U(dim_y)) && x_trafo.hasChild(_U(dim_z)) ) {
0088 pv = envelope_vol.paramVolume3D(start, box_vol,
0089 x_dim_x.repeat(), trafo1,
0090 x_dim_y.repeat(), trafo2,
0091 x_dim_z.repeat(), trafo3);
0092 }
0093 else if ( x_trafo.hasChild(_U(dim_y)) ) {
0094 pv = envelope_vol.paramVolume2D(start, box_vol,
0095 x_dim_x.repeat(), trafo1,
0096 x_dim_y.repeat(), trafo2);
0097 }
0098 else {
0099 pv = envelope_vol.paramVolume1D(start, box_vol, x_dim_x.repeat(), trafo1);
0100 }
0101 }
0102 if ( sens.isValid() ) {
0103 sens.setType("calorimeter");
0104 pv.addPhysVolID("volume", 0);
0105 }
0106 box_vol.setSensitiveDetector(sens);
0107 box_vol.setAttributes(description,x_param.regionStr(),x_param.limitsStr(),x_param.visStr());
0108
0109 det.setAttributes(description,envelope_vol,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
0110
0111
0112 xml_dim_t x_pos = x_det.position();
0113 xml_dim_t x_rot = x_det.rotation();
0114 auto mother = description.pickMotherVolume(det);
0115 Transform3D tr(RotationZYX(x_rot.x(), x_rot.y(), x_rot.z()),
0116 Position(x_pos.x(), x_pos.y(), x_pos.z()));
0117 PlacedVolume envelope_plv = mother.placeVolume(envelope_vol, tr);
0118 envelope_plv.addPhysVolID("system",x_det.id());
0119 det.setPlacement(envelope_plv);
0120 return det;
0121 }
0122
0123 DECLARE_DETELEMENT(DD4hep_ParamVolume,create_detector)