1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include <XML/Helper.h>
5 #include "DDRec/Surface.h"
6 #include "DDRec/DetectorData.h"
10 using namespace dd4hep::rec;
33 xml::DetElement detElem = handle;
35 std::string detName = detElem.nameStr();
36 int detID = detElem.id();
45 Material air = desc.air();
46 Material PyrexGlass = desc.material(
"PyrexGlass");
48 Assembly assembly( detName+
"_assembly" );
52 double l_side = 6.25 * cm;
53 double r_nearest = l_side * std::sqrt(3.0) / 2.0;
54 double thickness = 2.0 * cm;
55 double l_side_spacing = 6.25 * cm + 1.0 * mm;
56 double r_nearest_spacing = l_side_spacing * std::sqrt(3.0) / 2.0;
57 double y_spacing = 1.5*l_side_spacing;
63 double layer0_thickness = 0.5*cm;
64 double layer1_thickness = 1.5*cm;
65 double total_layer_thickness = layer0_thickness + layer1_thickness;
67 std::vector<double> ptx = { r_nearest, 0.0, -r_nearest, -r_nearest, 0.0, r_nearest };
68 std::vector<double> pty = { l_side/2.0, l_side, l_side/2.0, -l_side/2.0, -l_side, -l_side/2.0 };
69 std::vector<double> sec_x = { 0.0, 0.0 };
70 std::vector<double> sec_y = { 0.0, 0.0 };
71 std::vector<double> sec_z0 = { -layer0_thickness/2.0, layer0_thickness/2.0 };
72 std::vector<double> sec_z1 = { -layer1_thickness/2.0, layer1_thickness/2.0 };
73 std::vector<double> z_scale = { 1.0,1.0};
74 std::vector<double> sec_r = {r_nearest, r_nearest};
76 double width_x = (2.0*r_nearest_spacing)*nx + r_nearest_spacing;
77 double width_y = (y_spacing)*ny + 0.5*l_side_spacing;
79 double offset_x = -(width_x / 2.0) + r_nearest_spacing;
80 double offset_y = -(width_y / 2.0) + l_side_spacing;
82 auto blue_vis = desc.visAttributes(
"PurpleVis");
83 auto red_vis = desc.visAttributes(
"RedVis");
86 Assembly module_assembly(
"module_assembly" );
89 Polyhedra lead_layer_shape(
"hex_lead", 6, 0.0, 2.0*M_PI, sec_z0, sec_r);
90 Volume lead_layer_Vol(
"lead_layer_Vol", lead_layer_shape, desc.material(
"Lead"));
91 lead_layer_Vol.setVisAttributes(blue_vis);
94 Polyhedra scint_layer_shape(
"hex_scint", 6, 0.0, 2.0*M_PI, sec_z1, sec_r);
95 Volume scint_layer_Vol(
"hex_scint_vol", scint_layer_shape, desc.material(
"PlasticScint"));
96 scint_layer_Vol.setVisAttributes(red_vis);
98 for(
int ilayer = 0; ilayer < nlayers; ilayer++) {
99 double z_layer = ilayer * total_layer_thickness + layer0_thickness / 2.0;
100 auto lead_PV = module_assembly.placeVolume(lead_layer_Vol, Translation3D(0.0, 0.0, z_layer)*RotationZ(M_PI*30.0/180.0));
101 lead_PV.addPhysVolID(
"layer", ilayer).addPhysVolID(
"slice", 1);
102 double dz_scint = layer0_thickness / 2.0 + layer1_thickness / 2.0;
104 module_assembly.placeVolume(scint_layer_Vol, Translation3D(0.0, 0.0, z_layer + dz_scint)*RotationZ(M_PI*30.0/180.0));
105 scint_PV.addPhysVolID(
"layer", ilayer).addPhysVolID(
"slice", 2);
108 for(
int ix =0; ix<nx; ix++){
109 for(
int iy =0; iy<ny; iy++){
110 int imod = ix + iy*nx;
111 double extra_x = -(iy%2)*r_nearest_spacing + r_nearest_spacing;
112 PlacedVolume module_PV = assembly.placeVolume(
113 module_assembly, Position(offset_x + ix * (2.0 * r_nearest_spacing) + extra_x,
114 offset_y + iy * (y_spacing), 0.0));
115 module_PV.addPhysVolID(
"module", imod);
122 DetElement det(detName, detID);
123 Volume motherVol = desc.pickMotherVolume(det);
124 PlacedVolume envPV = motherVol.placeVolume(assembly, Position(0, 0, 0));
125 envPV.addPhysVolID(
"system", detID);
126 det.setPlacement(envPV);