9 #include <unordered_set>
17 #include "DD4hep/DetFactoryHelper.h"
35 static constexpr
double tol1 = 0.01;
38 waferNames_ =
args.value<std::vector<std::string>>(
"WaferNames");
40 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << waferNames_.size() <<
" wafers";
41 for (
unsigned int i = 0;
i < waferNames_.size(); ++
i)
44 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
45 volumeNames_ =
args.value<std::vector<std::string>>(
"VolumeNames");
46 thickness_ =
args.value<std::vector<double>>(
"Thickness");
47 copyNumber_.resize(materials_.size(), 1);
49 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materials_.size() <<
" types of volumes";
50 for (
unsigned int i = 0;
i < volumeNames_.size(); ++
i)
51 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << volumeNames_[
i] <<
" of thickness " << thickness_[
i]
52 <<
" filled with " << materials_[
i] <<
" first copy number " << copyNumber_[
i];
54 layerNumbers_ =
args.value<std::vector<int>>(
"Layers");
55 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
56 rMixLayer_ =
args.value<std::vector<double>>(
"LayerRmix");
58 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerNumbers_.size() <<
" blocks";
59 for (
unsigned int i = 0;
i < layerNumbers_.size(); ++
i)
60 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] of thickness " << layerThick_[
i] <<
" Rmid "
61 << rMixLayer_[
i] <<
" with " << layerNumbers_[
i] <<
" layers";
63 layerType_ =
args.value<std::vector<int>>(
"LayerType");
64 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
65 firstLayer_ =
args.value<
int>(
"FirstLayer");
66 absorbMode_ =
args.value<
int>(
"AbsorberMode");
67 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
70 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
72 layerCenter_ =
args.value<std::vector<int>>(
"LayerCenter");
74 for (
unsigned int i = 0;
i < layerCenter_.size(); ++
i)
77 if (firstLayer_ > 0) {
78 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
79 if (layerSense_[
i] > 0) {
80 int ii = layerType_[
i];
81 copyNumber_[
ii] = firstLayer_;
83 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with "
84 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
93 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
94 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
95 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class "
98 materialsTop_ =
args.value<std::vector<std::string>>(
"TopMaterialNames");
99 namesTop_ =
args.value<std::vector<std::string>>(
"TopVolumeNames");
100 layerThickTop_ =
args.value<std::vector<double>>(
"TopLayerThickness");
101 layerTypeTop_ =
args.value<std::vector<int>>(
"TopLayerType");
102 copyNumberTop_.resize(materialsTop_.size(), 1);
104 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materialsTop_.size()
105 <<
" types of volumes in the top part";
106 for (
unsigned int i = 0;
i < materialsTop_.size(); ++
i)
107 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " << layerThickTop_[
i]
108 <<
" filled with " << materialsTop_[
i] <<
" first copy number "
109 << copyNumberTop_[
i];
110 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
111 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
112 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
114 materialsBot_ =
args.value<std::vector<std::string>>(
"BottomMaterialNames");
115 namesBot_ =
args.value<std::vector<std::string>>(
"BottomVolumeNames");
116 layerTypeBot_ =
args.value<std::vector<int>>(
"BottomLayerType");
117 layerSenseBot_ =
args.value<std::vector<int>>(
"BottomLayerSense");
118 layerThickBot_ =
args.value<std::vector<double>>(
"BottomLayerThickness");
119 copyNumberBot_.resize(materialsBot_.size(), 1);
121 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materialsBot_.size()
122 <<
" types of volumes in the bottom part";
123 for (
unsigned int i = 0;
i < materialsBot_.size(); ++
i)
124 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesBot_[
i] <<
" of thickness " << layerThickBot_[
i]
125 <<
" filled with " << materialsBot_[
i] <<
" first copy number "
126 << copyNumberBot_[
i];
127 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeBot_.size() <<
" layers in the bottom part";
128 for (
unsigned int i = 0;
i < layerTypeBot_.size(); ++
i)
129 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeBot_[
i]
130 <<
" sensitive class " << layerSenseBot_[
i];
132 zMinBlock_ =
args.value<
double>(
"zMinBlock");
133 rad100to200_ =
args.value<std::vector<double>>(
"rad100to200");
134 rad200to300_ =
args.value<std::vector<double>>(
"rad200to300");
135 zMinRadPar_ =
args.value<
double>(
"zMinForRadPar");
136 choiceType_ =
args.value<
int>(
"choiceType");
137 nCutRadPar_ =
args.value<
int>(
"nCornerCut");
138 fracAreaMin_ =
args.value<
double>(
"fracAreaMin");
139 waferSize_ =
args.value<
double>(
"waferSize");
140 waferSepar_ =
args.value<
double>(
"SensorSeparation");
141 sectors_ =
args.value<
int>(
"Sectors");
142 alpha_ = (1._pi) / sectors_;
143 cosAlpha_ =
cos(alpha_);
146 <<
" radius for wafer type separation uses " << rad100to200_.size()
147 <<
" parameters; zmin " << zMinRadPar_ <<
" cutoff " << choiceType_ <<
":"
148 << nCutRadPar_ <<
":" << fracAreaMin_ <<
" wafer width " << waferSize_
149 <<
" separations " << waferSepar_ <<
" sectors " << sectors_ <<
":"
151 for (
unsigned int k = 0;
k < rad100to200_.size(); ++
k)
152 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k <<
"] 100-200 " << rad100to200_[
k] <<
" 200-300 " << rad200to300_[
k];
154 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
155 waferTypes_ =
args.value<std::vector<int>>(
"WaferTypes");
157 edm::LogVerbatim(
"HGCalGeom") <<
"waferTypes with " << waferTypes_.size() <<
" entries";
158 for (
unsigned int k = 0;
k < waferTypes_.size(); ++
k)
164 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
165 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
166 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
167 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
168 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
169 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
171 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
172 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] Zmin " << zFrontB_[
i] <<
" Rmin " << rMinFront_[
i]
173 <<
" Slope " << slopeB_[
i];
174 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
175 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] Zmin " << zFrontT_[
i] <<
" Rmax " << rMaxFront_[
i]
176 <<
" Slope " << slopeT_[
i];
183 double zi(zMinBlock_);
185 for (
unsigned int i = 0;
i < layerNumbers_.size();
i++) {
186 double zo = zi + layerThick_[
i];
188 int laymax = laymin + layerNumbers_[
i];
191 for (
int ly = laymin; ly < laymax; ++ly) {
192 int ii = layerType_[ly];
193 int copy = copyNumber_[
ii];
194 double hthick = 0.5 * thickness_[
ii];
197 thickTot += thickness_[
ii];
202 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Layer " << ly <<
":" <<
ii <<
" Front " << zi <<
", "
203 << routF <<
" Back " << zo <<
", " << rinB <<
" superlayer thickness "
210 if (layerSense_[ly] < 1) {
211 std::vector<double> pgonZ, pgonRin, pgonRout;
212 if (layerSense_[ly] == 0 || absorbMode_ == 0) {
216 pgonZ.emplace_back(-hthick);
217 pgonZ.emplace_back(hthick);
218 pgonRin.emplace_back(rinB);
219 pgonRin.emplace_back(rinB);
220 pgonRout.emplace_back(rmax);
221 pgonRout.emplace_back(rmax);
235 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
237 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
241 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
246 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" polyhedra of " << sectors_
248 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
249 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
251 <<
"[" <<
k <<
"] z " << pgonZ[
k] <<
" R " << pgonRin[
k] <<
":" << pgonRout[
k];
258 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
264 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
265 <<
" of dimensions " << rinB <<
":" << rins <<
", " << routF <<
":" << routs
266 <<
", " << hthick <<
", 0.0, 360.0 and positioned in: " << glog.name()
267 <<
" number " <<
copy;
269 positionMix(ctxt,
e, glog,
name,
copy, thickness_[
ii], matter, rins, rMixLayer_[
i], routs,
zz);
273 mother.placeVolume(glog,
copy,
r1);
276 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog.name() <<
" number " <<
copy <<
" positioned in "
277 << mother.name() <<
" at " <<
r1 <<
" with no rotation";
283 if (
std::abs(thickTot - layerThick_[
i]) > tol2_) {
284 if (thickTot > layerThick_[
i]) {
285 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << layerThick_[
i] <<
" is smaller than "
286 << thickTot <<
": thickness of all its components **** ERROR ****";
288 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << layerThick_[
i] <<
" does not match with "
289 << thickTot <<
" of the components";
295 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << copies_.size() <<
" different wafer copy numbers";
297 for (std::unordered_set<int>::const_iterator
itr = copies_.begin();
itr != copies_.end(); ++
itr, ++
k) {
301 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalHEFileAlgo construction...";
319 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
320 int ii = layerTypeTop_[ly];
321 copyNumberTop_[
ii] = copyM;
323 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
324 int ii = layerTypeBot_[ly];
325 copyNumberBot_[
ii] = copyM;
327 double hthick = 0.5 * thick;
331 dd4hep::Solid solid = dd4hep::Tube(rmid, rout, hthick, 0.0, 2._pi);
336 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
337 <<
" of dimensions " << rmid <<
", " << rout <<
", " << hthick <<
", 0.0, 360.0";
339 glog.placeVolume(glog1, 1);
342 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
343 <<
" at (0, 0, 0) with no rotation";
345 double thickTot(0), zpos(-hthick);
346 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
347 int ii = layerTypeTop_[ly];
348 int copy = copyNumberTop_[
ii];
349 double hthickl = 0.5 * layerThickTop_[
ii];
350 thickTot += layerThickTop_[
ii];
353 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Layer " << ly <<
":" <<
ii <<
" R " << rmid <<
":" << rout
354 <<
" Thick " << layerThickTop_[
ii];
358 solid = dd4hep::Tube(rmid, rout, hthickl, 0.0, 2._pi);
368 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
369 <<
" of dimensions " << rmid <<
", " << rout <<
", " << hthickl <<
", 0.0, 360.0";
374 glog1.placeVolume(glog2,
copy,
r1);
377 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in "
378 << glog1.name() <<
" at " <<
r1 <<
" with no rotation";
380 ++copyNumberTop_[
ii];
383 if (
std::abs(thickTot - thick) > tol2_) {
384 if (thickTot > thick) {
385 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" is smaller than " << thickTot
386 <<
": thickness of all its components in the top part **** ERROR ****";
388 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" does not match with " << thickTot
389 <<
" of the components in top part";
394 name = nameM +
"Bottom";
396 solid = dd4hep::Tube(rin, rmid, hthick, 0.0, 2._pi);
402 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
403 <<
" of dimensions " << rin <<
", " << rmid <<
", " << hthick <<
", 0.0, 360.0";
406 glog.placeVolume(glog1, 1);
408 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
409 <<
" at (0, 0, 0) with no rotation";
413 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
414 int ii = layerTypeBot_[ly];
415 int copy = copyNumberBot_[
ii];
416 double hthickl = 0.5 * layerThickBot_[
ii];
417 thickTot += layerThickBot_[
ii];
420 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Layer " << ly <<
":" <<
ii <<
" R " << rin <<
":" << rmid
421 <<
" Thick " << layerThickBot_[
ii];
425 solid = dd4hep::Tube(rin, rmid, hthickl, 0.0, 2._pi);
435 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
436 <<
" of dimensions " << rin <<
", " << rmid <<
", " << hthickl <<
", 0.0, 360.0";
441 glog1.placeVolume(glog2,
copy,
r1);
443 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in "
444 << glog1.name() <<
" at " <<
r1 <<
" with no rotation";
446 if (layerSenseBot_[ly] != 0) {
449 << (
copy - firstLayer_) <<
":" << layerCenter_[
copy - firstLayer_];
451 positionSensitive(ctxt,
e, glog2, rin, rmid,
zz + zpos, layerSenseBot_[ly], (
copy - firstLayer_));
454 ++copyNumberBot_[
ii];
456 if (
std::abs(thickTot - thick) > tol2_) {
457 if (thickTot > thick) {
458 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" is smaller than " << thickTot
459 <<
": thickness of all its components in the top part **** ERROR ****";
461 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" does not match with " << thickTot
462 <<
" of the components in top part";
476 int layercenter = layerCenter_[layer];
477 static const double sqrt3 =
std::sqrt(3.0);
478 double r = 0.5 * (waferSize_ + waferSepar_);
479 double R = 2.0 *
r / sqrt3;
480 double dy = 0.75 *
R;
481 int N = (
int)(0.5 * rout /
r) + 2;
482 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
484 int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0), ntot(0),
nin(0);
485 std::vector<int> ntype(6, 0);
486 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog.name() <<
" rout " << rout <<
" N " <<
N
487 <<
" for maximum u, v Offset; Shift " << xyoff.first <<
":" << xyoff.second
488 <<
" WaferSize " << (waferSize_ + waferSepar_);
490 for (
int u = -
N; u <=
N; ++u) {
491 for (
int v = -
N;
v <=
N; ++
v) {
498 double xpos = xyoff.first + nc *
r;
499 double ypos = xyoff.second +
nr *
dy;
510 <<
type <<
" layer:u:v:indx " << (layer + firstLayer_) <<
":" << u <<
":" <<
v
517 if (copies_.count(
copy) == 0)
518 copies_.insert(
copy);
537 <<
" positioned in " << glog.name() <<
" at " << tran <<
" with no rotation";
544 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Maximum # of u " << ium <<
":" << iumAll <<
" # of v " << ivm
545 <<
":" << ivmAll <<
" and " <<
nin <<
":" << kount <<
":" << ntot <<
" wafers ("
546 << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
":" << ntype[3] <<
":"
547 << ntype[4] <<
":" << ntype[5] <<
") for " << glog.name() <<
" R " << rin <<
":"
554 static constexpr
double tol2_ = 0.00001;