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