File indexing completed on 2025-01-18 09:16:00
0001
0002
0003
0004 #include "DD4hep/DetFactoryHelper.h"
0005 #include "DD4hep/OpticalSurfaces.h"
0006 #include "DD4hep/Printout.h"
0007 #include "DDRec/DetectorData.h"
0008 #include "DDRec/Surface.h"
0009 #include <XML/Helper.h>
0010 #include <XML/Layering.h>
0011
0012
0013
0014
0015 using namespace std;
0016 using namespace dd4hep;
0017
0018 static Ref_t createDetector(Detector& desc, xml_h e, SensitiveDetector sens) {
0019 xml_det_t x_det = e;
0020 string detName = x_det.nameStr();
0021 int detID = x_det.id();
0022
0023 xml_dim_t dim = x_det.dimensions();
0024 double Width = dim.x();
0025
0026
0027 xml_dim_t pos = x_det.position();
0028 double z = pos.z();
0029 xml_dim_t rot = x_det.rotation();
0030
0031 Material Vacuum = desc.material("Vacuum");
0032
0033 double totWidth = Layering(x_det).totalThickness();
0034
0035 Box envelope(Width / 2.0, Width / 2.0, totWidth / 2.0);
0036 Volume envelopeVol(detName + "_envelope", envelope, Vacuum);
0037 envelopeVol.setVisAttributes(desc.visAttributes(x_det.visStr()));
0038 PlacedVolume pv;
0039
0040 int layer_num = 1;
0041
0042 for (xml_coll_t c(x_det, _U(layer)); c; ++c) {
0043 xml_comp_t x_layer = c;
0044 int repeat = x_layer.repeat();
0045 double layerWidth = 0;
0046
0047 for (xml_coll_t l(x_layer, _U(slice)); l; ++l)
0048 layerWidth += xml_comp_t(l).thickness();
0049
0050
0051 for (int i = 0; i < repeat; i++) {
0052 double zlayer = z;
0053 string layer_name = detName + _toString(layer_num, "_layer%d");
0054 Volume layer_vol(layer_name, Box(Width / 2.0, Width / 2.0, layerWidth / 2.0), Vacuum);
0055
0056 int slice_num = 1;
0057
0058 for (xml_coll_t l(x_layer, _U(slice)); l; ++l) {
0059 xml_comp_t x_slice = l;
0060 double w = x_slice.thickness();
0061 string slice_name = layer_name + _toString(slice_num, "slice%d");
0062 Material slice_mat = desc.material(x_slice.materialStr());
0063 Volume slice_vol(slice_name, Box(Width / 2.0, Width / 2.0, w / 2.0), slice_mat);
0064
0065 if (x_slice.isSensitive()) {
0066 sens.setType("calorimeter");
0067 slice_vol.setSensitiveDetector(sens);
0068 }
0069
0070 slice_vol.setAttributes(desc, x_slice.regionStr(), x_slice.limitsStr(), x_slice.visStr());
0071 pv = layer_vol.placeVolume(
0072 slice_vol, Transform3D(RotationZYX(0, 0, 0),
0073 Position(0.0, 0.0, z - zlayer - layerWidth / 2.0 + w / 2.0)));
0074 pv.addPhysVolID("slice", slice_num);
0075 z += w;
0076 ++slice_num;
0077 }
0078
0079 string layer_vis =
0080 dd4hep::getAttrOrDefault<std::string>(x_layer, _Unicode(vis), "InvisibleWithDaughters");
0081 layer_vol.setAttributes(desc, x_layer.regionStr(), x_layer.limitsStr(), layer_vis);
0082 pv = envelopeVol.placeVolume(
0083 layer_vol,
0084 Transform3D(RotationZYX(0, 0, 0),
0085 Position(0, 0, zlayer - pos.z() - totWidth / 2.0 + layerWidth / 2.0)));
0086 pv.addPhysVolID("layer", layer_num);
0087 ++layer_num;
0088 }
0089 }
0090
0091 DetElement det(detName, detID);
0092 Volume motherVol = desc.pickMotherVolume(det);
0093 Transform3D tr(RotationZYX(rot.z(), rot.y(), rot.x()),
0094 Position(pos.x(), pos.y(), pos.z() + totWidth / 2.0));
0095 PlacedVolume phv = motherVol.placeVolume(envelopeVol, tr);
0096 phv.addPhysVolID("system", detID);
0097 det.setPlacement(phv);
0098
0099 return det;
0100 }
0101 DECLARE_DETELEMENT(ZDC_Sampling, createDetector)