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) << cms::convert2mm(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  int cassette0 = HGCalCassette::cassetteType(2, 1, cassette); //
400  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: Layer " << copy << ":" << (layer + 1) << " iR "
401  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << ":"
402  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << " R "
403  << cms::convert2mm(r1) << ":" << cms::convert2mm(r2) << " Thick "
404  << cms::convert2mm((2.0 * hthickl)) << " phi " << fimin << ":" << fimax << ":"
405  << convertRadToDeg(phi1) << ":" << convertRadToDeg(phi2) << " cassette "
406  << cassette << ":" << cassette0 << " Shift " << cms::convert2mm(cshift.first)
407  << ":" << cms::convert2mm(cshift.second);
408 #endif
409  std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
410  ++k;
411  dd4hep::Solid solid = dd4hep::Tube(r1, r2, hthickl, phi1, phi2);
412  ns.addSolidNS(ns.prepend(name), solid);
413  dd4hep::Volume glog1 = dd4hep::Volume(solid.name(), solid, matter1);
414  ns.addVolumeNS(glog1);
415 #ifdef EDM_ML_DEBUG
416  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: " << glog1.name() << " Tubs made of "
417  << materialTop_[ii] << " of dimensions " << cms::convert2mm(r1) << ", "
418  << cms::convert2mm(r2) << ", " << cms::convert2mm(hthickl) << ", "
419  << convertRadToDeg(phi1) << ", " << convertRadToDeg(phi2);
420 #endif
421  dd4hep::Position tran(-cshift.first, cshift.second, zpos);
422  glog.placeVolume(glog1, copy, tran);
423 #ifdef EDM_ML_DEBUG
424  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: Position " << glog1.name() << " number " << copy
425  << " in " << glog.name() << " at (" << cms::convert2mm(cshift.first) << ", "
426  << cms::convert2mm(cshift.second) << ", " << cms::convert2mm(zpos)
427  << ") with no rotation";
428 #endif
429  }
430  ++copyNumberTop_[ii];
431  zpos += hthickl;
432  }
433  if (std::abs(thickTot - thick) > tol2_) {
434  if (thickTot > thick) {
435  edm::LogError("HGCalGeom") << "DDHGCalMixRotatedLayer: Thickness of the partition " << cms::convert2mm(thick)
436  << " is smaller than " << cms::convert2mm(thickTot)
437  << ": thickness of all its components in the top part **** ERROR ****";
438  } else {
439  edm::LogWarning("HGCalGeom") << "DDHGCalMixRotatedLayer: Thickness of the partition " << cms::convert2mm(thick)
440  << " does not match with " << cms::convert2mm(thickTot)
441  << " of the components in top part";
442  }
443  }
444 
445  // Make the bottom part next
446  int layer = (copyM - firstLayer_);
447  static const double sqrt3 = std::sqrt(3.0);
448  int layercenter = layerOrient_[layer];
449  int layertype = HGCalTypes::layerFrontBack(layerOrient_[layer]);
450  int firstWafer = waferLayerStart_[layer];
451  int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
452  : static_cast<int>(waferIndex_.size()));
453  double delx = 0.5 * (waferSize_ + waferSepar_);
454  double dely = 2.0 * delx / sqrt3;
455  double dy = 0.75 * dely;
456  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
457 #ifdef EDM_ML_DEBUG
458  int ium(0), ivm(0), kount(0);
459  std::vector<int> ntype(3, 0);
460  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: " << glog.name() << " r " << cms::convert2mm(delx)
461  << " R " << cms::convert2mm(dely) << " dy " << cms::convert2mm(dy) << " Shift "
462  << cms::convert2mm(xyoff.first) << ":" << cms::convert2mm(xyoff.second)
463  << " WaferSize " << cms::convert2mm((waferSize_ + waferSepar_)) << " index "
464  << firstWafer << ":" << (lastWafer - 1);
465 #endif
466  for (int k = firstWafer; k < lastWafer; ++k) {
467  int u = HGCalWaferIndex::waferU(waferIndex_[k]);
468  int v = HGCalWaferIndex::waferV(waferIndex_[k]);
469 #ifdef EDM_ML_DEBUG
470  int iu = std::abs(u);
471  int iv = std::abs(v);
472 #endif
473  int nr = 2 * v;
474  int nc = -2 * u + v;
475  int type = HGCalProperty::waferThick(waferProperty_[k]);
476  int part = HGCalProperty::waferPartial(waferProperty_[k]);
477  int orien = HGCalProperty::waferOrient(waferProperty_[k]);
478  int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
479  int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
480 #ifdef EDM_ML_DEBUG
481  edm::LogVerbatim("HGCalGeom")
482  << "DDHGCalMixRotatedLayer::index:Property:layertype:type:part:orien:cassette:place:offsets:ind " << k << ":"
483  << waferProperty_[k] << ":" << layertype << ":" << type << ":" << part << ":" << orien << ":" << cassette
484  << ":" << place;
485 #endif
486  auto cshift = cassette_.getShift(layer + 1, -1, cassette);
487  double xpos = xyoff.first - cshift.first + nc * delx;
488  double ypos = xyoff.second + cshift.second + nr * dy;
489 #ifdef EDM_ML_DEBUG
490  double xorig = xyoff.first + nc * delx;
491  double yorig = xyoff.second + nr * dy;
492  double angle = std::atan2(yorig, xorig);
493  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer::Wafer: layer " << layer + 1 << " cassette " << cassette
494  << " Shift " << cms::convert2mm(cshift.first) << ":"
495  << cms::convert2mm(cshift.second) << " Original " << cms::convert2mm(xorig) << ":"
496  << cms::convert2mm(yorig) << ":" << convertRadToDeg(angle) << " Final "
497  << cms::convert2mm(xpos) << ":" << cms::convert2mm(ypos);
498 #endif
499  std::string wafer;
500  int i(999);
501  if (part == HGCalTypes::WaferFull) {
502  i = type * facingTypes_ * orientationTypes_ + place - placeOffset_;
503 #ifdef EDM_ML_DEBUG
504  edm::LogVerbatim("HGCalGeom") << " FullWafer type:place:ind " << type << ":" << place << ":" << i << ":"
505  << waferFull_.size();
506 #endif
507  wafer = waferFull_[i];
508  } else {
509  int partoffset =
511  i = (part - partoffset) * facingTypes_ * orientationTypes_ +
512  HGCalTypes::WaferTypeOffset[type] * facingTypes_ * orientationTypes_ + place - placeOffset_;
513 #ifdef EDM_ML_DEBUG
514  edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
515  << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
516  << partoffset << ":" << HGCalTypes::WaferTypeOffset[type] << ":" << i << ":"
517  << waferPart_.size();
518 #endif
519  wafer = waferPart_[i];
520  }
521  int copy = HGCalTypes::packTypeUV(type, u, v);
522 #ifdef EDM_ML_DEBUG
523  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedLayer: Layer " << HGCalWaferIndex::waferLayer(waferIndex_[k])
524  << " Wafer " << wafer << " number " << copy << " type :part:orien:ind " << type
525  << ":" << part << ":" << orien << ":" << i << " layer:u:v " << (layer + firstLayer_)
526  << ":" << u << ":" << v;
527  if (iu > ium)
528  ium = iu;
529  if (iv > ivm)
530  ivm = iv;
531  kount++;
532  if (copies_.count(copy) == 0)
533  copies_.insert(copy);
534 #endif
535  dd4hep::Position tran(xpos, ypos, 0.0);
536  glog.placeVolume(ns.volume(wafer), copy, tran);
537 #ifdef EDM_ML_DEBUG
538  ++ntype[type];
539  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedLayer: " << wafer << " number " << copy << " type "
540  << layertype << ":" << type << " positioned in " << glog.name() << " at ("
541  << cms::convert2mm(xpos) << "," << cms::convert2mm(ypos) << ",0) with no rotation";
542 #endif
543  }
544 
545 #ifdef EDM_ML_DEBUG
546  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedLayer: Maximum # of u " << ium << " # of v " << ivm << " and "
547  << kount << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ") for "
548  << glog.name();
549 #endif
550  }
551 
552  //Required data members to cache the values from XML file
555 
556  static constexpr double tol2_ = 0.00001 * dd4hep::mm;
557 
558  int waferTypes_; // Number of wafer types
559  int facingTypes_; // Types of facings of modules toward IP
560  int orientationTypes_; // Number of partial wafer orienations
561  int placeOffset_; // Offset for placement
562  int phiBinsScint_; // Maximum number of cells along phi
563  int forFireworks_; // Needed for Fireworks(1)/Geant4(0)
564  int firstLayer_; // Copy # of the first sensitive layer
565  int absorbMode_; // Absorber mode
566  int sensitiveMode_; // Sensitive mode
567  double zMinBlock_; // Starting z-value of the block
568  double waferSize_; // Width of the wafer
569  double waferSepar_; // Sensor separation
570  int sectors_; // Sectors
571  int cassettes_; // Cassettes
572  std::vector<double> slopeB_; // Slope at the lower R
573  std::vector<double> zFrontB_; // Starting Z values for the slopes
574  std::vector<double> rMinFront_; // Corresponding rMin's
575  std::vector<double> slopeT_; // Slopes at the larger R
576  std::vector<double> zFrontT_; // Starting Z values for the slopes
577  std::vector<double> rMaxFront_; // Corresponding rMax's
578  std::vector<std::string> waferFull_; // Names of full wafer modules
579  std::vector<std::string> waferPart_; // Names of partial wafer modules
580  std::vector<std::string> materials_; // Materials
581  std::vector<std::string> names_; // Names
582  std::vector<double> thick_; // Thickness of the material
583  std::vector<int> copyNumber_; // Initial copy numbers
584  std::vector<int> layers_; // Number of layers in a section
585  std::vector<double> layerThick_; // Thickness of each section
586  std::vector<int> layerType_; // Type of the layer
587  std::vector<int> layerSense_; // Content of a layer (sensitive?)
588  std::vector<std::string> materialTop_; // Materials of top layers
589  std::vector<std::string> namesTop_; // Names of top layers
590  std::vector<double> layerThickTop_; // Thickness of the top sections
591  std::vector<int> layerTypeTop_; // Type of the Top layer
592  std::vector<int> copyNumberTop_; // Initial copy numbers (top section)
593  std::vector<int> layerOrient_; // Layer orientation for the silicon component
594  std::vector<int> waferIndex_; // Wafer index for the types
595  std::vector<int> waferProperty_; // Wafer property
596  std::vector<int> waferLayerStart_; // Start index of wafers in each layer
597  std::vector<double> cassetteShift_; // Shifts of the cassetes
598  std::vector<double> tileRMin_; // Minimum radius of each ring
599  std::vector<double> tileRMax_; // Maximum radius of each ring
600  std::vector<int> tileIndex_; // Index of tile (layer/start|end ring)
601  std::vector<int> tilePhis_; // Tile phi range for each index
602  std::vector<int> tileLayerStart_; // Start index of tiles in each layer
603  std::unordered_set<int> copies_; // List of copy #'s
604  double alpha_, cosAlpha_;
605 };
606 
607 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
608  HGCalMixRotatedLayer mixRotatedLayerAlgo(ctxt, e);
609  return cms::s_executed;
610 }
611 
612 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:237
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)
static constexpr int32_t WaferTypeOffset[3]
Definition: HGCalTypes.h:61
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::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_
static std::string to_string(const XMLCh *ch)
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_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
static int cassetteType(int det, int zside, int cassette)
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
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
static constexpr int32_t layerFrontBack(int32_t layerOrient)
Definition: HGCalTypes.h:137