CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TkMSParameterization.h
Go to the documentation of this file.
1 #ifndef TkNavigation_TkMSParameterization_H
2 #define TkNavigation_TkMSParameterization_H
3 
5 
6 #include <array>
7 #include <vector>
8 #include <unordered_map>
9 #include <cmath>
10 #include <algorithm>
11 
12 #include <ostream>
13 
15 namespace tkMSParameterization {
16 
17  constexpr unsigned short packLID(unsigned int id, unsigned int od) { return (id << 8) | od; }
18  constexpr std::tuple<unsigned short, unsigned short> unpackLID(unsigned short lid) {
19  return std::make_tuple(lid >> 8, lid & 255);
20  }
21 
22  constexpr unsigned int nLmBins() { return 12 * 10; }
23  constexpr float lmBin() { return 0.1f; }
24  constexpr float lmBinInv() { return 1.f / lmBin(); }
25 
26  struct Elem {
27  float vi;
28  float vo;
29  float uerr;
30  float verr;
31  };
32 
33  // this shall be sorted by "vo"
34  class Elems {
35  public:
36  Elem find(float v) {
37  auto p = find_if(data.begin(), data.end(), [=](Elem const& d) { return d.vo > v; });
38  if (p != data.begin())
39  --p;
40  return *p;
41  }
42  auto const& operator()() const { return data; }
43 
44  private:
45  std::vector<Elem> data;
47  };
48 
49  class FromToData {
50  public:
51  Elems const& get(float tnLambda) const {
52  auto i = std::min(nLmBins() - 1, (unsigned int)(std::abs(tnLambda) * lmBinInv()));
53  return data[i];
54  }
55 
56  auto const& operator()() const { return data; }
57 
58  private:
59  std::array<Elems, nLmBins()> data;
61  };
62 
63  using AllData = std::unordered_map<unsigned short, FromToData>;
64 
65 } // namespace tkMSParameterization
66 
67 inline std::ostream& operator<<(std::ostream& os, tkMSParameterization::Elem d) {
68  os << d.vi << '/' << d.vo << ':' << d.uerr << '/' << d.verr;
69  return os;
70 }
71 
73 public:
76 
77  FromToData const* fromTo(DetLayer const& in, DetLayer const& out) const { return fromTo(in.seqNum(), out.seqNum()); }
78 
79  FromToData const* fromTo(int in, int out) const {
80  using namespace tkMSParameterization;
81  auto id = packLID(in, out);
82  auto p = data.find(id);
83  if (p != data.end())
84  return &(*p).second;
85  return nullptr;
86  }
87 
88  auto const& operator()() const { return data; }
89 
90 private:
93 };
94 
95 #endif // TkNavigation_TkMSParameterization_H
constexpr unsigned int nLmBins()
tkMSParameterization::AllData AllData
constexpr std::tuple< unsigned short, unsigned short > unpackLID(unsigned short lid)
constexpr float lmBin()
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
std::array< Elems, nLmBins()> data
constexpr unsigned short packLID(unsigned int id, unsigned int od)
tuple d
Definition: ztail.py:151
int seqNum() const
Definition: DetLayer.h:35
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
T min(T a, T b)
Definition: MathUtil.h:58
std::unordered_map< unsigned short, FromToData > AllData
auto const & operator()() const
FromToData const * fromTo(int in, int out) const
auto const & operator()() const
constexpr float lmBinInv()
FromToData const * fromTo(DetLayer const &in, DetLayer const &out) const