File indexing completed on 2024-06-25 02:44:37
0001
0002
0003
0004
0005
0006 #include "DataFormats/Math/interface/angle_units.h"
0007 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0008 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0009 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0010 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0011 #include "DetectorDescription/Core/interface/DDMaterial.h"
0012 #include "DetectorDescription/Core/interface/DDSolid.h"
0013 #include "DetectorDescription/Core/interface/DDSplit.h"
0014 #include "DetectorDescription/Core/interface/DDTypes.h"
0015 #include "DetectorDescription/Core/interface/DDutils.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/PluginManager/interface/PluginFactory.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalGeomTools.h"
0019
0020 #include <string>
0021 #include <vector>
0022 #include <sstream>
0023
0024
0025
0026 using namespace angle_units::operators;
0027
0028 class DDHGCalPassive : public DDAlgorithm {
0029 public:
0030
0031 DDHGCalPassive();
0032 ~DDHGCalPassive() override = default;
0033
0034 void initialize(const DDNumericArguments& nArgs,
0035 const DDVectorArguments& vArgs,
0036 const DDMapArguments& mArgs,
0037 const DDStringArguments& sArgs,
0038 const DDStringVectorArguments& vsArgs) override;
0039 void execute(DDCompactView& cpv) override;
0040
0041 private:
0042 std::string material_;
0043 double thick_;
0044 double zMinBlock_;
0045 double moduleThick_;
0046 std::vector<std::string> tagLayer_;
0047 int sectors_;
0048 int parts_;
0049 std::vector<std::string> tagSector_;
0050 double phi0_;
0051 double dphi_;
0052 double shiftTop_;
0053 double shiftBot_;
0054 std::vector<std::string> layerNames_;
0055 std::vector<std::string> materials_;
0056 std::vector<double> layerThick_;
0057 std::vector<int> layerType_;
0058 std::vector<double> slopeB_;
0059 std::vector<double> zFrontB_;
0060 std::vector<double> rMinFront_;
0061 std::vector<double> slopeT_;
0062 std::vector<double> zFrontT_;
0063 std::vector<double> rMaxFront_;
0064 };
0065
0066 DDHGCalPassive::DDHGCalPassive() {
0067 #ifdef EDM_ML_DEBUG
0068 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Creating an instance";
0069 #endif
0070 }
0071
0072 void DDHGCalPassive::initialize(const DDNumericArguments& nArgs,
0073 const DDVectorArguments& vArgs,
0074 const DDMapArguments&,
0075 const DDStringArguments& sArgs,
0076 const DDStringVectorArguments& vsArgs) {
0077 material_ = sArgs["ModuleMaterial"];
0078 thick_ = nArgs["Thickness"];
0079 zMinBlock_ = nArgs["zMinBlock"];
0080 moduleThick_ = nArgs["ModuleThick"];
0081 tagLayer_ = vsArgs["TagLayer"];
0082 tagSector_ = vsArgs["TagSector"];
0083 parts_ = static_cast<int>(nArgs["Parts"]);
0084 phi0_ = convertDegToRad(nArgs["PhiStart"]);
0085 dphi_ = (2._pi) / tagSector_.size();
0086 #ifdef EDM_ML_DEBUG
0087 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << tagLayer_.size() << " Modules with base name "
0088 << parent().name() << " made of " << material_ << " T " << thick_ << " Sectors "
0089 << tagSector_.size() << " Parts " << parts_ << " phi0 " << convertRadToDeg(phi0_);
0090 for (unsigned int i = 0; i < tagLayer_.size(); ++i)
0091 edm::LogVerbatim("HGCalGeom") << "Layer " << i << " Tag " << tagLayer_[i] << " T " << moduleThick_;
0092 for (unsigned int i = 0; i < tagSector_.size(); ++i)
0093 edm::LogVerbatim("HGCalGeom") << "Sector " << i << " Tag " << tagSector_[i] << " W " << convertRadToDeg(dphi_);
0094 #endif
0095
0096 layerNames_ = vsArgs["LayerNames"];
0097 materials_ = vsArgs["LayerMaterials"];
0098 layerThick_ = vArgs["LayerThickness"];
0099 #ifdef EDM_ML_DEBUG
0100 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << layerNames_.size() << " types of volumes";
0101 for (unsigned int i = 0; i < layerNames_.size(); ++i)
0102 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0103 << " filled with " << materials_[i];
0104 #endif
0105 layerType_ = dbl_to_int(vArgs["LayerType"]);
0106 #ifdef EDM_ML_DEBUG
0107 std::ostringstream st1;
0108 for (unsigned int i = 0; i < layerType_.size(); ++i)
0109 st1 << " [" << i << "] " << layerType_[i];
0110 edm::LogVerbatim("HGCalGeom") << "There are " << layerType_.size() << " blocks" << st1.str();
0111 #endif
0112
0113 shiftTop_ = nArgs["ShiftTop"];
0114 shiftBot_ = nArgs["ShiftBottom"];
0115 #ifdef EDM_ML_DEBUG
0116 edm::LogVerbatim("HGCalGeom") << "Shifts st the top " << shiftTop_ << " and at the bottom " << shiftBot_;
0117 #endif
0118 slopeB_ = vArgs["SlopeBottom"];
0119 zFrontB_ = vArgs["ZFrontBottom"];
0120 rMinFront_ = vArgs["RMinFront"];
0121 slopeT_ = vArgs["SlopeTop"];
0122 zFrontT_ = vArgs["ZFrontTop"];
0123 rMaxFront_ = vArgs["RMaxFront"];
0124 #ifdef EDM_ML_DEBUG
0125 for (unsigned int i = 0; i < slopeB_.size(); ++i)
0126 edm::LogVerbatim("HGCalGeom") << "Bottom Block [" << i << "] Zmin " << zFrontB_[i] << " Rmin " << rMinFront_[i]
0127 << " Slope " << slopeB_[i];
0128 for (unsigned int i = 0; i < slopeT_.size(); ++i)
0129 edm::LogVerbatim("HGCalGeom") << "Top Block [" << i << "] Zmin " << zFrontT_[i] << " Rmax " << rMaxFront_[i]
0130 << " Slope " << slopeT_[i];
0131 #endif
0132 }
0133
0134 void DDHGCalPassive::execute(DDCompactView& cpv) {
0135 #ifdef EDM_ML_DEBUG
0136 edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassive...";
0137 #endif
0138 static constexpr double tol = 0.00001;
0139
0140
0141 double zim(zMinBlock_);
0142
0143 for (unsigned int j = 0; j < tagLayer_.size(); ++j) {
0144 double routF = HGCalGeomTools::radius(zim, zFrontT_, rMaxFront_, slopeT_) - shiftTop_;
0145 double zo = zim + moduleThick_;
0146 double rinB = HGCalGeomTools::radius(zo, zFrontB_, rMinFront_, slopeB_) + shiftBot_;
0147 zim += moduleThick_;
0148 for (unsigned int k = 0; k < tagSector_.size(); ++k) {
0149 std::string parentName = parent().name().name() + tagLayer_[j] + tagSector_[k];
0150 double phi1 = phi0_ + k * dphi_;
0151 double phi2 = phi1 + dphi_;
0152 double phi0 = phi1 + 0.5 * dphi_;
0153
0154 std::vector<double> xM, yM;
0155 if (parts_ == 1) {
0156 xM = {rinB * cos(phi1), routF * cos(phi1), routF * cos(phi2), rinB * cos(phi2)};
0157 yM = {rinB * sin(phi1), routF * sin(phi1), routF * sin(phi2), rinB * sin(phi2)};
0158 } else {
0159
0160 std::vector<double> xTmp = {rinB * cos(phi1),
0161 routF * cos(phi1),
0162 routF * cos(phi0),
0163 routF * cos(phi2),
0164 rinB * cos(phi2),
0165 rinB * cos(phi0)};
0166 std::vector<double> yTmp = {rinB * sin(phi1),
0167 routF * sin(phi1),
0168 routF * sin(phi0),
0169 routF * sin(phi2),
0170 rinB * sin(phi2),
0171 rinB * sin(phi0)};
0172 xM = std::move(xTmp);
0173 yM = std::move(yTmp);
0174 }
0175 std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0176 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0177 DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0178 DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0179 DDMaterial matter(matName);
0180 DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0181 #ifdef EDM_ML_DEBUG
0182 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << solid.name() << " extruded polygon made of " << matName
0183 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0184 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0185 << " and " << xM.size() << " edges";
0186 for (unsigned int kk = 0; kk < xM.size(); ++kk)
0187 edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0188 #endif
0189
0190
0191 std::vector<DDLogicalPart> glogs(materials_.size());
0192 std::vector<int> copyNumber(materials_.size(), 1);
0193 double zi(-0.5 * thick_), thickTot(0.0);
0194 for (unsigned int l = 0; l < layerType_.size(); l++) {
0195 unsigned int i = layerType_[l];
0196 if (copyNumber[i] == 1) {
0197 zw[0] = -0.5 * layerThick_[i];
0198 zw[1] = 0.5 * layerThick_[i];
0199 std::string layerName = parentName + layerNames_[i];
0200 solid = DDSolidFactory::extrudedpolygon(layerName, xM, yM, zw, zx, zy, scale);
0201 DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0202 DDMaterial matter(matN);
0203 glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0204 #ifdef EDM_ML_DEBUG
0205 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: Layer " << i << ":" << l << ":" << solid.name()
0206 << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
0207 << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
0208 << zx[1] << ":" << zy[1] << ":" << scale[1] << " and " << xM.size() << " edges";
0209 for (unsigned int kk = 0; kk < xM.size(); ++kk)
0210 edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0211 #endif
0212 }
0213 DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0214 DDRotation rot;
0215 cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0216 #ifdef EDM_ML_DEBUG
0217 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassive: " << glogs[i].name() << " number " << copyNumber[i]
0218 << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0219 #endif
0220 ++copyNumber[i];
0221 zi += layerThick_[i];
0222 thickTot += layerThick_[i];
0223 }
0224 if ((std::abs(thickTot - thick_) >= tol) && (!layerType_.empty())) {
0225 if (thickTot > thick_) {
0226 edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0227 << ": thickness of all its components **** ERROR ****";
0228 } else {
0229 edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0230 << " of the components";
0231 }
0232 }
0233 }
0234 }
0235 }
0236
0237 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalPassive, "hgcal:DDHGCalPassive");