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