CMS 3D CMS Logo

DDMuonAngular.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
6 
7 //#define EDM_ML_DEBUG
8 
9 using namespace angle_units::operators;
10 
11 static long algorithm(dd4hep::Detector& /* description */, cms::DDParsingContext& context, xml_h element) {
12  cms::DDNamespace ns(context, element, true);
14 
15  int n = args.value<int>("n");
16  int startCopyNo = args.find("startCopyNo") ? args.value<int>("startCopyNo") : 1;
17  int incrCopyNo = args.find("incrCopyNo") ? args.value<int>("incrCopyNo") : 1;
18  float startAngle = args.value<float>("startAngle");
19  float stepAngle = args.value<float>("stepAngle");
20  float zoffset = args.value<float>("zoffset");
21  std::string rotns = args.value<std::string>("RotNameSpace");
22  dd4hep::Volume mother = ns.volume(args.parentName());
23  std::string childName = args.value<std::string>("ChildName");
24  childName = ns.prepend(childName);
25  dd4hep::Volume child = ns.volume(childName);
26 
27 #ifdef EDM_ML_DEBUG
28  edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Parameters for positioning:: n " << n << " Start, Step "
29  << convertRadToDeg(startAngle) << ", " << convertRadToDeg(stepAngle) << ", zoffset "
30  << cms::convert2mm(zoffset) << ", RotNameSpace " << rotns;
31  edm::LogVerbatim("MuonGeom") << "DDMuonAngular: Parent " << mother.name() << "\tChild " << child.name()
32  << " NameSpace " << ns.name();
33 #endif
34  double phi = startAngle;
35  int copyNo = startCopyNo;
36 
37  for (int i = 0; i < n; ++i) {
38  double phitmp = phi;
39  if (phitmp >= 2._pi)
40  phitmp -= 2._pi;
41  dd4hep::Rotation3D rotation = cms::makeRotation3D(90._deg, phitmp, 90._deg, 90._deg + phitmp, 0., 0.);
42  std::string rotstr = ns.nsName(child.name()) + std::to_string(phitmp * 10.);
43  auto irot = context.rotations.find(ns.prepend(rotstr));
44  if (irot != context.rotations.end()) {
45  rotation = ns.rotation(ns.prepend(rotstr));
46  }
47  dd4hep::Position tran(0., 0., zoffset);
48  mother.placeVolume(child, copyNo, dd4hep::Transform3D(rotation, tran));
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("MuonGeom") << "DDMuonAngular:" << child.name() << " number " << copyNo << " positioned in "
51  << mother.name() << " at (0,0," << cms::convert2mm(zoffset) << ") with " << rotstr
52  << ": " << rotation;
53 #endif
54  phi += stepAngle;
55  copyNo += incrCopyNo;
56  }
57  return cms::s_executed;
58 }
59 
60 // first argument is the type from the xml file
61 DECLARE_DDCMS_DETELEMENT(DDCMS_muon_DDMuonAngular, algorithm)
Log< level::Info, true > LogVerbatim
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:182
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
constexpr NumType convert2mm(NumType length)
Definition: DDutils.h:7
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
static std::string to_string(const XMLCh *ch)
static long algorithm(dd4hep::Detector &, cms::DDParsingContext &context, xml_h element)
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
static std::string nsName(const std::string &)
Definition: DDNamespace.cc:122
static constexpr long s_executed
std::string_view name() const
Definition: DDNamespace.h:79
dd4hep::Volume Volume
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