9 #include <unordered_set>
19 #include "DD4hep/DetFactoryHelper.h"
26 using namespace angle_units::operators;
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");
56 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer::First Layer " << firstLayer_ <<
" and "
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_;
70 slopeB_ = args.
value<std::vector<double>>(
"SlopeBottom");
71 zFrontB_ = args.
value<std::vector<double>>(
"ZFrontBottom");
72 rMinFront_ = args.
value<std::vector<double>>(
"RMinFront");
73 slopeT_ = args.
value<std::vector<double>>(
"SlopeTop");
74 zFrontT_ = args.
value<std::vector<double>>(
"ZFrontTop");
75 rMaxFront_ = args.
value<std::vector<double>>(
"RMaxFront");
77 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
80 for (
unsigned int i = 0; i < slopeT_.size(); ++
i)
85 waferFull_ = args.
value<std::vector<std::string>>(
"WaferNamesFull");
86 waferPart_ = args.
value<std::vector<std::string>>(
"WaferNamesPartial");
88 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << waferFull_.size() <<
" full and " << waferPart_.size()
89 <<
" partial modules\nDDHGCalMixLayer:Full Modules:";
90 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
91 for (
unsigned int i1 = 0; i1 < i1max; i1 += 2) {
92 std::ostringstream st1;
93 unsigned int i2 =
std::min((i1 + 2), i1max);
94 for (
unsigned int i = i1; i < i2; ++
i)
95 st1 <<
" [" << i <<
"] " << waferFull_[i];
99 i1max =
static_cast<unsigned int>(waferPart_.size());
100 for (
unsigned int i1 = 0; i1 < i1max; i1 += 2) {
101 std::ostringstream st1;
102 unsigned int i2 =
std::min((i1 + 2), i1max);
103 for (
unsigned int i = i1; i < i2; ++
i)
104 st1 <<
" [" << i <<
"] " << waferPart_[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 layerTypes_ = args.
value<std::vector<int>>(
"LayerTypes");
132 for (
unsigned int i = 0; i < layerTypes_.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)
201 edm::LogVerbatim(
"HGCalGeom") <<
"LayerStart[" << k <<
"] " << tileLayerStart_[
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 "
242 dd4hep::Material matter = ns.
material(materials_[ii]);
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);
302 mother.placeVolume(glog, copy, r1);
305 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog.name() <<
" number " << copy <<
" positioned in "
306 << mother.name() <<
" at (0,0," <<
cms::convert2mm(zz) <<
") with no rotation";
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...";
341 const dd4hep::Material& matter) {
345 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
346 int ii = layerTypeTop_[ly];
347 copyNumberTop_[
ii] = copyM;
349 double hthick = 0.5 * thick;
350 double dphi = (2._pi) / phiBinsScint_;
351 double thickTot(0), zpos(-hthick);
352 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
353 int ii = layerTypeTop_[ly];
354 int copy = copyNumberTop_[
ii];
355 int layer = copy - firstLayer_;
356 double hthickl = 0.5 * layerThickTop_[
ii];
357 thickTot += layerThickTop_[
ii];
359 dd4hep::Material matter1 = ns.
material(materialTop_[ii]);
361 int firstTile = tileLayerStart_[
layer];
362 int lastTile = ((layer + 1 <
static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
363 :
static_cast<int>(tileIndex_.size()));
365 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << ly <<
":" << ii <<
" Copy " << copy <<
" Tiles "
366 << firstTile <<
":" << lastTile;
368 for (
int ti = firstTile; ti < lastTile; ++ti) {
373 double phi1 = dphi * (fimin - 1);
374 double phi2 = dphi * (fimax - fimin + 1);
376 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << copy <<
" iR "
380 <<
cms::convert2mm((2.0 * hthickl)) <<
" phi " << fimin <<
":" << fimax <<
":"
383 std::string name = namesTop_[
ii] +
"L" + std::to_string(copy) +
"F" + std::to_string(k);
385 dd4hep::Solid solid = dd4hep::Tube(r1, r2, hthickl, phi1, phi2);
390 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog1.name() <<
" Tubs made of " << materialTop_[
ii]
396 glog.placeVolume(glog1, copy, tran);
398 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Position " << glog1.name() <<
" number " << copy <<
" in "
399 << glog.name() <<
" at (0, 0, " <<
cms::convert2mm(zpos) <<
") with no rotation";
402 ++copyNumberTop_[
ii];
405 if (
std::abs(thickTot - thick) > tol2_) {
406 if (thickTot > thick) {
409 <<
": thickness of all its components in the top part **** ERROR ****";
413 <<
" of the components in top part";
418 int layer = (copyM - firstLayer_);
419 static const double sqrt3 =
std::sqrt(3.0);
424 int firstWafer = waferLayerStart_[
layer];
425 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
426 :
static_cast<int>(waferIndex_.size()));
427 double r = 0.5 * (waferSize_ + waferSepar_);
428 double R = 2.0 * r / sqrt3;
429 double dy = 0.75 *
R;
430 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
432 int ium(0), ivm(0), kount(0);
433 std::vector<int> ntype(3, 0);
437 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index "
438 << firstWafer <<
":" << (lastWafer - 1);
440 for (
int k = firstWafer;
k < lastWafer; ++
k) {
449 double xpos = xyoff.first + nc *
r;
450 double ypos = xyoff.second + nr *
dy;
457 i = layerType * waferTypes_ +
type;
458 wafer = waferFull_[
i];
460 i = (part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ + layerType * waferTypes_ * orientationTypes_ +
461 type * orientationTypes_ + orien;
463 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:ind " << layerType <<
":" << type <<
":" << part
464 <<
":" << orien <<
":" << i <<
":" << waferPart_.size();
466 wafer = waferPart_[
i];
471 <<
" Wafer " << wafer <<
" number " << copy <<
" type :part:orien:ind " << type
472 <<
":" << part <<
":" << orien <<
":" << i <<
" layer:u:v " << (layer + firstLayer_)
473 <<
":" << u <<
":" << v;
479 if (copies_.count(copy) == 0)
480 copies_.insert(copy);
483 glog.placeVolume(ns.
volume(wafer),
copy, tran);
486 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalMixLayer: " << wafer <<
" number " << copy <<
" type " << layerType
487 <<
":" << type <<
" positioned in " << glog.name() <<
" at ("
493 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Maximum # of u " << ium <<
" # of v " << ivm <<
" and " << kount
494 <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
") for "
501 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;
std::vector< int > copyNumberTop_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Log< level::Info, true > LogVerbatim
std::vector< double > tileRMin_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
std::vector< int > layerTypeTop_
std::vector< std::string > namesTop_
std::vector< std::string > materialTop_
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
T value(const std::string &name) const
std::vector< double > tileRMax_
std::vector< double > layerThick_
std::vector< std::string > waferFull_
std::vector< int > waferLayerStart_
Log< level::Error, false > LogError
std::vector< int > layerSense_
HGCalGeomTools geomTools_
std::vector< int > copyNumber_
int32_t waferOrient(const int32_t property)
std::vector< double > slopeB_
std::vector< int > waferIndex_
constexpr std::array< uint8_t, layerIndexSize > layer
std::string_view name() const
std::vector< double > rMinFront_
std::vector< double > zFrontB_
#define DECLARE_DDCMS_DETELEMENT(name, func)
std::vector< int > tilePhis_
HGCalMixLayer(cms::DDParsingContext &ctxt, xml_h e)
static constexpr long s_executed
std::vector< int > layers_
std::vector< int > tileLayerStart_
Cos< T >::type cos(const T &t)
std::vector< std::string > waferPart_
std::vector< std::string > materials_
Abs< T >::type abs(const T &t)
dd4hep::Material material(const std::string &name) const
int32_t waferThick(const int32_t property)
std::vector< int > layerType_
std::string prepend(const std::string &) const
std::vector< int > waferProperty_
std::vector< double > rMaxFront_
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter)
std::tuple< int32_t, int32_t, int32_t > tileUnpack(int32_t index)
std::vector< std::string > names_
std::vector< double > thick_
std::vector< double > slopeT_
int32_t waferPartial(const int32_t property)
std::vector< double > zFrontT_
std::vector< int > layerTypes_
int32_t waferV(const int32_t index)
std::unordered_set< int > copies_
static int32_t packTypeUV(int type, int u, int v)
Log< level::Warning, false > LogWarning
std::vector< double > layerThickTop_
std::string parentName() const
Access value of rParent child node.
std::vector< int > tileIndex_