Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-23 15:57:51

0001 #include "Geometry/MTDGeometryBuilder/interface/MTDTopology.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "Geometry/MTDCommonData/interface/MTDTopologyMode.h"
0004 
0005 #include <utility>
0006 
0007 MTDTopology::MTDTopology(const int& topologyMode, const BTLValues& btl, const ETLValues& etl)
0008     : mtdTopologyMode_(topologyMode), btlVals_(btl), etlVals_(etl) {}
0009 
0010 std::pair<uint32_t, uint32_t> MTDTopology::btlIndex(const uint32_t detId) const {
0011   size_t index(0);
0012   bool found(false);
0013   for (const auto& theid : btlVals_.btlDetId_) {
0014     if (theid == detId) {
0015       found = true;
0016       break;
0017     }
0018     index++;
0019   }
0020   if (found) {
0021     return std::make_pair(btlVals_.btlPhi_[index], btlVals_.btlEta_[index]);
0022   } else {
0023     edm::LogWarning("MTDTopology") << "Searching BTL topology for BTLDetId " << detId
0024                                    << " not in BTL geometry structure";
0025     return std::make_pair(std::numeric_limits<uint32_t>::max(), std::numeric_limits<uint32_t>::max());
0026   }
0027 }
0028 
0029 uint32_t MTDTopology::btlidFromIndex(const uint32_t iphi, const uint32_t ieta) const {
0030   uint32_t res(0);
0031   for (uint32_t index = 0; index < btlVals_.nBTLmodules_; index++) {
0032     if (iphi == btlVals_.btlPhi_[index] && ieta == btlVals_.btlEta_[index]) {
0033       res = btlVals_.btlDetId_[index];
0034       break;
0035     }
0036   }
0037   return res;
0038 }
0039 
0040 uint32_t MTDTopology::phishiftBTL(const uint32_t detid, const int phiShift) const {
0041   if (phiShift == 0) {
0042     edm::LogWarning("MTDTopology") << "asking of a null phiShift in BTL";
0043     return failIndex_;
0044   }
0045   // search for the next detector, check only sign from input
0046   int sh = phiShift > 0 ? 1 : -1;
0047   size_t index(0);
0048   bool found(false);
0049   for (const auto& theid : btlVals_.btlDetId_) {
0050     if (theid == detid) {
0051       found = true;
0052       break;
0053     }
0054     index++;
0055   }
0056   if (found) {
0057     int newIndex = index + sh * btlVals_.nBTLeta_;
0058     if (newIndex >= static_cast<int>(btlVals_.nBTLmodules_)) {
0059       newIndex = newIndex - btlVals_.nBTLmodules_;
0060     } else if (newIndex < 0) {
0061       newIndex = newIndex + btlVals_.nBTLmodules_;
0062     }
0063     return newIndex;
0064   } else {
0065     edm::LogWarning("MTDTopology") << "Searching for non existent BTLDetId " << detid;
0066     return failIndex_;
0067   }
0068 }
0069 
0070 uint32_t MTDTopology::etashiftBTL(const uint32_t detid, const int etaShift) const {
0071   if (etaShift == 0) {
0072     edm::LogWarning("MTDTopology") << "asking of a null etaShift in BTL";
0073     return failIndex_;
0074   }
0075   // search for the next detector, check only sign from input
0076   int sh = etaShift > 0 ? 1 : -1;
0077   size_t index(0);
0078   bool found(false);
0079   for (const auto& theid : btlVals_.btlDetId_) {
0080     if (theid == detid) {
0081       found = true;
0082       break;
0083     }
0084     index++;
0085   }
0086   if (found) {
0087     int newIndex = index + sh;
0088     if (newIndex < 0 || newIndex >= static_cast<int>(btlVals_.nBTLmodules_)) {
0089       return failIndex_;
0090     } else if (btlVals_.btlPhi_[newIndex] != btlVals_.btlPhi_[index]) {
0091       return failIndex_;
0092     }
0093     return newIndex;
0094   } else {
0095     edm::LogWarning("MTDTopology") << "Searching for non existent BTLDetId " << detid;
0096     return failIndex_;
0097   }
0098 }
0099 
0100 bool MTDTopology::orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2) {
0101   ETLDetId det1(gd1->geographicalId().rawId());
0102   ETLDetId det2(gd2->geographicalId().rawId());
0103 
0104   if (det1.mtdRR() != det2.mtdRR()) {
0105     return det1.mtdRR() < det2.mtdRR();
0106   } else if (det1.modType() != det2.modType()) {
0107     return det1.modType() < det2.modType();
0108   } else if (det1.module() != det2.module()) {
0109     return det1.module() < det2.module();
0110   } else {
0111     return det1.sensor() < det2.sensor();
0112   }
0113 }
0114 
0115 size_t MTDTopology::hshiftETL(const uint32_t detid, const int horizontalShift) const {
0116   ETLDetId start_mod(detid);
0117 
0118   if (horizontalShift == 0) {
0119     edm::LogWarning("MTDTopology") << "asking of a null horizotalShift in ETL";
0120     return failIndex_;
0121   }
0122   int hsh = horizontalShift > 0 ? 1 : -1;
0123 
0124   int sensor = start_mod.sensor();
0125   int module = start_mod.module();
0126   uint32_t modtyp = start_mod.modType();
0127   uint32_t discface = start_mod.discSide() + 2 * (start_mod.nDisc() - 1);
0128   int geomDetIndex;
0129 
0130   // distinguish numbering in prev8 / v8 geometries
0131   auto topoMode = getMTDTopologyMode();
0132   if (static_cast<int>(MTDTopologyMode::etlLayoutFromTopoMode(topoMode)) >=
0133       static_cast<int>(MTDTopologyMode::EtlLayout::v8)) {
0134     geomDetIndex = 2 * (module - 1) + sensor;
0135   } else {
0136     geomDetIndex = module;
0137   }
0138 
0139   // ilayout number coincides at present with disc face, use this
0140 
0141   size_t iHome = (modtyp == etlVals_[discface].idDetType1_) ? 0 : 1;
0142   size_t iLeft = (etlVals_[discface].idDetType1_ == 1) ? 0 : 1;
0143 
0144   // for left type modules the position according to the default order is module - 1, for the rigth type modules the total number of left modules must be added
0145 
0146   size_t nmodOffset = (modtyp == 1) ? 0 : etlVals_[discface].start_copy_[iLeft].back() - 1;
0147 
0148   for (size_t iloop = 0; iloop < etlVals_[discface].start_copy_[iHome].size() - 1; iloop++) {
0149     if (geomDetIndex >= etlVals_[discface].start_copy_[iHome][iloop] &&
0150         geomDetIndex < etlVals_[discface].start_copy_[iHome][iloop + 1]) {
0151       if (geomDetIndex + hsh >= etlVals_[discface].start_copy_[iHome][iloop] &&
0152           geomDetIndex + hsh < etlVals_[discface].start_copy_[iHome][iloop + 1]) {
0153         return geomDetIndex + hsh - 1 + nmodOffset;
0154       }
0155       break;
0156     }
0157   }
0158 
0159   return failIndex_;
0160 }
0161 
0162 size_t MTDTopology::vshiftETL(const uint32_t detid, const int verticalShift, size_t& closest) const {
0163   closest = failIndex_;
0164 
0165   ETLDetId start_mod(detid);
0166 
0167   if (verticalShift == 0) {
0168     edm::LogWarning("MTDTopology") << "asking of a null verticalShift in ETL";
0169     return failIndex_;
0170   }
0171   int vsh = verticalShift > 0 ? 1 : -1;
0172 
0173   int sensor = start_mod.sensor();
0174   int module = start_mod.module();
0175   uint32_t modtyp = start_mod.modType();
0176   uint32_t discface = start_mod.discSide() + 2 * (start_mod.nDisc() - 1);
0177   int geomDetIndex;
0178 
0179   // distinguish numbering in prev8 / v8 geometries
0180   auto topoMode = getMTDTopologyMode();
0181   if (static_cast<int>(MTDTopologyMode::etlLayoutFromTopoMode(topoMode)) >=
0182       static_cast<int>(MTDTopologyMode::EtlLayout::v8)) {
0183     geomDetIndex = 2 * (module - 1) + sensor;
0184   } else {
0185     geomDetIndex = module;
0186   }
0187 
0188   // ilayout number coincides at present with disc face, use this
0189 
0190   size_t iHome = (modtyp == etlVals_[discface].idDetType1_) ? 0 : 1;
0191   size_t iOther = (iHome == 0) ? 1 : 0;
0192   size_t iLeft = (etlVals_[discface].idDetType1_ == 1) ? 0 : 1;
0193 
0194   // for right type modules the offset of the total number of left modules needs to be added,
0195   // what matters here is the other type, i.e. if the starting module is left the vertical shift moves towards a right type, and viceversa
0196 
0197   size_t nmodOffset = (modtyp == 1) ? etlVals_[discface].start_copy_[iLeft].back() - 1 : 0;
0198 
0199   size_t iBin(etlVals_[discface].start_copy_[iHome].size());  // never allowed
0200   for (size_t iloop = 0; iloop < etlVals_[discface].start_copy_[iHome].size() - 1; iloop++) {
0201     if (geomDetIndex >= etlVals_[discface].start_copy_[iHome][iloop] &&
0202         geomDetIndex < etlVals_[discface].start_copy_[iHome][iloop + 1]) {
0203       iBin = iloop;
0204       break;
0205     }
0206   }
0207 
0208   if (iBin == etlVals_[discface].start_copy_[iHome].size()) {
0209     edm::LogWarning("MTDTopology") << "Module number not compatible with layout, abort";
0210     return failIndex_;
0211   }
0212 
0213   // define the interval of interest for the other type according to the vertical shift sign
0214 
0215   int iBinOther(iBin);
0216   if (iHome == 0 && vsh < 0) {
0217     iBinOther = iBin - 1;
0218   }
0219   if (iHome == 1 && vsh > 0) {
0220     iBinOther = iBin + 1;
0221   }
0222   if (iBinOther < 0 || iBinOther >= static_cast<int>(etlVals_[discface].start_copy_[iOther].size()) - 1) {
0223     return failIndex_;
0224   }
0225 
0226   // determine the position of the other type corresponding to the same column of the home type
0227 
0228   int vpos = etlVals_[discface].offset_[iHome][iBin] + geomDetIndex - etlVals_[discface].start_copy_[iHome][iBin] + 1;
0229   if (vpos <= etlVals_[discface].offset_[iOther][iBinOther]) {
0230     closest = etlVals_[discface].start_copy_[iOther][iBinOther];
0231   } else if (vpos > etlVals_[discface].offset_[iOther][iBinOther] +
0232                         etlVals_[discface].start_copy_[iOther][iBinOther + 1] -
0233                         etlVals_[discface].start_copy_[iOther][iBinOther] ||
0234              (vpos == etlVals_[discface].offset_[iOther][iBinOther] +
0235                           etlVals_[discface].start_copy_[iOther][iBinOther + 1] -
0236                           etlVals_[discface].start_copy_[iOther][iBinOther] &&
0237               iBinOther + 1 == static_cast<int>(etlVals_[discface].start_copy_[iOther].size()))) {
0238     closest = etlVals_[discface].start_copy_[iOther][iBinOther + 1] - 1;
0239   }
0240   if (closest < failIndex_) {
0241     closest = closest + nmodOffset - 1;
0242     return failIndex_;
0243   } else {
0244     // number of module shifted by 1 wrt the position in the array (i.e. module 1 has index 0)
0245     return etlVals_[discface].start_copy_[iOther][iBinOther] + vpos - 1 -
0246            etlVals_[discface].offset_[iOther][iBinOther] + nmodOffset - 1;
0247   }
0248 }