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");
46 forFireworks_ =
args.value<
int>(
"ForFireWorks");
48 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer::Number of types of wafers: " << waferTypes_
49 <<
" facings: " << facingTypes_ <<
" partials: " << partialTypes_
50 <<
" Orientations: " << orientationTypes_ <<
"; number of cells along phi " 51 << phiBinsScint_ <<
" forFireworks_: " << forFireworks_;
53 firstLayer_ =
args.value<
int>(
"FirstLayer");
54 absorbMode_ =
args.value<
int>(
"AbsorberMode");
55 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
57 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer::First Layer " << firstLayer_ <<
" and " 58 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
60 zMinBlock_ =
args.value<
double>(
"zMinBlock");
61 waferSize_ =
args.value<
double>(
"waferSize");
62 waferSepar_ =
args.value<
double>(
"SensorSeparation");
63 sectors_ =
args.value<
int>(
"Sectors");
64 alpha_ = (1._pi) / sectors_;
65 cosAlpha_ =
cos(alpha_);
69 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_;
71 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
72 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
73 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
74 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
75 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
76 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
78 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
81 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
86 waferFull_ =
args.value<std::vector<std::string>>(
"WaferNamesFull");
87 waferPart_ =
args.value<std::vector<std::string>>(
"WaferNamesPartial");
89 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << waferFull_.size() <<
" full and " << waferPart_.size()
90 <<
" partial modules\nDDHGCalMixLayer:Full Modules:";
91 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
92 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
93 std::ostringstream st1;
95 for (
unsigned int i =
i1;
i <
i2; ++
i)
96 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
100 i1max =
static_cast<unsigned int>(waferPart_.size());
101 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
102 std::ostringstream st1;
104 for (
unsigned int i =
i1;
i <
i2; ++
i)
105 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
110 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
111 names_ =
args.value<std::vector<std::string>>(
"VolumeNames");
112 thick_ =
args.value<std::vector<double>>(
"Thickness");
113 copyNumber_.resize(materials_.size(), 1);
115 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << materials_.size() <<
" types of volumes";
116 for (
unsigned int i = 0;
i < names_.size(); ++
i)
117 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness " 119 <<
" first copy number " << copyNumber_[
i];
121 layers_ =
args.value<std::vector<int>>(
"Layers");
122 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
124 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
125 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
127 <<
" with " << layers_[
i] <<
" layers";
129 layerType_ =
args.value<std::vector<int>>(
"LayerType");
130 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
131 layerOrient_ =
args.value<std::vector<int>>(
"LayerTypes");
132 for (
unsigned int k = 0;
k < layerOrient_.size(); ++
k)
135 for (
unsigned int i = 0;
i < layerOrient_.size(); ++
i)
138 if (firstLayer_ > 0) {
139 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
140 if (layerSense_[
i] > 0) {
141 int ii = layerType_[
i];
142 copyNumber_[
ii] = firstLayer_;
144 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 145 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
154 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
155 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
156 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 159 materialTop_ =
args.value<std::vector<std::string>>(
"TopMaterialNames");
160 namesTop_ =
args.value<std::vector<std::string>>(
"TopVolumeNames");
161 layerThickTop_ =
args.value<std::vector<double>>(
"TopLayerThickness");
162 layerTypeTop_ =
args.value<std::vector<int>>(
"TopLayerType");
163 copyNumberTop_.resize(materialTop_.size(), firstLayer_);
165 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << materialTop_.size() <<
" types of volumes in the top part";
166 for (
unsigned int i = 0;
i < materialTop_.size(); ++
i)
167 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " 169 <<
" first copy number " << copyNumberTop_[
i];
170 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
171 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
172 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
174 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
175 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
176 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
178 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in " 179 << waferLayerStart_.size() <<
" layers";
180 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
182 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
191 tileRMin_ =
args.value<std::vector<double>>(
"TileRMin");
192 tileRMax_ =
args.value<std::vector<double>>(
"TileRMax");
193 tileIndex_ =
args.value<std::vector<int>>(
"TileLayerRings");
194 tilePhis_ =
args.value<std::vector<int>>(
"TilePhiRange");
195 tileLayerStart_ =
args.value<std::vector<int>>(
"TileLayerStart");
197 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer:: with " << tileRMin_.size() <<
" rings";
198 for (
unsigned int k = 0;
k < tileRMin_.size(); ++
k)
201 edm::LogVerbatim(
"HGCalGeom") <<
"TileProperties with " << tileIndex_.size() <<
" entries in " 202 << tileLayerStart_.size() <<
" layers";
203 for (
unsigned int k = 0;
k < tileLayerStart_.size(); ++
k)
205 for (
unsigned int k = 0;
k < tileIndex_.size(); ++
k)
221 double zi(zMinBlock_);
223 for (
unsigned int i = 0;
i < layers_.size();
i++) {
224 double zo = zi + layerThick_[
i];
226 int laymax = laymin + layers_[
i];
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];
235 thickTot += thick_[
ii];
239 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << ly <<
":" <<
ii <<
" Front " 248 if (layerSense_[ly] < 1) {
249 std::vector<double> pgonZ, pgonRin, pgonRout;
264 for (
unsigned int isec = 0;
isec < pgonZ.size(); ++
isec) {
266 if (layerSense_[ly] == 0 || absorbMode_ == 0)
267 pgonRout[
isec] = rmax;
269 pgonRout[
isec] = pgonRout[
isec] * cosAlpha_ - tol1;
272 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
277 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << solid.name() <<
" polyhedra of " << sectors_
279 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
280 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
289 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
295 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << solid.name() <<
" Tubs made of " << matter.name()
298 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and positioned in: " << glog.name()
299 <<
" number " <<
copy;
301 positionMix(ctxt,
e, glog,
name,
copy, thick_[
ii], matter);
305 mother.placeVolume(glog,
copy, r1);
308 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog.name() <<
" number " <<
copy <<
" positioned in " 315 if (
std::abs(thickTot - layerThick_[
i]) > tol2_) {
316 if (thickTot > layerThick_[
i]) {
319 <<
": thickness of all its components **** ERROR ****";
322 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
328 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << copies_.size() <<
" different wafer copy numbers";
330 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
334 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalMixLayer construction...";
348 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
349 int ii = layerTypeTop_[ly];
350 copyNumberTop_[
ii] = copyM;
352 double hthick = 0.5 * thick;
353 double dphi = (2._pi) / phiBinsScint_;
354 double thickTot(0), zpos(-hthick);
355 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
356 int ii = layerTypeTop_[ly];
357 int copy = copyNumberTop_[
ii];
358 int layer =
copy - firstLayer_;
359 double hthickl = 0.5 * layerThickTop_[
ii];
360 thickTot += layerThickTop_[
ii];
364 int firstTile = tileLayerStart_[layer];
365 int lastTile = ((layer + 1 <
static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
366 :
static_cast<int>(tileIndex_.size()));
368 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Layer " << ly <<
":" <<
ii <<
" Copy " <<
copy <<
" Tiles " 369 << firstTile <<
":" << lastTile;
371 for (
int ti = firstTile; ti < lastTile; ++ti) {
376 double phi1 = dphi * (fimin - 1);
377 double phi2 = (forFireworks_ == 1) ? (dphi * (fimax - fimin + 1)) : (dphi * fimax);
383 <<
cms::convert2mm((2.0 * hthickl)) <<
" phi " << fimin <<
":" << fimax <<
":" 388 dd4hep::Solid solid = dd4hep::Tube(r1,
r2, hthickl, phi1, phi2);
393 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: " << glog1.name() <<
" Tubs made of " << materialTop_[
ii]
399 glog.placeVolume(glog1,
copy, tran);
401 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Position " << glog1.name() <<
" number " <<
copy <<
" in " 402 << glog.name() <<
" at (0, 0, " <<
cms::convert2mm(zpos) <<
") with no rotation";
405 ++copyNumberTop_[
ii];
408 if (
std::abs(thickTot - thick) > tol2_) {
409 if (thickTot > thick) {
412 <<
": thickness of all its components in the top part **** ERROR ****";
416 <<
" of the components in top part";
421 int layer = (copyM - firstLayer_);
422 static const double sqrt3 =
std::sqrt(3.0);
423 int layercenter = layerOrient_[layer];
425 int firstWafer = waferLayerStart_[layer];
426 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
427 :
static_cast<int>(waferIndex_.size()));
428 double r = 0.5 * (waferSize_ + waferSepar_);
429 double R = 2.0 * r / sqrt3;
430 double dy = 0.75 *
R;
431 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
433 int ium(0), ivm(0), kount(0);
434 std::vector<int> ntype(3, 0);
438 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index " 439 << firstWafer <<
":" << (lastWafer - 1);
441 for (
int k = firstWafer;
k < lastWafer; ++
k) {
450 double xpos = xyoff.first + nc * r;
451 double ypos = xyoff.second +
nr *
dy;
458 i = layerType * waferTypes_ +
type;
459 wafer = waferFull_[
i];
461 i = (
part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ + layerType * waferTypes_ * orientationTypes_ +
462 type * orientationTypes_ + orien;
465 <<
":" << orien <<
":" <<
i <<
":" << waferPart_.size();
467 wafer = waferPart_[
i];
472 <<
" Wafer " << wafer <<
" number " <<
copy <<
" type :part:orien:ind " <<
type 473 <<
":" <<
part <<
":" << orien <<
":" <<
i <<
" layer:u:v " << (layer + firstLayer_)
474 <<
":" << u <<
":" <<
v;
480 if (copies_.count(
copy) == 0)
481 copies_.insert(
copy);
484 glog.placeVolume(ns.
volume(wafer),
copy, tran);
487 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalMixLayer: " << wafer <<
" number " <<
copy <<
" type " << layerType
488 <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 494 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixLayer: Maximum # of u " << ium <<
" # of v " << ivm <<
" and " << kount
495 <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
") for " 502 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;
std::vector< int > copyNumberTop_
std::vector< int > layerOrient_
Log< level::Info, true > LogVerbatim
std::vector< double > tileRMin_
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)
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_
dd4hep::Material material(const std::string &name) const
HGCalGeomTools geomTools_
std::vector< int > copyNumber_
int32_t waferOrient(const int32_t property)
static std::string to_string(const XMLCh *ch)
std::vector< double > slopeB_
std::vector< int > waferIndex_
std::vector< double > rMinFront_
std::vector< double > zFrontB_
#define DECLARE_DDCMS_DETELEMENT(name, func)
static constexpr int32_t WaferFull
std::vector< int > tilePhis_
HGCalMixLayer(cms::DDParsingContext &ctxt, xml_h e)
static constexpr long s_executed
std::vector< int > layers_
std::string_view name() const
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)
int32_t waferThick(const int32_t property)
std::vector< int > layerType_
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_
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
static int32_t layerType(int type)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
static constexpr int32_t WaferCenterB
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
std::vector< double > layerThickTop_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
std::vector< int > tileIndex_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
std::string prepend(const std::string &) const