CMS 3D CMS Logo

PeriodicBinFinderInZ.h
Go to the documentation of this file.
1 #ifndef DetLayers_PeriodicBinFinderInZ_H
2 #define DetLayers_PeriodicBinFinderInZ_H
3 
6 #include <cmath>
7 
12 template <class T>
14 public:
16 
17  PeriodicBinFinderInZ(std::vector<const GeomDet*>::const_iterator first,
18  std::vector<const GeomDet*>::const_iterator last)
19  : theNbins(last - first) {
20  float zFirst = (**first).surface().position().z();
21  theZStep = ((**(last - 1)).surface().position().z() - zFirst) / (theNbins - 1);
22  theZOffset = zFirst - 0.5 * theZStep;
23  }
24 
26  int binIndex(T z) const override { return binIndex(int((z - theZOffset) / theZStep)); }
27 
29  int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
30 
32  T binPosition(int ind) const override { return theZOffset + theZStep * (ind + 0.5); }
33 
34 private:
35  int theNbins;
38 };
39 #endif
int binIndex(int i) const override
returns an index in the valid range
T binPosition(int ind) const override
the middle of the bin
T min(T a, T b)
Definition: MathUtil.h:58
int binIndex(T z) const override
returns an index in the valid range for the bin that contains Z
PeriodicBinFinderInZ(std::vector< const GeomDet * >::const_iterator first, std::vector< const GeomDet * >::const_iterator last)
long double T