CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDTrackerAngular.cc
Go to the documentation of this file.
1 #include "DD4hep/DetFactoryHelper.h"
5 
6 using namespace std;
7 using namespace dd4hep;
8 using namespace cms;
9 using namespace cms_units::operators;
10 
11 static long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
12  cms::DDNamespace ns(ctxt, e, true);
13  DDAlgoArguments args(ctxt, e);
14  // Header section of original DDTrackerAngular.h
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  double rangeAngle = args.value<double>("RangeAngle"); //Range in angle
19  double startAngle = args.value<double>("StartAngle"); //Start anle
20  double radius = args.value<double>("Radius"); //Radius
21  vector<double> center = args.value<vector<double> >("Center"); //Phi values
22  Volume mother = ns.volume(args.parentName());
23  Volume child = ns.volume(args.value<string>("ChildName"));
24 
25  double delta = 0e0; //Increment in phi
26  // Code section of original DDTrackerAngular.cc
27  if (fabs(rangeAngle - 360.0_deg) < 0.001_deg) {
28  delta = rangeAngle / double(n);
29  } else if (n > 1) {
30  delta = rangeAngle / double(n - 1);
31  }
32 
33  edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular debug: Parameters for positioning:: n " << n
34  << " Start, Range, Delta " << convertRadToDeg(startAngle) << " "
35  << convertRadToDeg(rangeAngle) << " " << convertRadToDeg(delta) << " Radius "
36  << radius << " Centre " << center[0] << ", " << center[1] << ", " << center[2];
37  edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular debug: Parent " << mother.name() << "\tChild " << child.name()
38  << " NameSpace " << ns.name();
39 
40  double theta = 90._deg;
41  int copy = startCopyNo;
42  double phi = startAngle;
43  for (int i = 0; i < n; i++) {
44  double phix = phi;
45  double phiy = phix + 90._deg;
46  double phideg = convertRadToDeg(phix);
47 
48  Rotation3D rotation;
49  if (phideg != 0) {
50  string rotstr = ns.nsName(child.name()) + std::to_string(phideg * 10.);
51  auto irot = ctxt.rotations.find(ns.prepend(rotstr));
52  if (irot != ctxt.rotations.end()) {
53  rotation = ns.rotation(ns.prepend(rotstr));
54  } else {
55  edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular Creating a new "
56  << "rotation: " << rotstr << "\t90., " << convertRadToDeg(phix) << ", 90.,"
57  << convertRadToDeg(phiy) << ", 0, 0";
58  RotationZYX rot;
59  rotation = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
60  }
61  }
62 
63  double xpos = radius * cos(phi) + center[0];
64  double ypos = radius * sin(phi) + center[1];
65  double zpos = center[2];
66  Position tran(xpos, ypos, zpos);
67  mother.placeVolume(child, copy, Transform3D(rotation, tran));
68  edm::LogVerbatim("TrackerGeom") << "DDTrackerAngular test " << child.name() << " number " << copy
69  << " positioned in " << mother.name() << " at " << tran << " with " << rotation;
70  copy += incrCopyNo;
71  phi += delta;
72  }
73  return 1;
74 }
75 
76 // first argument is the type from the xml file
77 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerAngular, algorithm)
Log< level::Info, true > LogVerbatim
dd4hep::Volume volume(const std::string &name, bool exc=true) const
Definition: DDNamespace.cc:276
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::unordered_map< std::string, dd4hep::Rotation3D > rotations
T value(const std::string &name) const
Geom::Theta< T > theta() const
std::string to_string(const V &value)
Definition: OMSAccess.h:71
DDRotationMatrix makeRotation3D(double thetaX, double phiX, double thetaY, double phiY, double thetaZ, double phiZ)
std::string_view name() const
Definition: DDNamespace.h:79
#define DECLARE_DDCMS_DETELEMENT(name, func)
Definition: DDPlugins.h:25
tuple dd4hep
Definition: dd4hep_cff.py:3
static std::string nsName(const std::string &)
Definition: DDNamespace.cc:122
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::string prepend(const std::string &) const
Definition: DDNamespace.cc:99
dd4hep::Volume Volume
const dd4hep::Rotation3D & rotation(const std::string &name) const
Definition: DDNamespace.cc:182
bool find(const std::string &name) const
Check the existence of an argument by name.
std::string parentName() const
Access value of rParent child node.