CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDMTDLinear.cc
Go to the documentation of this file.
15 
16 #include <cmath>
17 #include <memory>
18 
19 using namespace geant_units::operators;
20 using namespace angle_units::operators;
21 
22 class DDMTDLinear : public DDAlgorithm {
23 public:
25  : 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.) {}
26 
27  void initialize(const DDNumericArguments& nArgs,
28  const DDVectorArguments& vArgs,
29  const DDMapArguments& mArgs,
30  const DDStringArguments& sArgs,
31  const DDStringVectorArguments& vsArgs) override;
32 
33  void execute(DDCompactView& cpv) override;
34 
35 private:
36  int m_n; //Number of copies
37  int m_startCopyNo; //Start Copy number
38  int m_incrCopyNo; //Increment in Copy number
39  double m_theta; //Theta
40  double m_phi; //Phi dir[Theta,Phi] ... unit-std::vector in direction Theta, Phi
41  double m_delta; //Delta - distance between two subsequent positions along dir[Theta,Phi]
42  double m_phi_obj; //Phi angle to rotate volumes (indipendent from m_phi traslation direction)
43  double m_theta_obj; //Theta angle to rotate volumes
44  std::vector<double> m_base; //Base values - a 3d-point where the offset is calculated from
45  //base is optional, if omitted base=(0,0,0)
46  std::pair<std::string, std::string> m_childNmNs; //Child name
47  //Namespace of the child
48 };
49 
51  const DDVectorArguments& vArgs,
52  const DDMapArguments&,
53  const DDStringArguments& sArgs,
54  const DDStringVectorArguments&) {
55  m_n = int(nArgs["N"]);
56  m_startCopyNo = int(nArgs["StartCopyNo"]);
57  m_incrCopyNo = int(nArgs["IncrCopyNo"]);
58  m_theta = nArgs["Theta"];
59  m_phi = nArgs["Phi"];
60  m_delta = nArgs["Delta"];
61  m_base = vArgs["Base"];
62  m_phi_obj = nArgs["Phi_obj"];
63  m_theta_obj = nArgs["Theta_obj"];
64 
65  LogDebug("DDAlgorithm") << "DDMTDLinear: Parameters for position"
66  << "ing:: n " << m_n << " Direction Theta, Phi, Offset, Delta " << convertRadToDeg(m_theta)
67  << " " << convertRadToDeg(m_phi) << " "
68  << " " << convertRadToDeg(m_delta) << " Base " << m_base[0] << ", " << m_base[1] << ", "
69  << m_base[2] << "Objects placement Phi_obj, Theta_obj " << convertRadToDeg(m_phi_obj) << " "
70  << convertRadToDeg(m_theta_obj);
71 
72  m_childNmNs = DDSplit(sArgs["ChildName"]);
73  if (m_childNmNs.second.empty())
74  m_childNmNs.second = DDCurrentNamespace::ns();
75 
76  DDName parentName = parent().name();
77  LogDebug("DDAlgorithm") << "DDMTDLinear: Parent " << parentName << "\tChild " << m_childNmNs.first << " NameSpace "
78  << m_childNmNs.second;
79 }
80 
82  DDName mother = parent().name();
83  DDName ddname(m_childNmNs.first, m_childNmNs.second);
84  int copy = m_startCopyNo;
85 
86  DDTranslation direction(sin(m_theta) * cos(m_phi), sin(m_theta) * sin(m_phi), cos(m_theta));
87 
88  DDTranslation basetr(m_base[0], m_base[1], m_base[2]);
89 
90  //rotation is in xy plane
91  double thetaZ = m_theta_obj - 0.5_pi;
92  double phiZ = m_phi_obj;
93  double thetaX = m_theta_obj;
94  double thetaY = m_theta_obj;
95  double phiX = m_phi_obj;
96  double phiY = m_phi_obj + 0.5_pi;
97 
98  DDRotation rotation = DDRotation("Rotation");
99 
100  if (!rotation) {
101  LogDebug("DDAlgorithm") << "DDMTDLinear: Creating a new "
102  << "rotation for " << ddname;
103 
104  rotation = DDrot("Rotation", DDcreateRotationMatrix(thetaX, phiX, thetaY, phiY, thetaZ, phiZ));
105  }
106 
107  for (int i = 0; i < m_n; ++i) {
108  DDTranslation tran = basetr + (double(i) * m_delta) * direction;
109  cpv.position(ddname, mother, copy, tran, rotation);
110  LogDebug("DDAlgorithm") << "DDMTDLinear: " << m_childNmNs.second << ":" << m_childNmNs.first << " number " << copy
111  << " positioned in " << mother << " at " << tran << " with " << rotation;
112  copy += m_incrCopyNo;
113  }
114 }
115 
static AlgebraicMatrix initialize()
double m_phi_obj
Definition: DDMTDLinear.cc:42
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
double m_theta_obj
Definition: DDMTDLinear.cc:43
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
double m_delta
Definition: DDMTDLinear.cc:41
double m_phi
Definition: DDMTDLinear.cc:40
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
std::pair< std::string, std::string > m_childNmNs
Definition: DDMTDLinear.cc:46
void execute(DDCompactView &cpv) override
Definition: DDMTDLinear.cc:81
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:67
std::unique_ptr< DDRotationMatrix > DDcreateRotationMatrix(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
create a new DDRotationMatrix in the GEANT3 style.
Definition: DDRotation.cc:120
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Definition: DDMTDLinear.cc:50
int m_startCopyNo
Definition: DDMTDLinear.cc:37
double m_theta
Definition: DDMTDLinear.cc:39
std::vector< double > m_base
Definition: DDMTDLinear.cc:44
#define DEFINE_EDM_PLUGIN(factory, type, name)
int m_incrCopyNo
Definition: DDMTDLinear.cc:38
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
#define LogDebug(id)