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