10 #include <unordered_set>
19 #include "DD4hep/DetFactoryHelper.h"
26 using namespace angle_units::operators;
35 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: Creating an instance";
37 static constexpr
double tol1 = 0.01 * dd4hep::mm;
38 static constexpr
double tol2 = 0.00001 * 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");
46 edm::LogVerbatim(
"HGCalGeom") <<
"Number of types of wafers: " << waferTypes_ <<
" facings: " << facingTypes_
47 <<
" partials: " << partialTypes_ <<
" Orientations: " << orientationTypes_;
49 firstLayer_ = args.
value<
int>(
"FirstLayer");
50 absorbMode_ = args.
value<
int>(
"AbsorberMode");
51 sensitiveMode_ = args.
value<
int>(
"SensitiveMode");
54 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
56 zMinBlock_ = args.
value<
double>(
"zMinBlock");
57 waferSize_ = args.
value<
double>(
"waferSize");
58 waferSepar_ = args.
value<
double>(
"SensorSeparation");
59 sectors_ = args.
value<
int>(
"Sectors");
60 alpha_ = (1._pi) / sectors_;
61 cosAlpha_ =
cos(alpha_);
66 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_
67 <<
" rotation matrix " << rotstr_;
69 waferFull_ = args.
value<std::vector<std::string>>(
"WaferNamesFull");
70 waferPart_ = args.
value<std::vector<std::string>>(
"WaferNamesPartial");
72 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << waferFull_.size() <<
" full and " << waferPart_.size()
73 <<
" partial modules\nDDHGCalSiliconModule:Full Modules:";
74 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
75 for (
unsigned int i1 = 0; i1 < i1max; i1 += 2) {
76 std::ostringstream st1;
77 unsigned int i2 =
std::min((i1 + 2), i1max);
78 for (
unsigned int i = i1;
i < i2; ++
i)
79 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
83 i1max =
static_cast<unsigned int>(waferPart_.size());
84 for (
unsigned int i1 = 0; i1 < i1max; i1 += 2) {
85 std::ostringstream st1;
86 unsigned int i2 =
std::min((i1 + 2), i1max);
87 for (
unsigned int i = i1;
i < i2; ++
i)
88 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
92 materials_ = args.
value<std::vector<std::string>>(
"MaterialNames");
93 names_ = args.
value<std::vector<std::string>>(
"VolumeNames");
94 thick_ = args.
value<std::vector<double>>(
"Thickness");
95 copyNumber_.resize(materials_.size(), 1);
97 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << materials_.size() <<
" types of volumes";
98 for (
unsigned int i = 0;
i < names_.size(); ++
i)
99 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness "
101 <<
" first copy number " << copyNumber_[
i];
103 layers_ = args.
value<std::vector<int>>(
"Layers");
104 layerThick_ = args.
value<std::vector<double>>(
"LayerThick");
106 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
107 for (
unsigned int i = 0; i < layers_.size(); ++
i)
109 <<
" with " << layers_[
i] <<
" layers";
111 layerType_ = args.
value<std::vector<int>>(
"LayerType");
112 layerSense_ = args.
value<std::vector<int>>(
"LayerSense");
113 layerTypes_ = args.
value<std::vector<int>>(
"LayerTypes");
115 for (
unsigned int i = 0; i < layerTypes_.size(); ++
i)
118 if (firstLayer_ > 0) {
119 for (
unsigned int i = 0; i < layerType_.size(); ++
i) {
120 if (layerSense_[i] > 0) {
121 int ii = layerType_[
i];
122 copyNumber_[
ii] = (layerSense_[
i] == 1) ? firstLayer_ : (firstLayer_ + 1);
124 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " << i <<
":" << ii <<
" with "
125 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
133 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
134 for (
unsigned int i = 0; i < layerType_.size(); ++
i)
135 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" << i <<
"] with material type " << layerType_[
i] <<
" sensitive class "
138 slopeB_ = args.
value<std::vector<double>>(
"SlopeBottom");
139 zFrontB_ = args.
value<std::vector<double>>(
"ZFrontBottom");
140 rMinFront_ = args.
value<std::vector<double>>(
"RMinFront");
141 slopeT_ = args.
value<std::vector<double>>(
"SlopeTop");
142 zFrontT_ = args.
value<std::vector<double>>(
"ZFrontTop");
143 rMaxFront_ = args.
value<std::vector<double>>(
"RMaxFront");
145 for (
unsigned int i = 0; i < slopeB_.size(); ++
i)
148 for (
unsigned int i = 0; i < slopeT_.size(); ++
i)
152 waferIndex_ = args.
value<std::vector<int>>(
"WaferIndex");
153 waferProperty_ = args.
value<std::vector<int>>(
"WaferProperties");
154 waferLayerStart_ = args.
value<std::vector<int>>(
"WaferLayerStart");
156 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in "
157 << waferLayerStart_.size() <<
" layers";
158 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
160 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
172 edm::LogVerbatim(
"HGCalGeom") <<
"==>> Constructing DDHGCalSiliconModule...";
176 double zi(zMinBlock_);
178 for (
unsigned int i = 0; i < layers_.size(); ++
i) {
179 double zo = zi + layerThick_[
i];
181 int laymax = laymin + layers_[
i];
184 for (
int ly = laymin; ly < laymax; ++ly) {
185 int ii = layerType_[ly];
186 int copy = copyNumber_[
ii];
187 double hthick = 0.5 * thick_[
ii];
190 thickTot += thick_[
ii];
194 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: Layer " << ly <<
":" << ii <<
" Front "
200 dd4hep::Material matter = ns.
material(materials_[ii]);
203 if (layerSense_[ly] < 1) {
204 std::vector<double> pgonZ, pgonRin, pgonRout;
205 double rmax = routF * cosAlpha_ - tol1;
218 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
220 if (layerSense_[ly] == 0 || absorbMode_ == 0)
221 pgonRout[isec] = rmax;
223 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
225 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
230 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << solid.name() <<
" polyhedra of " << sectors_
233 <<
" sections and filled with " << matter.name();
234 for (
unsigned int k = 0; k < pgonZ.size(); ++
k)
243 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
249 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << solid.name() <<
" Tubs made of " << matter.name()
252 <<
cms::convert2mm(hthick) <<
", 0.0, 360.0 and position " << glog.name()
253 <<
" number " << copy <<
":" << layerTypes_[copy - firstLayer_];
255 positionSensitive(ctxt, e, glog, (copy - firstLayer_));
259 dd4hep::Rotation3D
rot;
269 mother.placeVolume(glog, copy, dd4hep::Transform3D(rot, r1));
270 int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
271 copyNumber_[
ii] = copy + inc;
273 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << glog.name() <<
" number " << copy
274 <<
" positioned in " << mother.name() <<
" at (0,0," <<
cms::convert2mm(zz)
275 <<
") with " << rotName <<
" rotation";
282 if (
std::abs(thickTot - layerThick_[i]) >= tol2) {
283 if (thickTot > layerThick_[i]) {
286 <<
": thickness of all its components **** ERROR ****";
289 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
295 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: " << 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 DDHGCalSiliconModule construction...";
307 static const double sqrt3 =
std::sqrt(3.0);
312 int firstWafer = waferLayerStart_[
layer];
313 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
314 :
static_cast<int>(waferIndex_.size()));
315 double r = 0.5 * (waferSize_ + waferSepar_);
316 double R = 2.0 * r / sqrt3;
317 double dy = 0.75 *
R;
318 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
320 int ium(0), ivm(0), kount(0);
321 std::vector<int> ntype(3, 0);
325 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index "
326 << firstWafer <<
":" << (lastWafer - 1);
328 for (
int k = firstWafer;
k < lastWafer; ++
k) {
337 double xpos = xyoff.first + nc *
r;
338 double ypos = xyoff.second + nr *
dy;
345 i = layertype * waferTypes_ +
type;
346 wafer = waferFull_[
i];
348 i = (part - 1) * waferTypes_ * facingTypes_ * orientationTypes_ + layertype * waferTypes_ * orientationTypes_ +
349 type * orientationTypes_ + orien;
351 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:ind " << layertype <<
":" << type <<
":" << part
352 <<
":" << orien <<
":" << i <<
":" << waferPart_.size();
354 wafer = waferPart_[
i];
359 <<
" Wafer " << wafer <<
" number " << copy <<
" type:part:orien:ind " << type
360 <<
":" << part <<
":" << orien <<
":" << i <<
" layer:u:v:indx "
361 << (layer + firstLayer_) <<
":" << u <<
":" << v;
367 if (copies_.count(copy) == 0)
368 copies_.insert(copy);
371 glog.placeVolume(ns.
volume(wafer),
copy, tran);
374 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalSiliconModule: " << wafer <<
" number " << copy <<
" type " << layertype
375 <<
":" << type <<
" positioned in " << glog.name() <<
" at ("
381 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconModule: Maximum # of u " << ium <<
" # of v " << ivm <<
" and "
382 << kount <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
") for "
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
std::unordered_set< int > copies_
std::vector< double > slopeT_
std::vector< double > slopeB_
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
std::vector< int > copyNumber_
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
T value(const std::string &name) const
std::string to_string(const V &value)
std::vector< int > layerSense_
Log< level::Error, false > LogError
int32_t waferOrient(const int32_t property)
std::vector< double > zFrontT_
constexpr std::array< uint8_t, layerIndexSize > layer
std::string_view name() const
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
HGCalGeomTools geomTools_
#define DECLARE_DDCMS_DETELEMENT(name, func)
std::vector< int > layerTypes_
std::vector< double > zFrontB_
static constexpr long s_executed
std::vector< double > thick_
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
std::vector< std::string > names_
dd4hep::Material material(const std::string &name) const
int32_t waferThick(const int32_t property)
std::vector< int > waferProperty_
std::string prepend(const std::string &) const
std::vector< std::string > waferPart_
std::vector< double > rMaxFront_
std::vector< int > waferLayerStart_
std::vector< std::string > materials_
std::vector< int > layerType_
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, int layer)
const dd4hep::Rotation3D & rotation(const std::string &name) const
int32_t waferPartial(const int32_t property)
int32_t waferV(const int32_t index)
static int32_t packTypeUV(int type, int u, int v)
std::vector< int > layers_
Log< level::Warning, false > LogWarning
std::vector< std::string > waferFull_
std::vector< double > rMinFront_
std::vector< int > waferIndex_
std::vector< double > layerThick_
std::string parentName() const
Access value of rParent child node.
HGCalSiliconModule(cms::DDParsingContext &ctxt, xml_h e)