CMS 3D CMS Logo

DDTrackerIrregularRingAlgo.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 namespace {
12  long algorithm(Detector& /* description */, cms::DDParsingContext& ctxt, xml_h e) {
13  DDNamespace ns(ctxt, e, true);
14  DDAlgoArguments args(ctxt, e);
15  Volume mother = ns.volume(args.parentName());
16  string childName = args.value<string>("ChildName");
17  Volume child = ns.volume(childName);
18 
19  string parentName = args.parentName();
20  int n = args.value<int>("N");
21  int startCopyNo = args.value<int>("StartCopyNo");
22  int incrCopyNo = args.value<int>("IncrCopyNo");
23  double rangeAngle = args.value<double>("RangeAngle");
24  double startAngle = args.value<double>("StartAngle");
25  double radius = args.value<double>("Radius");
26  vector<double> center = args.value<vector<double> >("Center");
27  vector<double> phiAngles = args.value<vector<double> >("phiAngleValues");
28  vector<double> radiusValues = args.value<vector<double> >("radiusValues");
29  vector<double> yawAngles = args.value<vector<double> >("yawAngleValues");
30  bool isZPlus = args.value<int>("IsZPlus") == 1;
31  double tiltAngle = args.value<double>("TiltAngle");
32  bool isFlipped = args.value<int>("IsFlipped") == 1;
33 
34  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parameters for position"
35  << "ing:: n " << n << " Start, Range " << convertRadToDeg(startAngle) << " "
36  << convertRadToDeg(rangeAngle) << " Radius " << radius << " Centre " << center[0]
37  << ", " << center[1] << ", " << center[2];
38 
39  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parent " << parentName << "\tChild "
40  << childName << " NameSpace " << ns.name();
41 
42  Rotation3D flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix, phiOwnAxisRotMatrix; // Identity matrix
43 
44  // flipMatrix calculus
45  if (isFlipped) {
46  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
47  << "\t90., 180., "
48  << "90., 90., "
49  << "180., 0.";
50  flipMatrix = makeRotation3D(90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0._deg);
51  }
52  // tiltMatrix calculus
53  if (isZPlus) {
54  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
55  << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
56  << convertRadToDeg(90._deg - tiltAngle) << ", 0.";
57  tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0._deg);
58  if (isFlipped) {
59  tiltMatrix *= flipMatrix;
60  }
61  } else {
62  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
63  << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
64  << convertRadToDeg(90._deg + tiltAngle) << ", 0.";
65  tiltMatrix = makeRotation3D(90._deg, 90._deg, tiltAngle, 0._deg, 90._deg + tiltAngle, 0._deg);
66  if (isFlipped) {
67  tiltMatrix *= flipMatrix;
68  }
69  }
70 
71  // Loops for all phi values
72  double theta = 90._deg;
73  int copy = startCopyNo;
74 
75  for (int i = 0; i < n; ++i) {
76  // phiRotMatrix calculus
77  double phix = convertDegToRad(phiAngles.at(i));
78  double phix_ownaxis = convertDegToRad(yawAngles.at(i));
79  radius = radiusValues.at(i);
80  double phiy = phix + 90._deg;
81  double phiy_ownaxis = phix_ownaxis + 90._deg;
82  if (phix_ownaxis != 0.) {
83  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
84  << "\t90., " << convertRadToDeg(phix_ownaxis) << ", 90.,"
85  << convertRadToDeg(phiy_ownaxis) << ", 0., 0.";
86  phiOwnAxisRotMatrix = makeRotation3D(theta, phix_ownaxis, theta, phiy_ownaxis, 0., 0.);
87  }
88  if (phix != 0.) {
89  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: "
90  << "\t90., " << convertRadToDeg(phix) << ", 90.," << convertRadToDeg(phiy)
91  << ", 0., 0.";
92  phiRotMatrix = makeRotation3D(theta, phix, theta, phiy, 0., 0.);
93  }
94 
95  globalRotMatrix = phiOwnAxisRotMatrix * phiRotMatrix * tiltMatrix;
96 
97  // translation def
98  double xpos = radius * cos(phix) + center[0];
99  double ypos = radius * sin(phix) + center[1];
100  double zpos = center[2];
101  Position tran(xpos, ypos, zpos);
102 
103  // Positions child with respect to parent
104  mother.placeVolume(child, copy, Transform3D(globalRotMatrix, tran));
105  edm::LogVerbatim("TrackerGeom") << "DDTrackerIrregularRingAlgo test " << child.data()->GetName() << " number "
106  << copy << " positioned in " << mother.data()->GetName() << " at " << tran
107  << " with " << globalRotMatrix;
108 
109  copy += incrCopyNo;
110  }
111  return s_executed;
112  }
113 } // namespace
114 // first argument is the type from the xml file
115 DECLARE_DDCMS_DETELEMENT(DDCMS_track_DDTrackerIrregularRingAlgo, ::algorithm)
Log< level::Info, true > LogVerbatim
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
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 constexpr long s_executed
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
Geom::Theta< T > theta() const
#define LogDebug(id)