11 #include <unordered_set> 14 #include "DD4hep/DetFactoryHelper.h" 38 waferNames_ =
args.value<std::vector<std::string>>(
"WaferNames");
40 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << 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") <<
"DDHGCalHEAlgo: " << 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 " 53 <<
" first copy number " << copyNumber_[
i];
55 layerNumbers_ =
args.value<std::vector<int>>(
"Layers");
56 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
57 rMixLayer_ =
args.value<std::vector<double>>(
"LayerRmix");
59 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerNumbers_.size() <<
" blocks";
60 for (
unsigned int i = 0;
i < layerNumbers_.size(); ++
i)
65 layerType_ =
args.value<std::vector<int>>(
"LayerType");
66 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
67 firstLayer_ =
args.value<
int>(
"FirstLayer");
68 absorbMode_ =
args.value<
int>(
"AbsorberMode");
69 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
72 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
74 layerCenter_ =
args.value<std::vector<int>>(
"LayerCenter");
76 for (
unsigned int i = 0;
i < layerCenter_.size(); ++
i)
79 if (firstLayer_ > 0) {
80 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
81 if (layerSense_[
i] > 0) {
82 int ii = layerType_[
i];
83 copyNumber_[
ii] = firstLayer_;
85 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 86 << 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") <<
"DDHGCalHEAlgo: " << materialsTop_.size() <<
" types of volumes in the top part";
105 for (
unsigned int i = 0;
i < materialsTop_.size(); ++
i)
106 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " 108 <<
" first copy number " << copyNumberTop_[
i];
109 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
110 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
111 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
113 materialsBot_ =
args.value<std::vector<std::string>>(
"BottomMaterialNames");
114 namesBot_ =
args.value<std::vector<std::string>>(
"BottomVolumeNames");
115 layerTypeBot_ =
args.value<std::vector<int>>(
"BottomLayerType");
116 layerSenseBot_ =
args.value<std::vector<int>>(
"BottomLayerSense");
117 layerThickBot_ =
args.value<std::vector<double>>(
"BottomLayerThickness");
118 copyNumberBot_.resize(materialsBot_.size(), 1);
121 <<
" types of volumes in the bottom part";
122 for (
unsigned int i = 0;
i < materialsBot_.size(); ++
i)
123 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesBot_[
i] <<
" of thickness " 125 <<
" first copy number " << copyNumberBot_[
i];
126 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeBot_.size() <<
" layers in the bottom part";
127 for (
unsigned int i = 0;
i < layerTypeBot_.size(); ++
i)
128 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeBot_[
i]
129 <<
" sensitive class " << layerSenseBot_[
i];
131 zMinBlock_ =
args.value<
double>(
"zMinBlock");
132 rad100to200_ =
args.value<std::vector<double>>(
"rad100to200");
133 rad200to300_ =
args.value<std::vector<double>>(
"rad200to300");
134 zMinRadPar_ =
args.value<
double>(
"zMinForRadPar");
135 choiceType_ =
args.value<
int>(
"choiceType");
136 nCutRadPar_ =
args.value<
int>(
"nCornerCut");
137 fracAreaMin_ =
args.value<
double>(
"fracAreaMin");
138 waferSize_ =
args.value<
double>(
"waferSize");
139 waferSepar_ =
args.value<
double>(
"SensorSeparation");
140 sectors_ =
args.value<
int>(
"Sectors");
141 alpha_ = (1._pi) / sectors_;
142 cosAlpha_ =
cos(alpha_);
145 <<
" radius for wafer type separation uses " << rad100to200_.size()
146 <<
" parameters; zmin " <<
cms::convert2mm(zMinRadPar_) <<
" cutoff " << choiceType_
147 <<
":" << nCutRadPar_ <<
":" << fracAreaMin_ <<
" wafer width " 149 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_;
150 for (
unsigned int k = 0;
k < rad100to200_.size(); ++
k)
151 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k <<
"] 100-200 " << rad100to200_[
k] <<
" 200-300 " << rad200to300_[
k];
153 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
154 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
155 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
156 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
157 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
158 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
160 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
163 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
169 waferType_ = std::make_unique<HGCalWaferType>(rad100to200_,
182 double zi(zMinBlock_);
184 for (
unsigned int i = 0;
i < layerNumbers_.size();
i++) {
185 double zo = zi + layerThick_[
i];
187 int laymax = laymin + layerNumbers_[
i];
190 for (
int ly = laymin; ly < laymax; ++ly) {
191 int ii = layerType_[ly];
192 int copy = copyNumber_[
ii];
193 double hthick = 0.5 * thickness_[
ii];
196 thickTot += thickness_[
ii];
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") <<
"DDHGCalHEAlgo: " << solid.name() <<
" polyhedra of " << sectors_
248 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
249 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
258 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
264 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
267 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and positioned in: " << glog.name()
268 <<
" number " <<
copy;
270 positionMix(ctxt,
e, glog,
name,
copy, thickness_[
ii], matter, rins, rMixLayer_[
i], routs,
zz);
274 mother.placeVolume(glog,
copy, r1);
277 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << glog.name() <<
" number " <<
copy <<
" positioned in " 284 if (
std::abs(thickTot - layerThick_[
i]) >= tol2_) {
285 if (thickTot > layerThick_[
i]) {
288 <<
": thickness of all its components **** ERROR ****";
291 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
297 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << copies_.size() <<
" different wafer copy numbers";
299 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
303 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalHEAlgo construction...";
321 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
322 int ii = layerTypeTop_[ly];
323 copyNumberTop_[
ii] = copyM;
325 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
326 int ii = layerTypeBot_[ly];
327 copyNumberBot_[
ii] = copyM;
329 double hthick = 0.5 * thick;
333 dd4hep::Solid solid = dd4hep::Tube(rmid, rout, hthick, 0.0, 2._pi);
338 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
342 glog.placeVolume(glog1, 1);
345 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
346 <<
" at (0,0,0) with no rotation";
348 double thickTot(0), zpos(-hthick);
349 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
350 int ii = layerTypeTop_[ly];
351 int copy = copyNumberTop_[
ii];
352 double hthickl = 0.5 * layerThickTop_[
ii];
353 thickTot += layerThickTop_[
ii];
361 solid = dd4hep::Tube(rmid, rout, hthickl, 0.0, 2._pi);
371 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
378 glog1.placeVolume(glog2,
copy, r1);
381 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in " 382 << glog1.name() <<
" at (0,0," <<
cms::convert2mm(zpos) <<
") with no rotation";
384 ++copyNumberTop_[
ii];
387 if (
std::abs(thickTot - thick) >= tol2_) {
388 if (thickTot > thick) {
391 <<
": thickness of all its components in the top part **** ERROR ****";
395 <<
" of the components in top part";
400 name = nameM +
"Bottom";
402 solid = dd4hep::Tube(rin, rmid, hthick, 0.0, 2._pi);
408 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
413 glog.placeVolume(glog1, 1);
415 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << glog1.name() <<
" number 1 positioned in " << glog.name()
416 <<
" at (0,0,0) with no rotation";
420 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
421 int ii = layerTypeBot_[ly];
422 int copy = copyNumberBot_[
ii];
423 double hthickl = 0.5 * layerThickBot_[
ii];
424 thickTot += layerThickBot_[
ii];
432 solid = dd4hep::Tube(rin, rmid, hthickl, 0.0, 2._pi);
442 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.name() <<
" Tubs made of " << matter1.name()
449 glog1.placeVolume(glog2,
copy, r1);
451 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Position " << glog2.name() <<
" number " <<
copy <<
" in " 452 << glog1.name() <<
" at (0,0," <<
cms::convert2mm(zpos) <<
") with no rotation";
454 if (layerSenseBot_[ly] != 0) {
457 <<
":" << (
copy - firstLayer_) <<
":" << layerCenter_[
copy - firstLayer_];
459 positionSensitive(ctxt,
e, glog2, rin, rmid,
zz + zpos, layerSenseBot_[ly], layerCenter_[
copy - firstLayer_]);
462 ++copyNumberBot_[
ii];
464 if (
std::abs(thickTot - thick) >= tol2_) {
465 if (thickTot > thick) {
468 <<
": thickness of all its components in the top part **** ERROR ****";
472 <<
" of the components in top part";
486 static const double sqrt3 =
std::sqrt(3.0);
487 double r = 0.5 * (waferSize_ + waferSepar_);
488 double R = 2.0 * r / sqrt3;
489 double dy = 0.75 *
R;
490 int N = (
int)(0.5 * rout / r) + 2;
491 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
493 int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0),
ntot(0), nin(0);
494 std::vector<int> ntype(6, 0);
496 <<
" for maximum u, v Offset; Shift " <<
cms::convert2mm(xyoff.first) <<
":" 500 for (
int u = -
N; u <=
N; ++u) {
501 for (
int v = -
N;
v <=
N; ++
v) {
504 double xpos = xyoff.first + nc * r;
505 double ypos = xyoff.second +
nr *
dy;
513 int type = waferType_->getType((xpos / dd4hep::mm), (ypos / dd4hep::mm), (zpos / dd4hep::mm));
521 if (copies_.count(
copy) == 0)
522 copies_.insert(
copy);
541 <<
"DDHGCalHEAlgo: " << glog.name() <<
" number " <<
copy <<
" positioned in " << glog.name() <<
" at (" 549 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Maximum # of u " << ium <<
":" << iumAll <<
" # of v " << ivm
550 <<
":" << ivmAll <<
" and " << nin <<
":" << kount <<
":" <<
ntot <<
" wafers (" 551 << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
":" << ntype[3] <<
":" 552 << ntype[4] <<
":" << ntype[5] <<
") for " << glog.name() <<
" R " 606 static constexpr
double tol1_ = 0.01 * dd4hep::mm;
607 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;
std::vector< int > layerNumbers_
Log< level::Info, true > LogVerbatim
std::vector< double > rad100to200_
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)
HGCalGeomTools geomTools_
std::unordered_set< int > copies_
std::vector< double > slopeT_
std::vector< std::string > volumeNames_
std::vector< double > rMixLayer_
std::vector< double > thickness_
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
HGCalHEAlgo(cms::DDParsingContext &ctxt, xml_h e)
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, double rin, double rout, double zpos, int layertype, int layercenter)
std::vector< int > copyNumberTop_
std::string to_string(const V &value)
std::vector< double > layerThick_
std::vector< double > rMaxFront_
std::vector< int > layerSense_
std::vector< int > layerTypeTop_
Log< level::Error, false > LogError
dd4hep::Material material(const std::string &name) const
std::vector< double > zFrontT_
std::vector< std::string > namesBot_
std::vector< std::string > materialsTop_
static constexpr uint32_t k_CornerSize
std::vector< double > zFrontB_
std::vector< std::string > waferNames_
std::vector< std::string > materialsBot_
std::vector< double > layerThickTop_
std::vector< int > layerSenseBot_
#define DECLARE_DDCMS_DETELEMENT(name, func)
std::vector< double > slopeB_
static constexpr long s_executed
std::unique_ptr< HGCalWaferType > waferType_
std::vector< double > rMinFront_
std::vector< int > layerType_
std::string_view name() const
Cos< T >::type cos(const T &t)
std::vector< int > copyNumber_
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
std::vector< int > layerTypeBot_
std::vector< std::string > namesTop_
std::vector< std::string > materials_
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
std::vector< double > rad200to300_
std::vector< int > copyNumberBot_
static int32_t packTypeUV(int type, int u, int v)
Log< level::Warning, false > LogWarning
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
dd4hep::Volume volume(const std::string &name, bool exc=true) const
std::vector< double > layerThickBot_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
std::string prepend(const std::string &) const
std::vector< int > layerCenter_