CMS 3D CMS Logo

DDHGCalSiliconRotatedCassette.cc
Go to the documentation of this file.
1 // File: DDHGCalSiliconRotatedCassette.cc
3 // Description: Geometry factory class for HGCal (EE and HESil) using
4 // information from the file
6 
27 
28 #include <cmath>
29 #include <memory>
30 #include <sstream>
31 #include <string>
32 #include <unordered_set>
33 #include <vector>
34 
35 //#define EDM_ML_DEBUG
36 using namespace angle_units::operators;
37 
38 class DDHGCalSiliconRotatedCassette : public DDAlgorithm {
39 public:
41 
42  void initialize(const DDNumericArguments& nArgs,
43  const DDVectorArguments& vArgs,
44  const DDMapArguments& mArgs,
45  const DDStringArguments& sArgs,
46  const DDStringVectorArguments& vsArgs) override;
47  void execute(DDCompactView& cpv) override;
48 
49 protected:
50  void constructLayers(const DDLogicalPart&, DDCompactView& cpv);
51  void positionSensitive(const DDLogicalPart& glog, int layer, DDCompactView& cpv);
52  void positionPassive(const DDLogicalPart& glog, int layer, int passiveType, DDCompactView& cpv);
53 
54 private:
57 
58  static constexpr double tol1_ = 0.01;
59  static constexpr double tol2_ = 0.00001;
60 
61  int waferTypes_; // Number of wafer types
62  int passiveTypes_; // Number of passive types
63  int facingTypes_; // Types of facings of modules toward IP
64  int orientationTypes_; // Number of wafer orienations
65  int partialTypes_; // Number of partial types
66  int placeOffset_; // Offset for placement
67  int firstLayer_; // Copy # of the first sensitive layer
68  int absorbMode_; // Absorber mode
69  int sensitiveMode_; // Sensitive mode
70  double zMinBlock_; // Starting z-value of the block
71  double waferSize_; // Width of the wafer
72  double waferSepar_; // Sensor separation
73  int sectors_; // Sectors
74  int cassettes_; // Cassettes
75  std::string rotstr_; // Rotation matrix (if needed)
76  std::vector<std::string> waferFull_; // Names of full wafer modules
77  std::vector<std::string> waferPart_; // Names of partial wafer modules
78  std::vector<std::string> passiveFull_; // Names of full passive modules
79  std::vector<std::string> passivePart_; // Names of partial passive modules
80  std::vector<std::string> materials_; // names of materials
81  std::vector<std::string> names_; // Names of volumes
82  std::vector<double> thick_; // Thickness of the material
83  std::vector<int> copyNumber_; // Initial copy numbers
84  std::vector<int> layers_; // Number of layers in a section
85  std::vector<double> layerThick_; // Thickness of each section
86  std::vector<int> layerType_; // Type of the layer
87  std::vector<int> layerSense_; // Content of a layer (sensitive?)
88  std::vector<double> slopeB_; // Slope at the lower R
89  std::vector<double> zFrontB_; // Starting Z values for the slopes
90  std::vector<double> rMinFront_; // Corresponding rMin's
91  std::vector<double> slopeT_; // Slopes at the larger R
92  std::vector<double> zFrontT_; // Starting Z values for the slopes
93  std::vector<double> rMaxFront_; // Corresponding rMax's
94  std::vector<int> layerOrient_; // Layer orientation (Centering, rotations..)
95  std::vector<int> waferIndex_; // Wafer index for the types
96  std::vector<int> waferProperty_; // Wafer property
97  std::vector<int> waferLayerStart_; // Index of wafers in each layer
98  std::vector<double> cassetteShift_; // Shifts of the cassetes
99  std::string nameSpace_; // Namespace of this and ALL sub-parts
100  std::unordered_set<int> copies_; // List of copy #'s
101  double alpha_, cosAlpha_;
102 };
103 
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Creating an instance";
107 #endif
108 }
109 
111  const DDVectorArguments& vArgs,
112  const DDMapArguments&,
113  const DDStringArguments& sArgs,
114  const DDStringVectorArguments& vsArgs) {
115  waferTypes_ = static_cast<int>(nArgs["WaferTypes"]);
116  passiveTypes_ = static_cast<int>(nArgs["PassiveTypes"]);
117  facingTypes_ = static_cast<int>(nArgs["FacingTypes"]);
118  orientationTypes_ = static_cast<int>(nArgs["OrientationTypes"]);
119  partialTypes_ = static_cast<int>(nArgs["PartialTypes"]);
120  placeOffset_ = static_cast<int>(nArgs["PlaceOffset"]);
121 #ifdef EDM_ML_DEBUG
122  edm::LogVerbatim("HGCalGeom") << "Number of types of wafers: " << waferTypes_ << " passives: " << passiveTypes_
123  << " facings: " << facingTypes_ << " Orientations: " << orientationTypes_
124  << " PartialTypes: " << partialTypes_ << " PlaceOffset: " << placeOffset_;
125 #endif
126  firstLayer_ = static_cast<int>(nArgs["FirstLayer"]);
127  absorbMode_ = static_cast<int>(nArgs["AbsorberMode"]);
128  sensitiveMode_ = static_cast<int>(nArgs["SensitiveMode"]);
129 #ifdef EDM_ML_DEBUG
130  edm::LogVerbatim("HGCalGeom") << "First Layer " << firstLayer_ << " and "
131  << "Absober:Sensitive mode " << absorbMode_ << ":" << sensitiveMode_;
132 #endif
133  zMinBlock_ = nArgs["zMinBlock"];
134  waferSize_ = nArgs["waferSize"];
135  waferSepar_ = nArgs["SensorSeparation"];
136  sectors_ = static_cast<int>(nArgs["Sectors"]);
137  cassettes_ = static_cast<int>(nArgs["Cassettes"]);
138  alpha_ = (1._pi) / sectors_;
139  cosAlpha_ = cos(alpha_);
140  rotstr_ = sArgs["LayerRotation"];
141 #ifdef EDM_ML_DEBUG
142  edm::LogVerbatim("HGCalGeom") << "zStart " << zMinBlock_ << " wafer width " << waferSize_ << " separations "
143  << waferSepar_ << " sectors " << sectors_ << ":" << convertRadToDeg(alpha_) << ":"
144  << cosAlpha_ << " rotation matrix " << rotstr_ << " with " << cassettes_
145  << " cassettes";
146 #endif
147  waferFull_ = vsArgs["WaferNamesFull"];
148  waferPart_ = vsArgs["WaferNamesPartial"];
149 #ifdef EDM_ML_DEBUG
150  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << waferFull_.size() << " full and "
151  << waferPart_.size() << " partial modules";
152  unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
153  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
154  std::ostringstream st1;
155  unsigned int i2 = std::min((i1 + 2), i1max);
156  for (unsigned int i = i1; i < i2; ++i)
157  st1 << " [" << i << "] " << waferFull_[i];
158  edm::LogVerbatim("HGCalGeom") << st1.str();
159  }
160  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Partial Modules:";
161  i1max = static_cast<unsigned int>(waferPart_.size());
162  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
163  std::ostringstream st1;
164  unsigned int i2 = std::min((i1 + 2), i1max);
165  for (unsigned int i = i1; i < i2; ++i)
166  st1 << " [" << i << "] " << waferPart_[i];
167  edm::LogVerbatim("HGCalGeom") << st1.str();
168  }
169 #endif
170  passiveFull_ = vsArgs["PassiveNamesFull"];
171  passivePart_ = vsArgs["PassiveNamesPartial"];
172 #ifdef EDM_ML_DEBUG
173  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << passiveFull_.size() << " full and "
174  << passivePart_.size() << " partial passive modules";
175  i1max = static_cast<unsigned int>(passiveFull_.size());
176  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
177  std::ostringstream st1;
178  unsigned int i2 = std::min((i1 + 2), i1max);
179  for (unsigned int i = i1; i < i2; ++i)
180  st1 << " [" << i << "] " << passiveFull_[i];
181  edm::LogVerbatim("HGCalGeom") << st1.str();
182  }
183  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Partial Modules:";
184  i1max = static_cast<unsigned int>(passivePart_.size());
185  for (unsigned int i1 = 0; i1 < i1max; i1 += 2) {
186  std::ostringstream st1;
187  unsigned int i2 = std::min((i1 + 2), i1max);
188  for (unsigned int i = i1; i < i2; ++i)
189  st1 << " [" << i << "] " << passivePart_[i];
190  edm::LogVerbatim("HGCalGeom") << st1.str();
191  }
192 #endif
193  materials_ = vsArgs["MaterialNames"];
194  names_ = vsArgs["VolumeNames"];
195  thick_ = vArgs["Thickness"];
196  copyNumber_.resize(materials_.size(), 1);
197 #ifdef EDM_ML_DEBUG
198  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << materials_.size() << " types of volumes";
199  for (unsigned int i = 0; i < names_.size(); ++i)
200  edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << names_[i] << " of thickness " << thick_[i]
201  << " filled with " << materials_[i] << " first copy number " << copyNumber_[i];
202 #endif
203  layers_ = dbl_to_int(vArgs["Layers"]);
204  layerThick_ = vArgs["LayerThick"];
205 #ifdef EDM_ML_DEBUG
206  edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks";
207  for (unsigned int i = 0; i < layers_.size(); ++i)
208  edm::LogVerbatim("HGCalGeom") << "Block [" << i << "] of thickness " << layerThick_[i] << " with " << layers_[i]
209  << " layers";
210 #endif
211  layerType_ = dbl_to_int(vArgs["LayerType"]);
212  layerSense_ = dbl_to_int(vArgs["LayerSense"]);
213  layerOrient_ = dbl_to_int(vArgs["LayerTypes"]);
214  for (unsigned int k = 0; k < layerOrient_.size(); ++k)
215  layerOrient_[k] = HGCalTypes::layerType(layerOrient_[k]);
216 #ifdef EDM_ML_DEBUG
217  for (unsigned int i = 0; i < layerOrient_.size(); ++i)
218  edm::LogVerbatim("HGCalGeom") << "LayerTypes [" << i << "] " << layerOrient_[i];
219 #endif
220  if (firstLayer_ > 0) {
221  for (unsigned int i = 0; i < layerType_.size(); ++i) {
222  if (layerSense_[i] > 0) {
223  int ii = layerType_[i];
224  copyNumber_[ii] = (layerSense_[i] == 1) ? firstLayer_ : (firstLayer_ + 1);
225 #ifdef EDM_ML_DEBUG
226  edm::LogVerbatim("HGCalGeom") << "First copy number for layer type " << i << ":" << ii << " with "
227  << materials_[ii] << " changed to " << copyNumber_[ii];
228 #endif
229  }
230  }
231  } else {
232  firstLayer_ = 1;
233  }
234 #ifdef EDM_ML_DEBUG
235  edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " layers";
236  for (unsigned int i = 0; i < layerType_.size(); ++i)
237  edm::LogVerbatim("HGCalGeom") << "Layer [" << i << "] with material type " << layerType_[i] << " sensitive class "
238  << layerSense_[i];
239 #endif
240  slopeB_ = vArgs["SlopeBottom"];
241  zFrontB_ = vArgs["ZFrontBottom"];
242  rMinFront_ = vArgs["RMinFront"];
243  slopeT_ = vArgs["SlopeTop"];
244  zFrontT_ = vArgs["ZFrontTop"];
245  rMaxFront_ = vArgs["RMaxFront"];
246 #ifdef EDM_ML_DEBUG
247  for (unsigned int i = 0; i < slopeB_.size(); ++i)
248  edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
249  << " Slope " << slopeB_[i];
250  for (unsigned int i = 0; i < slopeT_.size(); ++i)
251  edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
252  << " Slope " << slopeT_[i];
253 #endif
254  waferIndex_ = dbl_to_int(vArgs["WaferIndex"]);
255  waferProperty_ = dbl_to_int(vArgs["WaferProperties"]);
256  waferLayerStart_ = dbl_to_int(vArgs["WaferLayerStart"]);
257  cassetteShift_ = vArgs["CassetteShift"];
258 #ifdef EDM_ML_DEBUG
259  edm::LogVerbatim("HGCalGeom") << "waferProperties with " << waferIndex_.size() << " entries in "
260  << waferLayerStart_.size() << " layers";
261  for (unsigned int k = 0; k < waferLayerStart_.size(); ++k)
262  edm::LogVerbatim("HGCalGeom") << "LayerStart[" << k << "] " << waferLayerStart_[k];
263  for (unsigned int k = 0; k < waferIndex_.size(); ++k)
264  edm::LogVerbatim("HGCalGeom") << "Wafer[" << k << "] " << waferIndex_[k] << " ("
265  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << ", "
266  << HGCalWaferIndex::waferU(waferIndex_[k]) << ", "
267  << HGCalWaferIndex::waferV(waferIndex_[k]) << ") : ("
268  << HGCalProperty::waferThick(waferProperty_[k]) << ":"
269  << HGCalProperty::waferPartial(waferProperty_[k]) << ":"
270  << HGCalProperty::waferOrient(waferProperty_[k]) << ")";
271  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << cassetteShift_.size()
272  << " elements for cassette shifts";
273  unsigned int j1max = cassetteShift_.size();
274  for (unsigned int j1 = 0; j1 < j1max; j1 += 6) {
275  std::ostringstream st1;
276  unsigned int j2 = std::min((j1 + 6), j1max);
277  for (unsigned int j = j1; j < j2; ++j)
278  st1 << " [" << j << "] " << std::setw(9) << cassetteShift_[j];
279  edm::LogVerbatim("HGCalGeom") << st1.str();
280  }
281 #endif
282  nameSpace_ = DDCurrentNamespace::ns();
283 #ifdef EDM_ML_DEBUG
284  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: NameSpace " << nameSpace_ << ":";
285 #endif
286  cassette_.setParameter(cassettes_, cassetteShift_);
287 }
288 
290 // DDHGCalSiliconRotatedCassette methods...
292 
294 #ifdef EDM_ML_DEBUG
295  edm::LogVerbatim("HGCalGeom") << "==>> Constructing DDHGCalSiliconRotatedCassette...";
296  copies_.clear();
297 #endif
298  constructLayers(parent(), cpv);
299 #ifdef EDM_ML_DEBUG
300  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << copies_.size()
301  << " different wafer copy numbers";
302  int k(0);
303  for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++k) {
304  edm::LogVerbatim("HGCalGeom") << "Copy [" << k << "] : " << (*itr);
305  }
306  copies_.clear();
307  edm::LogVerbatim("HGCalGeom") << "<<== End of DDHGCalSiliconRotatedCassette construction...";
308 #endif
309 }
310 
312  double zi(zMinBlock_);
313  int laymin(0);
314  for (unsigned int i = 0; i < layers_.size(); i++) {
315  double zo = zi + layerThick_[i];
316  double routF = HGCalGeomTools::radius(zi, zFrontT_, rMaxFront_, slopeT_);
317  int laymax = laymin + layers_[i];
318  double zz = zi;
319  double thickTot(0);
320  for (int ly = laymin; ly < laymax; ++ly) {
321  int ii = layerType_[ly];
322  int copy = copyNumber_[ii];
323  double hthick = 0.5 * thick_[ii];
324  double rinB = HGCalGeomTools::radius(zo - tol1_, zFrontB_, rMinFront_, slopeB_);
325  zz += hthick;
326  thickTot += thick_[ii];
327 
328  std::string name = names_[ii] + std::to_string(copy);
329 #ifdef EDM_ML_DEBUG
330  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Layer " << ly << ":" << ii << " Front " << zi
331  << ", " << routF << " Back " << zo << ", " << rinB << " superlayer thickness "
332  << layerThick_[i];
333 #endif
334  DDName matName(DDSplit(materials_[ii]).first, DDSplit(materials_[ii]).second);
335  DDMaterial matter(matName);
336  DDLogicalPart glog;
337  if (layerSense_[ly] == 0) {
338  std::vector<double> pgonZ, pgonRin, pgonRout;
339  double rmax = routF * cosAlpha_ - tol1_;
340  HGCalGeomTools::radius(zz - hthick,
341  zz + hthick,
342  zFrontB_,
343  rMinFront_,
344  slopeB_,
345  zFrontT_,
346  rMaxFront_,
347  slopeT_,
348  -layerSense_[ly],
349  pgonZ,
350  pgonRin,
351  pgonRout);
352  for (unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
353  pgonZ[isec] -= zz;
354  if (layerSense_[ly] == 0 || absorbMode_ == 0)
355  pgonRout[isec] = rmax;
356  else
357  pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1_;
358  }
359  DDSolid solid =
360  DDSolidFactory::polyhedra(DDName(name, nameSpace_), sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
361  glog = DDLogicalPart(solid.ddname(), matter, solid);
362 #ifdef EDM_ML_DEBUG
363  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << solid.name() << " polyhedra of "
364  << sectors_ << " sectors covering " << convertRadToDeg(-alpha_) << ":"
365  << convertRadToDeg(-alpha_ + 2._pi) << " with " << pgonZ.size()
366  << " sections and filled with " << matName;
367  for (unsigned int k = 0; k < pgonZ.size(); ++k)
368  edm::LogVerbatim("HGCalGeom") << "[" << k << "] z " << pgonZ[k] << " R " << pgonRin[k] << ":" << pgonRout[k];
369 #endif
370  } else {
371  int mode = (layerSense_[ly] > 0) ? sensitiveMode_ : absorbMode_;
372  double rins = (mode < 1) ? rinB : HGCalGeomTools::radius(zz + hthick - tol1_, zFrontB_, rMinFront_, slopeB_);
373  double routs = (mode < 1) ? routF : HGCalGeomTools::radius(zz - hthick, zFrontT_, rMaxFront_, slopeT_);
374  DDSolid solid = DDSolidFactory::tubs(DDName(name, nameSpace_), hthick, rins, routs, 0.0, 2._pi);
375  glog = DDLogicalPart(solid.ddname(), matter, solid);
376 #ifdef EDM_ML_DEBUG
377  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << solid.name() << " Tubs made of "
378  << matName << " of dimensions " << rinB << ":" << rins << ", " << routF << ":"
379  << routs << ", " << hthick << ", 0.0, 360.0 and position " << glog.name()
380  << " number " << copy << ":" << layerOrient_[copy - firstLayer_] << " Z " << zz;
381 #endif
382  if (layerSense_[ly] > 0)
383  positionSensitive(glog, (copy - firstLayer_), cpv);
384  else
385  positionPassive(glog, (copy - firstLayer_), -layerSense_[ly], cpv);
386  }
387  DDTranslation r1(0, 0, zz);
388  DDRotation rot;
389 #ifdef EDM_ML_DEBUG
390  std::string rotName("Null");
391 #endif
392  if ((layerSense_[ly] != 0) && (layerOrient_[copy - firstLayer_] == HGCalTypes::WaferCenterR)) {
393  rot = DDRotation(DDName(DDSplit(rotstr_).first, DDSplit(rotstr_).second));
394 #ifdef EDM_ML_DEBUG
395  rotName = rotstr_;
396 #endif
397  }
398  cpv.position(glog, module, copy, r1, rot);
399  int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
400  copyNumber_[ii] = copy + inc;
401 #ifdef EDM_ML_DEBUG
402  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << glog.name() << " number " << copy
403  << " positioned in " << module.name() << " at " << r1 << " with " << rotName
404  << " rotation";
405 #endif
406  zz += hthick;
407  } // End of loop over layers in a block
408  zi = zo;
409  laymin = laymax;
410  // Make consistency check of all the partitions of the block
411  if (std::abs(thickTot - layerThick_[i]) >= tol2_) {
412  if (thickTot > layerThick_[i]) {
413  edm::LogError("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " is smaller than " << thickTot
414  << ": thickness of all its components **** ERROR ****";
415  } else {
416  edm::LogWarning("HGCalGeom") << "Thickness of the partition " << layerThick_[i] << " does not match with "
417  << thickTot << " of the components";
418  }
419  }
420  } // End of loop over blocks
421 }
422 
423 // Position the silicon modules
425  static const double sqrt3 = std::sqrt(3.0);
426  int layercenter = layerOrient_[layer];
427  int layertype = (layerOrient_[layer] == HGCalTypes::WaferCenterB) ? 1 : 0;
428  int firstWafer = waferLayerStart_[layer];
429  int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
430  : static_cast<int>(waferIndex_.size()));
431  double delx = 0.5 * (waferSize_ + waferSepar_);
432  double dely = 2.0 * delx / sqrt3;
433  double dy = 0.75 * dely;
434  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
435 #ifdef EDM_ML_DEBUG
436  int ium(0), ivm(0), kount(0);
437  std::vector<int> ntype(3, 0);
438  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << glog.ddname() << " r " << delx << " R " << dely
439  << " dy " << dy << " Shift " << xyoff.first << ":" << xyoff.second << " WaferSize "
440  << (waferSize_ + waferSepar_) << " index " << firstWafer << ":" << (lastWafer - 1)
441  << " Layer Center " << layercenter << ":" << layertype;
442 #endif
443  for (int k = firstWafer; k < lastWafer; ++k) {
444  int u = HGCalWaferIndex::waferU(waferIndex_[k]);
445  int v = HGCalWaferIndex::waferV(waferIndex_[k]);
446 #ifdef EDM_ML_DEBUG
447  int iu = std::abs(u);
448  int iv = std::abs(v);
449 #endif
450  int nr = 2 * v;
451  int nc = -2 * u + v;
452  int type = HGCalProperty::waferThick(waferProperty_[k]);
453  int part = HGCalProperty::waferPartial(waferProperty_[k]);
454  int orien = HGCalProperty::waferOrient(waferProperty_[k]);
455  int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
456  int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
457  auto cshift = cassette_.getShift(layer + 1, -1, cassette);
458  double xpos = xyoff.first - cshift.first + nc * delx;
459  double ypos = xyoff.second + cshift.second + nr * dy;
460 #ifdef EDM_ML_DEBUG
461  double xorig = xyoff.first + nc * delx;
462  double yorig = xyoff.second + nr * dy;
463  double angle = std::atan2(yorig, xorig);
464  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette::Wafer: layer " << layer + 1 << " cassette "
465  << cassette << " Shift " << cshift.first << ":" << cshift.second << " Original "
466  << xorig << ":" << yorig << ":" << convertRadToDeg(angle) << " Final " << xpos << ":"
467  << ypos << " u|v " << u << ":" << v << " type|part|orient|place " << type << ":"
468  << part << ":" << orien << ":" << place;
469 #endif
470  std::string wafer;
471  int i(999);
472  if (part == HGCalTypes::WaferFull) {
473  i = type * facingTypes_ * orientationTypes_ + place - placeOffset_;
474  wafer = waferFull_[i];
475 #ifdef EDM_ML_DEBUG
476  edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
477  << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
478  << placeOffset_ << ":" << facingTypes_ << ":" << orientationTypes_ << " wafer " << i
479  << ":" << wafer;
480 #endif
481  } else {
483  i = (part - partoffset) * facingTypes_ * orientationTypes_ +
484  HGCalTypes::WaferTypeOffset[type] * facingTypes_ * orientationTypes_ + place - placeOffset_;
485 #ifdef EDM_ML_DEBUG
486  edm::LogVerbatim("HGCalGeom") << " layertype:type:part:orien:cassette:place:offsets:ind " << layertype << ":"
487  << type << ":" << part << ":" << orien << ":" << cassette << ":" << place << ":"
488  << partoffset << ":" << HGCalTypes::WaferTypeOffset[type] << ":" << i << ":"
489  << waferPart_.size();
490 #endif
491  wafer = waferPart_[i];
492  }
493  int copy = HGCalTypes::packTypeUV(type, u, v);
494 #ifdef EDM_ML_DEBUG
495  edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedCassette: Layer "
496  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << " Wafer " << wafer << " number "
497  << copy << " type:part:orien:place:ind " << type << ":" << part << ":" << orien << ":"
498  << place << ":" << i << " layer:u:v:indx " << (layer + firstLayer_) << ":" << u << ":"
499  << v << " pos " << xpos << ":" << ypos;
500  if (iu > ium)
501  ium = iu;
502  if (iv > ivm)
503  ivm = iv;
504  kount++;
505  if (copies_.count(copy) == 0)
506  copies_.insert(copy);
507 #endif
508  DDTranslation tran(xpos, ypos, 0.0);
510  DDName name = DDName(DDSplit(wafer).first, DDSplit(wafer).second);
511  cpv.position(name, glog.ddname(), copy, tran, rotation);
512 #ifdef EDM_ML_DEBUG
513  ++ntype[type];
514  edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedCassette: " << name << " number " << copy << " type "
515  << layertype << ":" << type << " positioned in " << glog.ddname() << " at " << tran
516  << " with no rotation";
517 #endif
518  }
519 #ifdef EDM_ML_DEBUG
520  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Maximum # of u " << ium << " # of v " << ivm
521  << " and " << kount << " passives (" << ntype[0] << ":" << ntype[1] << ":" << ntype[2]
522  << ") for " << glog.ddname();
523 #endif
524 }
525 
526 // Position the passive modules
528  int layer,
529  int absType,
530  DDCompactView& cpv) {
531  static const double sqrt3 = std::sqrt(3.0);
532  int layercenter = layerOrient_[layer];
533  int layertype = (layerOrient_[layer] == HGCalTypes::WaferCenterB) ? 1 : 0;
534  int firstWafer = waferLayerStart_[layer];
535  int lastWafer = ((layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
536  : static_cast<int>(waferIndex_.size()));
537  double delx = 0.5 * (waferSize_ + waferSepar_);
538  double dely = 2.0 * delx / sqrt3;
539  double dy = 0.75 * dely;
540  const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
541 #ifdef EDM_ML_DEBUG
542  int ium(0), ivm(0), kount(0);
543  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: " << glog.ddname() << " r " << delx << " R " << dely
544  << " dy " << dy << " Shift " << xyoff.first << ":" << xyoff.second << " WaferSize "
545  << (waferSize_ + waferSepar_) << " index " << firstWafer << ":" << (lastWafer - 1)
546  << " Layer Center " << layercenter << ":" << layertype;
547 #endif
548  for (int k = firstWafer; k < lastWafer; ++k) {
549  int u = HGCalWaferIndex::waferU(waferIndex_[k]);
550  int v = HGCalWaferIndex::waferV(waferIndex_[k]);
551 #ifdef EDM_ML_DEBUG
552  int iu = std::abs(u);
553  int iv = std::abs(v);
554 #endif
555  int nr = 2 * v;
556  int nc = -2 * u + v;
557  int part = HGCalProperty::waferPartial(waferProperty_[k]);
558  int orien = HGCalProperty::waferOrient(waferProperty_[k]);
559  int cassette = HGCalProperty::waferCassette(waferProperty_[k]);
560  int place = HGCalCell::cellPlacementIndex(1, layertype, orien);
561  auto cshift = cassette_.getShift(layer + 1, -1, cassette);
562  double xpos = xyoff.first - cshift.first + nc * delx;
563  double ypos = xyoff.second + cshift.second + nr * dy;
564 #ifdef EDM_ML_DEBUG
565  double xorig = xyoff.first + nc * delx;
566  double yorig = xyoff.second + nr * dy;
567  double angle = std::atan2(yorig, xorig);
568  int type = HGCalProperty::waferThick(waferProperty_[k]);
569  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette::Passive: layer " << layer + 1 << " cassette "
570  << cassette << " Shift " << cshift.first << ":" << cshift.second << " Original "
571  << xorig << ":" << yorig << ":" << convertRadToDeg(angle) << " Final " << xpos << ":"
572  << ypos << " u|v " << u << ":" << v << " type|part|orient" << type << ":" << part
573  << ":" << orien;
574 #endif
575  std::string passive;
576  int i(999);
577  if (part == HGCalTypes::WaferFull) {
578  i = absType - 1;
579  passive = passiveFull_[i];
580 #ifdef EDM_ML_DEBUG
581  edm::LogVerbatim("HGCalGeom") << " layertype:abstype:part:orien:cassette:offsets:ind " << layertype << ":"
582  << absType << ":" << part << ":" << orien << ":" << cassette << ":"
583  << ":" << partialTypes_ << ":" << orientationTypes_ << " passive " << i << ":"
584  << passive;
585 #endif
586  } else {
587  int partoffset = (part >= HGCalTypes::WaferHDTop)
590  i = (part - partoffset) * facingTypes_ * orientationTypes_ +
591  (absType - 1) * facingTypes_ * orientationTypes_ * partialTypes_ + place - placeOffset_;
592 #ifdef EDM_ML_DEBUG
593  edm::LogVerbatim("HGCalGeom") << " layertype:abstype:part:orien:cassette:3Types:offset:ind " << layertype << ":"
594  << absType << ":" << part << ":" << orien << ":" << cassette << ":" << partialTypes_
595  << ":" << facingTypes_ << ":" << orientationTypes_ << ":" << partoffset << ":" << i
596  << ":" << passivePart_.size();
597 #endif
598  passive = passivePart_[i];
599  }
600  int copy = HGCalTypes::packTypeUV(absType, u, v);
601 #ifdef EDM_ML_DEBUG
602  edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedCassette: Layer "
603  << HGCalWaferIndex::waferLayer(waferIndex_[k]) << " Passive " << passive << " number "
604  << copy << " type:part:orien:place:ind " << type << ":" << part << ":" << orien << ":"
605  << place << ":" << i << " layer:u:v:indx " << (layer + firstLayer_) << ":" << u << ":"
606  << v << " pos " << xpos << ":" << ypos;
607  if (iu > ium)
608  ium = iu;
609  if (iv > ivm)
610  ivm = iv;
611  kount++;
612 #endif
613  DDTranslation tran(xpos, ypos, 0.0);
615  DDName name = DDName(DDSplit(passive).first, DDSplit(passive).second);
616  cpv.position(name, glog.ddname(), copy, tran, rotation);
617 #ifdef EDM_ML_DEBUG
618  edm::LogVerbatim("HGCalGeom") << " DDHGCalSiliconRotatedCassette: " << name << " number " << copy << " type "
619  << layertype << ":" << type << " positioned in " << glog.ddname() << " at " << tran
620  << " with no rotation";
621 #endif
622  }
623 #ifdef EDM_ML_DEBUG
624  edm::LogVerbatim("HGCalGeom") << "DDHGCalSiliconRotatedCassette: Maximum # of u " << ium << " # of v " << ivm
625  << " and " << kount << " passives for " << glog.ddname();
626 #endif
627 }
628 
629 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalSiliconRotatedCassette, "hgcal:DDHGCalSiliconRotatedCassette");
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
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
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)
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
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
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)
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
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
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
U second(std::pair< T, U > const &p)
int32_t waferCassette(const int32_t property)
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
void positionSensitive(const DDLogicalPart &glog, int layer, DDCompactView &cpv)
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
void execute(DDCompactView &cpv) 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
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
static constexpr int32_t WaferPartHDOffset
Definition: HGCalTypes.h:58
static constexpr int32_t WaferCenterR
Definition: HGCalTypes.h:27
part
Definition: HCALResponse.h:20
const N & ddname() const
Definition: DDBase.h:61
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
static constexpr int32_t WaferCenterB
Definition: HGCalTypes.h:26
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
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
void positionPassive(const DDLogicalPart &glog, int layer, int passiveType, DDCompactView &cpv)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11