Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:59

0001 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
0002 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0003 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0004 
0005 #include "DataFormats/Math/interface/deltaR.h"
0006 #include "DataFormats/Common/interface/ValueMap.h"
0007 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0008 #include "DataFormats/MuonReco/interface/Muon.h"
0009 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0010 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
0011 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
0012 #include "DataFormats/JetReco/interface/PFJet.h"
0013 #include "DataFormats/JetReco/interface/PFJetCollection.h"
0014 #include "DataFormats/METReco/interface/PFMET.h"
0015 #include "DataFormats/METReco/interface/PFMETCollection.h"
0016 #include "DataFormats/BTauReco/interface/JetTag.h"
0017 #include "DataFormats/Candidate/interface/CompositeCandidate.h"
0018 #include "DataFormats/Candidate/interface/CompositeCandidateFwd.h"
0019 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
0020 #include "DataFormats/Common/interface/TriggerResults.h"
0021 #include "DataFormats/BTauReco/interface/ShallowTagInfo.h"
0022 #include "DataFormats/Math/interface/LorentzVector.h"
0023 
0024 #include "DQMServices/Core/interface/DQMStore.h"
0025 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0026 #include "DQMOffline/Trigger/plugins/TriggerDQMBase.h"
0027 
0028 #include "FWCore/Utilities/interface/EDGetToken.h"
0029 #include "FWCore/Framework/interface/Frameworkfwd.h"
0030 #include "FWCore/Framework/interface/Event.h"
0031 #include "FWCore/Framework/interface/MakerMacros.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/ServiceRegistry/interface/Service.h"
0034 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0035 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0036 #include "FWCore/ParameterSet/interface/Registry.h"
0037 #include "FWCore/Utilities/interface/transform.h"
0038 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0039 
0040 #include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"
0041 
0042 #include <string>
0043 #include <vector>
0044 #include <memory>
0045 #include <map>
0046 
0047 class ParticleNetJetTagMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
0048 public:
0049   typedef dqm::reco::MonitorElement MonitorElement;
0050   typedef dqm::reco::DQMStore DQMStore;
0051 
0052   ParticleNetJetTagMonitor(const edm::ParameterSet&);
0053   ~ParticleNetJetTagMonitor() throw() override;
0054   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0055 
0056 protected:
0057   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0058   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0059 
0060 private:
0061   // folder for output histograms
0062   const std::string folderName_;
0063   // validity of HLT paths required for the monitoring element
0064   const bool requireValidHLTPaths_;
0065   const bool requireHLTOfflineJetMatching_;
0066   bool denHLTPathsAreValid_;
0067   bool numHLTPathsAreValid_;
0068   // input vertex collection
0069   const edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
0070   // input muon collection
0071   const edm::EDGetTokenT<reco::MuonCollection> muonToken_;
0072   // input electron collection and IDs
0073   const edm::EDGetTokenT<reco::GsfElectronCollection> electronToken_;
0074   const edm::EDGetTokenT<edm::ValueMap<bool>> tagElectronIDToken_;
0075   const edm::EDGetTokenT<edm::ValueMap<bool>> vetoElectronIDToken_;
0076   // input jet collection
0077   const edm::EDGetTokenT<reco::PFJetCollection> jetToken_;
0078   // PNET score for offline and online jets
0079   const edm::EDGetTokenT<reco::JetTagCollection> jetPNETScoreToken_;
0080   const edm::EDGetTokenT<reco::JetTagCollection> jetPNETScoreHLTToken_;
0081   // Collection and PNET score for ak4 b-tagging and HT if needed
0082   const edm::EDGetTokenT<reco::PFJetCollection> jetForHTandBTagToken_;
0083   const edm::EDGetTokenT<reco::JetTagCollection> jetPNETScoreForHTandBTagToken_;
0084   // Jet soft drop value map
0085   const edm::EDGetTokenT<edm::ValueMap<float>> jetSoftDropMassToken_;
0086   // input MET collection
0087   const edm::EDGetTokenT<reco::PFMETCollection> metToken_;
0088   // JEC corrections
0089   const edm::EDGetTokenT<reco::JetCorrector> jecMCToken_;
0090   const edm::EDGetTokenT<reco::JetCorrector> jecDataToken_;
0091   // trigger conditions for numerator and denominator
0092   std::unique_ptr<GenericTriggerEventFlag> numGenericTriggerEvent_;
0093   std::unique_ptr<GenericTriggerEventFlag> denGenericTriggerEvent_;
0094   // Selectors for jets, electrons, muons, and lepton pairs
0095   StringCutObjectSelector<reco::PFJet, true> jetSelection_;
0096   StringCutObjectSelector<reco::PFJet, true> jetSelectionForHTandBTag_;
0097   StringCutObjectSelector<reco::Muon, true> tagMuonSelection_;
0098   StringCutObjectSelector<reco::GsfElectron, true> tagElectronSelection_;
0099   StringCutObjectSelector<reco::Muon, true> vetoMuonSelection_;
0100   StringCutObjectSelector<reco::GsfElectron, true> vetoElectronSelection_;
0101   StringCutObjectSelector<reco::Vertex, true> vertexSelection_;
0102   StringCutObjectSelector<reco::CompositeCandidate, true> dileptonSelection_;
0103   StringCutObjectSelector<reco::PFMET, true> metSelection_;
0104   // Number of objects used in the event selection
0105   const int njets_;
0106   const int nbjets_;
0107   const int ntagleptons_;
0108   const int ntagmuons_;
0109   const int ntagelectrons_;
0110   const int nvetoleptons_;
0111   const int nvetomuons_;
0112   const int nvetoelectrons_;
0113   const int nemupairs_;
0114   const unsigned int ntrigobjecttomatch_;
0115   // delta-R for cleaning and other parameters for the event selection
0116   const double lepJetDeltaRmin_;
0117   const double lepJetDeltaRminForHTandBTag_;
0118   const double hltRecoDeltaRmax_;
0119   const double maxLeptonDxyCut_;
0120   const double maxLeptonDzCut_;
0121   const double minPNETScoreCut_;
0122   const double minPNETBTagCut_;
0123   const double minSoftDropMassCut_;
0124   const double maxSoftDropMassCut_;
0125   // binning for efficiency histograms (up to two jets in the final state)
0126   std::vector<double> leptonPtBinning;
0127   std::vector<double> leptonEtaBinning;
0128   std::vector<double> diLeptonPtBinning;
0129   std::vector<double> diLeptonMassBinning;
0130   std::vector<double> HTBinning;
0131   std::vector<double> NjetBinning;
0132   std::vector<double> jet1PtBinning;
0133   std::vector<double> jet2PtBinning;
0134   std::vector<double> jet1EtaBinning;
0135   std::vector<double> jet2EtaBinning;
0136   std::vector<double> jet1PNETscoreBinning;
0137   std::vector<double> jet2PNETscoreBinning;
0138   std::vector<double> jet1PNETscoreTransBinning;
0139   std::vector<double> jet2PNETscoreTransBinning;
0140   std::vector<double> jet1PtBinning2d;
0141   std::vector<double> jet2PtBinning2d;
0142   std::vector<double> jet1EtaBinning2d;
0143   std::vector<double> jet2EtaBinning2d;
0144   std::vector<double> jet1PNETscoreBinning2d;
0145   std::vector<double> jet2PNETscoreBinning2d;
0146   std::vector<double> jet1PNETscoreTransBinning2d;
0147   std::vector<double> jet2PNETscoreTransBinning2d;
0148 
0149   // Selections imposed
0150   MonitorElement* selectionFlow = nullptr;
0151   // Efficiencies
0152   ObjME muon_pt;
0153   ObjME electron_pt;
0154   ObjME muon_eta;
0155   ObjME electron_eta;
0156   ObjME dilepton_pt;
0157   ObjME dilepton_mass;
0158   ObjME njets;
0159   ObjME nbjets;
0160   ObjME ht;
0161   ObjME jet1_pt;
0162   ObjME jet2_pt;
0163   ObjME jet1_eta;
0164   ObjME jet2_eta;
0165   ObjME jet1_pnetscore;
0166   ObjME jet2_pnetscore;
0167   ObjME jet1_pnetscore_trans;
0168   ObjME jet2_pnetscore_trans;
0169   ObjME mean_2j_pnetscore;
0170   ObjME mean_2j_pnetscore_trans;
0171 
0172   ObjME jet1_pt_eta;
0173   ObjME jet2_pt_eta;
0174   ObjME jet1_pt_pnetscore1;
0175   ObjME jet2_pt_pnetscore1;
0176   ObjME jet1_pt_pnetscore2;
0177   ObjME jet2_pt_pnetscore2;
0178   ObjME jet1_pt_pnetscore1_trans;
0179   ObjME jet2_pt_pnetscore1_trans;
0180   ObjME jet1_pt_pnetscore2_trans;
0181   ObjME jet2_pt_pnetscore2_trans;
0182   ObjME jet1_pt_mean2pnetscore;
0183   ObjME jet2_pt_mean2pnetscore;
0184   ObjME jet1_pt_mean2pnetscore_trans;
0185   ObjME jet2_pt_mean2pnetscore_trans;
0186 };
0187 
0188 ParticleNetJetTagMonitor::ParticleNetJetTagMonitor(const edm::ParameterSet& iConfig)
0189     : folderName_(iConfig.getParameter<std::string>("FolderName")),
0190       requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
0191       requireHLTOfflineJetMatching_(iConfig.getParameter<bool>("requireHLTOfflineJetMatching")),
0192       denHLTPathsAreValid_(false),
0193       numHLTPathsAreValid_(false),
0194       vertexToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
0195       muonToken_(consumes<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
0196       electronToken_(consumes<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons"))),
0197       tagElectronIDToken_(consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("tagElectronID"))),
0198       vetoElectronIDToken_(consumes<edm::ValueMap<bool>>(iConfig.getParameter<edm::InputTag>("vetoElectronID"))),
0199       jetToken_(consumes<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jets"))),
0200       jetPNETScoreToken_(consumes<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("jetPNETScore"))),
0201       jetPNETScoreHLTToken_(mayConsume<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("jetPNETScoreHLT"))),
0202       jetForHTandBTagToken_(mayConsume<reco::PFJetCollection>(iConfig.getParameter<edm::InputTag>("jetsForHTandBTag"))),
0203       jetPNETScoreForHTandBTagToken_(
0204           mayConsume<reco::JetTagCollection>(iConfig.getParameter<edm::InputTag>("jetPNETScoreForHTandBTag"))),
0205       jetSoftDropMassToken_(mayConsume<edm::ValueMap<float>>(iConfig.getParameter<edm::InputTag>("jetSoftDropMass"))),
0206       metToken_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
0207       jecMCToken_(mayConsume<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("jecForMC"))),
0208       jecDataToken_(mayConsume<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("jecForData"))),
0209       numGenericTriggerEvent_(new GenericTriggerEventFlag(
0210           iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEvent"), consumesCollector(), *this)),
0211       denGenericTriggerEvent_(new GenericTriggerEventFlag(
0212           iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEvent"), consumesCollector(), *this)),
0213       jetSelection_(iConfig.getParameter<std::string>("jetSelection")),
0214       jetSelectionForHTandBTag_(iConfig.existsAs<std::string>("jetSelectionForHTandBTag")
0215                                     ? iConfig.getParameter<std::string>("jetSelectionForHTandBTag")
0216                                     : ""),
0217       tagMuonSelection_(iConfig.getParameter<std::string>("tagMuonSelection")),
0218       tagElectronSelection_(iConfig.getParameter<std::string>("tagElectronSelection")),
0219       vetoMuonSelection_(iConfig.getParameter<std::string>("vetoMuonSelection")),
0220       vetoElectronSelection_(iConfig.getParameter<std::string>("vetoElectronSelection")),
0221       vertexSelection_(iConfig.getParameter<std::string>("vertexSelection")),
0222       dileptonSelection_(iConfig.getParameter<std::string>("dileptonSelection")),
0223       metSelection_(iConfig.getParameter<std::string>("metSelection")),
0224       njets_(iConfig.getParameter<int>("njets")),
0225       nbjets_(iConfig.getParameter<int>("nbjets")),
0226       ntagleptons_(iConfig.getParameter<int>("ntagleptons")),
0227       ntagmuons_(iConfig.getParameter<int>("ntagmuons")),
0228       ntagelectrons_(iConfig.getParameter<int>("ntagelectrons")),
0229       nvetoleptons_(iConfig.getParameter<int>("nvetoleptons")),
0230       nvetomuons_(iConfig.getParameter<int>("nvetomuons")),
0231       nvetoelectrons_(iConfig.getParameter<int>("nvetoelectrons")),
0232       nemupairs_(iConfig.getParameter<int>("nemupairs")),
0233       ntrigobjecttomatch_(iConfig.getParameter<unsigned int>("ntrigobjecttomatch")),
0234       lepJetDeltaRmin_(iConfig.getParameter<double>("lepJetDeltaRmin")),
0235       lepJetDeltaRminForHTandBTag_(iConfig.getParameter<double>("lepJetDeltaRminForHTandBTag")),
0236       hltRecoDeltaRmax_(iConfig.getParameter<double>("hltRecoDeltaRmax")),
0237       maxLeptonDxyCut_(iConfig.getParameter<double>("maxLeptonDxyCut")),
0238       maxLeptonDzCut_(iConfig.getParameter<double>("maxLeptonDzCut")),
0239       minPNETScoreCut_(iConfig.getParameter<double>("minPNETScoreCut")),
0240       minPNETBTagCut_(iConfig.getParameter<double>("minPNETBTagCut")),
0241       minSoftDropMassCut_(iConfig.getParameter<double>("minSoftDropMassCut")),
0242       maxSoftDropMassCut_(iConfig.getParameter<double>("maxSoftDropMassCut")),
0243       leptonPtBinning(iConfig.getParameter<std::vector<double>>("leptonPtBinning")),
0244       leptonEtaBinning(iConfig.getParameter<std::vector<double>>("leptonEtaBinning")),
0245       diLeptonMassBinning(iConfig.getParameter<std::vector<double>>("diLeptonMassBinning")),
0246       HTBinning(iConfig.getParameter<std::vector<double>>("HTBinning")),
0247       NjetBinning(iConfig.getParameter<std::vector<double>>("NjetBinning")),
0248       jet1PtBinning(iConfig.getParameter<std::vector<double>>("jet1PtBinning")),
0249       jet2PtBinning(iConfig.getParameter<std::vector<double>>("jet2PtBinning")),
0250       jet1EtaBinning(iConfig.getParameter<std::vector<double>>("jet1EtaBinning")),
0251       jet2EtaBinning(iConfig.getParameter<std::vector<double>>("jet2EtaBinning")),
0252       jet1PNETscoreBinning(iConfig.getParameter<std::vector<double>>("jet1PNETscoreBinning")),
0253       jet2PNETscoreBinning(iConfig.getParameter<std::vector<double>>("jet2PNETscoreBinning")),
0254       jet1PNETscoreTransBinning(iConfig.getParameter<std::vector<double>>("jet1PNETscoreTransBinning")),
0255       jet2PNETscoreTransBinning(iConfig.getParameter<std::vector<double>>("jet2PNETscoreTransBinning")),
0256       jet1PtBinning2d(iConfig.getParameter<std::vector<double>>("jet1PtBinning2d")),
0257       jet2PtBinning2d(iConfig.getParameter<std::vector<double>>("jet2PtBinning2d")),
0258       jet1EtaBinning2d(iConfig.getParameter<std::vector<double>>("jet1EtaBinning2d")),
0259       jet2EtaBinning2d(iConfig.getParameter<std::vector<double>>("jet2EtaBinning2d")),
0260       jet1PNETscoreBinning2d(iConfig.getParameter<std::vector<double>>("jet1PNETscoreBinning2d")),
0261       jet2PNETscoreBinning2d(iConfig.getParameter<std::vector<double>>("jet2PNETscoreBinning2d")),
0262       jet1PNETscoreTransBinning2d(iConfig.getParameter<std::vector<double>>("jet1PNETscoreTransBinning2d")),
0263       jet2PNETscoreTransBinning2d(iConfig.getParameter<std::vector<double>>("jet2PNETscoreTransBinning2d")) {}
0264 
0265 ParticleNetJetTagMonitor::~ParticleNetJetTagMonitor() throw() {
0266   if (numGenericTriggerEvent_)
0267     denGenericTriggerEvent_.reset();
0268   if (numGenericTriggerEvent_)
0269     denGenericTriggerEvent_.reset();
0270 }
0271 
0272 void ParticleNetJetTagMonitor::bookHistograms(DQMStore::IBooker& ibooker,
0273                                               edm::Run const& iRun,
0274                                               edm::EventSetup const& iSetup) {
0275   // Initialize the GenericTriggerEventFlag
0276   if (denGenericTriggerEvent_ and denGenericTriggerEvent_->on())
0277     denGenericTriggerEvent_->initRun(iRun, iSetup);
0278   if (numGenericTriggerEvent_ and numGenericTriggerEvent_->on())
0279     numGenericTriggerEvent_->initRun(iRun, iSetup);
0280 
0281   denHLTPathsAreValid_ =
0282       (denGenericTriggerEvent_ && denGenericTriggerEvent_->on() && denGenericTriggerEvent_->allHLTPathsAreValid());
0283   numHLTPathsAreValid_ =
0284       (numGenericTriggerEvent_ && numGenericTriggerEvent_->on() && numGenericTriggerEvent_->allHLTPathsAreValid());
0285 
0286   if (requireValidHLTPaths_ && (!denHLTPathsAreValid_))
0287     return;
0288   if (requireValidHLTPaths_ && (!numHLTPathsAreValid_))
0289     return;
0290 
0291   ibooker.setCurrentFolder(folderName_);
0292 
0293   selectionFlow = ibooker.book1D("selectionFlow", "selectionFlow", 17, 0, 17);
0294   selectionFlow->setBinLabel(1, "all");
0295   selectionFlow->setBinLabel(2, "denTrigSel");
0296   selectionFlow->setBinLabel(3, "collecttionSel");
0297   selectionFlow->setBinLabel(4, "vtxSel");
0298   selectionFlow->setBinLabel(5, "tagMuSel");
0299   selectionFlow->setBinLabel(6, "vetoMuSel");
0300   selectionFlow->setBinLabel(7, "tagEleSel");
0301   selectionFlow->setBinLabel(8, "vetoEleSel");
0302   selectionFlow->setBinLabel(9, "tagLepSel");
0303   selectionFlow->setBinLabel(10, "vetoLepSel");
0304   selectionFlow->setBinLabel(11, "diLepSel");
0305   selectionFlow->setBinLabel(12, "btagSel");
0306   selectionFlow->setBinLabel(13, "METSel");
0307   selectionFlow->setBinLabel(14, "jetSel");
0308   selectionFlow->setBinLabel(15, "pnetScoreSel");
0309   selectionFlow->setBinLabel(16, "trigMatchSel");
0310   selectionFlow->setBinLabel(17, "numTrigSel");
0311 
0312   if (!NjetBinning.empty()) {
0313     bookME(ibooker, njets, "njets", "n-jets", NjetBinning);
0314     setMETitle(njets, "number of jets", "Entries");
0315     bookME(ibooker, nbjets, "nbjets", "b-jets", NjetBinning);
0316     setMETitle(nbjets, "number of b-jets", "Entries");
0317   }
0318   if (!HTBinning.empty()) {
0319     bookME(ibooker, ht, "ht", "HT", HTBinning);
0320     setMETitle(ht, "H_{T}", "Entries");
0321   }
0322 
0323   if (!leptonPtBinning.empty()) {
0324     bookME(ibooker, muon_pt, "muon_pt", "muon p_{T}", leptonPtBinning);
0325     setMETitle(muon_pt, "p_{T}(#mu)", "Entries");
0326     bookME(ibooker, electron_pt, "electron_pt", "electron p_{T}", leptonPtBinning);
0327     setMETitle(electron_pt, "p_{T}(ele)", "Entries");
0328   }
0329   if (!leptonEtaBinning.empty()) {
0330     bookME(ibooker, muon_eta, "muon_eta", "muon #eta", leptonEtaBinning);
0331     setMETitle(muon_eta, "#eta(#mu)", "Entries");
0332     bookME(ibooker, electron_eta, "electron_eta", "electron #eta", leptonEtaBinning);
0333     setMETitle(electron_eta, "#eta(ele)", "Entries");
0334   }
0335   if (!diLeptonPtBinning.empty()) {
0336     bookME(ibooker, dilepton_pt, "dilepton_pt", "dilepton p_{T}", diLeptonPtBinning);
0337     setMETitle(dilepton_pt, "p_{T}(ll)", "Entries");
0338   }
0339   if (!diLeptonMassBinning.empty()) {
0340     bookME(ibooker, dilepton_mass, "dilepton_mass", "dilepton mass", diLeptonMassBinning);
0341     setMETitle(dilepton_mass, "m(ll)", "Entries");
0342   }
0343 
0344   if (!jet1PtBinning.empty()) {
0345     bookME(ibooker, jet1_pt, "jet1_pt", "jet1 p_{T}", jet1PtBinning);
0346     setMETitle(jet1_pt, "p_{T}(j1)", "Entries");
0347   }
0348   if (!jet2PtBinning.empty()) {
0349     bookME(ibooker, jet2_pt, "jet2_pt", "jet2 p_{T}", jet2PtBinning);
0350     setMETitle(jet2_pt, "p_{T}(j2)", "Entries");
0351   }
0352   if (!jet1EtaBinning.empty()) {
0353     bookME(ibooker, jet1_eta, "jet1_eta", "jet1 #eta", jet1EtaBinning);
0354     setMETitle(jet1_eta, "#eta(j1)", "Entries");
0355   }
0356   if (!jet2EtaBinning.empty()) {
0357     bookME(ibooker, jet2_eta, "jet2_eta", "jet2 #eta", jet2EtaBinning);
0358     setMETitle(jet2_eta, "#eta(j2)", "Entries");
0359   }
0360   if (!jet1PNETscoreBinning.empty()) {
0361     bookME(ibooker, jet1_pnetscore, "jet1_pnetscore", "jet lead PNET-score", jet1PNETscoreBinning);
0362     setMETitle(jet1_pnetscore, "Lead PNET-score", "Entries");
0363   }
0364 
0365   if (!jet2PNETscoreBinning.empty()) {
0366     bookME(ibooker, jet2_pnetscore, "jet2_pnetscore", "jet train PNET-score", jet2PNETscoreBinning);
0367     setMETitle(jet2_pnetscore, "Trail PNET-score", "Entries");
0368   }
0369   if (!jet1PNETscoreBinning.empty() and !jet2PNETscoreBinning.empty()) {
0370     bookME(ibooker, mean_2j_pnetscore, "mean_2j_pnetscore", "mean 2jet PNET-score", jet1PNETscoreBinning);
0371     setMETitle(mean_2j_pnetscore, "Mean(PNET-score)", "Entries");
0372   }
0373 
0374   if (!jet1PNETscoreTransBinning.empty()) {
0375     bookME(ibooker,
0376            jet1_pnetscore_trans,
0377            "jet1_pnetscore_trans",
0378            "jet lead PNET-score transformed",
0379            jet1PNETscoreTransBinning);
0380     setMETitle(jet1_pnetscore_trans, "Lead atanh(PNET-score)", "Entries");
0381   }
0382   if (!jet2PNETscoreTransBinning.empty()) {
0383     bookME(ibooker,
0384            jet2_pnetscore_trans,
0385            "jet2_pnetscore_trans",
0386            "jet trail PNET-score transformed",
0387            jet2PNETscoreTransBinning);
0388     setMETitle(jet2_pnetscore_trans, "Trail atanh(PNET-score)", "Entries");
0389   }
0390   if (!jet1PNETscoreTransBinning.empty() and !jet2PNETscoreTransBinning.empty()) {
0391     bookME(ibooker,
0392            mean_2j_pnetscore_trans,
0393            "mean_2j_pnetscore_trans",
0394            "mean 2jet PNET-score transformed",
0395            jet1PNETscoreTransBinning);
0396     setMETitle(mean_2j_pnetscore_trans, "atanh(Mean(PNET-score))", "Entries");
0397   }
0398 
0399   // 2D efficiencies
0400   if (!jet1PtBinning2d.empty() and !jet1EtaBinning2d.empty()) {
0401     bookME(ibooker, jet1_pt_eta, "jet1_pt_eta", "jet1 p_{T} vs #eta", jet1PtBinning2d, jet1EtaBinning2d);
0402     setMETitle(jet1_pt_eta, "p_{T}(j1)", "#eta(j1)");
0403   }
0404   if (!jet2PtBinning2d.empty() and !jet2EtaBinning2d.empty()) {
0405     bookME(ibooker, jet2_pt_eta, "jet2_pt_eta", "jet2 p_{T} vs #eta", jet2PtBinning2d, jet2EtaBinning2d);
0406     setMETitle(jet2_pt_eta, "p_{T}(j2)", "#eta(j2)");
0407   }
0408 
0409   if (!jet1PtBinning2d.empty() and !jet1PNETscoreBinning2d.empty()) {
0410     bookME(ibooker,
0411            jet1_pt_pnetscore1,
0412            "jet1_pt_pnetscore1",
0413            "jet1 p{T} vs lead PNET-score",
0414            jet1PtBinning2d,
0415            jet1PNETscoreBinning2d);
0416     setMETitle(jet1_pt_pnetscore1, "p_{T}(j1)", "Lead PNET-score");
0417   }
0418   if (!jet1PtBinning2d.empty() and !jet2PNETscoreBinning2d.empty()) {
0419     bookME(ibooker,
0420            jet1_pt_pnetscore2,
0421            "jet1_pt_pnetscore2",
0422            "jet1 p_{T} vs trail PNET-score",
0423            jet1PtBinning2d,
0424            jet2PNETscoreBinning2d);
0425     setMETitle(jet1_pt_pnetscore2, "p_{T}(j1)", "Trail PNET-score");
0426   }
0427   if (!jet1PtBinning2d.empty() and !jet1PNETscoreBinning2d.empty() and !jet2PNETscoreBinning2d.empty()) {
0428     bookME(ibooker,
0429            jet1_pt_mean2pnetscore,
0430            "jet1_pt_mean2pnetscore",
0431            "jet1 p_{T} vs mean 2jet PNET-score",
0432            jet1PtBinning2d,
0433            jet1PNETscoreBinning2d);
0434     setMETitle(jet1_pt_mean2pnetscore, "p_{T}(j1)", "Mean(PNET-score)");
0435   }
0436 
0437   if (!jet2PtBinning2d.empty() and !jet1PNETscoreBinning2d.empty()) {
0438     bookME(ibooker,
0439            jet2_pt_pnetscore1,
0440            "jet2_pt_pnetscore1",
0441            "jet2 p_{T} vs lead PNET-score",
0442            jet2PtBinning2d,
0443            jet1PNETscoreBinning2d);
0444     setMETitle(jet2_pt_pnetscore1, "p_{T}(j2)", "Lead PNET-score");
0445   }
0446   if (!jet2PtBinning2d.empty() and !jet2PNETscoreBinning2d.empty()) {
0447     bookME(ibooker,
0448            jet2_pt_pnetscore2,
0449            "jet2_pt_pnetscore2",
0450            "jet2 p_{T} vs trail PNET-score",
0451            jet2PtBinning2d,
0452            jet2PNETscoreBinning2d);
0453     setMETitle(jet2_pt_pnetscore2, "p_{T}(j2)", "Trail PNET-score");
0454   }
0455   if (!jet2PtBinning2d.empty() and !jet1PNETscoreBinning2d.empty() and !jet2PNETscoreBinning2d.empty()) {
0456     bookME(ibooker,
0457            jet2_pt_mean2pnetscore,
0458            "jet2_pt_mean2pnetscore",
0459            "jet2 p_{T} vs mean 2jet PNET-score",
0460            jet2PtBinning2d,
0461            jet1PNETscoreBinning2d);
0462     setMETitle(jet2_pt_mean2pnetscore, "p_{T}(j2)", "Mean(PNET-score)");
0463   }
0464 
0465   if (!jet1PtBinning2d.empty() and !jet1PNETscoreTransBinning2d.empty()) {
0466     bookME(ibooker,
0467            jet1_pt_pnetscore1_trans,
0468            "jet1_pt_pnetscore1_trans",
0469            "jet1 p_{T} vs lead PNET-score transformed",
0470            jet1PtBinning2d,
0471            jet1PNETscoreTransBinning2d);
0472     setMETitle(jet1_pt_pnetscore1_trans, "p_{T}(j1)", "Lead atanh(PNET-score)");
0473   }
0474   if (!jet1PtBinning2d.empty() and !jet2PNETscoreTransBinning2d.empty()) {
0475     bookME(ibooker,
0476            jet1_pt_pnetscore2_trans,
0477            "jet1_pt_pnetscore2_trans",
0478            "jet1 p_{T} vs trail PNET-score transformed",
0479            jet1PtBinning2d,
0480            jet2PNETscoreTransBinning2d);
0481     setMETitle(jet1_pt_pnetscore2_trans, "p_{T}(j1)", "Trail atanh(PNET-score)");
0482   }
0483   if (!jet1PtBinning2d.empty() and !jet1PNETscoreTransBinning2d.empty() and !jet2PNETscoreTransBinning2d.empty()) {
0484     bookME(ibooker,
0485            jet1_pt_mean2pnetscore_trans,
0486            "jet1_pt_mean2pnetscore_trans",
0487            "jet1 p_{T} vs mean 2jet PNET-score transformed",
0488            jet1PtBinning2d,
0489            jet1PNETscoreBinning2d);
0490     setMETitle(jet1_pt_mean2pnetscore_trans, "p_{T}(j1)", "atanh(Mean(PNET-score))");
0491   }
0492 
0493   if (!jet2PtBinning2d.empty() and !jet1PNETscoreTransBinning2d.empty()) {
0494     bookME(ibooker,
0495            jet2_pt_pnetscore1_trans,
0496            "jet2_pt_pnetscore1_trans",
0497            "jet2 p_{T} vs lead PNET-score transformed",
0498            jet2PtBinning2d,
0499            jet1PNETscoreTransBinning2d);
0500     setMETitle(jet2_pt_pnetscore1_trans, "p_{T}(j2)", "Lead atanh(PNET-score)");
0501   }
0502   if (!jet2PtBinning2d.empty() and !jet2PNETscoreTransBinning2d.empty()) {
0503     bookME(ibooker,
0504            jet2_pt_pnetscore2_trans,
0505            "jet2_pt_pnetscore2_trans",
0506            "jet2 p_{T} vs trail PNET-score transformed",
0507            jet2PtBinning2d,
0508            jet2PNETscoreTransBinning2d);
0509     setMETitle(jet2_pt_pnetscore2_trans, "p_{T}(j2)", "Trail atanh(PNET-score)");
0510   }
0511   if (!jet2PtBinning2d.empty() and !jet1PNETscoreTransBinning2d.empty() and !jet2PNETscoreTransBinning2d.empty()) {
0512     bookME(ibooker,
0513            jet2_pt_mean2pnetscore_trans,
0514            "jet2_pt_mean2pnetscore_trans",
0515            "jet2 p_{T} vs mean 2jet PNET-score transformed",
0516            jet2PtBinning2d,
0517            jet1PNETscoreBinning2d);
0518     setMETitle(jet2_pt_mean2pnetscore_trans, "p_{T}(j2)", "atanh(Mean(PNET-score))");
0519   }
0520 }
0521 
0522 void ParticleNetJetTagMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0523   // abort if triggers are not valid
0524   if (requireValidHLTPaths_ and (!denHLTPathsAreValid_ or !numHLTPathsAreValid_))
0525     return;
0526 
0527   int selectionFlowStatus = 0;
0528   selectionFlow->Fill(selectionFlowStatus);
0529 
0530   // Filter out events that don't pass the denominator trigger condition
0531   if (denGenericTriggerEvent_->on() and !denGenericTriggerEvent_->accept(iEvent, iSetup))
0532     return;
0533 
0534   selectionFlowStatus++;
0535   selectionFlow->Fill(selectionFlowStatus);
0536 
0537   // get all input collections
0538   edm::Handle<reco::VertexCollection> primaryVertices;
0539   iEvent.getByToken(vertexToken_, primaryVertices);
0540   if (!primaryVertices.isValid()) {
0541     edm::LogWarning("ParticleNetJetTagMonitor") << "Invalid primary vertex collection, will skip the event";
0542     return;
0543   }
0544 
0545   edm::Handle<reco::MuonCollection> muonHandle;
0546   iEvent.getByToken(muonToken_, muonHandle);
0547   if (!muonHandle.isValid()) {
0548     edm::LogWarning("ParticleNetJetTagMonitor") << "Muon collection not valid, will skip the event \n";
0549     return;
0550   }
0551 
0552   edm::Handle<reco::GsfElectronCollection> electronHandle;
0553   iEvent.getByToken(electronToken_, electronHandle);
0554   if (!electronHandle.isValid()) {
0555     edm::LogWarning("ParticleNetJetTagMonitor") << "Electron collection not valid, will skip the event \n";
0556     return;
0557   }
0558 
0559   edm::Handle<edm::ValueMap<bool>> tagEleIDHandle;
0560   iEvent.getByToken(tagElectronIDToken_, tagEleIDHandle);
0561   if (!tagEleIDHandle.isValid()) {
0562     edm::LogWarning("ParticleNetJetTagMonitor") << "Electron ID for tag not valid, will skip the event \n";
0563     return;
0564   }
0565 
0566   edm::Handle<edm::ValueMap<bool>> vetoEleIDHandle;
0567   iEvent.getByToken(vetoElectronIDToken_, vetoEleIDHandle);
0568   if (!vetoEleIDHandle.isValid()) {
0569     edm::LogWarning("ParticleNetJetTagMonitor") << "Electron ID for veto not valid, will skip the event \n";
0570     return;
0571   }
0572 
0573   edm::Handle<reco::PFJetCollection> jetHandle;
0574   iEvent.getByToken(jetToken_, jetHandle);
0575   if (!jetHandle.isValid()) {
0576     edm::LogWarning("ParticleNetJetTagMonitor") << "Jet collection not valid, will skip the event \n";
0577     return;
0578   }
0579 
0580   edm::Handle<reco::PFMETCollection> metHandle;
0581   iEvent.getByToken(metToken_, metHandle);
0582   if (!metHandle.isValid()) {
0583     edm::LogWarning("ParticleNetJetTagMonitor") << "MET collection not valid, will skip the event \n";
0584     return;
0585   }
0586 
0587   edm::Handle<reco::JetTagCollection> jetPNETScoreHandle;
0588   iEvent.getByToken(jetPNETScoreToken_, jetPNETScoreHandle);
0589   if (!jetPNETScoreHandle.isValid()) {
0590     edm::LogWarning("ParticleNetJetTagMonitor") << "Jet PNET score collection not valid, will skip event \n";
0591     return;
0592   }
0593   const reco::JetTagCollection& jetPNETScore = *(jetPNETScoreHandle.product());
0594 
0595   // Collections that are only imported when necessary and their validity determins the selection applied (different for ak4/ak8 workflows)
0596   edm::Handle<edm::ValueMap<float>> jetSoftDropMassHandle;
0597   iEvent.getByToken(jetSoftDropMassToken_, jetSoftDropMassHandle);
0598   edm::Handle<reco::PFJetCollection> jetForHTandBTagHandle;
0599   iEvent.getByToken(jetForHTandBTagToken_, jetForHTandBTagHandle);
0600   edm::Handle<reco::JetTagCollection> jetPNETScoreForHTandBTagHandle;
0601   iEvent.getByToken(jetPNETScoreForHTandBTagToken_, jetPNETScoreForHTandBTagHandle);
0602   edm::Handle<reco::JetCorrector> jecHandle;
0603   if (iEvent.isRealData())
0604     iEvent.getByToken(jecDataToken_, jecHandle);
0605   else
0606     iEvent.getByToken(jecMCToken_, jecHandle);
0607 
0608   // Start the selection part
0609   selectionFlowStatus++;
0610   selectionFlow->Fill(selectionFlowStatus);
0611 
0612   // primary vertex selection
0613   const reco::Vertex* pv = nullptr;
0614   for (auto const& v : *primaryVertices) {
0615     if (not vertexSelection_(v))
0616       continue;
0617     pv = &v;
0618     break;
0619   }
0620 
0621   if (pv == nullptr) {
0622     edm::LogWarning("ParticleNetJetTagMonitor") << "No good vertex found in the event --> skipped";
0623     return;
0624   }
0625 
0626   selectionFlowStatus++;
0627   selectionFlow->Fill(selectionFlowStatus);
0628 
0629   // Muon selection
0630   std::vector<reco::Muon> tagMuons;
0631   std::vector<reco::Muon> vetoMuons;
0632   for (auto const& m : *muonHandle) {
0633     if (tagMuonSelection_(m) and std::fabs(m.muonBestTrack()->dxy(pv->position())) <= maxLeptonDxyCut_ and
0634         std::fabs(m.muonBestTrack()->dz(pv->position())) <= maxLeptonDzCut_)
0635       tagMuons.push_back(m);
0636     if (vetoMuonSelection_(m) and std::fabs(m.muonBestTrack()->dxy(pv->position())) <= maxLeptonDxyCut_ and
0637         std::fabs(m.muonBestTrack()->dz(pv->position())) <= maxLeptonDzCut_)
0638       vetoMuons.push_back(m);
0639   }
0640 
0641   if (ntagmuons_ >= 0 and int(tagMuons.size()) != ntagmuons_)
0642     return;
0643   selectionFlowStatus++;
0644   selectionFlow->Fill(selectionFlowStatus);
0645 
0646   if (nvetomuons_ >= 0 and int(vetoMuons.size()) != nvetomuons_)
0647     return;
0648   selectionFlowStatus++;
0649   selectionFlow->Fill(selectionFlowStatus);
0650 
0651   // electron selection
0652   std::vector<reco::GsfElectron> tagElectrons;
0653   std::vector<reco::GsfElectron> vetoElectrons;
0654   for (size_t index = 0; index < electronHandle->size(); index++) {
0655     const auto e = electronHandle->at(index);
0656     if (tagElectronSelection_(e) and (*tagEleIDHandle)[reco::GsfElectronRef(electronHandle, index)] and
0657         std::fabs(e.gsfTrack()->dxy(pv->position())) <= maxLeptonDxyCut_ and
0658         std::fabs(e.gsfTrack()->dz(pv->position())) <= maxLeptonDzCut_)
0659       tagElectrons.push_back(e);
0660     if (vetoElectronSelection_(e) and (*vetoEleIDHandle)[reco::GsfElectronRef(electronHandle, index)] and
0661         std::fabs(e.gsfTrack()->dxy(pv->position())) <= maxLeptonDxyCut_ and
0662         std::fabs(e.gsfTrack()->dz(pv->position())) <= maxLeptonDzCut_)
0663       vetoElectrons.push_back(e);
0664   }
0665 
0666   if (ntagelectrons_ >= 0 and int(tagElectrons.size()) != ntagelectrons_)
0667     return;
0668   selectionFlowStatus++;
0669   selectionFlow->Fill(selectionFlowStatus);
0670 
0671   if (nvetoelectrons_ >= 0 and int(vetoElectrons.size()) != nvetoelectrons_)
0672     return;
0673   selectionFlowStatus++;
0674   selectionFlow->Fill(selectionFlowStatus);
0675 
0676   // Overall number of leptons for flavor composition
0677   if (ntagleptons_ >= 0 and int(tagElectrons.size() + tagMuons.size()) != ntagleptons_)
0678     return;
0679   selectionFlowStatus++;
0680   selectionFlow->Fill(selectionFlowStatus);
0681 
0682   if (nvetoleptons_ >= 0 and int(vetoElectrons.size() + vetoMuons.size()) != nvetoleptons_)
0683     return;
0684   selectionFlowStatus++;
0685   selectionFlow->Fill(selectionFlowStatus);
0686 
0687   // Dilepton pairs
0688   std::vector<reco::CompositeCandidate> emuPairs;
0689   for (auto const& muon : tagMuons) {
0690     for (auto const& electron : tagElectrons) {
0691       reco::CompositeCandidate emuPair("emPair");
0692       emuPair.addDaughter(*dynamic_cast<const reco::Candidate*>(&muon), "lep1");
0693       emuPair.addDaughter(*dynamic_cast<const reco::Candidate*>(&electron), "lep2");
0694       AddFourMomenta addp4;
0695       addp4.set(emuPair);
0696       if (dileptonSelection_(emuPair))
0697         emuPairs.push_back(emuPair);
0698     }
0699   }
0700 
0701   if (nemupairs_ >= 0 and int(emuPairs.size()) != nemupairs_)
0702     return;
0703   selectionFlowStatus++;
0704   selectionFlow->Fill(selectionFlowStatus);
0705 
0706   // For b-tagging requriements / content used in AK8 PNET efficiency measurement in semi-leptonic ttbar
0707   float hT = 0;
0708   std::vector<math::XYZTLorentzVector> jetsBTagged;
0709   if (jetForHTandBTagHandle.isValid()) {
0710     const reco::JetTagCollection& jetPNETScoreForHTandBTag = *(jetPNETScoreForHTandBTagHandle.product());
0711     for (auto const& j : *jetForHTandBTagHandle) {
0712       if (not jetSelectionForHTandBTag_(j))
0713         continue;
0714       float minDR_jm = 1000;
0715       for (size_t imu = 0; imu < vetoMuons.size(); imu++) {
0716         float dR = reco::deltaR(vetoMuons.at(imu).p4(), j.p4());
0717         if (dR < minDR_jm)
0718           minDR_jm = dR;
0719       }
0720       if (minDR_jm < lepJetDeltaRminForHTandBTag_)
0721         continue;
0722       float minDR_je = 1000;
0723       for (size_t iel = 0; iel < vetoElectrons.size(); iel++) {
0724         float dR = reco::deltaR(vetoElectrons.at(iel).p4(), j.p4());
0725         if (dR < minDR_je)
0726           minDR_je = dR;
0727       }
0728       if (minDR_je < lepJetDeltaRminForHTandBTag_)
0729         continue;
0730       hT += j.pt();
0731       auto const& jref = reco::JetBaseRef(reco::PFJetRef(jetForHTandBTagHandle, &j - &(*jetForHTandBTagHandle)[0]));
0732       if (jetPNETScoreForHTandBTag[jref] < minPNETBTagCut_)
0733         continue;
0734       jetsBTagged.push_back(j.p4());
0735     }
0736     if (int(jetsBTagged.size()) < nbjets_)
0737       return;
0738   }
0739   selectionFlowStatus++;
0740   selectionFlow->Fill(selectionFlowStatus);
0741 
0742   // MET selectiona
0743   reco::PFMET pfMet = metHandle->front();
0744   if (!metSelection_(pfMet))
0745     return;
0746   selectionFlowStatus++;
0747   selectionFlow->Fill(selectionFlowStatus);
0748 
0749   // Jet selection
0750   std::vector<reco::PFJet> selectedJets;
0751   std::vector<float> jetPtCorrectedValues;
0752   std::vector<float> jetPNETScoreValues;
0753 
0754   for (auto const& j : *jetHandle) {
0755     // apply or not jecs
0756     float jec = 1;
0757     if (jecHandle.isValid())
0758       jec = jecHandle->correction(j);
0759     auto jet = *(j.clone());
0760     jet.setP4(j.p4() * jec);
0761 
0762     // Basic selection
0763     if (not jetSelection_(jet))
0764       continue;
0765     // SoftDrop mass
0766     if (jetSoftDropMassHandle.isValid()) {
0767       auto const& massSD = (*jetSoftDropMassHandle)[reco::PFJetRef(jetHandle, &j - &(*jetHandle)[0])];
0768       if (massSD < minSoftDropMassCut_ or massSD > maxSoftDropMassCut_)
0769         continue;
0770     }
0771     // cleaning with leptons
0772     float minDR_jm = 1000;
0773     for (size_t imu = 0; imu < vetoMuons.size(); imu++) {
0774       float dR = reco::deltaR(vetoMuons.at(imu).p4(), jet.p4());
0775       if (dR < minDR_jm)
0776         minDR_jm = dR;
0777     }
0778     if (minDR_jm < lepJetDeltaRmin_)
0779       continue;
0780     float minDR_je = 1000;
0781     for (size_t iel = 0; iel < vetoElectrons.size(); iel++) {
0782       float dR = reco::deltaR(vetoElectrons.at(iel).p4(), jet.p4());
0783       if (dR < minDR_je)
0784         minDR_je = dR;
0785     }
0786     if (minDR_je < lepJetDeltaRmin_)
0787       continue;
0788     // Compute HT
0789     if (not jetForHTandBTagHandle.isValid())
0790       hT += jet.pt();
0791     // selected jets, pT values (post-correction), and PNET score
0792     selectedJets.push_back(jet);
0793     jetPtCorrectedValues.push_back(jet.pt());
0794     auto jref = reco::JetBaseRef(reco::PFJetRef(jetHandle, &j - &(*jetHandle)[0]));
0795     if (jetPNETScore[jref])
0796       jetPNETScoreValues.push_back(jetPNETScore[jref]);
0797     else
0798       jetPNETScoreValues.push_back(0);
0799   }
0800   if (njets_ >= 0 and int(selectedJets.size()) < njets_)
0801     return;
0802   selectionFlowStatus++;
0803   selectionFlow->Fill(selectionFlowStatus);
0804 
0805   // count number of jets over minPNETScoreCut
0806   if (std::count_if(jetPNETScoreValues.begin(), jetPNETScoreValues.end(), [&](float score) {
0807         return score > minPNETScoreCut_;
0808       }) < njets_)
0809     return;
0810   selectionFlowStatus++;
0811   selectionFlow->Fill(selectionFlowStatus);
0812 
0813   // sort descending corrected pt order only if jecHandle is valid otherwise keep the current ordering
0814   std::vector<size_t> jetPtSortedIndices(jetPtCorrectedValues.size());
0815   std::iota(jetPtSortedIndices.begin(), jetPtSortedIndices.end(), 0);
0816   if (jecHandle.isValid()) {
0817     std::sort(jetPtSortedIndices.begin(), jetPtSortedIndices.end(), [&](const size_t& i1, const size_t& i2) {
0818       return jetPtCorrectedValues[i1] > jetPtCorrectedValues[i2];
0819     });
0820   }
0821 
0822   // sort descending PNET score order
0823   std::vector<size_t> jetPNETScoreSortedIndices(jetPNETScoreValues.size());
0824   std::iota(jetPNETScoreSortedIndices.begin(), jetPNETScoreSortedIndices.end(), 0);
0825   std::sort(jetPNETScoreSortedIndices.begin(),
0826             jetPNETScoreSortedIndices.end(),
0827             [&](const size_t& i1, const size_t& i2) { return jetPNETScoreValues[i1] > jetPNETScoreValues[i2]; });
0828 
0829   // trigger object matching (for jets)
0830   if (requireHLTOfflineJetMatching_) {
0831     edm::Handle<reco::JetTagCollection> jetPNETScoreHLTHandle;
0832     iEvent.getByToken(jetPNETScoreHLTToken_, jetPNETScoreHLTHandle);
0833     if (!jetPNETScoreHLTHandle.isValid()) {
0834       edm::LogWarning("ParticleNetJetTagMonitor") << "HLT Jet tags collection not valid, will skip event \n";
0835       return;
0836     }
0837 
0838     std::vector<float> jetPNETScoreValuesHLT;
0839     std::vector<reco::JetBaseRef> jetHLTRefs;
0840 
0841     // protect for wrong event content
0842     if (not jetPNETScoreHLTHandle->keyProduct().isAvailable()) {
0843       edm::LogWarning("ParticleNetJetTagMonitor")
0844           << "Collection used as a key by HLT Jet tags collection is not available, will skip event";
0845       return;
0846     }
0847 
0848     for (const auto& jtag : *jetPNETScoreHLTHandle) {
0849       jetPNETScoreValuesHLT.push_back(jtag.second);
0850       jetHLTRefs.push_back(jtag.first);
0851     }
0852 
0853     // sort in PNET score
0854     std::vector<size_t> jetPNETScoreSortedIndicesHLT(jetPNETScoreValuesHLT.size());
0855     std::iota(jetPNETScoreSortedIndicesHLT.begin(), jetPNETScoreSortedIndicesHLT.end(), 0);
0856     std::sort(
0857         jetPNETScoreSortedIndicesHLT.begin(),
0858         jetPNETScoreSortedIndicesHLT.end(),
0859         [&](const size_t& i1, const size_t& i2) { return jetPNETScoreValuesHLT[i1] > jetPNETScoreValuesHLT[i2]; });
0860 
0861     // match reco and hlt objects considering only the first ntrigobjecttomatch jets for both reco and HLT. Each of them must be matched
0862     std::vector<int> matched_obj;
0863     for (size_t jreco = 0; jreco < ntrigobjecttomatch_; jreco++) {
0864       if (jreco >= jetPNETScoreSortedIndices.size())
0865         break;
0866       float minDR = 1000;
0867       int match_index = -1;
0868       for (size_t jhlt = 0; jhlt < ntrigobjecttomatch_; jhlt++) {
0869         if (jhlt >= jetPNETScoreSortedIndicesHLT.size())
0870           break;
0871         if (std::find(matched_obj.begin(), matched_obj.end(), jhlt) != matched_obj.end())
0872           continue;
0873         float dR = reco::deltaR(selectedJets[jetPNETScoreSortedIndices.at(jreco)].p4(),
0874                                 jetHLTRefs.at(jetPNETScoreSortedIndicesHLT.at(jhlt))->p4());
0875         if (dR < hltRecoDeltaRmax_ and dR < minDR) {
0876           match_index = jhlt;
0877           minDR = dR;
0878         }
0879       }
0880       if (match_index >= 0)
0881         matched_obj.push_back(match_index);
0882     }
0883     if (matched_obj.size() != ntrigobjecttomatch_)
0884       return;
0885   }
0886   selectionFlowStatus++;
0887   selectionFlow->Fill(selectionFlowStatus);
0888 
0889   // numerator condition
0890   const bool trg_passed = (numGenericTriggerEvent_->on() and numGenericTriggerEvent_->accept(iEvent, iSetup));
0891   if (trg_passed) {
0892     selectionFlowStatus++;
0893     selectionFlow->Fill(selectionFlowStatus);
0894   }
0895 
0896   // Fill histograms for efficiency
0897   if (njets.numerator != nullptr)
0898     njets.fill(trg_passed, selectedJets.size());
0899   if (nbjets.numerator != nullptr)
0900     nbjets.fill(trg_passed, jetsBTagged.size());
0901   if (ht.numerator != nullptr)
0902     ht.fill(trg_passed, hT);
0903   if (muon_pt.numerator != nullptr)
0904     muon_pt.fill(trg_passed, (!tagMuons.empty()) ? tagMuons.front().pt() : 0);
0905   if (muon_eta.numerator != nullptr)
0906     muon_eta.fill(trg_passed, (!tagMuons.empty()) ? tagMuons.front().eta() : 0);
0907   if (electron_pt.numerator != nullptr)
0908     electron_pt.fill(trg_passed, (!tagElectrons.empty()) ? tagElectrons.front().pt() : -100);
0909   if (electron_eta.numerator != nullptr)
0910     electron_eta.fill(trg_passed, (!tagElectrons.empty()) ? tagElectrons.front().eta() : -100);
0911   if (dilepton_pt.numerator != nullptr)
0912     dilepton_pt.fill(trg_passed, (!emuPairs.empty()) ? emuPairs.front().pt() : 0);
0913   if (dilepton_mass.numerator != nullptr)
0914     dilepton_mass.fill(trg_passed, (!emuPairs.empty()) ? emuPairs.front().mass() : 0);
0915 
0916   if (jet1_pt.numerator != nullptr)
0917     jet1_pt.fill(trg_passed, (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0);
0918   if (jet2_pt.numerator != nullptr)
0919     jet2_pt.fill(trg_passed, (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0);
0920   if (jet1_eta.numerator != nullptr)
0921     jet1_eta.fill(trg_passed, (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).eta() : -100);
0922   if (jet2_eta.numerator != nullptr)
0923     jet2_eta.fill(trg_passed, (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).eta() : -100);
0924   if (jet1_pnetscore.numerator != nullptr)
0925     jet1_pnetscore.fill(trg_passed,
0926                         (!selectedJets.empty()) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) : -1);
0927   if (jet2_pnetscore.numerator != nullptr)
0928     jet2_pnetscore.fill(trg_passed,
0929                         (selectedJets.size() > 1) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1)) : -1);
0930   if (jet1_pnetscore_trans.numerator != nullptr)
0931     jet1_pnetscore_trans.fill(
0932         trg_passed, (!selectedJets.empty()) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0))) : -1);
0933   if (jet2_pnetscore_trans.numerator != nullptr)
0934     jet2_pnetscore_trans.fill(
0935         trg_passed, (selectedJets.size() > 1) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) : -1);
0936   if (mean_2j_pnetscore.numerator != nullptr)
0937     mean_2j_pnetscore.fill(trg_passed,
0938                            (selectedJets.size() > 1) ? (jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
0939                                                         jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
0940                                                            2.
0941                                                      : -1);
0942   if (mean_2j_pnetscore_trans.numerator != nullptr)
0943     mean_2j_pnetscore_trans.fill(trg_passed,
0944                                  (selectedJets.size() > 1)
0945                                      ? atanh((jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
0946                                               jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
0947                                              2.)
0948                                      : -1);
0949 
0950   if (jet1_pt_eta.numerator != nullptr)
0951     jet1_pt_eta.fill(trg_passed,
0952                      (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
0953                      (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).eta() : -1);
0954   if (jet2_pt_eta.numerator != nullptr)
0955     jet2_pt_eta.fill(trg_passed,
0956                      (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
0957                      (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).eta() : -1);
0958 
0959   if (jet1_pt_pnetscore1.numerator != nullptr)
0960     jet1_pt_pnetscore1.fill(trg_passed,
0961                             (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
0962                             (!selectedJets.empty()) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) : -1);
0963   if (jet2_pt_pnetscore1.numerator != nullptr)
0964     jet2_pt_pnetscore1.fill(trg_passed,
0965                             (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
0966                             (selectedJets.size() > 1) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) : -1);
0967   if (jet1_pt_pnetscore2.numerator != nullptr)
0968     jet1_pt_pnetscore2.fill(trg_passed,
0969                             (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
0970                             (selectedJets.size() > 1) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1)) : -1);
0971   if (jet2_pt_pnetscore2.numerator != nullptr)
0972     jet2_pt_pnetscore2.fill(trg_passed,
0973                             (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
0974                             (selectedJets.size() > 1) ? jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1)) : -1);
0975 
0976   if (jet1_pt_pnetscore1_trans.numerator != nullptr)
0977     jet1_pt_pnetscore1_trans.fill(
0978         trg_passed,
0979         (!selectedJets.empty()) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
0980         (!selectedJets.empty()) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0))) : -1);
0981   if (jet2_pt_pnetscore1_trans.numerator != nullptr)
0982     jet2_pt_pnetscore1_trans.fill(
0983         trg_passed,
0984         (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
0985         (selectedJets.size() > 1) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0))) : -1);
0986   if (jet1_pt_pnetscore2_trans.numerator != nullptr)
0987     jet1_pt_pnetscore2_trans.fill(
0988         trg_passed,
0989         (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
0990         (selectedJets.size() > 1) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) : -1);
0991   if (jet2_pt_pnetscore2_trans.numerator != nullptr)
0992     jet2_pt_pnetscore2_trans.fill(
0993         trg_passed,
0994         (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
0995         (selectedJets.size() > 1) ? atanh(jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) : -1);
0996 
0997   if (jet1_pt_mean2pnetscore.numerator != nullptr)
0998     jet1_pt_mean2pnetscore.fill(trg_passed,
0999                                 (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
1000                                 (selectedJets.size() > 1) ? (jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
1001                                                              jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
1002                                                                 2
1003                                                           : -1);
1004   if (jet2_pt_mean2pnetscore.numerator != nullptr)
1005     jet2_pt_mean2pnetscore.fill(trg_passed,
1006                                 (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
1007                                 (selectedJets.size() > 1)
1008                                     ? atanh((jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
1009                                              jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
1010                                             2)
1011                                     : -1);
1012 
1013   if (jet1_pt_mean2pnetscore_trans.numerator != nullptr)
1014     jet1_pt_mean2pnetscore_trans.fill(trg_passed,
1015                                       (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(0)).pt() : 0,
1016                                       (selectedJets.size() > 1)
1017                                           ? atanh((jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
1018                                                    jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
1019                                                   2)
1020                                           : -1);
1021   if (jet2_pt_mean2pnetscore_trans.numerator != nullptr)
1022     jet2_pt_mean2pnetscore_trans.fill(trg_passed,
1023                                       (selectedJets.size() > 1) ? selectedJets.at(jetPtSortedIndices.at(1)).pt() : 0,
1024                                       (selectedJets.size() > 1)
1025                                           ? atanh((jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(0)) +
1026                                                    jetPNETScoreValues.at(jetPNETScoreSortedIndices.at(1))) /
1027                                                   2)
1028                                           : -1);
1029 }
1030 
1031 void ParticleNetJetTagMonitor::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
1032   edm::ParameterSetDescription desc;
1033   desc.add<std::string>("FolderName", "HLT/Higgs");
1034   desc.add<bool>("requireValidHLTPaths", true);
1035   desc.add<bool>("requireHLTOfflineJetMatching", true);
1036   desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
1037   desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
1038   desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
1039   desc.add<edm::InputTag>("tagElectronID",
1040                           edm::InputTag("egmGsfElectronIDsForDQM:cutBasedElectronID-RunIIIWinter22-V1-tight"));
1041   desc.add<edm::InputTag>("vetoElectronID",
1042                           edm::InputTag("egmGsfElectronIDsForDQM:cutBasedElectronID-RunIIIWinter22-V1-loose"));
1043   desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
1044   desc.add<edm::InputTag>("jetPNETScore", edm::InputTag("pfParticleNetAK4DiscriminatorsJetTags", "BvsAll"));
1045   desc.add<edm::InputTag>("jetPNETScoreHLT", edm::InputTag("hltParticleNetDiscriminatorsJetTags", "BvsAll"));
1046   desc.add<edm::InputTag>("jetsForHTandBTag", edm::InputTag(""));
1047   desc.add<edm::InputTag>("jetPNETScoreForHTandBTag", edm::InputTag(""));
1048   desc.add<edm::InputTag>("jetSoftDropMass", edm::InputTag(""));
1049   desc.add<edm::InputTag>("met", edm::InputTag("pfMetPuppi"));
1050   desc.add<edm::InputTag>("jecForMC", edm::InputTag("ak4PFCHSL1FastL2L3Corrector"));
1051   desc.add<edm::InputTag>("jecForData", edm::InputTag("ak4PFCHSL1FastL2L3ResidualCorrector"));
1052   desc.add<std::string>("tagMuonSelection",
1053                         "pt > 25 && abs(eta) < 2.4 && passed(CutBasedIdTight) && passed(PFIsoTight)");
1054   desc.add<std::string>("tagElectronSelection", "pt > 20 && abs(eta) < 2.5");
1055   desc.add<std::string>("vetoMuonSelection",
1056                         "pt > 10 && abs(eta) < 2.4 && passed(CutBasedIdLoose) && passed(PFIsoLoose)");
1057   desc.add<std::string>("vetoElectronSelection", "pt > 10 && abs(eta) < 2.5");
1058   desc.add<std::string>("jetSelection", "pt > 30 && abs(eta) < 2.5");
1059   desc.add<std::string>("jetSelectionForHTandBTag", "pt > 30 && abs(eta) < 2.5");
1060   desc.add<std::string>("vertexSelection", "!isFake && ndof > 4 && abs(z) <= 24 && position.Rho <= 2");
1061   desc.add<std::string>("dileptonSelection", "((mass > 20 && mass < 75) || mass > 105) && charge == 0");
1062   desc.add<std::string>("metSelection", "pt > 0");
1063   desc.add<int>("ntagleptons", 2);
1064   desc.add<int>("ntagmuons", 1);
1065   desc.add<int>("ntagelectrons", 1);
1066   desc.add<int>("nvetoleptons", 2);
1067   desc.add<int>("nvetomuons", 1);
1068   desc.add<int>("nvetoelectrons", 1);
1069   desc.add<int>("nemupairs", 1);
1070   desc.add<int>("njets", 2);
1071   desc.add<int>("nbjets", -1);
1072   desc.add<unsigned int>("ntrigobjecttomatch", 2);
1073   desc.add<double>("lepJetDeltaRmin", 0.4);
1074   desc.add<double>("lepJetDeltaRminForHTandBTag", 0.4);
1075   desc.add<double>("hltRecoDeltaRmax", 0.4);
1076   desc.add<double>("maxLeptonDxyCut", 0.1);
1077   desc.add<double>("maxLeptonDzCut", 0.2);
1078   desc.add<double>("minPNETScoreCut", 0.2);
1079   desc.add<double>("minPNETBTagCut", 0.5);
1080   desc.add<double>("minSoftDropMassCut", 50);
1081   desc.add<double>("maxSoftDropMassCut", 110);
1082   desc.add<std::vector<double>>("leptonPtBinning", {});
1083   desc.add<std::vector<double>>("leptonEtaBinning", {});
1084   desc.add<std::vector<double>>("diLeptonPtBinning", {});
1085   desc.add<std::vector<double>>("diLeptonMassBinning", {});
1086   desc.add<std::vector<double>>("HTBinning", {});
1087   desc.add<std::vector<double>>("NjetBinning", {});
1088   desc.add<std::vector<double>>("jet1PtBinning", {});
1089   desc.add<std::vector<double>>("jet2PtBinning", {});
1090   desc.add<std::vector<double>>("jet1EtaBinning", {});
1091   desc.add<std::vector<double>>("jet2EtaBinning", {});
1092   desc.add<std::vector<double>>("jet1PNETscoreBinning", {});
1093   desc.add<std::vector<double>>("jet2PNETscoreBinning", {});
1094   desc.add<std::vector<double>>("jet1PNETscoreTransBinning", {});
1095   desc.add<std::vector<double>>("jet2PNETscoreTransBinning", {});
1096   desc.add<std::vector<double>>("jet1PtBinning2d", {});
1097   desc.add<std::vector<double>>("jet2PtBinning2d", {});
1098   desc.add<std::vector<double>>("jet1EtaBinning2d", {});
1099   desc.add<std::vector<double>>("jet2EtaBinning2d", {});
1100   desc.add<std::vector<double>>("jet1PNETscoreBinning2d", {});
1101   desc.add<std::vector<double>>("jet2PNETscoreBinning2d", {});
1102   desc.add<std::vector<double>>("jet1PNETscoreTransBinning2d", {});
1103   desc.add<std::vector<double>>("jet2PNETscoreTransBinning2d", {});
1104   edm::ParameterSetDescription genericTriggerEventPSet;
1105   GenericTriggerEventFlag::fillPSetDescription(genericTriggerEventPSet);
1106   desc.add<edm::ParameterSetDescription>("numGenericTriggerEvent", genericTriggerEventPSet);
1107   desc.add<edm::ParameterSetDescription>("denGenericTriggerEvent", genericTriggerEventPSet);
1108   descriptions.add("ParticleNetJetTagMonitor", desc);
1109 }
1110 
1111 // Define this as a plug-in
1112 DEFINE_FWK_MODULE(ParticleNetJetTagMonitor);