26 #include <unordered_set>
30 using namespace angle_units::operators;
69 static constexpr
double tol1_ = 0.01;
70 static constexpr
double tol2_ = 0.00001;
132 wafers_ = vsArgs[
"WaferNames"];
134 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << wafers_.size() <<
" wafers";
135 for (
unsigned int i = 0;
i < wafers_.size(); ++
i)
138 materials_ = vsArgs[
"MaterialNames"];
139 names_ = vsArgs[
"VolumeNames"];
140 thick_ = vArgs[
"Thickness"];
141 copyNumber_.resize(materials_.size(), 1);
143 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << materials_.size() <<
" types of volumes";
144 for (
unsigned int i = 0;
i < names_.size(); ++
i)
145 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << names_[
i] <<
" of thickness " << thick_[
i]
146 <<
" filled with " << materials_[
i] <<
" first copy number " << copyNumber_[
i];
149 layerThick_ = vArgs[
"LayerThick"];
150 rMixLayer_ = vArgs[
"LayerRmix"];
152 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layers_.size() <<
" blocks";
153 for (
unsigned int i = 0;
i < layers_.size(); ++
i)
154 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] of thickness " << layerThick_[
i] <<
" Rmid " << rMixLayer_[
i]
155 <<
" with " << layers_[
i] <<
" layers";
158 layerSense_ =
dbl_to_int(vArgs[
"LayerSense"]);
159 firstLayer_ = (int)(nArgs[
"FirstLayer"]);
160 absorbMode_ = (int)(nArgs[
"AbsorberMode"]);
161 sensitiveMode_ = (int)(nArgs[
"SensitiveMode"]);
164 <<
"Absober:Sensitive mode " << absorbMode_ <<
":" << sensitiveMode_;
166 layerCenter_ =
dbl_to_int(vArgs[
"LayerCenter"]);
168 for (
unsigned int i = 0;
i < layerCenter_.size(); ++
i)
171 if (firstLayer_ > 0) {
172 for (
unsigned int i = 0;
i < layerType_.size(); ++
i) {
173 if (layerSense_[
i] > 0) {
174 int ii = layerType_[
i];
175 copyNumber_[
ii] = firstLayer_;
177 edm::LogVerbatim(
"HGCalGeom") <<
"First copy number for layer type " <<
i <<
":" << ii <<
" with "
178 << materials_[
ii] <<
" changed to " << copyNumber_[
ii];
185 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerType_.size() <<
" layers";
186 for (
unsigned int i = 0;
i < layerType_.size(); ++
i)
187 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerType_[
i] <<
" sensitive class "
190 materialsTop_ = vsArgs[
"TopMaterialNames"];
191 namesTop_ = vsArgs[
"TopVolumeNames"];
192 layerThickTop_ = vArgs[
"TopLayerThickness"];
193 layerTypeTop_ =
dbl_to_int(vArgs[
"TopLayerType"]);
194 copyNumberTop_.resize(materialsTop_.size(), 1);
196 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << materialsTop_.size() <<
" types of volumes in the top part";
197 for (
unsigned int i = 0;
i < materialsTop_.size(); ++
i)
198 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesTop_[
i] <<
" of thickness " << layerThickTop_[
i]
199 <<
" filled with " << materialsTop_[
i] <<
" first copy number " << copyNumberTop_[
i];
200 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeTop_.size() <<
" layers in the top part";
201 for (
unsigned int i = 0;
i < layerTypeTop_.size(); ++
i)
202 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeTop_[
i];
204 materialsBot_ = vsArgs[
"BottomMaterialNames"];
205 namesBot_ = vsArgs[
"BottomVolumeNames"];
206 layerTypeBot_ =
dbl_to_int(vArgs[
"BottomLayerType"]);
207 layerSenseBot_ =
dbl_to_int(vArgs[
"BottomLayerSense"]);
208 layerThickBot_ = vArgs[
"BottomLayerThickness"];
209 copyNumberBot_.resize(materialsBot_.size(), 1);
211 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << materialsBot_.size() <<
" types of volumes in the bottom part";
212 for (
unsigned int i = 0;
i < materialsBot_.size(); ++
i)
213 edm::LogVerbatim(
"HGCalGeom") <<
"Volume [" <<
i <<
"] " << namesBot_[
i] <<
" of thickness " << layerThickBot_[
i]
214 <<
" filled with " << materialsBot_[
i] <<
" first copy number " << copyNumberBot_[
i];
215 edm::LogVerbatim(
"HGCalGeom") <<
"There are " << layerTypeBot_.size() <<
" layers in the bottom part";
216 for (
unsigned int i = 0;
i < layerTypeBot_.size(); ++
i)
217 edm::LogVerbatim(
"HGCalGeom") <<
"Layer [" <<
i <<
"] with material type " << layerTypeBot_[
i]
218 <<
" sensitive class " << layerSenseBot_[
i];
220 zMinBlock_ = nArgs[
"zMinBlock"];
221 rad100to200_ = vArgs[
"rad100to200"];
222 rad200to300_ = vArgs[
"rad200to300"];
223 zMinRadPar_ = nArgs[
"zMinForRadPar"];
224 choiceType_ = (int)(nArgs[
"choiceType"]);
225 nCutRadPar_ = (int)(nArgs[
"nCornerCut"]);
226 fracAreaMin_ = nArgs[
"fracAreaMin"];
227 waferSize_ = nArgs[
"waferSize"];
228 waferSepar_ = nArgs[
"SensorSeparation"];
229 sectors_ = (int)(nArgs[
"Sectors"]);
230 alpha_ = (1._pi) / sectors_;
231 cosAlpha_ =
cos(alpha_);
233 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: zStart " << zMinBlock_ <<
" radius for wafer type separation uses "
234 << rad100to200_.size() <<
" parameters; zmin " << zMinRadPar_ <<
" cutoff "
235 << choiceType_ <<
":" << nCutRadPar_ <<
":" << fracAreaMin_ <<
" wafer width "
236 << waferSize_ <<
" separations " << waferSepar_ <<
" sectors " << sectors_ <<
":"
238 for (
unsigned int k = 0;
k < rad100to200_.size(); ++
k)
239 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k <<
"] 100-200 " << rad100to200_[
k] <<
" 200-300 " << rad200to300_[
k];
241 slopeB_ = vArgs[
"SlopeBottom"];
242 zFrontB_ = vArgs[
"ZFrontBottom"];
243 rMinFront_ = vArgs[
"RMinFront"];
244 slopeT_ = vArgs[
"SlopeTop"];
245 zFrontT_ = vArgs[
"ZFrontTop"];
246 rMaxFront_ = vArgs[
"RMaxFront"];
248 for (
unsigned int i = 0;
i < slopeB_.size(); ++
i)
249 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] Zmin " << zFrontB_[
i] <<
" Rmin " << rMinFront_[
i]
250 <<
" Slope " << slopeB_[
i];
251 for (
unsigned int i = 0;
i < slopeT_.size(); ++
i)
252 edm::LogVerbatim(
"HGCalGeom") <<
"Block [" <<
i <<
"] Zmin " << zFrontT_[
i] <<
" Rmax " << rMaxFront_[
i]
253 <<
" Slope " << slopeT_[
i];
260 waferType_ = std::make_unique<HGCalWaferType>(
261 rad100to200_, rad200to300_, (waferSize_ + waferSepar_), zMinRadPar_, choiceType_, nCutRadPar_, fracAreaMin_);
275 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << copies_.size() <<
" different wafer copy numbers";
277 for (std::unordered_set<int>::const_iterator itr = copies_.begin(); itr != copies_.end(); ++itr, ++
k) {
281 edm::LogVerbatim(
"HGCalGeom") <<
"<<== End of DDHGCalHEAlgo construction...";
289 double zi(zMinBlock_);
291 for (
unsigned int i = 0;
i < layers_.size();
i++) {
292 double zo = zi + layerThick_[
i];
294 int laymax = laymin + layers_[
i];
297 for (
int ly = laymin; ly < laymax; ++ly) {
298 int ii = layerType_[ly];
299 int copy = copyNumber_[
ii];
300 double hthick = 0.5 * thick_[
ii];
303 thickTot += thick_[
ii];
307 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Layer " << ly <<
":" << ii <<
" Front " << zi <<
", " << routF
308 <<
" Back " << zo <<
", " << rinB <<
" superlayer thickness " << layerThick_[
i];
313 if (layerSense_[ly] < 1) {
314 std::vector<double> pgonZ, pgonRin, pgonRout;
315 if (layerSense_[ly] == 0 || absorbMode_ == 0) {
318 pgonZ.emplace_back(-hthick);
319 pgonZ.emplace_back(hthick);
320 pgonRin.emplace_back(rinB);
321 pgonRin.emplace_back(rinB);
322 pgonRout.emplace_back(rmax);
323 pgonRout.emplace_back(rmax);
337 for (
unsigned int isec = 0; isec < pgonZ.size(); ++isec) {
339 pgonRout[isec] = pgonRout[isec] * cosAlpha_ - tol1_;
346 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.
name() <<
" polyhedra of " << sectors_
348 <<
convertRadToDeg(-alpha_ + 2._pi) <<
" with " << pgonZ.size() <<
" sections";
349 for (
unsigned int k = 0;
k < pgonZ.size(); ++
k)
350 edm::LogVerbatim(
"HGCalGeom") <<
"[" <<
k <<
"] z " << pgonZ[
k] <<
" R " << pgonRin[
k] <<
":" << pgonRout[
k];
353 double rins = (sensitiveMode_ < 1) ? rinB :
HGCalGeomTools::radius(zz + hthick, zFrontB_, rMinFront_, slopeB_);
359 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.
name() <<
" Tubs made of " << matName
360 <<
" of dimensions " << rinB <<
":" << rins <<
", " << routF <<
":" << routs
361 <<
", " << hthick <<
", 0.0, 360.0 and positioned in: " << glog.
name()
362 <<
" number " <<
copy;
364 positionMix(glog, name, copy, thick_[ii], matter, rins, rMixLayer_[
i], routs, zz, cpv);
368 cpv.
position(glog, module, copy, r1, rot);
371 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << glog.
name() <<
" number " << copy <<
" positioned in "
372 << module.
name() <<
" at " << r1 <<
" with no rotation";
378 if (
std::abs(thickTot - layerThick_[
i]) >= tol2_) {
379 if (thickTot > layerThick_[i]) {
380 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << layerThick_[
i] <<
" is smaller than " << thickTot
381 <<
": thickness of all its components **** ERROR ****";
383 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << layerThick_[
i] <<
" does not match with "
384 << thickTot <<
" of the components";
403 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
404 int ii = layerTypeTop_[ly];
405 copyNumberTop_[
ii] = copyM;
407 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
408 int ii = layerTypeBot_[ly];
409 copyNumberBot_[
ii] = copyM;
411 double hthick = 0.5 * thick;
418 <<
" of dimensions " << rmid <<
", " << rout <<
", " << hthick <<
", 0.0, 360.0";
420 cpv.
position(glog1, glog, 1, tran, rot);
423 <<
" at " << tran <<
" with no rotation";
425 double thickTot(0), zpos(-hthick);
426 for (
unsigned int ly = 0; ly < layerTypeTop_.size(); ++ly) {
427 int ii = layerTypeTop_[ly];
428 int copy = copyNumberTop_[
ii];
429 double hthickl = 0.5 * layerThickTop_[
ii];
430 thickTot += layerThickTop_[
ii];
433 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Layer " << ly <<
":" << ii <<
" R " << rmid <<
":" << rout
434 <<
" Thick " << layerThickTop_[
ii];
441 double eta1 = -
log(
tan(0.5 * atan(rmid / zz)));
442 double eta2 = -
log(
tan(0.5 * atan(rout / zz)));
443 edm::LogVerbatim(
"HGCalGeom") << name <<
" z|rin|rout " << zz <<
":" << rmid <<
":" << rout <<
" eta " << eta1
445 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.
name() <<
" Tubs made of " << matName
446 <<
" of dimensions " << rmid <<
", " << rout <<
", " << hthickl <<
", 0.0, 360.0";
450 cpv.
position(glog2, glog1, copy, r1, rot);
452 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Position " << glog2.
name() <<
" number " << copy <<
" in "
453 << glog1.
name() <<
" at " << r1 <<
" with no rotation";
455 ++copyNumberTop_[
ii];
458 if (
std::abs(thickTot - thick) >= tol2_) {
459 if (thickTot > thick) {
460 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" is smaller than " << thickTot
461 <<
": thickness of all its components in the top part **** ERROR ****";
463 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" does not match with " << thickTot
464 <<
" of the components in top part";
469 name = nameM +
"Bottom";
474 <<
" of dimensions " << rin <<
", " << rmid <<
", " << hthick <<
", 0.0, 360.0";
476 cpv.
position(glog1, glog, 1, tran, rot);
479 <<
" at " << tran <<
" with no rotation";
483 for (
unsigned int ly = 0; ly < layerTypeBot_.size(); ++ly) {
484 int ii = layerTypeBot_[ly];
485 int copy = copyNumberBot_[
ii];
486 double hthickl = 0.5 * layerThickBot_[
ii];
487 thickTot += layerThickBot_[
ii];
490 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Layer " << ly <<
":" << ii <<
" R " << rin <<
":" << rmid
491 <<
" Thick " << layerThickBot_[
ii];
498 double eta1 = -
log(
tan(0.5 * atan(rin / zz)));
499 double eta2 = -
log(
tan(0.5 * atan(rmid / zz)));
500 edm::LogVerbatim(
"HGCalGeom") << name <<
" z|rin|rout " << zz <<
":" << rin <<
":" << rmid <<
" eta " << eta1 <<
":"
502 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << solid.
name() <<
" Tubs made of " << matName
503 <<
" of dimensions " << rin <<
", " << rmid <<
", " << hthickl <<
", 0.0, 360.0";
507 cpv.
position(glog2, glog1, copy, r1, rot);
509 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Position " << glog2.
name() <<
" number " << copy <<
" in "
510 << glog1.
name() <<
" at " << r1 <<
" with no rotation";
512 if (layerSenseBot_[ly] != 0) {
514 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: z " << (zz + zpos) <<
" Center " << copy <<
":"
515 << (copy - firstLayer_) <<
":" << layerCenter_[copy - firstLayer_];
517 positionSensitive(glog2, rin, rmid, zz + zpos, layerSenseBot_[ly], layerCenter_[copy - firstLayer_], cpv);
520 ++copyNumberBot_[
ii];
522 if (
std::abs(thickTot - thick) >= tol2_) {
523 if (thickTot > thick) {
524 edm::LogError(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" is smaller than " << thickTot
525 <<
": thickness of all its components in the top part **** ERROR ****";
527 edm::LogWarning(
"HGCalGeom") <<
"Thickness of the partition " << thick <<
" does not match with " << thickTot
528 <<
" of the components in top part";
540 static const double sqrt3 =
std::sqrt(3.0);
541 double r = 0.5 * (waferSize_ + waferSepar_);
542 double R = 2.0 * r / sqrt3;
543 double dy = 0.75 *
R;
544 int N = (int)(0.5 * rout / r) + 2;
545 std::pair<double, double> xyoff = geomTools_.shiftXY(layercenter, (waferSize_ + waferSepar_));
547 int ium(0), ivm(0), iumAll(0), ivmAll(0), kount(0),
ntot(0),
nin(0);
548 std::vector<int> ntype(6, 0);
549 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << glog.
ddname() <<
" rin:rout " << rin <<
":" << rout <<
" zpos "
550 << zpos <<
" N " << N <<
" for maximum u, v Offset; Shift " << xyoff.first <<
":"
551 << xyoff.second <<
" WaferSize " << (waferSize_ + waferSepar_);
553 for (
int u = -N; u <=
N; ++u) {
554 for (
int v = -N;
v <=
N; ++
v) {
557 double xpos = xyoff.first + nc *
r;
558 double ypos = xyoff.second + nr *
dy;
565 if (corner.first > 0) {
566 int type = waferType_->getType(xpos, ypos, zpos);
576 if (copies_.count(copy) == 0)
577 copies_.insert(copy);
593 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: " << name <<
" number " << copy <<
" positioned in "
594 << glog.
ddname() <<
" at " << tran <<
" with no rotation";
601 edm::LogVerbatim(
"HGCalGeom") <<
"DDHGCalHEAlgo: Maximum # of u " << ium <<
":" << iumAll <<
" # of v " << ivm <<
":"
602 << ivmAll <<
" and " << nin <<
":" << kount <<
":" <<
ntot <<
" wafers (" << ntype[0]
603 <<
":" << ntype[1] <<
":" << ntype[2] <<
":" << ntype[3] <<
":" << ntype[4] <<
":"
604 << ntype[5] <<
") for " << glog.
ddname() <<
" R " << rin <<
":" << rout;
std::vector< double > rMixLayer_
Log< level::Info, true > LogVerbatim
static AlgebraicMatrix initialize()
std::vector< int > layerTypeTop_
std::vector< double > layerThickBot_
static std::vector< std::string > checklist log
void positionMix(const DDLogicalPart &glog, const std::string &name, int copy, double thick, const DDMaterial &matter, double rin, double rmid, double routF, double zz, DDCompactView &cpv)
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string ©no, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
std::vector< double > slopeB_
std::vector< std::string > materials_
DDMaterial is used to define and access material information.
constexpr NumType convertRadToDeg(NumType radians)
std::vector< double > zFrontB_
void execute(DDCompactView &cpv) override
DDName is used to identify DDD entities uniquely.
std::string to_string(const V &value)
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
static std::string & ns()
std::vector< double > thick_
Log< level::Error, false > LogError
std::vector< std::string > namesTop_
Compact representation of the geometrical detector hierarchy.
~DDHGCalHEAlgo() override
A DDSolid represents the shape of a part.
static constexpr uint32_t k_CornerSize
Represents a uniquely identifyable rotation matrix.
U second(std::pair< T, U > const &p)
std::unique_ptr< HGCalWaferType > waferType_
std::vector< int > layerSense_
std::vector< int > copyNumberBot_
std::vector< std::string > materialsBot_
std::vector< double > slopeT_
void positionSensitive(const DDLogicalPart &glog, double rin, double rout, double zpos, int layertype, int layercenter, DDCompactView &cpv)
void constructLayers(const DDLogicalPart &, DDCompactView &cpv)
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
void constructLayers(const cms::DDNamespace &ns, const std::vector< std::string > &wafers, const std::vector< std::string > &covers, const std::vector< int > &layerType, const std::vector< int > &layerSense, const std::vector< int > &maxModule, const std::vector< std::string > &names, const std::vector< std::string > &materials, std::vector< int > ©Number, const std::vector< double > &layerThick, const double &absorbW, const double &absorbH, const double &waferTot, const double &rMax, const double &rMaxFine, std::unordered_set< int > &copies, int firstLayer, int lastLayer, double zFront, double totalWidth, bool ignoreCenter, dd4hep::Volume &module)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
static DDSolid tubs(const DDName &name, double zhalf, double rIn, double rOut, double startPhi, double deltaPhi)
std::vector< int > layers_
std::vector< double > rMinFront_
HGCalGeomTools geomTools_
std::vector< int > layerCenter_
std::vector< double > rad100to200_
std::vector< int > dbl_to_int(const std::vector< double > &vecdbl)
Converts a std::vector of doubles to a std::vector of int.
std::vector< double > zFrontT_
std::vector< double > layerThickTop_
std::unordered_set< int > copies_
std::vector< int > copyNumber_
std::vector< int > layerType_
std::vector< std::string > materialsTop_
std::vector< int > copyNumberTop_
static int32_t packTypeUV(int type, int u, int v)
std::vector< int > layerSenseBot_
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< std::string > wafers_
Log< level::Warning, false > LogWarning
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = ':'
std::vector< std::string > namesBot_
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
std::vector< double > layerThick_
static DDSolid polyhedra(const DDName &name, int sides, double startPhi, double deltaPhi, const std::vector< double > &z, const std::vector< double > &rmin, const std::vector< double > &rmax)
Creates a polyhedra (refere to Geant3 or Geant4 documentation)
std::vector< std::string > names_
std::vector< int > layerTypeBot_
std::vector< double > rMaxFront_
std::vector< double > rad200to300_