File indexing completed on 2024-04-06 12:15:01
0001
0002
0003
0004
0005
0006
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/HGCalTypes.h"
0019
0020 #include <string>
0021 #include <vector>
0022 #include <sstream>
0023
0024
0025
0026 class DDHGCalWaferF : public DDAlgorithm {
0027 public:
0028
0029 DDHGCalWaferF() {}
0030 ~DDHGCalWaferF() override = default;
0031
0032 void initialize(const DDNumericArguments& nArgs,
0033 const DDVectorArguments& vArgs,
0034 const DDMapArguments& mArgs,
0035 const DDStringArguments& sArgs,
0036 const DDStringVectorArguments& vsArgs) override;
0037 void execute(DDCompactView& cpv) override;
0038
0039 private:
0040 std::string material_;
0041 double thick_;
0042 double waferSize_;
0043 double waferSepar_;
0044 double waferThick_;
0045 std::vector<std::string> layerNames_;
0046 std::vector<std::string> materials_;
0047 std::vector<double> layerThick_;
0048 std::vector<int> layerType_;
0049 std::vector<int> copyNumber_;
0050 std::vector<int> layers_;
0051 int nCells_;
0052 int cellType_;
0053 std::vector<std::string> cellNames_;
0054 std::string nameSpace_;
0055 };
0056
0057 void DDHGCalWaferF::initialize(const DDNumericArguments& nArgs,
0058 const DDVectorArguments& vArgs,
0059 const DDMapArguments&,
0060 const DDStringArguments& sArgs,
0061 const DDStringVectorArguments& vsArgs) {
0062 material_ = sArgs["ModuleMaterial"];
0063 thick_ = nArgs["ModuleThickness"];
0064 waferSize_ = nArgs["WaferSize"];
0065 waferSepar_ = nArgs["SensorSeparation"];
0066 waferThick_ = nArgs["WaferThickness"];
0067 #ifdef EDM_ML_DEBUG
0068 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Module " << parent().name() << " made of " << material_ << " T "
0069 << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_ << " T "
0070 << waferThick_;
0071 #endif
0072 layerNames_ = vsArgs["LayerNames"];
0073 materials_ = vsArgs["LayerMaterials"];
0074 layerThick_ = vArgs["LayerThickness"];
0075 layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0076 copyNumber_.resize(materials_.size(), 1);
0077 #ifdef EDM_ML_DEBUG
0078 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << layerNames_.size() << " types of volumes";
0079 for (unsigned int i = 0; i < layerNames_.size(); ++i)
0080 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0081 << " filled with " << materials_[i] << " type " << layerType_[i];
0082 #endif
0083 layers_ = dbl_to_int(vArgs["Layers"]);
0084 #ifdef EDM_ML_DEBUG
0085 std::ostringstream st1;
0086 for (unsigned int i = 0; i < layers_.size(); ++i)
0087 st1 << " [" << i << "] " << layers_[i];
0088 edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
0089 #endif
0090 nCells_ = (int)(nArgs["NCells"]);
0091 cellType_ = (int)(nArgs["CellType"]);
0092 cellNames_ = vsArgs["CellNames"];
0093 nameSpace_ = DDCurrentNamespace::ns();
0094 #ifdef EDM_ML_DEBUG
0095 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cells/Wafer " << nCells_ << " Cell Type " << cellType_
0096 << " NameSpace " << nameSpace_ << ": # of cells " << cellNames_.size();
0097 for (unsigned int k = 0; k < cellNames_.size(); ++k)
0098 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cell[" << k << "] " << cellNames_[k];
0099 #endif
0100 }
0101
0102 void DDHGCalWaferF::execute(DDCompactView& cpv) {
0103 #ifdef EDM_ML_DEBUG
0104 int counter(0);
0105 #endif
0106
0107 static constexpr double tol = 0.00001;
0108 static const double sqrt3 = std::sqrt(3.0);
0109 double rM = 0.5 * waferSize_;
0110 double RM2 = rM / sqrt3;
0111 double R = waferSize_ / (3.0 * nCells_);
0112 double r = 0.5 * R * sqrt3;
0113 double r2 = 0.5 * waferSize_;
0114 double R2 = r2 / sqrt3;
0115
0116
0117 std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0118 std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0119 std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0120 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0121 DDName parentName = parent().name();
0122 DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0123 DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0124 DDMaterial matter(matName);
0125 DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0126 #ifdef EDM_ML_DEBUG
0127 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << matName
0128 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0129 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0130 << " and " << xM.size() << " edges";
0131 for (unsigned int k = 0; k < xM.size(); ++k)
0132 edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xM[k] << ":" << yM[k];
0133 #endif
0134
0135
0136 std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
0137 std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0138 std::vector<DDLogicalPart> glogs(materials_.size());
0139 double zi(-0.5 * thick_), thickTot(0.0);
0140 for (unsigned int l = 0; l < layers_.size(); l++) {
0141 unsigned int i = layers_[l];
0142 if (copyNumber_[i] == 1) {
0143 if (layerType_[i] > 0) {
0144 zw[0] = -0.5 * waferThick_;
0145 zw[1] = 0.5 * waferThick_;
0146 } else {
0147 zw[0] = -0.5 * layerThick_[i];
0148 zw[1] = 0.5 * layerThick_[i];
0149 }
0150 solid = DDSolidFactory::extrudedpolygon(layerNames_[i], xL, yL, zw, zx, zy, scale);
0151 DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0152 DDMaterial matter(matN);
0153 glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0154 #ifdef EDM_ML_DEBUG
0155 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << matN
0156 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0]
0157 << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1]
0158 << " and " << xL.size() << " edges";
0159 for (unsigned int k = 0; k < xL.size(); ++k)
0160 edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << xL[k] << ":" << yL[k];
0161 #endif
0162 }
0163 DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0164 DDRotation rot;
0165 cpv.position(glogs[i], glogM, copyNumber_[i], tran0, rot);
0166 #ifdef EDM_ML_DEBUG
0167 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << glogs[i].name() << " number " << copyNumber_[i]
0168 << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0169 #endif
0170 ++copyNumber_[i];
0171 zi += layerThick_[i];
0172 thickTot += layerThick_[i];
0173 if (layerType_[i] > 0) {
0174 int n2 = nCells_ / 2;
0175 double y0 = (cellType_ >= 3) ? 0.5 : 0.0;
0176 double x0 = (cellType_ >= 3) ? 0.5 : 1.0;
0177 int voff = (cellType_ >= 3) ? 0 : 1;
0178 int uoff = 1 - voff;
0179 int cellType = (cellType_ >= 3) ? (cellType_ - 3) : cellType_;
0180 for (int u = 0; u < 2 * nCells_; ++u) {
0181 for (int v = 0; v < 2 * nCells_; ++v) {
0182 if (((v - u) < (nCells_ + uoff)) && (u - v) < (nCells_ + voff)) {
0183 #ifdef EDM_ML_DEBUG
0184 counter++;
0185 #endif
0186 double yp = (u - 0.5 * v - n2 + y0) * 2 * r;
0187 double xp = (1.5 * (v - nCells_) + x0) * R;
0188 int cell(0);
0189 if ((u == 0) && (v == 0))
0190 cell = 7;
0191 else if ((u == 0) && (v == nCells_ - voff))
0192 cell = 8;
0193 else if ((u == nCells_ - uoff) && (v == 2 * nCells_ - 1))
0194 cell = 9;
0195 else if ((u == (2 * nCells_ - 1)) && (v == 2 * nCells_ - 1))
0196 cell = 10;
0197 else if ((u == 2 * nCells_ - 1) && (v == (nCells_ - voff)))
0198 cell = 11;
0199 else if ((u == (nCells_ - uoff)) && (v == 0))
0200 cell = 12;
0201 else if (u == 0)
0202 cell = 1;
0203 else if ((v - u) == (nCells_ - voff))
0204 cell = 4;
0205 else if (v == (2 * nCells_ - 1))
0206 cell = 2;
0207 else if (u == (2 * nCells_ - 1))
0208 cell = 5;
0209 else if ((u - v) == (nCells_ - uoff))
0210 cell = 3;
0211 else if (v == 0)
0212 cell = 6;
0213 if ((cellType_ >= 3) && (cell != 0))
0214 cell += 12;
0215 DDTranslation tran(xp, yp, 0);
0216 int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
0217 cpv.position(DDName(cellNames_[cell]), glogs[i], copy, tran, rot);
0218 #ifdef EDM_ML_DEBUG
0219 edm::LogVerbatim("HGCalGeom")
0220 << "DDHGCalWaferF: " << cellNames_[cell] << " number " << copy << " positioned in " << glogs[i].name()
0221 << " at " << tran << " with no rotation";
0222 #endif
0223 }
0224 }
0225 }
0226 }
0227 }
0228 #ifdef EDM_ML_DEBUG
0229 edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWaferF::Counter : " << counter << "\n===============================\n";
0230 #endif
0231 if (std::abs(thickTot - thick_) >= tol) {
0232 if (thickTot > thick_) {
0233 edm::LogError("HGCalGeom") << "Thickness of the partition " << thick_ << " is smaller than " << thickTot
0234 << ": thickness of all its components **** ERROR ****";
0235 } else {
0236 edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick_ << " does not match with " << thickTot
0237 << " of the components";
0238 }
0239 }
0240 }
0241
0242 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferF, "hgcal:DDHGCalWaferF");