CMS 3D CMS Logo

GeometricDet.cc
Go to the documentation of this file.
1 #include <DD4hep/DD4hepUnits.h>
2 
9 
10 #include <cfloat>
11 #include <string>
12 
13 namespace {
14 
15  const std::string strue("true");
16 
17  template <typename DDView>
18  double getDouble(const char* s, DDView const& ev) {
19  DDValue val(s);
20  std::vector<const DDsvalues_type*> result;
21  ev.specificsV(result);
22  std::vector<const DDsvalues_type*>::iterator it = result.begin();
23  bool foundIt = false;
24  for (; it != result.end(); ++it) {
25  foundIt = DDfetch(*it, val);
26  if (foundIt)
27  break;
28  }
29  if (foundIt) {
30  const std::vector<std::string>& temp = val.strings();
31  if (temp.size() != 1) {
32  throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
33  }
34  return double(::atof(temp[0].c_str()));
35  }
36  return 0;
37  }
38 
39  template <typename DDView>
40  std::string getString(const char* s, DDView const& ev) {
41  DDValue val(s);
42  std::vector<const DDsvalues_type*> result;
43  ev.specificsV(result);
44  std::vector<const DDsvalues_type*>::iterator it = result.begin();
45  bool foundIt = false;
46  for (; it != result.end(); ++it) {
47  foundIt = DDfetch(*it, val);
48  if (foundIt)
49  break;
50  }
51  if (foundIt) {
52  const std::vector<std::string>& temp = val.strings();
53  if (temp.size() != 1) {
54  throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
55  }
56  return temp[0];
57  }
58  return "NotFound";
59  }
60 } // namespace
61 
67 
68 /*
69  Constructor from old DD Filtered view.
70 */
72  : ddname_(fv->name()),
73  type_(type),
74  ddd_(), // To remove after DetExtra is removed (not used)
75  trans_(fv->translation()),
76  rho_(trans_.Rho()),
77  phi_(trans_.Phi()),
78  rot_(fv->rotation()),
79  shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, fv->shape())),
80  params_(fv->parameters()),
81  isFromDD4hep_(false) {
82  // workaround instead of this at initialization
83  const DDFilteredView::nav_type& nt = fv->navPos();
84  ddd_ = nav_type(nt.begin(), nt.end());
85 
86  // Only look for sensor-related info on sensor volumes!
87  if (type_ == DetUnit) {
88  radLength_ = getDouble("TrackerRadLength", *fv);
89  xi_ = getDouble("TrackerXi", *fv);
90  pixROCRows_ = getDouble("PixelROCRows", *fv);
91  pixROCCols_ = getDouble("PixelROCCols", *fv);
92  pixROCx_ = getDouble("PixelROC_X", *fv);
93  pixROCy_ = getDouble("PixelROC_Y", *fv);
94  stereo_ = (getString("TrackerStereoDetectors", *fv) == strue);
95  isLowerSensor_ = (getString("TrackerLowerDetectors", *fv) == strue);
96  isUpperSensor_ = (getString("TrackerUpperDetectors", *fv) == strue);
97  siliconAPVNum_ = getDouble("SiliconAPVNumber", *fv);
98  }
99 }
100 
101 /*
102  Constructor from DD4HEP Filtered view.
103 */
105  : ddname_(dd4hep::dd::noNamespace(fv->name())),
106  type_(type),
107  ddd_(fv->navPos()), // To remove after DetExtra is removed (not used)
108  trans_((fv->translation()) / dd4hep::mm),
109  rho_(trans_.Rho()),
110  phi_(trans_.Phi()),
111  rot_(fv->rotation()),
112  shape_(fv->shape()),
113  params_(computeLegacyShapeParameters(shape_, fv->solid())),
114  isFromDD4hep_(true) {
115  // Only look for sensor-related info on sensor volumes!
116  if (type_ == DetUnit) {
117  // IT sensors only (NB: hence could add a branch here, but not a critical part on perf)
118  pixROCRows_ = fv->get<double>("PixelROCRows");
119  pixROCCols_ = fv->get<double>("PixelROCCols");
120  pixROCx_ = fv->get<double>("PixelROC_X");
121  pixROCy_ = fv->get<double>("PixelROC_Y");
122 
123  // Phase 1 OT sensors only (NB: hence could add a branch here, but not a critical part on perf)
124  stereo_ = (fv->get<std::string_view>("TrackerStereoDetectors") == strue);
125  siliconAPVNum_ = fv->get<double>("SiliconAPVNumber");
126 
127  // Phase 2 OT sensors only (NB: hence could add a branch here, but not a critical part on perf)
128  isLowerSensor_ = (fv->get<std::string_view>("TrackerLowerDetectors") == strue);
129  isUpperSensor_ = (fv->get<std::string_view>("TrackerUpperDetectors") == strue);
130 
131  // All sensors: IT or OT, Phase 1 or Phase 2 (NB: critical part on perf)
132  fv->findSpecPar("TrackerRadLength", "TrackerXi");
133  radLength_ = fv->getNextValue("TrackerRadLength");
134  xi_ = fv->getNextValue("TrackerXi");
135  }
136 }
137 
138 /*
139  Constructor from persistent version (DB).
140 */
142  : ddname_(onePGD._name),
143  type_(type),
144  ddd_(),
145  geographicalID_(onePGD._geographicalID),
146  trans_(onePGD._x, onePGD._y, onePGD._z),
147  rho_(onePGD._rho),
148  phi_(onePGD._phi),
149  rot_(onePGD._a11,
150  onePGD._a12,
151  onePGD._a13,
152  onePGD._a21,
153  onePGD._a22,
154  onePGD._a23,
155  onePGD._a31,
156  onePGD._a32,
157  onePGD._a33),
158  shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, static_cast<LegacySolidShape>(onePGD._shape))),
159  params_(),
160  radLength_(onePGD._radLength),
161  xi_(onePGD._xi),
162  pixROCRows_(onePGD._pixROCRows),
163  pixROCCols_(onePGD._pixROCCols),
164  pixROCx_(onePGD._pixROCx),
165  pixROCy_(onePGD._pixROCy),
166  stereo_(onePGD._stereo),
167  siliconAPVNum_(onePGD._siliconAPVNum)
168 // NB: what about new data members isLowerSensor_, isUpperSensor_, isFromDD4hep_?
169 // They are presently not added to PGeometricDet (no change in info stored into DB).
170 {
171  // Solid shape parameters: only for box (1) and trapezoid (3)
172  if (onePGD._shape == 1 || onePGD._shape == 3) {
173  params_.reserve(11);
174  params_.emplace_back(onePGD._params0);
175  params_.emplace_back(onePGD._params1);
176  params_.emplace_back(onePGD._params2);
177  params_.emplace_back(onePGD._params3);
178  params_.emplace_back(onePGD._params4);
179  params_.emplace_back(onePGD._params5);
180  params_.emplace_back(onePGD._params6);
181  params_.emplace_back(onePGD._params7);
182  params_.emplace_back(onePGD._params8);
183  params_.emplace_back(onePGD._params9);
184  params_.emplace_back(onePGD._params10);
185  }
186 
187  ddd_.reserve(onePGD._numnt);
188  ddd_.emplace_back(onePGD._nt0);
189  ddd_.emplace_back(onePGD._nt1);
190  ddd_.emplace_back(onePGD._nt2);
191  ddd_.emplace_back(onePGD._nt3);
192  if (onePGD._numnt > 4) {
193  ddd_.emplace_back(onePGD._nt4);
194  if (onePGD._numnt > 5) {
195  ddd_.emplace_back(onePGD._nt5);
196  if (onePGD._numnt > 6) {
197  ddd_.emplace_back(onePGD._nt6);
198  if (onePGD._numnt > 7) {
199  ddd_.emplace_back(onePGD._nt7);
200  if (onePGD._numnt > 8) {
201  ddd_.emplace_back(onePGD._nt8);
202  if (onePGD._numnt > 9) {
203  ddd_.emplace_back(onePGD._nt9);
204  if (onePGD._numnt > 10) {
205  ddd_.emplace_back(onePGD._nt10);
206  }
207  }
208  }
209  }
210  }
211  }
212  }
213 }
214 
215 std::unique_ptr<Bounds> GeometricDet::bounds() const {
216  TrackerShapeToBounds shapeToBounds;
217  return std::unique_ptr<Bounds>(shapeToBounds.buildBounds(shape_, params_));
218 }
219 
221  Position pos_(static_cast<float>(geant_units::operators::convertMmToCm(trans_.x())),
222  static_cast<float>(geant_units::operators::convertMmToCm(trans_.y())),
223  static_cast<float>(geant_units::operators::convertMmToCm(trans_.z())));
224  return pos_;
225 }
226 
228  Translation x, y, z;
229  rot_.GetComponents(x, y, z);
230  Rotation rotation_(float(x.X()),
231  float(x.Y()),
232  float(x.Z()),
233  float(y.X()),
234  float(y.Y()),
235  float(y.Z()),
236  float(z.X()),
237  float(z.Y()),
238  float(z.Z()));
239  return rotation_;
240 }
241 
243  // iterate on all the DESCENDANTS!!
245  deepComponents(temp_);
246  return temp_;
247 }
248 
250  if (isLeaf())
251  cont.emplace_back(this);
252  else
253  std::for_each(container_.begin(), container_.end(), [&](const GeometricDet* iDet) { iDet->deepComponents(cont); });
254 }
255 
257  container_.reserve(container_.size() + cont.size());
258  std::copy(cont.begin(), cont.end(), back_inserter(container_));
259 }
260 
262  container_.reserve(container_.size() + cont.size());
263  std::copy(cont.begin(), cont.end(), back_inserter(container_));
264 }
265 
266 void GeometricDet::addComponent(GeometricDet* det) { container_.emplace_back(det); }
267 
268 namespace {
269  struct Deleter {
270  void operator()(GeometricDet const* det) const { delete const_cast<GeometricDet*>(det); }
271  };
272 } // namespace
273 
275  std::for_each(container_.begin(), container_.end(), Deleter());
276  container_.clear();
277 }
278 
279 /*
280  * PRIVATE
281  */
282 
283 /*
284  * DD4hep.
285  * Keep order and units of parameters same as old DD, to avoid numerous regressions.
286  * Shape parameters of interest, and those to be stored in DB, are only from boxes, trapezoids, and tubs.
287  * Hence, they are the only shapes treated here.
288  * params() will complain, if the parameters of any other shape are accessed.
289  */
290 std::vector<double> GeometricDet::computeLegacyShapeParameters(const cms::DDSolidShape& mySolidShape,
291  const dd4hep::Solid& mySolid) const {
292  std::vector<double> myOldDDShapeParameters;
293 
294  // Box
295  if (mySolidShape == cms::DDSolidShape::ddbox) {
296  const dd4hep::Box& myBox = dd4hep::Box(mySolid);
297  myOldDDShapeParameters = {(myBox.x()) / dd4hep::mm, (myBox.y()) / dd4hep::mm, (myBox.z()) / dd4hep::mm};
298  }
299 
300  // Trapezoid
301  else if (mySolidShape == cms::DDSolidShape::ddtrap) {
302  const dd4hep::Trap& myTrap = dd4hep::Trap(mySolid);
303  myOldDDShapeParameters = {(myTrap->GetDZ()) / dd4hep::mm,
304  static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetTheta())),
305  static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetPhi())),
306  (myTrap->GetH1()) / dd4hep::mm,
307  (myTrap->GetBl1()) / dd4hep::mm,
308  (myTrap->GetTl1()) / dd4hep::mm,
309  static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetAlpha1())),
310  (myTrap->GetH2()) / dd4hep::mm,
311  (myTrap->GetBl2()) / dd4hep::mm,
312  (myTrap->GetTl2()) / dd4hep::mm,
313  static_cast<double>(angle_units::operators::convertDegToRad(myTrap->GetAlpha2()))};
314  }
315 
316  // Tub
317  else if (mySolidShape == cms::DDSolidShape::ddtubs) {
318  const dd4hep::Tube& myTube = dd4hep::Tube(mySolid);
319  myOldDDShapeParameters = {
320  (myTube->GetDz()) / dd4hep::mm,
321  (myTube->GetRmin()) / dd4hep::mm,
322  (myTube->GetRmax()) / dd4hep::mm,
323  static_cast<double>(fmod(angle_units::operators::convertDegToRad(myTube->GetPhi1()), 2. * M_PI) - 2. * M_PI),
324  static_cast<double>(angle_units::operators::convertDegToRad(myTube->GetPhi2() - myTube->GetPhi1()))};
325  }
326 
327  return myOldDDShapeParameters;
328 }
PGeometricDet::Item::_params3
double _params3
Definition: PGeometricDet.h:25
TkRotation< float >
DDAxes::y
BeamSpotPI::parameters
parameters
Definition: BeamSpotPayloadInspectorHelper.h:30
GeometricDet::rot_
RotationMatrix rot_
Definition: GeometricDet.h:179
GeometricDet::positionBounds
Position positionBounds() const
Definition: GeometricDet.cc:220
PGeometricDet::Item::_params6
double _params6
Definition: PGeometricDet.h:25
DDSolidShape
DDSolidShape
Definition: DDSolidShapes.h:6
funct::false
false
Definition: Factorize.h:29
cms::DDSolidShape::ddtubs
PGeometricDet::Item::_nt0
int _nt0
Definition: PGeometricDet.h:42
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
nt
int nt
Definition: AMPTWrapper.h:42
GeometricDet::isUpperSensor_
bool isUpperSensor_
Definition: GeometricDet.h:192
PGeometricDet::Item::_params4
double _params4
Definition: PGeometricDet.h:25
cms::LegacySolidShapeMap
const std::array< const cms::dd::ValuePair< LegacySolidShape, cms::DDSolidShape >, 20 > LegacySolidShapeMap
Definition: DDSolidShapes.h:118
GeometricDet::DetUnit
Definition: GeometricDet.h:65
GeometricDet::~GeometricDet
~GeometricDet()
Definition: GeometricDet.cc:66
angle_units::operators::convertDegToRad
constexpr long double convertDegToRad(NumType degrees)
Definition: angle_units.h:27
DDFilteredView::navPos
nav_type navPos() const
return the stack of sibling numbers
Definition: DDFilteredView.cc:191
generateEDF.cont
cont
load Luminosity info ##
Definition: generateEDF.py:629
GeometricDet::pixROCx_
double pixROCx_
Definition: GeometricDet.h:188
PGeometricDet::Item::_nt5
int _nt5
Definition: PGeometricDet.h:42
GeometricDet::isLowerSensor_
bool isLowerSensor_
Definition: GeometricDet.h:191
PGeometricDet::Item::_nt3
int _nt3
Definition: PGeometricDet.h:42
GeometricDet::container_
ConstGeometricDetContainer container_
Definition: GeometricDet.h:197
DDAxes::x
GeometricDet::pixROCCols_
double pixROCCols_
Definition: GeometricDet.h:187
cms::DDFilteredView
Definition: DDFilteredView.h:70
PGeometricDet::Item::_nt7
int _nt7
Definition: PGeometricDet.h:42
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
cms::dd::name_from_value
Mapping::value_type::name_type name_from_value(Mapping a, V value)
Definition: DDSolidShapes.h:62
GeometricDet::rotationBounds
Rotation rotationBounds() const
Definition: GeometricDet.cc:227
cms::DDFilteredView::findSpecPar
void findSpecPar(T const &first, Ts const &... rest)
find a current Node SpecPar that has at least
Definition: DDFilteredView.h:230
GeometricDet::xi_
double xi_
Definition: GeometricDet.h:185
cms::DDFilteredView::get
T get(const std::string &)
extract attribute value
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DDFilteredView.h
GeometricDet::deleteComponents
void deleteComponents()
Definition: GeometricDet.cc:274
DDAxes::z
GeometricDet::computeLegacyShapeParameters
std::vector< double > computeLegacyShapeParameters(const cms::DDSolidShape &mySolidShape, const dd4hep::Solid &mySolid) const
Definition: GeometricDet.cc:290
GeometricDet
Definition: GeometricDet.h:31
PGeometricDet::Item::_nt1
int _nt1
Definition: PGeometricDet.h:42
DDfetch
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
DDFilteredView.h
VtxSmearedParameters_cfi.Phi
Phi
Definition: VtxSmearedParameters_cfi.py:112
Point3DBase< float, GlobalTag >
createTree.dd
string dd
Definition: createTree.py:154
GeometricDet::GeometricEnumType
enum GeometricDet::GDEnumType GeometricEnumType
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::DDSolidShape
DDSolidShape
Definition: DDSolidShapes.h:73
PGeometricDet::Item
Definition: PGeometricDet.h:14
PGeometricDet::Item::_params8
double _params8
Definition: PGeometricDet.h:25
GeometricDet::nav_type
std::vector< int > nav_type
Definition: GeometricDet.h:42
funct::true
true
Definition: Factorize.h:173
PGeometricDet::Item::_nt6
int _nt6
Definition: PGeometricDet.h:42
PGeometricDet::Item::_nt9
int _nt9
Definition: PGeometricDet.h:42
GeometricDet::ddd_
nav_type ddd_
Definition: GeometricDet.h:173
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
PGeometricDet::Item::_params9
double _params9
Definition: PGeometricDet.h:25
GeantUnits.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
GeometricDet::trans_
Translation trans_
Definition: GeometricDet.h:176
PGeometricDet::Item::_nt2
int _nt2
Definition: PGeometricDet.h:42
GeometricDet::type_
GeometricEnumType type_
Definition: GeometricDet.h:171
GeometricDet::radLength_
double radLength_
Definition: GeometricDet.h:184
cms::DDSolidShape::ddtrap
cms::DDSolidShape::ddbox
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
GeometricDet::addComponents
void addComponents(GeometricDetContainer const &cont)
Definition: GeometricDet.cc:256
PGeometricDet::Item::_numnt
int _numnt
Definition: PGeometricDet.h:41
PGeometricDet::Item::_params1
double _params1
Definition: PGeometricDet.h:25
PGeometricDet::Item::_nt8
int _nt8
Definition: PGeometricDet.h:42
GeometricDet::GeometricDet
GeometricDet(DDFilteredView *fv, GeometricEnumType dd)
Definition: GeometricDet.cc:71
PGeometricDet::Item::_nt4
int _nt4
Definition: PGeometricDet.h:42
PGeometricDet::Item::_params7
double _params7
Definition: PGeometricDet.h:25
GeometricDet::deepComponents
ConstGeometricDetContainer deepComponents() const
Definition: GeometricDet.cc:242
GeometricDet.h
PGeometricDet::Item::_shape
int _shape
Definition: PGeometricDet.h:36
PGeometricDet::Item::_nt10
int _nt10
Definition: PGeometricDet.h:42
cms::DDFilteredView::getNextValue
double getNextValue(const std::string &) const
extract another value from the same SpecPar
Definition: DDFilteredView.cc:841
GeometricDet::stereo_
bool stereo_
Definition: GeometricDet.h:190
heppy_batch.val
val
Definition: heppy_batch.py:351
PGeometricDet::Item::_params5
double _params5
Definition: PGeometricDet.h:25
GeometricDet::bounds
std::unique_ptr< Bounds > bounds() const
Definition: GeometricDet.cc:215
GeometricDet::Translation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > Translation
Definition: GeometricDet.h:37
GeometricDet::ConstGeometricDetContainer
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:34
DDValue
Definition: DDValue.h:21
GeometricDet::pixROCRows_
double pixROCRows_
Definition: GeometricDet.h:186
dd4hep
Definition: DDPlugins.h:8
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
Exception
Definition: hltDiff.cc:245
TrackerShapeToBounds.h
GeometricDet::siliconAPVNum_
double siliconAPVNum_
Definition: GeometricDet.h:193
GeometricDet::shape_
cms::DDSolidShape shape_
Definition: GeometricDet.h:181
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
GeometricDet::pixROCy_
double pixROCy_
Definition: GeometricDet.h:189
GeometricDet::isLeaf
bool isLeaf() const
Definition: GeometricDet.h:146
GeometricDet::GeometricDetContainer
std::vector< GeometricDet * > GeometricDetContainer
Definition: GeometricDet.h:35
PGeometricDet.h
DDFilteredView
Definition: DDFilteredView.h:20
geant_units::operators::convertMmToCm
constexpr NumType convertMmToCm(NumType millimeters)
Definition: GeantUnits.h:62
mps_fire.result
result
Definition: mps_fire.py:311
TrackerShapeToBounds
Definition: TrackerShapeToBounds.h:11
PGeometricDet::Item::_params0
double _params0
Definition: PGeometricDet.h:25
DDFilteredView::nav_type
DDExpandedView::nav_type nav_type
Definition: DDFilteredView.h:22
PGeometricDet::Item::_params2
double _params2
Definition: PGeometricDet.h:25
PGeometricDet::Item::_params10
double _params10
Definition: PGeometricDet.h:25
GeometricDet::addComponent
void addComponent(GeometricDet *)
Definition: GeometricDet.cc:266
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21
GeometricDet::params_
std::vector< double > params_
Definition: GeometricDet.h:182
TrackerShapeToBounds::buildBounds
Bounds * buildBounds(const cms::DDSolidShape &, const std::vector< double > &) const
Definition: TrackerShapeToBounds.cc:32