Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-25 02:14:11

0001 #ifndef RecoTracker_MkFitCMS_interface_LayerNumberConverter_h
0002 #define RecoTracker_MkFitCMS_interface_LayerNumberConverter_h
0003 
0004 #include <stdexcept>
0005 
0006 namespace mkfit {
0007 
0008   enum struct TkLayout { phase0 = 0, phase1 = 1, phase2 = 2 };
0009 
0010   class LayerNumberConverter {
0011   public:
0012     LayerNumberConverter(TkLayout layout) : lo_(layout) {}
0013     void reset(TkLayout layout) { lo_ = layout; }
0014     unsigned int nLayers() const {
0015       if (lo_ == TkLayout::phase0)
0016         return 69;
0017       if (lo_ == TkLayout::phase1)
0018         return 72;
0019       if (lo_ == TkLayout::phase2)
0020         return 60;  // 4 + 12 + 2*(12 + 10) = 16 + 22 + 22 = 60
0021       return 10;
0022     }
0023     TkLayout getEra() const { return lo_; }
0024     bool isPhase1() const { return lo_ == TkLayout::phase1; }
0025     bool isPhase2() const { return lo_ == TkLayout::phase2; }
0026     int convertLayerNumber(int det, int lay, bool useMatched, int isStereo, bool posZ) const {
0027       if (lo_ == TkLayout::phase2) {
0028         if (det == 1)
0029           return lay - 1;
0030         if (det == 2)
0031           return 16 + lay - 1 + (posZ ? 0 : 22);
0032         if (det == 5)
0033           return 4 + (2 * (lay - 1)) + isStereo;
0034         if (det == 4)
0035           return 16 + 12 + (2 * (lay - 1)) + isStereo + (posZ ? 0 : 22);
0036         throw std::runtime_error("bad subDet");
0037       }
0038 
0039       if (det == 1 || det == 3 || det == 5) {
0040         return convertBarrelLayerNumber(det, lay, useMatched, isStereo);
0041       } else {
0042         int disk = convertDiskNumber(det, lay, useMatched, isStereo);
0043         if (disk < 0)
0044           return -1;
0045 
0046         int lOffset = 0;
0047         if (lo_ == TkLayout::phase1)
0048           lOffset = 1;
0049         disk += 17 + lOffset;
0050         if (!posZ)
0051           disk += 25 + 2 * lOffset;
0052         return disk;
0053       }
0054       return -1;
0055     }
0056     bool doesHaveStereo(int det, int lay) const {
0057       if (lo_ == TkLayout::phase2) {
0058         if (det == 1 || det == 2)
0059           return false;
0060         if (det == 4 || det == 5)
0061           return true;
0062         throw std::runtime_error("bad subDet");
0063       }
0064       if (det == 3 || det == 5) {
0065         return lay == 1 || lay == 2;
0066       }
0067       if (det == 4 || det == 6) {
0068         return true;
0069       }
0070       return false;
0071     }
0072 
0073     int convertBarrelLayerNumber(int cmsswdet, int cmsswlay, bool useMatched, int isStereo) const {
0074       int lOffset = 0;
0075       if (lo_ == TkLayout::phase1)
0076         lOffset = 1;
0077       if (cmsswdet == 2 || cmsswdet == 4 || cmsswdet == 6)
0078         return -1;  //FPIX, TID, TEC
0079       if (cmsswdet == 1)
0080         return cmsswlay - 1;  //BPIX
0081       if (useMatched) {
0082         //TIB
0083         if (cmsswdet == 3) {
0084           if (cmsswlay == 1 && isStereo == -1)
0085             return 3 + lOffset;
0086           else if (cmsswlay == 2 && isStereo == -1)
0087             return 4 + lOffset;
0088           else if (cmsswlay == 3 && isStereo == 0)
0089             return 5 + lOffset;
0090           else if (cmsswlay == 4 && isStereo == 0)
0091             return 6 + lOffset;
0092         }
0093         //TOB
0094         else if (cmsswdet == 5) {
0095           if (cmsswlay == 1 && isStereo == -1)
0096             return 7 + lOffset;
0097           else if (cmsswlay == 2 && isStereo == -1)
0098             return 8 + lOffset;
0099           else if (cmsswlay >= 3 && cmsswlay <= 6 && isStereo == 0)
0100             return 6 + cmsswlay + lOffset;
0101         }
0102         return -1;
0103       } else {
0104         //TIB
0105         if (cmsswdet == 3) {
0106           if ((cmsswlay == 1 || cmsswlay == 2) && (isStereo == 0 || isStereo == 1)) {
0107             return 1 + cmsswlay * 2 + isStereo + lOffset;
0108           } else if (cmsswlay == 3 && isStereo == 0)
0109             return 7 + lOffset;
0110           else if (cmsswlay == 4 && isStereo == 0)
0111             return 8 + lOffset;
0112         }
0113         //TOB
0114         else if (cmsswdet == 5) {
0115           if ((cmsswlay == 1 || cmsswlay == 2) && (isStereo == 0 || isStereo == 1)) {
0116             return 7 + cmsswlay * 2 + isStereo + lOffset;
0117           } else if (cmsswlay >= 3 && cmsswlay <= 6 && isStereo == 0)
0118             return 10 + cmsswlay + lOffset;
0119         }
0120         return -1;
0121       }
0122     }
0123     int convertDiskNumber(int cmsswdet, int cmsswdisk, bool useMatched, int isStereo) const {
0124       if (cmsswdet == 1 || cmsswdet == 3 || cmsswdet == 5)
0125         return -1;  //BPIX, TIB, TOB
0126       if (cmsswdet == 2)
0127         return cmsswdisk - 1;  //FPIX
0128       int lOffset = 0;
0129       if (lo_ == TkLayout::phase1)
0130         lOffset = 1;
0131       if (useMatched) {
0132         return -1;
0133       } else {
0134         if ((isStereo != 0 && isStereo != 1) || cmsswdisk < 1)
0135           return -1;
0136         //TID
0137         if (cmsswdet == 4 && cmsswdisk <= 3)
0138           return cmsswdisk * 2 + isStereo + lOffset;
0139         //TEC
0140         else if (cmsswdet == 6 && cmsswdisk <= 9)
0141           return 6 + cmsswdisk * 2 + isStereo + lOffset;
0142         return -1;
0143       }
0144     }
0145 
0146   private:
0147     TkLayout lo_;
0148   };
0149 
0150 }  // end namespace mkfit
0151 
0152 #endif