File indexing completed on 2024-04-06 12:15:17
0001 #include "Geometry/MTDNumberingBuilder/interface/GeometricTimingDet.h"
0002 #include "Geometry/TrackerNumberingBuilder/interface/TrackerShapeToBounds.h"
0003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0004 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0005 #include "CondFormats/GeometryObjects/interface/PGeometricTimingDet.h"
0006
0007 #include "DataFormats/Math/interface/GeantUnits.h"
0008 #include <DD4hep/DD4hepUnits.h>
0009
0010 #include <cfloat>
0011 #include <vector>
0012 #include <string>
0013
0014 namespace {
0015
0016 const std::string strue("true");
0017
0018 template <typename DDView>
0019 double getDouble(const char* s, DDView const& ev) {
0020 DDValue val(s);
0021 std::vector<const DDsvalues_type*> result;
0022 ev.specificsV(result);
0023 std::vector<const DDsvalues_type*>::iterator it = result.begin();
0024 bool foundIt = false;
0025 for (; it != result.end(); ++it) {
0026 foundIt = DDfetch(*it, val);
0027 if (foundIt)
0028 break;
0029 }
0030 if (foundIt) {
0031 const std::vector<std::string>& temp = val.strings();
0032 if (temp.size() != 1) {
0033 throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
0034 }
0035 return double(::atof(temp[0].c_str()));
0036 }
0037 return 0;
0038 }
0039
0040 template <typename DDView>
0041 std::string getString(const char* s, DDView const& ev) {
0042 DDValue val(s);
0043 std::vector<const DDsvalues_type*> result;
0044 ev.specificsV(result);
0045 std::vector<const DDsvalues_type*>::iterator it = result.begin();
0046 bool foundIt = false;
0047 for (; it != result.end(); ++it) {
0048 foundIt = DDfetch(*it, val);
0049 if (foundIt)
0050 break;
0051 }
0052 if (foundIt) {
0053 const std::vector<std::string>& temp = val.strings();
0054 if (temp.size() != 1) {
0055 throw cms::Exception("Configuration") << "I need 1 " << s << " tags";
0056 }
0057 return temp[0];
0058 }
0059 return "NotFound";
0060 }
0061 }
0062
0063
0064
0065
0066
0067 GeometricTimingDet::~GeometricTimingDet() { deleteComponents(); }
0068
0069 GeometricTimingDet::GeometricTimingDet(DDFilteredView* fv, GeometricTimingEnumType type)
0070 :
0071
0072
0073 trans_(fv->translation()),
0074 phi_(trans_.Phi()),
0075 rho_(trans_.Rho()),
0076 rot_(fv->rotation()),
0077 shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, fv->shape())),
0078 ddname_(fv->name()),
0079 type_(type),
0080 params_(fv->parameters()),
0081 radLength_(getDouble("TrackerRadLength", *fv)),
0082 xi_(getDouble("TrackerXi", *fv)),
0083 pixROCRows_(getDouble("PixelROCRows", *fv)),
0084 pixROCCols_(getDouble("PixelROCCols", *fv)),
0085 pixROCx_(getDouble("PixelROC_X", *fv)),
0086 pixROCy_(getDouble("PixelROC_Y", *fv)),
0087 stereo_(getString("TrackerStereoDetectors", *fv) == strue),
0088 siliconAPVNum_(getDouble("SiliconAPVNumber", *fv)) {
0089 const DDFilteredView::nav_type& nt = fv->navPos();
0090 ddd_ = nav_type(nt.begin(), nt.end());
0091 }
0092
0093 GeometricTimingDet::GeometricTimingDet(cms::DDFilteredView* fv, GeometricTimingEnumType type)
0094 : trans_(fv->translation() / dd4hep::mm),
0095 rot_(fv->rotation()),
0096 shape_(fv->shape()),
0097 ddname_(fv->name()),
0098 type_(type),
0099 params_(fv->parameters()),
0100 radLength_(fv->get<double>("TrackerRadLength")),
0101 xi_(fv->get<double>("TrackerXi")),
0102 pixROCRows_(fv->get<double>("PixelROCRows")),
0103 pixROCCols_(fv->get<double>("PixelROCCols")),
0104 pixROCx_(fv->get<double>("PixelROC_X")),
0105 pixROCy_(fv->get<double>("PixelROC_Y")),
0106 stereo_(fv->get<std::string_view>("TrackerStereoDetectors") == strue),
0107 siliconAPVNum_(fv->get<double>("SiliconAPVNumber")) {
0108 phi_ = trans_.Phi();
0109 rho_ = trans_.Rho();
0110 for (size_t pit = 0; pit < params_.size(); pit++) {
0111 params_[pit] = params_[pit] / dd4hep::mm;
0112 }
0113
0114
0115
0116 ddd_ = nav_type(fv->copyNos().size(), 0);
0117 }
0118
0119
0120
0121 GeometricTimingDet::GeometricTimingDet(const PGeometricTimingDet::Item& onePGD, GeometricTimingEnumType type)
0122 : trans_(onePGD.x_, onePGD.y_, onePGD.z_),
0123 phi_(onePGD.phi_),
0124 rho_(onePGD.rho_),
0125 rot_(onePGD.a11_,
0126 onePGD.a12_,
0127 onePGD.a13_,
0128 onePGD.a21_,
0129 onePGD.a22_,
0130 onePGD.a23_,
0131 onePGD.a31_,
0132 onePGD.a32_,
0133 onePGD.a33_),
0134 shape_(cms::dd::name_from_value(cms::LegacySolidShapeMap, static_cast<LegacySolidShape>(onePGD.shape_))),
0135 ddd_(),
0136 ddname_(onePGD.name_),
0137 type_(type),
0138 params_(),
0139 geographicalID_(onePGD.geographicalID_),
0140 radLength_(onePGD.radLength_),
0141 xi_(onePGD.xi_),
0142 pixROCRows_(onePGD.pixROCRows_),
0143 pixROCCols_(onePGD.pixROCCols_),
0144 pixROCx_(onePGD.pixROCx_),
0145 pixROCy_(onePGD.pixROCy_),
0146 stereo_(onePGD.stereo_),
0147 siliconAPVNum_(onePGD.siliconAPVNum_) {
0148 if (onePGD.shape_ == 1 || onePGD.shape_ == 3) {
0149 params_.reserve(11);
0150 params_.emplace_back(onePGD.params_0);
0151 params_.emplace_back(onePGD.params_1);
0152 params_.emplace_back(onePGD.params_2);
0153 params_.emplace_back(onePGD.params_3);
0154 params_.emplace_back(onePGD.params_4);
0155 params_.emplace_back(onePGD.params_5);
0156 params_.emplace_back(onePGD.params_6);
0157 params_.emplace_back(onePGD.params_7);
0158 params_.emplace_back(onePGD.params_8);
0159 params_.emplace_back(onePGD.params_9);
0160 params_.emplace_back(onePGD.params_10);
0161 }
0162
0163 ddd_.reserve(onePGD.numnt_);
0164 ddd_.emplace_back(onePGD.nt0_);
0165 ddd_.emplace_back(onePGD.nt1_);
0166 ddd_.emplace_back(onePGD.nt2_);
0167 ddd_.emplace_back(onePGD.nt3_);
0168 if (onePGD.numnt_ > 4) {
0169 ddd_.emplace_back(onePGD.nt4_);
0170 if (onePGD.numnt_ > 5) {
0171 ddd_.emplace_back(onePGD.nt5_);
0172 if (onePGD.numnt_ > 6) {
0173 ddd_.emplace_back(onePGD.nt6_);
0174 if (onePGD.numnt_ > 7) {
0175 ddd_.emplace_back(onePGD.nt7_);
0176 if (onePGD.numnt_ > 8) {
0177 ddd_.emplace_back(onePGD.nt8_);
0178 if (onePGD.numnt_ > 9) {
0179 ddd_.emplace_back(onePGD.nt9_);
0180 if (onePGD.numnt_ > 10) {
0181 ddd_.emplace_back(onePGD.nt10_);
0182 }
0183 }
0184 }
0185 }
0186 }
0187 }
0188 }
0189 }
0190
0191 GeometricTimingDet::ConstGeometricTimingDetContainer GeometricTimingDet::deepComponents() const {
0192
0193
0194
0195 ConstGeometricTimingDetContainer temp;
0196 deepComponents(temp);
0197 return temp;
0198 }
0199
0200 void GeometricTimingDet::deepComponents(ConstGeometricTimingDetContainer& cont) const {
0201 if (isLeaf()) {
0202 cont.emplace_back(this);
0203 } else
0204 std::for_each(
0205 container_.begin(), container_.end(), [&](const GeometricTimingDet* iDet) { iDet->deepComponents(cont); });
0206 }
0207
0208 void GeometricTimingDet::addComponents(GeometricTimingDetContainer const& cont) {
0209 container_.reserve(container_.size() + cont.size());
0210 std::copy(cont.begin(), cont.end(), back_inserter(container_));
0211 }
0212
0213 void GeometricTimingDet::addComponents(ConstGeometricTimingDetContainer const& cont) {
0214 container_.reserve(container_.size() + cont.size());
0215 std::copy(cont.begin(), cont.end(), back_inserter(container_));
0216 }
0217
0218 void GeometricTimingDet::addComponent(GeometricTimingDet* det) { container_.emplace_back(det); }
0219
0220 namespace {
0221 struct Deleter {
0222 void operator()(GeometricTimingDet const* det) const { delete const_cast<GeometricTimingDet*>(det); }
0223 };
0224 }
0225
0226 void GeometricTimingDet::deleteComponents() {
0227 std::for_each(container_.begin(), container_.end(), Deleter());
0228 container_.clear();
0229 }
0230
0231 GeometricTimingDet::Position GeometricTimingDet::positionBounds() const {
0232 Position pos(geant_units::operators::convertMmToCm(trans_.x()),
0233 geant_units::operators::convertMmToCm(trans_.y()),
0234 geant_units::operators::convertMmToCm(trans_.z()));
0235 return pos;
0236 }
0237
0238 GeometricTimingDet::Rotation GeometricTimingDet::rotationBounds() const {
0239 Translation x, y, z;
0240 rot_.GetComponents(x, y, z);
0241 Rotation rotation(float(x.X()),
0242 float(x.Y()),
0243 float(x.Z()),
0244 float(y.X()),
0245 float(y.Y()),
0246 float(y.Z()),
0247 float(z.X()),
0248 float(z.Y()),
0249 float(z.Z()));
0250 return rotation;
0251 }
0252
0253 std::unique_ptr<Bounds> GeometricTimingDet::bounds() const {
0254 const std::vector<double>& par = params_;
0255 TrackerShapeToBounds shapeToBounds;
0256 return std::unique_ptr<Bounds>(shapeToBounds.buildBounds(shape_, par));
0257 }