CMS 3D CMS Logo

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