CMS 3D CMS Logo

CaloRectangle.h
Go to the documentation of this file.
1 #ifndef RecoCaloTools_Navigation_CaloRectangle_H
2 #define RecoCaloTools_Navigation_CaloRectangle_H
3 
6 
7 /*
8  * CaloRectangle is a class to create a rectangular range of DetIds around a
9  * central DetId. Meant to be used for range-based loops to calculate cluster
10  * shape variables.
11  */
12 
13 struct CaloRectangle {
14  const int iEtaOrIXMin;
15  const int iEtaOrIXMax;
16  const int iPhiOrIYMin;
17  const int iPhiOrIYMax;
18 
19  template<class T>
20  auto operator()(T home, CaloTopology const& topology);
21 
22 };
23 
24 template<class T>
25 T offsetBy(T start, CaloSubdetectorTopology const& topo, int dIEtaOrIX, int dIPhiOrIY)
26 {
27  for(int i = 0; i < std::abs(dIEtaOrIX) && start != T(0); i++) {
28  start = dIEtaOrIX > 0 ? topo.goEast(start) : topo.goWest(start);
29  }
30 
31  for(int i = 0; i < std::abs(dIPhiOrIY) && start != T(0); i++) {
32  start = dIPhiOrIY > 0 ? topo.goNorth(start) : topo.goSouth(start);
33  }
34  return start;
35 }
36 
37 template<class T>
39 
40  public:
41 
42  class Iterator {
43 
44  public:
45 
46  Iterator(T const& home, int iEtaOrIX, int iPhiOrIY, CaloRectangle const rectangle, CaloSubdetectorTopology const& topology)
47  : home_(home)
48  , rectangle_(rectangle)
49  , topology_(topology)
50  , iEtaOrIX_(iEtaOrIX)
51  , iPhiOrIY_(iPhiOrIY)
52  {}
53 
55  if(iPhiOrIY_ == rectangle_.iPhiOrIYMax) {
56  iPhiOrIY_ = rectangle_.iPhiOrIYMin;
57  iEtaOrIX_++;
58  } else ++iPhiOrIY_;
59  return *this;
60  }
61 
62  int iEtaOrIX() const { return iEtaOrIX_; }
63  int iPhiOrIY() const { return iPhiOrIY_; }
64 
65  bool operator==(Iterator const& other) const { return iEtaOrIX_ == other.iEtaOrIX() && iPhiOrIY_ == other.iPhiOrIY(); }
66  bool operator!=(Iterator const& other) const { return iEtaOrIX_ != other.iEtaOrIX() || iPhiOrIY_ != other.iPhiOrIY(); }
67 
68  T operator*() const { return offsetBy(home_, topology_, iEtaOrIX_, iPhiOrIY_); }
69 
70  private:
71 
72  const T home_;
73 
76 
77  int iEtaOrIX_;
78  int iPhiOrIY_;
79  };
80 
81  public:
83  : home_(home)
84  , rectangle_(rectangle)
85  , topology_(*topology.getSubdetectorTopology(home))
86  {}
87 
89  : home_(home)
90  , rectangle_{-size, size, -size, size}
91  , topology_(*topology.getSubdetectorTopology(home))
92  {}
93 
94  auto begin() {
95  return Iterator(home_, rectangle_.iEtaOrIXMin, rectangle_.iPhiOrIYMin, rectangle_, topology_);
96  }
97  auto end() {
98  return Iterator(home_, rectangle_.iEtaOrIXMax + 1, rectangle_.iPhiOrIYMin, rectangle_, topology_);
99  }
100 
101  private:
102  const T home_;
105 };
106 
107 template<class T>
109  return CaloRectangleRange<T>(*this, home, topology);
110 }
111 
112 #endif
virtual DetId goSouth(const DetId &id) const
virtual DetId goWest(const DetId &id) const
size
Write out results.
Definition: start.py:1
CaloSubdetectorTopology const & topology_
const int iEtaOrIXMax
Definition: CaloRectangle.h:15
CaloTopology const * topology(0)
CaloRectangleRange(int size, T home, CaloTopology const &topology)
Definition: CaloRectangle.h:88
const CaloRectangle rectangle_
Definition: CaloRectangle.h:74
virtual DetId goEast(const DetId &id) const
TGeoIterator Iterator
CaloRectangleRange(CaloRectangle rectangle, T home, CaloTopology const &topology)
Definition: CaloRectangle.h:82
const CaloRectangle rectangle_
auto operator()(T home, CaloTopology const &topology)
virtual DetId goNorth(const DetId &id) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int iPhiOrIYMax
Definition: CaloRectangle.h:17
const int iPhiOrIYMin
Definition: CaloRectangle.h:16
const int iEtaOrIXMin
Definition: CaloRectangle.h:14
T offsetBy(T start, CaloSubdetectorTopology const &topo, int dIEtaOrIX, int dIPhiOrIY)
Definition: CaloRectangle.h:25
Iterator(T const &home, int iEtaOrIX, int iPhiOrIY, CaloRectangle const rectangle, CaloSubdetectorTopology const &topology)
Definition: CaloRectangle.h:46
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:20
bool operator!=(Iterator const &other) const
Definition: CaloRectangle.h:66
bool operator==(Iterator const &other) const
Definition: CaloRectangle.h:65
long double T
CaloSubdetectorTopology const & topology_
Definition: CaloRectangle.h:75