Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:28

0001 #ifndef L1TRIGGER_PHASE2L1PARTICLEFLOWS_JETID_H
0002 #define L1TRIGGER_PHASE2L1PARTICLEFLOWS_JETID_H
0003 
0004 #include <string>
0005 #include "PhysicsTools/TensorFlow/interface/TensorFlow.h"
0006 #include "DataFormats/L1TParticleFlow/interface/PFCandidate.h"
0007 #include "DataFormats/L1TParticleFlow/interface/PFJet.h"
0008 
0009 //HLS4ML compiled emulator modeling
0010 #include <string>
0011 #include "ap_fixed.h"
0012 #include "hls4ml/emulator.h"
0013 
0014 struct BJetTFCache {
0015   BJetTFCache(const std::string &graphPath) : graphDef(tensorflow::loadGraphDef(graphPath)) {
0016     session = tensorflow::createSession(graphDef.get());
0017   }
0018   ~BJetTFCache() { tensorflow::closeSession(session); }
0019   std::unique_ptr<tensorflow::GraphDef> graphDef;
0020   tensorflow::Session *session;
0021 };
0022 
0023 class JetId {
0024 public:
0025   JetId(const std::string &iInput,
0026         const std::string &iOutput,
0027         const std::shared_ptr<hls4mlEmulator::Model> model,
0028         int iNParticles);
0029   JetId(const std::string &iInput, const std::string &iOutput, const BJetTFCache *cache, int iNParticles);
0030   ~JetId() = default;
0031 
0032   void setNNVectorVar();
0033   float EvaluateNN();
0034   ap_fixed<16, 6> EvaluateNNFixed();
0035   float compute(const l1t::PFJet &iJet, float vz, bool useRawPt);
0036   ap_fixed<16, 6> computeFixed(const l1t::PFJet &iJet, float vz, bool useRawPt);
0037 
0038 private:
0039   std::vector<float> NNvectorVar_;
0040   std::string fInput_;
0041   std::string fOutput_;
0042   int fNParticles_;
0043   unique_ptr<float[]> fPt_;
0044   unique_ptr<float[]> fEta_;
0045   unique_ptr<float[]> fPhi_;
0046   unique_ptr<int[]> fId_;
0047   unique_ptr<int[]> fCharge_;
0048   unique_ptr<float[]> fDZ_;
0049   unique_ptr<float[]> fDX_;
0050   unique_ptr<float[]> fDY_;
0051   tensorflow::Session *sessionRef_;
0052   std::shared_ptr<hls4mlEmulator::Model> modelRef_;
0053 };
0054 #endif