Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:37:00

0001 /*
0002  * LutNetworkCommon.h
0003  *
0004  *  Created on: Jan 13, 2023
0005  *      Author: kbunkow
0006  */
0007 
0008 #ifndef L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h
0009 #define L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h
0010 
0011 #include <ap_fixed.h>
0012 #include <ap_int.h>
0013 #include <array>
0014 #include <vector>
0015 #include <limits>
0016 
0017 #include <boost/property_tree/ptree.hpp>
0018 
0019 namespace lutNN {
0020 
0021   template <int W, int I>
0022   const ap_ufixed<W, I> max_ap_ufixed() {
0023     static_assert(I < 64, "this max_ap_ufixed works only for I < 64");
0024     return ap_ufixed<W, I, AP_RND, AP_SAT>(std::numeric_limits<uint64_t>::max());
0025     //AP_SAT Saturate the value to the maximum value in case of overflow
0026   }
0027 
0028   template <int W, int I>
0029   const ap_fixed<W, I> max_ap_fixed() {
0030     static_assert(I < 64, "this max_ap_ufixed works only for I < 64");
0031     return ap_fixed<W, I, AP_RND, AP_SAT>(std::numeric_limits<uint64_t>::max());
0032     //AP_SAT Saturate the value to the maximum value in case of overflow
0033   }
0034 
0035 #define PUT_VAR(tree, keyPath, var) tree.put((keyPath) + "." + #var, (var));
0036 
0037 #define CHECK_VAR(tree, keyPath, var)                 \
0038   if ((var) != tree.get<int>((keyPath) + "." + #var)) \
0039     throw std::runtime_error((keyPath) + "." + #var + " has different value in the file then given");
0040 
0041   class LutNetworkFixedPointRegressionBase {
0042   public:
0043     virtual ~LutNetworkFixedPointRegressionBase() {}
0044 
0045     virtual void save(const std::string& filename) = 0;
0046     virtual void load(const std::string& filename) = 0;
0047 
0048     virtual void run(std::vector<float>& inputs, float noHitVal, std::vector<double>& nnResult) = 0;
0049 
0050     //pt in the hardware scale, ptGeV = (ptHw -1) / 2
0051     virtual int getCalibratedHwPt() = 0;
0052   };
0053 
0054 }  // namespace lutNN
0055 
0056 #endif /* L1Trigger_L1TMuonOverlapPhase2_LutNetworkFixedPointCommon_h */