10 #include <unordered_set> 21 #include "DD4hep/DetFactoryHelper.h" 32 throw cms::Exception(
"HGCalGeom") <<
"Wrong initialization to HGCalSiliconRotatedCassette";
39 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: 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 passiveTypes_ =
args.value<
int>(
"PassiveTypes");
47 facingTypes_ =
args.value<
int>(
"FacingTypes");
48 orientationTypes_ =
args.value<
int>(
"OrientationTypes");
49 partialTypes_ =
args.value<
int>(
"PartialTypes");
50 placeOffset_ =
args.value<
int>(
"PlaceOffset");
52 edm::LogVerbatim(
"HGCalGeom") <<
"Number of types of wafers: " << waferTypes_ <<
" passives: " << passiveTypes_
53 <<
" facings: " << facingTypes_ <<
" Orientations: " << orientationTypes_
54 <<
" PartialTypes: " << partialTypes_ <<
" PlaceOffset: " << placeOffset_;
56 firstLayer_ =
args.value<
int>(
"FirstLayer");
57 absorbMode_ =
args.value<
int>(
"AbsorberMode");
58 sensitiveMode_ =
args.value<
int>(
"SensitiveMode");
60 edm::LogVerbatim(
"HGCalGeom") <<
"First Layer " << firstLayer_ <<
" and Absober:Sensitive mode " << absorbMode_
61 <<
":" << sensitiveMode_;
63 zMinBlock_ =
args.value<
double>(
"zMinBlock");
64 waferSize_ =
args.value<
double>(
"waferSize");
65 waferSepar_ =
args.value<
double>(
"SensorSeparation");
66 sectors_ =
args.value<
int>(
"Sectors");
67 cassettes_ =
args.value<
int>(
"Cassettes");
68 alpha_ = (1._pi) / sectors_;
69 cosAlpha_ =
cos(alpha_);
74 <<
" sectors " << sectors_ <<
":" <<
convertRadToDeg(alpha_) <<
":" << cosAlpha_
75 <<
" rotation matrix " << rotstr_ <<
" with " << cassettes_ <<
" cassettes";
77 waferFull_ =
args.value<std::vector<std::string>>(
"WaferNamesFull");
78 waferPart_ =
args.value<std::vector<std::string>>(
"WaferNamesPartial");
80 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << waferFull_.size() <<
" full and " 81 << waferPart_.size() <<
" partial modules";
82 unsigned int i1max =
static_cast<unsigned int>(waferFull_.size());
83 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
84 std::ostringstream st1;
86 for (
unsigned int i =
i1;
i <
i2; ++
i)
87 st1 <<
" [" <<
i <<
"] " << waferFull_[
i];
90 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: Partial Modules:";
91 i1max =
static_cast<unsigned int>(waferPart_.size());
92 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
93 std::ostringstream st1;
95 for (
unsigned int i =
i1;
i <
i2; ++
i)
96 st1 <<
" [" <<
i <<
"] " << waferPart_[
i];
100 passiveFull_ =
args.value<std::vector<std::string>>(
"PassiveNamesFull");
101 passivePart_ =
args.value<std::vector<std::string>>(
"PassiveNamesPartial");
103 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << passiveFull_.size() <<
" full and " 104 << passivePart_.size() <<
" partial passive modules";
105 i1max =
static_cast<unsigned int>(passiveFull_.size());
106 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
107 std::ostringstream st1;
109 for (
unsigned int i =
i1;
i <
i2; ++
i)
110 st1 <<
" [" <<
i <<
"] " << passiveFull_[
i];
113 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: Partial Modules:";
114 i1max =
static_cast<unsigned int>(passivePart_.size());
115 for (
unsigned int i1 = 0;
i1 < i1max;
i1 += 2) {
116 std::ostringstream st1;
118 for (
unsigned int i =
i1;
i <
i2; ++
i)
119 st1 <<
" [" <<
i <<
"] " << passivePart_[
i];
123 materials_ =
args.value<std::vector<std::string>>(
"MaterialNames");
124 names_ =
args.value<std::vector<std::string>>(
"VolumeNames");
125 thick_ =
args.value<std::vector<double>>(
"Thickness");
126 copyNumber_.resize(materials_.size(), 1);
128 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << materials_.size() <<
" types of volumes";
129 for (
unsigned int i = 0;
i < names_.size(); ++
i)
130 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness " 132 <<
" first copy number " << copyNumber_[
i];
134 layers_ =
args.value<std::vector<int>>(
"Layers");
135 layerThick_ =
args.value<std::vector<double>>(
"LayerThick");
137 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
138 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
140 <<
" with " << layers_[
i] <<
" layers";
142 layerType_ =
args.value<std::vector<int>>(
"LayerType");
143 layerSense_ =
args.value<std::vector<int>>(
"LayerSense");
144 layerOrient_ =
args.value<std::vector<int>>(
"LayerTypes");
145 for (
unsigned int k = 0;
k < layerOrient_.size(); ++
k)
148 for (
unsigned int i = 0;
i < layerOrient_.size(); ++
i)
151 if (firstLayer_ > 0) {
152 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
153 if (layerSense_[
i] > 0) {
154 int ii = layerType_[
i];
155 copyNumber_[
ii] = (layerSense_[
i] == 1) ? firstLayer_ : (firstLayer_ + 1);
157 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" <<
ii <<
" with " 158 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
166 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
167 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
168 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class " 171 slopeB_ =
args.value<std::vector<double>>(
"SlopeBottom");
172 zFrontB_ =
args.value<std::vector<double>>(
"ZFrontBottom");
173 rMinFront_ =
args.value<std::vector<double>>(
"RMinFront");
174 slopeT_ =
args.value<std::vector<double>>(
"SlopeTop");
175 zFrontT_ =
args.value<std::vector<double>>(
"ZFrontTop");
176 rMaxFront_ =
args.value<std::vector<double>>(
"RMaxFront");
178 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
181 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
185 waferIndex_ =
args.value<std::vector<int>>(
"WaferIndex");
186 waferProperty_ =
args.value<std::vector<int>>(
"WaferProperties");
187 waferLayerStart_ =
args.value<std::vector<int>>(
"WaferLayerStart");
188 cassetteShift_ =
args.value<std::vector<double>>(
"CassetteShift");
190 edm::LogVerbatim(
"HGCalGeom") <<
"waferProperties with " << waferIndex_.size() <<
" entries in " 191 << waferLayerStart_.size() <<
" layers";
192 for (
unsigned int k = 0;
k < waferLayerStart_.size(); ++
k)
194 for (
unsigned int k = 0;
k < waferIndex_.size(); ++
k)
202 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << cassetteShift_.size()
203 <<
" elements for cassette shifts";
204 unsigned int j1max = cassetteShift_.size();
205 for (
unsigned int j1 = 0; j1 < j1max; j1 += 6) {
206 std::ostringstream st1;
207 unsigned int j2 =
std::min((j1 + 6), j1max);
208 for (
unsigned int j = j1;
j < j2; ++
j)
213 cassette_.setParameter(cassettes_, cassetteShift_);
216 edm::LogVerbatim(
"HGCalGeom") <<
"==>> Constructing DDHGCalSiliconRotatedCassette...";
220 double zi(zMinBlock_);
222 for (
unsigned int i = 0;
i < layers_.size();
i++) {
223 double zo = zi + layerThick_[
i];
225 int laymax = laymin + layers_[
i];
228 for (
int ly = laymin; ly < laymax; ++ly) {
229 int ii = layerType_[ly];
230 int copy = copyNumber_[
ii];
231 double hthick = 0.5 * thick_[
ii];
234 thickTot += thick_[
ii];
238 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: Layer " << ly <<
":" <<
ii <<
" Front " 245 if (layerSense_[ly] == 0) {
246 std::vector<double> pgonZ, pgonRin, pgonRout;
247 double rmax = routF * cosAlpha_ - tol1;
260 for (
unsigned int isec = 0;
isec < pgonZ.size(); ++
isec) {
262 if (layerSense_[ly] == 0 || absorbMode_ == 0)
263 pgonRout[
isec] = rmax;
265 pgonRout[
isec] = pgonRout[
isec] * cosAlpha_ - tol1;
267 dd4hep::Solid solid =
dd4hep::Polyhedra(sectors_, -alpha_, 2._pi, pgonZ, pgonRin, pgonRout);
272 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << solid.name() <<
" polyhedra of " 275 <<
" sections and filled with " << matter.name();
276 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
281 int mode = (layerSense_[ly] > 0) ? sensitiveMode_ : absorbMode_;
284 dd4hep::Solid solid = dd4hep::Tube(rins, routs, hthick, 0.0, 2._pi);
289 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << solid.name() <<
" Tubs made of " 293 <<
", 0.0, 360.0 and position " << glog.name() <<
" number " <<
copy <<
":" 296 if (layerSense_[ly] > 0)
297 positionSensitive(ctxt,
e, glog, (
copy - firstLayer_));
299 positionPassive(ctxt,
e, glog, (
copy - firstLayer_), -layerSense_[ly]);
302 dd4hep::Rotation3D
rot;
312 mother.placeVolume(glog,
copy, dd4hep::Transform3D(
rot, r1));
313 int inc = ((layerSense_[ly] > 0) && (facingTypes_ > 1)) ? 2 : 1;
314 copyNumber_[
ii] =
copy + inc;
316 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << glog.name() <<
" number " <<
copy 318 <<
") with " <<
rotName <<
" rotation";
325 if (
std::abs(thickTot - layerThick_[
i]) >= tol2) {
326 if (thickTot > layerThick_[
i]) {
329 <<
": thickness of all its components **** ERROR ****";
332 <<
" does not match with " <<
cms::convert2mm(thickTot) <<
" of the components";
338 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: " << copies_.size()
339 <<
" different wafer copy numbers";
341 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
345 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalSiliconRotatedCassette construction...";
351 static const double sqrt3 =
std::sqrt(3.0);
352 int layercenter = layerOrient_[layer];
354 int firstWafer = waferLayerStart_[layer];
355 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
356 :
static_cast<int>(waferIndex_.size()));
357 double delx = 0.5 * (waferSize_ + waferSepar_);
358 double dely = 2.0 * delx / sqrt3;
359 double dy = 0.75 * dely;
360 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
362 int ium(0), ivm(0), kount(0);
363 std::vector<int> ntype(3, 0);
367 <<
" WaferSize " <<
cms::convert2mm(waferSize_ + waferSepar_) <<
" index " 368 << firstWafer <<
":" << (lastWafer - 1) <<
" Layer Center " << layercenter <<
":" 371 for (
int k = firstWafer;
k < lastWafer; ++
k) {
385 auto cshift = cassette_.getShift(layer + 1, -1, cassette);
386 double xpos = xyoff.first - cshift.first + nc * delx;
387 double ypos = xyoff.second + cshift.second +
nr *
dy;
389 double xorig = xyoff.first + nc * delx;
390 double yorig = xyoff.second +
nr *
dy;
391 double angle = std::atan2(yorig, xorig);
392 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette::Wafer: layer " << layer + 1 <<
" cassette " 397 <<
" type|part|orient|place " <<
type <<
":" <<
part <<
":" << orien <<
":" 403 i =
type * facingTypes_ * orientationTypes_ + place - placeOffset_;
404 wafer = waferFull_[
i];
406 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:cassette:place:offsets:ind " << layertype <<
":" 407 <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" << place <<
":" 408 << placeOffset_ <<
":" << facingTypes_ <<
":" << orientationTypes_ <<
" wafer " 409 <<
i <<
":" << wafer;
414 i = (
part - partoffset) * facingTypes_ * orientationTypes_ +
417 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:type:part:orien:cassette:place:offsets:ind " << layertype <<
":" 418 <<
type <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" << place <<
":" 420 << waferPart_.size();
422 wafer = waferPart_[
i];
428 <<
copy <<
" type:part:orien:place:ind " <<
type <<
":" <<
part <<
":" << orien
429 <<
":" << place <<
":" <<
i <<
" layer:u:v:indx " << (layer + firstLayer_) <<
":" 437 if (copies_.count(
copy) == 0)
438 copies_.insert(
copy);
441 glog.placeVolume(ns.
volume(wafer),
copy, tran);
444 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalSiliconRotatedCassette: " << wafer <<
" number " <<
copy <<
" type " 445 << layertype <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 450 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: Maximum # of u " << ium <<
" # of v " << ivm
451 <<
" and " << kount <<
" passives (" << ntype[0] <<
":" << ntype[1] <<
":" << ntype[2]
452 <<
") for " << glog.name();
458 static const double sqrt3 =
std::sqrt(3.0);
459 int layercenter = layerOrient_[layer];
461 int firstWafer = waferLayerStart_[layer];
462 int lastWafer = ((layer + 1 <
static_cast<int>(waferLayerStart_.size())) ? waferLayerStart_[layer + 1]
463 :
static_cast<int>(waferIndex_.size()));
464 double delx = 0.5 * (waferSize_ + waferSepar_);
465 double dely = 2.0 * delx / sqrt3;
466 double dy = 0.75 * dely;
467 const auto& xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
469 int ium(0), ivm(0), kount(0);
473 <<
" WaferSize " <<
cms::convert2mm(waferSize_ + waferSepar_) <<
" index " 474 << firstWafer <<
":" << (lastWafer - 1) <<
" Layer Center " << layercenter <<
":" 477 for (
int k = firstWafer;
k < lastWafer; ++
k) {
490 auto cshift = cassette_.getShift(layer + 1, -1, cassette);
491 double xpos = xyoff.first - cshift.first + nc * delx;
492 double ypos = xyoff.second + cshift.second +
nr *
dy;
494 double xorig = xyoff.first + nc * delx;
495 double yorig = xyoff.second +
nr *
dy;
496 double angle = std::atan2(yorig, xorig);
498 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette::Passive: layer " << layer + 1 <<
" cassette " 503 <<
" type|part|orient" <<
type <<
":" <<
part <<
":" << orien;
509 passive = passiveFull_[
i];
511 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:abstype:part:orien:cassette:offsets:ind " << layertype <<
":" 512 << absType <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" 513 <<
":" << partialTypes_ <<
":" << orientationTypes_ <<
" passive " <<
i <<
":" 520 i = (
part - partoffset) * facingTypes_ * orientationTypes_ +
521 (absType - 1) * facingTypes_ * orientationTypes_ * partialTypes_ + place - placeOffset_;
523 edm::LogVerbatim(
"HGCalGeom") <<
" layertype:abstype:part:orien:cassette:3Types:offset:ind " << layertype <<
":" 524 << absType <<
":" <<
part <<
":" << orien <<
":" << cassette <<
":" 525 << partialTypes_ <<
":" << facingTypes_ <<
":" << orientationTypes_ <<
":" 526 << partoffset <<
":" <<
i <<
":" << passivePart_.size();
528 passive = passivePart_[
i];
534 <<
" number " <<
copy <<
" type:part:orien:place:ind " <<
type <<
":" <<
part <<
":" 535 << orien <<
":" << place <<
":" <<
i <<
" layer:u:v:indx " << (layer + firstLayer_)
545 glog.placeVolume(ns.
volume(passive),
copy, tran);
547 edm::LogVerbatim(
"HGCalGeom") <<
" DDHGCalSiliconRotatedCassette: " << passive <<
" number " <<
copy <<
" type " 548 << layertype <<
":" <<
type <<
" positioned in " << glog.name() <<
" at (" 553 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalSiliconRotatedCassette: Maximum # of u " << ium <<
" # of v " << ivm
554 <<
" and " << kount <<
" passives for " << glog.name();
std::vector< double > slopeB_
Log< level::Info, true > LogVerbatim
static int32_t cellPlacementIndex(int32_t iz, int32_t frontBack, int32_t orient)
static constexpr int32_t WaferPartLDOffset
HGCalGeomTools geomTools_
const dd4hep::Rotation3D & rotation(const std::string &name) const
std::vector< int > waferProperty_
static constexpr int32_t WaferTypeOffset[3]
std::vector< std::string > waferFull_
int32_t waferU(const int32_t index)
std::vector< double > thick_
int32_t waferLayer(const int32_t index)
std::vector< int > layerOrient_
constexpr NumType convertRadToDeg(NumType radians)
constexpr NumType convert2mm(NumType length)
std::vector< int > layerType_
std::unordered_set< int > copies_
std::vector< int > waferIndex_
std::vector< int > layerSense_
void positionPassive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, int layer, int absType)
Log< level::Error, false > LogError
std::vector< double > zFrontT_
dd4hep::Material material(const std::string &name) const
int32_t waferOrient(const int32_t property)
HGCalSiliconRotatedCassette(cms::DDParsingContext &ctxt, xml_h e)
static std::string to_string(const XMLCh *ch)
std::vector< std::string > waferPart_
static const std::string & rotName(const T &rot, const cms::DDParsingContext &context)
int32_t waferCassette(const int32_t property)
#define DECLARE_DDCMS_DETELEMENT(name, func)
static constexpr int32_t WaferFull
std::vector< int > waferLayerStart_
static constexpr long s_executed
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Cos< T >::type cos(const T &t)
Abs< T >::type abs(const T &t)
std::vector< std::string > passivePart_
std::vector< double > cassetteShift_
int32_t waferThick(const int32_t property)
HGCalSiliconRotatedCassette()
std::vector< double > slopeT_
std::vector< double > zFrontB_
static constexpr int32_t WaferPartHDOffset
static constexpr int32_t WaferCenterR
std::vector< double > rMaxFront_
std::vector< std::string > names_
std::vector< double > rMinFront_
std::vector< int > layers_
std::vector< std::string > passiveFull_
int32_t waferPartial(const int32_t property)
std::vector< int > copyNumber_
int32_t waferV(const int32_t index)
void positionSensitive(cms::DDParsingContext &ctxt, xml_h e, const dd4hep::Volume &glog, int layer)
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)
std::vector< std::string > materials_
dd4hep::Volume addVolumeNS(dd4hep::Volume vol) const
static constexpr int32_t WaferCenterB
std::vector< double > layerThick_
dd4hep::Volume volume(const std::string &name, bool exc=true) const
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)