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 
13 #include "PhiBorderFinder.h"
16 
17 #include <vector>
18 
19 template <class T>
21 public:
22 
23  typedef PhiBorderFinder::Det Det; //FIXME!!!
24 
26 
30  theBins=bf.phiBins();
31  theNbins=theBins.size();
32  }
33 
35  GeneralBinFinderInPhi(std::vector<Det*>::const_iterator first,
36  std::vector<Det*>::const_iterator last)
37  : theNbins( last-first)
38  {
39  std::vector<const Det*> dets(first,last);
40  PhiBorderFinder bf(dets);
42  theBins=bf.phiBins();
43  theNbins=theBins.size();
44  }
45 
47 
50  virtual int binIndex( T phi) const {
51 
52  const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|GeneralBinFinderInPhi";
53 
55  // Assume -pi, pi range in pi (which is the case for Geom::Phi
56 
57  LogTrace(metname) << "GeneralBinFinderInPhi::binIndex,"
58  << " Nbins: "<< theNbins;
59 
60  for (int i = 0; i< theNbins; i++) {
61 
62  T cur = theBorders[i];
63  T next = theBorders[binIndex(i+1)];
64  T phi_ = phi;
65 
66  LogTrace(metname) << "bin: " << i
67  << " border min " << cur << " border max: " << next << " phi: "<< phi_;
68 
69  if ( cur > next ) // we are crossing the pi edge: so move the edge to 0!
70  {
71  cur = positiveRange(cur);
72  next = positiveRange(next);
73  phi_ = positiveRange(phi_);
74  }
75  if (phi_ > cur-epsilon && phi_ < next) return i;
76  }
77  throw cms::Exception("UnexpectedState") << "GeneralBinFinderInPhi::binIndex( T phi) bin not found!";
78  }
79 
81  virtual int binIndex( int i) const {
82  int ind = i % (int)theNbins;
83  return (ind < 0) ? ind+theNbins : ind;
84  }
85 
87  virtual T binPosition( int ind) const {
88  return theBins[binIndex(ind)];
89  }
90 
91 
92 private:
93  int theNbins;
94  std::vector<T> theBorders;
95  std::vector<T> theBins;
96 
97  // returns a positive angle; does NOT reduce the range to 2 pi
98  inline T positiveRange (T phi) const
99  {
100  return (phi > 0) ? phi : phi + Geom::twoPi();
101  }
102 
103 };
104 #endif
105 
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:94
#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