File indexing completed on 2024-04-06 12:15:14
0001 #include "DetectorDescription/Core/interface/DDAlgorithm.h"
0002 #include "DetectorDescription/Core/interface/DDAlgorithmFactory.h"
0003 #include "DetectorDescription/Core/interface/DDCompactView.h"
0004 #include "DetectorDescription/Core/interface/DDCurrentNamespace.h"
0005 #include "DetectorDescription/Core/interface/DDLogicalPart.h"
0006 #include "DetectorDescription/Core/interface/DDName.h"
0007 #include "DetectorDescription/Core/interface/DDRotationMatrix.h"
0008 #include "DetectorDescription/Core/interface/DDSplit.h"
0009 #include "DetectorDescription/Core/interface/DDTransform.h"
0010 #include "DetectorDescription/Core/interface/DDTranslation.h"
0011 #include "DetectorDescription/Core/interface/DDTypes.h"
0012 #include "DataFormats/Math/interface/GeantUnits.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "FWCore/PluginManager/interface/PluginFactory.h"
0015
0016 #include <cmath>
0017 #include <memory>
0018
0019 using namespace geant_units::operators;
0020 using namespace angle_units::operators;
0021
0022 class DDMTDLinear : public DDAlgorithm {
0023 public:
0024 DDMTDLinear()
0025 : m_n(1), m_startCopyNo(1), m_incrCopyNo(1), m_theta(0.), m_phi(0.), m_delta(0.), m_phi_obj(0.), m_theta_obj(0.) {}
0026
0027 void initialize(const DDNumericArguments& nArgs,
0028 const DDVectorArguments& vArgs,
0029 const DDMapArguments& mArgs,
0030 const DDStringArguments& sArgs,
0031 const DDStringVectorArguments& vsArgs) override;
0032
0033 void execute(DDCompactView& cpv) override;
0034
0035 private:
0036 int m_n;
0037 int m_startCopyNo;
0038 int m_incrCopyNo;
0039 double m_theta;
0040 double m_phi;
0041 double m_delta;
0042 double m_phi_obj;
0043 double m_theta_obj;
0044 std::vector<double> m_base;
0045
0046 std::pair<std::string, std::string> m_childNmNs;
0047
0048 };
0049
0050 void DDMTDLinear::initialize(const DDNumericArguments& nArgs,
0051 const DDVectorArguments& vArgs,
0052 const DDMapArguments&,
0053 const DDStringArguments& sArgs,
0054 const DDStringVectorArguments&) {
0055 m_n = int(nArgs["N"]);
0056 m_startCopyNo = int(nArgs["StartCopyNo"]);
0057 m_incrCopyNo = int(nArgs["IncrCopyNo"]);
0058 m_theta = nArgs["Theta"];
0059 m_phi = nArgs["Phi"];
0060 m_delta = nArgs["Delta"];
0061 m_base = vArgs["Base"];
0062 m_phi_obj = nArgs["Phi_obj"];
0063 m_theta_obj = nArgs["Theta_obj"];
0064
0065 LogDebug("DDAlgorithm") << "DDMTDLinear: Parameters for position"
0066 << "ing:: n " << m_n << " Direction Theta, Phi, Offset, Delta " << convertRadToDeg(m_theta)
0067 << " " << convertRadToDeg(m_phi) << " "
0068 << " " << convertRadToDeg(m_delta) << " Base " << m_base[0] << ", " << m_base[1] << ", "
0069 << m_base[2] << "Objects placement Phi_obj, Theta_obj " << convertRadToDeg(m_phi_obj) << " "
0070 << convertRadToDeg(m_theta_obj);
0071
0072 m_childNmNs = DDSplit(sArgs["ChildName"]);
0073 if (m_childNmNs.second.empty())
0074 m_childNmNs.second = DDCurrentNamespace::ns();
0075
0076 DDName parentName = parent().name();
0077 LogDebug("DDAlgorithm") << "DDMTDLinear: Parent " << parentName << "\tChild " << m_childNmNs.first << " NameSpace "
0078 << m_childNmNs.second;
0079 }
0080
0081 void DDMTDLinear::execute(DDCompactView& cpv) {
0082 DDName mother = parent().name();
0083 DDName ddname(m_childNmNs.first, m_childNmNs.second);
0084 int copy = m_startCopyNo;
0085
0086 DDTranslation direction(sin(m_theta) * cos(m_phi), sin(m_theta) * sin(m_phi), cos(m_theta));
0087
0088 DDTranslation basetr(m_base[0], m_base[1], m_base[2]);
0089
0090
0091 double thetaZ = m_theta_obj - 0.5_pi;
0092 double phiZ = m_phi_obj;
0093 double thetaX = m_theta_obj;
0094 double thetaY = m_theta_obj;
0095 double phiX = m_phi_obj;
0096 double phiY = m_phi_obj + 0.5_pi;
0097
0098 DDRotation rotation = DDRotation("Rotation");
0099
0100 if (!rotation) {
0101 LogDebug("DDAlgorithm") << "DDMTDLinear: Creating a new "
0102 << "rotation for " << ddname;
0103
0104 rotation = DDrot("Rotation", DDcreateRotationMatrix(thetaX, phiX, thetaY, phiY, thetaZ, phiZ));
0105 }
0106
0107 for (int i = 0; i < m_n; ++i) {
0108 DDTranslation tran = basetr + (double(i) * m_delta) * direction;
0109 cpv.position(ddname, mother, copy, tran, rotation);
0110 LogDebug("DDAlgorithm") << "DDMTDLinear: " << m_childNmNs.second << ":" << m_childNmNs.first << " number " << copy
0111 << " positioned in " << mother << " at " << tran << " with " << rotation;
0112 copy += m_incrCopyNo;
0113 }
0114 }
0115
0116 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDMTDLinear, "mtd:DDMTDLinear");