File indexing completed on 2024-04-06 12:31:27
0001 #ifndef DetLayers_PeriodicBinFinderInZ_H
0002 #define DetLayers_PeriodicBinFinderInZ_H
0003
0004 #include "Utilities/BinningTools/interface/BaseBinFinder.h"
0005 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0006 #include <cmath>
0007
0008
0009
0010
0011
0012 template <class T>
0013 class PeriodicBinFinderInZ : public BaseBinFinder<T> {
0014 public:
0015 PeriodicBinFinderInZ() : theNbins(0), theZStep(0), theZOffset(0) {}
0016
0017 PeriodicBinFinderInZ(std::vector<const GeomDet*>::const_iterator first,
0018 std::vector<const GeomDet*>::const_iterator last)
0019 : theNbins(last - first) {
0020 float zFirst = (**first).surface().position().z();
0021 theZStep = ((**(last - 1)).surface().position().z() - zFirst) / (theNbins - 1);
0022 theZOffset = zFirst - 0.5 * theZStep;
0023 }
0024
0025
0026 int binIndex(T z) const override { return binIndex(int((z - theZOffset) / theZStep)); }
0027
0028
0029 int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
0030
0031
0032 T binPosition(int ind) const override { return theZOffset + theZStep * (ind + 0.5); }
0033
0034 private:
0035 int theNbins;
0036 T theZStep;
0037 T theZOffset;
0038 };
0039 #endif