File indexing completed on 2023-03-17 11:05:22
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 "CLHEP/Units/GlobalPhysicalConstants.h"
0016 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0017
0018 #include <string>
0019 #include <vector>
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
0052 using namespace std;
0053
0054 class DDTrackerRingAlgo : public DDAlgorithm {
0055 public:
0056
0057 DDTrackerRingAlgo();
0058 ~DDTrackerRingAlgo() 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 bool isZPlus;
0077 double tiltAngle;
0078 bool isFlipped;
0079 double delta;
0080
0081 string idNameSpace;
0082 string childName;
0083 };
0084
0085 DDTrackerRingAlgo::DDTrackerRingAlgo() { LogDebug("TrackerGeom") << "DDTrackerRingAlgo info: Creating an instance"; }
0086
0087 DDTrackerRingAlgo::~DDTrackerRingAlgo() {}
0088
0089 void DDTrackerRingAlgo::initialize(const DDNumericArguments& nArgs,
0090 const DDVectorArguments& vArgs,
0091 const DDMapArguments&,
0092 const DDStringArguments& sArgs,
0093 const DDStringVectorArguments&) {
0094 n = int(nArgs["N"]);
0095 startCopyNo = int(nArgs["StartCopyNo"]);
0096 incrCopyNo = int(nArgs["IncrCopyNo"]);
0097 rangeAngle = nArgs["RangeAngle"];
0098 startAngle = nArgs["StartAngle"];
0099 radius = nArgs["Radius"];
0100 center = vArgs["Center"];
0101 isZPlus = bool(nArgs["IsZPlus"]);
0102 tiltAngle = nArgs["TiltAngle"];
0103 isFlipped = bool(nArgs["IsFlipped"]);
0104
0105 if (fabs(rangeAngle - 360.0 * CLHEP::deg) < 0.001 * CLHEP::deg) {
0106 delta = rangeAngle / double(n);
0107 } else {
0108 if (n > 1) {
0109 delta = rangeAngle / double(n - 1);
0110 } else {
0111 delta = 0.;
0112 }
0113 }
0114
0115 LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
0116 << "ing:: n " << n << " Start, Range, Delta " << startAngle / CLHEP::deg << " "
0117 << rangeAngle / CLHEP::deg << " " << delta / CLHEP::deg << " Radius " << radius << " Centre "
0118 << center[0] << ", " << center[1] << ", " << center[2];
0119
0120 idNameSpace = DDCurrentNamespace::ns();
0121 childName = sArgs["ChildName"];
0122
0123 DDName parentName = parent().name();
0124 LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName << "\tChild " << childName
0125 << " NameSpace " << idNameSpace;
0126 }
0127
0128 void DDTrackerRingAlgo::execute(DDCompactView& cpv) {
0129 DDRotation flipRot, tiltRot, phiRot, globalRot;
0130 DDRotationMatrix flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix;
0131 string rotstr = "RTrackerRingAlgo";
0132
0133
0134 if (isFlipped) {
0135 string flipRotstr = rotstr + "Flip";
0136 flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
0137 if (!flipRot) {
0138 LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << flipRotstr << "\t90., 180., "
0139 << "90., 90., "
0140 << "180., 0.";
0141 flipRot = DDrot(DDName(flipRotstr, idNameSpace),
0142 90. * CLHEP::deg,
0143 180. * CLHEP::deg,
0144 90. * CLHEP::deg,
0145 90. * CLHEP::deg,
0146 180. * CLHEP::deg,
0147 0.);
0148 }
0149 flipMatrix = flipRot.matrix();
0150 }
0151
0152 if (isZPlus) {
0153 string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZPlus";
0154 tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0155 if (!tiltRot) {
0156 LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
0157 << tiltAngle / CLHEP::deg << ", 180., " << 90. - tiltAngle / CLHEP::deg << ", 0.";
0158 tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
0159 90. * CLHEP::deg,
0160 90. * CLHEP::deg,
0161 tiltAngle,
0162 180. * CLHEP::deg,
0163 90. * CLHEP::deg - tiltAngle,
0164 0.);
0165 }
0166 tiltMatrix = tiltRot.matrix();
0167 if (isFlipped) {
0168 tiltMatrix *= flipMatrix;
0169 }
0170 } else {
0171 string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZMinus";
0172 tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
0173 if (!tiltRot) {
0174 LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
0175 << tiltAngle / CLHEP::deg << ", 0., " << 90. + tiltAngle / CLHEP::deg << ", 0.";
0176 tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
0177 90. * CLHEP::deg,
0178 90. * CLHEP::deg,
0179 tiltAngle,
0180 0.,
0181 90. * CLHEP::deg + tiltAngle,
0182 0.);
0183 }
0184 tiltMatrix = tiltRot.matrix();
0185 if (isFlipped) {
0186 tiltMatrix *= flipMatrix;
0187 }
0188 }
0189
0190
0191 DDName mother = parent().name();
0192 DDName child(DDSplit(childName).first, DDSplit(childName).second);
0193 double theta = 90. * CLHEP::deg;
0194 int copy = startCopyNo;
0195 double phi = startAngle;
0196
0197 for (int i = 0; i < n; i++) {
0198
0199 double phix = phi;
0200 double phiy = phix + 90. * CLHEP::deg;
0201 double phideg = phix / CLHEP::deg;
0202 if (phideg != 0) {
0203 string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
0204 phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
0205 if (!phiRot) {
0206 LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << phiRotstr << "\t90., "
0207 << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 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(tiltAngle / CLHEP::deg);
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") << "DDTrackerRingAlgo test: Creating a new "
0229 << "rotation: " << globalRotstr;
0230 globalRotMatrix = phiRotMatrix * tiltMatrix;
0231 globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
0232 }
0233
0234
0235 double xpos = radius * cos(phi) + center[0];
0236 double ypos = radius * sin(phi) + 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") << "DDTrackerRingAlgo test " << child << " number " << copy << " positioned in " << mother
0243 << " at " << tran << " with " << globalRot;
0244
0245 copy += incrCopyNo;
0246 phi += delta;
0247 }
0248 }
0249
0250 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerRingAlgo, "track:DDTrackerRingAlgo");