9 #include <unordered_set> 18 #include "DD4hep/DetFactoryHelper.h" 37 static constexpr
double tol1 = 0.01 * dd4hep::mm;
40 waferNames_ =
args.value<std::vector<std::string>>(
"WaferNames");
42 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << waferNames_.size() <<
" wafers";
43 for (
unsigned int i = 0;
i < waferNames_.size(); ++
i)
46 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
47 volumeNames_ =
args.value<std::vector<std::string>>(
"VolumeNames");
48 thickness_ =
args.value<std::vector<double>>(
"Thickness");
49 copyNumber_.resize(materials_.size(), 1);
51 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materials_.size() <<
" types of volumes";
52 for (
unsigned int i = 0;
i < volumeNames_.size(); ++
i)
53 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << volumeNames_[
i] <<
" of thickness " 55 <<
" first copy number " << copyNumber_[
i];
57 layerNumbers_ =
args.value<std::vector<int>>(
"Layers");
58 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
59 rMixLayer_ =
args.value<std::vector<double>>(
"LayerRmix");
61 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerNumbers_.size() <<
" blocks";
62 for (
unsigned int i = 0;
i < layerNumbers_.size(); ++
i)
67 layerType_ =
args.value<std::vector<int>>(
"LayerType");
68 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
69 firstLayer_ =
args.value<
int>(
"FirstLayer");
70 absorbMode_ =
args.value<
int>(
"AbsorberMode");
71 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
74 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
76 layerCenter_ =
args.value<std::vector<int>>(
"LayerCenter");
78 for (
unsigned int i = 0;
i < layerCenter_.size(); ++
i)
81 if (firstLayer_ > 0) {
82 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
83 if (layerSense_[
i] > 0) {
84 int ii = layerType_[
i];
85 copyNumber_[
ii] = firstLayer_;
87 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 88 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
97 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
98 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
99 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 102 materialsTop_ =
args.value<std::vector<std::string>>(
"TopMaterialNames");
103 namesTop_ =
args.value<std::vector<std::string>>(
"TopVolumeNames");
104 layerThickTop_ =
args.value<std::vector<double>>(
"TopLayerThickness");
105 layerTypeTop_ =
args.value<std::vector<int>>(
"TopLayerType");
106 copyNumberTop_.resize(materialsTop_.size(), 1);
108 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materialsTop_.size()
109 <<
" types of volumes in the top part";
110 for (
unsigned int i = 0;
i < materialsTop_.size(); ++
i)
111 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " 113 <<
" first copy number " << copyNumberTop_[
i];
114 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
115 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
116 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
118 materialsBot_ =
args.value<std::vector<std::string>>(
"BottomMaterialNames");
119 namesBot_ =
args.value<std::vector<std::string>>(
"BottomVolumeNames");
120 layerTypeBot_ =
args.value<std::vector<int>>(
"BottomLayerType");
121 layerSenseBot_ =
args.value<std::vector<int>>(
"BottomLayerSense");
122 layerThickBot_ =
args.value<std::vector<double>>(
"BottomLayerThickness");
123 copyNumberBot_.resize(materialsBot_.size(), 1);
125 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << materialsBot_.size()
126 <<
" types of volumes in the bottom part";
127 for (
unsigned int i = 0;
i < materialsBot_.size(); ++
i)
128 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesBot_[
i] <<
" of thickness " 130 <<
" first copy number " << copyNumberBot_[
i];
131 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeBot_.size() <<
" layers in the bottom part";
132 for (
unsigned int i = 0;
i < layerTypeBot_.size(); ++
i)
133 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeBot_[
i]
134 <<
" sensitive class " << layerSenseBot_[
i];
136 zMinBlock_ =
args.value<
double>(
"zMinBlock");
137 waferSize_ =
args.value<
double>(
"waferSize");
138 waferSepar_ =
args.value<
double>(
"SensorSeparation");
139 sectors_ =
args.value<
int>(
"Sectors");
140 alpha_ = (1._pi) / sectors_;
141 cosAlpha_ =
cos(alpha_);
145 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_;
147 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
148 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
150 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries";
151 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
160 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
161 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
162 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
163 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
164 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
165 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
167 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
170 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
179 double zi(zMinBlock_);
181 for (
unsigned int i = 0;
i < layerNumbers_.size();
i++) {
182 double zo = zi + layerThick_[
i];
184 int laymax = laymin + layerNumbers_[
i];
187 for (
int ly = laymin; ly < laymax; ++ly) {
188 int ii = layerType_[ly];
189 int copy = copyNumber_[
ii];
190 double hthick = 0.5 * thickness_[
ii];
193 thickTot += thickness_[
ii];
198 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Layer " << ly <<
":" <<
ii <<
" Front " 207 if (layerSense_[ly] < 1) {
208 std::vector<double> pgonZ, pgonRin, pgonRout;
223 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
225 if (layerSense_[ly] == 0 || absorbMode_ == 0)
226 pgonRout[isec] = rmax;
228 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
231 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
236 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" polyhedra of " << sectors_
238 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
239 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
248 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
254 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
257 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and positioned in: " << glog.name()
258 <<
" number " <<
copy;
260 positionMix(ctxt,
e, glog,
name,
copy, thickness_[
ii], matter, rins, rMixLayer_[
i], routs,
zz);
264 mother.placeVolume(glog,
copy, r1);
267 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog.name() <<
" number " <<
copy <<
" positioned in " 274 if (
std::abs(thickTot - layerThick_[
i]) > tol2_) {
275 if (thickTot > layerThick_[
i]) {
278 <<
": thickness of all its components **** ERROR ****";
281 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
287 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << copies_.size() <<
" different wafer copy numbers";
289 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
293 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalHEFileAlgo construction...";
311 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
312 int ii = layerTypeTop_[ly];
313 copyNumberTop_[
ii] = copyM;
315 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
316 int ii = layerTypeBot_[ly];
317 copyNumberBot_[
ii] = copyM;
319 double hthick = 0.5 * thick;
323 dd4hep::Solid solid = dd4hep::Tube(rmid, rout, hthick, 0.0, 2._pi);
328 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
332 glog.placeVolume(glog1, 1);
335 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
336 <<
" at (0,0,0) with no rotation";
338 double thickTot(0), zpos(-hthick);
339 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
340 int ii = layerTypeTop_[ly];
341 int copy = copyNumberTop_[
ii];
342 double hthickl = 0.5 * layerThickTop_[
ii];
343 thickTot += layerThickTop_[
ii];
351 solid = dd4hep::Tube(rmid, rout, hthickl, 0.0, 2._pi);
361 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
368 glog1.placeVolume(glog2,
copy, r1);
371 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in " 372 << glog1.name() <<
" at (0,0," <<
cms::convert2mm(zpos) <<
") with no rotation";
374 ++copyNumberTop_[
ii];
377 if (
std::abs(thickTot - thick) > tol2_) {
378 if (thickTot > thick) {
381 <<
": thickness of all its components in the top part **** ERROR ****";
385 <<
" of the components in top part";
390 name = nameM +
"Bottom";
392 solid = dd4hep::Tube(rin, rmid, hthick, 0.0, 2._pi);
398 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
403 glog.placeVolume(glog1, 1);
405 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
406 <<
" at (0,0,0) with no rotation";
410 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
411 int ii = layerTypeBot_[ly];
412 int copy = copyNumberBot_[
ii];
413 double hthickl = 0.5 * layerThickBot_[
ii];
414 thickTot += layerThickBot_[
ii];
422 solid = dd4hep::Tube(rin, rmid, hthickl, 0.0, 2._pi);
432 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
439 glog1.placeVolume(glog2,
copy, r1);
441 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in " 442 << glog1.name() <<
" at (0,0," <<
cms::convert2mm(zpos) <<
") with no rotation";
444 if (layerSenseBot_[ly] != 0) {
447 <<
":" << (
copy - firstLayer_) <<
":" << layerCenter_[
copy - firstLayer_];
449 positionSensitive(ctxt,
e, glog2, rin, rmid,
zz + zpos, layerSenseBot_[ly], (
copy - firstLayer_));
452 ++copyNumberBot_[
ii];
454 if (
std::abs(thickTot - thick) > tol2_) {
455 if (thickTot > thick) {
458 <<
": thickness of all its components in the top part **** ERROR ****";
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);
488 <<
" for maximum u, v Offset; Shift " <<
cms::convert2mm(xyoff.first) <<
":" 492 for (
int u = -
N; u <=
N; ++u) {
493 for (
int v = -
N;
v <=
N; ++
v) {
500 double xpos = xyoff.first + nc * r;
501 double ypos = xyoff.second +
nr *
dy;
514 <<
type <<
" layer:u:v:indx " << (layer + firstLayer_) <<
":" << u <<
":" <<
v 521 if (copies_.count(
copy) == 0)
522 copies_.insert(
copy);
537 <<
"DDHGCalHEFileAlgo: " << waferNames_[
type] <<
" number " <<
copy <<
" type " << layertype <<
":" 546 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEFileAlgo: Maximum # of u " << ium <<
":" << iumAll <<
" # of v " << ivm
547 <<
":" << ivmAll <<
" and " << nin <<
":" << kount <<
":" <<
ntot <<
" wafers (" 548 << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
":" << ntype[3] <<
":" 549 << ntype[4] <<
":" << ntype[5] <<
") for " << glog.name() <<
" R " 556 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;
Log< level::Info, true > LogVerbatim
std::vector< std::string > namesBot_
std::vector< int > copyNumberBot_
static int getType(int index, const HGCalParameters::waferInfo_map &wafers)
std::vector< std::string > materialsBot_
std::vector< double > rMinFront_
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
HGCalGeomTools geomTools_
std::vector< double > layerThickBot_
std::vector< int > layerTypeTop_
std::string to_string(const V &value)
std::vector< double > thickness_
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Log< level::Error, false > LogError
std::vector< double > layerThickTop_
std::vector< double > slopeB_
dd4hep::Material material(const std::string &name) const
std::vector< std::string > namesTop_
std::vector< int > copyNumber_
int32_t waferOrient(const int32_t property)
static constexpr uint32_t k_CornerSize
#define DECLARE_DDCMS_DETELEMENT(name, func)
std::vector< int > copyNumberTop_
std::vector< std::string > materialsTop_
std::vector< std::string > volumeNames_
static constexpr long s_executed
std::string_view name() const
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
std::vector< double > zFrontT_
int32_t waferThick(const int32_t property)
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::unordered_set< int > copies_
std::vector< std::string > waferNames_
std::vector< int > waferProperty_
std::vector< double > slopeT_
std::vector< int > waferIndex_
std::vector< int > layerTypeBot_
HGCalHEFileAlgo(cms::DDParsingContext &ctxt, xml_h e)
std::vector< int > layerNumbers_
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter, double rin, double rmid, double rout, double zz)
std::vector< int > layerSense_
int32_t waferPartial(const int32_t property)
std::vector< double > rMaxFront_
std::vector< double > layerThick_
std::vector< int > layerSenseBot_
int32_t waferV(const int32_t index)
std::vector< double > zFrontB_
static int32_t packTypeUV(int type, int u, int v)
std::vector< int > layerCenter_
std::vector< int > layerType_
Log< level::Warning, false > LogWarning
std::vector< std::string > materials_
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
dd4hep::Volume volume(const std::string &name, bool exc=true) const
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, double rin, double rout, double zpos, int layertype, int layer)
std::vector< double > rMixLayer_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
std::string prepend(const std::string &) const