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