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 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0014
0015 #include <string>
0016 #include <vector>
0017 #include <sstream>
0018
0019
0020
0021 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0022 cms::DDNamespace ns(ctxt, e, true);
0023 cms::DDAlgoArguments args(ctxt, e);
0024 std::string parentName = args.parentName();
0025 const auto& material = args.value<std::string>("ModuleMaterial");
0026 const auto& thick = args.value<double>("ModuleThickness");
0027 const auto& waferSize = args.value<double>("WaferSize");
0028 const auto& waferThick = args.value<double>("WaferThickness");
0029 #ifdef EDM_ML_DEBUG
0030 const auto& waferSepar = args.value<double>("SensorSeparation");
0031 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: Module " << parentName << " made of " << material << " T "
0032 << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
0033 << " Half Separation " << cms::convert2mm(waferSepar) << " T "
0034 << cms::convert2mm(waferThick);
0035 #endif
0036 const auto& tags = args.value<std::vector<std::string>>("Tags");
0037 const auto& partialTypes = args.value<std::vector<int>>("PartialTypes");
0038 const auto& orientations = args.value<std::vector<int>>("Orientations");
0039 #ifdef EDM_ML_DEBUG
0040 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << tags.size() << " variations of wafer types";
0041 for (unsigned int k = 0; k < tags.size(); ++k)
0042 edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
0043 << " Orientation " << orientations[k];
0044 #endif
0045 const auto& layerNames = args.value<std::vector<std::string>>("LayerNames");
0046 const auto& materials = args.value<std::vector<std::string>>("LayerMaterials");
0047 const auto& layerThick = args.value<std::vector<double>>("LayerThickness");
0048 const auto& layerType = args.value<std::vector<int>>("LayerTypes");
0049 #ifdef EDM_ML_DEBUG
0050 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << layerNames.size() << " types of volumes";
0051 for (unsigned int i = 0; i < layerNames.size(); ++i)
0052 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
0053 << cms::convert2mm(layerThick[i]) << " filled with " << materials[i] << " type "
0054 << layerType[i];
0055 #endif
0056 const auto& layers = args.value<std::vector<int>>("Layers");
0057 #ifdef EDM_ML_DEBUG
0058 std::ostringstream st1;
0059 for (unsigned int i = 0; i < layers.size(); ++i)
0060 st1 << " [" << i << "] " << layers[i];
0061 edm::LogVerbatim("HGCalGeom") << "There are " << layers.size() << " blocks" << st1.str();
0062 #endif
0063 const auto& senseName = args.value<std::string>("SenseName");
0064 const auto& senseT = args.value<double>("SenseThick");
0065 const auto& senseType = args.value<int>("SenseType");
0066 const auto& posSense = args.value<int>("PosSensitive");
0067 #ifdef EDM_ML_DEBUG
0068 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: NameSpace " << ns.name() << " Sensitive Layer Name " << senseName
0069 << " Thickness " << senseT << " Type " << senseType << " Position " << posSense;
0070 #endif
0071
0072 static constexpr double tol = 0.00001 * dd4hep::mm;
0073
0074
0075 for (unsigned int k = 0; k < tags.size(); ++k) {
0076
0077 std::string mother = parentName + tags[k];
0078 std::vector<std::pair<double, double>> wxy =
0079 HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, waferSize, 0.0, 0.0, 0.0, true);
0080 std::vector<double> xM, yM;
0081 for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0082 xM.emplace_back(wxy[i].first);
0083 yM.emplace_back(wxy[i].second);
0084 }
0085 std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
0086 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0087
0088 dd4hep::Material matter = ns.material(material);
0089 dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0090 ns.addSolidNS(ns.prepend(mother), solid);
0091 dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
0092 ns.addVolumeNS(glogM);
0093 #ifdef EDM_ML_DEBUG
0094 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of " << material
0095 << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":" << cms::convert2mm(zx[0]) << ":"
0096 << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0097 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":"
0098 << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial " << partialTypes[k]
0099 << " orientation " << orientations[k] << " and " << xM.size() << " edges";
0100 for (unsigned int j = 0; j < xM.size(); ++j)
0101 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xM[j]) << ":" << cms::convert2mm(yM[j]);
0102 #endif
0103
0104
0105 dd4hep::Rotation3D rotation;
0106 wxy = HGCalWaferMask::waferXY(partialTypes[k], orientations[k], 1, waferSize, 0.0, 0.0, 0.0, true);
0107 std::vector<double> xL, yL;
0108 for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0109 xL.emplace_back(wxy[i].first);
0110 yL.emplace_back(wxy[i].second);
0111 }
0112 std::vector<dd4hep::Volume> glogs(materials.size());
0113 std::vector<int> copyNumber(materials.size(), 1);
0114 double zi(-0.5 * thick), thickTot(0.0);
0115 for (unsigned int l = 0; l < layers.size(); l++) {
0116 unsigned int i = layers[l];
0117 #ifdef EDM_ML_DEBUG
0118 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP:Layer " << l << ":" << i << " T " << layerThick[i] << " Copy "
0119 << copyNumber[i];
0120 #endif
0121 if (copyNumber[i] == 1) {
0122 if (layerType[i] > 0) {
0123 zw[0] = -0.5 * waferThick;
0124 zw[1] = 0.5 * waferThick;
0125 } else {
0126 zw[0] = -0.5 * layerThick[i];
0127 zw[1] = 0.5 * layerThick[i];
0128 }
0129 solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0130 std::string lname = layerNames[i] + tags[k];
0131 ns.addSolidNS(ns.prepend(lname), solid);
0132 matter = ns.material(materials[i]);
0133 glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0134 ns.addVolumeNS(glogs[i]);
0135 #ifdef EDM_ML_DEBUG
0136 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
0137 << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0138 << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
0139 << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
0140 << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
0141 << partialTypes[k] << " orientation " << orientations[k] << " and " << xM.size()
0142 << " edges";
0143 for (unsigned int j = 0; j < xL.size(); ++j)
0144 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
0145 #endif
0146 }
0147 if (layerType[i] > 0) {
0148 std::string sname = senseName + tags[k];
0149 zw[0] = -0.5 * senseT;
0150 zw[1] = 0.5 * senseT;
0151 solid = dd4hep::ExtrudedPolygon(xL, yL, zw, zx, zy, scale);
0152 ns.addSolidNS(ns.prepend(sname), solid);
0153 dd4hep::Volume glog = dd4hep::Volume(solid.name(), solid, matter);
0154 ns.addVolumeNS(glog);
0155 #ifdef EDM_ML_DEBUG
0156 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << solid.name() << " extruded polygon made of "
0157 << materials[i] << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0158 << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
0159 << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
0160 << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " partial "
0161 << partialTypes[k] << " orientation " << orientations[k] << " and " << xL.size()
0162 << " edges";
0163 for (unsigned int j = 0; j < xL.size(); ++j)
0164 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << cms::convert2mm(xL[j]) << ":" << cms::convert2mm(yL[j]);
0165 #endif
0166 double zpos = (posSense == 0) ? -0.5 * (waferThick - senseT) : 0.5 * (waferThick - senseT);
0167 dd4hep::Position tran(0, 0, zpos);
0168 int copy = 10 + senseType;
0169 glogs[i].placeVolume(glog, copy, tran);
0170 #ifdef EDM_ML_DEBUG
0171 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glog.name() << " number " << copy << " positioned in "
0172 << glogs[i].name() << " at (0,0," << cms::convert2mm(zpos)
0173 << ") with no rotation";
0174 #endif
0175 }
0176 dd4hep::Position tran0(0, 0, (zi + 0.5 * layerThick[i]));
0177 glogM.placeVolume(glogs[i], copyNumber[i], tran0);
0178 #ifdef EDM_ML_DEBUG
0179 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferP: " << glogs[i].name() << " number " << copyNumber[i]
0180 << " positioned in " << glogM.name() << " at (0,0,"
0181 << cms::convert2mm(zi + 0.5 * layerThick[i]) << ") with no rotation";
0182 #endif
0183 ++copyNumber[i];
0184 zi += layerThick[i];
0185 thickTot += layerThick[i];
0186 }
0187 if (std::abs(thickTot - thick) >= tol) {
0188 if (thickTot > thick) {
0189 edm::LogError("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick) << " is smaller than "
0190 << cms::convert2mm(thickTot) << ": thickness of all its components **** ERROR ****";
0191 } else {
0192 edm::LogWarning("HGCalGeom") << "Thickness of the partition " << cms::convert2mm(thick)
0193 << " does not match with " << cms::convert2mm(thickTot) << " of the components";
0194 }
0195 }
0196 }
0197
0198 return cms::s_executed;
0199 }
0200
0201
0202 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalWaferP, algorithm)