CMS 3D CMS Logo

DDHGCalMixLayer.cc
Go to the documentation of this file.
1 // File: DDHGCalMixLayer.cc
3 // Description: Geometry factory class for HGCal (Mix) adopted for DD4hep
5 
6 #include <cmath>
7 #include <memory>
8 #include <string>
9 #include <unordered_set>
10 #include <vector>
11 
19 #include "DD4hep/DetFactoryHelper.h"
24 
25 //#define EDM_ML_DEBUG
26 using namespace angle_units::operators;
27 
28 struct HGCalMixLayer {
29  HGCalMixLayer() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalMixLayer"; }
31  cms::DDNamespace ns(ctxt, e, true);
33 
34 #ifdef EDM_ML_DEBUG
35  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Creating an instance";
36 #endif
37 
38  static constexpr double tol1 = 0.01 * dd4hep::mm;
39  dd4hep::Volume mother = ns.volume(args.parentName());
40 
41  waferTypes_ = args.value<int>("WaferTypes");
42  facingTypes_ = args.value<int>("FacingTypes");
43  partialTypes_ = args.value<int>("PartialTypes");
44  orientationTypes_ = args.value<int>("OrientationTypes");
45  phiBinsScint_ = args.value<int>("NPhiBinScint");
46  forFireworks_ = args.value<int>("ForFireWorks");
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer::Number of types of wafers: " << waferTypes_
49  << " facings: " << facingTypes_ << " partials: " << partialTypes_
50  << " Orientations: " << orientationTypes_ << "; number of cells along phi "
51  << phiBinsScint_ << " forFireworks_: " << forFireworks_;
52 #endif
53  firstLayer_ = args.value<int>("FirstLayer");
54  absorbMode_ = args.value<int>("AbsorberMode");
55  sensitiveMode_ = args.value<int>("SensitiveMode");
56 #ifdef EDM_ML_DEBUG
57  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer::First Layer " << firstLayer_ << " and "
58  << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
59 #endif
60  zMinBlock_ = args.value<double>("zMinBlock");
61  waferSize_ = args.value<double>("waferSize");
62  waferSepar_ = args.value<double>("SensorSeparation");
63  sectors_ = args.value<int>("Sectors");
64  alpha_ = (1._pi) / sectors_;
65  cosAlpha_ = cos(alpha_);
66 #ifdef EDM_ML_DEBUG
67  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: zStart " << cms::convert2mm(zMinBlock_) << " wafer width "
68  << cms::convert2mm(waferSize_) << " separations " << cms::convert2mm(waferSepar_)
69  << " sectors " << sectors_ << ":" << convertRadToDeg(alpha_) << ":" << cosAlpha_;
70 #endif
71  slopeB_ = args.value<std::vector<double>>("SlopeBottom");
72  zFrontB_ = args.value<std::vector<double>>("ZFrontBottom");
73  rMinFront_ = args.value<std::vector<double>>("RMinFront");
74  slopeT_ = args.value<std::vector<double>>("SlopeTop");
75  zFrontT_ = args.value<std::vector<double>>("ZFrontTop");
76  rMaxFront_ = args.value<std::vector<double>>("RMaxFront");
77 #ifdef EDM_ML_DEBUG
78  for (unsigned int i = 0; i < slopeB_.size(); ++i)
79  edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << cms::convert2mm(zFrontB_[i]) << " Rmin "
80  << cms::convert2mm(rMinFront_[i]) << " Slope " << slopeB_[i];
81  for (unsigned int i = 0; i < slopeT_.size(); ++i)
82  edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << cms::convert2mm(zFrontT_[i]) << " Rmax "
83  << cms::convert2mm(rMaxFront_[i]) << " Slope " << slopeT_[i];
84 #endif
85 
86  waferFull_ = args.value<std::vector<std::string>>("WaferNamesFull");
87  waferPart_ = args.value<std::vector<std::string>>("WaferNamesPartial");
88 #ifdef EDM_ML_DEBUG
89  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << waferFull_.size() << " full and " << waferPart_.size()
90  << " partial modules\nDDHGCalMixLayer:Full Modules:";
91  unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
92  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
93  std::ostringstream st1;
94  unsigned int i2 = std::min((i1 + 2), i1max);
95  for (unsigned int i = i1; i < i2; ++i)
96  st1 << " [" << i << "] " << waferFull_[i];
97  edm::LogVerbatim("HGCalGeom") << st1.str() << std::endl;
98  }
99  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Partial Modules:";
100  i1max = static_cast<unsigned int>(waferPart_.size());
101  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
102  std::ostringstream st1;
103  unsigned int i2 = std::min((i1 + 2), i1max);
104  for (unsigned int i = i1; i < i2; ++i)
105  st1 << " [" << i << "] " << waferPart_[i];
106  edm::LogVerbatim("HGCalGeom") << st1.str() << std::endl;
107  }
108 #endif
109 
110  materials_ = args.value<std::vector<std::string>>("MaterialNames");
111  names_ = args.value<std::vector<std::string>>("VolumeNames");
112  thick_ = args.value<std::vector<double>>("Thickness");
113  copyNumber_.resize(materials_.size(), 1);
114 #ifdef EDM_ML_DEBUG
115  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << materials_.size() << " types of volumes";
116  for (unsigned int i = 0; i < names_.size(); ++i)
117  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness "
118  << cms::convert2mm(thick_[i]) << " filled with " << materials_[i]
119  << " first copy number " << copyNumber_[i];
120 #endif
121  layers_ = args.value<std::vector<int>>("Layers");
122  layerThick_ = args.value<std::vector<double>>("LayerThick");
123 #ifdef EDM_ML_DEBUG
124  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
125  for (unsigned int i = 0; i < layers_.size(); ++i)
126  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << cms::convert2mm(layerThick_[i])
127  << " with " << layers_[i] << " layers";
128 #endif
129  layerType_ = args.value<std::vector<int>>("LayerType");
130  layerSense_ = args.value<std::vector<int>>("LayerSense");
131  layerOrient_ = args.value<std::vector<int>>("LayerTypes");
132  for (unsigned int k = 0; k < layerOrient_.size(); ++k)
133  layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
134 #ifdef EDM_ML_DEBUG
135  for (unsigned int i = 0; i < layerOrient_.size(); ++i)
136  edm::LogVerbatim("HGCalGeom") << "LayerTypes [" << i << "] " << layerOrient_[i];
137 #endif
138  if (firstLayer_ > 0) {
139  for (unsigned int i = 0; i < layerType_.size(); ++i) {
140  if (layerSense_[i] > 0) {
141  int ii = layerType_[i];
142  copyNumber_[ii] = firstLayer_;
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
145  << materials_[ii] << " changed to " << copyNumber_[ii];
146 #endif
147  break;
148  }
149  }
150  } else {
151  firstLayer_ = 1;
152  }
153 #ifdef EDM_ML_DEBUG
154  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
155  for (unsigned int i = 0; i < layerType_.size(); ++i)
156  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
157  << layerSense_[i];
158 #endif
159  materialTop_ = args.value<std::vector<std::string>>("TopMaterialNames");
160  namesTop_ = args.value<std::vector<std::string>>("TopVolumeNames");
161  layerThickTop_ = args.value<std::vector<double>>("TopLayerThickness");
162  layerTypeTop_ = args.value<std::vector<int>>("TopLayerType");
163  copyNumberTop_.resize(materialTop_.size(), firstLayer_);
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << materialTop_.size() << " types of volumes in the top part";
166  for (unsigned int i = 0; i < materialTop_.size(); ++i)
167  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness "
168  << cms::convert2mm(layerThickTop_[i]) << " filled with " << materialTop_[i]
169  << " first copy number " << copyNumberTop_[i];
170  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
171  for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
172  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
173 #endif
174  waferIndex_ = args.value<std::vector<int>>("WaferIndex");
175  waferProperty_ = args.value<std::vector<int>>("WaferProperties");
176  waferLayerStart_ = args.value<std::vector<int>>("WaferLayerStart");
177 #ifdef EDM_ML_DEBUG
178  edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
179  << waferLayerStart_.size() << " layers";
180  for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
181  edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
182  for (unsigned int k = 0; k < waferIndex_.size(); ++k)
183  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << waferIndex_[k] << " ("
184  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
185  << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
186  << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
187  << HGCalProperty::waferThick(waferProperty_[k]) << ":"
188  << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
189  << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
190 #endif
191  tileRMin_ = args.value<std::vector<double>>("TileRMin");
192  tileRMax_ = args.value<std::vector<double>>("TileRMax");
193  tileIndex_ = args.value<std::vector<int>>("TileLayerRings");
194  tilePhis_ = args.value<std::vector<int>>("TilePhiRange");
195  tileLayerStart_ = args.value<std::vector<int>>("TileLayerStart");
196 #ifdef EDM_ML_DEBUG
197  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer:: with " << tileRMin_.size() << " rings";
198  for (unsigned int k = 0; k < tileRMin_.size(); ++k)
199  edm::LogVerbatim("HGCalGeom") << "Ring[" << k << "] " << cms::convert2mm(tileRMin_[k]) << " : "
200  << cms::convert2mm(tileRMax_[k]);
201  edm::LogVerbatim("HGCalGeom") << "TileProperties with " << tileIndex_.size() << " entries in "
202  << tileLayerStart_.size() << " layers";
203  for (unsigned int k = 0; k < tileLayerStart_.size(); ++k)
204  edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << tileLayerStart_[k];
205  for (unsigned int k = 0; k < tileIndex_.size(); ++k)
206  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << tileIndex_[k] << " ("
207  << "Layer " << std::get<0>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << " Ring "
208  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ":"
209  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ") Phi "
210  << std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[k])) << ":"
211  << std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[k]));
212 #endif
213 
214 #ifdef EDM_ML_DEBUG
215  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: NameSpace " << ns.name();
216 
217  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalMixLayer...";
218  copies_.clear();
219 #endif
220 
221  double zi(zMinBlock_);
222  int laymin(0);
223  for (unsigned int i = 0; i < layers_.size(); i++) {
224  double zo = zi + layerThick_[i];
225  double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
226  int laymax = laymin + layers_[i];
227  double zz = zi;
228  double thickTot(0);
229  for (int ly = laymin; ly < laymax; ++ly) {
230  int ii = layerType_[ly];
231  int copy = copyNumber_[ii];
232  double hthick = 0.5 * thick_[ii];
233  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
234  zz += hthick;
235  thickTot += thick_[ii];
236 
237  std::string name = names_[ii] + std::to_string(copy);
238 #ifdef EDM_ML_DEBUG
239  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << ly << ":" << ii << " Front "
240  << cms::convert2mm(zi) << ", " << cms::convert2mm(routF) << " Back "
241  << cms::convert2mm(zo) << ", " << cms::convert2mm(rinB)
242  << " superlayer thickness " << cms::convert2mm(layerThick_[i]);
243 #endif
244 
245  dd4hep::Material matter = ns.material(materials_[ii]);
246  dd4hep::Volume glog;
247 
248  if (layerSense_[ly] < 1) {
249  std::vector<double> pgonZ, pgonRin, pgonRout;
250  double rmax =
251  (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) - tol1;
252  HGCalGeomTools::radius(zz - hthick,
253  zz + hthick,
254  zFrontB_,
255  rMinFront_,
256  slopeB_,
257  zFrontT_,
258  rMaxFront_,
259  slopeT_,
260  -layerSense_[ly],
261  pgonZ,
262  pgonRin,
263  pgonRout);
264  for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
265  pgonZ[isec] -= zz;
266  if (layerSense_[ly] == 0 || absorbMode_ == 0)
267  pgonRout[isec] = rmax;
268  else
269  pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
270  }
271 
272  dd4hep::Solid solid = dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
273  ns.addSolidNS(ns.prepend(name), solid);
274  glog = dd4hep::Volume(solid.name(), solid, matter);
275  ns.addVolumeNS(glog);
276 #ifdef EDM_ML_DEBUG
277  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << solid.name() << " polyhedra of " << sectors_
278  << " sectors covering " << convertRadToDeg(-alpha_) << ":"
279  << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
280  for (unsigned int k = 0; k < pgonZ.size(); ++k)
281  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << cms::convert2mm(pgonZ[k]) << " R "
282  << cms::convert2mm(pgonRin[k]) << ":" << cms::convert2mm(pgonRout[k]);
283 #endif
284  } else {
285  double rins =
286  (sensitiveMode_ < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
287  double routs =
288  (sensitiveMode_ < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
289  dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
290  ns.addSolidNS(ns.prepend(name), solid);
291  glog = dd4hep::Volume(solid.name(), solid, matter);
292  ns.addVolumeNS(glog);
293 
294 #ifdef EDM_ML_DEBUG
295  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << solid.name() << " Tubs made of " << matter.name()
296  << " of dimensions " << cms::convert2mm(rinB) << ":" << cms::convert2mm(rins)
297  << ", " << cms::convert2mm(routF) << ":" << cms::convert2mm(routs) << ", "
298  << cms::convert2mm(hthick) << ", 0.0, 360.0 and positioned in: " << glog.name()
299  << " number " << copy;
300 #endif
301  positionMix(ctxt, e, glog, name, copy, thick_[ii], matter);
302  }
303 
304  dd4hep::Position r1(0, 0, zz);
305  mother.placeVolume(glog, copy, r1);
306  ++copyNumber_[ii];
307 #ifdef EDM_ML_DEBUG
308  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog.name() << " number " << copy << " positioned in "
309  << mother.name() << " at (0,0," << cms::convert2mm(zz) << ") with no rotation";
310 #endif
311  zz += hthick;
312  } // End of loop over layers in a block
313  zi = zo;
314  laymin = laymax;
315  if (std::abs(thickTot - layerThick_[i]) > tol2_) {
316  if (thickTot > layerThick_[i]) {
317  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
318  << " is smaller than " << cms::convert2mm(thickTot)
319  << ": thickness of all its components **** ERROR ****";
320  } else {
321  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(layerThick_[i])
322  << " does not match with " << cms::convert2mm(thickTot) << " of the components";
323  }
324  }
325  } // End of loop over blocks
326 
327 #ifdef EDM_ML_DEBUG
328  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << copies_.size() << " different wafer copy numbers";
329  int k(0);
330  for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
331  edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
332  }
333  copies_.clear();
334  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalMixLayer construction...";
335 #endif
336  }
337 
339  xml_h e,
340  const dd4hep::Volume& glog,
341  const std::string& nameM,
342  int copyM,
343  double thick,
344  const dd4hep::Material& matter) {
345  cms::DDNamespace ns(ctxt, e, true);
346 
347  // Make the top part first
348  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
349  int ii = layerTypeTop_[ly];
350  copyNumberTop_[ii] = copyM;
351  }
352  double hthick = 0.5 * thick;
353  double dphi = (2._pi) / phiBinsScint_;
354  double thickTot(0), zpos(-hthick);
355  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
356  int ii = layerTypeTop_[ly];
357  int copy = copyNumberTop_[ii];
358  int layer = copy - firstLayer_;
359  double hthickl = 0.5 * layerThickTop_[ii];
360  thickTot += layerThickTop_[ii];
361  zpos += hthickl;
362  dd4hep::Material matter1 = ns.material(materialTop_[ii]);
363  unsigned int k = 0;
364  int firstTile = tileLayerStart_[layer];
365  int lastTile = ((layer + 1 < static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
366  : static_cast<int>(tileIndex_.size()));
367 #ifdef EDM_ML_DEBUG
368  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << ly << ":" << ii << " Copy " << copy << " Tiles "
369  << firstTile << ":" << lastTile;
370 #endif
371  for (int ti = firstTile; ti < lastTile; ++ti) {
372  double r1 = tileRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
373  double r2 = tileRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
374  int fimin = std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
375  int fimax = std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
376  double phi1 = dphi * (fimin - 1);
377  double phi2 = (forFireworks_ == 1) ? (dphi * (fimax - fimin + 1)) : (dphi * fimax);
378 #ifdef EDM_ML_DEBUG
379  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Layer " << copy << " iR "
380  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << ":"
381  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << " R "
382  << cms::convert2mm(r1) << ":" << cms::convert2mm(r2) << " Thick "
383  << cms::convert2mm((2.0 * hthickl)) << " phi " << fimin << ":" << fimax << ":"
384  << convertRadToDeg(phi1) << ":" << convertRadToDeg(phi2);
385 #endif
386  std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
387  ++k;
388  dd4hep::Solid solid = dd4hep::Tube(r1, r2, hthickl, phi1, phi2);
389  ns.addSolidNS(ns.prepend(name), solid);
390  dd4hep::Volume glog1 = dd4hep::Volume(solid.name(), solid, matter1);
391  ns.addVolumeNS(glog1);
392 #ifdef EDM_ML_DEBUG
393  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog1.name() << " Tubs made of " << materialTop_[ii]
394  << " of dimensions " << cms::convert2mm(r1) << ", " << cms::convert2mm(r2) << ", "
395  << cms::convert2mm(hthickl) << ", " << convertRadToDeg(phi1) << ", "
396  << convertRadToDeg(phi2);
397 #endif
398  dd4hep::Position tran(0, 0, zpos);
399  glog.placeVolume(glog1, copy, tran);
400 #ifdef EDM_ML_DEBUG
401  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Position " << glog1.name() << " number " << copy << " in "
402  << glog.name() << " at (0, 0, " << cms::convert2mm(zpos) << ") with no rotation";
403 #endif
404  }
405  ++copyNumberTop_[ii];
406  zpos += hthickl;
407  }
408  if (std::abs(thickTot - thick) > tol2_) {
409  if (thickTot > thick) {
410  edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
411  << cms::convert2mm(thickTot)
412  << ": thickness of all its components in the top part **** ERROR ****";
413  } else {
414  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
415  << " does not match with " << cms::convert2mm(thickTot)
416  << " of the components in top part";
417  }
418  }
419 
420  // Make the bottom part next
421  int layer = (copyM - firstLayer_);
422  static const double sqrt3 = std::sqrt(3.0);
423  int layercenter = layerOrient_[layer];
424  int layerType = (layerOrient_[layer] == HGCalTypes::WaferCenterB) ? 1 : 0;
425  int firstWafer = waferLayerStart_[layer];
426  int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
427  : static_cast<int>(waferIndex_.size()));
428  double r = 0.5 * (waferSize_ + waferSepar_);
429  double R = 2.0 * r / sqrt3;
430  double dy = 0.75 * R;
431  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
432 #ifdef EDM_ML_DEBUG
433  int ium(0), ivm(0), kount(0);
434  std::vector<int> ntype(3, 0);
435  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: " << glog.name() << " r " << cms::convert2mm(r) << " R "
436  << cms::convert2mm(R) << " dy " << cms::convert2mm(dy) << " Shift "
437  << cms::convert2mm(xyoff.first) << ":" << cms::convert2mm(xyoff.second)
438  << " WaferSize " << cms::convert2mm((waferSize_ + waferSepar_)) << " index "
439  << firstWafer << ":" << (lastWafer - 1);
440 #endif
441  for (int k = firstWafer; k < lastWafer; ++k) {
442  int u = HGCalWaferIndex::waferU(waferIndex_[k]);
443  int v = HGCalWaferIndex::waferV(waferIndex_[k]);
444 #ifdef EDM_ML_DEBUG
445  int iu = std::abs(u);
446  int iv = std::abs(v);
447 #endif
448  int nr = 2 * v;
449  int nc = -2 * u + v;
450  double xpos = xyoff.first + nc * r;
451  double ypos = xyoff.second + nr * dy;
452  int type = HGCalProperty::waferThick(waferProperty_[k]);
453  int part = HGCalProperty::waferPartial(waferProperty_[k]);
454  int orien = HGCalProperty::waferOrient(waferProperty_[k]);
455  std::string wafer;
456  int i(999);
457  if (part == HGCalTypes::WaferFull) {
458  i = layerType * waferTypes_ + type;
459  wafer = waferFull_[i];
460  } else {
461  i = (part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ + layerType * waferTypes_ * orientationTypes_ +
462  type * orientationTypes_ + orien;
463 #ifdef EDM_ML_DEBUG
464  edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:ind " << layerType << ":" << type << ":" << part
465  << ":" << orien << ":" << i << ":" << waferPart_.size();
466 #endif
467  wafer = waferPart_[i];
468  }
469  int copy = HGCalTypes::packTypeUV(type, u, v);
470 #ifdef EDM_ML_DEBUG
471  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixLayer: Layer " << HGCalWaferIndex::waferLayer(waferIndex_[k])
472  << " Wafer " << wafer << " number " << copy << " type :part:orien:ind " << type
473  << ":" << part << ":" << orien << ":" << i << " layer:u:v " << (layer + firstLayer_)
474  << ":" << u << ":" << v;
475  if (iu > ium)
476  ium = iu;
477  if (iv > ivm)
478  ivm = iv;
479  kount++;
480  if (copies_.count(copy) == 0)
481  copies_.insert(copy);
482 #endif
483  dd4hep::Position tran(xpos, ypos, 0.0);
484  glog.placeVolume(ns.volume(wafer), copy, tran);
485 #ifdef EDM_ML_DEBUG
486  ++ntype[type];
487  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixLayer: " << wafer << " number " << copy << " type " << layerType
488  << ":" << type << " positioned in " << glog.name() << " at ("
489  << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
490 #endif
491  }
492 
493 #ifdef EDM_ML_DEBUG
494  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixLayer: Maximum # of u " << ium << " # of v " << ivm << " and " << kount
495  << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ") for "
496  << glog.name();
497 #endif
498  }
499 
500  //Required data members to cache the values from XML file
502  static constexpr double tol2_ = 0.00001 * dd4hep::mm;
503 
504  int waferTypes_; // Number of wafer types
505  int facingTypes_; // Types of facings of modules toward IP
506  int partialTypes_; // Number of partial wafer types
507  int orientationTypes_; // Number of partial wafer orienations
508  int phiBinsScint_; // Maximum number of cells along phi
509  int forFireworks_; // Needed for Fireworks(1)/Geant4(0)
510  int firstLayer_; // Copy # of the first sensitive layer
511  int absorbMode_; // Absorber mode
512  int sensitiveMode_; // Sensitive mode
513  double zMinBlock_; // Starting z-value of the block
514  double waferSize_; // Width of the wafer
515  double waferSepar_; // Sensor separation
516  int sectors_; // Sectors
517  std::vector<double> slopeB_; // Slope at the lower R
518  std::vector<double> zFrontB_; // Starting Z values for the slopes
519  std::vector<double> rMinFront_; // Corresponding rMin's
520  std::vector<double> slopeT_; // Slopes at the larger R
521  std::vector<double> zFrontT_; // Starting Z values for the slopes
522  std::vector<double> rMaxFront_; // Corresponding rMax's
523  std::vector<std::string> waferFull_; // Names of full wafer modules
524  std::vector<std::string> waferPart_; // Names of partial wafer modules
525  std::vector<std::string> materials_; // Materials
526  std::vector<std::string> names_; // Names
527  std::vector<double> thick_; // Thickness of the material
528  std::vector<int> copyNumber_; // Initial copy numbers
529  std::vector<int> layers_; // Number of layers in a section
530  std::vector<double> layerThick_; // Thickness of each section
531  std::vector<int> layerType_; // Type of the layer
532  std::vector<int> layerSense_; // Content of a layer (sensitive?)
533  std::vector<std::string> materialTop_; // Materials of top layers
534  std::vector<std::string> namesTop_; // Names of top layers
535  std::vector<double> layerThickTop_; // Thickness of the top sections
536  std::vector<int> layerTypeTop_; // Type of the Top layer
537  std::vector<int> copyNumberTop_; // Initial copy numbers (top section)
538  std::vector<int> layerOrient_; // Layer orientation of silicon layers
539  std::vector<int> waferIndex_; // Wafer index for the types
540  std::vector<int> waferProperty_; // Wafer property
541  std::vector<int> waferLayerStart_; // Start index of wafers in each layer
542  std::vector<double> tileRMin_; // Minimum radius of each ring
543  std::vector<double> tileRMax_; // Maximum radius of each ring
544  std::vector<int> tileIndex_; // Index of tile (layer/start|end ring)
545  std::vector<int> tilePhis_; // Tile phi range for each index
546  std::vector<int> tileLayerStart_; // Start index of tiles in each layer
547  std::unordered_set<int> copies_; // List of copy #'s
548  double alpha_, cosAlpha_;
549 };
550 
551 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
552  HGCalMixLayer mixLayerAlgo(ctxt, e);
553  return cms::s_executed;
554 }
555 
556 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalMixLayer, algorithm)
std::vector< int > copyNumberTop_
std::vector< int > layerOrient_
Log< level::Info, true > LogVerbatim
std::vector< double > tileRMin_
static void radius(double zf, double zb, std::vector< double > const &zFront1, std::vector< double > const &rFront1, std::vector< double > const &slope1, std::vector< double > const &zFront2, std::vector< double > const &rFront2, std::vector< double > const &slope2, int flag, std::vector< double > &zz, std::vector< double > &rin, std::vector< double > &rout)
std::vector< int > layerTypeTop_
std::vector< std::string > namesTop_
std::vector< std::string > materialTop_
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
std::vector< double > tileRMax_
std::vector< double > layerThick_
std::vector< std::string > waferFull_
std::vector< int > waferLayerStart_
Log< level::Error, false > LogError
std::vector< int > layerSense_
dd4hep::Material material(const std::string &name) const
Definition: DDNamespace.cc:166
HGCalGeomTools geomTools_
std::vector< int > copyNumber_
int32_t waferOrient(const int32_t property)
static std::string to_string(const XMLCh *ch)
std::vector< double > slopeB_
std::vector< int > waferIndex_
std::vector< double > rMinFront_
std::vector< double > zFrontB_
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
std::vector< int > tilePhis_
HGCalMixLayer(cms::DDParsingContext &ctxt, xml_h e)
static constexpr long s_executed
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< int > layers_
std::string_view name() const
Definition: DDNamespace.h:79
std::vector< int > tileLayerStart_
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< std::string > waferPart_
std::vector< std::string > materials_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int32_t waferThick(const int32_t property)
std::vector< int > layerType_
std::vector< int > waferProperty_
dd4hep::Volume Volume
std::vector< double > rMaxFront_
ii
Definition: cuy.py:589
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter)
std::tuple< int32_t, int32_t, int32_t > tileUnpack(int32_t index)
std::vector< std::string > names_
part
Definition: HCALResponse.h:20
std::vector< double > thick_
std::vector< double > slopeT_
int32_t waferPartial(const int32_t property)
std::vector< double > zFrontT_
int32_t waferV(const int32_t index)
std::unordered_set< int > copies_
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
Log< level::Warning, false > LogWarning
static int32_t layerType(int type)
Definition: HGCalTypes.cc:42
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
Definition: DDNamespace.cc:202
static constexpr int32_t WaferCenterB
Definition: HGCalTypes.h:26
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
std::vector< double > layerThickTop_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::vector< int > tileIndex_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Definition: DDNamespace.cc:292
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99