Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:53:52

0001 #include <vector>
0002 #include <numeric>
0003 
0004 ////////////////////
0005 //// FRAMEWORK HEADERS
0006 #include "FWCore/Framework/interface/global/EDProducer.h"
0007 #include "FWCore/Framework/interface/Event.h"
0008 #include "FWCore/Utilities/interface/InputTag.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 
0011 #include "DataFormats/L1TParticleFlow/interface/PFCandidate.h"
0012 #include "DataFormats/L1TParticleFlow/interface/PFJet.h"
0013 
0014 #include "DataFormats/L1Trigger/interface/EtSum.h"
0015 #include "DataFormats/Math/interface/LorentzVector.h"
0016 
0017 // bitwise emulation headers
0018 #include "L1Trigger/Phase2L1ParticleFlow/interface/jetmet/L1PFHtEmulator.h"
0019 
0020 class L1MhtPfProducer : public edm::global::EDProducer<> {
0021 public:
0022   explicit L1MhtPfProducer(const edm::ParameterSet&);
0023   ~L1MhtPfProducer() override;
0024 
0025 private:
0026   void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0027   edm::EDGetTokenT<std::vector<l1t::PFJet>> jetsToken;
0028   float minJetPt;
0029   float maxJetEta;
0030 
0031   std::vector<l1ct::Jet> convertEDMToHW(std::vector<l1t::PFJet> edmJets) const;
0032   std::vector<l1t::EtSum> convertHWToEDM(l1ct::Sum hwSums) const;
0033 };
0034 
0035 L1MhtPfProducer::L1MhtPfProducer(const edm::ParameterSet& cfg)
0036     : jetsToken(consumes<std::vector<l1t::PFJet>>(cfg.getParameter<edm::InputTag>("jets"))),
0037       minJetPt(cfg.getParameter<double>("minJetPt")),
0038       maxJetEta(cfg.getParameter<double>("maxJetEta")) {
0039   produces<std::vector<l1t::EtSum>>();
0040 }
0041 
0042 void L1MhtPfProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0043   // Get the jets from the event
0044   l1t::PFJetCollection edmJets = iEvent.get(jetsToken);
0045 
0046   // Apply pT and eta selections
0047   l1t::PFJetCollection edmJetsFiltered;
0048   std::copy_if(edmJets.begin(), edmJets.end(), std::back_inserter(edmJetsFiltered), [&](auto jet) {
0049     return jet.pt() > minJetPt && std::abs(jet.eta()) < maxJetEta;
0050   });
0051 
0052   // Run the emulation
0053   std::vector<l1ct::Jet> hwJets = convertEDMToHW(edmJetsFiltered);  // convert to the emulator format
0054   l1ct::Sum hwSums = htmht(hwJets);                                 // call the emulator
0055   std::vector<l1t::EtSum> edmSums = convertHWToEDM(hwSums);         // convert back to edm format
0056 
0057   // Put the sums in the event
0058   std::unique_ptr<std::vector<l1t::EtSum>> mhtCollection(new std::vector<l1t::EtSum>(0));
0059   mhtCollection->push_back(edmSums.at(0));  // HT
0060   mhtCollection->push_back(edmSums.at(1));  // MHT
0061 
0062   iEvent.put(std::move(mhtCollection));
0063 }
0064 
0065 std::vector<l1ct::Jet> L1MhtPfProducer::convertEDMToHW(std::vector<l1t::PFJet> edmJets) const {
0066   std::vector<l1ct::Jet> hwJets;
0067   std::for_each(edmJets.begin(), edmJets.end(), [&](l1t::PFJet jet) {
0068     l1ct::Jet hwJet = l1ct::Jet::unpack(jet.encodedJet());
0069     hwJets.push_back(hwJet);
0070   });
0071   return hwJets;
0072 }
0073 
0074 std::vector<l1t::EtSum> L1MhtPfProducer::convertHWToEDM(l1ct::Sum hwSums) const {
0075   std::vector<l1t::EtSum> edmSums;
0076 
0077   reco::Candidate::PolarLorentzVector htVector;
0078   htVector.SetPt(hwSums.hwSumPt.to_double());
0079   htVector.SetPhi(0);
0080   htVector.SetEta(0);
0081 
0082   reco::Candidate::PolarLorentzVector mhtVector;
0083   mhtVector.SetPt(hwSums.hwPt.to_double());
0084   mhtVector.SetPhi(l1ct::Scales::floatPhi(hwSums.hwPhi));
0085   mhtVector.SetEta(0);
0086 
0087   l1t::EtSum ht(htVector, l1t::EtSum::EtSumType::kTotalHt);
0088   l1t::EtSum mht(mhtVector, l1t::EtSum::EtSumType::kMissingHt);
0089 
0090   edmSums.push_back(ht);
0091   edmSums.push_back(mht);
0092   return edmSums;
0093 }
0094 
0095 L1MhtPfProducer::~L1MhtPfProducer() {}
0096 
0097 #include "FWCore/Framework/interface/MakerMacros.h"
0098 DEFINE_FWK_MODULE(L1MhtPfProducer);