-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
GeometricDet.cc
305 lines (279 loc) · 11.2 KB
/
GeometricDet.cc
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#include "Geometry/TrackerNumberingBuilder/interface/GeometricDet.h"
#include "Geometry/TrackerNumberingBuilder/interface/TrackerShapeToBounds.h"
#include "DetectorDescription/Core/interface/DDFilteredView.h"
#include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
#include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
#include "CLHEP/Units/GlobalSystemOfUnits.h"
#include "DataFormats/Math/interface/GeantUnits.h"
#include <cfloat>
#include <string>
namespace {
const std::string strue("true");
template <typename DDView>
double getDouble(const char* s, DDView const& ev) {
DDValue val(s);
std::vector<const DDsvalues_type*> result;
ev.specificsV(result);
std::vector<const DDsvalues_type*>::iterator it = result.begin();
bool foundIt = false;
for (; it != result.end(); ++it) {
foundIt = DDfetch(*it, val);
if (foundIt)
break;
}
if (foundIt) {
const std::vector<std::string>& temp = val.strings();
if (temp.size() != 1) {
throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
}
return double(::atof(temp[0].c_str()));
}
return 0;
}
template <typename DDView>
std::string getString(const char* s, DDView const& ev) {
DDValue val(s);
std::vector<const DDsvalues_type*> result;
ev.specificsV(result);
std::vector<const DDsvalues_type*>::iterator it = result.begin();
bool foundIt = false;
for (; it != result.end(); ++it) {
foundIt = DDfetch(*it, val);
if (foundIt)
break;
}
if (foundIt) {
const std::vector<std::string>& temp = val.strings();
if (temp.size() != 1) {
throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
}
return temp[0];
}
return "NotFound";
}
} // namespace
/**
* What to do in the destructor?
* destroy all the daughters!
*/
GeometricDet::~GeometricDet() { deleteComponents(); }
/*
Constructor from old DD Filtered view.
*/
GeometricDet::GeometricDet(DDFilteredView* fv, GeometricEnumType type)
: trans_(fv->translation()),
phi_(trans_.Phi()),
rho_(trans_.Rho()),
rot_(fv->rotation()),
shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, fv->shape())),
ddname_(fv->name()),
type_(type),
params_(fv->parameters()),
radLength_(getDouble("TrackerRadLength", *fv)),
xi_(getDouble("TrackerXi", *fv)),
pixROCRows_(getDouble("PixelROCRows", *fv)),
pixROCCols_(getDouble("PixelROCCols", *fv)),
pixROCx_(getDouble("PixelROC_X", *fv)),
pixROCy_(getDouble("PixelROC_Y", *fv)),
stereo_(getString("TrackerStereoDetectors", *fv) == strue),
isLowerSensor_(getString("TrackerLowerDetectors", *fv) == strue),
isUpperSensor_(getString("TrackerUpperDetectors", *fv) == strue),
siliconAPVNum_(getDouble("SiliconAPVNumber", *fv)),
isFromDD4hep_(false) {
// workaround instead of this at initialization ddd_(fv->navPos().begin(),fv->navPos().end()),
const DDFilteredView::nav_type& nt = fv->navPos();
ddd_ = nav_type(nt.begin(), nt.end());
}
/*
Constructor from DD4HEP Filtered view.
*/
GeometricDet::GeometricDet(cms::DDFilteredView* fv, GeometricEnumType type)
: trans_(geant_units::operators::convertCmToMm(fv->translation())),
phi_(trans_.Phi()),
rho_(trans_.Rho()),
rot_(fv->rotation()),
shape_(fv->shape()),
ddd_(fv->navPos()), // To be studied
ddname_(dd4hep::dd::noNamespace(fv->name())),
type_(type),
params_(computeLegacyShapeParameters(shape_, fv->solid())),
radLength_(fv->get<double>("TrackerRadLength")), // To be studied
xi_(fv->get<double>("TrackerXi")), // To be studied
pixROCRows_(fv->get<double>("PixelROCRows")),
pixROCCols_(fv->get<double>("PixelROCCols")),
pixROCx_(fv->get<double>("PixelROC_X")),
pixROCy_(fv->get<double>("PixelROC_Y")),
stereo_(fv->get<std::string_view>("TrackerStereoDetectors") == strue),
isLowerSensor_(fv->get<std::string_view>("TrackerLowerDetectors") == strue),
isUpperSensor_(fv->get<std::string_view>("TrackerUpperDetectors") == strue),
siliconAPVNum_(fv->get<double>("SiliconAPVNumber")),
isFromDD4hep_(true) {}
// PGeometricDet is persistent version... make it... then come back here and make the
// constructor.
GeometricDet::GeometricDet(const PGeometricDet::Item& onePGD, GeometricEnumType type)
: trans_(onePGD._x, onePGD._y, onePGD._z),
phi_(onePGD._phi), //trans_.Phi()),
rho_(onePGD._rho), //trans_.Rho()),
rot_(onePGD._a11,
onePGD._a12,
onePGD._a13,
onePGD._a21,
onePGD._a22,
onePGD._a23,
onePGD._a31,
onePGD._a32,
onePGD._a33),
shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, static_cast<LegacySolidShape>(onePGD._shape))),
ddd_(),
ddname_(onePGD._name),
type_(type),
params_(),
geographicalID_(onePGD._geographicalID),
radLength_(onePGD._radLength),
xi_(onePGD._xi),
pixROCRows_(onePGD._pixROCRows),
pixROCCols_(onePGD._pixROCCols),
pixROCx_(onePGD._pixROCx),
pixROCy_(onePGD._pixROCy),
stereo_(onePGD._stereo),
siliconAPVNum_(onePGD._siliconAPVNum) {
if (onePGD._shape == 1 || onePGD._shape == 3) { //The parms vector is neede only in the case of box or trap shape
params_.reserve(11);
params_.emplace_back(onePGD._params0);
params_.emplace_back(onePGD._params1);
params_.emplace_back(onePGD._params2);
params_.emplace_back(onePGD._params3);
params_.emplace_back(onePGD._params4);
params_.emplace_back(onePGD._params5);
params_.emplace_back(onePGD._params6);
params_.emplace_back(onePGD._params7);
params_.emplace_back(onePGD._params8);
params_.emplace_back(onePGD._params9);
params_.emplace_back(onePGD._params10);
}
ddd_.reserve(onePGD._numnt);
ddd_.emplace_back(onePGD._nt0);
ddd_.emplace_back(onePGD._nt1);
ddd_.emplace_back(onePGD._nt2);
ddd_.emplace_back(onePGD._nt3);
if (onePGD._numnt > 4) {
ddd_.emplace_back(onePGD._nt4);
if (onePGD._numnt > 5) {
ddd_.emplace_back(onePGD._nt5);
if (onePGD._numnt > 6) {
ddd_.emplace_back(onePGD._nt6);
if (onePGD._numnt > 7) {
ddd_.emplace_back(onePGD._nt7);
if (onePGD._numnt > 8) {
ddd_.emplace_back(onePGD._nt8);
if (onePGD._numnt > 9) {
ddd_.emplace_back(onePGD._nt9);
if (onePGD._numnt > 10) {
ddd_.emplace_back(onePGD._nt10);
}
}
}
}
}
}
}
}
GeometricDet::ConstGeometricDetContainer GeometricDet::deepComponents() const {
//
// iterate on all the components ;)
//
ConstGeometricDetContainer temp_;
deepComponents(temp_);
return temp_;
}
void GeometricDet::deepComponents(ConstGeometricDetContainer& cont) const {
if (isLeaf())
cont.emplace_back(this);
else
std::for_each(container_.begin(), container_.end(), [&](const GeometricDet* iDet) { iDet->deepComponents(cont); });
}
void GeometricDet::addComponents(GeometricDetContainer const& cont) {
container_.reserve(container_.size() + cont.size());
std::copy(cont.begin(), cont.end(), back_inserter(container_));
}
void GeometricDet::addComponents(ConstGeometricDetContainer const& cont) {
container_.reserve(container_.size() + cont.size());
std::copy(cont.begin(), cont.end(), back_inserter(container_));
}
void GeometricDet::addComponent(GeometricDet* det) { container_.emplace_back(det); }
namespace {
struct Deleter {
void operator()(GeometricDet const* det) const { delete const_cast<GeometricDet*>(det); }
};
} // namespace
void GeometricDet::deleteComponents() {
std::for_each(container_.begin(), container_.end(), Deleter());
container_.clear();
}
GeometricDet::Position GeometricDet::positionBounds() const {
Position pos_(float(trans_.x() / cm), float(trans_.y() / cm), float(trans_.z() / cm));
return pos_;
}
GeometricDet::Rotation GeometricDet::rotationBounds() const {
Translation x, y, z;
rot_.GetComponents(x, y, z);
Rotation rotation_(float(x.X()),
float(x.Y()),
float(x.Z()),
float(y.X()),
float(y.Y()),
float(y.Z()),
float(z.X()),
float(z.Y()),
float(z.Z()));
return rotation_;
}
std::unique_ptr<Bounds> GeometricDet::bounds() const {
const std::vector<double>& par = params_;
TrackerShapeToBounds shapeToBounds;
return std::unique_ptr<Bounds>(shapeToBounds.buildBounds(shape_, par));
}
/*
* DD4hep.
* Keep order and units of parameters same as old DD, to avoid numerous regressions.
* Shape parameters of interest, and those to be stored in DB, are only from boxes, trapezoids, and tubs.
* Hence, they are the only shapes treated here.
* params() will complain, if the parameters of any other shape are accessed.
*/
std::vector<double> GeometricDet::computeLegacyShapeParameters(const cms::DDSolidShape& mySolidShape,
const dd4hep::Solid& mySolid) const {
std::vector<double> myOldDDShapeParameters;
// Box
if (mySolidShape == cms::DDSolidShape::ddbox) {
const dd4hep::Box& myBox = dd4hep::Box(mySolid);
myOldDDShapeParameters = {geant_units::operators::convertCmToMm(myBox.x()),
geant_units::operators::convertCmToMm(myBox.y()),
geant_units::operators::convertCmToMm(myBox.z())};
}
// Trapezoid
else if (mySolidShape == cms::DDSolidShape::ddtrap) {
const dd4hep::Trap& myTrap = dd4hep::Trap(mySolid);
myOldDDShapeParameters = {geant_units::operators::convertCmToMm(myTrap->GetDZ()),
static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetTheta())),
static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetPhi())),
geant_units::operators::convertCmToMm(myTrap->GetH1()),
geant_units::operators::convertCmToMm(myTrap->GetBl1()),
geant_units::operators::convertCmToMm(myTrap->GetTl1()),
static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetAlpha1())),
geant_units::operators::convertCmToMm(myTrap->GetH2()),
geant_units::operators::convertCmToMm(myTrap->GetBl2()),
geant_units::operators::convertCmToMm(myTrap->GetTl2()),
static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetAlpha2()))};
}
// Tub
else if (mySolidShape == cms::DDSolidShape::ddtubs) {
const dd4hep::Tube& myTube = dd4hep::Tube(mySolid);
myOldDDShapeParameters = {
geant_units::operators::convertCmToMm(myTube->GetDz()),
geant_units::operators::convertCmToMm(myTube->GetRmin()),
geant_units::operators::convertCmToMm(myTube->GetRmax()),
static_cast<double>(angle_units::operators::convertDegToRad(myTube->GetPhi1())),
static_cast<double>(angle_units::operators::convertDegToRad(myTube->GetPhi2() - myTube->GetPhi1()))};
}
return myOldDDShapeParameters;
}