CMS 3D CMS Logo

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