CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeneralBinFinderInZforGeometricSearchDet.h
Go to the documentation of this file.
1 #ifndef GeneralBinFinderInZ_H
2 #define GeneralBinFinderInZ_H
3 
10 #include <cmath>
11 
12 template <class T>
14 public:
15 
17 
19  std::vector<const GeometricSearchDet*>::const_iterator first,
20  std::vector<const GeometricSearchDet*>::const_iterator last) :
21  theNbins( last-first)
22  {
23  theBins.reserve(theNbins);
24  for (std::vector<const GeometricSearchDet*>::const_iterator i=first; i<last-1; i++) {
25  theBins.push_back((**i).position().z());
26  theBorders.push_back(((**i).position().z() +
27  (**(i+1)).position().z()) / 2.);
28  }
29 
30  theZOffset = theBorders.front();
31  theZStep = (theBorders.back() - theBorders.front()) / (theNbins-2);
32  }
33 
35  virtual int binIndex( T z) const {
36  int bin = binIndex( int((z-theZOffset)/theZStep)+1);
37 
38  // check left border
39  if (bin > 0) {
40  if ( z < theBorders[bin-1]) {
41  // z is to the left of the left border, the correct bin is left
42  for (int i=bin-1; ; i--) {
43  if (i <= 0) return 0;
44  if ( z > theBorders[i-1]) return i;
45  }
46  }
47  }
48  else return 0;
49 
50  // check right border
51  if (bin < theNbins-1) {
52  if ( z > theBorders[bin]) {
53  // z is to the right of the right border, the correct bin is right
54  for (int i=bin+1; ; i++) {
55  if (i >= theNbins-1) return theNbins-1;
56  if ( z < theBorders[i]) return i;
57  }
58  }
59  }
60  else return theNbins-1;
61 
62  // if we arrive here it means that the bin is ok
63  return bin;
64  }
65 
67  virtual int binIndex( int i) const {
68  return std::min( std::max( i, 0), theNbins-1);
69  }
70 
72  virtual T binPosition( int ind) const {
73  return theBins[binIndex(ind)];
74  }
75 
76  static double pi() { return 3.141592653589793238;}
77  static double twoPi() { return 2.*pi();}
78 
79 private:
80 
81  int theNbins;
84  std::vector<float> theBorders;
85  std::vector<T> theBins;
86 };
87 #endif
int i
Definition: DBlmapReader.cc:9
virtual T binPosition(int ind) const
the middle of the bin.
GeneralBinFinderInZforGeometricSearchDet(std::vector< const GeometricSearchDet * >::const_iterator first, std::vector< const GeometricSearchDet * >::const_iterator last)
#define min(a, b)
Definition: mlp_lapack.h:161
virtual int binIndex(int i) const
returns an index in the valid range
double double double z
const T & max(const T &a, const T &b)
bool first
Definition: L1TdeRCT.cc:94
long double T
virtual int binIndex(T z) const
returns an index in the valid range for the bin closest to Z