File indexing completed on 2024-05-10 02:20:55
0001
0002
0003
0004
0005
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTypes.h"
0010 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0011 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0012 #include <CLHEP/Units/GlobalPhysicalConstants.h>
0013 #include <CLHEP/Units/SystemOfUnits.h>
0014
0015 #include <string>
0016 #include <vector>
0017
0018 using namespace std;
0019
0020 class DDTrackerPhiAlgo : public DDAlgorithm {
0021 public:
0022
0023 DDTrackerPhiAlgo();
0024 ~DDTrackerPhiAlgo() override;
0025
0026 void initialize(const DDNumericArguments& nArgs,
0027 const DDVectorArguments& vArgs,
0028 const DDMapArguments& mArgs,
0029 const DDStringArguments& sArgs,
0030 const DDStringVectorArguments& vsArgs) override;
0031
0032 void execute(DDCompactView& cpv) override;
0033
0034 private:
0035 double radius;
0036 double tilt;
0037 vector<double> phi;
0038 vector<double> zpos;
0039
0040 string idNameSpace;
0041 string childName;
0042
0043 size_t startcn;
0044 int incrcn;
0045 size_t numcopies;
0046 };
0047
0048 DDTrackerPhiAlgo::DDTrackerPhiAlgo() : startcn(1), incrcn(1) {
0049 LogDebug("TrackerGeom") << "DDTrackerPhiAlgo info: Creating an instance";
0050 }
0051
0052 DDTrackerPhiAlgo::~DDTrackerPhiAlgo() {}
0053
0054 void DDTrackerPhiAlgo::initialize(const DDNumericArguments& nArgs,
0055 const DDVectorArguments& vArgs,
0056 const DDMapArguments&,
0057 const DDStringArguments& sArgs,
0058 const DDStringVectorArguments&) {
0059 if (nArgs.find("StartCopyNo") != nArgs.end()) {
0060 startcn = size_t(nArgs["StartCopyNo"]);
0061 } else {
0062 startcn = 1;
0063 }
0064 if (nArgs.find("IncrCopyNo") != nArgs.end()) {
0065 incrcn = int(nArgs["IncrCopyNo"]);
0066 } else {
0067 incrcn = 1;
0068 }
0069
0070 radius = nArgs["Radius"];
0071 tilt = nArgs["Tilt"];
0072 phi = vArgs["Phi"];
0073 zpos = vArgs["ZPos"];
0074
0075 if (nArgs.find("NumCopies") != nArgs.end()) {
0076 numcopies = size_t(nArgs["NumCopies"]);
0077 if (numcopies != phi.size()) {
0078 edm::LogError("TrackerGeom") << "DDTrackerPhiAlgo error: Parameter "
0079 << "NumCopies does not agree with the size "
0080 << "of the Phi vector. It was adjusted to "
0081 << "be the size of the Phi vector and may "
0082 << "lead to crashes or errors.";
0083 }
0084 } else {
0085 numcopies = phi.size();
0086 }
0087
0088 LogDebug("TrackerGeom") << "DDTrackerPhiAlgo debug: Parameters for position"
0089 << "ing:: "
0090 << " Radius " << radius << " Tilt " << tilt / CLHEP::deg << " Copies " << phi.size() << " at";
0091 for (int i = 0; i < (int)(phi.size()); i++)
0092 LogDebug("TrackerGeom") << "\t[" << i << "] phi = " << phi[i] / CLHEP::deg << " z = " << zpos[i];
0093
0094 idNameSpace = DDCurrentNamespace::ns();
0095 childName = sArgs["ChildName"];
0096 DDName parentName = parent().name();
0097 LogDebug("TrackerGeom") << "DDTrackerPhiAlgo debug: Parent " << parentName << "\tChild " << childName << " NameSpace "
0098 << idNameSpace;
0099 }
0100
0101 void DDTrackerPhiAlgo::execute(DDCompactView& cpv) {
0102 DDName mother = parent().name();
0103 DDName child(DDSplit(childName).first, DDSplit(childName).second);
0104 double theta = 90. * CLHEP::deg;
0105 size_t i = 0;
0106 int ci = startcn;
0107 for (; i < numcopies; ++i) {
0108 double phix = phi[i] + tilt;
0109 double phiy = phix + 90. * CLHEP::deg;
0110 double phideg = phi[i] / CLHEP::deg;
0111
0112 string rotstr = DDSplit(childName).first + to_string(phideg);
0113 DDRotation rotation = DDRotation(DDName(rotstr, idNameSpace));
0114 if (!rotation) {
0115 LogDebug("TrackerGeom") << "DDTrackerPhiAlgo test: Creating a new "
0116 << "rotation: " << rotstr << "\t"
0117 << "90., " << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 0, 0";
0118 rotation = DDrot(DDName(rotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
0119 }
0120
0121 double xpos = radius * cos(phi[i]);
0122 double ypos = radius * sin(phi[i]);
0123 DDTranslation tran(xpos, ypos, zpos[i]);
0124
0125 cpv.position(child, mother, ci, tran, rotation);
0126 LogDebug("TrackerGeom") << "DDTrackerPhiAlgo test: " << child << " number " << ci << " positioned in " << mother
0127 << " at " << tran << " with " << rotation;
0128 ci = ci + incrcn;
0129 }
0130 }
0131
0132 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerPhiAlgo, "track:DDTrackerPhiAlgo");