File indexing completed on 2024-04-06 12:14:57
0001
0002
0003
0004
0005
0006
0007 #include "DD4hep/DetFactoryHelper.h"
0008 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0009 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0013
0014 #include <string>
0015 #include <vector>
0016 #include <sstream>
0017
0018
0019
0020 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0021 cms::DDNamespace ns(ctxt, e, true);
0022 cms::DDAlgoArguments args(ctxt, e);
0023 std::string motherName = args.parentName();
0024 const auto& material = args.value<std::string>("ModuleMaterial");
0025 const auto& thick = args.value<double>("ModuleThickness");
0026 const auto& waferSize = args.value<double>("WaferSize");
0027 const auto& waferThick = args.value<double>("WaferThickness");
0028 #ifdef EDM_ML_DEBUG
0029 const auto& waferSepar = args.value<double>("SensorSeparation");
0030 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Module " << motherName << " made of " << material << " T "
0031 << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
0032 << " Half Separation " << cms::convert2mm(waferSepar) << " T "
0033 << cms::convert2mm(waferThick);
0034 #endif
0035 const auto& layerNames = args.value<std::vector<std::string>>("LayerNames");
0036 const auto& materials = args.value<std::vector<std::string>>("LayerMaterials");
0037 const auto& layerThick = args.value<std::vector<double>>("LayerThickness");
0038 const auto& layerType = args.value<std::vector<int>>("LayerTypes");
0039 std::vector<int> copyNumber(materials.size(), 1);
0040 #ifdef EDM_ML_DEBUG
0041 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << layerNames.size() << " types of volumes";
0042 for (unsigned int i = 0; i < layerNames.size(); ++i)
0043 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
0044 << cms::convert2mm(layerThick[i]) << " filled with " << materials[i] << " type "
0045 << layerType[i];
0046 #endif
0047 const auto& layers = args.value<std::vector<int>>("Layers");
0048 #ifdef EDM_ML_DEBUG
0049 std::ostringstream st1;
0050 for (unsigned int i = 0; i < layers.size(); ++i)
0051 st1 << " [" << i << "] " << layers[i];
0052 edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
0053 #endif
0054 const auto& nCells = args.value<int>("NCells");
0055 const auto& cellTypeX = args.value<int>("CellType");
0056 const auto& cellNames = args.value<std::vector<std::string>>("CellNames");
0057 #ifdef EDM_ML_DEBUG
0058 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cells/Wafer " << nCells << " Cell Type " << cellTypeX
0059 << " NameSpace " << ns.name() << " # of cells " << cellNames.size();
0060 for (unsigned int k = 0; k < cellNames.size(); ++k)
0061 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: Cell[" << k << "] " << cellNames[k];
0062 int counter(0);
0063 #endif
0064
0065 static constexpr double tol = 0.00001 * dd4hep::mm;
0066 static const double sqrt3 = std::sqrt(3.0);
0067 double rM = 0.5 * waferSize;
0068 double RM2 = rM / sqrt3;
0069 double R = waferSize / (3.0 * nCells);
0070 double r = 0.5 * R * sqrt3;
0071 double r2 = 0.5 * waferSize;
0072 double R2 = r2 / sqrt3;
0073
0074
0075 std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0076 std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0077 std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
0078 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0079
0080 dd4hep::Material matter = ns.material(material);
0081 dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0082 ns.addSolidNS(ns.prepend(motherName), solid);
0083 dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
0084 ns.addVolumeNS(glogM);
0085 #ifdef EDM_ML_DEBUG
0086 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << material
0087 << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0088 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0089 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0090 << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
0091 for (unsigned int k = 0; k < xM.size(); ++k)
0092 edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xM[k]) << ":" << cms::convert2mm(yM[k]);
0093 #endif
0094
0095
0096 dd4hep::Rotation3D rotation;
0097 std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
0098 std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0099 std::vector<dd4hep::Volume> glogs(materials.size());
0100 double zi(-0.5 * thick), thickTot(0.0);
0101 for (unsigned int l = 0; l < layers.size(); l++) {
0102 unsigned int i = layers[l];
0103 if (copyNumber[i] == 1) {
0104 if (layerType[i] > 0) {
0105 zw[0] = -0.5 * waferThick;
0106 zw[1] = 0.5 * waferThick;
0107 } else {
0108 zw[0] = -0.5 * layerThick[i];
0109 zw[1] = 0.5 * layerThick[i];
0110 }
0111 solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0112 ns.addSolidNS(ns.prepend(layerNames[i]), solid);
0113 matter = ns.material(materials[i]);
0114 glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0115 ns.addVolumeNS(glogs[i]);
0116 #ifdef EDM_ML_DEBUG
0117 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << solid.name() << " extruded polygon made of " << materials[i]
0118 << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0119 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0120 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0121 << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size() << " edges";
0122 for (unsigned int k = 0; k < xL.size(); ++k)
0123 edm::LogVerbatim("HGCalGeom") << "[" << k << "] " << cms::convert2mm(xL[k]) << ":" << cms::convert2mm(yL[k]);
0124 #endif
0125 }
0126 dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
0127 glogM.placeVolume(glogs[i], copyNumber[i], tran0);
0128 #ifdef EDM_ML_DEBUG
0129 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferF: " << glogs[i].name() << " number " << copyNumber[i]
0130 << " positioned in " << glogM.name() << " at (0,0,"
0131 << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
0132 #endif
0133 ++copyNumber[i];
0134 zi += layerThick[i];
0135 thickTot += layerThick[i];
0136
0137 if (layerType[i] > 0) {
0138 int n2 = nCells / 2;
0139 double y0 = (cellTypeX >= 3) ? 0.5 : 0.0;
0140 double x0 = (cellTypeX >= 3) ? 0.5 : 1.0;
0141 int voff = (cellTypeX >= 3) ? 0 : 1;
0142 int uoff = 1 - voff;
0143 int cellType = (cellTypeX >= 3) ? (cellTypeX - 3) : cellTypeX;
0144 for (int u = 0; u < 2 * nCells; ++u) {
0145 for (int v = 0; v < 2 * nCells; ++v) {
0146 if (((v - u) < (nCells + uoff)) && (u - v) < (nCells + voff)) {
0147 #ifdef EDM_ML_DEBUG
0148 counter++;
0149 #endif
0150 double yp = (u - 0.5 * v - n2 + y0) * 2 * r;
0151 double xp = (1.5 * (v - nCells) + x0) * R;
0152 int cell(0);
0153 if ((u == 0) && (v == 0))
0154 cell = 7;
0155 else if ((u == 0) && (v == nCells - 1))
0156 cell = 8;
0157 else if ((u == nCells) && (v == 2 * nCells - 1))
0158 cell = 9;
0159 else if ((u == 2 * nCells - 1) && (v == 2 * nCells - 1))
0160 cell = 10;
0161 else if ((u == 2 * nCells - 1) && (v == nCells - 1))
0162 cell = 11;
0163 else if ((u == nCells) && (v == 0))
0164 cell = 12;
0165 else if (u == 0)
0166 cell = 1;
0167 else if ((v - u) == (nCells - 1))
0168 cell = 4;
0169 else if (v == (2 * nCells - 1))
0170 cell = 2;
0171 else if (u == (2 * nCells - 1))
0172 cell = 5;
0173 else if ((u - v) == nCells)
0174 cell = 3;
0175 else if (v == 0)
0176 cell = 6;
0177 dd4hep::Position tran(xp, yp, 0);
0178 int copy = HGCalTypes::packCellTypeUV(cellType, u, v);
0179 glogs[i].placeVolume(ns.volume(cellNames[cell]), copy, dd4hep::Transform3D(rotation, tran));
0180 #ifdef EDM_ML_DEBUG
0181 edm::LogVerbatim("HGCalGeom")
0182 << "DDHGCalWaferF: " << cellNames[cell] << " number " << copy << " positioned in " << glogs[i].name()
0183 << " at (" << cms::convert2mm(xp) << "," << cms::convert2mm(yp) << ",0) with no rotation";
0184 #endif
0185 }
0186 }
0187 }
0188 }
0189 }
0190 #ifdef EDM_ML_DEBUG
0191 edm::LogVerbatim("HGCalGeom") << "\nDDHGCalWaferF::Counter : " << counter << "\n===============================\n";
0192 #endif
0193 if (std::abs(thickTot - thick) >= tol) {
0194 if (thickTot > thick) {
0195 edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
0196 << ": thickness of all its components **** ERROR ****";
0197 } else {
0198 edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with " << thickTot
0199 << " of the components";
0200 }
0201 }
0202
0203 return cms::s_executed;
0204 }
0205
0206
0207 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferF, algorithm)