File indexing completed on 2024-04-06 12:14:59
0001 #include <algorithm>
0002 #include <cmath>
0003 #include <string>
0004 #include <vector>
0005
0006 #include "DataFormats/Math/interface/angle_units.h"
0007 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0008 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0009 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0010 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0011 #include "DetectorDescription/Core/interface/DDMaterial.h"
0012 #include "DetectorDescription/Core/interface/DDSolid.h"
0013 #include "DetectorDescription/Core/interface/DDSplit.h"
0014 #include "DetectorDescription/Core/interface/DDTypes.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016 #include "FWCore/PluginManager/interface/PluginFactory.h"
0017
0018
0019 using namespace angle_units::operators;
0020
0021 class DDHGCalNoTaperEndcap : public DDAlgorithm {
0022 public:
0023 DDHGCalNoTaperEndcap(void);
0024
0025 void initialize(const DDNumericArguments& nArgs,
0026 const DDVectorArguments& vArgs,
0027 const DDMapArguments& mArgs,
0028 const DDStringArguments& sArgs,
0029 const DDStringVectorArguments& vsArgs) override;
0030
0031 void execute(DDCompactView& cpv) override;
0032
0033 private:
0034 int createQuarter(DDCompactView& cpv, int xQuadrant, int yQuadrant, int startCopyNo);
0035
0036 double m_startAngle;
0037 double m_tiltAngle;
0038 int m_invert;
0039 double m_rMin;
0040 double m_rMax;
0041 double m_zoffset;
0042 double m_xyoffset;
0043 int m_n;
0044 int m_startCopyNo;
0045 int m_incrCopyNo;
0046 std::string m_childName;
0047 std::string m_idNameSpace;
0048 };
0049
0050 DDHGCalNoTaperEndcap::DDHGCalNoTaperEndcap() {
0051 edm::LogVerbatim("HGCalGeom") << "DDHGCalNoTaperEndcap test: Creating an instance";
0052 }
0053
0054 void DDHGCalNoTaperEndcap::initialize(const DDNumericArguments& nArgs,
0055 const DDVectorArguments& vArgs,
0056 const DDMapArguments&,
0057 const DDStringArguments& sArgs,
0058 const DDStringVectorArguments&) {
0059 m_tiltAngle = nArgs["tiltAngle"];
0060 m_invert = int(nArgs["invert"]);
0061 m_rMin = int(nArgs["rMin"]);
0062 m_rMax = int(nArgs["rMax"]);
0063 m_zoffset = nArgs["zoffset"];
0064 m_xyoffset = nArgs["xyoffset"];
0065 m_n = int(nArgs["n"]);
0066 m_startCopyNo = int(nArgs["startCopyNo"]);
0067 m_incrCopyNo = int(nArgs["incrCopyNo"]);
0068 m_childName = sArgs["ChildName"];
0069 #ifdef EDM_ML_DEBUG
0070 edm::LogVerbatim("HGCalGeom") << "Tilt Angle " << m_tiltAngle << " Invert " << m_invert << " R " << m_rMin << ":"
0071 << m_rMax << " Offset " << m_zoffset << ":" << m_xyoffset << " N " << m_n << " Copy "
0072 << m_startCopyNo << ":" << m_incrCopyNo << " Child " << m_childName;
0073 #endif
0074
0075 m_idNameSpace = DDCurrentNamespace::ns();
0076 #ifdef EDM_ML_DEBUG
0077 edm::LogVerbatim("HGCalGeom") << "DDHGCalNoTaperEndcap: NameSpace " << m_idNameSpace << "\tParent "
0078 << parent().name();
0079 #endif
0080 }
0081
0082 void DDHGCalNoTaperEndcap::execute(DDCompactView& cpv) {
0083 int lastCopyNo = m_startCopyNo;
0084 #ifdef EDM_ML_DEBUG
0085 edm::LogVerbatim("HGCalGeom") << "Create quarter 1:1";
0086 #endif
0087 lastCopyNo = createQuarter(cpv, 1, 1, lastCopyNo);
0088 #ifdef EDM_ML_DEBUG
0089 edm::LogVerbatim("HGCalGeom") << "Create quarter -1:1";
0090 #endif
0091 lastCopyNo = createQuarter(cpv, -1, 1, lastCopyNo);
0092 #ifdef EDM_ML_DEBUG
0093 edm::LogVerbatim("HGCalGeom") << "Create quarter -1:-1";
0094 #endif
0095 lastCopyNo = createQuarter(cpv, -1, -1, lastCopyNo);
0096 #ifdef EDM_ML_DEBUG
0097 edm::LogVerbatim("HGCalGeom") << "Create quarter 1:-1";
0098 #endif
0099 createQuarter(cpv, 1, -1, lastCopyNo);
0100 }
0101
0102 int DDHGCalNoTaperEndcap::createQuarter(DDCompactView& cpv, int xQuadrant, int yQuadrant, int startCopyNo) {
0103 int copyNo = startCopyNo;
0104 double tiltAngle = m_tiltAngle;
0105 double xphi = xQuadrant * tiltAngle;
0106 double yphi = yQuadrant * tiltAngle;
0107 double theta = 90._deg;
0108 double phiX = 0.0;
0109 double phiY = theta;
0110 double phiZ = 3 * theta;
0111 double offsetZ = m_zoffset;
0112 double offsetXY = m_xyoffset;
0113
0114 double offsetX = xQuadrant * 0.5 * offsetXY;
0115 double offsetY = yQuadrant * 0.5 * offsetXY;
0116
0117 #ifdef EDM_ML_DEBUG
0118 int rowmax(0), column(0);
0119 #endif
0120 while (std::abs(offsetX) < m_rMax) {
0121 #ifdef EDM_ML_DEBUG
0122 column++;
0123 int row(0);
0124 #endif
0125 while (std::abs(offsetY) < m_rMax) {
0126 #ifdef EDM_ML_DEBUG
0127 row++;
0128 #endif
0129 double limit1 = sqrt((offsetX + 0.5 * xQuadrant * offsetXY) * (offsetX + 0.5 * xQuadrant * offsetXY) +
0130 (offsetY + 0.5 * yQuadrant * offsetXY) * (offsetY + 0.5 * yQuadrant * offsetXY));
0131 double limit2 = sqrt((offsetX - 0.5 * xQuadrant * offsetXY) * (offsetX - 0.5 * xQuadrant * offsetXY) +
0132 (offsetY - 0.5 * yQuadrant * offsetXY) * (offsetY - 0.5 * yQuadrant * offsetXY));
0133
0134 if (limit2 > m_rMin && limit1 < m_rMax) {
0135 #ifdef EDM_ML_DEBUG
0136 edm::LogVerbatim("HGCalGeom") << m_childName << " copyNo = " << copyNo << " (" << column << "," << row
0137 << "): offsetX,Y = " << offsetX << "," << offsetY << " limit=" << limit1 << ":"
0138 << limit2 << " rMin, rMax = " << m_rMin << "," << m_rMax;
0139 #endif
0140 DDRotation rotation;
0141 std::string rotstr("NULL");
0142
0143
0144 rotstr = "R";
0145 rotstr += std::to_string(copyNo);
0146 rotation = DDRotation(DDName(rotstr));
0147 if (!rotation) {
0148 rotation = DDrot(DDName(rotstr, m_idNameSpace),
0149 std::make_unique<DDRotationMatrix>(
0150 *DDcreateRotationMatrix(theta, phiX, theta + yphi, phiY, -yphi, phiZ) *
0151 (*DDcreateRotationMatrix(theta + xphi, phiX, 90._deg, 90._deg, xphi, 0.0))));
0152 }
0153
0154 DDTranslation tran(offsetX, offsetY, offsetZ);
0155 #ifdef EDM_ML_DEBUG
0156 edm::LogVerbatim("HGCalGeom") << "Module " << copyNo << ": location = " << tran << " Rotation " << rotation;
0157 #endif
0158 DDName parentName = parent().name();
0159 cpv.position(DDName(m_childName), parentName, copyNo, tran, rotation);
0160
0161 copyNo += m_incrCopyNo;
0162 } else {
0163 #ifdef EDM_ML_DEBUG
0164 edm::LogVerbatim("HGCalGeom") << " (" << column << "," << row << "): offsetX,Y = " << offsetX << "," << offsetY
0165 << " is out of limit=" << limit1 << ":" << limit2 << " rMin, rMax = " << m_rMin
0166 << "," << m_rMax;
0167 #endif
0168 }
0169
0170 yphi += yQuadrant * 2. * tiltAngle;
0171 offsetY += yQuadrant * offsetXY;
0172 }
0173 #ifdef EDM_ML_DEBUG
0174 if (row > rowmax)
0175 rowmax = row;
0176 #endif
0177 xphi += xQuadrant * 2. * tiltAngle;
0178 yphi = yQuadrant * tiltAngle;
0179 offsetY = yQuadrant * 0.5 * offsetXY;
0180 offsetX += xQuadrant * offsetXY;
0181 }
0182 #ifdef EDM_ML_DEBUG
0183 edm::LogVerbatim("HGCalGeom") << rowmax << " rows and " << column << " columns in quadrant " << xQuadrant << ":"
0184 << yQuadrant;
0185 #endif
0186 return copyNo;
0187 }
0188
0189 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDHGCalNoTaperEndcap, "hgcal:DDHGCalNoTaperEndcap");