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 <algorithm>
0011 #include <iostream>
0012 #include <math.h>
0013 #include <tuple>
0014
0015
0016
0017
0018
0019 using namespace std;
0020 using namespace dd4hep;
0021
0022
0023 static Ref_t create_detector(Detector& desc, xml_h handle, SensitiveDetector sens) {
0024 xml::DetElement detElem = handle;
0025 std::string detName = detElem.nameStr();
0026 int detID = detElem.id();
0027 DetElement det(detName, detID);
0028 sens.setType("calorimeter");
0029 auto dim = detElem.dimensions();
0030 auto xwidth = dim.x();
0031 auto ywidth = dim.y();
0032 auto length = dim.z();
0033 xml_dim_t pos = detElem.position();
0034 xml_dim_t rot = detElem.rotation();
0035
0036
0037 Box envShape(xwidth * 0.5, ywidth * 0.5, length * 0.5);
0038 Volume env(detName + "_envelope", envShape, desc.material("Air"));
0039 env.setVisAttributes(desc.visAttributes(detElem.visStr()));
0040
0041 xml_comp_t mod_x = detElem.child(_Unicode(module));
0042 auto nbox = mod_x.attr<int>(_Unicode(nbox));
0043 auto boxgap = mod_x.attr<int>(_Unicode(gapspace));
0044
0045 xml_comp_t x_lyr = mod_x.child(_Unicode(layer));
0046 auto nlyr = x_lyr.attr<int>(_Unicode(nlayer));
0047
0048 map<int, string> v_sl_name;
0049 map<string, Volume> slices;
0050 map<string, double> sl_thickness;
0051
0052 int nsl = 0;
0053 xml_coll_t ci(x_lyr, _Unicode(slice));
0054 for (ci.reset(); ci; ++ci) {
0055 xml_comp_t x_sl = ci;
0056 Material sl_mat = desc.material(x_sl.materialStr());
0057 string sl_name = x_sl.nameStr();
0058 double sl_z = x_sl.thickness();
0059
0060 Box sl_Shape(xwidth / 2., ywidth / 2., sl_z / 2.);
0061 Volume sl_Vol("slice_vol", sl_Shape, sl_mat);
0062 sl_Vol.setVisAttributes(desc.visAttributes(x_sl.visStr()));
0063 if (x_sl.isSensitive())
0064 sl_Vol.setSensitiveDetector(sens);
0065
0066 nsl++;
0067 v_sl_name[nsl] = sl_name;
0068 slices[sl_name] = sl_Vol;
0069 sl_thickness[sl_name] = sl_z;
0070 }
0071
0072 double zpos_0 = -length / 2.;
0073 int layerid = 0;
0074 for (int ibox = 0; ibox < nbox; ibox++) {
0075 for (int ilyr = 0; ilyr < nlyr; ilyr++) {
0076 layerid++;
0077 for (int isl = 0; isl < nsl; isl++) {
0078 string sl_name = v_sl_name[isl + 1];
0079
0080 double zpos = zpos_0 + sl_thickness[sl_name] / 2.;
0081 Position sl_pos(0, 0, zpos);
0082 PlacedVolume pv = env.placeVolume(slices[sl_name], sl_pos);
0083 if (slices[sl_name].isSensitive())
0084 pv.addPhysVolID(sl_name, layerid);
0085
0086 zpos_0 += sl_thickness[sl_name];
0087 }
0088 }
0089 zpos_0 += boxgap;
0090 }
0091
0092
0093 Volume motherVol = desc.pickMotherVolume(det);
0094 Transform3D tr(RotationZYX(rot.z(), rot.y(), rot.x()), Position(pos.x(), pos.y(), pos.z()));
0095 PlacedVolume envPV = motherVol.placeVolume(env, tr);
0096 envPV.addPhysVolID("system", detID);
0097 det.setPlacement(envPV);
0098 return det;
0099 }
0100
0101 DECLARE_DETELEMENT(ZDC_SamplingCal, create_detector)