File indexing completed on 2024-04-06 12:15:16
0001
0002
0003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
0004 #include "DetectorDescription/DDCMS/interface/DDFilteredView.h"
0005 #include "Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.h"
0006 #include "Geometry/MTDNumberingBuilder/plugins/ExtractStringFromDD.h"
0007
0008 #include "DataFormats/ForwardDetId/interface/BTLDetId.h"
0009 #include "DataFormats/ForwardDetId/interface/ETLDetId.h"
0010 #include "Geometry/MTDCommonData/interface/MTDBaseNumber.h"
0011
0012 #include "DataFormats/Math/interface/deltaPhi.h"
0013
0014 using angle_units::operators::convertRadToDeg;
0015
0016 template <class FilteredView>
0017 CmsMTDConstruction<FilteredView>::CmsMTDConstruction() : btlScheme_(), etlScheme_(), baseNumber_() {}
0018
0019 template <class FilteredView>
0020 bool CmsMTDConstruction<FilteredView>::mtdOrderZ(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0021 bool order = (a->translation().z() == b->translation().z()) ? a->translation().rho() < b->translation().rho()
0022 : a->translation().z() < b->translation().z();
0023 return order;
0024 }
0025
0026 template <class FilteredView>
0027 bool CmsMTDConstruction<FilteredView>::mtdOrderRR(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0028 MTDDetId id1(a->geographicalId());
0029 MTDDetId id2(b->geographicalId());
0030 return id1.mtdRR() < id2.mtdRR();
0031 }
0032
0033 template <class FilteredView>
0034 bool CmsMTDConstruction<FilteredView>::mtdOrderPhi(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0035 MTDDetId id1(a->geographicalId());
0036 MTDDetId id2(b->geographicalId());
0037 return (id1.mtdRR() == id2.mtdRR()) && (angle0to2pi::make0To2pi(a->phi()) < angle0to2pi::make0To2pi(b->phi()));
0038 }
0039
0040 template <class FilteredView>
0041 bool CmsMTDConstruction<FilteredView>::btlOrderPhi(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0042 return static_cast<int>(convertRadToDeg(angle0to2pi::make0To2pi(a->phi()))) <
0043 static_cast<int>(convertRadToDeg(angle0to2pi::make0To2pi(b->phi())));
0044 }
0045
0046 template <class FilteredView>
0047 bool CmsMTDConstruction<FilteredView>::btlOrderZ(const GeometricTimingDet* a, const GeometricTimingDet* b) {
0048 bool order = (static_cast<int>(convertRadToDeg(angle0to2pi::make0To2pi(a->phi()))) ==
0049 static_cast<int>(convertRadToDeg(angle0to2pi::make0To2pi(b->phi())))) &&
0050 (a->translation().z() < b->translation().z());
0051 return order;
0052 }
0053
0054 template <>
0055 void CmsMTDConstruction<DDFilteredView>::buildBTLModule(DDFilteredView& fv, GeometricTimingDet* mother) {
0056 std::string nodeName(fv.name());
0057 GeometricTimingDet* det =
0058 new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0059
0060 if (isBTLV2(fv)) {
0061 auto& gh = fv.geoHistory();
0062
0063 baseNumber_.reset();
0064 baseNumber_.setSize(gh.size());
0065
0066 for (uint i = gh.size(); i-- > 0;) {
0067 baseNumber_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
0068 #ifdef EDM_ML_DEBUG
0069 edm::LogVerbatim("CmsMTDConstruction") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
0070 #endif
0071 }
0072
0073 det->setGeographicalID(BTLDetId(btlScheme_.getUnitID(baseNumber_)));
0074
0075 } else {
0076 const auto& copyNumbers = fv.copyNumbers();
0077 auto module_number = copyNumbers[copyNumbers.size() - 2];
0078
0079 constexpr char positive[] = "PositiveZ";
0080 constexpr char negative[] = "NegativeZ";
0081
0082 const std::string& modname(fv.name());
0083 size_t delim1 = modname.find("BModule");
0084 size_t delim2 = modname.find("Layer");
0085 module_number += atoi(modname.substr(delim1 + CmsMTDStringToEnum::kModStrLen, delim2).c_str()) - 1;
0086
0087 #ifdef EDM_ML_DEBUG
0088 edm::LogVerbatim("CmsMTDConstruction")
0089 << "BTLModule = " << modname << " " << copyNumbers[copyNumbers.size() - 3] << " " << module_number;
0090 #endif
0091
0092 if (modname.find(positive) != std::string::npos) {
0093 det->setGeographicalID(BTLDetId(1, copyNumbers[copyNumbers.size() - 3], module_number, 0, 1));
0094 } else if (modname.find(negative) != std::string::npos) {
0095 det->setGeographicalID(BTLDetId(0, copyNumbers[copyNumbers.size() - 3], module_number, 0, 1));
0096 } else {
0097 throw cms::Exception("CmsMTDConstruction::buildBTLModule")
0098 << "BTL Module " << module_number << " is neither positive nor negative in Z!";
0099 }
0100 }
0101
0102 mother->addComponent(det);
0103 }
0104
0105 template <>
0106 void CmsMTDConstruction<cms::DDFilteredView>::buildBTLModule(cms::DDFilteredView& fv, GeometricTimingDet* mother) {
0107 std::string nodeName(fv.name());
0108 GeometricTimingDet* det =
0109 new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0110
0111 if (isBTLV2(fv)) {
0112 baseNumber_.reset();
0113 baseNumber_.setSize(fv.copyNos().size());
0114
0115 for (uint i = 0; i < fv.copyNos().size(); i++) {
0116 std::string_view name((fv.geoHistory()[i])->GetName());
0117 size_t ipos = name.rfind('_');
0118 baseNumber_.addLevel(name.substr(0, ipos), fv.copyNos()[i]);
0119 #ifdef EDM_ML_DEBUG
0120 edm::LogVerbatim("CmsMTDConstruction") << name.substr(0, ipos) << " " << fv.copyNos()[i];
0121 #endif
0122 }
0123
0124 det->setGeographicalID(BTLDetId(btlScheme_.getUnitID(baseNumber_)));
0125
0126 } else {
0127 const auto& copyNumbers = fv.copyNumbers();
0128 auto module_number = copyNumbers[1];
0129
0130 constexpr char positive[] = "PositiveZ";
0131 constexpr char negative[] = "NegativeZ";
0132
0133 const std::string modname(fv.name());
0134 size_t delim1 = modname.find("BModule");
0135 size_t delim2 = modname.find("Layer");
0136 module_number += atoi(modname.substr(delim1 + CmsMTDStringToEnum::kModStrLen, delim2).c_str()) - 1;
0137
0138 #ifdef EDM_ML_DEBUG
0139 edm::LogVerbatim("MTDNumbering") << fv.path() << "\nBTLModule = " << modname << " " << copyNumbers[2] << " "
0140 << module_number;
0141 #endif
0142
0143 if (modname.find(positive) != std::string::npos) {
0144 det->setGeographicalID(BTLDetId(1, copyNumbers[2], module_number, 0, 1));
0145 } else if (modname.find(negative) != std::string::npos) {
0146 det->setGeographicalID(BTLDetId(0, copyNumbers[2], module_number, 0, 1));
0147 } else {
0148 throw cms::Exception("CmsMTDConstruction::buildBTLModule")
0149 << "BTL Module " << module_number << " is neither positive nor negative in Z!";
0150 }
0151 }
0152
0153 mother->addComponent(det);
0154 }
0155
0156 template <>
0157 void CmsMTDConstruction<DDFilteredView>::buildETLModule(DDFilteredView& fv, GeometricTimingDet* mother) {
0158 std::string nodeName(fv.name());
0159 GeometricTimingDet* det =
0160 new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0161
0162 auto& gh = fv.geoHistory();
0163
0164 baseNumber_.reset();
0165 baseNumber_.setSize(gh.size());
0166
0167 for (uint i = gh.size(); i-- > 0;) {
0168 baseNumber_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
0169 #ifdef EDM_ML_DEBUG
0170 edm::LogVerbatim("CmsMTDConstruction") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
0171 #endif
0172 }
0173
0174 det->setGeographicalID(ETLDetId(etlScheme_.getUnitID(baseNumber_)));
0175
0176 mother->addComponent(det);
0177 }
0178
0179 template <>
0180 void CmsMTDConstruction<cms::DDFilteredView>::buildETLModule(cms::DDFilteredView& fv, GeometricTimingDet* mother) {
0181 std::string nodeName(fv.name());
0182 GeometricTimingDet* det =
0183 new GeometricTimingDet(&fv, theCmsMTDStringToEnum.type(nodeName.substr(0, CmsMTDStringToEnum::kModStrLen)));
0184
0185 baseNumber_.reset();
0186 baseNumber_.setSize(fv.copyNos().size());
0187
0188 for (uint i = 0; i < fv.copyNos().size(); i++) {
0189 std::string_view name((fv.geoHistory()[i])->GetName());
0190 size_t ipos = name.rfind('_');
0191 baseNumber_.addLevel(name.substr(0, ipos), fv.copyNos()[i]);
0192 #ifdef EDM_ML_DEBUG
0193 edm::LogVerbatim("CmsMTDConstruction") << name.substr(0, ipos) << " " << fv.copyNos()[i];
0194 #endif
0195 }
0196
0197 det->setGeographicalID(ETLDetId(etlScheme_.getUnitID(baseNumber_)));
0198
0199 mother->addComponent(det);
0200 }
0201
0202 template <class FilteredView>
0203 GeometricTimingDet* CmsMTDConstruction<FilteredView>::buildSubdet(FilteredView& fv) {
0204 std::string nodeName(fv.name());
0205 auto thisDet = theCmsMTDStringToEnum.type(nodeName);
0206 GeometricTimingDet* subdet = new GeometricTimingDet(&fv, thisDet);
0207
0208 if (thisDet == GeometricTimingDet::BTL) {
0209 subdet->setGeographicalID(BTLDetId(0, 0, 0, 0, 0));
0210 } else if (thisDet == GeometricTimingDet::ETL) {
0211 const uint32_t side = subdet->translation().z() > 0 ? 1 : 0;
0212 subdet->setGeographicalID(ETLDetId(side, 0, 0, 0, 0));
0213 } else {
0214 throw cms::Exception("CmsMTDConstruction") << " ERROR - I was expecting a SubDet, I got a " << fv.name();
0215 }
0216
0217 return subdet;
0218 }
0219
0220 template <class FilteredView>
0221 GeometricTimingDet* CmsMTDConstruction<FilteredView>::buildLayer(FilteredView& fv) {
0222 std::string nodeName(fv.name());
0223 auto thisDet = theCmsMTDStringToEnum.type(nodeName);
0224 GeometricTimingDet* layer = new GeometricTimingDet(&fv, thisDet);
0225
0226 if (thisDet != GeometricTimingDet::BTLLayer && thisDet != GeometricTimingDet::ETLDisc) {
0227 throw cms::Exception("CmsMTDConstruction") << " ERROR - I was expecting a SubDet, I got a " << fv.name();
0228 }
0229
0230 uint32_t nLayer;
0231 if (thisDet == GeometricTimingDet::BTLLayer) {
0232
0233
0234
0235 nLayer = 1;
0236 layer->setGeographicalID(nLayer);
0237 } else if (thisDet == GeometricTimingDet::ETLDisc) {
0238
0239
0240
0241 nLayer = (fv.name().find("Disc1") != std::string::npos) ? 1 : 2;
0242 layer->setGeographicalID(nLayer);
0243 }
0244
0245 return layer;
0246 }
0247
0248 template <class FilteredView>
0249 bool CmsMTDConstruction<FilteredView>::isBTLV2(FilteredView& fv) {
0250 return (fv.name().substr(0, 9) == "BTLModule");
0251 }
0252
0253 template <class FilteredView>
0254 bool CmsMTDConstruction<FilteredView>::isETLpreV8(FilteredView& fv) {
0255 return (fv.name().find("EModule") != std::string::npos);
0256 }
0257
0258 template class CmsMTDConstruction<DDFilteredView>;
0259 template class CmsMTDConstruction<cms::DDFilteredView>;