10 #include <unordered_set> 21 #include "DD4hep/DetFactoryHelper.h" 32 throw cms::Exception(
"HGCalGeom") <<
"Wrong initialization to HGCalSiliconRotatedModule";
39 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Creating an instance";
41 static constexpr
double tol1 = 0.01 * dd4hep::mm;
42 static constexpr
double tol2 = 0.00001 * dd4hep::mm;
45 waferTypes_ =
args.value<
int>(
"WaferTypes");
46 facingTypes_ =
args.value<
int>(
"FacingTypes");
47 orientationTypes_ =
args.value<
int>(
"OrientationTypes");
48 placeOffset_ =
args.value<
int>(
"PlaceOffset");
50 edm::LogVerbatim(
"HGCalGeom") <<
"Number of types of wafers: " << waferTypes_ <<
" facings: " << facingTypes_
51 <<
" Orientations: " << orientationTypes_ <<
" PlaceOffset: " << placeOffset_;
53 firstLayer_ =
args.value<
int>(
"FirstLayer");
54 absorbMode_ =
args.value<
int>(
"AbsorberMode");
55 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
58 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
60 zMinBlock_ =
args.value<
double>(
"zMinBlock");
61 waferSize_ =
args.value<
double>(
"waferSize");
62 waferSepar_ =
args.value<
double>(
"SensorSeparation");
63 sectors_ =
args.value<
int>(
"Sectors");
64 cassettes_ =
args.value<
int>(
"Cassettes");
65 alpha_ = (1._pi) / sectors_;
66 cosAlpha_ =
cos(alpha_);
71 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_
72 <<
" rotation matrix " << rotstr_ << cassettes_ <<
" cassettes";
74 waferFull_ =
args.value<std::vector<std::string>>(
"WaferNamesFull");
75 waferPart_ =
args.value<std::vector<std::string>>(
"WaferNamesPartial");
77 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << waferFull_.size() <<
" full and " 78 << waferPart_.size() <<
" partial modules\nDDHGCalSiliconRotatedModule:Full Modules:";
79 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
80 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
81 std::ostringstream st1;
83 for (
unsigned int i =
i1;
i <
i2; ++
i)
84 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
87 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Partial Modules:";
88 i1max =
static_cast<unsigned int>(waferPart_.size());
89 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
90 std::ostringstream st1;
92 for (
unsigned int i =
i1;
i <
i2; ++
i)
93 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
97 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
98 names_ =
args.value<std::vector<std::string>>(
"VolumeNames");
99 thick_ =
args.value<std::vector<double>>(
"Thickness");
100 copyNumber_.resize(materials_.size(), 1);
102 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << materials_.size() <<
" types of volumes";
103 for (
unsigned int i = 0;
i < names_.size(); ++
i)
104 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness " 106 <<
" first copy number " << copyNumber_[
i];
108 layers_ =
args.value<std::vector<int>>(
"Layers");
109 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
111 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
112 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
114 <<
" with " << layers_[
i] <<
" layers";
116 layerType_ =
args.value<std::vector<int>>(
"LayerType");
117 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
118 layerTypes_ =
args.value<std::vector<int>>(
"LayerTypes");
120 for (
unsigned int i = 0;
i < layerTypes_.size(); ++
i)
123 if (firstLayer_ > 0) {
124 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
125 if (layerSense_[
i] > 0) {
126 int ii = layerType_[
i];
127 copyNumber_[
ii] = (layerSense_[
i] == 1) ? firstLayer_ : (firstLayer_ + 1);
129 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 130 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
138 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
139 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
140 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 143 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
144 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
145 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
146 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
147 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
148 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
150 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
153 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
157 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
158 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
159 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
160 cassetteShift_ =
args.value<std::vector<double>>(
"CassetteShift");
162 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in " 163 << waferLayerStart_.size() <<
" layers";
164 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
166 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
174 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << cassetteShift_.size()
175 <<
" elements for cassette shifts";
176 unsigned int j1max = cassetteShift_.size();
177 for (
unsigned int j1 = 0; j1 < j1max; j1 += 6) {
178 std::ostringstream st1;
179 unsigned int j2 =
std::min((j1 + 6), j1max);
180 for (
unsigned int j = j1;
j < j2; ++
j)
181 st1 <<
" [" <<
j <<
"] " << std::setw(9) << cassetteShift_[
j];
187 cassette_.setParameter(cassettes_, cassetteShift_);
190 edm::LogVerbatim(
"HGCalGeom") <<
"==>> Constructing DDHGCalSiliconRotatedModule...";
194 double zi(zMinBlock_);
196 for (
unsigned int i = 0;
i < layers_.size(); ++
i) {
197 double zo = zi + layerThick_[
i];
199 int laymax = laymin + layers_[
i];
202 for (
int ly = laymin; ly < laymax; ++ly) {
203 int ii = layerType_[ly];
204 int copy = copyNumber_[
ii];
205 double hthick = 0.5 * thick_[
ii];
208 thickTot += thick_[
ii];
212 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Layer " << ly <<
":" <<
ii <<
" Front " 221 if (layerSense_[ly] < 1) {
222 std::vector<double> pgonZ, pgonRin, pgonRout;
223 double rmax = routF * cosAlpha_ - tol1;
236 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
238 if (layerSense_[ly] == 0 || absorbMode_ == 0)
239 pgonRout[isec] = rmax;
241 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
243 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
248 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << solid.name() <<
" polyhedra of " 251 <<
" sections and filled with " << matter.name();
252 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
261 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
267 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << solid.name() <<
" Tubs made of " 271 <<
", 0.0, 360.0 and position " << glog.name() <<
" number " <<
copy <<
":" 272 << layerTypes_[
copy - firstLayer_];
274 positionSensitive(ctxt,
e, glog, (
copy - firstLayer_));
278 dd4hep::Rotation3D
rot;
288 mother.placeVolume(glog,
copy, dd4hep::Transform3D(
rot,
r1));
289 int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
290 copyNumber_[
ii] =
copy + inc;
292 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << glog.name() <<
" number " <<
copy 294 <<
") with " <<
rotName <<
" rotation";
301 if (
std::abs(thickTot - layerThick_[
i]) >= tol2) {
302 if (thickTot > layerThick_[
i]) {
305 <<
": thickness of all its components **** ERROR ****";
308 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
314 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << copies_.size()
315 <<
" different wafer copy numbers";
317 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
321 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalSiliconRotatedModule construction...";
327 static const double sqrt3 =
std::sqrt(3.0);
333 int firstWafer = waferLayerStart_[
layer];
334 int lastWafer = ((
layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[
layer + 1]
335 :
static_cast<int>(waferIndex_.size()));
336 double r = 0.5 * (waferSize_ + waferSepar_);
337 double R = 2.0 *
r / sqrt3;
338 double dy = 0.75 *
R;
339 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
341 int ium(0), ivm(0), kount(0);
342 std::vector<int> ntype(3, 0);
346 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index " 347 << firstWafer <<
":" << (lastWafer - 1);
349 for (
int k = firstWafer;
k < lastWafer; ++
k) {
363 auto cshift = cassette_.getShift(
layer, 1, cassette);
364 double xpos = xyoff.first + cshift.first + nc *
r;
365 double ypos = xyoff.second + cshift.second +
nr *
dy;
369 i =
type * facingTypes_ * orientationTypes_ + place - placeOffset_;
370 wafer = waferFull_[
i];
374 i = (
part - partoffset) * facingTypes_ * orientationTypes_ +
377 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:cassette:place:offsets:ind " << layertype <<
":" 378 <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" << place <<
":" 380 << waferPart_.size();
382 wafer = waferPart_[
i];
388 <<
copy <<
" type:part:orien:ind " <<
type <<
":" <<
part <<
":" << orien <<
":" 389 <<
i <<
" layer:u:v:indx " << (
layer + firstLayer_) <<
":" << u <<
":" <<
v;
395 if (copies_.count(
copy) == 0)
396 copies_.insert(
copy);
399 glog.placeVolume(ns.
volume(wafer),
copy, tran);
402 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalSiliconRotatedModule: " << wafer <<
" number " <<
copy <<
" type " 403 << layertype <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 409 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Maximum # of u " << ium <<
" # of v " << ivm
410 <<
" and " << kount <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2]
411 <<
") for " << glog.name();
Log< level::Info, true > LogVerbatim
static constexpr int32_t WaferCenteredRotated
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
static constexpr int32_t WaferPartLDOffset
static constexpr int32_t WaferCenter
std::vector< double > slopeT_
const dd4hep::Rotation3D & rotation(const std::string &name) const
std::vector< double > thick_
HGCalSiliconRotatedModule()
std::vector< double > layerThick_
static constexpr int32_t WaferTypeOffset[3]
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
std::vector< int > layerSense_
static constexpr int32_t CornerCenterYm
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
std::vector< double > rMinFront_
std::string to_string(const V &value)
std::vector< std::string > materials_
Log< level::Error, false > LogError
std::vector< int > layers_
dd4hep::Material material(const std::string &name) const
int32_t waferOrient(const int32_t property)
std::vector< int > waferIndex_
HGCalSiliconRotatedModule(cms::DDParsingContext &ctxt, xml_h e)
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< int > copyNumber_
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
std::unordered_set< int > copies_
std::vector< int > layerTypes_
int32_t waferCassette(const int32_t property)
#define DECLARE_DDCMS_DETELEMENT(name, func)
static constexpr int32_t WaferFull
static constexpr long s_executed
static int32_t cellPlacementIndex(int32_t iz, int32_t fwdBack, int32_t orient)
std::string_view name() const
std::vector< double > zFrontB_
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
HGCalGeomTools geomTools_
std::vector< std::string > waferFull_
int32_t waferThick(const int32_t property)
std::vector< double > slopeB_
static constexpr int32_t CornerCenterYp
static constexpr int32_t WaferPartHDOffset
static constexpr int32_t WaferCenteredBack
std::vector< int > waferLayerStart_
std::vector< double > zFrontT_
static constexpr int32_t CornerCenteredLambda
int32_t waferPartial(const int32_t property)
static constexpr int32_t CornerCenteredY
int32_t waferV(const int32_t index)
std::vector< std::string > names_
static int32_t packTypeUV(int type, int u, int v)
static constexpr int32_t WaferHDTop
std::vector< int > layerType_
std::vector< int > waferProperty_
Log< level::Warning, false > LogWarning
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, int layer)
std::vector< double > rMaxFront_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
std::vector< double > cassetteShift_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
std::string prepend(const std::string &) const
std::vector< std::string > waferPart_