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 template <class T>
24 T offsetBy(T start, CaloSubdetectorTopology const* topo, int dIEtaOrIX, int dIPhiOrIY) {
25  if (topo) {
26  for (int i = 0; i < std::abs(dIEtaOrIX) && start != T(0); i++) {
27  start = dIEtaOrIX > 0 ? topo->goEast(start) : topo->goWest(start);
28  }
29 
30  for (int i = 0; i < std::abs(dIPhiOrIY) && start != T(0); i++) {
31  start = dIPhiOrIY > 0 ? topo->goNorth(start) : topo->goSouth(start);
32  }
33  }
34  return start;
35 }
36 
37 template <class T>
39 public:
40  class Iterator {
41  public:
42  Iterator(T const& home,
43  int iEtaOrIX,
44  int iPhiOrIY,
45  CaloRectangle const rectangle,
48 
52  iEtaOrIX_++;
53  } else
54  ++iPhiOrIY_;
55  return *this;
56  }
57 
58  int iEtaOrIX() const { return iEtaOrIX_; }
59  int iPhiOrIY() const { return iPhiOrIY_; }
60 
61  bool operator==(Iterator const& other) const {
62  return iEtaOrIX_ == other.iEtaOrIX() && iPhiOrIY_ == other.iPhiOrIY();
63  }
64  bool operator!=(Iterator const& other) const {
65  return iEtaOrIX_ != other.iEtaOrIX() || iPhiOrIY_ != other.iPhiOrIY();
66  }
67 
69 
70  private:
71  const T home_;
72 
75 
76  int iEtaOrIX_;
77  int iPhiOrIY_;
78  };
79 
80 public:
82  : home_(home), rectangle_(rectangle), topology_(topology.getSubdetectorTopology(home)) {}
83 
85  : home_(home), rectangle_{-size, size, -size, size}, topology_(topology.getSubdetectorTopology(home)) {}
86 
89 
90 private:
91  const T home_;
94 };
95 
96 template <class T>
98  return CaloRectangleRange<T>(*this, home, topology);
99 }
100 
101 #endif
size
Write out results.
Definition: start.py:1
virtual DetId goNorth(const DetId &id) const
const int iEtaOrIXMax
Definition: CaloRectangle.h:15
CaloRectangleRange(int size, T home, CaloTopology const &topology)
Definition: CaloRectangle.h:84
const CaloRectangle rectangle_
Definition: CaloRectangle.h:73
bool operator!=(Iterator const &other) const
Definition: CaloRectangle.h:64
virtual DetId goSouth(const DetId &id) const
TGeoIterator Iterator
CaloRectangleRange(CaloRectangle rectangle, T home, CaloTopology const &topology)
Definition: CaloRectangle.h:81
const CaloRectangle rectangle_
Definition: CaloRectangle.h:92
Iterator(T const &home, int iEtaOrIX, int iPhiOrIY, CaloRectangle const rectangle, CaloSubdetectorTopology const *topology)
Definition: CaloRectangle.h:42
auto operator()(T home, CaloTopology const &topology)
Definition: CaloRectangle.h:97
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const int iPhiOrIYMax
Definition: CaloRectangle.h:17
virtual DetId goEast(const DetId &id) const
const int iPhiOrIYMin
Definition: CaloRectangle.h:16
const int iEtaOrIXMin
Definition: CaloRectangle.h:14
bool operator==(Iterator const &other) const
Definition: CaloRectangle.h:61
T offsetBy(T start, CaloSubdetectorTopology const *topo, int dIEtaOrIX, int dIPhiOrIY)
Definition: CaloRectangle.h:24
virtual DetId goWest(const DetId &id) const
long double T
CaloSubdetectorTopology const * topology_
Definition: CaloRectangle.h:74
CaloSubdetectorTopology const * topology_
Definition: CaloRectangle.h:93