ScintillatingTileEndcapHCAL_geo.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // Scintillating Tile Endcap H Calorimeter Detector implementation
3 //--------------------------------------------------------------------------
4 // J.KIM 2020-04-07
5 // Created tile-shaped Pb/Sci
6 //==========================================================================
7 #include "DD4hep/DetFactoryHelper.h"
8 #include "DD4hep/Printout.h"
9 #include <XML/Helper.h>
10 #include "TMath.h"
11 #include "DDRec/Surface.h"
12 #include "DDRec/DetectorData.h"
13 
14 using namespace std;
15 using namespace dd4hep;
16 using namespace dd4hep::rec;
17 using namespace dd4hep::detail;
18 
36 static Ref_t createDetector(Detector& description, xml_h e, SensitiveDetector sens) {
37  xml_det_t x_det = e;
38  int det_id = x_det.id();
39  string det_name = x_det.nameStr();
40  // Size of Endcap
41  double rmin = 2.0*cm;
42  double rmax = 10.0*cm;
43 
44  Assembly assembly( det_name+"_assembly" );
45  // Number of layers of each tile
46  int nlayers = 30;
47  // Thickness of plates
48  double layer0_thickness = 0.5*mm; //Pb_slice
49  double layer1_thickness = 1.5*mm; //Scint_slice
50  double total_layer_thickness = layer0_thickness + layer1_thickness;
51  // Size of tile
52  double width_x = 1*cm;
53  double width_y = 1*cm;
54  // Visualization Setting
55  auto gray_vis = description.visAttributes("GrayVis");
56  auto red_vis = description.visAttributes("RedVis");
57 
58  DetElement det(det_name, det_id);
59 
60  Assembly module_assembly( "module_assembly" );
61  PlacedVolume module_PV;
62 
63  //Pb tile
64  Box lead_layer_shape(width_x/2.0, width_y/2.0,layer0_thickness/2.0);
65  Volume lead_layer_Vol("lead_layer_Vol", lead_layer_shape, description.material("Lead"));
66  lead_layer_Vol.setVisAttributes(gray_vis);
67  //Sci tile
68  Box scint_layer_shape(width_x/2.0, width_y/2.0,layer1_thickness/2.0);
69  Volume scint_layer_Vol("scint_layer_Vol", scint_layer_shape, description.material("PlasticScint"));
70  scint_layer_Vol.setVisAttributes(red_vis);
71  // A Stack of Pb and Scintillator tiles
72  for(int ilayer = 0; ilayer < nlayers; ilayer++) {
73  double z_layer = ilayer * total_layer_thickness + layer0_thickness / 2.0;
74  auto lead_PV = module_assembly.placeVolume(lead_layer_Vol, Position(0.0, 0.0, z_layer));
75  lead_PV.addPhysVolID("layer", ilayer).addPhysVolID("slice", 1);
76  sens.setType("calorimeter");
77  lead_layer_Vol.setSensitiveDetector(sens);
78  double dz_scint = layer0_thickness / 2.0 + layer1_thickness / 2.0;
79  auto scint_PV = module_assembly.placeVolume(scint_layer_Vol, Position(0.0, 0.0, z_layer + dz_scint));
80  scint_PV.addPhysVolID("layer", ilayer).addPhysVolID("slice", 2);
81  sens.setType("calorimeter");
82  scint_layer_Vol.setSensitiveDetector(sens);
83  }
84 
85  // How many
86  int nx = 10;
87  int ny = 10;
88  // Offset between X and Y
89  double offset_x = 0.1*mm;
90  double offset_y = 0.1*mm;
91  // Position of each stack of Pb/Sc
92  double pos_x = 0.0*cm;
93  double pos_y = 0.0*cm;
94  // Starting Position of each stack of Pb/Sc
95  double x_start = (width_x + offset_x)/2.0;
96  double y_start = (width_y + offset_x)/2.0;
97  // Spacing between stacks and Diagonal length
98  double x_spacing = width_x + offset_x;
99  double y_spacing = width_y + offset_y;
100  double diagonal = width_x*sqrt(2);
101  // Limit based on Endcap size
102  double limit_inner = rmin + diagonal/2.0;
103  double limit_outer = rmax - diagonal/2.0;
104 
106  // Start placing stacks of Pb/Sc
107  // Divide 4 sections; X+Y+, X-Y+, X+Y-, X-Y-
109  // X+Y+
111  int imod = 0;
112  for(int ix = 0; ix<nx; ix++)
113  {
114  pos_x = x_start + (ix*x_spacing);
115  pos_y = y_start;
116  for(int iy = 0; iy<ny; iy++)
117  {
118  pos_y = y_start + (iy*y_spacing);
119  if(sqrt((pos_x*pos_x) + (pos_y*pos_y)) > limit_inner && sqrt((pos_x*pos_x) + (pos_y*pos_y)) < limit_outer)
120  {
121  module_PV = assembly.placeVolume(module_assembly, Position(pos_x,pos_y,0.0));
122  imod++;
123  module_PV.addPhysVolID("module", imod);
124  }
125  else
126  continue;
127  }
128  }
130  // X-Y+
132  for(int ix = 0; ix<nx; ix++)
133  {
134  pos_x = -x_start - (ix*x_spacing);
135  pos_y = y_start;
136  for(int iy = 0; iy<ny; iy++)
137  {
138  pos_y = y_start + (iy*y_spacing);
139  if(sqrt((pos_x*pos_x) + (pos_y*pos_y)) > limit_inner && sqrt((pos_x*pos_x) + (pos_y*pos_y)) < limit_outer)
140  {
141  module_PV = assembly.placeVolume(module_assembly, Position(pos_x,pos_y, 0.0));
142  imod++;
143  module_PV.addPhysVolID("module", imod);
144  }
145  else
146  continue;
147  }
148  }
150  // X+Y-
152  for(int ix = 0; ix<nx; ix++)
153  {
154  pos_x = x_start + (ix*x_spacing);
155  pos_y = -y_start;
156  for(int iy = 0; iy<ny; iy++)
157  {
158  pos_y = -y_start - (iy*y_spacing);
159  if(sqrt((pos_x*pos_x) + (pos_y*pos_y)) > limit_inner && sqrt((pos_x*pos_x) + (pos_y*pos_y)) < limit_outer)
160  {
161  module_PV = assembly.placeVolume(module_assembly, Position(pos_x,pos_y, 0.0));
162  imod++;
163  module_PV.addPhysVolID("module", imod);
164  }
165  else
166  continue;
167  }
168  }
170  // X-Y-
172  for(int ix = 0; ix<nx; ix++)
173  {
174  pos_x = -x_start - (ix*x_spacing);
175  pos_y = -y_start;
176  for(int iy = 0; iy<ny; iy++)
177  {
178  pos_y = -y_start - (iy*y_spacing);
179  if(sqrt((pos_x*pos_x) + (pos_y*pos_y)) > limit_inner && sqrt((pos_x*pos_x) + (pos_y*pos_y)) < limit_outer)
180  {
181  module_PV = assembly.placeVolume(module_assembly, Position(pos_x,pos_y, 0.0));
182  imod++;
183  module_PV.addPhysVolID("module", imod);
184  }
185  else
186  continue;
187  }
188  }
189 
190  Volume motherVol = description.pickMotherVolume(det);
191  PlacedVolume envPV = motherVol.placeVolume(assembly, Position(0, 0, 0));
192  envPV.addPhysVolID("system", det_id);
193  det.setPlacement(envPV);
194  return det;
195 }
197 // clang-format off
198 DECLARE_DETELEMENT(ScintillatingTileEndcapHCAL, createDetector)
static Ref_t createDetector(Detector &description, xml_h e, SensitiveDetector sens)
Detector
Definition: DDG4.py:69
Namespace for the AIDA detector description toolkit.