Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:16

0001 ///
0002 /// Description: Simple Navigator class for the CaloTowers
0003 ///
0004 ///
0005 ///
0006 /// \authors: Sam Harper - RAL, Olivier Davignon - Bristol
0007 ///
0008 
0009 //
0010 //
0011 
0012 #ifndef L1Trigger_L1TCalorimeter_CaloStage2Nav_h
0013 #define L1Trigger_L1TCalorimeter_CaloStage2Nav_h
0014 
0015 #include "L1Trigger/L1TCalorimeter/interface/CaloTools.h"
0016 #include <utility>
0017 #include <cstdlib>
0018 
0019 //allows us to move around in the Caloimeter from tower to tower
0020 //invalid position is 0,0 no movement is possible for this
0021 //0 is technically a valid phi position (0 for eta is really not) so we could have phi movement from such a position but I've decided that would be confusing have phi move and eta not.
0022 namespace l1t {
0023 
0024   class CaloStage2Nav {
0025   public:
0026     CaloStage2Nav();  //defaults to 0,0 an invalid position
0027     CaloStage2Nav(int iEta, int iPhi);
0028     explicit CaloStage2Nav(std::pair<int, int> pos);
0029 
0030     //this function needs to ensure iPhi is range 1-72
0031     static int offsetIPhi(int iPhi, int offset) {
0032       if (iPhi == 0)
0033         return 0;  //some debate here on whether I should accept 0 and just cast it to 72, I've decided that it is less confusing for 0,0 (the invalid position) to not move eta or phi rather than allowing phi to move
0034       else {
0035         iPhi += offset;
0036         while (iPhi <= 0)
0037           iPhi += 72;
0038         while (iPhi > 72)
0039           iPhi -= 72;
0040         return iPhi;
0041       }
0042     }
0043 
0044     //straight forward but have to watch the cases where we cross the 0 and/or 29 boundaries
0045     static int offsetIEta(int iEta, int offset) {
0046       int etaMax = CaloTools::kHFEnd;
0047       int etaBoundaryHF = CaloTools::kHFBegin;
0048 
0049       if (iEta == 0)
0050         return 0;  //0 is not a valid position
0051       if (abs(iEta) > etaMax)
0052         return 0;  //beyond +/-41 is not a valid position
0053       if (abs(iEta) == etaBoundaryHF)
0054         return 0;  //+/-29 is not a valid position
0055 
0056       if (iEta > etaBoundaryHF) {
0057         int iEta_tmp = iEta;
0058 
0059         if (offset < 0) {
0060           if (iEta_tmp + offset <= etaBoundaryHF)
0061             iEta_tmp--;
0062           if (iEta_tmp + offset <= 0)
0063             iEta_tmp--;
0064           if (iEta_tmp + offset <= -etaBoundaryHF)
0065             iEta_tmp--;
0066           if (iEta_tmp + offset <= -etaMax)
0067             return -etaMax;
0068           return iEta_tmp + offset;
0069         }
0070         if (offset >= 0) {
0071           if (iEta_tmp + offset >= etaMax)
0072             return etaMax;
0073           return iEta_tmp + offset;
0074         }
0075       } else if (iEta > 0) {
0076         int iEta_tmp = iEta;
0077 
0078         if (offset < 0) {
0079           if (iEta_tmp + offset <= 0)
0080             iEta_tmp--;
0081           if (iEta_tmp + offset <= -etaBoundaryHF)
0082             iEta_tmp--;
0083           if (iEta_tmp + offset <= -etaMax)
0084             return -etaMax;
0085           return iEta_tmp + offset;
0086         }
0087         if (offset >= 0) {
0088           if (iEta_tmp + offset >= etaBoundaryHF)
0089             iEta_tmp++;
0090           if (iEta_tmp + offset >= etaMax)
0091             return etaMax;
0092           else
0093             return iEta_tmp + offset;
0094         }
0095       } else if (iEta > -etaBoundaryHF) {
0096         int iEta_tmp = iEta;
0097 
0098         if (offset < 0) {
0099           if (iEta_tmp + offset <= -etaBoundaryHF)
0100             iEta_tmp--;
0101           if (iEta_tmp + offset <= -etaMax)
0102             return -etaMax;
0103           return iEta_tmp + offset;
0104         }
0105         if (offset >= 0) {
0106           if (iEta_tmp + offset >= 0)
0107             iEta_tmp++;
0108           if (iEta_tmp + offset >= etaBoundaryHF)
0109             iEta_tmp++;
0110           if (iEta_tmp + offset >= etaMax)
0111             return etaMax;
0112           return iEta_tmp + offset;
0113         }
0114       } else {
0115         int iEta_tmp = iEta;
0116 
0117         if (offset < 0) {
0118           if (iEta_tmp + offset <= -etaMax)
0119             return -etaMax;
0120           return iEta_tmp + offset;
0121         }
0122         if (offset >= 0) {
0123           if (iEta_tmp + offset >= -etaBoundaryHF)
0124             iEta_tmp++;
0125           if (iEta_tmp + offset >= 0)
0126             iEta_tmp++;
0127           if (iEta_tmp + offset >= etaBoundaryHF)
0128             iEta_tmp++;
0129           if (iEta_tmp + offset >= etaMax)
0130             return etaMax;
0131           return iEta_tmp + offset;
0132         }
0133       }
0134       return 0;
0135     }
0136 
0137     std::pair<int, int> offsetFromCurrPos(int iEtaOffset, int iPhiOffset) const;
0138 
0139     std::pair<int, int> move(int iEtaOffset, int iPhiOffset);
0140     std::pair<int, int> north() { return move(0, 1); }
0141     std::pair<int, int> south() { return move(0, -1); }
0142     std::pair<int, int> east() { return move(1, 0); }
0143     std::pair<int, int> west() { return move(-1, 0); }
0144 
0145     std::pair<int, int> currPos() const { return currPos_; }
0146     int currIEta() const { return currPos().first; }
0147     int currIPhi() const { return currPos().second; }
0148 
0149     void resetPos() { currPos_ = homePos_; }
0150     void resetIEta() { currPos_.first = homePos_.first; }
0151     void resetIPhi() { currPos_.second = homePos_.second; }
0152     void setHomePos(int iEta, int iPhi) {
0153       homePos_.first = iEta;
0154       homePos_.second = iPhi;
0155     }
0156     void setHomePos(std::pair<int, int> pos) { setHomePos(pos.first, pos.second); }
0157 
0158   private:
0159     std::pair<int, int> homePos_;  //home position, can be reset to this
0160     std::pair<int, int>
0161         currPos_;  //current position, null is 0,0 and no offseting or movement is possible from this (will return 0,0)
0162   };
0163 
0164 }  // namespace l1t
0165 
0166 #endif