File indexing completed on 2023-03-17 13:03:28
0001
0002
0003
0004
0005
0006 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0007 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0008 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0009 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0010 #include "DetectorDescription/Core/interface/DDMaterial.h"
0011 #include "DetectorDescription/Core/interface/DDSolid.h"
0012 #include "DetectorDescription/Core/interface/DDSplit.h"
0013 #include "DetectorDescription/Core/interface/DDTypes.h"
0014 #include "DetectorDescription/Core/interface/DDutils.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/PluginManager/interface/PluginFactory.h"
0017 #include "Geometry/HGCalCommonData/interface/HGCalTypes.h"
0018 #include "Geometry/HGCalCommonData/interface/HGCalCell.h"
0019
0020 #include <string>
0021 #include <vector>
0022 #include <sstream>
0023
0024
0025
0026 class DDHGCalWaferFullRotated : public DDAlgorithm {
0027 public:
0028
0029 DDHGCalWaferFullRotated();
0030 ~DDHGCalWaferFullRotated() override = default;
0031
0032 void initialize(const DDNumericArguments& nArgs,
0033 const DDVectorArguments& vArgs,
0034 const DDMapArguments& mArgs,
0035 const DDStringArguments& sArgs,
0036 const DDStringVectorArguments& vsArgs) override;
0037 void execute(DDCompactView& cpv) override;
0038
0039 private:
0040 std::string material_;
0041 std::string waferTag_;
0042 double thick_;
0043 double waferSize_;
0044 double waferSepar_;
0045 double waferThick_;
0046 std::vector<std::string> layerNames_;
0047 std::vector<std::string> materials_;
0048 std::vector<std::string> tag_;
0049 std::vector<double> layerThick_;
0050 std::vector<double> layerSizeOff_;
0051 std::vector<int> layerType_;
0052 std::vector<int> copyNumber_;
0053 std::vector<int> layers_;
0054 std::vector<int> orient_;
0055 std::vector<int> face_;
0056 int nCells_;
0057 int cellType_;
0058 std::vector<int> cellOffset_;
0059 std::vector<std::string> cellNames_;
0060 std::string nameSpace_;
0061 };
0062
0063 DDHGCalWaferFullRotated::DDHGCalWaferFullRotated() {
0064 #ifdef EDM_ML_DEBUG
0065 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Creating an instance";
0066 #endif
0067 }
0068
0069 void DDHGCalWaferFullRotated::initialize(const DDNumericArguments& nArgs,
0070 const DDVectorArguments& vArgs,
0071 const DDMapArguments&,
0072 const DDStringArguments& sArgs,
0073 const DDStringVectorArguments& vsArgs) {
0074 material_ = sArgs["ModuleMaterial"];
0075 thick_ = nArgs["ModuleThickness"];
0076 waferSize_ = nArgs["WaferSize"];
0077 waferSepar_ = nArgs["SensorSeparation"];
0078 waferThick_ = nArgs["WaferThickness"];
0079 waferTag_ = sArgs["WaferTag"];
0080 #ifdef EDM_ML_DEBUG
0081 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Module " << parent().name() << " made of " << material_
0082 << " T " << thick_ << " Wafer 2r " << waferSize_ << " Half Separation " << waferSepar_
0083 << " T " << waferThick_;
0084 #endif
0085 orient_ = dbl_to_int(vArgs["WaferOrient"]);
0086 face_ = dbl_to_int(vArgs["WaferFace"]);
0087 tag_ = vsArgs["WaferPlacementIndex"];
0088 layerNames_ = vsArgs["LayerNames"];
0089 materials_ = vsArgs["LayerMaterials"];
0090 layerThick_ = vArgs["LayerThickness"];
0091 layerSizeOff_ = vArgs["LayerSizeOffset"];
0092 layerType_ = dbl_to_int(vArgs["LayerTypes"]);
0093 copyNumber_.resize(materials_.size(), 1);
0094 #ifdef EDM_ML_DEBUG
0095 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << 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 nCells_ = static_cast<int>(nArgs["NCells"]);
0109 if (nCells_ > 0) {
0110 cellType_ = static_cast<int>(nArgs["CellType"]);
0111 cellNames_ = vsArgs["CellNames"];
0112 cellOffset_ = dbl_to_int(vArgs["CellOffset"]);
0113 } else {
0114 cellType_ = -1;
0115 }
0116 nameSpace_ = DDCurrentNamespace::ns();
0117 #ifdef EDM_ML_DEBUG
0118 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cells/Wafer " << nCells_ << " Cell Type " << cellType_
0119 << " NameSpace " << nameSpace_ << ": # of cells " << cellNames_.size();
0120 std::ostringstream st2;
0121 for (unsigned int i = 0; i < cellOffset_.size(); ++i)
0122 st2 << " [" << i << "] " << cellOffset_[i];
0123 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << cellOffset_.size() << " types of cells with offsets "
0124 << st2.str();
0125 for (unsigned int k = 0; k < cellNames_.size(); ++k)
0126 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Cell[" << k << "] " << cellNames_[k];
0127 #endif
0128 }
0129
0130 void DDHGCalWaferFullRotated::execute(DDCompactView& cpv) {
0131 #ifdef EDM_ML_DEBUG
0132 edm::LogVerbatim("HGCalGeom") << "==>> Executing DDHGCalWaferFullRotated...";
0133 #endif
0134
0135 static constexpr double tol = 0.00001;
0136 static const double sqrt3 = std::sqrt(3.0);
0137 double rM = 0.5 * waferSize_;
0138 double RM2 = rM / sqrt3;
0139 const int nFine(nCells_), nCoarse(nCells_);
0140 HGCalCell wafer(waferSize_, nFine, nCoarse);
0141 for (unsigned int k = 0; k < tag_.size(); ++k) {
0142
0143 std::vector<double> xM = {rM, 0, -rM, -rM, 0, rM};
0144 std::vector<double> yM = {RM2, 2 * RM2, RM2, -RM2, -2 * RM2, -RM2};
0145 std::vector<double> zw = {-0.5 * thick_, 0.5 * thick_};
0146 std::vector<double> zx(2, 0), zy(2, 0), scale(2, 1.0);
0147 std::string parentName = parent().name().name();
0148 parentName = parentName + tag_[k] + waferTag_;
0149 DDSolid solid = DDSolidFactory::extrudedpolygon(parentName, xM, yM, zw, zx, zy, scale);
0150 DDName matName(DDSplit(material_).first, DDSplit(material_).second);
0151 DDMaterial matter(matName);
0152 DDLogicalPart glogM = DDLogicalPart(solid.ddname(), matter, solid);
0153 #ifdef EDM_ML_DEBUG
0154 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0155 << matName << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0156 << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0157 << scale[1] << " and " << xM.size() << " edges";
0158 for (unsigned int kk = 0; kk < xM.size(); ++kk)
0159 edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xM[kk] << ":" << yM[kk];
0160 #endif
0161
0162
0163 std::vector<DDLogicalPart> glogs(materials_.size());
0164 for (unsigned int ii = 0; ii < copyNumber_.size(); ii++) {
0165 copyNumber_[ii] = 1;
0166 }
0167 double zi(-0.5 * thick_), thickTot(0.0);
0168 for (unsigned int l = 0; l < layers_.size(); l++) {
0169 unsigned int i = layers_[l];
0170 double r2 = 0.5 * (waferSize_ - layerSizeOff_[i]);
0171 double R2 = r2 / sqrt3;
0172 std::vector<double> xL = {r2, 0, -r2, -r2, 0, r2};
0173 std::vector<double> yL = {R2, 2 * R2, R2, -R2, -2 * R2, -R2};
0174 if (copyNumber_[i] == 1) {
0175 if (layerType_[i] > 0) {
0176 zw[0] = -0.5 * waferThick_;
0177 zw[1] = 0.5 * waferThick_;
0178 } else {
0179 zw[0] = -0.5 * layerThick_[i];
0180 zw[1] = 0.5 * layerThick_[i];
0181 }
0182 std::string layerName = layerNames_[i] + tag_[k] + waferTag_;
0183 #ifdef EDM_ML_DEBUG
0184 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: Layer " << l << ": " << i << ": " << layerName << " "
0185 << layerSizeOff_[i] << " r " << r2 << ":" << R2;
0186 #endif
0187 solid = DDSolidFactory::extrudedpolygon(layerName, xL, yL, zw, zx, zy, scale);
0188 DDName matN(DDSplit(materials_[i]).first, DDSplit(materials_[i]).second);
0189 DDMaterial matter(matN);
0190 glogs[i] = DDLogicalPart(solid.ddname(), matter, solid);
0191 #ifdef EDM_ML_DEBUG
0192 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << solid.name() << " extruded polygon made of "
0193 << matN << " z|x|y|s (0) " << zw[0] << ":" << zx[0] << ":" << zy[0] << ":"
0194 << scale[0] << " z|x|y|s (1) " << zw[1] << ":" << zx[1] << ":" << zy[1] << ":"
0195 << scale[1] << " and " << xL.size() << " edges";
0196 for (unsigned int kk = 0; kk < xL.size(); ++kk)
0197 edm::LogVerbatim("HGCalGeom") << "[" << kk << "] " << xL[kk] << ":" << yL[kk];
0198 #endif
0199 }
0200 DDTranslation tran0(0, 0, (zi + 0.5 * layerThick_[i]));
0201 DDRotation rot;
0202 cpv.position(glogs[i], glogM, copyNumber_[i], tran0, rot);
0203 #ifdef EDM_ML_DEBUG
0204 edm::LogVerbatim("HGCalGeom") << "DDHGCalWaferFullRotated: " << glogs[i].name() << " number " << copyNumber_[i]
0205 << " positioned in " << glogM.name() << " at " << tran0 << " with no rotation";
0206 #endif
0207 ++copyNumber_[i];
0208 zi += layerThick_[i];
0209 thickTot += layerThick_[i];
0210 if ((layerType_[i] > 0) && (nCells_ > 0)) {
0211 for (int u = 0; u < 2 * nCells_; ++u) {
0212 for (int v = 0; v < 2 * nCells_; ++v) {
0213 if (((v - u) < nCells_) && ((u - v) <= nCells_)) {
0214 int placeIndex = wafer.cellPlacementIndex(1, HGCalTypes::waferFrontBack(face_[k]), orient_[k]);
0215 std::pair<double, double> xy1 = wafer.cellUV2XY1(u, v, placeIndex, cellType_);
0216 double yp = xy1.second;
0217 double xp = xy1.first;
0218 int cell(0);
0219 std::pair<int, int> cell1 = wafer.cellUV2Cell(u, v, placeIndex, cellType_);
0220 cell = cell1.first + cellOffset_[cell1.second];
0221 DDTranslation tran(xp, yp, 0);
0222 int copy = HGCalTypes::packCellTypeUV(cellType_, u, v);
0223 cpv.position(DDName(cellNames_[cell]), glogs[i], copy, tran, rot);
0224 #ifdef EDM_ML_DEBUG
0225 edm::LogVerbatim("HGCalGeom")
0226 << "DDHGCalWaferFullRotated: " << cellNames_[cell] << " number " << copy << " positioned in "
0227 << glogs[i].name() << " at " << tran << " with no rotation";
0228 #endif
0229 }
0230 }
0231 }
0232 }
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 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalWaferFullRotated, "hgcal:DDHGCalWaferFullRotated");