CMS 3D CMS Logo

DDHGCalMixRotatedCassette.cc
Go to the documentation of this file.
1 // File: DDHGCalMixRotatedCassette.cc
3 // Description: Geometry factory class for HGCal (Mix)
5 
27 
28 #include <cmath>
29 #include <memory>
30 #include <string>
31 #include <unordered_set>
32 #include <vector>
33 
34 //#define EDM_ML_DEBUG
35 using namespace angle_units::operators;
36 
37 class DDHGCalMixRotatedCassette : public DDAlgorithm {
38 public:
40 
41  void initialize(const DDNumericArguments& nArgs,
42  const DDVectorArguments& vArgs,
43  const DDMapArguments& mArgs,
44  const DDStringArguments& sArgs,
45  const DDStringVectorArguments& vsArgs) override;
46  void execute(DDCompactView& cpv) override;
47 
48 protected:
49  void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
50  void positionMix(const DDLogicalPart& glog,
51  const std::string& nameM,
52  int copyM,
53  double thick,
54  const DDMaterial& matter,
55  int absType,
56  DDCompactView& cpv);
57 
58 private:
61 
62  static constexpr double tol1_ = 0.01;
63  static constexpr double tol2_ = 0.00001;
64 
65  int waferTypes_; // Number of wafer types
66  int passiveTypes_; // Number of passive types
67  int facingTypes_; // Types of facings of modules toward IP
68  int orientationTypes_; // Number of partial wafer orienations
69  int partialTypes_; // Number of partial types
70  int placeOffset_; // Offset for placement
71  int phiBinsScint_; // Maximum number of cells along phi
72  int firstLayer_; // Copy # of the first sensitive layer
73  int absorbMode_; // Absorber mode
74  int sensitiveMode_; // Sensitive mode
75  double zMinBlock_; // Starting z-value of the block
76  double waferSize_; // Width of the wafer
77  double waferSepar_; // Sensor separation
78  int sectors_; // Sectors
79  int cassettes_; // Cassettes
80  std::vector<double> slopeB_; // Slope at the lower R
81  std::vector<double> zFrontB_; // Starting Z values for the slopes
82  std::vector<double> rMinFront_; // Corresponding rMin's
83  std::vector<double> slopeT_; // Slopes at the larger R
84  std::vector<double> zFrontT_; // Starting Z values for the slopes
85  std::vector<double> rMaxFront_; // Corresponding rMax's
86  std::vector<std::string> waferFull_; // Names of full wafer modules
87  std::vector<std::string> waferPart_; // Names of partial wafer modules
88  std::vector<std::string> passiveFull_; // Names of full passive modules
89  std::vector<std::string> passivePart_; // Names of partial passive modules
90  std::vector<std::string> materials_; // Materials
91  std::vector<std::string> names_; // Names
92  std::vector<double> thick_; // Thickness of the material
93  std::vector<int> copyNumber_; // Initial copy numbers
94  std::vector<int> layers_; // Number of layers in a section
95  std::vector<double> layerThick_; // Thickness of each section
96  std::vector<int> layerType_; // Type of the layer
97  std::vector<int> layerSense_; // Content of a layer (sensitive?)
98  std::vector<std::string> materialTop_; // Materials of top layers
99  std::vector<std::string> namesTop_; // Names of top layers
100  std::vector<double> layerThickTop_; // Thickness of the top sections
101  std::vector<int> layerTypeTop_; // Type of the Top layer
102  std::vector<int> copyNumberTop_; // Initial copy numbers (top section)
103  int coverTypeTop_; // Type of the Top layer cover
104  int copyNumberCoverTop_; // Initial copy number of top cover
105  std::vector<int> layerOrient_; // Layer orientation for the silicon component
106  std::vector<int> waferIndex_; // Wafer index for the types
107  std::vector<int> waferProperty_; // Wafer property
108  std::vector<int> waferLayerStart_; // Start index of wafers in each layer
109  std::vector<double> cassetteShift_; // Shifts of the cassetes
110  std::vector<double> tileRMin_; // Minimum radius of each ring
111  std::vector<double> tileRMax_; // Maximum radius of each ring
112  std::vector<int> tileIndex_; // Index of tile (layer/start|end ring)
113  std::vector<int> tilePhis_; // Tile phi range for each index
114  std::vector<int> tileLayerStart_; // Start index of tiles in each layer
115  std::string nameSpace_; // Namespace of this and ALL sub-parts
116  std::unordered_set<int> copies_; // List of copy #'s
117  double alpha_, cosAlpha_;
118 };
119 
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Creating an instance";
123 #endif
124 }
125 
127  const DDVectorArguments& vArgs,
128  const DDMapArguments&,
129  const DDStringArguments& sArgs,
130  const DDStringVectorArguments& vsArgs) {
131  waferTypes_ = static_cast<int>(nArgs["WaferTypes"]);
132  passiveTypes_ = static_cast<int>(nArgs["PassiveTypes"]);
133  facingTypes_ = static_cast<int>(nArgs["FacingTypes"]);
134  orientationTypes_ = static_cast<int>(nArgs["OrientationTypes"]);
135  partialTypes_ = static_cast<int>(nArgs["PartialTypes"]);
136  placeOffset_ = static_cast<int>(nArgs["PlaceOffset"]);
137  phiBinsScint_ = static_cast<int>(nArgs["NPhiBinScint"]);
138 #ifdef EDM_ML_DEBUG
139  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette::Number of types of wafers: " << waferTypes_
140  << " passives: " << passiveTypes_ << " facings: " << facingTypes_
141  << " Orientations: " << orientationTypes_ << " PartialTypes: " << partialTypes_
142  << " PlaceOffset: " << placeOffset_ << "; number of cells along phi " << phiBinsScint_;
143 #endif
144  firstLayer_ = (int)(nArgs["FirstLayer"]);
145  absorbMode_ = (int)(nArgs["AbsorberMode"]);
146  sensitiveMode_ = (int)(nArgs["SensitiveMode"]);
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette::First Layer " << firstLayer_ << " and "
149  << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
150 #endif
151  zMinBlock_ = nArgs["zMinBlock"];
152  waferSize_ = nArgs["waferSize"];
153  waferSepar_ = nArgs["SensorSeparation"];
154  sectors_ = static_cast<int>(nArgs["Sectors"]);
155  cassettes_ = static_cast<int>(nArgs["Cassettes"]);
156  alpha_ = (1._pi) / sectors_;
157  cosAlpha_ = cos(alpha_);
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: zStart " << zMinBlock_ << " wafer width " << waferSize_
160  << " separations " << waferSepar_ << " sectors " << sectors_ << ":"
161  << convertRadToDeg(alpha_) << ":" << cosAlpha_ << " with " << cassettes_
162  << " cassettes";
163 #endif
164  slopeB_ = vArgs["SlopeBottom"];
165  zFrontB_ = vArgs["ZFrontBottom"];
166  rMinFront_ = vArgs["RMinFront"];
167  slopeT_ = vArgs["SlopeTop"];
168  zFrontT_ = vArgs["ZFrontTop"];
169  rMaxFront_ = vArgs["RMaxFront"];
170 #ifdef EDM_ML_DEBUG
171  for (unsigned int i = 0; i < slopeB_.size(); ++i)
172  edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
173  << " Slope " << slopeB_[i];
174  for (unsigned int i = 0; i < slopeT_.size(); ++i)
175  edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
176  << " Slope " << slopeT_[i];
177 #endif
178  waferFull_ = vsArgs["WaferNamesFull"];
179  waferPart_ = vsArgs["WaferNamesPartial"];
180 #ifdef EDM_ML_DEBUG
181  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << waferFull_.size() << " full and "
182  << waferPart_.size() << " partial modules\nDDHGCalMixRotatedCassette:Full Modules:";
183  unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
184  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
185  std::ostringstream st1;
186  unsigned int i2 = std::min((i1 + 2), i1max);
187  for (unsigned int i = i1; i < i2; ++i)
188  st1 << " [" << i << "] " << waferFull_[i];
189  edm::LogVerbatim("HGCalGeom") << st1.str();
190  }
191  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Partial Modules:";
192  i1max = static_cast<unsigned int>(waferPart_.size());
193  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
194  std::ostringstream st1;
195  unsigned int i2 = std::min((i1 + 2), i1max);
196  for (unsigned int i = i1; i < i2; ++i)
197  st1 << " [" << i << "] " << waferPart_[i];
198  edm::LogVerbatim("HGCalGeom") << st1.str();
199  }
200 #endif
201  passiveFull_ = vsArgs["PassiveNamesFull"];
202  passivePart_ = vsArgs["PassiveNamesPartial"];
203 #ifdef EDM_ML_DEBUG
204  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << passiveFull_.size() << " full and "
205  << passivePart_.size() << " partial passive modules";
206  i1max = static_cast<unsigned int>(passiveFull_.size());
207  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
208  std::ostringstream st1;
209  unsigned int i2 = std::min((i1 + 2), i1max);
210  for (unsigned int i = i1; i < i2; ++i)
211  st1 << " [" << i << "] " << passiveFull_[i];
212  edm::LogVerbatim("HGCalGeom") << st1.str();
213  }
214  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Partial Modules:";
215  i1max = static_cast<unsigned int>(passivePart_.size());
216  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
217  std::ostringstream st1;
218  unsigned int i2 = std::min((i1 + 2), i1max);
219  for (unsigned int i = i1; i < i2; ++i)
220  st1 << " [" << i << "] " << passivePart_[i];
221  edm::LogVerbatim("HGCalGeom") << st1.str();
222  }
223 #endif
224  materials_ = vsArgs["MaterialNames"];
225  names_ = vsArgs["VolumeNames"];
226  thick_ = vArgs["Thickness"];
227  copyNumber_.resize(materials_.size(), 1);
228 #ifdef EDM_ML_DEBUG
229  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << materials_.size() << " types of volumes";
230  for (unsigned int i = 0; i < names_.size(); ++i)
231  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
232  << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
233 #endif
234  layers_ = dbl_to_int(vArgs["Layers"]);
235  layerThick_ = vArgs["LayerThick"];
236 #ifdef EDM_ML_DEBUG
237  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
238  for (unsigned int i = 0; i < layers_.size(); ++i)
239  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
240  << " layers";
241 #endif
242  layerType_ = dbl_to_int(vArgs["LayerType"]);
243  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
244  layerOrient_ = dbl_to_int(vArgs["LayerTypes"]);
245  for (unsigned int k = 0; k < layerOrient_.size(); ++k)
246  layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
247 #ifdef EDM_ML_DEBUG
248  for (unsigned int i = 0; i < layerOrient_.size(); ++i)
249  edm::LogVerbatim("HGCalGeom") << "LayerOrient [" << i << "] " << layerOrient_[i];
250 #endif
251  if (firstLayer_ > 0) {
252  for (unsigned int i = 0; i < layerType_.size(); ++i) {
253  if (layerSense_[i] != 0) {
254  int ii = layerType_[i];
255  copyNumber_[ii] = firstLayer_;
256 #ifdef EDM_ML_DEBUG
257  edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
258  << materials_[ii] << " changed to " << copyNumber_[ii];
259 #endif
260  }
261  }
262  } else {
263  firstLayer_ = 1;
264  }
265 #ifdef EDM_ML_DEBUG
266  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
267  for (unsigned int i = 0; i < layerType_.size(); ++i)
268  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
269  << layerSense_[i];
270 #endif
271  materialTop_ = vsArgs["TopMaterialNames"];
272  namesTop_ = vsArgs["TopVolumeNames"];
273  layerThickTop_ = vArgs["TopLayerThickness"];
274  layerTypeTop_ = dbl_to_int(vArgs["TopLayerType"]);
275  copyNumberTop_.resize(materialTop_.size(), firstLayer_);
276  coverTypeTop_ = static_cast<int>(nArgs["TopCoverLayerType"]);
277  copyNumberCoverTop_ = firstLayer_;
278 #ifdef EDM_ML_DEBUG
279  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << materialTop_.size()
280  << " types of volumes in the top part; cover Type " << coverTypeTop_
281  << " with initial copy number " << copyNumberCoverTop_;
282  for (unsigned int i = 0; i < materialTop_.size(); ++i)
283  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << namesTop_[i] << " of thickness " << layerThickTop_[i]
284  << " filled with " << materialTop_[i] << " first copy number " << copyNumberTop_[i];
285  edm::LogVerbatim("HGCalGeom") << "There are " << layerTypeTop_.size() << " layers in the top part";
286  for (unsigned int i = 0; i < layerTypeTop_.size(); ++i)
287  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerTypeTop_[i];
288 #endif
289  waferIndex_ = dbl_to_int(vArgs["WaferIndex"]);
290  waferProperty_ = dbl_to_int(vArgs["WaferProperties"]);
291  waferLayerStart_ = dbl_to_int(vArgs["WaferLayerStart"]);
292  cassetteShift_ = vArgs["CassetteShift"];
293 #ifdef EDM_ML_DEBUG
294  edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
295  << waferLayerStart_.size() << " layers";
296  for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
297  edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
298  for (unsigned int k = 0; k < waferIndex_.size(); ++k)
299  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << waferIndex_[k] << " ("
300  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
301  << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
302  << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
303  << HGCalProperty::waferThick(waferProperty_[k]) << ":"
304  << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
305  << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
306  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << cassetteShift_.size()
307  << " elements for cassette shifts";
308  unsigned int j1max = cassetteShift_.size();
309  for (unsigned int j1 = 0; j1 < j1max; j1 += 6) {
310  std::ostringstream st1;
311  unsigned int j2 = std::min((j1 + 6), j1max);
312  for (unsigned int j = j1; j < j2; ++j)
313  st1 << " [" << j << "] " << std::setw(9) << cassetteShift_[j];
314  edm::LogVerbatim("HGCalGeom") << st1.str();
315  }
316 #endif
317  tileRMin_ = vArgs["TileRMin"];
318  tileRMax_ = vArgs["TileRMax"];
319  tileIndex_ = dbl_to_int(vArgs["TileLayerRings"]);
320  tilePhis_ = dbl_to_int(vArgs["TilePhiRange"]);
321  tileLayerStart_ = dbl_to_int(vArgs["TileLayerStart"]);
322 #ifdef EDM_ML_DEBUG
323  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette:: with " << tileRMin_.size() << " rings";
324  for (unsigned int k = 0; k < tileRMin_.size(); ++k)
325  edm::LogVerbatim("HGCalGeom") << "Ring[" << k << "] " << tileRMin_[k] << " : " << tileRMax_[k];
326  edm::LogVerbatim("HGCalGeom") << "TileProperties with " << tileIndex_.size() << " entries in "
327  << tileLayerStart_.size() << " layers";
328  for (unsigned int k = 0; k < tileLayerStart_.size(); ++k)
329  edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << tileLayerStart_[k];
330  for (unsigned int k = 0; k < tileIndex_.size(); ++k)
331  edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << tileIndex_[k] << " ("
332  << "Layer " << std::get<0>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << " Ring "
333  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ":"
334  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[k])) << ") Phi "
335  << std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[k])) << ":"
336  << std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[k]));
337 #endif
338  nameSpace_ = DDCurrentNamespace::ns();
339 #ifdef EDM_ML_DEBUG
340  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: NameSpace " << nameSpace_ << ":";
341 #endif
342  cassette_.setParameter(cassettes_, cassetteShift_);
343 }
344 
346 // DDHGCalMixRotatedCassette methods...
348 
350 #ifdef EDM_ML_DEBUG
351  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalMixRotatedCassette...";
352  copies_.clear();
353 #endif
354  constructLayers(parent(), cpv);
355 #ifdef EDM_ML_DEBUG
356  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << copies_.size() << " different wafer copy numbers";
357  int k(0);
358  for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
359  edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
360  }
361  copies_.clear();
362  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalMixRotatedCassette construction...";
363 #endif
364 }
365 
367  double zi(zMinBlock_);
368  int laymin(0);
369  for (unsigned int i = 0; i < layers_.size(); i++) {
370  double zo = zi + layerThick_[i];
371  double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
372  int laymax = laymin + layers_[i];
373  double zz = zi;
374  double thickTot(0);
375  for (int ly = laymin; ly < laymax; ++ly) {
376  int ii = layerType_[ly];
377  int copy = copyNumber_[ii];
378  double hthick = 0.5 * thick_[ii];
379  double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_);
380  zz += hthick;
381  thickTot += thick_[ii];
382 
383  std::string name = names_[ii] + std::to_string(copy);
384 #ifdef EDM_ML_DEBUG
385  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Layer " << ly << ":" << ii << " Front " << zi << ", "
386  << routF << " Back " << zo << ", " << rinB << " superlayer thickness "
387  << layerThick_[i];
388 #endif
389  DDName matName(DDSplit(materials_[ii]).first, DDSplit(materials_[ii]).second);
390  DDMaterial matter(matName);
391  DDLogicalPart glog;
392  if (layerSense_[ly] == 0) {
393  std::vector<double> pgonZ, pgonRin, pgonRout;
394  double rmax =
395  (std::min(routF, HGCalGeomTools::radius(zz + hthick, zFrontT_, rMaxFront_, slopeT_)) * cosAlpha_) - tol1_;
396  HGCalGeomTools::radius(zz - hthick,
397  zz + hthick,
398  zFrontB_,
399  rMinFront_,
400  slopeB_,
401  zFrontT_,
402  rMaxFront_,
403  slopeT_,
404  -layerSense_[ly],
405  pgonZ,
406  pgonRin,
407  pgonRout);
408  for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
409  pgonZ[isec] -= zz;
410  if (layerSense_[ly] == 0 || absorbMode_ == 0)
411  pgonRout[isec] = rmax;
412  else
413  pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1_;
414  }
415  DDSolid solid =
416  DDSolidFactory::polyhedra(DDName(name, nameSpace_), sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
417  glog = DDLogicalPart(solid.ddname(), matter, solid);
418 #ifdef EDM_ML_DEBUG
419  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << solid.name() << " polyhedra of " << sectors_
420  << " sectors covering " << convertRadToDeg(-alpha_) << ":"
421  << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size() << " sections";
422  for (unsigned int k = 0; k < pgonZ.size(); ++k)
423  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
424 #endif
425  } else {
426  int mode = (layerSense_[ly] > 0) ? sensitiveMode_ : absorbMode_;
427  double rins = (mode < 1) ? rinB : HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
428  double routs = (mode < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
429  DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthick, rins, routs, 0.0, 2._pi);
430  glog = DDLogicalPart(solid.ddname(), matter, solid);
431 #ifdef EDM_ML_DEBUG
432  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << solid.name() << " Tubs made of " << matName
433  << " of dimensions " << rinB << ":" << rins << ", " << routF << ":" << routs
434  << ", " << hthick << ", 0.0, 360.0 and positioned in: " << glog.name()
435  << " number " << copy;
436 #endif
437  positionMix(glog, name, copy, thick_[ii], matter, -layerSense_[ly], cpv);
438  }
439  DDTranslation r1(0, 0, zz);
440  DDRotation rot;
441  cpv.position(glog, module, copy, r1, rot);
442  ++copyNumber_[ii];
443 #ifdef EDM_ML_DEBUG
444  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << glog.name() << " number " << copy
445  << " positioned in " << module.name() << " at " << r1 << " with no rotation";
446 #endif
447  zz += hthick;
448  } // End of loop over layers in a block
449  zi = zo;
450  laymin = laymax;
451  // Make consistency check of all the partitions of the block
452  if (std::abs(thickTot - layerThick_[i]) >= tol2_) {
453  if (thickTot > layerThick_[i]) {
454  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than " << thickTot
455  << ": thickness of all its components **** ERROR ****";
456  } else {
457  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
458  << thickTot << " of the components";
459  }
460  }
461  } // End of loop over blocks
462 }
463 
465  const std::string& nameM,
466  int copyM,
467  double thick,
468  const DDMaterial& matter,
469  int absType,
470  DDCompactView& cpv) {
471  DDRotation rot;
472 
473  // Make the top part first
474  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
475  int ii = layerTypeTop_[ly];
476  copyNumberTop_[ii] = copyM;
477  }
478  double hthick = 0.5 * thick;
479  double dphi = (2._pi) / phiBinsScint_;
480  double thickTot(0), zpos(-hthick);
481  if (absType < 0) {
482  for (unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
483  int ii = layerTypeTop_[ly];
484  int copy = copyNumberTop_[ii];
485  int layer = copy - firstLayer_;
486  double hthickl = 0.5 * layerThickTop_[ii];
487  thickTot += layerThickTop_[ii];
488  zpos += hthickl;
489  DDName matName(DDSplit(materialTop_[ii]).first, DDSplit(materialTop_[ii]).second);
490  DDMaterial matter1(matName);
491  unsigned int k = 0;
492  int firstTile = tileLayerStart_[layer];
493  int lastTile = ((layer + 1 < static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
494  : static_cast<int>(tileIndex_.size()));
495 #ifdef EDM_ML_DEBUG
496  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Layer " << ly << ":" << ii << " Copy " << copy
497  << " Tiles " << firstTile << ":" << lastTile;
498 #endif
499  for (int ti = firstTile; ti < lastTile; ++ti) {
500  double r1 = tileRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
501  double r2 = tileRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
502  int cassette = std::get<0>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
503  int fimin = std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
504  int fimax = std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
505  double phi1 = dphi * (fimin - 1);
506  double phi2 = dphi * (fimax - fimin + 1);
507  auto cshift = cassette_.getShift(layer + 1, 1, cassette);
508 #ifdef EDM_ML_DEBUG
509  int cassette0 = HGCalCassette::cassetteType(2, 1, cassette); //
510  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Layer " << copy << ":" << (layer + 1) << " iR "
511  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << ":"
512  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << " R " << r1 << ":"
513  << r2 << " Thick " << (2.0 * hthickl) << " phi " << fimin << ":" << fimax << ":"
514  << convertRadToDeg(phi1) << ":" << convertRadToDeg(phi2) << " cassette "
515  << cassette << ":" << cassette0 << " Shift " << cshift.first << ":"
516  << cshift.second;
517 #endif
518  std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
519  ++k;
520  DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthickl, r1, r2, phi1, phi2);
521  DDLogicalPart glog1 = DDLogicalPart(solid.ddname(), matter1, solid);
522 #ifdef EDM_ML_DEBUG
523  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << glog1.name() << " Tubs made of " << matName
524  << " of dimensions " << r1 << ", " << r2 << ", " << hthickl << ", "
525  << convertRadToDeg(phi1) << ", " << convertRadToDeg(phi2);
526 #endif
527  DDTranslation tran(-cshift.first, cshift.second, zpos);
528  cpv.position(glog1, glog, copy, tran, rot);
529 #ifdef EDM_ML_DEBUG
530  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Position " << glog1.name() << " number " << copy
531  << " in " << glog.name() << " at " << tran << " with no rotation";
532 #endif
533  }
534  ++copyNumberTop_[ii];
535  zpos += hthickl;
536  }
537  if (std::abs(thickTot - thick) >= tol2_) {
538  if (thickTot > thick) {
539  edm::LogError("HGCalGeom") << "DDHGCalMixRotatedCassette: Thickness of the partition " << thick
540  << " is smaller than " << thickTot
541  << ": thickness of all its components in the top part **** ERROR ****";
542  } else {
543  edm::LogWarning("HGCalGeom") << "DDHGCalMixRotatedCassette: Thickness of the partition " << thick
544  << " does not match with " << thickTot << " of the components in top part";
545  }
546  }
547  } else {
548  int ii = coverTypeTop_;
549  int copy = copyNumberCoverTop_;
550  int layer = copy - firstLayer_;
551  double hthickl = 0.5 * layerThickTop_[ii];
552  zpos += hthickl;
553  DDName matName(DDSplit(materialTop_[ii]).first, DDSplit(materialTop_[ii]).second);
554  DDMaterial matter1(matName);
555  unsigned int k = 0;
556  int firstTile = tileLayerStart_[layer];
557  int lastTile = ((layer + 1 < static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
558  : static_cast<int>(tileIndex_.size()));
559 #ifdef EDM_ML_DEBUG
560  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Layer " << layer << ":" << ii << " Copy " << copy
561  << " Tiles " << firstTile << ":" << lastTile;
562 #endif
563  for (int ti = firstTile; ti < lastTile; ++ti) {
564  double r1 = tileRMin_[std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
565  double r2 = tileRMax_[std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) - 1];
566  int cassette = std::get<0>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
567  int fimin = std::get<1>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
568  int fimax = std::get<2>(HGCalTileIndex::tileUnpack(tilePhis_[ti]));
569  double phi1 = dphi * (fimin - 1);
570  double phi2 = dphi * (fimax - fimin + 1);
571  auto cshift = cassette_.getShift(layer + 1, 1, cassette);
572 #ifdef EDM_ML_DEBUG
573  int cassette0 = HGCalCassette::cassetteType(2, 1, cassette); //
574  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Layer " << copy << ":" << (layer + 1) << " iR "
575  << std::get<1>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << ":"
576  << std::get<2>(HGCalTileIndex::tileUnpack(tileIndex_[ti])) << " R " << r1 << ":"
577  << r2 << " Thick " << (2.0 * hthickl) << " phi " << fimin << ":" << fimax << ":"
578  << convertRadToDeg(phi1) << ":" << convertRadToDeg(phi2) << " cassette " << cassette
579  << ":" << cassette0 << " Shift " << cshift.first << ":" << cshift.second;
580 #endif
581  std::string name = namesTop_[ii] + "L" + std::to_string(copy) + "F" + std::to_string(k);
582  ++k;
583  DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthickl, r1, r2, phi1, phi2);
584  DDLogicalPart glog1 = DDLogicalPart(solid.ddname(), matter1, solid);
585 #ifdef EDM_ML_DEBUG
586  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: " << glog1.name() << " Tubs made of " << matName
587  << " of dimensions " << r1 << ", " << r2 << ", " << hthickl << ", "
588  << convertRadToDeg(phi1) << ", " << convertRadToDeg(phi2);
589 #endif
590  DDTranslation tran(-cshift.first, cshift.second, zpos);
591  cpv.position(glog1, glog, copy, tran, rot);
592 #ifdef EDM_ML_DEBUG
593  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Position " << glog1.name() << " number " << copy
594  << " in " << glog.name() << " at " << tran << " with no rotation";
595 #endif
596  }
597  ++copyNumberCoverTop_;
598  zpos += hthickl;
599  }
600 
601  // Make the bottom part next
602  int layer = (copyM - firstLayer_);
603  static const double sqrt3 = std::sqrt(3.0);
604  int layercenter = layerOrient_[layer];
605  int layertype = HGCalTypes::layerFrontBack(layerOrient_[layer]);
606  int firstWafer = waferLayerStart_[layer];
607  int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
608  : static_cast<int>(waferIndex_.size()));
609  double delx = 0.5 * (waferSize_ + waferSepar_);
610  double dely = 2.0 * delx / sqrt3;
611  double dy = 0.75 * dely;
612  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
613 #ifdef EDM_ML_DEBUG
614  int ium(0), ivm(0), kount(0);
615  std::vector<int> ntype(3, 0);
616  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette::Bottom: " << glog.ddname() << " r " << delx << " R "
617  << dely << " dy " << dy << " Shift " << xyoff.first << ":" << xyoff.second
618  << " WaferSize " << (waferSize_ + waferSepar_) << " index " << firstWafer << ":"
619  << (lastWafer - 1) << " Copy " << copyM << ":" << layer;
620 #endif
621  for (int k = firstWafer; k < lastWafer; ++k) {
622  int u = HGCalWaferIndex::waferU(waferIndex_[k]);
623  int v = HGCalWaferIndex::waferV(waferIndex_[k]);
624 #ifdef EDM_ML_DEBUG
625  int iu = std::abs(u);
626  int iv = std::abs(v);
627 #endif
628  int nr = 2 * v;
629  int nc = -2 * u + v;
630  int type = HGCalProperty::waferThick(waferProperty_[k]);
631  int part = HGCalProperty::waferPartial(waferProperty_[k]);
632  int orien = HGCalProperty::waferOrient(waferProperty_[k]);
633  int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
634  int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
635 #ifdef EDM_ML_DEBUG
636  edm::LogVerbatim("HGCalGeom")
637  << "DDHGCalMixRotatedCassette::index:Property:layertype:type:part:orien:cassette:place:offsets:ind " << k << ":"
638  << waferProperty_[k] << ":" << layertype << ":" << type << ":" << part << ":" << orien << ":" << cassette << ":"
639  << place;
640 #endif
641  auto cshift = cassette_.getShift(layer + 1, -1, cassette);
642  double xpos = xyoff.first - cshift.first + nc * delx;
643  double ypos = xyoff.second + cshift.second + nr * dy;
644 #ifdef EDM_ML_DEBUG
645  double xorig = xyoff.first + nc * delx;
646  double yorig = xyoff.second + nr * dy;
647  double angle = std::atan2(yorig, xorig);
648  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette::Wafer: layer " << layer + 1 << " cassette " << cassette
649  << " Shift " << cshift.first << ":" << cshift.second << " Original " << xorig << ":"
650  << yorig << ":" << convertRadToDeg(angle) << " Final " << xpos << ":" << ypos;
651 #endif
652  std::string wafer;
653  int i(999);
654  if (absType < 0) {
655  if (part == HGCalTypes::WaferFull) {
656  i = type * facingTypes_ * orientationTypes_ + place - placeOffset_;
657 #ifdef EDM_ML_DEBUG
658  edm::LogVerbatim("HGCalGeom") << " FullWafer type:place:ind " << type << ":" << place << ":" << i << ":"
659  << waferFull_.size();
660 #endif
661  wafer = waferFull_[i];
662  } else {
663  int partoffset =
665  i = (part - partoffset) * facingTypes_ * orientationTypes_ +
666  HGCalTypes::WaferTypeOffset[type] * facingTypes_ * orientationTypes_ + place - placeOffset_;
667 #ifdef EDM_ML_DEBUG
668  edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
669  << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
670  << partoffset << ":" << HGCalTypes::WaferTypeOffset[type] << ":" << i << ":"
671  << waferPart_.size();
672 #endif
673  wafer = waferPart_[i];
674  }
675  } else {
676  type = absType;
677  if (part == HGCalTypes::WaferFull) {
678  i = absType - 1;
679  wafer = passiveFull_[i];
680 #ifdef EDM_ML_DEBUG
681  edm::LogVerbatim("HGCalGeom") << " layertype:abstype:part:orien:cassette:offsets:ind " << layertype << ":"
682  << absType << ":" << part << ":" << orien << ":" << cassette << ":"
683  << ":" << partialTypes_ << ":" << orientationTypes_ << " passive " << i << ":"
684  << wafer;
685 #endif
686  } else {
687  int partoffset = (part >= HGCalTypes::WaferHDTop)
690  i = (part - partoffset) * facingTypes_ * orientationTypes_ +
691  (absType - 1) * facingTypes_ * orientationTypes_ * partialTypes_ + place - placeOffset_;
692 #ifdef EDM_ML_DEBUG
693  edm::LogVerbatim("HGCalGeom") << " layertype:abstype:part:orien:cassette:3Types:offset:ind " << layertype << ":"
694  << absType << ":" << part << ":" << orien << ":" << cassette << ":"
695  << partialTypes_ << ":" << facingTypes_ << ":" << orientationTypes_ << ":"
696  << partoffset << ":" << i << ":" << passivePart_.size();
697 #endif
698  wafer = passivePart_[i];
699  }
700  }
701  int copy = HGCalTypes::packTypeUV(type, u, v);
702 #ifdef EDM_ML_DEBUG
703  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedCassette: Layer " << HGCalWaferIndex::waferLayer(waferIndex_[k])
704  << " Wafer " << wafer << " number " << copy << " type :part:orien:ind " << type << ":"
705  << part << ":" << orien << ":" << i << " layer:u:v " << (layer + firstLayer_) << ":"
706  << u << ":" << v;
707  if (iu > ium)
708  ium = iu;
709  if (iv > ivm)
710  ivm = iv;
711  kount++;
712  if (copies_.count(copy) == 0)
713  copies_.insert(copy);
714 #endif
715  DDTranslation tran(xpos, ypos, 0.0);
716  DDName name = DDName(DDSplit(wafer).first, DDSplit(wafer).second);
717  cpv.position(name, glog.ddname(), copy, tran, rot);
718 #ifdef EDM_ML_DEBUG
719  ++ntype[type];
720  edm::LogVerbatim("HGCalGeom") << " DDHGCalMixRotatedCassette: " << name << " number " << copy << " type "
721  << layertype << ":" << type << " positioned in " << glog.ddname() << " at " << tran
722  << " with no rotation";
723 #endif
724  }
725 #ifdef EDM_ML_DEBUG
726  edm::LogVerbatim("HGCalGeom") << "DDHGCalMixRotatedCassette: Maximum # of u " << ium << " # of v " << ivm << " and "
727  << kount << " wafers (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2] << ") for "
728  << glog.ddname();
729 #endif
730 }
731 
732 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalMixRotatedCassette, "hgcal:DDHGCalMixRotatedCassette");
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
Definition: HGCalCell.cc:237
static constexpr int32_t WaferPartLDOffset
Definition: HGCalTypes.h:57
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::unordered_set< int > copies_
int32_t *__restrict__ iv
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
static constexpr int32_t WaferTypeOffset[3]
Definition: HGCalTypes.h:59
DDMaterial is used to define and access material information.
Definition: DDMaterial.h:45
void positionMix(const DDLogicalPart &glog, const std::string &nameM, int copyM, double thick, const DDMaterial &matter, int absType, DDCompactView &cpv)
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
void execute(DDCompactView &cpv) override
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
std::vector< std::string > names_
static std::string & ns()
Log< level::Error, false > LogError
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
int32_t waferOrient(const int32_t property)
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
static std::string to_string(const XMLCh *ch)
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
int32_t waferCassette(const int32_t property)
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< std::string > namesTop_
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void constructLayers(const cms::DDNamespace &ns, const std::vector< std::string > &wafers, const std::vector< std::string > &covers, const std::vector< int > &layerType, const std::vector< int > &layerSense, const std::vector< int > &maxModule, const std::vector< std::string > &names, const std::vector< std::string > &materials, std::vector< int > &copyNumber, const std::vector< double > &layerThick, const double &absorbW, const double &absorbH, const double &waferTot, const double &rMax, const double &rMaxFine, std::unordered_set< int > &copies, int firstLayer, int lastLayer, double zFront, double totalWidth, bool ignoreCenter, dd4hep::Volume &module)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
std::vector< std::string > waferFull_
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
Definition: DDSolid.cc:667
int32_t waferThick(const int32_t property)
ii
Definition: cuy.py:589
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
Definition: DDutils.h:7
const N & name() const
Definition: DDBase.h:59
std::tuple< int32_t, int32_t, int32_t > tileUnpack(int32_t index)
static constexpr int32_t WaferPartHDOffset
Definition: HGCalTypes.h:58
std::vector< std::string > passivePart_
part
Definition: HCALResponse.h:20
const N & ddname() const
Definition: DDBase.h:61
std::vector< std::string > materialTop_
std::vector< std::string > passiveFull_
int32_t waferPartial(const int32_t property)
int32_t waferV(const int32_t index)
static int32_t packTypeUV(int type, int u, int v)
Definition: HGCalTypes.cc:3
static constexpr int32_t WaferHDTop
Definition: HGCalTypes.h:51
#define DEFINE_EDM_PLUGIN(factory, type, name)
Log< level::Warning, false > LogWarning
static int32_t layerType(int type)
Definition: HGCalTypes.cc:42
std::vector< std::string > materials_
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
std::vector< std::string > waferPart_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
Definition: DDSolid.cc:565
static int32_t layerFrontBack(int32_t layerOrient)
Definition: HGCalTypes.h:125
static int cassetteType(int det, int zside, int cassette)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11