CMS 3D CMS Logo

GenericBinFinderInZ.h
Go to the documentation of this file.
1 #ifndef BinningTools_GenericBinFinderInZ_H
2 #define BinningTools_GenericBinFinderInZ_H
3 
12 #include <cmath>
13 #include <vector>
14 
15 template <class T, class G>
17 public:
18  typedef typename std::vector<const G*>::const_iterator ConstItr;
20 
21  GenericBinFinderInZ(ConstItr first, ConstItr last) :
22  theNbins( last-first)
23  {
24  theBins.reserve(theNbins);
25  theBorders.reserve(theNbins-1);
26  for (ConstItr i=first; i<last-1; i++) {
27  theBins.push_back((**i).position().z());
28  theBorders.push_back(((**i).position().z() +
29  (**(i+1)).position().z()) / 2.);
30  }
31  theBins.push_back((**(last-1)).position().z());
32 
33  theZOffset = theBorders.front();
34  theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
35  }
36 
38  int binIndex( T z) const override {
39  int bin = binIndex( int((z-theZOffset)/theZStep)+1);
40 
41  // check left border
42  if (bin > 0) {
43  if ( z < theBorders[bin-1]) {
44  // z is to the left of the left border, the correct bin is left
45  for (int i=bin-1; ; i--) {
46  if (i <= 0) return 0;
47  if ( z > theBorders[i-1]) return i;
48  }
49  }
50  }
51  else return 0;
52 
53  // check right border
54  if (bin < theNbins-1) {
55  if ( z > theBorders[bin]) {
56  // z is to the right of the right border, the correct bin is right
57  for (int i=bin+1; ; i++) {
58  if (i >= theNbins-1) return theNbins-1;
59  if ( z < theBorders[i]) return i;
60  }
61  }
62  }
63  else return theNbins-1;
64 
65  // if we arrive here it means that the bin is ok
66  return bin;
67  }
68 
70  int binIndex( int i) const override {
71  return std::min( std::max( i, 0), theNbins-1);
72  }
73 
75  T binPosition( int ind) const override {
76  return theBins[binIndex(ind)];
77  }
78 
79  static double pi() { return 3.141592653589793238;}
80  static double twoPi() { return 2.*pi();}
81 
82 private:
83 
84  int theNbins;
87  std::vector<float> theBorders;
88  std::vector<T> theBins;
89 };
90 #endif
GenericBinFinderInZ(ConstItr first, ConstItr last)
T binPosition(int ind) const override
the middle of the bin.
int binIndex(T z) const override
returns an index in the valid range for the bin closest to Z
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< T > theBins
bin
set the eta bin as selection string.
std::vector< const G * >::const_iterator ConstItr
int binIndex(int i) const override
returns an index in the valid range
static int position[264][3]
Definition: ReadPGInfo.cc:509
long double T
std::vector< float > theBorders