9 #include <unordered_set>
19 #include "DD4hep/DetFactoryHelper.h"
38 static constexpr
double tol1 = 0.01 * dd4hep::mm;
41 waferTypes_ =
args.value<
int>(
"WaferTypes");
42 facingTypes_ =
args.value<
int>(
"FacingTypes");
43 partialTypes_ =
args.value<
int>(
"PartialTypes");
44 orientationTypes_ =
args.value<
int>(
"OrientationTypes");
45 phiBinsScint_ =
args.value<
int>(
"NPhiBinScint");
47 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer::Number of types of wafers: " << waferTypes_
48 <<
" facings: " << facingTypes_ <<
" partials: " << partialTypes_
49 <<
" Orientations: " << orientationTypes_ <<
"; number of cells along phi "
52 firstLayer_ =
args.value<
int>(
"FirstLayer");
53 absorbMode_ =
args.value<
int>(
"AbsorberMode");
54 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
57 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
59 zMinBlock_ =
args.value<
double>(
"zMinBlock");
60 waferSize_ =
args.value<
double>(
"waferSize");
61 waferSepar_ =
args.value<
double>(
"SensorSeparation");
62 sectors_ =
args.value<
int>(
"Sectors");
63 alpha_ = (1._pi) / sectors_;
64 cosAlpha_ =
cos(alpha_);
68 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_;
71 waferFull_ =
args.value<std::vector<std::string>>(
"WaferNamesFull");
72 waferPart_ =
args.value<std::vector<std::string>>(
"WaferNamesPartial");
74 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << waferFull_.size() <<
" full and " << waferPart_.size()
75 <<
" partial modules\nDDHGCalMixLayer:Full Modules:";
76 unsigned int i1max = static_cast<unsigned int>(waferFull_.size());
77 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
78 std::ostringstream st1;
80 for (
unsigned int i =
i1;
i <
i2; ++
i)
81 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
85 i1max = static_cast<unsigned int>(waferPart_.size());
86 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
87 std::ostringstream st1;
89 for (
unsigned int i =
i1;
i <
i2; ++
i)
90 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
94 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
95 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
96 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
97 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
98 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
99 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
101 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
104 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
109 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
110 names_ =
args.value<std::vector<std::string>>(
"VolumeNames");
111 thick_ =
args.value<std::vector<double>>(
"Thickness");
112 copyNumber_.resize(materials_.size(), 1);
114 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << materials_.size() <<
" types of volumes";
115 for (
unsigned int i = 0;
i < names_.size(); ++
i)
116 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness "
118 <<
" first copy number " << copyNumber_[
i];
120 layers_ =
args.value<std::vector<int>>(
"Layers");
121 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
123 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
124 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
126 <<
" with " << layers_[
i] <<
" layers";
128 layerType_ =
args.value<std::vector<int>>(
"LayerType");
129 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
130 layerCenter_ =
args.value<std::vector<int>>(
"LayerCenter");
132 for (
unsigned int i = 0;
i < layerCenter_.size(); ++
i)
135 if (firstLayer_ > 0) {
136 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
137 if (layerSense_[
i] > 0) {
138 int ii = layerType_[
i];
139 copyNumber_[
ii] = firstLayer_;
141 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with "
142 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
151 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
152 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
153 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class "
156 materialTop_ =
args.value<std::vector<std::string>>(
"TopMaterialNames");
157 namesTop_ =
args.value<std::vector<std::string>>(
"TopVolumeNames");
158 layerThickTop_ =
args.value<std::vector<double>>(
"TopLayerThickness");
159 layerTypeTop_ =
args.value<std::vector<int>>(
"TopLayerType");
160 copyNumberTop_.resize(materialTop_.size(), firstLayer_);
162 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << materialTop_.size() <<
" types of volumes in the top part";
163 for (
unsigned int i = 0;
i < materialTop_.size(); ++
i)
164 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness "
166 <<
" first copy number " << copyNumberTop_[
i];
167 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
168 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
169 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
171 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
172 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
173 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
175 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in "
176 << waferLayerStart_.size() <<
" layers";
177 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
179 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
188 tileRMin_ =
args.value<std::vector<double>>(
"TileRMin");
189 tileRMax_ =
args.value<std::vector<double>>(
"TileRMax");
190 tileIndex_ =
args.value<std::vector<int>>(
"TileLayerRings");
191 tilePhis_ =
args.value<std::vector<int>>(
"TilePhiRange");
192 tileLayerStart_ =
args.value<std::vector<int>>(
"TileLayerStart");
194 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer:: with " << tileRMin_.size() <<
" rings";
195 for (
unsigned int k = 0;
k < tileRMin_.size(); ++
k)
198 edm::LogVerbatim(
"HGCalGeom") <<
"TileProperties with " << tileIndex_.size() <<
" entries in "
199 << tileLayerStart_.size() <<
" layers";
200 for (
unsigned int k = 0;
k < tileLayerStart_.size(); ++
k)
202 for (
unsigned int k = 0;
k < tileIndex_.size(); ++
k)
218 double zi(zMinBlock_);
220 for (
unsigned int i = 0;
i < layers_.size();
i++) {
221 double zo = zi + layerThick_[
i];
223 int laymax = laymin + layers_[
i];
226 for (
int ly = laymin; ly < laymax; ++ly) {
227 int ii = layerType_[ly];
228 int copy = copyNumber_[
ii];
229 double hthick = 0.5 * thick_[
ii];
232 thickTot += thick_[
ii];
236 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << ly <<
":" <<
ii <<
" Front "
245 if (layerSense_[ly] < 1) {
246 std::vector<double> pgonZ, pgonRin, pgonRout;
261 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
263 if (layerSense_[ly] == 0 || absorbMode_ == 0)
264 pgonRout[isec] = rmax;
266 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
269 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
274 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << solid.name() <<
" polyhedra of " << sectors_
276 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
277 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
286 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
292 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << solid.name() <<
" Tubs made of " << matter.name()
295 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and positioned in: " << glog.name()
296 <<
" number " <<
copy;
298 positionMix(ctxt,
e, glog,
name,
copy, thick_[
ii], matter, layerSense_[ly]);
302 mother.placeVolume(glog,
copy,
r1);
305 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog.name() <<
" number " <<
copy <<
" positioned in "
312 if (
std::abs(thickTot - layerThick_[
i]) > tol2_) {
313 if (thickTot > layerThick_[
i]) {
316 <<
": thickness of all its components **** ERROR ****";
319 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
325 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << copies_.size() <<
" different wafer copy numbers";
327 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
331 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalMixLayer construction...";
346 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
347 int ii = layerTypeTop_[ly];
348 copyNumberTop_[
ii] = copyM;
350 double hthick = 0.5 * thick;
351 double dphi = (2._pi) / phiBinsScint_;
352 double thickTot(0), zpos(-hthick);
353 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
354 int ii = layerTypeTop_[ly];
355 int copy = copyNumberTop_[
ii];
357 double hthickl = 0.5 * layerThickTop_[
ii];
358 thickTot += layerThickTop_[
ii];
362 int firstTile = tileLayerStart_[
layer];
363 int lastTile = ((
layer + 1 < static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[
layer + 1]
364 : static_cast<int>(tileIndex_.size()));
366 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << ly <<
":" <<
ii <<
" Copy " <<
copy <<
" Tiles "
367 << firstTile <<
":" << lastTile;
369 for (
int ti = firstTile; ti < lastTile; ++ti) {
374 double phi1 = dphi * (fimin - 1);
375 double phi2 = dphi * (fimax - fimin + 1);
381 <<
cms::convert2mm((2.0 * hthickl)) <<
" phi " << fimin <<
":" << fimax <<
":"
386 dd4hep::Solid solid = dd4hep::Tube(
r1,
r2, hthickl, phi1, phi2);
391 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog1.name() <<
" Tubs made of " << materialTop_[
ii]
397 glog.placeVolume(glog1,
copy, tran);
399 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Position " << glog1.name() <<
" number " <<
copy <<
" in "
400 << glog.name() <<
" at (0, 0, " <<
cms::convert2mm(zpos) <<
") with no rotation";
403 ++copyNumberTop_[
ii];
406 if (
std::abs(thickTot - thick) > tol2_) {
407 if (thickTot > thick) {
410 <<
": thickness of all its components in the top part **** ERROR ****";
414 <<
" of the components in top part";
419 int layer = (copyM - firstLayer_);
420 static const double sqrt3 =
std::sqrt(3.0);
421 int layercenter = layerCenter_[
layer];
422 int firstWafer = waferLayerStart_[
layer];
423 int lastWafer = ((
layer + 1 < static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[
layer + 1]
424 : static_cast<int>(waferIndex_.size()));
425 double r = 0.5 * (waferSize_ + waferSepar_);
426 double R = 2.0 *
r / sqrt3;
427 double dy = 0.75 *
R;
428 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
430 int ium(0), ivm(0), kount(0);
431 std::vector<int> ntype(3, 0);
435 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index "
436 << firstWafer <<
":" << (lastWafer - 1);
438 for (
int k = firstWafer;
k < lastWafer; ++
k) {
447 double xpos = xyoff.first + nc *
r;
448 double ypos = xyoff.second +
nr *
dy;
455 i = (layerType - 1) * waferTypes_ +
type;
456 wafer = waferFull_[
i];
458 i = (
part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ +
459 (layerType - 1) * waferTypes_ * orientationTypes_ +
type * orientationTypes_ + orien;
462 <<
":" << orien <<
":" <<
i <<
":" << waferPart_.size();
464 wafer = waferPart_[
i];
469 <<
" Wafer " << wafer <<
" number " <<
copy <<
" type :part:orien:ind " <<
type
470 <<
":" <<
part <<
":" << orien <<
":" <<
i <<
" layer:u:v " << (
layer + firstLayer_)
471 <<
":" << u <<
":" <<
v;
477 if (copies_.count(
copy) == 0)
478 copies_.insert(
copy);
481 glog.placeVolume(ns.
volume(wafer),
copy, tran);
484 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalMixLayer: " << wafer <<
" number " <<
copy <<
" type " << layerType
485 <<
":" <<
type <<
" positioned in " << glog.name() <<
" at ("
491 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Maximum # of u " << ium <<
" # of v " << ivm <<
" and " << kount
492 <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
") for "
499 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;