9 #include <unordered_set> 21 #include "DD4hep/DetFactoryHelper.h" 37 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Creating an instance";
40 static constexpr
double tol1 = 0.01 * dd4hep::mm;
43 waferTypes_ =
args.value<
int>(
"WaferTypes");
44 facingTypes_ =
args.value<
int>(
"FacingTypes");
45 orientationTypes_ =
args.value<
int>(
"OrientationTypes");
46 placeOffset_ =
args.value<
int>(
"PlaceOffset");
47 phiBinsScint_ =
args.value<
int>(
"NPhiBinScint");
48 forFireworks_ =
args.value<
int>(
"ForFireWorks");
50 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer::Number of types of wafers: " << waferTypes_
51 <<
" facings: " << facingTypes_ <<
" Orientations: " << orientationTypes_
52 <<
" PlaceOffset: " << placeOffset_ <<
"; number of cells along phi " << phiBinsScint_
53 <<
" forFireworks_: " << forFireworks_;
55 firstLayer_ =
args.value<
int>(
"FirstLayer");
56 absorbMode_ =
args.value<
int>(
"AbsorberMode");
57 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
59 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer::First Layer " << firstLayer_ <<
" and " 60 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
62 zMinBlock_ =
args.value<
double>(
"zMinBlock");
63 waferSize_ =
args.value<
double>(
"waferSize");
64 waferSepar_ =
args.value<
double>(
"SensorSeparation");
65 sectors_ =
args.value<
int>(
"Sectors");
66 cassettes_ =
args.value<
int>(
"Cassettes");
67 alpha_ = (1._pi) / sectors_;
68 cosAlpha_ =
cos(alpha_);
72 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_
73 <<
" with " << cassettes_ <<
" cassettes";
75 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
76 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
77 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
78 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
79 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
80 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
82 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
85 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
90 waferFull_ =
args.value<std::vector<std::string>>(
"WaferNamesFull");
91 waferPart_ =
args.value<std::vector<std::string>>(
"WaferNamesPartial");
93 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << waferFull_.size() <<
" full and " 94 << waferPart_.size() <<
" partial modules\nDDHGCalMixRotatedLayer:Full Modules:";
95 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
96 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
97 std::ostringstream st1;
99 for (
unsigned int i =
i1;
i <
i2; ++
i)
100 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
103 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Partial Modules:";
104 i1max =
static_cast<unsigned int>(waferPart_.size());
105 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
106 std::ostringstream st1;
108 for (
unsigned int i =
i1;
i <
i2; ++
i)
109 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
114 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
115 names_ =
args.value<std::vector<std::string>>(
"VolumeNames");
116 thick_ =
args.value<std::vector<double>>(
"Thickness");
117 copyNumber_.resize(materials_.size(), 1);
119 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << materials_.size() <<
" types of volumes";
120 for (
unsigned int i = 0;
i < names_.size(); ++
i)
121 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness " 123 <<
" first copy number " << copyNumber_[
i];
125 layers_ =
args.value<std::vector<int>>(
"Layers");
126 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
128 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
129 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
131 <<
" with " << layers_[
i] <<
" layers";
133 layerType_ =
args.value<std::vector<int>>(
"LayerType");
134 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
135 layerOrient_ =
args.value<std::vector<int>>(
"LayerTypes");
136 for (
unsigned int k = 0;
k < layerOrient_.size(); ++
k)
139 for (
unsigned int i = 0;
i < layerOrient_.size(); ++
i)
142 if (firstLayer_ > 0) {
143 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
144 if (layerSense_[
i] > 0) {
145 int ii = layerType_[
i];
146 copyNumber_[
ii] = firstLayer_;
148 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 149 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
158 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
159 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
160 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 163 materialTop_ =
args.value<std::vector<std::string>>(
"TopMaterialNames");
164 namesTop_ =
args.value<std::vector<std::string>>(
"TopVolumeNames");
165 layerThickTop_ =
args.value<std::vector<double>>(
"TopLayerThickness");
166 layerTypeTop_ =
args.value<std::vector<int>>(
"TopLayerType");
167 copyNumberTop_.resize(materialTop_.size(), firstLayer_);
169 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << materialTop_.size()
170 <<
" types of volumes in the top part";
171 for (
unsigned int i = 0;
i < materialTop_.size(); ++
i)
172 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " 174 <<
" first copy number " << copyNumberTop_[
i];
175 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
176 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
177 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
179 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
180 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
181 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
182 cassetteShift_ =
args.value<std::vector<double>>(
"CassetteShift");
184 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in " 185 << waferLayerStart_.size() <<
" layers";
186 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
188 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
196 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << cassetteShift_.size()
197 <<
" elements for cassette shifts";
198 unsigned int j1max = cassetteShift_.size();
199 for (
unsigned int j1 = 0; j1 < j1max; j1 += 6) {
200 std::ostringstream st1;
201 unsigned int j2 =
std::min((j1 + 6), j1max);
202 for (
unsigned int j = j1;
j < j2; ++
j)
203 st1 <<
" [" <<
j <<
"] " << std::setw(9) << cassetteShift_[
j];
207 tileRMin_ =
args.value<std::vector<double>>(
"TileRMin");
208 tileRMax_ =
args.value<std::vector<double>>(
"TileRMax");
209 tileIndex_ =
args.value<std::vector<int>>(
"TileLayerRings");
210 tilePhis_ =
args.value<std::vector<int>>(
"TilePhiRange");
211 tileLayerStart_ =
args.value<std::vector<int>>(
"TileLayerStart");
213 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer:: with " << tileRMin_.size() <<
" rings";
214 for (
unsigned int k = 0;
k < tileRMin_.size(); ++
k)
217 edm::LogVerbatim(
"HGCalGeom") <<
"TileProperties with " << tileIndex_.size() <<
" entries in " 218 << tileLayerStart_.size() <<
" layers";
219 for (
unsigned int k = 0;
k < tileLayerStart_.size(); ++
k)
221 for (
unsigned int k = 0;
k < tileIndex_.size(); ++
k)
229 cassette_.setParameter(cassettes_, cassetteShift_);
234 edm::LogVerbatim(
"HGCalGeom") <<
"==>> Constructing DDHGCalMixRotatedLayer...";
238 double zi(zMinBlock_);
240 for (
unsigned int i = 0;
i < layers_.size();
i++) {
241 double zo = zi + layerThick_[
i];
243 int laymax = laymin + layers_[
i];
246 for (
int ly = laymin; ly < laymax; ++ly) {
247 int ii = layerType_[ly];
248 int copy = copyNumber_[
ii];
249 double hthick = 0.5 * thick_[
ii];
252 thickTot += thick_[
ii];
256 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Layer " << ly <<
":" <<
ii <<
" Front " 265 if (layerSense_[ly] < 1) {
266 std::vector<double> pgonZ, pgonRin, pgonRout;
281 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
283 if (layerSense_[ly] == 0 || absorbMode_ == 0)
284 pgonRout[isec] = rmax;
286 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
289 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
294 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << solid.name() <<
" polyhedra of " << sectors_
296 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
297 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
306 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
312 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << solid.name() <<
" Tubs made of " 316 <<
", 0.0, 360.0 and positioned in: " << glog.name() <<
" number " <<
copy;
318 positionMix(ctxt,
e, glog,
name,
copy, thick_[
ii], matter);
322 mother.placeVolume(glog,
copy, r1);
325 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << glog.name() <<
" number " <<
copy 327 <<
") with no rotation";
333 if (
std::abs(thickTot - layerThick_[
i]) > tol2_) {
334 if (thickTot > layerThick_[
i]) {
337 <<
": thickness of all its components **** ERROR ****";
340 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
346 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << copies_.size() <<
" different wafer copy numbers";
348 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
352 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalMixRotatedLayer construction...";
366 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
367 int ii = layerTypeTop_[ly];
368 copyNumberTop_[
ii] = copyM;
370 double hthick = 0.5 * thick;
371 double dphi = (2._pi) / phiBinsScint_;
372 double thickTot(0), zpos(-hthick);
373 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
374 int ii = layerTypeTop_[ly];
375 int copy = copyNumberTop_[
ii];
376 int layer =
copy - firstLayer_;
377 double hthickl = 0.5 * layerThickTop_[
ii];
378 thickTot += layerThickTop_[
ii];
382 int firstTile = tileLayerStart_[layer];
383 int lastTile = ((layer + 1 <
static_cast<int>(tileLayerStart_.size())) ? tileLayerStart_[layer + 1]
384 :
static_cast<int>(tileIndex_.size()));
387 <<
" Tiles " << firstTile <<
":" << lastTile;
389 for (
int ti = firstTile; ti < lastTile; ++ti) {
395 double phi1 = dphi * (fimin - 1);
396 double phi2 = (forFireworks_ == 1) ? (dphi * (fimax - fimin + 1)) : (dphi * fimax);
397 auto cshift = cassette_.getShift(layer + 1, 1, cassette);
399 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Layer " <<
copy <<
":" << (layer + 1) <<
" iR " 403 <<
cms::convert2mm((2.0 * hthickl)) <<
" phi " << fimin <<
":" << fimax <<
":" 405 << cassette <<
" Shift " << cshift.first <<
":" << cshift.second;
409 dd4hep::Solid solid = dd4hep::Tube(r1,
r2, hthickl, phi1, phi2);
414 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: " << glog1.name() <<
" Tubs made of " 420 glog.placeVolume(glog1,
copy, tran);
422 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Position " << glog1.name() <<
" number " <<
copy 423 <<
" in " << glog.name() <<
" at (" <<
cms::convert2mm(cshift.first) <<
", " 425 <<
") with no rotation";
428 ++copyNumberTop_[
ii];
431 if (
std::abs(thickTot - thick) > tol2_) {
432 if (thickTot > thick) {
435 <<
": thickness of all its components in the top part **** ERROR ****";
439 <<
" of the components in top part";
444 int layer = (copyM - firstLayer_);
445 static const double sqrt3 =
std::sqrt(3.0);
446 int layercenter = layerOrient_[layer];
448 int firstWafer = waferLayerStart_[layer];
449 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
450 :
static_cast<int>(waferIndex_.size()));
451 double delx = 0.5 * (waferSize_ + waferSepar_);
452 double dely = 2.0 * delx / sqrt3;
453 double dy = 0.75 * dely;
454 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
456 int ium(0), ivm(0), kount(0);
457 std::vector<int> ntype(3, 0);
461 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index " 462 << firstWafer <<
":" << (lastWafer - 1);
464 for (
int k = firstWafer;
k < lastWafer; ++
k) {
480 <<
"DDHGCalMixRotatedLayer::index:Property:layertype:type:part:orien:cassette:place:offsets:ind " <<
k <<
":" 481 << waferProperty_[
k] <<
":" << layertype <<
":" <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette
484 auto cshift = cassette_.getShift(layer + 1, -1, cassette);
485 double xpos = xyoff.first - cshift.first + nc * delx;
486 double ypos = xyoff.second + cshift.second +
nr *
dy;
488 double xorig = xyoff.first + nc * delx;
489 double yorig = xyoff.second +
nr *
dy;
490 double angle = std::atan2(yorig, xorig);
491 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer::Wafer: layer " << layer + 1 <<
" cassette " << cassette
492 <<
" Shift " << cshift.first <<
":" << cshift.second <<
" Original " << xorig <<
":" 498 i =
type * facingTypes_ * orientationTypes_ + place - placeOffset_;
500 edm::LogVerbatim(
"HGCalGeom") <<
" FullWafer type:place:ind " <<
type <<
":" << place <<
":" <<
i <<
":" 501 << waferFull_.size();
503 wafer = waferFull_[
i];
507 i = (
part - partoffset) * facingTypes_ * orientationTypes_ +
510 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:cassette:place:offsets:ind " << layertype <<
":" 511 <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" << place <<
":" 513 << waferPart_.size();
515 wafer = waferPart_[
i];
520 <<
" Wafer " << wafer <<
" number " <<
copy <<
" type :part:orien:ind " <<
type 521 <<
":" <<
part <<
":" << orien <<
":" <<
i <<
" layer:u:v " << (layer + firstLayer_)
522 <<
":" << u <<
":" <<
v;
528 if (copies_.count(
copy) == 0)
529 copies_.insert(
copy);
532 glog.placeVolume(ns.
volume(wafer),
copy, tran);
535 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalMixRotatedLayer: " << wafer <<
" number " <<
copy <<
" type " 536 << layertype <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 542 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalMixRotatedLayer: Maximum # of u " << ium <<
" # of v " << ivm <<
" and " 543 << kount <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2] <<
") for " 552 static constexpr
double tol2_ = 0.00001 * dd4hep::mm;
std::vector< int > tileIndex_
Log< level::Info, true > LogVerbatim
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
std::vector< int > layerTypeTop_
static constexpr int32_t WaferPartLDOffset
std::vector< double > thick_
static constexpr int32_t WaferTypeOffset[3]
std::vector< int > waferIndex_
int32_t waferU(const int32_t index)
int32_t waferLayer(const int32_t index)
std::vector< int > layerSense_
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
std::vector< int > tileLayerStart_
HGCalGeomTools geomTools_
std::string to_string(const V &value)
std::vector< int > copyNumber_
std::vector< int > copyNumberTop_
std::vector< double > cassetteShift_
Log< level::Error, false > LogError
std::vector< double > zFrontB_
dd4hep::Material material(const std::string &name) const
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
int32_t waferOrient(const int32_t property)
std::vector< int > waferProperty_
std::vector< double > layerThickTop_
std::vector< std::string > materialTop_
std::vector< double > rMaxFront_
int32_t waferCassette(const int32_t property)
std::vector< std::string > namesTop_
#define DECLARE_DDCMS_DETELEMENT(name, func)
static constexpr int32_t WaferFull
static constexpr long s_executed
std::string_view name() const
Cos< T >::type cos(const T &t)
std::vector< int > tilePhis_
std::vector< double > tileRMax_
Abs< T >::type abs(const T &t)
std::vector< int > waferLayerStart_
std::vector< double > layerThick_
int32_t waferThick(const int32_t property)
std::vector< double > slopeT_
std::unordered_set< int > copies_
std::tuple< int32_t, int32_t, int32_t > tileUnpack(int32_t index)
static constexpr int32_t WaferPartHDOffset
HGCalMixRotatedLayer(cms::DDParsingContext &ctxt, xml_h e)
std::vector< int > layers_
std::vector< double > zFrontT_
std::vector< int > layerOrient_
std::vector< std::string > waferPart_
void positionMix(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, const std::string &nameM, int copyM, double thick, const dd4hep::Material &matter)
std::vector< int > layerType_
std::vector< double > tileRMin_
int32_t waferPartial(const int32_t property)
std::vector< double > slopeB_
int32_t waferV(const int32_t index)
std::vector< std::string > waferFull_
static int32_t packTypeUV(int type, int u, int v)
static constexpr int32_t WaferHDTop
Log< level::Warning, false > LogWarning
static int32_t layerType(int type)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
std::vector< std::string > names_
std::vector< double > rMinFront_
static int32_t layerFrontBack(int32_t layerOrient)
dd4hep::Volume volume(const std::string &name, bool exc=true) const
std::vector< std::string > materials_
dd4hep::Solid addSolidNS(const std::string &name, dd4hep::Solid solid) const
std::string prepend(const std::string &) const
T angle(T x1, T y1, T z1, T x2, T y2, T z2)