CMS 3D CMS Logo

DDHGCalCell.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 //#define EDM_ML_DEBUG
7 
8 static long algorithm(dd4hep::Detector& /* description */,
10  xml_h e,
11  dd4hep::SensitiveDetector& /* sens */) {
12  cms::DDNamespace ns(ctxt, e, true);
13  cms::DDAlgoArguments args(ctxt, e);
14  // Header section of original DDHGCalCell.h
15  double waferSize = args.value<double>("WaferSize"); // size of wafer
16  double waferT = args.value<double>("WaferThick"); // Thickness of wafer
17  double cellT = args.value<double>("CellThick"); // Thickness of depletion layer
18  int nCells = args.value<int>("NCells"); // Number of cells
19  int posSens = args.value<int>("PosSensitive"); // Position of delpletion layer within wafer
20  std::string material = args.value<std::string>("Material"); // Material
21  std::string fullCN = args.value<std::string>("FullCell"); // Name of the full cell
22  std::string fullSensN = args.value<std::string>("FullSensitive"); // Name of the sensitive part for a full cell
23  std::vector<std::string> truncCN =
24  args.value<std::vector<std::string> >("TruncatedCell"); // Names of truncated cells
25  std::vector<std::string> truncSensN =
26  args.value<std::vector<std::string> >("TruncatedSensitive"); // Names of the sensitive parts for truncated cells
27  std::vector<std::string> extenCN = args.value<std::vector<std::string> >("ExtendedCell"); // Names of extended cells
28  std::vector<std::string> extenSensN =
29  args.value<std::vector<std::string> >("ExtendedSensitive"); // Names of the sensitive parts for extended cells
30  std::vector<std::string> cornrCN = args.value<std::vector<std::string> >("CornerCell"); // Names of the corner cells
31  std::vector<std::string> cornrSensN =
32  args.value<std::vector<std::string> >("CornerSensitive"); // Names of the sensitive parts for corner cells
33 
34  if ((truncCN.size() != truncSensN.size()) || (extenCN.size() != extenSensN.size()) ||
35  (cornrCN.size() != cornrSensN.size())) {
36  edm::LogError("HGCalGeom") << "The number of cells & sensitive differ:"
37  << " Truncated " << truncCN.size() << ":" << truncSensN.size() << " Extended "
38  << extenCN.size() << ":" << extenSensN.size() << " Corners " << cornrCN.size() << ":"
39  << cornrSensN.size();
40  throw cms::Exception("DDException") << "The number of cells & sensitive "
41  << "differ: Truncated " << truncCN.size() << ":" << truncSensN.size()
42  << " Extended " << extenCN.size() << ":" << extenSensN.size() << " Corners "
43  << cornrCN.size() << ":" << cornrSensN.size();
44  }
45  if ((truncCN.size() != 3) || (extenCN.size() != 3) || (cornrCN.size() != 6)) {
46  edm::LogError("HGCalGeom") << "DDHGCalCell: The number of cells does not"
47  << " match with Standard: Truncated " << truncCN.size() << ":3 Extended "
48  << extenCN.size() << ":3"
49  << " Corners " << cornrCN.size() << ":6";
50  throw cms::Exception("DDException") << "Wrong size of truncated|extended"
51  << "|corner cells: " << truncCN.size() << ":" << extenCN.size() << ":"
52  << cornrCN.size();
53  }
54 #ifdef EDM_ML_DEBUG
55  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Wafer r " << waferSize << " T " << waferT << " Cell T " << cellT
56  << " Cells/Wafer " << nCells << " Material " << material << "Sensitive Position "
57  << posSens << " Full Cell: " << fullCN << ":" << fullSensN;
58  for (int k = 0; k < 3; ++k)
59  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Truncated Cell[" << k << "] " << truncCN[k] << ":" << truncSensN[k];
60  for (int k = 0; k < 3; ++k)
61  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Extended Cell[" << k << "] " << extenCN[k] << ":" << extenSensN[k];
62  for (int k = 0; k < 6; ++k)
63  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: Corner Cell[" << k << "] " << cornrCN[k] << ":" << cornrSensN[k];
64  edm::LogVerbatim("HGCalGeom") << "Name space " << ns.name();
65 #endif
66 
67  dd4hep::Material matter = ns.material(material);
68 #ifdef EDM_ML_DEBUG
69  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << material << " initialized at " << &matter;
70 #endif
71  dd4hep::Volume glog1, glog2;
72 
73  static const double sqrt3 = std::sqrt(3.0);
74  static const double waf2cell = 3.0;
75  static const double cornerfac = 2.5;
76  double R = waferSize / (waf2cell * nCells);
77  double r = 0.5 * R * sqrt3;
78  double dx1 = R;
79  double dx2 = 0.5 * dx1;
80  double dx3 = cornerfac * dx2;
81  double dx4 = 0.5 * dx2;
82  double dy1 = r;
83  double dy2 = 0.5 * dy1;
84  double dy3 = 1.5 * dy1;
85  std::vector<double> xx = {dx1, dx2, -dx2, -dx1, -dx2, dx2, dx3, -dx4, -dx1, -dx1, -dx4, dx3};
86  std::vector<double> yy = {0, dy1, dy1, 0, -dy1, -dy1, dy2, dy3, dy1, -dy1, -dy3, -dy2};
87  double zpos = (posSens == 0) ? -0.5 * (waferT - cellT) : 0.5 * (waferT - cellT);
88  dd4hep::Position tran(0, 0, zpos);
89 
90  // First the full cell
91  std::vector<double> xw = {xx[0], xx[1], xx[2], xx[3], xx[4], xx[5]};
92  std::vector<double> yw = {yy[0], yy[1], yy[2], yy[3], yy[4], yy[5]};
93  std::vector<double> zw = {-0.5 * waferT, 0.5 * waferT};
94  std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
95  dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
96  ns.addSolidNS(ns.prepend(fullCN), solid);
97  glog1 = dd4hep::Volume(solid.name(), solid, matter);
98  ns.addVolumeNS(glog1);
99 #ifdef EDM_ML_DEBUG
100  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
101  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
102  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
103  << " and " << xw.size() << " edges";
104  for (unsigned int k = 0; k < xw.size(); ++k)
105  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
106 #endif
107  std::vector<double> zc = {-0.5 * cellT, 0.5 * cellT};
108  solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
109  ns.addSolidNS(ns.prepend(fullSensN), solid);
110  glog2 = dd4hep::Volume(solid.name(), solid, matter);
111  ns.addVolumeNS(glog2);
112 #ifdef EDM_ML_DEBUG
113  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
114  << " z|x|y|s (0) " << zc[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
115  << " z|x|y|s (1) " << zc[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
116  << " and " << xw.size() << " edges";
117  for (unsigned int k = 0; k < xw.size(); ++k)
118  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
119 #endif
120 
121  dd4hep::Rotation3D rotation;
122  glog1.placeVolume(glog2, 1, dd4hep::Transform3D(rotation, tran));
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name() << " at "
125  << tran << " with " << rotation;
126 #endif
127 
128  static const int ir0[] = {0, 1, 0};
129  static const int ir1[] = {1, 2, 1};
130  static const int ir2[] = {2, 3, 3};
131  static const int ir3[] = {3, 4, 4};
132  static const int ir4[] = {5, 5, 5};
133  for (int i = 0; i < 3; ++i) {
134  std::vector<double> xw = {xx[ir0[i]], xx[ir1[i]], xx[ir2[i]], xx[ir3[i]], xx[ir4[i]]};
135  std::vector<double> yw = {yy[ir0[i]], yy[ir1[i]], yy[ir2[i]], yy[ir3[i]], yy[ir4[i]]};
136 
137  solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
138  ns.addSolidNS(ns.prepend(truncCN[i]), solid);
139  glog1 = dd4hep::Volume(solid.name(), solid, matter);
140  ns.addVolumeNS(glog1);
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
143  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
144  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
145  << " and " << xw.size() << " edges";
146  for (unsigned int k = 0; k < xw.size(); ++k)
147  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
148 #endif
149 
150  solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
151  ns.addSolidNS(ns.prepend(truncSensN[i]), solid);
152  glog2 = dd4hep::Volume(solid.name(), solid, matter);
153  ns.addVolumeNS(glog2);
154 #ifdef EDM_ML_DEBUG
155  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
156  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
157  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
158  << " and " << xw.size() << " edges";
159  for (unsigned int k = 0; k < xw.size(); ++k)
160  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
161 #endif
162  glog1.placeVolume(glog2, 1, dd4hep::Transform3D(rotation, tran));
163 #ifdef EDM_ML_DEBUG
164  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
165  << " at " << tran << " with " << rotation;
166 #endif
167  }
168 
169  static const int ie0[] = {1, 5, 0};
170  static const int ie1[] = {2, 6, 1};
171  static const int ie2[] = {3, 7, 8};
172  static const int ie3[] = {10, 3, 9};
173  static const int ie4[] = {11, 4, 5};
174  for (int i = 0; i < 3; ++i) {
175  std::vector<double> xw = {xx[ie0[i]], xx[ie1[i]], xx[ie2[i]], xx[ie3[i]], xx[ie4[i]]};
176  std::vector<double> yw = {yy[ie0[i]], yy[ie1[i]], yy[ie2[i]], yy[ie3[i]], yy[ie4[i]]};
177  solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
178  ns.addSolidNS(ns.prepend(extenCN[i]), solid);
179  glog1 = dd4hep::Volume(solid.name(), solid, matter);
180  ns.addVolumeNS(glog1);
181 #ifdef EDM_ML_DEBUG
182  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
183  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
184  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
185  << " and " << xw.size() << " edges";
186  for (unsigned int k = 0; k < xw.size(); ++k)
187  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
188 #endif
189  solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
190  ns.addSolidNS(ns.prepend(extenSensN[i]), solid);
191  glog2 = dd4hep::Volume(solid.name(), solid, matter);
192  ns.addVolumeNS(glog2);
193 #ifdef EDM_ML_DEBUG
194  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
195  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
196  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
197  << " and " << xw.size() << " edges";
198  for (unsigned int k = 0; k < xw.size(); ++k)
199  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
200 #endif
201  glog1.placeVolume(glog2, 1, dd4hep::Transform3D(rotation, tran));
202 #ifdef EDM_ML_DEBUG
203  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
204  << " at " << tran << " with " << rotation;
205 #endif
206  }
207 
208  static const int ic0[] = {0, 1, 1, 1, 1, 0};
209  static const int ic1[] = {1, 2, 2, 7, 3, 1};
210  static const int ic2[] = {8, 3, 3, 3, 4, 3};
211  static const int ic3[] = {3, 5, 10, 4, 5, 9};
212  static const int ic4[] = {5, 11, 5, 5, 6, 5};
213  for (int i = 0; i < 6; ++i) {
214  std::vector<double> xw = {xx[ic0[i]], xx[ic1[i]], xx[ic2[i]], xx[ic3[i]], xx[ic4[i]]};
215  std::vector<double> yw = {yy[ic0[i]], yy[ic1[i]], yy[ic2[i]], yy[ic3[i]], yy[ic4[i]]};
216  solid = dd4hep::ExtrudedPolygon(xw, yw, zw, zx, zy, scale);
217  ns.addSolidNS(ns.prepend(cornrCN[i]), solid);
218  glog1 = dd4hep::Volume(solid.name(), solid, matter);
219  ns.addVolumeNS(glog1);
220 #ifdef EDM_ML_DEBUG
221  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
222  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
223  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
224  << " and " << xw.size() << " edges";
225  for (unsigned int k = 0; k < xw.size(); ++k)
226  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
227 #endif
228  solid = dd4hep::ExtrudedPolygon(xw, yw, zc, zx, zy, scale);
229  ns.addSolidNS(ns.prepend(cornrSensN[i]), solid);
230  glog2 = dd4hep::Volume(solid.name(), solid, matter);
231  ns.addVolumeNS(glog2);
232 #ifdef EDM_ML_DEBUG
233  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << solid.name() << " extruded polygon made of " << material
234  << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
235  << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
236  << " and " << xw.size() << " edges";
237  for (unsigned int k = 0; k < xw.size(); ++k)
238  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xw[k] << ":" << yw[k];
239 #endif
240  glog1.placeVolume(glog2, 1, dd4hep::Transform3D(rotation, tran));
241 #ifdef EDM_ML_DEBUG
242  edm::LogVerbatim("HGCalGeom") << "DDHGCalCell: " << glog2.name() << " number 1 position in " << glog1.name()
243  << " at " << tran << " with " << rotation;
244 #endif
245  }
246  return 1;
247 }
248 
249 // first argument is the type from the xml file
250 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalCell, algorithm)
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:200
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:150
T value(const std::string &name) const
std::string_view name() const
Definition: DDNamespace.h:68
T sqrt(T t)
Definition: SSEVec.h:19
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:121
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:66
dd4hep::Volume Volume
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:30
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e, dd4hep::SensitiveDetector &)
Definition: DDHGCalCell.cc:8