File indexing completed on 2024-04-06 12:14:56
0001
0002
0003
0004
0005
0006
0007
0008 #include <string>
0009 #include <vector>
0010 #include <sstream>
0011
0012 #include "DD4hep/DetFactoryHelper.h"
0013 #include "DataFormats/Math/interface/angle_units.h"
0014 #include "DetectorDescription/DDCMS/interface/DDPlugins.h"
0015 #include "DetectorDescription/DDCMS/interface/DDutils.h"
0016 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0017 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0018
0019
0020 using namespace angle_units::operators;
0021
0022 struct HGCalPassivePartial {
0023 HGCalPassivePartial() { throw cms::Exception("HGCalGeom") << "Wrong initialization to HGCalPassivePartial"; }
0024 HGCalPassivePartial(cms::DDParsingContext& ctxt, xml_h e) {
0025 cms::DDNamespace ns(ctxt, e, true);
0026 cms::DDAlgoArguments args(ctxt, e);
0027 #ifdef EDM_ML_DEBUG
0028 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Creating an instance";
0029 #endif
0030 std::string parentName = args.parentName();
0031 std::string material = args.value<std::string>("ModuleMaterial");
0032 double thick = args.value<double>("ModuleThickness");
0033 double waferSize = args.value<double>("WaferSize");
0034 double waferSepar = args.value<double>("SensorSeparation");
0035 #ifdef EDM_ML_DEBUG
0036 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: Module " << parentName << " made of " << material << " T "
0037 << cms::convert2mm(thick) << " Wafer 2r " << cms::convert2mm(waferSize)
0038 << " Half Separation " << cms::convert2mm(waferSepar);
0039 #endif
0040 std::vector<std::string> tags = args.value<std::vector<std::string>>("Tags");
0041 std::vector<int> partialTypes = args.value<std::vector<int>>("PartialTypes");
0042 std::vector<int> placementIndex = args.value<std::vector<int>>("PlacementIndex");
0043 std::vector<std::string> placementIndexTags = args.value<std::vector<std::string>>("PlacementIndexTags");
0044 #ifdef EDM_ML_DEBUG
0045 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << tags.size() << " variations of wafer types";
0046 for (unsigned int k = 0; k < tags.size(); ++k) {
0047 for (unsigned int m = 0; m < placementIndex.size(); ++m) {
0048 edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags[k] << " Partial " << partialTypes[k]
0049 << " Placement Index " << placementIndex[m] << " Tag " << placementIndexTags[m];
0050 }
0051 }
0052 #endif
0053 std::vector<std::string> layerNames = args.value<std::vector<std::string>>("LayerNames");
0054 std::vector<std::string> materials = args.value<std::vector<std::string>>("LayerMaterials");
0055 std::vector<double> layerThick = args.value<std::vector<double>>("LayerThickness");
0056 #ifdef EDM_ML_DEBUG
0057 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << layerNames.size() << " types of volumes";
0058 for (unsigned int i = 0; i < layerNames.size(); ++i)
0059 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames[i] << " of thickness "
0060 << cms::convert2mm(layerThick[i]) << " filled with " << materials[i];
0061 #endif
0062 std::vector<int> layerType = args.value<std::vector<int>>("LayerType");
0063 #ifdef EDM_ML_DEBUG
0064 std::ostringstream st1;
0065 for (unsigned int i = 0; i < layerType.size(); ++i)
0066 st1 << " [" << i << "] " << layerType[i];
0067 edm::LogVerbatim("HGCalGeom") << "There are " << layerType.size() << " blocks" << st1.str();
0068
0069 edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalPassivePartial...";
0070 #endif
0071
0072 static constexpr double tol = 0.00001;
0073
0074
0075 for (unsigned int k = 0; k < tags.size(); ++k) {
0076 for (unsigned int m = 0; m < placementIndex.size(); ++m) {
0077
0078 std::string mother = parentName + placementIndexTags[m] + tags[k];
0079 std::vector<std::pair<double, double>> wxy =
0080 HGCalWaferMask::waferXY(partialTypes[k], placementIndex[m], (waferSize + waferSepar), 0.0, 0.0, 0.0, false);
0081 std::vector<double> xM, yM;
0082 for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0083 xM.emplace_back(wxy[i].first);
0084 yM.emplace_back(wxy[i].second);
0085 }
0086 std::vector<double> zw = {-0.5 * thick, 0.5 * thick};
0087 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0088 dd4hep::Solid solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0089 ns.addSolidNS(ns.prepend(mother), solid);
0090 dd4hep::Material matter = ns.material(material);
0091 dd4hep::Volume glogM = dd4hep::Volume(solid.name(), solid, matter);
0092 ns.addVolumeNS(glogM);
0093 #ifdef EDM_ML_DEBUG
0094 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << solid.name() << " extruded polygon made of "
0095 << matter.name() << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0096 << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0]
0097 << " z|x|y|s (1) " << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1])
0098 << ":" << cms::convert2mm(zy[1]) << ":" << scale[1] << " and " << xM.size()
0099 << " edges";
0100 for (unsigned int kk = 0; kk < xM.size(); ++kk)
0101 edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":"
0102 << cms::convert2mm(yM[kk]);
0103 #endif
0104
0105
0106 std::vector<dd4hep::Volume> glogs(materials.size());
0107 std::vector<int> copyNumber;
0108 copyNumber.resize(materials.size(), 1);
0109 double zi(-0.5 * thick), thickTot(0.0);
0110 for (unsigned int l = 0; l < layerType.size(); l++) {
0111 unsigned int i = layerType[l];
0112 if (copyNumber[i] == 1) {
0113 zw[0] = -0.5 * layerThick[i];
0114 zw[1] = 0.5 * layerThick[i];
0115 std::string layerName = mother + layerNames[i];
0116 solid = dd4hep::ExtrudedPolygon(xM, yM, zw, zx, zy, scale);
0117 ns.addSolidNS(ns.prepend(layerName), solid);
0118 matter = ns.material(materials[i]);
0119 glogs[i] = dd4hep::Volume(solid.name(), solid, matter);
0120 ns.addVolumeNS(glogs[i]);
0121 #ifdef EDM_ML_DEBUG
0122 edm::LogVerbatim("HGCalGeom")
0123 << "DDHGCalPassivePartial: Layer " << i << ":" << l << ":" << solid.name()
0124 << " extruded polygon made of " << matter.name() << " z|x|y|s (0) " << cms::convert2mm(zw[0]) << ":"
0125 << cms::convert2mm(zx[0]) << ":" << cms::convert2mm(zy[0]) << ":" << scale[0] << " z|x|y|s (1) "
0126 << cms::convert2mm(zw[1]) << ":" << cms::convert2mm(zx[1]) << ":" << cms::convert2mm(zy[1]) << ":"
0127 << scale[1] << " and " << xM.size() << " edges";
0128 for (unsigned int kk = 0; kk < xM.size(); ++kk)
0129 edm::LogVerbatim("HGCalGeom")
0130 << "[" << kk << "] " << cms::convert2mm(xM[kk]) << ":" << cms::convert2mm(yM[kk]);
0131 #endif
0132 }
0133 dd4hep::Position tran(0, 0, (zi + 0.5 * layerThick[i]));
0134 glogM.placeVolume(glogs[i], copyNumber[i], tran);
0135 #ifdef EDM_ML_DEBUG
0136 edm::LogVerbatim("HGCalGeom") << "DDHGCalPassivePartial: " << glogs[i].name() << " number " << copyNumber[i]
0137 << " positioned in " << glogM.name() << " at (0, 0, "
0138 << cms::convert2mm(zi + 0.5 * layerThick[i]) << " with no rotation";
0139 #endif
0140 ++copyNumber[i];
0141 zi += layerThick[i];
0142 thickTot += layerThick[i];
0143 }
0144 if ((std::abs(thickTot - thick) >= tol) && (!layerType.empty())) {
0145 if (thickTot > thick) {
0146 edm::LogError("HGCalGeom") << "Thickness of the partition " << thick << " is smaller than " << thickTot
0147 << ": thickness of all its components **** ERROR ****";
0148 } else {
0149 edm::LogWarning("HGCalGeom") << "Thickness of the partition " << thick << " does not match with "
0150 << thickTot << " of the components";
0151 }
0152 }
0153 }
0154 }
0155 }
0156 };
0157
0158 static long algorithm(dd4hep::Detector& , cms::DDParsingContext& ctxt, xml_h e) {
0159 HGCalPassivePartial passivePartialAlgo(ctxt, e);
0160 return cms::s_executed;
0161 }
0162
0163 DECLARE_DDCMS_DETELEMENT(DDCMS_hgcal_DDHGCalPassivePartial, algorithm)