File indexing completed on 2024-04-06 12:15:25
0001
0002
0003
0004
0005
0006
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0009 #include "DetectorDescription/Core/interface/DDSplit.h"
0010 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0011 #include "DetectorDescription/Core/interface/DDTransform.h"
0012 #include "DetectorDescription/Core/interface/DDTypes.h"
0013 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0014 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0015 #include "DataFormats/Math/interface/angle_units.h"
0016
0017 #include <string>
0018 #include <vector>
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051 using namespace std;
0052 using namespace angle_units::operators;
0053
0054 class DDTrackerIrregularRingAlgo : public DDAlgorithm {
0055 public:
0056
0057 DDTrackerIrregularRingAlgo();
0058 ~DDTrackerIrregularRingAlgo() override;
0059
0060 void initialize(const DDNumericArguments& nArgs,
0061 const DDVectorArguments& vArgs,
0062 const DDMapArguments& mArgs,
0063 const DDStringArguments& sArgs,
0064 const DDStringVectorArguments& vsArgs) override;
0065
0066 void execute(DDCompactView& cpv) override;
0067
0068 private:
0069 int n;
0070 int startCopyNo;
0071 int incrCopyNo;
0072 double rangeAngle;
0073 double startAngle;
0074 double radius;
0075 vector<double> center;
0076 vector<double> phiAngles;
0077 vector<double> radiusValues;
0078 vector<double> yawAngles;
0079 bool isZPlus;
0080 double tiltAngle;
0081 bool isFlipped;
0082
0083 string idNameSpace;
0084 string childName;
0085 };
0086
0087 DDTrackerIrregularRingAlgo::DDTrackerIrregularRingAlgo() {
0088 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo info: Creating an instance";
0089 }
0090
0091 DDTrackerIrregularRingAlgo::~DDTrackerIrregularRingAlgo() = default;
0092
0093 void DDTrackerIrregularRingAlgo::initialize(const DDNumericArguments& nArgs,
0094 const DDVectorArguments& vArgs,
0095 const DDMapArguments&,
0096 const DDStringArguments& sArgs,
0097 const DDStringVectorArguments&) {
0098 n = int(nArgs["N"]);
0099 startCopyNo = int(nArgs["StartCopyNo"]);
0100 incrCopyNo = int(nArgs["IncrCopyNo"]);
0101 rangeAngle = nArgs["RangeAngle"];
0102 startAngle = nArgs["StartAngle"];
0103 radius = nArgs["Radius"];
0104 center = vArgs["Center"];
0105 yawAngles = vArgs["yawAngleValues"];
0106 phiAngles = vArgs["phiAngleValues"];
0107 radiusValues = vArgs["radiusValues"];
0108 isZPlus = bool(nArgs["IsZPlus"]);
0109 tiltAngle = nArgs["TiltAngle"];
0110 isFlipped = bool(nArgs["IsFlipped"]);
0111
0112 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parameters for position"
0113 << "ing:: n " << n << " Start, Range " << convertRadToDeg(startAngle) << " "
0114 << convertRadToDeg(rangeAngle) << " Radius " << radius << " Centre " << center[0] << ", "
0115 << center[1] << ", " << center[2];
0116
0117 idNameSpace = DDCurrentNamespace::ns();
0118 childName = sArgs["ChildName"];
0119
0120 DDName parentName = parent().name();
0121 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parent " << parentName << "\tChild " << childName
0122 << " NameSpace " << idNameSpace;
0123 }
0124
0125 void DDTrackerIrregularRingAlgo::execute(DDCompactView& cpv) {
0126 DDRotation flipRot, tiltRot, phiOwnAxisRot, phiRot, globalRot;
0127 DDRotationMatrix flipMatrix, tiltMatrix, phiOwnAxisRotMatrix, phiRotMatrix, globalRotMatrix;
0128 string rotstr = "RTrackerRingAlgo";
0129
0130
0131 if (isFlipped) {
0132 string flipRotstr = rotstr + "Flip";
0133 flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
0134 if (!flipRot) {
0135 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << flipRotstr
0136 << "\t90., 180., "
0137 << "90., 90., "
0138 << "180., 0.";
0139 flipRot = DDrot(DDName(flipRotstr, idNameSpace), 90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0.);
0140 }
0141 flipMatrix = flipRot.matrix();
0142 }
0143
0144 if (isZPlus) {
0145 string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZPlus";
0146 tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0147 if (!tiltRot) {
0148 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
0149 << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
0150 << 90. - convertRadToDeg(tiltAngle) << ", 0.";
0151 tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0.);
0152 }
0153 tiltMatrix = tiltRot.matrix();
0154 if (isFlipped) {
0155 tiltMatrix *= flipMatrix;
0156 }
0157 } else {
0158 string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZMinus";
0159 tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0160 if (!tiltRot) {
0161 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
0162 << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
0163 << 90. + convertRadToDeg(tiltAngle) << ", 0.";
0164 tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 0., 90._deg + tiltAngle, 0.);
0165 }
0166 tiltMatrix = tiltRot.matrix();
0167 if (isFlipped) {
0168 tiltMatrix *= flipMatrix;
0169 }
0170 }
0171
0172
0173 DDName mother = parent().name();
0174 DDName child(DDSplit(childName).first, DDSplit(childName).second);
0175 double theta = 90._deg;
0176 int copy = startCopyNo;
0177
0178
0179 for (int i = 0; i < n; i++) {
0180
0181
0182
0183 double phix = convertDegToRad(phiAngles.at(i));
0184 double phix_ownaxis = convertDegToRad(yawAngles.at(i));
0185 radius = radiusValues.at(i);
0186 double phiy = phix + 90._deg;
0187 double phiy_ownaxis = phix_ownaxis + 90._deg;
0188 double phideg = convertRadToDeg(phix);
0189 double phideg_ownaxis = convertRadToDeg(phix_ownaxis);
0190 if (phideg_ownaxis != 0) {
0191 string phiOwnAxisRotstr = rotstr + "PhiOwnAxis" + to_string(phideg_ownaxis * 10.);
0192 phiOwnAxisRot = DDRotation(DDName(phiOwnAxisRotstr, idNameSpace));
0193 if (!phiOwnAxisRot) {
0194 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiOwnAxisRotstr
0195 << "\t90., " << convertRadToDeg(phix_ownaxis) << ", 90.,"
0196 << convertRadToDeg(phiy_ownaxis) << ", 0., 0.";
0197 phiOwnAxisRot = DDrot(DDName(phiOwnAxisRotstr, idNameSpace), theta, phix_ownaxis, theta, phiy_ownaxis, 0., 0.);
0198 }
0199 phiOwnAxisRotMatrix = phiOwnAxisRot.matrix();
0200 }
0201 if (phideg != 0) {
0202 string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
0203 phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
0204 if (!phiRot) {
0205 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiRotstr
0206 << "\t90., " << convertRadToDeg(phix) << ", 90.," << convertRadToDeg(phiy)
0207 << ", 0., 0.";
0208 phiRot = DDrot(DDName(phiRotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
0209 }
0210 phiRotMatrix = phiRot.matrix();
0211 }
0212
0213
0214 string globalRotstr = rotstr + "Phi" + to_string(phideg * 10.) + "Tilt" + to_string(convertRadToDeg(tiltAngle));
0215 if (isZPlus) {
0216 globalRotstr += "ZPlus";
0217 if (isFlipped) {
0218 globalRotstr += "Flip";
0219 }
0220 } else {
0221 globalRotstr += "ZMinus";
0222 if (isFlipped) {
0223 globalRotstr += "Flip";
0224 }
0225 }
0226 globalRot = DDRotation(DDName(globalRotstr, idNameSpace));
0227 if (!globalRot) {
0228 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new "
0229 << "rotation: " << globalRotstr;
0230 globalRotMatrix = phiOwnAxisRotMatrix * phiRotMatrix * tiltMatrix;
0231 globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
0232 }
0233
0234
0235 double xpos = radius * cos(phix) + center[0];
0236 double ypos = radius * sin(phix) + center[1];
0237 double zpos = center[2];
0238 DDTranslation tran(xpos, ypos, zpos);
0239
0240
0241 cpv.position(child, mother, copy, tran, globalRot);
0242 LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test " << child << " number " << copy << " positioned in "
0243 << mother << " at " << tran << " with " << globalRot;
0244
0245 copy += incrCopyNo;
0246 }
0247 }
0248
0249 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerIrregularRingAlgo, "track:DDTrackerIrregularRingAlgo");