File indexing completed on 2023-04-11 02:04:43
0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0004 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0005 #include "DetectorDescription/Core/interface/DDMaterial.h"
0006 #include "DetectorDescription/Core/interface/DDSolid.h"
0007 #include "DetectorDescription/Core/interface/DDSplit.h"
0008 #include "DetectorDescription/Core/interface/DDTypes.h"
0009 #include "DetectorDescription/Core/interface/DDutils.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "FWCore/PluginManager/interface/PluginFactory.h"
0012 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0013 #include "Geometry/HGCalCommonData/interface/HGCalWaferMask.h"
0014 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0015
0016 #include <string>
0017 #include <vector>
0018 #include <sstream>
0019
0020
0021
0022 class DDHGCalWaferPartialRotated : public DDAlgorithm {
0023 public:
0024
0025 DDHGCalWaferPartialRotated() = default;
0026 ~DDHGCalWaferPartialRotated() override = default;
0027
0028 void initialize(const DDNumericArguments& nArgs,
0029 const DDVectorArguments& vArgs,
0030 const DDMapArguments& mArgs,
0031 const DDStringArguments& sArgs,
0032 const DDStringVectorArguments& vsArgs) override;
0033 void execute(DDCompactView& cpv) override;
0034
0035 private:
0036 std::string material_;
0037 std::string waferTag_;
0038 double thick_;
0039 double waferSize_;
0040 double waferSepar_;
0041 double waferThick_;
0042 std::vector<std::string> tags_;
0043 std::vector<int> partialTypes_;
0044 std::vector<int> placementIndex_;
0045 std::vector<std::string> placementIndexTags_;
0046 std::vector<std::string> layerNames_;
0047 std::vector<std::string> materials_;
0048 std::vector<double> layerThick_;
0049 std::vector<double> layerSizeOff_;
0050 std::vector<int> layerType_;
0051 std::vector<int> layers_;
0052 std::string senseName_;
0053 double senseT_;
0054 int senseType_;
0055 std::string nameSpace_;
0056 };
0057
0058 void DDHGCalWaferPartialRotated::initialize(const DDNumericArguments& nArgs,
0059 const DDVectorArguments& vArgs,
0060 const DDMapArguments&,
0061 const DDStringArguments& sArgs,
0062 const DDStringVectorArguments& vsArgs) {
0063 material_ = sArgs["ModuleMaterial"];
0064 thick_ = nArgs["ModuleThickness"];
0065 waferSize_ = nArgs["WaferSize"];
0066 waferThick_ = nArgs["WaferThickness"];
0067 waferTag_ = sArgs["WaferTag"];
0068 #ifdef EDM_ML_DEBUG
0069 waferSepar_ = nArgs["SensorSeparation"];
0070 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: Module " << parent().name() << " made of " << material_
0071 << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
0072 << " T " << waferThick_;
0073 #endif
0074 tags_ = vsArgs["Tags"];
0075 partialTypes_ = dbl_to_int(vArgs["PartialTypes"]);
0076 placementIndex_ = dbl_to_int(vArgs["PlacementIndex"]);
0077 placementIndexTags_ = vsArgs["PlacementIndexTags"];
0078 #ifdef EDM_ML_DEBUG
0079 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << tags_.size() << " variations of wafer types";
0080 for (unsigned int k = 0; k < tags_.size(); ++k) {
0081 for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0082 edm::LogVerbatim("HGCalGeom") << "Type[" << k << "] " << tags_[k] << " Partial " << partialTypes_[k]
0083 << " Placement Index " << placementIndex_[m] << " Tag " << placementIndexTags_[m];
0084 }
0085 }
0086 #endif
0087 layerNames_ = vsArgs["LayerNames"];
0088 materials_ = vsArgs["LayerMaterials"];
0089 layerThick_ = vArgs["LayerThickness"];
0090 layerSizeOff_ = vArgs["LayerSizeOffset"];
0091 layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0092 #ifdef EDM_ML_DEBUG
0093 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << layerNames_.size() << " types of volumes";
0094 for (unsigned int i = 0; i < layerNames_.size(); ++i)
0095 edm::LogVerbatim("HGCalGeom") << "Volume [" << i << "] " << layerNames_[i] << " of thickness " << layerThick_[i]
0096 << " size offset " << layerSizeOff_[i] << " filled with " << materials_[i] << " type "
0097 << layerType_[i];
0098 #endif
0099 layers_ = dbl_to_int(vArgs["Layers"]);
0100 #ifdef EDM_ML_DEBUG
0101 std::ostringstream st1;
0102 for (unsigned int i = 0; i < layers_.size(); ++i)
0103 st1 << " [" << i << "] " << layers_[i];
0104 edm::LogVerbatim("HGCalGeom") << "There are " << layers_.size() << " blocks" << st1.str();
0105 #endif
0106 senseName_ = sArgs["SenseName"];
0107 senseT_ = nArgs["SenseThick"];
0108 senseType_ = static_cast<int>(nArgs["SenseType"]);
0109 nameSpace_ = DDCurrentNamespace::ns();
0110 #ifdef EDM_ML_DEBUG
0111 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: NameSpace " << nameSpace_ << ": Sensitive Layer Name "
0112 << senseName_ << " Thickness " << senseT_ << " Type " << senseType_;
0113 #endif
0114 }
0115
0116 void DDHGCalWaferPartialRotated::execute(DDCompactView& cpv) {
0117 #ifdef EDM_ML_DEBUG
0118 edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferPartialRotated...";
0119 #endif
0120
0121 static constexpr double tol = 0.00001;
0122 std::string parentName = parent().name().name();
0123
0124
0125 for (unsigned int k = 0; k < tags_.size(); ++k) {
0126 for (unsigned int m = 0; m < placementIndex_.size(); ++m) {
0127
0128 std::string mother = parentName + placementIndexTags_[m] + waferTag_ + tags_[k];
0129 std::vector<std::pair<double, double> > wxy =
0130 HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], waferSize_, 0.0, 0.0, 0.0);
0131 std::vector<double> xM, yM;
0132 for (unsigned int i = 0; i < (wxy.size() - 1); ++i) {
0133 xM.emplace_back(wxy[i].first);
0134 yM.emplace_back(wxy[i].second);
0135 }
0136 std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0137 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0138 DDSolid solid = DDSolidFactory::extrudedpolygon(mother, xM, yM, zw, zx, zy, scale);
0139 DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0140 DDMaterial matter(matName);
0141 DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0142 #ifdef EDM_ML_DEBUG
0143 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of "
0144 << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0145 << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0146 << scale[1] << " partial " << partialTypes_[k] << " placement index "
0147 << placementIndex_[m] << " and " << xM.size() << " edges";
0148 for (unsigned int j = 0; j < xM.size(); ++j)
0149 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xM[j] << ":" << yM[j];
0150 #endif
0151
0152
0153 std::vector<DDLogicalPart> glogs(materials_.size());
0154 std::vector<int> copyNumber(materials_.size(), 1);
0155 double zi(-0.5 * thick_), thickTot(0.0);
0156 for (unsigned int l = 0; l < layers_.size(); l++) {
0157 unsigned int i = layers_[l];
0158 wxy = HGCalWaferMask::waferXY(partialTypes_[k], placementIndex_[m], waferSize_, layerSizeOff_[i], 0.0, 0.0);
0159 std::vector<double> xL, yL;
0160 for (unsigned int i0 = 0; i0 < (wxy.size() - 1); ++i0) {
0161 xL.emplace_back(wxy[i0].first);
0162 yL.emplace_back(wxy[i0].second);
0163 }
0164 #ifdef EDM_ML_DEBUG
0165 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated:Layer " << l << ":" << i << " T " << layerThick_[i]
0166 << " Size offset " << layerSizeOff_[i] << " Copy " << copyNumber[i]
0167 << " Partial type " << partialTypes_[k];
0168 #endif
0169 DDRotation rot;
0170 if (copyNumber[i] == 1) {
0171 if (layerType_[i] > 0) {
0172 zw[0] = -0.5 * waferThick_;
0173 zw[1] = 0.5 * waferThick_;
0174 } else {
0175 zw[0] = -0.5 * layerThick_[i];
0176 zw[1] = 0.5 * layerThick_[i];
0177 }
0178 std::string lname = layerNames_[i] + placementIndexTags_[m] + waferTag_ + tags_[k];
0179 solid = DDSolidFactory::extrudedpolygon(lname, xL, yL, zw, zx, zy, scale);
0180 DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0181 DDMaterial matter(matN);
0182 glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0183 #ifdef EDM_ML_DEBUG
0184 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << solid.name()
0185 << " extruded polygon made of " << matN << " z|x|y|s (0) " << zw[0] << ":"
0186 << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) " << zw[1] << ":"
0187 << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
0188 << " placement index " << placementIndex_[m] << " and " << xL.size()
0189 << " edges";
0190 for (unsigned int j = 0; j < xL.size(); ++j)
0191 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0192 #endif
0193 if ((layerType_[i] > 0) && (senseType_ >= 0)) {
0194 std::string sname = senseName_ + placementIndexTags_[m] + waferTag_ + tags_[k];
0195 zw[0] = -0.5 * senseT_;
0196 zw[1] = 0.5 * senseT_;
0197 solid = DDSolidFactory::extrudedpolygon(sname, xL, yL, zw, zx, zy, scale);
0198 DDLogicalPart glog = DDLogicalPart(solid.ddname(), matter, solid);
0199 #ifdef EDM_ML_DEBUG
0200 edm::LogVerbatim("HGCalGeom")
0201 << "DDHGCalWaferPartialRotated: " << solid.name() << " extruded polygon made of " << matN
0202 << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":" << scale[0] << " z|x|y|s (1) "
0203 << zw[1] << ":" << zx[1] << ":" << zy[1] << ":" << scale[1] << " partial " << partialTypes_[k]
0204 << " placement index " << placementIndex_[m] << " and " << xL.size() << " edges";
0205 for (unsigned int j = 0; j < xL.size(); ++j)
0206 edm::LogVerbatim("HGCalGeom") << "[" << j << "] " << xL[j] << ":" << yL[j];
0207 #endif
0208 auto posSense = HGCalCell::cellOrient(placementIndex_[m]);
0209 double zpos = (posSense.second > 0) ? -0.5 * (waferThick_ - senseT_) : 0.5 * (waferThick_ - senseT_);
0210 DDTranslation tran(0, 0, zpos);
0211 int copy = 10 + senseType_;
0212 cpv.position(glog, glogs[i], copy, tran, rot);
0213 #ifdef EDM_ML_DEBUG
0214 edm::LogVerbatim("HGCalGeom")
0215 << "DDHGCalWaferPartialRotated: " << glog.name() << " number " << copy << " positioned in "
0216 << glogs[i].name() << " at " << tran << " with no rotation";
0217 #endif
0218 }
0219 }
0220 DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0221 cpv.position(glogs[i], glogM, copyNumber[i], tran0, rot);
0222 #ifdef EDM_ML_DEBUG
0223 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferPartialRotated: " << glogs[i].name() << " number "
0224 << copyNumber[i] << " positioned in " << glogM.name() << " at " << tran0
0225 << " with no rotation";
0226 #endif
0227 ++copyNumber[i];
0228 zi += layerThick_[i];
0229 thickTot += layerThick_[i];
0230 }
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 }
0243
0244 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferPartialRotated, "hgcal:DDHGCalWaferPartialRotated");