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