9 #include <unordered_set>
18 #include "DD4hep/DetFactoryHelper.h"
25 using namespace angle_units::operators;
36 static constexpr
double tol1 = 0.01 * dd4hep::mm;
37 static constexpr
double tol2 = 0.00001 * dd4hep::mm;
40 wafers_ = args.
value<std::vector<std::string>>(
"WaferNames");
42 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << wafers_.size() <<
" wafers";
43 for (
unsigned int i = 0;
i < wafers_.size(); ++
i)
46 materials_ = args.
value<std::vector<std::string>>(
"MaterialNames");
47 names_ = args.
value<std::vector<std::string>>(
"VolumeNames");
48 thick_ = args.
value<std::vector<double>>(
"Thickness");
49 copyNumber_.resize(materials_.size(), 1);
51 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << materials_.size() <<
" types of volumes";
52 for (
unsigned int i = 0;
i < names_.size(); ++
i)
53 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness "
55 <<
" first copy number " << copyNumber_[
i];
57 layers_ = args.
value<std::vector<int>>(
"Layers");
58 layerThick_ = args.
value<std::vector<double>>(
"LayerThick");
60 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
61 for (
unsigned int i = 0; i < layers_.size(); ++
i)
63 <<
" with " << layers_[
i] <<
" layers";
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];
95 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
96 for (
unsigned int i = 0; i < layerType_.size(); ++
i)
97 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" << i <<
"] with material type " << layerType_[
i] <<
" sensitive class "
100 zMinBlock_ = args.
value<
double>(
"zMinBlock");
101 waferSize_ = args.
value<
double>(
"waferSize");
102 waferSepar_ = args.
value<
double>(
"SensorSeparation");
103 sectors_ = args.
value<
int>(
"Sectors");
104 alpha_ = (1._pi) / sectors_;
105 cosAlpha_ =
cos(alpha_);
109 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_;
111 waferIndex_ = args.
value<std::vector<int>>(
"WaferIndex");
112 waferProperty_ = args.
value<std::vector<int>>(
"WaferProperties");
114 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries";
115 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
124 slopeB_ = args.
value<std::vector<double>>(
"SlopeBottom");
125 zFrontB_ = args.
value<std::vector<double>>(
"ZFrontBottom");
126 rMinFront_ = args.
value<std::vector<double>>(
"RMinFront");
127 slopeT_ = args.
value<std::vector<double>>(
"SlopeTop");
128 zFrontT_ = args.
value<std::vector<double>>(
"ZFrontTop");
129 rMaxFront_ = args.
value<std::vector<double>>(
"RMaxFront");
131 for (
unsigned int i = 0; i < slopeB_.size(); ++
i)
134 for (
unsigned int i = 0; i < slopeT_.size(); ++
i)
145 double zi(zMinBlock_);
147 for (
unsigned int i = 0; i < layers_.size(); ++
i) {
148 double zo = zi + layerThick_[
i];
150 int laymax = laymin + layers_[
i];
153 for (
int ly = laymin; ly < laymax; ++ly) {
154 int ii = layerType_[ly];
155 int copy = copyNumber_[
ii];
156 double hthick = 0.5 * thick_[
ii];
159 thickTot += thick_[
ii];
163 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: Layer " << ly <<
":" << ii <<
" Front "
169 dd4hep::Material matter = ns.
material(materials_[ii]);
172 if (layerSense_[ly] < 1) {
173 std::vector<double> pgonZ, pgonRin, pgonRout;
174 double rmax = routF * cosAlpha_ - tol1;
187 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
189 if (layerSense_[ly] == 0 || absorbMode_ == 0)
190 pgonRout[isec] = rmax;
192 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
194 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
199 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << solid.name() <<
" polyhedra of " << sectors_
202 <<
" sections and filled with " << matter.name();
203 for (
unsigned int k = 0; k < pgonZ.size(); ++
k)
212 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
218 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << solid.name() <<
" Tubs made of " << matter.name()
221 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and position " << glog.name()
222 <<
" number " << copy <<
":" << layerCenter_[copy - firstLayer_];
224 positionSensitive(ctxt, e, glog, rins, routs, zz, layerSense_[ly], (copy - firstLayer_));
228 mother.placeVolume(glog, copy, r1);
231 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << glog.name() <<
" number " << copy <<
" positioned in "
232 << mother.name() <<
" at (0,0," <<
cms::convert2mm(zz) <<
") with no rotation";
239 if (
std::abs(thickTot - layerThick_[i]) >= tol2) {
240 if (thickTot > layerThick_[i]) {
243 <<
": thickness of all its components **** ERROR ****";
246 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
252 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: " << copies_.size() <<
" different wafer copy numbers";
254 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
258 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalEEFileAlgo construction...";
271 static const double sqrt3 =
std::sqrt(3.0);
272 int layercenter = layerCenter_[
layer];
273 double r = 0.5 * (waferSize_ + waferSepar_);
274 double R = 2.0 * r / sqrt3;
275 double dy = 0.75 *
R;
276 int N = (int)(0.5 * rout / r) + 2;
277 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
279 int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0),
ntot(0),
nin(0);
280 std::vector<int> ntype(6, 0);
288 for (
int u = -N; u <=
N; ++u) {
289 for (
int v = -N;
v <=
N; ++
v) {
296 double xpos = xyoff.first + nc *
r;
297 double ypos = xyoff.second + nr *
dy;
304 << layertype <<
" u " << u <<
" v " << v <<
" with " << corner.first
310 if (corner.first > 0 && type >= 0) {
313 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalEEFileAlgo: " << wafers_[
type] <<
" number " << copy <<
" type "
314 << type <<
" layer:u:v:indx " << (layer + firstLayer_) <<
":" << u <<
":" << v
321 if (copies_.count(copy) == 0)
322 copies_.insert(copy);
335 glog.placeVolume(ns.
volume(wafers_[type]),
copy, tran);
339 <<
" DDHGCalEEFileAlgo: " << wafers_[
type] <<
" number " << copy <<
" type " << layertype <<
":" << type
341 <<
", 0) with no rotation";
349 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalEEFileAlgo: Maximum # of u " << ium <<
":" << iumAll <<
" # of v " << ivm
350 <<
":" << ivmAll <<
" and " << nin <<
":" << kount <<
":" <<
ntot <<
" wafers ("
351 << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
":" << ntype[3] <<
":"
352 << ntype[4] <<
":" << ntype[5] <<
") for " << glog.name() <<
" R "
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
Log< level::Info, true > LogVerbatim
dd4hep::Volume volume(const std::string &name, bool exc=true) const
HGCalGeomTools geomTools_
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, double rin, double rout, double zpos, int layertype, int layer)
int32_t waferU(const int32_t index)
std::vector< double > thick_
std::vector< double > layerThick_
int32_t waferLayer(const int32_t index)
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
std::vector< std::string > names_
T value(const std::string &name) const
Log< level::Error, false > LogError
std::vector< int > waferProperty_
int32_t waferOrient(const int32_t property)
static constexpr uint32_t k_CornerSize
constexpr std::array< uint8_t, layerIndexSize > layer
std::string_view name() const
#define DECLARE_DDCMS_DETELEMENT(name, func)
int getType(double xpos, double ypos, double zpos)
std::vector< double > slopeT_
std::vector< int > layerCenter_
std::vector< int > layerSense_
std::unordered_set< int > copies_
static constexpr long s_executed
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
dd4hep::Material material(const std::string &name) const
int32_t waferThick(const int32_t property)
std::string prepend(const std::string &) const
int32_t waferIndex(int32_t layer, int32_t waferU, int32_t waferV, bool old=false)
std::vector< int > copyNumber_
HGCalEEFileAlgo(cms::DDParsingContext &ctxt, xml_h e)
std::vector< double > slopeB_
int32_t waferPartial(const int32_t property)
std::vector< double > zFrontT_
std::vector< int > layerType_
std::vector< int > waferIndex_
std::vector< double > rMinFront_
int32_t waferV(const int32_t index)
static int32_t packTypeUV(int type, int u, int v)
std::vector< double > rMaxFront_
Log< level::Warning, false > LogWarning
std::vector< double > zFrontB_
std::vector< std::string > materials_
std::vector< int > layers_
std::vector< std::string > wafers_
std::string parentName() const
Access value of rParent child node.