Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:31:31

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 /** Bin finder along the global Z for (almost) equidistant bins.
0009  *  The bins are computed from GeomDet positions.
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   /// returns an index in the valid range for the bin that contains Z
0026   int binIndex(T z) const override { return binIndex(int((z - theZOffset) / theZStep)); }
0027 
0028   /// returns an index in the valid range
0029   int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
0030 
0031   /// the middle of the bin
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