CMS 3D CMS Logo

CaloStage2Nav.h
Go to the documentation of this file.
1 
9 //
10 //
11 
12 #ifndef L1Trigger_L1TCalorimeter_CaloStage2Nav_h
13 #define L1Trigger_L1TCalorimeter_CaloStage2Nav_h
14 
16 #include <utility>
17 #include <cstdlib>
18 
19 //allows us to move around in the Caloimeter from tower to tower
20 //invalid position is 0,0 no movement is possible for this
21 //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.
22 namespace l1t{
23 
25  public:
26 
27  CaloStage2Nav(); //defaults to 0,0 an invalid position
28  CaloStage2Nav(int iEta,int iPhi);
29  explicit CaloStage2Nav(std::pair<int,int> pos);
30 
31 
32  //this function needs to ensure iPhi is range 1-72
33  static int offsetIPhi(int iPhi,int offset){
34  if(iPhi==0) 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
35  else {
36  iPhi+=offset;
37  while(iPhi<=0) iPhi+=72;
38  while(iPhi>72) iPhi-=72;
39  return iPhi;
40  }
41  }
42 
43  //straight forward but have to watch the cases where we cross the 0 and/or 29 boundaries
44  static int offsetIEta(int iEta,int offset)
45 {
46 
48  int etaBoundaryHF = CaloTools::kHFBegin;
49 
50  if(iEta==0) return 0;//0 is not a valid position
51  if(abs(iEta)>etaMax) return 0;//beyond +/-41 is not a valid position
52  if(abs(iEta)==etaBoundaryHF) return 0;//+/-29 is not a valid position
53 
54  if(iEta>etaBoundaryHF)
55  {
56  int iEta_tmp = iEta;
57 
58  if(offset<0)
59  {
60  if(iEta_tmp+offset<=etaBoundaryHF) iEta_tmp--;
61  if(iEta_tmp+offset<=0) iEta_tmp--;
62  if(iEta_tmp+offset<=-etaBoundaryHF) iEta_tmp--;
63  if(iEta_tmp+offset<=-etaMax) return -etaMax;
64  return iEta_tmp+offset;
65  }
66  if(offset>=0)
67  {
68  if(iEta_tmp+offset>=etaMax) return etaMax;
69  return iEta_tmp+offset;
70  }
71  }
72  else if(iEta>0)
73  {
74  int iEta_tmp = iEta;
75 
76  if(offset<0)
77  {
78  if(iEta_tmp+offset<=0) iEta_tmp--;
79  if(iEta_tmp+offset<=-etaBoundaryHF) iEta_tmp--;
80  if(iEta_tmp+offset<=-etaMax) return -etaMax;
81  return iEta_tmp+offset;
82  }
83  if(offset>=0)
84  {
85  if(iEta_tmp+offset>=etaBoundaryHF) iEta_tmp++;
86  if(iEta_tmp+offset>=etaMax) return etaMax;
87  else return iEta_tmp+offset;
88  }
89  }
90  else if(iEta>-etaBoundaryHF)
91  {
92  int iEta_tmp = iEta;
93 
94  if(offset<0)
95  {
96  if(iEta_tmp+offset<=-etaBoundaryHF) iEta_tmp--;
97  if(iEta_tmp+offset<=-etaMax) return -etaMax;
98  return iEta_tmp+offset;
99  }
100  if(offset>=0)
101  {
102  if(iEta_tmp+offset>=0) iEta_tmp++;
103  if(iEta_tmp+offset>=etaBoundaryHF) iEta_tmp++;
104  if(iEta_tmp+offset>=etaMax) return etaMax;
105  return iEta_tmp+offset;
106  }
107  }
108  else
109  {
110  int iEta_tmp = iEta;
111 
112  if(offset<0)
113  {
114  if(iEta_tmp+offset<=-etaMax) return -etaMax;
115  return iEta_tmp+offset;
116  }
117  if(offset>=0)
118  {
119  if(iEta_tmp+offset>=-etaBoundaryHF) iEta_tmp++;
120  if(iEta_tmp+offset>=0) iEta_tmp++;
121  if(iEta_tmp+offset>=etaBoundaryHF) iEta_tmp++;
122  if(iEta_tmp+offset>=etaMax) return etaMax;
123  return iEta_tmp+offset;
124  }
125  }
126  return 0;
127  }
128 
129  std::pair<int,int> offsetFromCurrPos(int iEtaOffset,int iPhiOffset)const;
130 
131  std::pair<int,int> move(int iEtaOffset,int iPhiOffset);
132  std::pair<int,int> north(){return move(0,1);}
133  std::pair<int,int> south(){return move(0,-1);}
134  std::pair<int,int> east(){return move(1,0);}
135  std::pair<int,int> west(){return move(-1,0);}
136 
137  std::pair<int,int> currPos()const{return currPos_;}
138  int currIEta()const{return currPos().first;}
139  int currIPhi()const{return currPos().second;}
140 
142  void resetIEta(){currPos_.first=homePos_.first;}
143  void resetIPhi(){currPos_.second=homePos_.second;}
144  void setHomePos(int iEta,int iPhi){homePos_.first=iEta;homePos_.second=iPhi;}
145  void setHomePos(std::pair<int,int> pos){setHomePos(pos.first,pos.second);}
146 
147  private:
148  std::pair<int,int> homePos_; //home position, can be reset to this
149  std::pair<int,int> currPos_; //current position, null is 0,0 and no offseting or movement is possible from this (will return 0,0)
150 
151 
152  };
153 
154 }
155 
156 #endif
void setHomePos(int iEta, int iPhi)
std::pair< int, int > homePos_
std::pair< int, int > north()
std::pair< int, int > offsetFromCurrPos(int iEtaOffset, int iPhiOffset) const
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:44
std::pair< int, int > south()
delete x;
Definition: CaloConfig.h:22
static const int kHFBegin
Definition: CaloTools.h:40
int currIPhi() const
static int offsetIPhi(int iPhi, int offset)
Definition: CaloStage2Nav.h:33
void setHomePos(std::pair< int, int > pos)
static const int kHFEnd
Definition: CaloTools.h:41
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< int, int > currPos_
std::pair< int, int > east()
std::pair< int, int > move(int iEtaOffset, int iPhiOffset)
std::pair< int, int > west()
std::pair< int, int > currPos() const
int currIEta() const