File indexing completed on 2023-10-25 09:50:01
0001
0002
0003
0004
0005
0006 #include <cmath>
0007 #include <algorithm>
0008 #include <map>
0009 #include <string>
0010 #include <vector>
0011
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/PluginManager/interface/PluginFactory.h"
0014 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0015 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0016 #include "DataFormats/Math/interface/angle_units.h"
0017 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0018 #include "DetectorDescription/Core/interface/DDTypes.h"
0019 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0020
0021
0022
0023 using namespace angle_units::operators;
0024
0025 class DDGEMAngular : public DDAlgorithm {
0026 public:
0027
0028 DDGEMAngular();
0029 ~DDGEMAngular() override;
0030
0031 void initialize(const DDNumericArguments& nArgs,
0032 const DDVectorArguments& vArgs,
0033 const DDMapArguments& mArgs,
0034 const DDStringArguments& sArgs,
0035 const DDStringVectorArguments& vsArgs) override;
0036
0037 void execute(DDCompactView& cpv) override;
0038
0039 private:
0040 double startAngle;
0041 double stepAngle;
0042 int invert;
0043 double rPos;
0044 double zoffset;
0045 int n;
0046 int startCopyNo;
0047 int incrCopyNo;
0048
0049 std::string rotns;
0050 std::string idNameSpace;
0051 std::string childName;
0052 };
0053
0054 DDGEMAngular::DDGEMAngular() {
0055 #ifdef EDM_ML_DEBUG
0056 edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Creating an instance";
0057 #endif
0058 }
0059
0060 DDGEMAngular::~DDGEMAngular() {}
0061
0062 void DDGEMAngular::initialize(const DDNumericArguments& nArgs,
0063 const DDVectorArguments&,
0064 const DDMapArguments&,
0065 const DDStringArguments& sArgs,
0066 const DDStringVectorArguments&) {
0067 startAngle = nArgs["startAngle"];
0068 stepAngle = nArgs["stepAngle"];
0069 invert = int(nArgs["invert"]);
0070 rPos = nArgs["rPosition"];
0071 zoffset = nArgs["zoffset"];
0072 n = int(nArgs["n"]);
0073 startCopyNo = int(nArgs["startCopyNo"]);
0074 incrCopyNo = int(nArgs["incrCopyNo"]);
0075 #ifdef EDM_ML_DEBUG
0076 edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parameters for positioning-- " << n << " copies in steps of "
0077 << convertRadToDeg(stepAngle) << " from " << convertRadToDeg(startAngle)
0078 << " (inversion flag " << invert << ") \trPos " << rPos << " Zoffest " << zoffset
0079 << "\tStart and inremental "
0080 << "copy nos " << startCopyNo << ", " << incrCopyNo;
0081 #endif
0082
0083 rotns = sArgs["RotNameSpace"];
0084 idNameSpace = DDCurrentNamespace::ns();
0085 childName = sArgs["ChildName"];
0086 #ifdef EDM_ML_DEBUG
0087 edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parent " << parent().name() << "\tChild " << childName
0088 << "\tNameSpace " << idNameSpace << "\tRotation Namespace " << rotns;
0089 #endif
0090 }
0091
0092 void DDGEMAngular::execute(DDCompactView& cpv) {
0093 double phi = startAngle;
0094 int copyNo = startCopyNo;
0095
0096 for (int ii = 0; ii < n; ii++) {
0097 double phitmp = phi;
0098 if (phitmp >= 2._pi)
0099 phitmp -= 2._pi;
0100 DDRotation rotation;
0101 std::string rotstr("RG");
0102
0103 if (invert > 0)
0104 rotstr += "I";
0105 rotstr += formatAsDegrees(phitmp);
0106 rotation = DDRotation(DDName(rotstr, rotns));
0107 if (!rotation) {
0108 double thetax = 90.0_deg;
0109 double phix = invert == 0 ? (90.0_deg + phitmp) : (-90.0_deg + phitmp);
0110 double thetay = invert == 0 ? 0.0 : 180.0_deg;
0111 double phiz = phitmp;
0112 #ifdef EDM_ML_DEBUG
0113 edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Creating a new rotation " << DDName(rotstr, idNameSpace) << "\t "
0114 << convertRadToDeg(thetax) << ", " << convertRadToDeg(phix) << ", "
0115 << convertRadToDeg(thetay) << ", 0, " << convertRadToDeg(thetax) << ", "
0116 << convertRadToDeg(phiz);
0117 #endif
0118 rotation = DDrot(DDName(rotstr, rotns), thetax, phix, thetay, 0., thetax, phiz);
0119 }
0120
0121 DDTranslation tran(rPos * cos(phitmp), rPos * sin(phitmp), zoffset);
0122
0123 DDName parentName = parent().name();
0124 cpv.position(DDName(childName, idNameSpace), parentName, copyNo, tran, rotation);
0125 #ifdef EDM_ML_DEBUG
0126 edm::LogVerbatim("MuonGeom") << "DDGEMAngular: " << DDName(childName, idNameSpace) << " number " << copyNo
0127 << " positioned in " << parentName << " at " << tran << " with " << rotstr << " "
0128 << rotation;
0129 #endif
0130 phi += stepAngle;
0131 copyNo += incrCopyNo;
0132 }
0133 }
0134
0135 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDGEMAngular, "muon:DDGEMAngular");