Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:50

0001 #ifndef TkNavigation_TkMSParameterization_H
0002 #define TkNavigation_TkMSParameterization_H
0003 
0004 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0005 
0006 #include <array>
0007 #include <vector>
0008 #include <unordered_map>
0009 #include <cmath>
0010 #include <algorithm>
0011 
0012 #include <ostream>
0013 
0014 class TkMSParameterizationBuilder;
0015 namespace tkMSParameterization {
0016 
0017   constexpr unsigned short packLID(unsigned int id, unsigned int od) { return (id << 8) | od; }
0018   constexpr std::tuple<unsigned short, unsigned short> unpackLID(unsigned short lid) {
0019     return std::make_tuple(lid >> 8, lid & 255);
0020   }
0021 
0022   constexpr unsigned int nLmBins() { return 12 * 10; }
0023   constexpr float lmBin() { return 0.1f; }
0024   constexpr float lmBinInv() { return 1.f / lmBin(); }
0025 
0026   struct Elem {
0027     float vi;
0028     float vo;
0029     float uerr;
0030     float verr;
0031   };
0032 
0033   // this shall be sorted by "vo"
0034   class Elems {
0035   public:
0036     Elem find(float v) {
0037       auto p = find_if(data.begin(), data.end(), [=](Elem const& d) { return d.vo > v; });
0038       if (p != data.begin())
0039         --p;
0040       return *p;
0041     }
0042     auto const& operator()() const { return data; }
0043 
0044   private:
0045     std::vector<Elem> data;
0046     friend TkMSParameterizationBuilder;
0047   };
0048 
0049   class FromToData {
0050   public:
0051     Elems const& get(float tnLambda) const {
0052       auto i = std::min(nLmBins() - 1, (unsigned int)(std::abs(tnLambda) * lmBinInv()));
0053       return data[i];
0054     }
0055 
0056     auto const& operator()() const { return data; }
0057 
0058   private:
0059     std::array<Elems, nLmBins()> data;
0060     friend TkMSParameterizationBuilder;
0061   };
0062 
0063   using AllData = std::unordered_map<unsigned short, FromToData>;
0064 
0065 }  // namespace tkMSParameterization
0066 
0067 inline std::ostream& operator<<(std::ostream& os, tkMSParameterization::Elem d) {
0068   os << d.vi << '/' << d.vo << ':' << d.uerr << '/' << d.verr;
0069   return os;
0070 }
0071 
0072 class TkMSParameterization {
0073 public:
0074   using FromToData = tkMSParameterization::FromToData;
0075   using AllData = tkMSParameterization::AllData;
0076 
0077   FromToData const* fromTo(DetLayer const& in, DetLayer const& out) const { return fromTo(in.seqNum(), out.seqNum()); }
0078 
0079   FromToData const* fromTo(int in, int out) const {
0080     using namespace tkMSParameterization;
0081     auto id = packLID(in, out);
0082     auto p = data.find(id);
0083     if (p != data.end())
0084       return &(*p).second;
0085     return nullptr;
0086   }
0087 
0088   auto const& operator()() const { return data; }
0089 
0090 private:
0091   AllData data;
0092   friend TkMSParameterizationBuilder;
0093 };
0094 
0095 #endif  // TkNavigation_TkMSParameterization_H