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 
15 #include "CLHEP/Units/GlobalPhysicalConstants.h"
16 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 
18 #include <string>
19 #include <vector>
20 
21 /*
22  Tilts and positions n copies of a module at prescribed phi values
23  within a ring. The module can also be flipped if requested.
24 
25  (radius, Phi, Z) refers to the cylindrical coordinates in the global frame of reference.
26 
27  A module's tilt angle is defined with respect to the global frame of reference's Z axis.
28  Example, in the outer tracker : For a straight barrel module, tiltAngle = 0°.
29  For a module in the endcaps, tiltAngle = 90°.
30  tiltAngle ∈ [0, 90°].
31  Please note that parameter tiltAngle has to be set regardless of any sign consideration,
32  to the absolute value of the module's tilt angle.
33 
34  == Example of use : ==
35 
36  <Algorithm name="track:DDTrackerRingAlgo">
37  <rParent name="tracker:Ring5Layer1Plus"/>
38  <String name="ChildName" value="tracker:BModule5Layer1"/>
39  <Numeric name="N" value="9"/>
40  <Numeric name="StartCopyNo" value="1"/>
41  <Numeric name="IncrCopyNo" value="2"/>
42  <Numeric name="RangeAngle" value="360*deg"/>
43  <Numeric name="StartAngle" value="90*deg"/>
44  <Numeric name="Radius" value="247"/>
45  <Vector name="Center" type="numeric" nEntries="3">0,0,-5.45415</Vector>
46  <Numeric name="IsZPlus" value="1"/>
47  <Numeric name="TiltAngle" value="47*deg"/>
48  <Numeric name="IsFlipped" value="1"/>
49  </Algorithm>
50 */
51 
52 using namespace std;
53 
54 class DDTrackerRingAlgo : public DDAlgorithm {
55 public:
56  // Constructor and Destructor
58  ~DDTrackerRingAlgo() override;
59 
60  void initialize(const DDNumericArguments& nArgs,
61  const DDVectorArguments& vArgs,
62  const DDMapArguments& mArgs,
63  const DDStringArguments& sArgs,
64  const DDStringVectorArguments& vsArgs) override;
65 
66  void execute(DDCompactView& cpv) override;
67 
68 private:
69  int n; //Number of copies
70  int startCopyNo; //Start Copy number
71  int incrCopyNo; //Increment in Copy number
72  double rangeAngle; //Range in Phi angle
73  double startAngle; //Start Phi angle
74  double radius; //Radius
75  vector<double> center; //Phi values
76  bool isZPlus; //Is Z positive ?
77  double tiltAngle; //Module's tilt angle (absolute value)
78  bool isFlipped; //Is the module flipped ?
79  double delta; //Increment in Phi
80 
81  string idNameSpace; //Namespace of this and ALL sub-parts
82  string childName; //Child name
83 };
84 
85 DDTrackerRingAlgo::DDTrackerRingAlgo() { LogDebug("TrackerGeom") << "DDTrackerRingAlgo info: Creating an instance"; }
86 
88 
90  const DDVectorArguments& vArgs,
91  const DDMapArguments&,
92  const DDStringArguments& sArgs,
93  const DDStringVectorArguments&) {
94  n = int(nArgs["N"]);
95  startCopyNo = int(nArgs["StartCopyNo"]);
96  incrCopyNo = int(nArgs["IncrCopyNo"]);
97  rangeAngle = nArgs["RangeAngle"];
98  startAngle = nArgs["StartAngle"];
99  radius = nArgs["Radius"];
100  center = vArgs["Center"];
101  isZPlus = bool(nArgs["IsZPlus"]);
102  tiltAngle = nArgs["TiltAngle"];
103  isFlipped = bool(nArgs["IsFlipped"]);
104 
105  if (fabs(rangeAngle - 360.0 * CLHEP::deg) < 0.001 * CLHEP::deg) {
106  delta = rangeAngle / double(n);
107  } else {
108  if (n > 1) {
109  delta = rangeAngle / double(n - 1);
110  } else {
111  delta = 0.;
112  }
113  }
114 
115  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parameters for position"
116  << "ing:: n " << n << " Start, Range, Delta " << startAngle / CLHEP::deg << " "
117  << rangeAngle / CLHEP::deg << " " << delta / CLHEP::deg << " Radius " << radius << " Centre "
118  << center[0] << ", " << center[1] << ", " << center[2];
119 
120  idNameSpace = DDCurrentNamespace::ns();
121  childName = sArgs["ChildName"];
122 
123  DDName parentName = parent().name();
124  LogDebug("TrackerGeom") << "DDTrackerRingAlgo debug: Parent " << parentName << "\tChild " << childName
125  << " NameSpace " << idNameSpace;
126 }
127 
129  DDRotation flipRot, tiltRot, phiRot, globalRot; // Identity
130  DDRotationMatrix flipMatrix, tiltMatrix, phiRotMatrix, globalRotMatrix; // Identity matrix
131  string rotstr = "RTrackerRingAlgo";
132 
133  // flipMatrix calculus
134  if (isFlipped) {
135  string flipRotstr = rotstr + "Flip";
136  flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
137  if (!flipRot) {
138  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << flipRotstr << "\t90., 180., "
139  << "90., 90., "
140  << "180., 0.";
141  flipRot = DDrot(DDName(flipRotstr, idNameSpace),
142  90. * CLHEP::deg,
143  180. * CLHEP::deg,
144  90. * CLHEP::deg,
145  90. * CLHEP::deg,
146  180. * CLHEP::deg,
147  0.);
148  }
149  flipMatrix = flipRot.matrix();
150  }
151  // tiltMatrix calculus
152  if (isZPlus) {
153  string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZPlus";
154  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
155  if (!tiltRot) {
156  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
157  << tiltAngle / CLHEP::deg << ", 180., " << 90. - tiltAngle / CLHEP::deg << ", 0.";
158  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
159  90. * CLHEP::deg,
160  90. * CLHEP::deg,
161  tiltAngle,
162  180. * CLHEP::deg,
163  90. * CLHEP::deg - tiltAngle,
164  0.);
165  }
166  tiltMatrix = tiltRot.matrix();
167  if (isFlipped) {
168  tiltMatrix *= flipMatrix;
169  }
170  } else {
171  string tiltRotstr = rotstr + "Tilt" + to_string(tiltAngle / CLHEP::deg) + "ZMinus";
172  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
173  if (!tiltRot) {
174  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << tiltRotstr << "\t90., 90., "
175  << tiltAngle / CLHEP::deg << ", 0., " << 90. + tiltAngle / CLHEP::deg << ", 0.";
176  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace),
177  90. * CLHEP::deg,
178  90. * CLHEP::deg,
179  tiltAngle,
180  0.,
181  90. * CLHEP::deg + tiltAngle,
182  0.);
183  }
184  tiltMatrix = tiltRot.matrix();
185  if (isFlipped) {
186  tiltMatrix *= flipMatrix;
187  }
188  }
189 
190  // Loops for all phi values
191  DDName mother = parent().name();
192  DDName child(DDSplit(childName).first, DDSplit(childName).second);
193  double theta = 90. * CLHEP::deg;
194  int copy = startCopyNo;
195  double phi = startAngle;
196 
197  for (int i = 0; i < n; i++) {
198  // phiRotMatrix calculus
199  double phix = phi;
200  double phiy = phix + 90. * CLHEP::deg;
201  double phideg = phix / CLHEP::deg;
202  if (phideg != 0) {
203  string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
204  phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
205  if (!phiRot) {
206  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new rotation: " << phiRotstr << "\t90., "
207  << phix / CLHEP::deg << ", 90.," << phiy / CLHEP::deg << ", 0., 0.";
208  phiRot = DDrot(DDName(phiRotstr, idNameSpace), theta, phix, theta, phiy, 0., 0.);
209  }
210  phiRotMatrix = phiRot.matrix();
211  }
212 
213  // globalRot def
214  string globalRotstr = rotstr + "Phi" + to_string(phideg * 10.) + "Tilt" + to_string(tiltAngle / CLHEP::deg);
215  if (isZPlus) {
216  globalRotstr += "ZPlus";
217  if (isFlipped) {
218  globalRotstr += "Flip";
219  }
220  } else {
221  globalRotstr += "ZMinus";
222  if (isFlipped) {
223  globalRotstr += "Flip";
224  }
225  }
226  globalRot = DDRotation(DDName(globalRotstr, idNameSpace));
227  if (!globalRot) {
228  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test: Creating a new "
229  << "rotation: " << globalRotstr;
230  globalRotMatrix = phiRotMatrix * tiltMatrix;
231  globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
232  }
233 
234  // translation def
235  double xpos = radius * cos(phi) + center[0];
236  double ypos = radius * sin(phi) + center[1];
237  double zpos = center[2];
238  DDTranslation tran(xpos, ypos, zpos);
239 
240  // Positions child with respect to parent
241  cpv.position(child, mother, copy, tran, globalRot);
242  LogDebug("TrackerGeom") << "DDTrackerRingAlgo test " << child << " number " << copy << " positioned in " << mother
243  << " at " << tran << " with " << globalRot;
244 
245  copy += incrCopyNo;
246  phi += delta;
247  }
248 }
249 
250 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerRingAlgo, "track:DDTrackerRingAlgo");
static AlgebraicMatrix initialize()
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
vector< double > center
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
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
std::string to_string(const V &value)
Definition: OMSAccess.h:71
static std::string & ns()
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
void execute(DDCompactView &cpv) override
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
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:67
~DDTrackerRingAlgo() override
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::pair< std::string, std::string > DDSplit(const std::string &n)
split into (name,namespace), separator = &#39;:&#39;
Definition: DDSplit.cc:3
Geom::Theta< T > theta() const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDRotationMatrix & matrix()
Definition: DDTransform.h:85
#define LogDebug(id)