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