CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GeneralBinFinderInPhi.h
Go to the documentation of this file.
1 #ifndef GeneralBinFinderInPhi_H
2 #define GeneralBinFinderInPhi_H
3 
11 #include "PhiBorderFinder.h"
14 
15 #include <vector>
16 
17 template <class T>
19 public:
20 
21  typedef PhiBorderFinder::Det Det; //FIXME!!!
22 
24 
28  theBins=bf.phiBins();
29  theNbins=theBins.size();
30  }
31 
33  GeneralBinFinderInPhi(std::vector<Det*>::const_iterator first,
34  std::vector<Det*>::const_iterator last)
35  : theNbins( last-first)
36  {
37  std::vector<const Det*> dets(first,last);
38  PhiBorderFinder bf(dets);
40  theBins=bf.phiBins();
41  theNbins=theBins.size();
42  }
43 
45 
48  virtual int binIndex( T phi) const {
49 
50  const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|GeneralBinFinderInPhi";
51 
52  static const T epsilon = 10*std::numeric_limits<T>::epsilon();
53  // Assume -pi, pi range in pi (which is the case for Geom::Phi
54 
55  LogTrace(metname) << "GeneralBinFinderInPhi::binIndex,"
56  << " Nbins: "<< theNbins;
57 
58  for (int i = 0; i< theNbins; i++) {
59 
60  T cur = theBorders[i];
61  T next = theBorders[binIndex(i+1)];
62  T phi_ = phi;
63 
64  LogTrace(metname) << "bin: " << i
65  << " border min " << cur << " border max: " << next << " phi: "<< phi_;
66 
67  if ( cur > next ) // we are crossing the pi edge: so move the edge to 0!
68  {
69  cur = positiveRange(cur);
70  next = positiveRange(next);
71  phi_ = positiveRange(phi_);
72  }
73  if (phi_ > cur-epsilon && phi_ < next) return i;
74  }
75  throw cms::Exception("UnexpectedState") << "GeneralBinFinderInPhi::binIndex( T phi) bin not found!";
76  }
77 
79  virtual int binIndex( int i) const {
80  int ind = i % (int)theNbins;
81  return (ind < 0) ? ind+theNbins : ind;
82  }
83 
85  virtual T binPosition( int ind) const {
86  return theBins[binIndex(ind)];
87  }
88 
89 
90 private:
91  int theNbins;
92  std::vector<T> theBorders;
93  std::vector<T> theBins;
94 
95  // returns a positive angle; does NOT reduce the range to 2 pi
96  inline T positiveRange (T phi) const
97  {
98  return (phi > 0) ? phi : phi + Geom::twoPi();
99  }
100 
101 };
102 #endif
103 
int i
Definition: DBlmapReader.cc:9
virtual int binIndex(T phi) const
GeneralBinFinderInPhi(const PhiBorderFinder &bf)
Construct from an already initialized PhiBorderFinder.
const std::string metname
PhiBorderFinder::Det Det
const std::vector< double > & phiBorders() const
virtual int binIndex(int i) const
Returns an index in the valid range, modulo Nbins.
bool first
Definition: L1TdeRCT.cc:75
#define LogTrace(id)
Definition: DetRod.h:13
double twoPi()
Definition: Pi.h:32
const double epsilon
long double T
const std::vector< double > & phiBins() const
The centers of the Dets.
GeneralBinFinderInPhi(std::vector< Det * >::const_iterator first, std::vector< Det * >::const_iterator last)
Construct from the list of Det*.
virtual T binPosition(int ind) const
the middle of the bin in radians
Definition: DDAxes.h:10