CMS 3D CMS Logo

L1BJetProducer.cc
Go to the documentation of this file.
7 
13 
15 
16 #include <cmath>
17 #include <vector>
18 
19 using namespace l1t;
20 
21 class L1BJetProducer : public edm::stream::EDProducer<edm::GlobalCache<BJetTFCache>> {
22 public:
23  explicit L1BJetProducer(const edm::ParameterSet&, const BJetTFCache*);
24  ~L1BJetProducer() override = default;
25 
26  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
27  static std::unique_ptr<BJetTFCache> initializeGlobalCache(const edm::ParameterSet&);
28  static void globalEndJob(const BJetTFCache*);
29 
30 private:
31  std::unique_ptr<JetId> fBJetId_;
32  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override;
33 
35  bool const fUseRawPt_;
36  double const fMinPt_;
37  double const fMaxEta_;
38  unsigned int const fMaxJets_;
39  int const fNParticles_;
41 };
42 
44  : jets_(consumes<edm::View<l1t::PFJet>>(cfg.getParameter<edm::InputTag>("jets"))),
45  fUseRawPt_(cfg.getParameter<bool>("useRawPt")),
46  fMinPt_(cfg.getParameter<double>("minPt")),
47  fMaxEta_(cfg.getParameter<double>("maxEta")),
48  fMaxJets_(cfg.getParameter<int>("maxJets")),
49  fNParticles_(cfg.getParameter<int>("nParticles")),
50  fVtxEmu_(consumes<std::vector<l1t::VertexWord>>(cfg.getParameter<edm::InputTag>("vtx"))) {
51  fBJetId_ = std::make_unique<JetId>(
52  cfg.getParameter<std::string>("NNInput"), cfg.getParameter<std::string>("NNOutput"), cache, fNParticles_);
53  produces<edm::ValueMap<float>>("L1PFBJets");
54 }
55 std::unique_ptr<BJetTFCache> L1BJetProducer::initializeGlobalCache(const edm::ParameterSet& cfg) {
56  edm::FileInPath fp(cfg.getParameter<edm::FileInPath>("NNFileName"));
57  auto cache = std::make_unique<BJetTFCache>(fp.fullPath());
58  return cache;
59 }
63  iEvent.getByToken(jets_, jets);
64 
65  float vz = 0.;
66  double ptsum = 0;
68  iEvent.getByToken(fVtxEmu_, vtxEmuHandle);
69  for (const auto& vtx : *vtxEmuHandle) {
70  if (ptsum == 0 || vtx.pt() > ptsum) {
71  ptsum = vtx.pt();
72  vz = vtx.z0();
73  }
74  }
75 
76  std::vector<float> bScores;
77 
78  for (const auto& srcjet : *jets) {
79  if (((fUseRawPt_ ? srcjet.rawPt() : srcjet.pt()) < fMinPt_) || std::abs(srcjet.eta()) > fMaxEta_ ||
80  bScores.size() >= fMaxJets_) {
81  bScores.push_back(-1.);
82  continue;
83  }
84  float NN = fBJetId_->compute(srcjet, vz, fUseRawPt_);
85  bScores.push_back(NN);
86  }
87 
88  auto outT = std::make_unique<edm::ValueMap<float>>();
89  edm::ValueMap<float>::Filler fillerT(*outT);
90  fillerT.insert(jets, bScores.begin(), bScores.end());
91  fillerT.fill();
92 
93  iEvent.put(std::move(outT), "L1PFBJets");
94 }
95 
97  // L1BJetProducer
99  desc.add<edm::InputTag>("jets", edm::InputTag("scPFL1Puppi"));
100  desc.add<bool>("useRawPt", true);
101  desc.add<edm::FileInPath>("NNFileName",
102  edm::FileInPath("L1Trigger/Phase2L1ParticleFlow/data/modelTT_PUP_Off_dXY_XYCut_Graph.pb"));
103  desc.add<std::string>("NNInput", "input:0");
104  desc.add<std::string>("NNOutput", "sequential/dense_2/Sigmoid");
105  desc.add<int>("maxJets", 10);
106  desc.add<int>("nParticles", 10);
107  desc.add<double>("minPt", 20);
108  desc.add<double>("maxEta", 2.4);
109  desc.add<edm::InputTag>("vtx", edm::InputTag("L1VertexFinderEmulator", "L1VerticesEmulation"));
110  descriptions.add("L1BJetProducer", desc);
111 }
112 
114 DEFINE_FWK_MODULE(L1BJetProducer);
int const fNParticles_
double const fMaxEta_
delete x;
Definition: CaloConfig.h:22
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
bool const fUseRawPt_
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< edm::View< l1t::PFJet > > const jets_
constexpr Matriplex::idx_t NN
Definition: Matrix.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned int const fMaxJets_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static std::unique_ptr< BJetTFCache > initializeGlobalCache(const edm::ParameterSet &)
double const fMinPt_
L1BJetProducer(const edm::ParameterSet &, const BJetTFCache *)
edm::EDGetTokenT< std::vector< l1t::VertexWord > > const fVtxEmu_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void globalEndJob(const BJetTFCache *)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
def cache(function)
Definition: utilities.py:3
std::unique_ptr< JetId > fBJetId_
def move(src, dest)
Definition: eostools.py:511