HexagonalShashlykSamplingECAL_geo.cpp
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
2 #include "DD4hep/Printout.h"
3 #include <XML/Helper.h>
4 #include "TMath.h"
5 #include "DDRec/Surface.h"
6 #include "DDRec/DetectorData.h"
7 
8 using namespace std;
9 using namespace dd4hep;
10 using namespace dd4hep::rec;
11 
12 using namespace dd4hep;
13 
32 static Ref_t createDetector(Detector& desc, xml::Handle_t handle, SensitiveDetector sens) {
33  xml::DetElement detElem = handle;
34 
35  std::string detName = detElem.nameStr();
36  int detID = detElem.id();
37 
38  //xml::Component dims = detElem.dimensions();
39  //double rInner = dims.rmin();
40  //double rOuter1 = dims.rmax1();
41  //double rOuter2 = dims.rmax2();
42  //double zMin = dims.zmin();
43  //double zMax = dims.zmax();
44 
45  Material air = desc.air();
46  Material PyrexGlass = desc.material("PyrexGlass");
47 
48  Assembly assembly( detName+"_assembly" );
49  //Cone envShape(0.5 * (zMax - zMin), rInner, rOuter1, rInner, rOuter2);
50  //Volume envVol(detName + "_envelope", envShape, air);
51 
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;
58 
59  int nx = 2;
60  int ny = 2;
61  int nlayers = 194;
62 
63  double layer0_thickness = 0.5*cm;
64  double layer1_thickness = 1.5*cm;
65  double total_layer_thickness = layer0_thickness + layer1_thickness;
66 
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};
75 
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;
78 
79  double offset_x = -(width_x / 2.0) + r_nearest_spacing;
80  double offset_y = -(width_y / 2.0) + l_side_spacing;
81 
82  auto blue_vis = desc.visAttributes("PurpleVis");
83  auto red_vis = desc.visAttributes("RedVis");
84  //dd4hep::getAttrOrDefault(desc, _Unicode(vis), "BlueVis")
85 
86  Assembly module_assembly( "module_assembly" );
87  //Box Pb_wall_shape(width_x/2.0, width_y/2.0,1.2*cm/2.0);
88  //ExtrudedPolygon lead_layer_shape("hex_lead",ptx, pty, sec_z0, sec_x, sec_y, z_scale);
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);
92 
93  //ExtrudedPolygon scint_layer_shape("hex_scint",ptx, pty, sec_z1, sec_x, sec_y, z_scale);
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);
97 
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;
103  auto scint_PV =
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);
106  }
107 
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);
116  }
117  }
118 
119  //mirrorVol.setVisAttributes(desc.visAttributes(detElem.visStr()));
120  //assembly.setVisAttributes(desc.visAttributes(detElem.visStr()));
121 
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);
127  return det;
128 }
130 // clang-format off
131 DECLARE_DETELEMENT(HexagonalShashlykSamplingECAL, createDetector)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.
static Ref_t createDetector(Detector &desc, xml::Handle_t handle, SensitiveDetector sens)