Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-17 03:00:22

0001 #include "Geometry/MTDNumberingBuilder/interface/MTDTopology.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 MTDTopology::MTDTopology(const int& topologyMode, const ETLValues& etl)
0005     : mtdTopologyMode_(topologyMode), etlVals_(etl) {}
0006 
0007 bool MTDTopology::orderETLSector(const GeomDet*& gd1, const GeomDet*& gd2) {
0008   ETLDetId det1(gd1->geographicalId().rawId());
0009   ETLDetId det2(gd2->geographicalId().rawId());
0010 
0011   if (det1.mtdRR() != det2.mtdRR()) {
0012     return det1.mtdRR() < det2.mtdRR();
0013   } else if (det1.modType() != det2.modType()) {
0014     return det1.modType() < det2.modType();
0015   } else {
0016     return det1.module() < det2.module();
0017   }
0018 }
0019 
0020 size_t MTDTopology::hshiftETL(const uint32_t detid, const int horizontalShift) const {
0021   ETLDetId start_mod(detid);
0022 
0023   if (horizontalShift == 0) {
0024     edm::LogWarning("MTDTopology") << "asking of a null horizotalShift in ETL";
0025     return failIndex_;
0026   }
0027   int hsh = horizontalShift > 0 ? 1 : -1;
0028 
0029   int module = start_mod.module();
0030   uint32_t modtyp = start_mod.modType();
0031   uint32_t discside = start_mod.discSide();
0032 
0033   // ilayout number coincides at present with disc face, use this
0034 
0035   size_t iHome = (modtyp == etlVals_[discside].idDetType1_) ? 0 : 1;
0036   size_t iLeft = (etlVals_[discside].idDetType1_ == 1) ? 0 : 1;
0037 
0038   // 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
0039 
0040   size_t nmodOffset = (modtyp == 1) ? 0 : etlVals_[discside].start_copy_[iLeft].back() - 1;
0041 
0042   for (size_t iloop = 0; iloop < etlVals_[discside].start_copy_[iHome].size() - 1; iloop++) {
0043     if (module >= etlVals_[discside].start_copy_[iHome][iloop] &&
0044         module < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0045       if (module + hsh >= etlVals_[discside].start_copy_[iHome][iloop] &&
0046           module + hsh < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0047         return module + hsh - 1 + nmodOffset;
0048       }
0049       break;
0050     }
0051   }
0052 
0053   return failIndex_;
0054 }
0055 
0056 size_t MTDTopology::vshiftETL(const uint32_t detid, const int verticalShift, size_t& closest) const {
0057   closest = failIndex_;
0058 
0059   ETLDetId start_mod(detid);
0060 
0061   if (verticalShift == 0) {
0062     edm::LogWarning("MTDTopology") << "asking of a null verticalShift in ETL";
0063     return failIndex_;
0064   }
0065   int vsh = verticalShift > 0 ? 1 : -1;
0066 
0067   int module = start_mod.module();
0068   uint32_t modtyp = start_mod.modType();
0069   uint32_t discside = start_mod.discSide();
0070 
0071   // ilayout number coincides at present with disc face, use this
0072 
0073   size_t iHome = (modtyp == etlVals_[discside].idDetType1_) ? 0 : 1;
0074   size_t iOther = (iHome == 0) ? 1 : 0;
0075   size_t iLeft = (etlVals_[discside].idDetType1_ == 1) ? 0 : 1;
0076 
0077   // for right type modules the offset of the total number of left modules needs to be added,
0078   // 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
0079 
0080   size_t nmodOffset = (modtyp == 1) ? etlVals_[discside].start_copy_[iLeft].back() - 1 : 0;
0081 
0082   size_t iBin(etlVals_[discside].start_copy_[iHome].size());  // never allowed
0083   for (size_t iloop = 0; iloop < etlVals_[discside].start_copy_[iHome].size() - 1; iloop++) {
0084     if (module >= etlVals_[discside].start_copy_[iHome][iloop] &&
0085         module < etlVals_[discside].start_copy_[iHome][iloop + 1]) {
0086       iBin = iloop;
0087       break;
0088     }
0089   }
0090 
0091   if (iBin == etlVals_[discside].start_copy_[iHome].size()) {
0092     edm::LogWarning("MTDTopology") << "Module number not compatible with layout, abort";
0093     return failIndex_;
0094   }
0095 
0096   // define the interval of interest for the other type according to the vertical shift sign
0097 
0098   int iBinOther(iBin);
0099   if (iHome == 0 && vsh < 0) {
0100     iBinOther = iBin - 1;
0101   }
0102   if (iHome == 1 && vsh > 0) {
0103     iBinOther = iBin + 1;
0104   }
0105   if (iBinOther < 0 || iBinOther >= static_cast<int>(etlVals_[discside].start_copy_[iOther].size()) - 1) {
0106     return failIndex_;
0107   }
0108 
0109   // determine the position of the other type corresponding to the same column of the home type
0110 
0111   int vpos = etlVals_[discside].offset_[iHome][iBin] + module - etlVals_[discside].start_copy_[iHome][iBin] + 1;
0112   if (vpos <= etlVals_[discside].offset_[iOther][iBinOther]) {
0113     closest = etlVals_[discside].start_copy_[iOther][iBinOther];
0114   } else if (vpos > etlVals_[discside].offset_[iOther][iBinOther] +
0115                         etlVals_[discside].start_copy_[iOther][iBinOther + 1] -
0116                         etlVals_[discside].start_copy_[iOther][iBinOther] ||
0117              (vpos == etlVals_[discside].offset_[iOther][iBinOther] +
0118                           etlVals_[discside].start_copy_[iOther][iBinOther + 1] -
0119                           etlVals_[discside].start_copy_[iOther][iBinOther] &&
0120               iBinOther + 1 == static_cast<int>(etlVals_[discside].start_copy_[iOther].size()))) {
0121     closest = etlVals_[discside].start_copy_[iOther][iBinOther + 1] - 1;
0122   }
0123   if (closest < failIndex_) {
0124     closest = closest + nmodOffset - 1;
0125     return failIndex_;
0126   } else {
0127     // number of module shifted by 1 wrt the position in the array (i.e. module 1 has index 0)
0128     return etlVals_[discside].start_copy_[iOther][iBinOther] + vpos - 1 -
0129            etlVals_[discside].offset_[iOther][iBinOther] + nmodOffset - 1;
0130   }
0131 }