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_ <<
" with " << 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 layerOrient_ =
args.value<std::vector<int>>(
"LayerTypes");
119 for (
unsigned int k = 0;
k < layerOrient_.size(); ++
k)
122 for (
unsigned int i = 0;
i < layerOrient_.size(); ++
i)
125 if (firstLayer_ > 0) {
126 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
127 if (layerSense_[
i] > 0) {
128 int ii = layerType_[
i];
129 copyNumber_[
ii] = (layerSense_[
i] == 1) ? firstLayer_ : (firstLayer_ + 1);
131 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 132 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
140 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
141 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
142 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 145 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
146 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
147 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
148 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
149 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
150 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
152 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
155 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
159 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
160 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
161 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
162 cassetteShift_ =
args.value<std::vector<double>>(
"CassetteShift");
164 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in " 165 << waferLayerStart_.size() <<
" layers";
166 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
168 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
176 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << cassetteShift_.size()
177 <<
" elements for cassette shifts";
178 unsigned int j1max = cassetteShift_.size();
179 for (
unsigned int j1 = 0; j1 < j1max; j1 += 6) {
180 std::ostringstream st1;
181 unsigned int j2 =
std::min((j1 + 6), j1max);
182 for (
unsigned int j = j1;
j < j2; ++
j)
183 st1 <<
" [" <<
j <<
"] " << std::setw(9) << cassetteShift_[
j];
189 cassette_.setParameter(cassettes_, cassetteShift_);
192 edm::LogVerbatim(
"HGCalGeom") <<
"==>> Constructing DDHGCalSiliconRotatedModule...";
196 double zi(zMinBlock_);
198 for (
unsigned int i = 0;
i < layers_.size(); ++
i) {
199 double zo = zi + layerThick_[
i];
201 int laymax = laymin + layers_[
i];
204 for (
int ly = laymin; ly < laymax; ++ly) {
205 int ii = layerType_[ly];
206 int copy = copyNumber_[
ii];
207 double hthick = 0.5 * thick_[
ii];
210 thickTot += thick_[
ii];
214 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Layer " << ly <<
":" <<
ii <<
" Front " 223 if (layerSense_[ly] < 1) {
224 std::vector<double> pgonZ, pgonRin, pgonRout;
225 double rmax = routF * cosAlpha_ - tol1;
238 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
240 if (layerSense_[ly] == 0 || absorbMode_ == 0)
241 pgonRout[isec] = rmax;
243 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1;
245 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
250 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << solid.name() <<
" polyhedra of " 253 <<
" sections and filled with " << matter.name();
254 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
263 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
269 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << solid.name() <<
" Tubs made of " 273 <<
", 0.0, 360.0 and position " << glog.name() <<
" number " <<
copy <<
":" 274 << layerOrient_[
copy - firstLayer_];
276 positionSensitive(ctxt,
e, glog, (
copy - firstLayer_));
280 dd4hep::Rotation3D
rot;
290 mother.placeVolume(glog,
copy, dd4hep::Transform3D(
rot, r1));
291 int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
292 copyNumber_[
ii] =
copy + inc;
294 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << glog.name() <<
" number " <<
copy 296 <<
") with " <<
rotName <<
" rotation";
303 if (
std::abs(thickTot - layerThick_[
i]) >= tol2) {
304 if (thickTot > layerThick_[
i]) {
307 <<
": thickness of all its components **** ERROR ****";
310 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
316 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: " << copies_.size()
317 <<
" different wafer copy numbers";
319 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
323 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalSiliconRotatedModule construction...";
329 static const double sqrt3 =
std::sqrt(3.0);
330 int layercenter = layerOrient_[layer];
332 int firstWafer = waferLayerStart_[layer];
333 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
334 :
static_cast<int>(waferIndex_.size()));
335 double delx = 0.5 * (waferSize_ + waferSepar_);
336 double dely = 2.0 * delx / sqrt3;
337 double dy = 0.75 * dely;
338 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
340 int ium(0), ivm(0), kount(0);
341 std::vector<int> ntype(3, 0);
345 <<
" WaferSize " <<
cms::convert2mm((waferSize_ + waferSepar_)) <<
" index " 346 << firstWafer <<
":" << (lastWafer - 1);
348 for (
int k = firstWafer;
k < lastWafer; ++
k) {
362 auto cshift = cassette_.getShift(layer + 1, 1, cassette);
363 double xpos = xyoff.first + cshift.first + nc * delx;
364 double ypos = xyoff.second + cshift.second +
nr *
dy;
368 i =
type * facingTypes_ * orientationTypes_ + place - placeOffset_;
369 wafer = waferFull_[
i];
373 i = (
part - partoffset) * facingTypes_ * orientationTypes_ +
376 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:cassette:place:offsets:ind " << layertype <<
":" 377 <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" << place <<
":" 379 << waferPart_.size();
381 wafer = waferPart_[
i];
387 <<
copy <<
" type:part:orien:ind " <<
type <<
":" <<
part <<
":" << orien <<
":" 388 <<
i <<
" layer:u:v:indx " << (layer + firstLayer_) <<
":" << u <<
":" <<
v;
394 if (copies_.count(
copy) == 0)
395 copies_.insert(
copy);
398 glog.placeVolume(ns.
volume(wafer),
copy, tran);
401 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalSiliconRotatedModule: " << wafer <<
" number " <<
copy <<
" type " 402 << layertype <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 408 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedModule: Maximum # of u " << ium <<
" # of v " << ivm
409 <<
" and " << kount <<
" wafers (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2]
410 <<
") for " << glog.name();
Log< level::Info, true > LogVerbatim
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
static constexpr int32_t WaferPartLDOffset
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_
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
std::vector< double > rMinFront_
std::vector< int > layerOrient_
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)
std::vector< int > copyNumber_
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
std::unordered_set< int > copies_
int32_t waferCassette(const int32_t property)
#define DECLARE_DDCMS_DETELEMENT(name, func)
static constexpr int32_t WaferFull
static constexpr long s_executed
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 WaferPartHDOffset
static constexpr int32_t WaferCenterR
std::vector< int > waferLayerStart_
std::vector< double > zFrontT_
int32_t waferPartial(const int32_t property)
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
static int32_t layerType(int type)
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
static constexpr int32_t WaferCenterB
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_