File indexing completed on 2024-04-06 12:15:17
0001 #include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"
0004
0005 MTDTopology::MTDTopology(const int& topologyMode, const ETLValues& etl)
0006 : mtdTopologyMode_(topologyMode), etlVals_(etl) {}
0007
0008 bool MTDTopology::orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2) {
0009 ETLDetId det1(gd1->geographicalId().rawId());
0010 ETLDetId det2(gd2->geographicalId().rawId());
0011
0012 if (det1.mtdRR() != det2.mtdRR()) {
0013 return det1.mtdRR() < det2.mtdRR();
0014 } else if (det1.modType() != det2.modType()) {
0015 return det1.modType() < det2.modType();
0016 } else if (det1.module() != det2.module()) {
0017 return det1.module() < det2.module();
0018 } else {
0019 return det1.sensor() < det2.sensor();
0020 }
0021 }
0022
0023 size_t MTDTopology::hshiftETL(const uint32_t detid, const int horizontalShift) const {
0024 ETLDetId start_mod(detid);
0025
0026 if (horizontalShift == 0) {
0027 edm::LogWarning("MTDTopology") << "asking of a null horizotalShift in ETL";
0028 return failIndex_;
0029 }
0030 int hsh = horizontalShift > 0 ? 1 : -1;
0031
0032 int sensor = start_mod.sensor();
0033 int module = start_mod.module();
0034 uint32_t modtyp = start_mod.modType();
0035 uint32_t discside = start_mod.discSide();
0036 int geomDetIndex;
0037
0038
0039 if (getMTDTopologyMode() == static_cast<int>(MTDTopologyMode::Mode::btlv3etlv8)) {
0040 geomDetIndex = 2 * (module - 1) + sensor;
0041 } else {
0042 geomDetIndex = module;
0043 }
0044
0045
0046
0047 size_t iHome = (modtyp == etlVals_[discside].idDetType1_) ? 0 : 1;
0048 size_t iLeft = (etlVals_[discside].idDetType1_ == 1) ? 0 : 1;
0049
0050
0051
0052 size_t nmodOffset = (modtyp == 1) ? 0 : etlVals_[discside].start_copy_[iLeft].back() - 1;
0053
0054 for (size_t iloop = 0; iloop < etlVals_[discside].start_copy_[iHome].size() - 1; iloop++) {
0055 if (geomDetIndex >= etlVals_[discside].start_copy_[iHome][iloop] &&
0056 geomDetIndex < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0057 if (geomDetIndex + hsh >= etlVals_[discside].start_copy_[iHome][iloop] &&
0058 geomDetIndex + hsh < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0059 return geomDetIndex + hsh - 1 + nmodOffset;
0060 }
0061 break;
0062 }
0063 }
0064
0065 return failIndex_;
0066 }
0067
0068 size_t MTDTopology::vshiftETL(const uint32_t detid, const int verticalShift, size_t& closest) const {
0069 closest = failIndex_;
0070
0071 ETLDetId start_mod(detid);
0072
0073 if (verticalShift == 0) {
0074 edm::LogWarning("MTDTopology") << "asking of a null verticalShift in ETL";
0075 return failIndex_;
0076 }
0077 int vsh = verticalShift > 0 ? 1 : -1;
0078
0079 int sensor = start_mod.sensor();
0080 int module = start_mod.module();
0081 uint32_t modtyp = start_mod.modType();
0082 uint32_t discside = start_mod.discSide();
0083 int geomDetIndex;
0084
0085
0086 if (getMTDTopologyMode() == static_cast<int>(MTDTopologyMode::Mode::btlv3etlv8)) {
0087 geomDetIndex = 2 * (module - 1) + sensor;
0088 } else {
0089 geomDetIndex = module;
0090 }
0091
0092
0093
0094 size_t iHome = (modtyp == etlVals_[discside].idDetType1_) ? 0 : 1;
0095 size_t iOther = (iHome == 0) ? 1 : 0;
0096 size_t iLeft = (etlVals_[discside].idDetType1_ == 1) ? 0 : 1;
0097
0098
0099
0100
0101 size_t nmodOffset = (modtyp == 1) ? etlVals_[discside].start_copy_[iLeft].back() - 1 : 0;
0102
0103 size_t iBin(etlVals_[discside].start_copy_[iHome].size());
0104 for (size_t iloop = 0; iloop < etlVals_[discside].start_copy_[iHome].size() - 1; iloop++) {
0105 if (geomDetIndex >= etlVals_[discside].start_copy_[iHome][iloop] &&
0106 geomDetIndex < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0107 iBin = iloop;
0108 break;
0109 }
0110 }
0111
0112 if (iBin == etlVals_[discside].start_copy_[iHome].size()) {
0113 edm::LogWarning("MTDTopology") << "Module number not compatible with layout, abort";
0114 return failIndex_;
0115 }
0116
0117
0118
0119 int iBinOther(iBin);
0120 if (iHome == 0 && vsh < 0) {
0121 iBinOther = iBin - 1;
0122 }
0123 if (iHome == 1 && vsh > 0) {
0124 iBinOther = iBin + 1;
0125 }
0126 if (iBinOther < 0 || iBinOther >= static_cast<int>(etlVals_[discside].start_copy_[iOther].size()) - 1) {
0127 return failIndex_;
0128 }
0129
0130
0131
0132 int vpos = etlVals_[discside].offset_[iHome][iBin] + geomDetIndex - etlVals_[discside].start_copy_[iHome][iBin] + 1;
0133 if (vpos <= etlVals_[discside].offset_[iOther][iBinOther]) {
0134 closest = etlVals_[discside].start_copy_[iOther][iBinOther];
0135 } else if (vpos > etlVals_[discside].offset_[iOther][iBinOther] +
0136 etlVals_[discside].start_copy_[iOther][iBinOther + 1] -
0137 etlVals_[discside].start_copy_[iOther][iBinOther] ||
0138 (vpos == etlVals_[discside].offset_[iOther][iBinOther] +
0139 etlVals_[discside].start_copy_[iOther][iBinOther + 1] -
0140 etlVals_[discside].start_copy_[iOther][iBinOther] &&
0141 iBinOther + 1 == static_cast<int>(etlVals_[discside].start_copy_[iOther].size()))) {
0142 closest = etlVals_[discside].start_copy_[iOther][iBinOther + 1] - 1;
0143 }
0144 if (closest < failIndex_) {
0145 closest = closest + nmodOffset - 1;
0146 return failIndex_;
0147 } else {
0148
0149 return etlVals_[discside].start_copy_[iOther][iBinOther] + vpos - 1 -
0150 etlVals_[discside].offset_[iOther][iBinOther] + nmodOffset - 1;
0151 }
0152 }