CMS 3D CMS Logo

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 
14 
17 
18  constexpr unsigned short packLID(unsigned int id, unsigned int od) { return (id<<8) | od ;}
19  constexpr std::tuple<unsigned short, unsigned short> unpackLID(unsigned short lid) { return std::make_tuple(lid>>8, lid&255);}
20 
21 
22 
23  constexpr unsigned int nLmBins() { return 12*10;}
24  constexpr float lmBin() { return 0.1f;}
25  constexpr float lmBinInv() { return 1.f/lmBin();}
26 
27  struct Elem {
28  float vi;
29  float vo;
30  float uerr;
31  float verr;
32  };
33 
34  // this shall be sorted by "vo"
35  class Elems {
36  public:
37  Elem find(float v) {
38  auto p = find_if(data.begin(),data.end(),[=](Elem const & d) { return d.vo>v;});
39  if (p!=data.begin()) --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 
52  Elems const & get(float tnLambda) const {
53  auto i = std::min(nLmBins()-1,(unsigned int)(std::abs(tnLambda)*lmBinInv()));
54  return data[i];
55  }
56 
57  auto const& operator()() const { return data;}
58  private:
59  std::array<Elems,nLmBins()> data;
61  };
62 
63  using AllData = std::unordered_map<unsigned short, FromToData>;
64 
65 }
66 
67 inline
68 std::ostream & operator<<(std::ostream & os, tkMSParameterization::Elem d) {
69  os <<d.vi<<'/'<<d.vo<<':'<<d.uerr<<'/'<<d.verr;
70  return os;
71 }
72 
73 
75 public:
78 
79  FromToData const * fromTo(DetLayer const & in, DetLayer const & out) const {
80  return fromTo(in.seqNum(),out.seqNum());
81  }
82 
83 
84  FromToData const * fromTo(int in, int out) const {
85  using namespace tkMSParameterization;
86  auto id = packLID(in,out);
87  auto p = data.find(id);
88  if (p!=data.end()) return &(*p).second;
89  return nullptr;
90  }
91 
92 
93  auto const& operator()() const { return data;}
94 
95 private:
98 };
99 
100 
101 
102 #endif // TkNavigation_TkMSParameterization_H
103 
unsigned short packLID(unsigned int id, unsigned int od)
tkMSParameterization::AllData AllData
std::array< Elems, nLmBins()> data
int seqNum() const
Definition: DetLayer.h:36
std::ostream & operator<<(std::ostream &os, tkMSParameterization::Elem d)
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
auto const & operator()() const
FromToData const * fromTo(int in, int out) const
auto const & operator()() const
FromToData const * fromTo(DetLayer const &in, DetLayer const &out) const
std::tuple< unsigned short, unsigned short > unpackLID(unsigned short lid)
#define constexpr