CMS 3D CMS Logo

DDTrackerIrregularRingAlgo.cc
Go to the documentation of this file.
1 // File: DDTrackerIrregularRingAlgo.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 
16 
17 #include <string>
18 #include <vector>
19 
20 /*
21  Tilts and positions n copies of a module at prescribed phi values
22  within a ring. The module can also be flipped if requested.
23 
24  (radius, Phi, Z) refers to the cylindrical coordinates in the global frame of reference.
25 
26  A module's tilt angle is defined with respect to the global frame of reference's Z axis.
27  Example, in the outer tracker : For a straight barrel module, tiltAngle = 0°.
28  For a module in the endcaps, tiltAngle = 90°.
29  tiltAngle ∈ [0, 90°].
30  Please note that parameter tiltAngle has to be set regardless of any sign consideration,
31  to the absolute value of the module's tilt angle.
32 
33  == Example of use : ==
34 
35  <Algorithm name="track:DDTrackerIrregularRingAlgo">
36  <rParent name="tracker:Ring5Layer1Plus"/>
37  <String name="ChildName" value="tracker:BModule5Layer1"/>
38  <Numeric name="N" value="9"/>
39  <Numeric name="StartCopyNo" value="1"/>
40  <Numeric name="IncrCopyNo" value="2"/>
41  <Numeric name="RangeAngle" value="360*deg"/>
42  <Numeric name="StartAngle" value="90*deg"/>
43  <Numeric name="Radius" value="247"/>
44  <Vector name="Center" type="numeric" nEntries="3">0,0,-5.45415</Vector>
45  <Numeric name="IsZPlus" value="1"/>
46  <Numeric name="TiltAngle" value="47*deg"/>
47  <Numeric name="IsFlipped" value="1"/>
48  </Algorithm>
49 */
50 
51 using namespace std;
52 using namespace angle_units::operators;
53 
54 class DDTrackerIrregularRingAlgo : public DDAlgorithm {
55 public:
56  // Constructor and Destructor
58  ~DDTrackerIrregularRingAlgo() 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  vector<double> phiAngles;
77  vector<double> radiusValues;
78  vector<double> yawAngles;
79  bool isZPlus; //Is Z positive ?
80  double tiltAngle; //Module's tilt angle (absolute value)
81  bool isFlipped; //Is the module flipped ?
82 
83  string idNameSpace; //Namespace of this and ALL sub-parts
84  string childName; //Child name
85 };
86 
88  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo info: Creating an instance";
89 }
90 
92 
94  const DDVectorArguments& vArgs,
95  const DDMapArguments&,
96  const DDStringArguments& sArgs,
97  const DDStringVectorArguments&) {
98  n = int(nArgs["N"]);
99  startCopyNo = int(nArgs["StartCopyNo"]);
100  incrCopyNo = int(nArgs["IncrCopyNo"]);
101  rangeAngle = nArgs["RangeAngle"];
102  startAngle = nArgs["StartAngle"];
103  radius = nArgs["Radius"];
104  center = vArgs["Center"];
105  yawAngles = vArgs["yawAngleValues"];
106  phiAngles = vArgs["phiAngleValues"];
107  radiusValues = vArgs["radiusValues"];
108  isZPlus = bool(nArgs["IsZPlus"]);
109  tiltAngle = nArgs["TiltAngle"];
110  isFlipped = bool(nArgs["IsFlipped"]);
111 
112  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parameters for position"
113  << "ing:: n " << n << " Start, Range " << convertRadToDeg(startAngle) << " "
114  << convertRadToDeg(rangeAngle) << " Radius " << radius << " Centre " << center[0] << ", "
115  << center[1] << ", " << center[2];
116 
117  idNameSpace = DDCurrentNamespace::ns();
118  childName = sArgs["ChildName"];
119 
120  DDName parentName = parent().name();
121  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo debug: Parent " << parentName << "\tChild " << childName
122  << " NameSpace " << idNameSpace;
123 }
124 
126  DDRotation flipRot, tiltRot, phiOwnAxisRot, phiRot, globalRot; // Identity
127  DDRotationMatrix flipMatrix, tiltMatrix, phiOwnAxisRotMatrix, phiRotMatrix, globalRotMatrix; // Identity matrix
128  string rotstr = "RTrackerRingAlgo";
129 
130  // flipMatrix calculus
131  if (isFlipped) {
132  string flipRotstr = rotstr + "Flip";
133  flipRot = DDRotation(DDName(flipRotstr, idNameSpace));
134  if (!flipRot) {
135  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << flipRotstr
136  << "\t90., 180., "
137  << "90., 90., "
138  << "180., 0.";
139  flipRot = DDrot(DDName(flipRotstr, idNameSpace), 90._deg, 180._deg, 90._deg, 90._deg, 180._deg, 0.);
140  }
141  flipMatrix = flipRot.matrix();
142  }
143  // tiltMatrix calculus
144  if (isZPlus) {
145  string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZPlus";
146  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
147  if (!tiltRot) {
148  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
149  << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 180., "
150  << 90. - convertRadToDeg(tiltAngle) << ", 0.";
151  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 180._deg, 90._deg - tiltAngle, 0.);
152  }
153  tiltMatrix = tiltRot.matrix();
154  if (isFlipped) {
155  tiltMatrix *= flipMatrix;
156  }
157  } else {
158  string tiltRotstr = rotstr + "Tilt" + to_string(convertRadToDeg(tiltAngle)) + "ZMinus";
159  tiltRot = DDRotation(DDName(tiltRotstr, idNameSpace));
160  if (!tiltRot) {
161  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << tiltRotstr
162  << "\t90., 90., " << convertRadToDeg(tiltAngle) << ", 0., "
163  << 90. + convertRadToDeg(tiltAngle) << ", 0.";
164  tiltRot = DDrot(DDName(tiltRotstr, idNameSpace), 90._deg, 90._deg, tiltAngle, 0., 90._deg + tiltAngle, 0.);
165  }
166  tiltMatrix = tiltRot.matrix();
167  if (isFlipped) {
168  tiltMatrix *= flipMatrix;
169  }
170  }
171 
172  // Loops for all phi values
173  DDName mother = parent().name();
174  DDName child(DDSplit(childName).first, DDSplit(childName).second);
175  double theta = 90._deg;
176  int copy = startCopyNo;
177  //double phi = startAngle;
178 
179  for (int i = 0; i < n; i++) {
180  // phiRotMatrix calculus
181  //double phix = phi;
182  //double phix_ownaxis = 0._deg;
183  double phix = convertDegToRad(phiAngles.at(i));
184  double phix_ownaxis = convertDegToRad(yawAngles.at(i));
185  radius = radiusValues.at(i);
186  double phiy = phix + 90._deg;
187  double phiy_ownaxis = phix_ownaxis + 90._deg;
188  double phideg = convertRadToDeg(phix);
189  double phideg_ownaxis = convertRadToDeg(phix_ownaxis);
190  if (phideg_ownaxis != 0) {
191  string phiOwnAxisRotstr = rotstr + "PhiOwnAxis" + to_string(phideg_ownaxis * 10.);
192  phiOwnAxisRot = DDRotation(DDName(phiOwnAxisRotstr, idNameSpace));
193  if (!phiOwnAxisRot) {
194  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiOwnAxisRotstr
195  << "\t90., " << convertRadToDeg(phix_ownaxis) << ", 90.,"
196  << convertRadToDeg(phiy_ownaxis) << ", 0., 0.";
197  phiOwnAxisRot = DDrot(DDName(phiOwnAxisRotstr, idNameSpace), theta, phix_ownaxis, theta, phiy_ownaxis, 0., 0.);
198  }
199  phiOwnAxisRotMatrix = phiOwnAxisRot.matrix();
200  }
201  if (phideg != 0) {
202  string phiRotstr = rotstr + "Phi" + to_string(phideg * 10.);
203  phiRot = DDRotation(DDName(phiRotstr, idNameSpace));
204  if (!phiRot) {
205  LogDebug("TrackerGeom") << "DDTrackerIrregularRingAlgo test: Creating a new rotation: " << phiRotstr
206  << "\t90., " << convertRadToDeg(phix) << ", 90.," << convertRadToDeg(phiy)
207  << ", 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(convertRadToDeg(tiltAngle));
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") << "DDTrackerIrregularRingAlgo test: Creating a new "
229  << "rotation: " << globalRotstr;
230  globalRotMatrix = phiOwnAxisRotMatrix * phiRotMatrix * tiltMatrix;
231  globalRot = DDrot(DDName(globalRotstr, idNameSpace), make_unique<DDRotationMatrix>(globalRotMatrix));
232  }
233 
234  // translation def
235  double xpos = radius * cos(phix) + center[0];
236  double ypos = radius * sin(phix) + 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") << "DDTrackerIrregularRingAlgo test " << child << " number " << copy << " positioned in "
243  << mother << " at " << tran << " with " << globalRot;
244 
245  copy += incrCopyNo;
246  }
247 }
248 
249 DEFINE_EDM_PLUGIN(DDAlgorithmFactory, DDTrackerIrregularRingAlgo, "track:DDTrackerIrregularRingAlgo");
static AlgebraicMatrix initialize()
constexpr double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
void position(const DDLogicalPart &self, const DDLogicalPart &parent, const std::string &copyno, const DDTranslation &trans, const DDRotation &rot, const DDDivision *div=nullptr)
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
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
void initialize(const DDNumericArguments &nArgs, const DDVectorArguments &vArgs, const DDMapArguments &mArgs, const DDStringArguments &sArgs, const DDStringVectorArguments &vsArgs) override
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
U second(std::pair< T, U > const &p)
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
void execute(DDCompactView &cpv) 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
~DDTrackerIrregularRingAlgo() override
DDRotationMatrix & matrix()
Definition: DDTransform.h:85
#define LogDebug(id)