CMS 3D CMS Logo

DDGEMAngular.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
6 
7 using namespace angle_units::operators;
8 
9 //#define EDM_ML_DEBUG
10 
11 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
12  cms::DDNamespace ns(ctxt, e, true);
14 
15  // Header section of original DDGEMAngular.h
16  float startAngle = args.value<float>("startAngle");
17  float stepAngle = args.value<float>("stepAngle");
18  int invert = args.value<int>("invert");
19  double rPos = args.value<double>("rPosition");
20  double zoffset = args.value<double>("zoffset");
21  int n = args.value<int>("n");
22  int startCopyNo = args.value<int>("startCopyNo");
23  int incrCopyNo = args.value<int>("incrCopyNo");
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parameters for positioning-- " << n << " copies in steps of "
26  << convertRadToDeg(stepAngle) << " from " << convertRadToDeg(startAngle)
27  << " (inversion flag " << invert << ") \trPos " << cms::convert2mm(rPos) << " Zoffest "
28  << cms::convert2mm(zoffset) << "\tStart and inremental "
29  << "copy nos " << startCopyNo << ", " << incrCopyNo;
30 #endif
31  std::string childName = args.value<std::string>("ChildName");
32  childName = ns.prepend(childName);
33  std::string parentName = args.parentName();
34  parentName = ns.prepend(parentName);
35  dd4hep::Volume parent = ns.volume(parentName);
36  dd4hep::Volume child = ns.volume(childName);
37 #ifdef EDM_ML_DEBUG
38  edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Parent " << parentName << "\tChild " << child.name() << "\tNameSpace "
39  << ns.name();
40 #endif
41 
42  // Now position child in mother *n* times
43  double phi = startAngle;
44  int copyNo = startCopyNo;
45  double thetax = 90.0_deg;
46  double thetay = invert == 0 ? 0.0 : 180.0_deg;
47  for (int ii = 0; ii < n; ii++) {
48  double phiz = phi;
49  if (phiz >= 2._pi)
50  phiz -= 2._pi;
51  double phix = invert == 0 ? (90.0_deg + phiz) : (-90.0_deg + phiz);
52 #ifdef EDM_ML_DEBUG
53  edm::LogVerbatim("MuonGeom") << "DDGEMAngular: Creating a rotation " << convertRadToDeg(thetax) << ", "
54  << convertRadToDeg(phix) << ", " << convertRadToDeg(thetay) << ", 0, "
55  << convertRadToDeg(thetax) << ", " << convertRadToDeg(phiz);
56 #endif
57  dd4hep::Rotation3D rotation = cms::makeRotation3D(thetax, phix, thetay, 0., thetax, phiz);
58  dd4hep::Position tran(rPos * cos(phiz), rPos * sin(phiz), zoffset);
59  parent.placeVolume(child, copyNo, dd4hep::Transform3D(rotation, tran));
60 #ifdef EDM_ML_DEBUG
61  edm::LogVerbatim("MuonGeom") << "DDGEMAngular: " << child.name() << " number " << copyNo << " positioned in "
62  << parentName << " at (" << cms::convert2mm(rPos * cos(phiz)) << ","
63  << cms::convert2mm(rPos * sin(phiz)) << "," << cms::convert2mm(zoffset) << ") with "
64  << rotation;
65 #endif
66  phi += stepAngle;
67  copyNo += incrCopyNo;
68  }
69  return cms::s_executed;
70 }
71 
72 // first argument is the type from the xml file
73 DECLARE_DDCMS_DETELEMENT(DDCMS_muon_DDGEMAngular, algorithm)
Log< level::Info, true > LogVerbatim
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &ctxt, xml_h e)
Definition: DDGEMAngular.cc:11
static constexpr long s_executed
std::string_view name() const
Definition: DDNamespace.h:79
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dd4hep::Volume Volume
ii
Definition: cuy.py:589
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99