CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
15 #include <utility>
16 #include <cstdlib>
17 
18 //allows us to move around in the Caloimeter from tower to tower
19 //invalid position is 0,0 no movement is possible for this
20 //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.
21 namespace l1t{
22 
24  public:
25 
26  CaloStage2Nav(); //defaults to 0,0 an invalid position
27  CaloStage2Nav(int iEta,int iPhi);
28  explicit CaloStage2Nav(std::pair<int,int> pos);
29 
30 
31  //this function needs to ensure iPhi is range 1-72
32  static int offsetIPhi(int iPhi,int offset){
33  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
34  else {
35  iPhi+=offset;
36  while(iPhi<=0) iPhi+=72;
37  while(iPhi>72) iPhi-=72;
38  return iPhi;
39  }
40  }
41 
42  //straight forward but have to watch the case where we cross the 0 boundary
43  static int offsetIEta(int iEta,int offset){
44  if(iEta==0) return 0;//invalid starting position
45  else if(iEta*offset>=0) return iEta+offset; //same sign so cant cross zero
46  else if(std::abs(iEta)>std::abs(offset)) return iEta+offset; //offset smaller than iEta, cant cross zero
47  else if(iEta>0) return iEta+offset-1; //must cross zero, if initial iEta postive, then need to sub 1 from result
48  else return iEta+offset+1;
49  }
50 
51  std::pair<int,int> offsetFromCurrPos(int iEtaOffset,int iPhiOffset)const;
52 
53  std::pair<int,int> move(int iEtaOffset,int iPhiOffset);
54  std::pair<int,int> north(){return move(0,1);}
55  std::pair<int,int> south(){return move(0,-1);}
56  std::pair<int,int> east(){return move(1,0);}
57  std::pair<int,int> west(){return move(-1,0);}
58 
59  std::pair<int,int> currPos()const{return currPos_;}
60  int currIEta()const{return currPos().first;}
61  int currIPhi()const{return currPos().second;}
62 
64  void resetIEta(){currPos_.first=homePos_.first;}
65  void resetIPhi(){currPos_.second=homePos_.second;}
66  void setHomePos(int iEta,int iPhi){homePos_.first=iEta;homePos_.second=iPhi;}
67  void setHomePos(std::pair<int,int> pos){setHomePos(pos.first,pos.second);}
68 
69  private:
70  std::pair<int,int> homePos_; //home position, can be reset to this
71  std::pair<int,int> currPos_; //current position, null is 0,0 and no offseting or movement is possible from this (will return 0,0)
72 
73 
74  };
75 
76 }
77 
78 #endif
void setHomePos(int iEta, int iPhi)
Definition: CaloStage2Nav.h:66
std::pair< int, int > homePos_
Definition: CaloStage2Nav.h:70
std::pair< int, int > north()
Definition: CaloStage2Nav.h:54
std::pair< int, int > offsetFromCurrPos(int iEtaOffset, int iPhiOffset) const
static int offsetIEta(int iEta, int offset)
Definition: CaloStage2Nav.h:43
std::pair< int, int > south()
Definition: CaloStage2Nav.h:55
int currIPhi() const
Definition: CaloStage2Nav.h:61
static int offsetIPhi(int iPhi, int offset)
Definition: CaloStage2Nav.h:32
void setHomePos(std::pair< int, int > pos)
Definition: CaloStage2Nav.h:67
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::pair< int, int > currPos_
Definition: CaloStage2Nav.h:71
std::pair< int, int > east()
Definition: CaloStage2Nav.h:56
std::pair< int, int > move(int iEtaOffset, int iPhiOffset)
std::pair< int, int > west()
Definition: CaloStage2Nav.h:57
std::pair< int, int > currPos() const
Definition: CaloStage2Nav.h:59
int currIEta() const
Definition: CaloStage2Nav.h:60