CMS 3D CMS Logo

DDTrackerRingAlgo.cc
Go to the documentation of this file.
1 // File: DDTrackerRingAlgo.cc
3 // Description: Tilts and positions n copies of a module at prescribed phi
4 // values within a ring. The module can also be flipped if requested.
6 
7 
8 #include <cmath>
9 #include <algorithm>
10 
17 #include "CLHEP/Units/GlobalPhysicalConstants.h"
18 #include "CLHEP/Units/GlobalSystemOfUnits.h"
19 
20 
22  LogDebug("TrackerGeom") << "DDTrackerRingAlgo info: Creating an instance";
23 }
24 
26 
28  const DDVectorArguments & vArgs,
29  const DDMapArguments & ,
30  const DDStringArguments & sArgs,
31  const DDStringVectorArguments & ) {
32 
33  n = int(nArgs["N"]);
34  startCopyNo = int(nArgs["StartCopyNo"]);
35  incrCopyNo = int(nArgs["IncrCopyNo"]);
36  rangeAngle = nArgs["RangeAngle"];
37  startAngle = nArgs["StartAngle"];
38  radius = nArgs["Radius"];
39  center = vArgs["Center"];
40  isZPlus = bool(nArgs["IsZPlus"]);
41  tiltAngle = nArgs["TiltAngle"];
42  isFlipped = bool(nArgs["IsFlipped"]);
43 
44  if (fabs(rangeAngle-360.0*CLHEP::deg)<0.001*CLHEP::deg) {
45  delta = rangeAngle/double(n);
46  } else {
47  if (n > 1) {
48  delta = rangeAngle/double(n-1);
49  } else {
50  delta = 0.;
51  }
52  }
53 
54  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
55  << "ing:: n " << n << " Start, Range, Delta "
56  << startAngle/CLHEP::deg << " "
57  << rangeAngle/CLHEP::deg << " " << delta/CLHEP::deg
58  << " Radius " << radius << " Centre " << center[0]
59  << ", " << center[1] << ", "<<center[2];
60 
62  childName = sArgs["ChildName"];
63 
64  DDName parentName = parent().name();
65  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName
66  << "\tChild " << childName << " NameSpace "
67  << idNameSpace;
68 }
69 
71 
72  DDRotation flipRot, tiltRot, phiRot, globalRot; // Identity
73  DDRotationMatrix flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix; // Identity matrix
74  std::string rotstr = "RTrackerRingAlgo";
75 
76  // flipMatrix calculus
77  if (isFlipped) {
78  std::string flipRotstr = rotstr + "Flip";
79  flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
80  if (!flipRot) {
81  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << flipRotstr
82  << "\t90., 180., "
83  << "90., 90., "
84  << "180., 0.";
85  flipRot = DDrot(DDName(flipRotstr, idNameSpace),
86  90.*CLHEP::deg, 180.*CLHEP::deg, 90.*CLHEP::deg, 90.*CLHEP::deg, 180.*CLHEP::deg, 0.);
87  }
88  flipMatrix = flipRot.matrix();
89  }
90  // tiltMatrix calculus
91  if (isZPlus) {
92  std::string tiltRotstr = rotstr + "Tilt" + std::to_string(tiltAngle/CLHEP::deg) + "ZPlus";
93  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
94  if (!tiltRot) {
95  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr
96  << "\t90., 90., "
97  << tiltAngle/CLHEP::deg << ", 180., "
98  << 90. - tiltAngle/CLHEP::deg << ", 0.";
99  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
100  90.*CLHEP::deg, 90.*CLHEP::deg, tiltAngle, 180.*CLHEP::deg, 90.*CLHEP::deg - tiltAngle, 0.);
101  }
102  tiltMatrix = tiltRot.matrix();
103  if (isFlipped) { tiltMatrix *= flipMatrix; }
104  }
105  else {
106  std::string tiltRotstr = rotstr + "Tilt" + std::to_string(tiltAngle/CLHEP::deg) + "ZMinus";
107  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
108  if (!tiltRot) {
109  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr
110  << "\t90., 90., "
111  << tiltAngle/CLHEP::deg << ", 0., "
112  << 90. + tiltAngle/CLHEP::deg << ", 0.";
113  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
114  90.*CLHEP::deg, 90.*CLHEP::deg, tiltAngle, 0., 90.*CLHEP::deg + tiltAngle, 0.);
115  }
116  tiltMatrix = tiltRot.matrix();
117  if (isFlipped) { tiltMatrix *= flipMatrix; }
118  }
119 
120  // Loops for all phi values
121  DDName mother = parent().name();
123  double theta = 90.*CLHEP::deg;
124  int copy = startCopyNo;
125  double phi = startAngle;
126 
127  for (int i=0; i<n; i++) {
128 
129  // phiRotMatrix calculus
130  double phix = phi;
131  double phiy = phix + 90.*CLHEP::deg;
132  double phideg = phix/CLHEP::deg;
133  if (phideg != 0) {
134  std::string phiRotstr = rotstr + "Phi" + std::to_string(phideg*10.);
135  phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
136  if (!phiRot) {
137  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << phiRotstr
138  << "\t90., " << phix/CLHEP::deg
139  << ", 90.," << phiy/CLHEP::deg
140  <<", 0., 0.";
141  phiRot = DDrot(DDName(phiRotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
142  }
143  phiRotMatrix = phiRot.matrix();
144  }
145 
146  // globalRot def
147  std::string globalRotstr = rotstr + "Phi" + std::to_string(phideg*10.) + "Tilt" + std::to_string(tiltAngle/CLHEP::deg);
148  if (isZPlus) {
149  globalRotstr += "ZPlus";
150  if (isFlipped) { globalRotstr += "Flip"; }
151  }
152  else {
153  globalRotstr += "ZMinus";
154  if (isFlipped) { globalRotstr += "Flip"; }
155  }
156  globalRot = DDRotation(DDName(globalRotstr, idNameSpace));
157  if (!globalRot) {
158  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new "
159  << "rotation: " << globalRotstr;
160  globalRotMatrix = phiRotMatrix * tiltMatrix;
161  globalRot = DDrot(DDName(globalRotstr, idNameSpace), std::make_unique<DDRotationMatrix>(globalRotMatrix));
162  }
163 
164  // translation def
165  double xpos = radius*cos(phi) + center[0];
166  double ypos = radius*sin(phi) + center[1];
167  double zpos = center[2];
168  DDTranslation tran(xpos, ypos, zpos);
169 
170  // Positions child with respect to parent
171  cpv.position(child, mother, copy, tran, globalRot);
172  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test " << child << " number "
173  << copy << " positioned in " << mother << " at "
174  << tran << " with " << globalRot;
175 
176  copy += incrCopyNo;
177  phi += delta;
178  }
179 }
#define LogDebug(id)
def copy(args, dbName)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Geom::Theta< T > theta() const
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
std::string idNameSpace
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
U second(std::pair< T, U > const &p)
void execute(DDCompactView &cpv) override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DDRotation DDrot(const DDName &name, std::unique_ptr< DDRotationMatrix > rot)
Definition of a uniquely identifiable rotation matrix named by DDName name.
Definition: DDRotation.cc:80
~DDTrackerRingAlgo() override
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=0)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
DDRotationMatrix & matrix()
Definition: DDTransform.h:97
std::vector< double > center