CMS 3D CMS Logo

GeneralBinFinderInPhi.h
Go to the documentation of this file.
1 #ifndef TrackingTools_DetLayers_GeneralBinFinderInPhi_H
2 #define TrackingTools_DetLayers_GeneralBinFinderInPhi_H
3 
14 
15 #include <vector>
16 
17 template <class T>
19 public:
20  typedef PhiBorderFinder::Det Det; //FIXME!!!
21 
23 
26  theBorders = bf.phiBorders();
27  theBins = bf.phiBins();
28  theNbins = theBins.size();
29  }
30 
32  GeneralBinFinderInPhi(std::vector<Det*>::const_iterator first, std::vector<Det*>::const_iterator last)
33  : theNbins(last - first) {
34  std::vector<const Det*> dets(first, last);
35  PhiBorderFinder bf(dets);
36  theBorders = bf.phiBorders();
37  theBins = bf.phiBins();
38  theNbins = theBins.size();
39  }
40 
41  ~GeneralBinFinderInPhi() override{};
42 
45  int binIndex(T phi) const override {
46  const std::string metname = "Muon|RecoMuon|RecoMuonDetLayers|GeneralBinFinderInPhi";
47 
48  static const T epsilon = 10 * std::numeric_limits<T>::epsilon();
49  // Assume -pi, pi range in pi (which is the case for Geom::Phi
50 
51  LogTrace(metname) << "GeneralBinFinderInPhi::binIndex,"
52  << " Nbins: " << theNbins;
53 
54  for (int i = 0; i < theNbins; i++) {
55  T cur = theBorders[i];
56  T next = theBorders[binIndex(i + 1)];
57  T phi_ = phi;
58 
59  LogTrace(metname) << "bin: " << i << " border min " << cur << " border max: " << next << " phi: " << phi_;
60 
61  if (cur > next) // we are crossing the pi edge: so move the edge to 0!
62  {
63  cur = positiveRange(cur);
65  phi_ = positiveRange(phi_);
66  }
67  if (phi_ > cur - epsilon && phi_ < next)
68  return i;
69  }
70  throw cms::Exception("UnexpectedState") << "GeneralBinFinderInPhi::binIndex( T phi) bin not found!";
71  }
72 
74  int binIndex(int i) const override {
75  int ind = i % (int)theNbins;
76  return (ind < 0) ? ind + theNbins : ind;
77  }
78 
80  T binPosition(int ind) const override { return theBins[binIndex(ind)]; }
81 
82 private:
83  int theNbins;
84  std::vector<T> theBorders;
85  std::vector<T> theBins;
86 
87  // returns a positive angle; does NOT reduce the range to 2 pi
88  inline T positiveRange(T phi) const { return (phi > 0) ? phi : phi + Geom::twoPi(); }
89 };
90 #endif
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
PhiBorderFinder
Definition: PhiBorderFinder.h:27
PhiBorderFinder::phiBins
const std::vector< double > & phiBins() const
The centers of the Dets.
Definition: PhiBorderFinder.h:49
PhiBorderFinder.h
GeneralBinFinderInPhi::theBins
std::vector< T > theBins
Definition: GeneralBinFinderInPhi.h:85
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
dqmdumpme.last
last
Definition: dqmdumpme.py:56
PhiBorderFinder::phiBorders
const std::vector< double > & phiBorders() const
Definition: PhiBorderFinder.h:46
GeneralBinFinderInPhi::positiveRange
T positiveRange(T phi) const
Definition: GeneralBinFinderInPhi.h:88
GeneralBinFinderInPhi::Det
PhiBorderFinder::Det Det
Definition: GeneralBinFinderInPhi.h:20
DetRod
Definition: DetRod.h:13
GeneralBinFinderInPhi::GeneralBinFinderInPhi
GeneralBinFinderInPhi(const PhiBorderFinder &bf)
Construct from an already initialized PhiBorderFinder.
Definition: GeneralBinFinderInPhi.h:25
Geom::twoPi
constexpr double twoPi()
Definition: Pi.h:32
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
GeneralBinFinderInPhi::theBorders
std::vector< T > theBorders
Definition: GeneralBinFinderInPhi.h:84
Pi.h
GeneralBinFinderInPhi::GeneralBinFinderInPhi
GeneralBinFinderInPhi()
Definition: GeneralBinFinderInPhi.h:22
createfilelist.int
int
Definition: createfilelist.py:10
GeneralBinFinderInPhi::~GeneralBinFinderInPhi
~GeneralBinFinderInPhi() override
Definition: GeneralBinFinderInPhi.h:41
BaseBinFinder.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDAxes::phi
GeneralBinFinderInPhi::binPosition
T binPosition(int ind) const override
the middle of the bin in radians
Definition: GeneralBinFinderInPhi.h:80
GeneralBinFinderInPhi::binIndex
int binIndex(int i) const override
Returns an index in the valid range, modulo Nbins.
Definition: GeneralBinFinderInPhi.h:74
GeneralBinFinderInPhi::binIndex
int binIndex(T phi) const override
Definition: GeneralBinFinderInPhi.h:45
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:245
BaseBinFinder
Definition: BaseBinFinder.h:11
GeneralBinFinderInPhi
Definition: GeneralBinFinderInPhi.h:18
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
GeneralBinFinderInPhi::GeneralBinFinderInPhi
GeneralBinFinderInPhi(std::vector< Det * >::const_iterator first, std::vector< Det * >::const_iterator last)
Construct from the list of Det*.
Definition: GeneralBinFinderInPhi.h:32
GeneralBinFinderInPhi::theNbins
int theNbins
Definition: GeneralBinFinderInPhi.h:83
GetRecoTauVFromDQM_MC_cff.next
next
Definition: GetRecoTauVFromDQM_MC_cff.py:31
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:40