CMS 3D CMS Logo

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