Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:31

0001 // -*- C++ -*-
0002 //
0003 // Package:    HLTrigger/JetMET
0004 // Class:      HLTScoutingCaloProducer
0005 //
0006 /**\class HLTScoutingCaloProducer HLTScoutingCaloProducer.cc HLTrigger/JetMET/plugins/HLTScoutingCaloProducer.cc
0007 
0008 Description: Producer for Run3ScoutingCaloJets from reco::CaloJet objects
0009 
0010 */
0011 //
0012 // Original Author:  Dustin James Anderson
0013 //         Created:  Fri, 12 Jun 2015 15:49:20 GMT
0014 //
0015 //
0016 
0017 // system include files
0018 #include <memory>
0019 
0020 // user include files
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDProducer.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/MakerMacros.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 
0027 #include "DataFormats/JetReco/interface/CaloJet.h"
0028 #include "DataFormats/VertexReco/interface/Vertex.h"
0029 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0030 #include "DataFormats/METReco/interface/CaloMETCollection.h"
0031 #include "DataFormats/METReco/interface/CaloMET.h"
0032 #include "DataFormats/BTauReco/interface/JetTag.h"
0033 
0034 #include "DataFormats/Scouting/interface/Run3ScoutingCaloJet.h"
0035 #include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"
0036 
0037 #include "DataFormats/Math/interface/deltaR.h"
0038 
0039 class HLTScoutingCaloProducer : public edm::global::EDProducer<> {
0040 public:
0041   explicit HLTScoutingCaloProducer(const edm::ParameterSet&);
0042   ~HLTScoutingCaloProducer() override;
0043 
0044   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0045 
0046 private:
0047   void produce(edm::StreamID sid, edm::Event& iEvent, edm::EventSetup const& setup) const final;
0048 
0049   const edm::EDGetTokenT<reco::CaloJetCollection> caloJetCollection_;
0050   const edm::EDGetTokenT<reco::JetTagCollection> caloJetBTagCollection_;
0051   const edm::EDGetTokenT<reco::JetTagCollection> caloJetIDTagCollection_;
0052   const edm::EDGetTokenT<reco::VertexCollection> vertexCollection_;
0053   const edm::EDGetTokenT<reco::CaloMETCollection> metCollection_;
0054   const edm::EDGetTokenT<double> rho_;
0055 
0056   const double caloJetPtCut;
0057   const double caloJetEtaCut;
0058 
0059   const bool doMet;
0060   const bool doJetBTags;
0061   const bool doJetIDTags;
0062 };
0063 
0064 //
0065 // constructors and destructor
0066 //
0067 HLTScoutingCaloProducer::HLTScoutingCaloProducer(const edm::ParameterSet& iConfig)
0068     : caloJetCollection_(consumes<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("caloJetCollection"))),
0069       caloJetBTagCollection_(
0070           consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("caloJetBTagCollection"))),
0071       caloJetIDTagCollection_(
0072           consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("caloJetIDTagCollection"))),
0073       vertexCollection_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
0074       metCollection_(consumes<reco::CaloMETCollection>(iConfig.getParameter<edm::InputTag>("metCollection"))),
0075       rho_(consumes<double>(iConfig.getParameter<edm::InputTag>("rho"))),
0076       caloJetPtCut(iConfig.getParameter<double>("caloJetPtCut")),
0077       caloJetEtaCut(iConfig.getParameter<double>("caloJetEtaCut")),
0078       doMet(iConfig.getParameter<bool>("doMet")),
0079       doJetBTags(iConfig.getParameter<bool>("doJetBTags")),
0080       doJetIDTags(iConfig.getParameter<bool>("doJetIDTags")) {
0081   //register products
0082   produces<Run3ScoutingCaloJetCollection>();
0083   produces<double>("rho");
0084   produces<double>("caloMetPt");
0085   produces<double>("caloMetPhi");
0086 }
0087 
0088 HLTScoutingCaloProducer::~HLTScoutingCaloProducer() = default;
0089 
0090 // ------------ method called to produce the data  ------------
0091 void HLTScoutingCaloProducer::produce(edm::StreamID sid, edm::Event& iEvent, edm::EventSetup const& setup) const {
0092   using namespace edm;
0093 
0094   //get calo jets
0095   Handle<reco::CaloJetCollection> caloJetCollection;
0096   std::unique_ptr<Run3ScoutingCaloJetCollection> outCaloJets(new Run3ScoutingCaloJetCollection());
0097   if (iEvent.getByToken(caloJetCollection_, caloJetCollection)) {
0098     //get jet tags
0099     Handle<reco::JetTagCollection> caloJetBTagCollection;
0100     bool haveJetBTags = false;
0101     if (doJetBTags && iEvent.getByToken(caloJetBTagCollection_, caloJetBTagCollection)) {
0102       haveJetBTags = true;
0103     }
0104     Handle<reco::JetTagCollection> caloJetIDTagCollection;
0105     bool haveJetIDTags = false;
0106     if (doJetIDTags && iEvent.getByToken(caloJetIDTagCollection_, caloJetIDTagCollection)) {
0107       haveJetIDTags = true;
0108     }
0109 
0110     for (auto& jet : *caloJetCollection) {
0111       if (jet.pt() > caloJetPtCut && fabs(jet.eta()) < caloJetEtaCut) {
0112         //find the jet tag(s) corresponding to the jet
0113         float bTagValue = -20;
0114         float bTagMinDR2 = 0.01;
0115         if (haveJetBTags) {
0116           for (auto& tag : *caloJetBTagCollection) {
0117             float dR2 = reco::deltaR2(jet, *(tag.first));
0118             if (dR2 < bTagMinDR2) {
0119               bTagMinDR2 = dR2;
0120               bTagValue = tag.second;
0121             }
0122           }
0123         }
0124         float idTagValue = -20;
0125         float idTagMinDR2 = 0.01;
0126         if (haveJetIDTags) {
0127           for (auto& tag : *caloJetIDTagCollection) {
0128             float dR2 = reco::deltaR2(jet, *(tag.first));
0129             if (dR2 < idTagMinDR2) {
0130               idTagMinDR2 = dR2;
0131               idTagValue = tag.second;
0132             }
0133           }
0134         }
0135         outCaloJets->emplace_back(jet.pt(),
0136                                   jet.eta(),
0137                                   jet.phi(),
0138                                   jet.mass(),
0139                                   jet.jetArea(),
0140                                   jet.maxEInEmTowers(),
0141                                   jet.maxEInHadTowers(),
0142                                   jet.hadEnergyInHB(),
0143                                   jet.hadEnergyInHE(),
0144                                   jet.hadEnergyInHF(),
0145                                   jet.emEnergyInEB(),
0146                                   jet.emEnergyInEE(),
0147                                   jet.emEnergyInHF(),
0148                                   jet.towersArea(),
0149                                   idTagValue,
0150                                   bTagValue);
0151       }
0152     }
0153   }
0154 
0155   //get rho
0156   Handle<double> rho;
0157   std::unique_ptr<double> outRho(new double(-999));
0158   if (iEvent.getByToken(rho_, rho)) {
0159     outRho = std::make_unique<double>(*rho);
0160   }
0161 
0162   //get MET
0163   Handle<reco::CaloMETCollection> metCollection;
0164   std::unique_ptr<double> outMetPt(new double(-999));
0165   std::unique_ptr<double> outMetPhi(new double(-999));
0166   if (doMet && iEvent.getByToken(metCollection_, metCollection)) {
0167     outMetPt = std::make_unique<double>(metCollection->front().pt());
0168     outMetPhi = std::make_unique<double>(metCollection->front().phi());
0169   }
0170 
0171   //put output
0172   iEvent.put(std::move(outCaloJets));
0173   //    iEvent.put(std::move(outVertices));
0174   iEvent.put(std::move(outRho), "rho");
0175   iEvent.put(std::move(outMetPt), "caloMetPt");
0176   iEvent.put(std::move(outMetPhi), "caloMetPhi");
0177 }
0178 
0179 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0180 void HLTScoutingCaloProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0181   edm::ParameterSetDescription desc;
0182   desc.add<edm::InputTag>("caloJetCollection", edm::InputTag("hltAK4CaloJets"));
0183   desc.add<edm::InputTag>("caloJetBTagCollection", edm::InputTag("hltCombinedSecondaryVertexBJetTagsCalo"));
0184   desc.add<edm::InputTag>("caloJetIDTagCollection", edm::InputTag("hltCaloJetFromPV"));
0185   desc.add<edm::InputTag>("vertexCollection", edm::InputTag("hltPixelVertices"));
0186   desc.add<edm::InputTag>("metCollection", edm::InputTag("hltMet"));
0187   desc.add<edm::InputTag>("rho", edm::InputTag("hltFixedGridRhoFastjetAllCalo"));
0188   desc.add<double>("caloJetPtCut", 20.0);
0189   desc.add<double>("caloJetEtaCut", 3.0);
0190   desc.add<bool>("doMet", true);
0191   desc.add<bool>("doJetBTags", false);
0192   desc.add<bool>("doJetIDTags", false);
0193   descriptions.add("hltScoutingCaloProducer", desc);
0194 }
0195 
0196 // declare this class as a framework plugin
0197 DEFINE_FWK_MODULE(HLTScoutingCaloProducer);