CMS 3D CMS Logo

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