From 525ef8aa1c5d6ca2f5f6886f9626fad99499e58f Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 17 May 2021 23:08:00 +0200 Subject: [PATCH 01/28] add L1 muon prefiring to prefire weight producer --- .../NanoAOD/python/triggerObjects_cff.py | 25 +- .../plugins/L1ECALPrefiringWeightProducer.cc | 231 --------- .../plugins/L1PrefiringWeightProducer.cc | 482 ++++++++++++++++++ 3 files changed, 502 insertions(+), 236 deletions(-) delete mode 100644 PhysicsTools/PatUtils/plugins/L1ECALPrefiringWeightProducer.cc create mode 100644 PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 6c56743440c09..30fe428558bec 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -216,17 +216,20 @@ selections = selections2016 ) -from PhysicsTools.PatUtils.L1ECALPrefiringWeightProducer_cff import prefiringweight +from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight #Next line will be updated once we get UL2016 maps -run2_jme_2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH")) +run2_jme_2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH"), DataEraMuon = cms.string("2016")) #Next line is for UL2017 maps -run2_jme_2017.toModify( prefiringweight, DataEra = cms.string("UL2017BtoF")) +run2_jme_2017.toModify( prefiringweight, DataEra = cms.string("UL2017BtoF"), DataEraMuon = cms.string("20172018")) +#Next line is for UL2018 maps +run2_jme_2018.toModify( prefiringweight, DataEra = cms.string("None"), DataEraMuon = cms.string("20172018")) + #For pre-UL 2017 reprocessing, one should use the original maps and no muon jet protection for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2: - modifier.toModify( prefiringweight, DataEra = cms.string("2017BtoF")) + modifier.toModify( prefiringweight, DataEra = cms.string("2017BtoF"), DataEraMuon = cms.string("20172018")) modifier.toModify( prefiringweight, JetMaxMuonFraction = cms.double(-1.) ) #For pre-UL 2016 reprocessing, same thing -run2_nanoAOD_94X2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH") ) +run2_nanoAOD_94X2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH"), DataEraMuon = cms.string("2016") ) run2_nanoAOD_94X2016.toModify( prefiringweight, JetMaxMuonFraction = cms.double(-1.) ) l1PreFiringEventWeightTable = cms.EDProducer("GlobalVariablesTableProducer", @@ -234,6 +237,18 @@ L1PreFiringWeight_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProb"), "double", doc = "L1 pre-firing event correction weight (1-probability)", precision=8), L1PreFiringWeight_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "double", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), L1PreFiringWeight_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "double", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightMuon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightMuon_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightMuon_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightJet_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJet"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightJet_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetUp"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightJet_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetDown"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightPhoton_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhoton"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightPhoton_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonUp"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightPhoton_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonDown"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), down var.", precision=8), + + + ) ) diff --git a/PhysicsTools/PatUtils/plugins/L1ECALPrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1ECALPrefiringWeightProducer.cc deleted file mode 100644 index b67c0c4837326..0000000000000 --- a/PhysicsTools/PatUtils/plugins/L1ECALPrefiringWeightProducer.cc +++ /dev/null @@ -1,231 +0,0 @@ -// -*- C++ -*- -// -// Package: ProdTutorial/L1ECALPrefiringWeightProducer -// Class: L1ECALPrefiringWeightProducer -// -/**\class L1ECALPrefiringWeightProducer L1ECALPrefiringWeightProducer.cc ProdTutorial/L1ECALPrefiringWeightProducer/plugins/L1ECALPrefiringWeightProducer.cc - - Description: [one line class summary] - - Implementation: - [Notes on implementation] -*/ -// -// Original Author: localusers user -// Created: Thu, 08 Nov 2018 16:16:00 GMT -// -// - -// system include files -#include - -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/global/EDProducer.h" - -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/MakerMacros.h" - -#include "FWCore/ParameterSet/interface/ParameterSet.h" -#include "FWCore/Utilities/interface/StreamID.h" - -#include "DataFormats/PatCandidates/interface/Jet.h" -#include "DataFormats/PatCandidates/interface/Photon.h" -#include "TH2.h" - -#include -enum fluctuations { central = 0, up, down }; - -class L1ECALPrefiringWeightProducer : public edm::global::EDProducer<> { -public: - explicit L1ECALPrefiringWeightProducer(const edm::ParameterSet&); - ~L1ECALPrefiringWeightProducer() override; - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - -private: - void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; - - double getPrefiringRate(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const; - - edm::EDGetTokenT > photons_token_; - edm::EDGetTokenT > jets_token_; - - TH2F* h_prefmap_photon; - TH2F* h_prefmap_jet; - std::string dataera_; - bool useEMpt_; - double prefiringRateSystUnc_; - double jetMaxMuonFraction_; - bool skipwarnings_; -}; - -L1ECALPrefiringWeightProducer::L1ECALPrefiringWeightProducer(const edm::ParameterSet& iConfig) { - photons_token_ = consumes >(iConfig.getParameter("ThePhotons")); - jets_token_ = consumes >(iConfig.getParameter("TheJets")); - - dataera_ = iConfig.getParameter("DataEra"); - useEMpt_ = iConfig.getParameter("UseJetEMPt"); - prefiringRateSystUnc_ = iConfig.getParameter("PrefiringRateSystematicUncty"); - jetMaxMuonFraction_ = iConfig.getParameter("JetMaxMuonFraction"); - skipwarnings_ = iConfig.getParameter("SkipWarnings"); - - TFile* file_prefiringmaps_; - std::string fname = iConfig.getParameter("L1Maps"); - edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); - file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read"); - if (file_prefiringmaps_ == nullptr && !skipwarnings_) - std::cout << "File with maps not found. All prefiring weights set to 0. " << std::endl; - - TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_; - if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) - std::cout << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; - h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname); - - TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_; - if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) - std::cout << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; - h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname); - file_prefiringmaps_->Close(); - delete file_prefiringmaps_; - produces("nonPrefiringProb").setBranchAlias("nonPrefiringProb"); - produces("nonPrefiringProbUp").setBranchAlias("nonPrefiringProbUp"); - produces("nonPrefiringProbDown").setBranchAlias("nonPrefiringProbDown"); -} - -L1ECALPrefiringWeightProducer::~L1ECALPrefiringWeightProducer() { - delete h_prefmap_photon; - delete h_prefmap_jet; -} - -void L1ECALPrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { - using namespace edm; - - //Photons - edm::Handle > thePhotons; - iEvent.getByToken(photons_token_, thePhotons); - - //Jets - edm::Handle > theJets; - iEvent.getByToken(jets_token_, theJets); - - //Probability for the event NOT to prefire, computed with the prefiring maps per object. - //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. - double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - - for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { - for (const auto& photon : *thePhotons) { - double pt_gam = photon.pt(); - double eta_gam = photon.eta(); - if (pt_gam < 20.) - continue; - if (fabs(eta_gam) < 2.) - continue; - if (fabs(eta_gam) > 3.) - continue; - double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); - nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); - } - - //Now applying the prefiring maps to jets in the affected regions. - for (const auto& jet : *theJets) { - double pt_jet = jet.pt(); - double eta_jet = jet.eta(); - double phi_jet = jet.phi(); - if (pt_jet < 20.) - continue; - if (fabs(eta_jet) < 2.) - continue; - if (fabs(eta_jet) > 3.) - continue; - if (jetMaxMuonFraction_ > 0 && jet.muonEnergyFraction() > jetMaxMuonFraction_) - continue; - //Loop over photons to remove overlap - double nonprefiringprobfromoverlappingphotons = 1.; - for (const auto& photon : *thePhotons) { - double pt_gam = photon.pt(); - double eta_gam = photon.eta(); - double phi_gam = photon.phi(); - if (pt_gam < 20.) - continue; - if (fabs(eta_gam) < 2.) - continue; - if (fabs(eta_gam) > 3.) - continue; - double dR = reco::deltaR(eta_jet, phi_jet, eta_gam, phi_gam); - if (dR > 0.4) - continue; - double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); - nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam); - } - //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt. - if (useEMpt_) - pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction()); - double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRate(eta_jet, pt_jet, h_prefmap_jet, fluct); - - if (nonprefiringprobfromoverlappingphotons == 1.) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; - } - //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one - else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { - if (nonprefiringprobfromoverlappingphotons != 0.) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; - } else { - nonPrefiringProba[fluct] = 0.; - } - } - //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. - } - } - - auto nonPrefiringProb = std::make_unique(nonPrefiringProba[0]); - auto nonPrefiringProbUp = std::make_unique(nonPrefiringProba[1]); - auto nonPrefiringProbDown = std::make_unique(nonPrefiringProba[2]); - iEvent.put(std::move(nonPrefiringProb), "nonPrefiringProb"); - iEvent.put(std::move(nonPrefiringProbUp), "nonPrefiringProbUp"); - iEvent.put(std::move(nonPrefiringProbDown), "nonPrefiringProbDown"); -} - -double L1ECALPrefiringWeightProducer::getPrefiringRate(double eta, - double pt, - TH2F* h_prefmap, - fluctuations fluctuation) const { - if (h_prefmap == nullptr && !skipwarnings_) - std::cout << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; - if (h_prefmap == nullptr) - return 0.; - //Check pt is not above map overflow - int nbinsy = h_prefmap->GetNbinsY(); - double maxy = h_prefmap->GetYaxis()->GetBinLowEdge(nbinsy + 1); - if (pt >= maxy) - pt = maxy - 0.01; - int thebin = h_prefmap->FindBin(eta, pt); - - double prefrate = h_prefmap->GetBinContent(thebin); - - double statuncty = h_prefmap->GetBinError(thebin); - double systuncty = prefiringRateSystUnc_ * prefrate; - - if (fluctuation == up) - prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - if (fluctuation == down) - prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - return prefrate; -} - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void L1ECALPrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - edm::ParameterSetDescription desc; - - desc.add("ThePhotons", edm::InputTag("slimmedPhotons")); - desc.add("TheJets", edm::InputTag("slimmedJets")); - desc.add("L1Maps", "L1PrefiringMaps.root"); - desc.add("DataEra", "2017BtoF"); - desc.add("UseJetEMPt", false); - desc.add("PrefiringRateSystematicUncty", 0.2); - desc.add("JetMaxMuonFraction", 0.5); - desc.add("SkipWarnings", true); - descriptions.add("l1ECALPrefiringWeightProducer", desc); -} - -//define this as a plug-in -DEFINE_FWK_MODULE(L1ECALPrefiringWeightProducer); diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc new file mode 100644 index 0000000000000..eb9d6dfdb418b --- /dev/null +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -0,0 +1,482 @@ +// -*- C++ -*- +// +// Package: ProdTutorial/L1PrefiringWeightProducer +// Class: L1PrefiringWeightProducer +// +/**\class L1PrefiringWeightProducer L1PrefiringWeightProducer.cc ProdTutorial/L1ECALPrefiringWeightProducer/plugins/L1ECALPrefiringWeightProducer.cc + + Description: [one line class summary] + + Implementation: + [Notes on implementation] +*/ +// +// Original Author: localusers user +// Created: Thu, 08 Nov 2018 16:16:00 GMT +// +// + +// system include files +#include + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/global/EDProducer.h" + +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/MakerMacros.h" + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/StreamID.h" + +#include "DataFormats/PatCandidates/interface/Jet.h" +#include "DataFormats/PatCandidates/interface/Photon.h" +#include "DataFormats/PatCandidates/interface/Muon.h" + +#include "TFile.h" +#include "TF1.h" +#include "TH2.h" + +#include +enum fluctuations { central = 0, up, down }; + +class L1PrefiringWeightProducer : public edm::global::EDProducer<> { +public: + explicit L1PrefiringWeightProducer(const edm::ParameterSet&); + ~L1PrefiringWeightProducer() override; + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + +private: + void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + + double getPrefiringRate(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const; + double getPrefiringRateMuon(double eta, double phi, double pt, fluctuations fluctuation) const; + + edm::EDGetTokenT > photons_token_; + edm::EDGetTokenT > jets_token_; + edm::EDGetTokenT > muon_token_; + + TF1* parametrization0p0To0p2_; + TF1* parametrization0p2To0p3_; + TF1* parametrization0p3To0p55_; + TF1* parametrization0p55To0p83_; + TF1* parametrization0p83To1p24_; + TF1* parametrization1p24To1p4_; + TF1* parametrization1p4To1p6_; + TF1* parametrization1p6To1p8_; + TF1* parametrization1p8To2p1_; + TF1* parametrization2p1To2p25_; + TF1* parametrization2p25To2p4_; + TF1* parametrizationHotSpot_; + + TH2F* h_prefmap_photon; + TH2F* h_prefmap_jet; + std::string dataera_; + std::string dataeraMuon_; + bool useEMpt_; + double prefiringRateSystUnc_; + double jetMaxMuonFraction_; + bool skipwarnings_; +}; + +L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig) { + photons_token_ = consumes >(iConfig.getParameter("ThePhotons")); + jets_token_ = consumes >(iConfig.getParameter("TheJets")); + muon_token_ = consumes >(iConfig.getParameter("TheMuons")); + + dataera_ = iConfig.getParameter("DataEra"); + dataeraMuon_ = iConfig.getParameter("DataEraMuon"); + useEMpt_ = iConfig.getParameter("UseJetEMPt"); + prefiringRateSystUnc_ = iConfig.getParameter("PrefiringRateSystematicUncty"); + jetMaxMuonFraction_ = iConfig.getParameter("JetMaxMuonFraction"); + skipwarnings_ = iConfig.getParameter("SkipWarnings"); + + TFile* file_prefiringmaps_; + std::string fname = iConfig.getParameter("L1Maps"); + edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); + file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read"); + if (file_prefiringmaps_ == nullptr && !skipwarnings_) + std::cout << "File with maps not found. All prefiring weights set to 0. " << std::endl; + + TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_; + if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) + std::cout << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname); + + TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_; + if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) + std::cout << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname); + file_prefiringmaps_->Close(); + delete file_prefiringmaps_; + + TFile* file_prefiringparams_; + std::string fnameMuon = iConfig.getParameter("L1MuonParametrizations"); + edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon); + file_prefiringparams_ = new TFile(paramsfilepath.fullPath().c_str(), "read"); + if (file_prefiringparams_ == nullptr && !skipwarnings_) + std::cout << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; + + TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; + parametrization0p0To0p2_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_0.2To0.3_" + dataeraMuon_; + parametrization0p2To0p3_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_0.3To0.55_" + dataeraMuon_; + parametrization0p3To0p55_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_0.55To0.83_" + dataeraMuon_; + parametrization0p55To0p83_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_0.83To1.24_" + dataeraMuon_; + parametrization0p83To1p24_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_1.24To1.4_" + dataeraMuon_; + parametrization1p24To1p4_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_1.4To1.6_" + dataeraMuon_; + parametrization1p4To1p6_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_1.6To1.8_" + dataeraMuon_; + parametrization1p6To1p8_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_1.8To2.1_" + dataeraMuon_; + parametrization1p8To2p1_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_2.1To2.25_" + dataeraMuon_; + parametrization2p1To2p25_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_2.25To2.4_" + dataeraMuon_; + parametrization2p25To2p4_ = (TF1*)file_prefiringparams_->Get(paramName); + paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_; + parametrizationHotSpot_ = (TF1*)file_prefiringparams_->Get(paramName); + + + + produces("nonPrefiringProb").setBranchAlias("nonPrefiringProb"); + produces("nonPrefiringProbUp").setBranchAlias("nonPrefiringProbUp"); + produces("nonPrefiringProbDown").setBranchAlias("nonPrefiringProbDown"); + + produces("nonPrefiringProbJet").setBranchAlias("nonPrefiringProbJet"); + produces("nonPrefiringProbJetUp").setBranchAlias("nonPrefiringProbJetUp"); + produces("nonPrefiringProbJetDown").setBranchAlias("nonPrefiringProbJetDown"); + + produces("nonPrefiringProbPhoton").setBranchAlias("nonPrefiringProbPhoton"); + produces("nonPrefiringProbPhotonUp").setBranchAlias("nonPrefiringProbPhotonUp"); + produces("nonPrefiringProbPhotonDown").setBranchAlias("nonPrefiringProbPhotonDown"); + + produces("nonPrefiringProbMuon").setBranchAlias("nonPrefiringProbMuon"); + produces("nonPrefiringProbMuonUp").setBranchAlias("nonPrefiringProbMuonUp"); + produces("nonPrefiringProbMuonDown").setBranchAlias("nonPrefiringProbMuonDown"); +} + +L1PrefiringWeightProducer::~L1PrefiringWeightProducer() { + delete h_prefmap_photon; + delete h_prefmap_jet; + delete parametrization0p0To0p2_; + delete parametrization0p2To0p3_; + delete parametrization0p3To0p55_; + delete parametrization0p55To0p83_; + delete parametrization0p83To1p24_; + delete parametrization1p24To1p4_; + delete parametrization1p4To1p6_; + delete parametrization1p6To1p8_; + delete parametrization1p8To2p1_; + delete parametrization2p1To2p25_; + delete parametrization2p25To2p4_; + delete parametrizationHotSpot_; + +} + +void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { + using namespace edm; + + //Photons + edm::Handle > thePhotons; + iEvent.getByToken(photons_token_, thePhotons); + + //Jets + edm::Handle > theJets; + iEvent.getByToken(jets_token_, theJets); + + //Muons + edm::Handle > theMuons; + iEvent.getByToken(muon_token_, theMuons); + + //Probability for the event NOT to prefire, computed with the prefiring maps per object. + //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. + double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaPhoton[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + + for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { + for (const auto& photon : *thePhotons) { + double pt_gam = photon.pt(); + double eta_gam = photon.eta(); + if (pt_gam < 20.) + continue; + if (fabs(eta_gam) < 2.) + continue; + if (fabs(eta_gam) > 3.) + continue; + double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); + nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); + nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); + } + + //Now applying the prefiring maps to jets in the affected regions. + for (const auto& jet : *theJets) { + double pt_jet = jet.pt(); + double eta_jet = jet.eta(); + double phi_jet = jet.phi(); + if (pt_jet < 20.) + continue; + if (fabs(eta_jet) < 2.) + continue; + if (fabs(eta_jet) > 3.) + continue; + if (jetMaxMuonFraction_ > 0 && jet.muonEnergyFraction() > jetMaxMuonFraction_) + continue; + //Loop over photons to remove overlap + double nonprefiringprobfromoverlappingphotons = 1.; + for (const auto& photon : *thePhotons) { + double pt_gam = photon.pt(); + double eta_gam = photon.eta(); + double phi_gam = photon.phi(); + if (pt_gam < 20.) + continue; + if (fabs(eta_gam) < 2.) + continue; + if (fabs(eta_gam) > 3.) + continue; + double dR = reco::deltaR(eta_jet, phi_jet, eta_gam, phi_gam); + if (dR > 0.4) + continue; + double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); + nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam); + } + //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt. + if (useEMpt_) + pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction()); + double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRate(eta_jet, pt_jet, h_prefmap_jet, fluct); + + if (nonprefiringprobfromoverlappingphotons == 1.) { + nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; + nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; + } + //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one + else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { + if (nonprefiringprobfromoverlappingphotons != 0.) { + nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; + nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; + } else { + nonPrefiringProba[fluct] = 0.; + nonPrefiringProbaJet[fluct] = 0.; + } + } + //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. + } + for (const auto& muon : *theMuons) { + double pt = muon.pt(); + double phi = muon.eta(); + double eta = muon.eta(); + // Remove crappy tracker muons which would not have prefired the L1 trigger + if (pt < 5 && !muon.isStandAloneMuon()) continue; + double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); + nonPrefiringProba[fluct] *= (1. - prefiringprob_mu); + nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); + } + + + + } + auto nonPrefiringProb = std::make_unique(nonPrefiringProba[0]); + auto nonPrefiringProbUp = std::make_unique(nonPrefiringProba[1]); + auto nonPrefiringProbDown = std::make_unique(nonPrefiringProba[2]); + iEvent.put(std::move(nonPrefiringProb), "nonPrefiringProb"); + iEvent.put(std::move(nonPrefiringProbUp), "nonPrefiringProbUp"); + iEvent.put(std::move(nonPrefiringProbDown), "nonPrefiringProbDown"); + + auto nonPrefiringProbJet = std::make_unique(nonPrefiringProbaJet[0]); + auto nonPrefiringProbJetUp = std::make_unique(nonPrefiringProbaJet[1]); + auto nonPrefiringProbJetDown = std::make_unique(nonPrefiringProbaJet[2]); + iEvent.put(std::move(nonPrefiringProbJet), "nonPrefiringProbJet"); + iEvent.put(std::move(nonPrefiringProbJetUp), "nonPrefiringProbJetUp"); + iEvent.put(std::move(nonPrefiringProbJetDown), "nonPrefiringProbJetDown"); + + auto nonPrefiringProbPhoton = std::make_unique(nonPrefiringProbaPhoton[0]); + auto nonPrefiringProbPhotonUp = std::make_unique(nonPrefiringProbaPhoton[1]); + auto nonPrefiringProbPhotonDown = std::make_unique(nonPrefiringProbaPhoton[2]); + iEvent.put(std::move(nonPrefiringProbPhoton), "nonPrefiringProbPhoton"); + iEvent.put(std::move(nonPrefiringProbPhotonUp), "nonPrefiringProbPhotonUp"); + iEvent.put(std::move(nonPrefiringProbPhotonDown), "nonPrefiringProbPhotonDown"); + + auto nonPrefiringProbMuon = std::make_unique(nonPrefiringProbaMuon[0]); + auto nonPrefiringProbMuonUp = std::make_unique(nonPrefiringProbaMuon[1]); + auto nonPrefiringProbMuonDown = std::make_unique(nonPrefiringProbaMuon[2]); + iEvent.put(std::move(nonPrefiringProbMuon), "nonPrefiringProbMuon"); + iEvent.put(std::move(nonPrefiringProbMuonUp), "nonPrefiringProbMuonUp"); + iEvent.put(std::move(nonPrefiringProbMuonDown), "nonPrefiringProbMuonDown"); + +} + +double L1PrefiringWeightProducer::getPrefiringRate(double eta, + double pt, + TH2F* h_prefmap, + fluctuations fluctuation) const { + if (h_prefmap == nullptr && !skipwarnings_) + std::cout << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; + if (h_prefmap == nullptr) + return 0.; + //Check pt is not above map overflow + int nbinsy = h_prefmap->GetNbinsY(); + double maxy = h_prefmap->GetYaxis()->GetBinLowEdge(nbinsy + 1); + if (pt >= maxy) + pt = maxy - 0.01; + int thebin = h_prefmap->FindBin(eta, pt); + + double prefrate = h_prefmap->GetBinContent(thebin); + + double statuncty = h_prefmap->GetBinError(thebin); + double systuncty = prefiringRateSystUnc_ * prefrate; + + if (fluctuation == up) + prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); + if (fluctuation == down) + prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); + return prefrate; +} +double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, + double phi, + double pt, + fluctuations fluctuation) const { + double prefrate; + double statuncty; + if ( (dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && (phi > 2.44346 && phi < 2.79253)){ + if (parametrizationHotSpot_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi << std::endl; + if (parametrizationHotSpot_ == nullptr) + return 0.; + prefrate = parametrizationHotSpot_->Eval(pt); + statuncty = parametrizationHotSpot_->GetParError(2); + } + else if (std::abs(eta) < 0.2){ + if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p0To0p2_ == nullptr) + return 0.; + prefrate = parametrization0p0To0p2_->Eval(pt); + statuncty = parametrization0p0To0p2_->GetParError(2); + } + else if (std::abs(eta) < 0.3){ + if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p2To0p3_ == nullptr) + return 0.; + + prefrate = parametrization0p2To0p3_->Eval(pt); + statuncty = parametrization0p2To0p3_->GetParError(2); + } + else if (std::abs(eta) < 0.55){ + if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p3To0p55_ == nullptr) + return 0.; + + prefrate = parametrization0p3To0p55_->Eval(pt); + statuncty = parametrization0p3To0p55_->GetParError(2); + } + else if (std::abs(eta) < 0.83){ + if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p55To0p83_ == nullptr) + return 0.; + + prefrate = parametrization0p55To0p83_->Eval(pt); + statuncty = parametrization0p55To0p83_->GetParError(2); + } + else if (std::abs(eta) < 1.24){ + if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p83To1p24_ == nullptr) + return 0.; + + prefrate = parametrization0p83To1p24_->Eval(pt); + statuncty = parametrization0p83To1p24_->GetParError(2); + } + else if (std::abs(eta) < 1.4){ + if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p24To1p4_ == nullptr) + return 0.; + + prefrate = parametrization1p24To1p4_->Eval(pt); + statuncty = parametrization1p24To1p4_->GetParError(2); + } + else if (std::abs(eta) < 1.6){ + if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p4To1p6_ == nullptr) + return 0.; + + prefrate = parametrization1p4To1p6_->Eval(pt); + statuncty = parametrization1p4To1p6_->GetParError(2); + } + else if (std::abs(eta) < 1.8){ + if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p6To1p8_ == nullptr) + return 0.; + + prefrate = parametrization1p6To1p8_->Eval(pt); + statuncty = parametrization1p6To1p8_->GetParError(2); + } + else if (std::abs(eta) < 2.1){ + if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p8To2p1_ == nullptr) + return 0.; + + prefrate = parametrization1p8To2p1_->Eval(pt); + statuncty = parametrization1p8To2p1_->GetParError(2); + } + else if (std::abs(eta) < 2.25){ + if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization2p1To2p25_ == nullptr) + return 0.; + + prefrate = parametrization2p1To2p25_->Eval(pt); + statuncty = parametrization2p1To2p25_->GetParError(2); + } + else if (std::abs(eta) < 2.4){ + if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization2p25To2p4_ == nullptr) + return 0.; + + prefrate = parametrization2p25To2p4_->Eval(pt); + statuncty = parametrization2p25To2p4_->GetParError(2); + } + else + return 0.; + double systuncty = prefiringRateSystUnc_ * prefrate; + + if (fluctuation == up) + prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); + if (fluctuation == down) + prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); + return prefrate; +} + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + edm::ParameterSetDescription desc; + desc.add("TheMuons", edm::InputTag("slimmedMuons")); + desc.add("ThePhotons", edm::InputTag("slimmedPhotons")); + desc.add("TheJets", edm::InputTag("slimmedJets")); + desc.add("L1Maps", "L1PrefiringMaps.root"); + desc.add("L1MuonParametrizations", "L1MuonPrefiringParametriations.root"); + desc.add("DataEra", "2017BtoF"); + desc.add("DataEraMuon", "2016"); + desc.add("UseJetEMPt", false); + desc.add("PrefiringRateSystematicUncty", 0.2); + desc.add("JetMaxMuonFraction", 0.5); + desc.add("SkipWarnings", true); + descriptions.add("l1PrefiringWeightProducer", desc); +} + +//define this as a plug-in +DEFINE_FWK_MODULE(L1PrefiringWeightProducer); From 7145c79e018476488ab14a7c40c901429cf29918 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 17 May 2021 23:11:27 +0200 Subject: [PATCH 02/28] add missing era --- PhysicsTools/NanoAOD/python/nano_eras_cff.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PhysicsTools/NanoAOD/python/nano_eras_cff.py b/PhysicsTools/NanoAOD/python/nano_eras_cff.py index cfe39c6f1cc4e..ca9bc631185b8 100644 --- a/PhysicsTools/NanoAOD/python/nano_eras_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_eras_cff.py @@ -4,6 +4,7 @@ from Configuration.Eras.Modifier_run2_jme_2016_cff import run2_jme_2016 from Configuration.Eras.Modifier_run2_jme_2017_cff import run2_jme_2017 from Configuration.Eras.Modifier_run2_muon_2016_cff import run2_muon_2016 +from Configuration.Eras.Modifier_run2_muon_2018_cff import run2_muon_2018 from Configuration.Eras.Modifier_run2_HLTconditions_2016_cff import run2_HLTconditions_2016 from Configuration.Eras.Modifier_run2_HLTconditions_2017_cff import run2_HLTconditions_2017 From 9d42d6b8d6636f8270c264afff47394aa8ab332b Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 17 May 2021 23:20:54 +0200 Subject: [PATCH 03/28] code format --- .../plugins/L1PrefiringWeightProducer.cc | 228 ++++++++---------- 1 file changed, 106 insertions(+), 122 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index eb9d6dfdb418b..db93d7e1ebfc3 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -142,8 +142,6 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_; parametrizationHotSpot_ = (TF1*)file_prefiringparams_->Get(paramName); - - produces("nonPrefiringProb").setBranchAlias("nonPrefiringProb"); produces("nonPrefiringProbUp").setBranchAlias("nonPrefiringProbUp"); produces("nonPrefiringProbDown").setBranchAlias("nonPrefiringProbDown"); @@ -176,7 +174,6 @@ L1PrefiringWeightProducer::~L1PrefiringWeightProducer() { delete parametrization2p1To2p25_; delete parametrization2p25To2p4_; delete parametrizationHotSpot_; - } void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { @@ -196,10 +193,10 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const //Probability for the event NOT to prefire, computed with the prefiring maps per object. //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. - double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaPhoton[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { for (const auto& photon : *thePhotons) { @@ -273,14 +270,12 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const double phi = muon.eta(); double eta = muon.eta(); // Remove crappy tracker muons which would not have prefired the L1 trigger - if (pt < 5 && !muon.isStandAloneMuon()) continue; + if (pt < 5 && !muon.isStandAloneMuon()) + continue; double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); nonPrefiringProba[fluct] *= (1. - prefiringprob_mu); nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); } - - - } auto nonPrefiringProb = std::make_unique(nonPrefiringProba[0]); auto nonPrefiringProbUp = std::make_unique(nonPrefiringProba[1]); @@ -309,13 +304,12 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const iEvent.put(std::move(nonPrefiringProbMuon), "nonPrefiringProbMuon"); iEvent.put(std::move(nonPrefiringProbMuonUp), "nonPrefiringProbMuonUp"); iEvent.put(std::move(nonPrefiringProbMuonDown), "nonPrefiringProbMuonDown"); - } double L1PrefiringWeightProducer::getPrefiringRate(double eta, - double pt, - TH2F* h_prefmap, - fluctuations fluctuation) const { + double pt, + TH2F* h_prefmap, + fluctuations fluctuation) const { if (h_prefmap == nullptr && !skipwarnings_) std::cout << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; if (h_prefmap == nullptr) @@ -339,118 +333,108 @@ double L1PrefiringWeightProducer::getPrefiringRate(double eta, return prefrate; } double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, - double phi, + double phi, double pt, fluctuations fluctuation) const { double prefrate; double statuncty; - if ( (dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && (phi > 2.44346 && phi < 2.79253)){ - if (parametrizationHotSpot_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi << std::endl; - if (parametrizationHotSpot_ == nullptr) - return 0.; - prefrate = parametrizationHotSpot_->Eval(pt); - statuncty = parametrizationHotSpot_->GetParError(2); - } - else if (std::abs(eta) < 0.2){ - if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p0To0p2_ == nullptr) - return 0.; - prefrate = parametrization0p0To0p2_->Eval(pt); - statuncty = parametrization0p0To0p2_->GetParError(2); - } - else if (std::abs(eta) < 0.3){ - if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p2To0p3_ == nullptr) - return 0.; - - prefrate = parametrization0p2To0p3_->Eval(pt); - statuncty = parametrization0p2To0p3_->GetParError(2); - } - else if (std::abs(eta) < 0.55){ - if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p3To0p55_ == nullptr) - return 0.; - - prefrate = parametrization0p3To0p55_->Eval(pt); - statuncty = parametrization0p3To0p55_->GetParError(2); - } - else if (std::abs(eta) < 0.83){ - if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p55To0p83_ == nullptr) - return 0.; - - prefrate = parametrization0p55To0p83_->Eval(pt); - statuncty = parametrization0p55To0p83_->GetParError(2); - } - else if (std::abs(eta) < 1.24){ - if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p83To1p24_ == nullptr) - return 0.; - - prefrate = parametrization0p83To1p24_->Eval(pt); - statuncty = parametrization0p83To1p24_->GetParError(2); - } - else if (std::abs(eta) < 1.4){ - if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p24To1p4_ == nullptr) - return 0.; - - prefrate = parametrization1p24To1p4_->Eval(pt); - statuncty = parametrization1p24To1p4_->GetParError(2); - } - else if (std::abs(eta) < 1.6){ - if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p4To1p6_ == nullptr) - return 0.; - - prefrate = parametrization1p4To1p6_->Eval(pt); - statuncty = parametrization1p4To1p6_->GetParError(2); - } - else if (std::abs(eta) < 1.8){ - if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p6To1p8_ == nullptr) - return 0.; - - prefrate = parametrization1p6To1p8_->Eval(pt); - statuncty = parametrization1p6To1p8_->GetParError(2); - } - else if (std::abs(eta) < 2.1){ - if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p8To2p1_ == nullptr) - return 0.; - - prefrate = parametrization1p8To2p1_->Eval(pt); - statuncty = parametrization1p8To2p1_->GetParError(2); - } - else if (std::abs(eta) < 2.25){ - if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization2p1To2p25_ == nullptr) - return 0.; - - prefrate = parametrization2p1To2p25_->Eval(pt); - statuncty = parametrization2p1To2p25_->GetParError(2); - } - else if (std::abs(eta) < 2.4){ - if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization2p25To2p4_ == nullptr) - return 0.; - - prefrate = parametrization2p25To2p4_->Eval(pt); - statuncty = parametrization2p25To2p4_->GetParError(2); - } - else + if ((dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && + (phi > 2.44346 && phi < 2.79253)) { + if (parametrizationHotSpot_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi + << std::endl; + if (parametrizationHotSpot_ == nullptr) + return 0.; + prefrate = parametrizationHotSpot_->Eval(pt); + statuncty = parametrizationHotSpot_->GetParError(2); + } else if (std::abs(eta) < 0.2) { + if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p0To0p2_ == nullptr) + return 0.; + prefrate = parametrization0p0To0p2_->Eval(pt); + statuncty = parametrization0p0To0p2_->GetParError(2); + } else if (std::abs(eta) < 0.3) { + if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p2To0p3_ == nullptr) + return 0.; + + prefrate = parametrization0p2To0p3_->Eval(pt); + statuncty = parametrization0p2To0p3_->GetParError(2); + } else if (std::abs(eta) < 0.55) { + if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p3To0p55_ == nullptr) + return 0.; + + prefrate = parametrization0p3To0p55_->Eval(pt); + statuncty = parametrization0p3To0p55_->GetParError(2); + } else if (std::abs(eta) < 0.83) { + if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p55To0p83_ == nullptr) + return 0.; + + prefrate = parametrization0p55To0p83_->Eval(pt); + statuncty = parametrization0p55To0p83_->GetParError(2); + } else if (std::abs(eta) < 1.24) { + if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization0p83To1p24_ == nullptr) + return 0.; + + prefrate = parametrization0p83To1p24_->Eval(pt); + statuncty = parametrization0p83To1p24_->GetParError(2); + } else if (std::abs(eta) < 1.4) { + if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p24To1p4_ == nullptr) + return 0.; + + prefrate = parametrization1p24To1p4_->Eval(pt); + statuncty = parametrization1p24To1p4_->GetParError(2); + } else if (std::abs(eta) < 1.6) { + if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p4To1p6_ == nullptr) + return 0.; + + prefrate = parametrization1p4To1p6_->Eval(pt); + statuncty = parametrization1p4To1p6_->GetParError(2); + } else if (std::abs(eta) < 1.8) { + if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p6To1p8_ == nullptr) + return 0.; + + prefrate = parametrization1p6To1p8_->Eval(pt); + statuncty = parametrization1p6To1p8_->GetParError(2); + } else if (std::abs(eta) < 2.1) { + if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization1p8To2p1_ == nullptr) + return 0.; + + prefrate = parametrization1p8To2p1_->Eval(pt); + statuncty = parametrization1p8To2p1_->GetParError(2); + } else if (std::abs(eta) < 2.25) { + if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization2p1To2p25_ == nullptr) + return 0.; + + prefrate = parametrization2p1To2p25_->Eval(pt); + statuncty = parametrization2p1To2p25_->GetParError(2); + } else if (std::abs(eta) < 2.4) { + if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) + std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + if (parametrization2p25To2p4_ == nullptr) + return 0.; + + prefrate = parametrization2p25To2p4_->Eval(pt); + statuncty = parametrization2p25To2p4_->GetParError(2); + } else return 0.; double systuncty = prefiringRateSystUnc_ * prefrate; From 999876d3f2f19ffc058b0bb7382f9ce26d679b8f Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 18 May 2021 14:45:44 +0200 Subject: [PATCH 04/28] correctly rename cff config --- .../PatUtils/python/L1ECALPrefiringWeightProducer_cff.py | 6 ------ .../PatUtils/python/L1PrefiringWeightProducer_cff.py | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) delete mode 100644 PhysicsTools/PatUtils/python/L1ECALPrefiringWeightProducer_cff.py create mode 100644 PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py diff --git a/PhysicsTools/PatUtils/python/L1ECALPrefiringWeightProducer_cff.py b/PhysicsTools/PatUtils/python/L1ECALPrefiringWeightProducer_cff.py deleted file mode 100644 index c163719bd6fd4..0000000000000 --- a/PhysicsTools/PatUtils/python/L1ECALPrefiringWeightProducer_cff.py +++ /dev/null @@ -1,6 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -from PhysicsTools.PatUtils.l1ECALPrefiringWeightProducer_cfi import l1ECALPrefiringWeightProducer - -prefiringweight = l1ECALPrefiringWeightProducer.clone(SkipWarnings = False) - diff --git a/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py b/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py new file mode 100644 index 0000000000000..47737b19a9d31 --- /dev/null +++ b/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py @@ -0,0 +1,6 @@ +import FWCore.ParameterSet.Config as cms + +from PhysicsTools.PatUtils.l1PrefiringWeightProducer_cfi import l1PrefiringWeightProducer + +prefiringweight = l1PrefiringWeightProducer.clone(SkipWarnings = False) + From 8291674a6a6e3487bed56b8b050782b4e4ffee93 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 18 May 2021 15:42:48 +0200 Subject: [PATCH 05/28] fix test errors and address PR comments --- .../NanoAOD/python/triggerObjects_cff.py | 10 ++-- .../PatAlgos/python/slimming/miniAOD_tools.py | 10 ++-- .../plugins/L1PrefiringWeightProducer.cc | 55 +++++++++---------- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 30fe428558bec..29179821a09ff 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -218,18 +218,18 @@ from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight #Next line will be updated once we get UL2016 maps -run2_jme_2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH"), DataEraMuon = cms.string("2016")) +run2_jme_2016.toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016")) #Next line is for UL2017 maps -run2_jme_2017.toModify( prefiringweight, DataEra = cms.string("UL2017BtoF"), DataEraMuon = cms.string("20172018")) +run2_jme_2017.toModify( prefiringweight, DataEraECAL = cms.string("UL2017BtoF"), DataEraMuon = cms.string("20172018")) #Next line is for UL2018 maps -run2_jme_2018.toModify( prefiringweight, DataEra = cms.string("None"), DataEraMuon = cms.string("20172018")) +run2_muon_2018.toModify( prefiringweight, DataEraECAL = cms.string("None"), DataEraMuon = cms.string("20172018")) #For pre-UL 2017 reprocessing, one should use the original maps and no muon jet protection for modifier in run2_nanoAOD_94XMiniAODv1, run2_nanoAOD_94XMiniAODv2: - modifier.toModify( prefiringweight, DataEra = cms.string("2017BtoF"), DataEraMuon = cms.string("20172018")) + modifier.toModify( prefiringweight, DataEraECAL = cms.string("2017BtoF"), DataEraMuon = cms.string("20172018")) modifier.toModify( prefiringweight, JetMaxMuonFraction = cms.double(-1.) ) #For pre-UL 2016 reprocessing, same thing -run2_nanoAOD_94X2016.toModify( prefiringweight, DataEra = cms.string("2016BtoH"), DataEraMuon = cms.string("2016") ) +run2_nanoAOD_94X2016.toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016") ) run2_nanoAOD_94X2016.toModify( prefiringweight, JetMaxMuonFraction = cms.double(-1.) ) l1PreFiringEventWeightTable = cms.EDProducer("GlobalVariablesTableProducer", diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 8b04ba50a66f9..cb2b7025950e7 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -537,13 +537,15 @@ def _add_deepMET(process): process.load("RecoEgamma.EgammaTools.slimmedEgammaFromMultiCl_cff") phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaFromMultiClTask)) - # L1 pre-firing weights for 2016 and 2017 + # L1 pre-firing weights for 2016, 2017, and 2018 from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring from Configuration.Eras.Modifier_stage1L1Trigger_cff import stage1L1Trigger from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017 - process.load("PhysicsTools.PatUtils.L1ECALPrefiringWeightProducer_cff") - stage1L1Trigger.toModify(process.prefiringweight, DataEra = "2016BtoH") - stage2L1Trigger_2017.toModify(process.prefiringweight, DataEra = "2017BtoF") + from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018 + process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") + stage1L1Trigger.toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016" ) + stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "2017BtoF", DataEraMuon = "20172018") + stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight)) from PhysicsTools.PatAlgos.producersHeavyIons.heavyIonJetSetup import removeL1FastJetJECs diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index db93d7e1ebfc3..a84df525c94e7 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -84,7 +84,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC jets_token_ = consumes >(iConfig.getParameter("TheJets")); muon_token_ = consumes >(iConfig.getParameter("TheMuons")); - dataera_ = iConfig.getParameter("DataEra"); + dataera_ = iConfig.getParameter("DataEraECAL"); dataeraMuon_ = iConfig.getParameter("DataEraMuon"); useEMpt_ = iConfig.getParameter("UseJetEMPt"); prefiringRateSystUnc_ = iConfig.getParameter("PrefiringRateSystematicUncty"); @@ -96,16 +96,16 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read"); if (file_prefiringmaps_ == nullptr && !skipwarnings_) - std::cout << "File with maps not found. All prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "File with maps not found. All prefiring weights set to 0. " << std::endl; TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_; if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) - std::cout << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname); TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_; if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) - std::cout << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); delete file_prefiringmaps_; @@ -115,7 +115,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon); file_prefiringparams_ = new TFile(paramsfilepath.fullPath().c_str(), "read"); if (file_prefiringparams_ == nullptr && !skipwarnings_) - std::cout << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; parametrization0p0To0p2_ = (TF1*)file_prefiringparams_->Get(paramName); @@ -180,16 +180,13 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const using namespace edm; //Photons - edm::Handle > thePhotons; - iEvent.getByToken(photons_token_, thePhotons); + std::vector thePhotons = iEvent.get(photons_token_); //Jets - edm::Handle > theJets; - iEvent.getByToken(jets_token_, theJets); + std::vector theJets = iEvent.get(jets_token_); //Muons - edm::Handle > theMuons; - iEvent.getByToken(muon_token_, theMuons); + std::vector theMuons = iEvent.get(muon_token_); //Probability for the event NOT to prefire, computed with the prefiring maps per object. //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. @@ -199,7 +196,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { - for (const auto& photon : *thePhotons) { + for (const auto& photon : thePhotons) { double pt_gam = photon.pt(); double eta_gam = photon.eta(); if (pt_gam < 20.) @@ -214,7 +211,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const } //Now applying the prefiring maps to jets in the affected regions. - for (const auto& jet : *theJets) { + for (const auto& jet : theJets) { double pt_jet = jet.pt(); double eta_jet = jet.eta(); double phi_jet = jet.phi(); @@ -228,7 +225,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const continue; //Loop over photons to remove overlap double nonprefiringprobfromoverlappingphotons = 1.; - for (const auto& photon : *thePhotons) { + for (const auto& photon : thePhotons) { double pt_gam = photon.pt(); double eta_gam = photon.eta(); double phi_gam = photon.phi(); @@ -265,7 +262,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const } //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. } - for (const auto& muon : *theMuons) { + for (const auto& muon : theMuons) { double pt = muon.pt(); double phi = muon.eta(); double eta = muon.eta(); @@ -311,7 +308,7 @@ double L1PrefiringWeightProducer::getPrefiringRate(double eta, TH2F* h_prefmap, fluctuations fluctuation) const { if (h_prefmap == nullptr && !skipwarnings_) - std::cout << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; if (h_prefmap == nullptr) return 0.; //Check pt is not above map overflow @@ -341,7 +338,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, if ((dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && (phi > 2.44346 && phi < 2.79253)) { if (parametrizationHotSpot_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi << std::endl; if (parametrizationHotSpot_ == nullptr) return 0.; @@ -349,14 +346,14 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrizationHotSpot_->GetParError(2); } else if (std::abs(eta) < 0.2) { if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p0To0p2_ == nullptr) return 0.; prefrate = parametrization0p0To0p2_->Eval(pt); statuncty = parametrization0p0To0p2_->GetParError(2); } else if (std::abs(eta) < 0.3) { if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p2To0p3_ == nullptr) return 0.; @@ -364,7 +361,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p2To0p3_->GetParError(2); } else if (std::abs(eta) < 0.55) { if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p3To0p55_ == nullptr) return 0.; @@ -372,7 +369,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p3To0p55_->GetParError(2); } else if (std::abs(eta) < 0.83) { if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p55To0p83_ == nullptr) return 0.; @@ -380,7 +377,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p55To0p83_->GetParError(2); } else if (std::abs(eta) < 1.24) { if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p83To1p24_ == nullptr) return 0.; @@ -388,7 +385,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p83To1p24_->GetParError(2); } else if (std::abs(eta) < 1.4) { if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p24To1p4_ == nullptr) return 0.; @@ -396,7 +393,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p24To1p4_->GetParError(2); } else if (std::abs(eta) < 1.6) { if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p4To1p6_ == nullptr) return 0.; @@ -404,7 +401,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p4To1p6_->GetParError(2); } else if (std::abs(eta) < 1.8) { if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p6To1p8_ == nullptr) return 0.; @@ -412,7 +409,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p6To1p8_->GetParError(2); } else if (std::abs(eta) < 2.1) { if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p8To2p1_ == nullptr) return 0.; @@ -420,7 +417,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p8To2p1_->GetParError(2); } else if (std::abs(eta) < 2.25) { if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization2p1To2p25_ == nullptr) return 0.; @@ -428,7 +425,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization2p1To2p25_->GetParError(2); } else if (std::abs(eta) < 2.4) { if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) - std::cout << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization2p25To2p4_ == nullptr) return 0.; @@ -453,7 +450,7 @@ void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("TheJets", edm::InputTag("slimmedJets")); desc.add("L1Maps", "L1PrefiringMaps.root"); desc.add("L1MuonParametrizations", "L1MuonPrefiringParametriations.root"); - desc.add("DataEra", "2017BtoF"); + desc.add("DataEraECAL", "2017BtoF"); desc.add("DataEraMuon", "2016"); desc.add("UseJetEMPt", false); desc.add("PrefiringRateSystematicUncty", 0.2); From 29a1f5ddc541123ea1801f5ead9ec3e40a42e0e2 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 18 May 2021 15:50:03 +0200 Subject: [PATCH 06/28] code format --- .../plugins/L1PrefiringWeightProducer.cc | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index a84df525c94e7..7a990f4cd87e9 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -96,16 +96,19 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read"); if (file_prefiringmaps_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "File with maps not found. All prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "File with maps not found. All prefiring weights set to 0. " << std::endl; TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_; if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname); TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_; if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); delete file_prefiringmaps_; @@ -115,7 +118,8 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon); file_prefiringparams_ = new TFile(paramsfilepath.fullPath().c_str(), "read"); if (file_prefiringparams_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; parametrization0p0To0p2_ = (TF1*)file_prefiringparams_->Get(paramName); @@ -180,7 +184,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const using namespace edm; //Photons - std::vector thePhotons = iEvent.get(photons_token_); + std::vector thePhotons = iEvent.get(photons_token_); //Jets std::vector theJets = iEvent.get(jets_token_); @@ -338,22 +342,24 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, if ((dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && (phi > 2.44346 && phi < 2.79253)) { if (parametrizationHotSpot_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi - << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi << std::endl; if (parametrizationHotSpot_ == nullptr) return 0.; prefrate = parametrizationHotSpot_->Eval(pt); statuncty = parametrizationHotSpot_->GetParError(2); } else if (std::abs(eta) < 0.2) { if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p0To0p2_ == nullptr) return 0.; prefrate = parametrization0p0To0p2_->Eval(pt); statuncty = parametrization0p0To0p2_->GetParError(2); } else if (std::abs(eta) < 0.3) { if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p2To0p3_ == nullptr) return 0.; @@ -361,7 +367,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p2To0p3_->GetParError(2); } else if (std::abs(eta) < 0.55) { if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p3To0p55_ == nullptr) return 0.; @@ -369,7 +376,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p3To0p55_->GetParError(2); } else if (std::abs(eta) < 0.83) { if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p55To0p83_ == nullptr) return 0.; @@ -377,7 +385,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p55To0p83_->GetParError(2); } else if (std::abs(eta) < 1.24) { if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization0p83To1p24_ == nullptr) return 0.; @@ -385,7 +394,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization0p83To1p24_->GetParError(2); } else if (std::abs(eta) < 1.4) { if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p24To1p4_ == nullptr) return 0.; @@ -393,7 +403,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p24To1p4_->GetParError(2); } else if (std::abs(eta) < 1.6) { if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p4To1p6_ == nullptr) return 0.; @@ -401,7 +412,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p4To1p6_->GetParError(2); } else if (std::abs(eta) < 1.8) { if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p6To1p8_ == nullptr) return 0.; @@ -409,7 +421,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p6To1p8_->GetParError(2); } else if (std::abs(eta) < 2.1) { if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization1p8To2p1_ == nullptr) return 0.; @@ -417,7 +430,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization1p8To2p1_->GetParError(2); } else if (std::abs(eta) < 2.25) { if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization2p1To2p25_ == nullptr) return 0.; @@ -425,7 +439,8 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization2p1To2p25_->GetParError(2); } else if (std::abs(eta) < 2.4) { if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; if (parametrization2p25To2p4_ == nullptr) return 0.; From e961914be4be843140bff30ea8de9f3d9e952d6f Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 18 May 2021 18:22:05 +0200 Subject: [PATCH 07/28] add preVFP and postVFP options via modifiers --- PhysicsTools/NanoAOD/python/triggerObjects_cff.py | 3 ++- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 29179821a09ff..70655bd0c492f 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -218,7 +218,8 @@ from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight #Next line will be updated once we get UL2016 maps -run2_jme_2016.toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016")) +(run2_muon_2016 & tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016preVFP")) +(run2_muon_2016 & ~tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016postVFP")) #Next line is for UL2017 maps run2_jme_2017.toModify( prefiringweight, DataEraECAL = cms.string("UL2017BtoF"), DataEraMuon = cms.string("20172018")) #Next line is for UL2018 maps diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index cb2b7025950e7..d49c965d1bcd4 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -542,7 +542,10 @@ def _add_deepMET(process): from Configuration.Eras.Modifier_stage1L1Trigger_cff import stage1L1Trigger from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017 from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018 + from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016 process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") + (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) + (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) stage1L1Trigger.toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016" ) stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "2017BtoF", DataEraMuon = "20172018") stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") From baeed97b10481032ccf8f09a7449b45f8f5100dd Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 18 May 2021 18:54:43 +0200 Subject: [PATCH 08/28] fix --- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index d49c965d1bcd4..1c6b27cee50c2 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -545,7 +545,7 @@ def _add_deepMET(process): from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016 process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) - (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) + (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016postVFP" ) stage1L1Trigger.toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016" ) stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "2017BtoF", DataEraMuon = "20172018") stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") From 52dcdeb7c3d6b963ef448d319081d7f5c2e792f9 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Thu, 20 May 2021 00:18:39 +0200 Subject: [PATCH 09/28] bug fix plus add prefire weights to 2018 nanoAOD --- PhysicsTools/NanoAOD/python/nano_eras_cff.py | 1 + PhysicsTools/NanoAOD/python/triggerObjects_cff.py | 2 +- PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nano_eras_cff.py b/PhysicsTools/NanoAOD/python/nano_eras_cff.py index ca9bc631185b8..62b2723a2fe31 100644 --- a/PhysicsTools/NanoAOD/python/nano_eras_cff.py +++ b/PhysicsTools/NanoAOD/python/nano_eras_cff.py @@ -8,6 +8,7 @@ from Configuration.Eras.Modifier_run2_HLTconditions_2016_cff import run2_HLTconditions_2016 from Configuration.Eras.Modifier_run2_HLTconditions_2017_cff import run2_HLTconditions_2017 +from Configuration.Eras.Modifier_run2_HLTconditions_2018_cff import run2_HLTconditions_2018 from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy from Configuration.Eras.Modifier_run2_nanoAOD_92X_cff import run2_nanoAOD_92X diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 70655bd0c492f..bc5811e1640d5 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -257,4 +257,4 @@ _triggerObjectTables_withL1PreFiring = triggerObjectTables.copy() _triggerObjectTables_withL1PreFiring.replace(triggerObjectTable, prefiringweight + l1PreFiringEventWeightTable + triggerObjectTable) -(run2_HLTconditions_2016 | run2_HLTconditions_2017).toReplaceWith(triggerObjectTables, _triggerObjectTables_withL1PreFiring) +(run2_HLTconditions_2016 | run2_HLTconditions_2017 | run2_HLTconditions_2018).toReplaceWith(triggerObjectTables, _triggerObjectTables_withL1PreFiring) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 7a990f4cd87e9..c22ab66c165a2 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -268,7 +268,7 @@ void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const } for (const auto& muon : theMuons) { double pt = muon.pt(); - double phi = muon.eta(); + double phi = muon.phi(); double eta = muon.eta(); // Remove crappy tracker muons which would not have prefired the L1 trigger if (pt < 5 && !muon.isStandAloneMuon()) From 02827ffa16f55ac14d9193e9a7a4bbfa3a807a63 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Thu, 20 May 2021 17:13:26 +0200 Subject: [PATCH 10/28] make L1PrefiringWeightProducer a stream producer to address thread safety issue of TF1 --- .../PatUtils/plugins/L1PrefiringWeightProducer.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index c22ab66c165a2..839222b7801b3 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -20,7 +20,7 @@ #include #include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/global/EDProducer.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" @@ -39,7 +39,7 @@ #include enum fluctuations { central = 0, up, down }; -class L1PrefiringWeightProducer : public edm::global::EDProducer<> { +class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { public: explicit L1PrefiringWeightProducer(const edm::ParameterSet&); ~L1PrefiringWeightProducer() override; @@ -47,7 +47,7 @@ class L1PrefiringWeightProducer : public edm::global::EDProducer<> { static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override; + void produce(edm::Event&, const edm::EventSetup&) override; double getPrefiringRate(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const; double getPrefiringRateMuon(double eta, double phi, double pt, fluctuations fluctuation) const; @@ -180,7 +180,7 @@ L1PrefiringWeightProducer::~L1PrefiringWeightProducer() { delete parametrizationHotSpot_; } -void L1PrefiringWeightProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const { +void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; //Photons From e37a9cd352314f592f4b6ae679208a4f2dd5b56b Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 21 May 2021 16:46:03 +0200 Subject: [PATCH 11/28] addressing code momments from the PR --- .../PatAlgos/python/slimming/miniAOD_tools.py | 1 - .../plugins/L1PrefiringWeightProducer.cc | 220 +++++++++--------- 2 files changed, 114 insertions(+), 107 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 1c6b27cee50c2..2511a7d2cb0dd 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -546,7 +546,6 @@ def _add_deepMET(process): process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016postVFP" ) - stage1L1Trigger.toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016" ) stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "2017BtoF", DataEraMuon = "20172018") stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight)) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 839222b7801b3..0e144f9e71cdb 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -49,12 +49,31 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { private: void produce(edm::Event&, const edm::EventSetup&) override; - double getPrefiringRate(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const; + double getPrefiringRateEcal(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const; double getPrefiringRateMuon(double eta, double phi, double pt, fluctuations fluctuation) const; - edm::EDGetTokenT > photons_token_; - edm::EDGetTokenT > jets_token_; - edm::EDGetTokenT > muon_token_; + const edm::EDGetTokenT > photons_token_; + const edm::EDGetTokenT > jets_token_; + const edm::EDGetTokenT > muon_token_; + + const edm::EDPutTokenT nonPrefiringProbToken_; + const edm::EDPutTokenT nonPrefiringProbUpToken_; + const edm::EDPutTokenT nonPrefiringProbDownToken_; + + const edm::EDPutTokenT nonPrefiringProbJetToken_; + const edm::EDPutTokenT nonPrefiringProbJetUpToken_; + const edm::EDPutTokenT nonPrefiringProbJetDownToken_; + + const edm::EDPutTokenT nonPrefiringProbPhotonToken_; + const edm::EDPutTokenT nonPrefiringProbPhotonUpToken_; + const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; + + const edm::EDPutTokenT nonPrefiringProbMuonToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownToken_; + + std::unique_ptr file_prefiringmaps_; + std::unique_ptr file_prefiringparams_; TF1* parametrization0p0To0p2_; TF1* parametrization0p2To0p3_; @@ -69,103 +88,99 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { TF1* parametrization2p25To2p4_; TF1* parametrizationHotSpot_; - TH2F* h_prefmap_photon; - TH2F* h_prefmap_jet; - std::string dataera_; + TH2F* h_prefmap_photon_; + TH2F* h_prefmap_jet_; + std::string dataeraEcal_; std::string dataeraMuon_; bool useEMpt_; - double prefiringRateSystUnc_; + double prefiringRateSystUncEcal_; + double prefiringRateSystUncMuon_; double jetMaxMuonFraction_; bool skipwarnings_; }; -L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig) { - photons_token_ = consumes >(iConfig.getParameter("ThePhotons")); - jets_token_ = consumes >(iConfig.getParameter("TheJets")); - muon_token_ = consumes >(iConfig.getParameter("TheMuons")); - - dataera_ = iConfig.getParameter("DataEraECAL"); +L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig) + : photons_token_(consumes >(iConfig.getParameter("ThePhotons"))), + jets_token_(consumes >(iConfig.getParameter("TheJets"))), + muon_token_(consumes >(iConfig.getParameter("TheMuons"))), + nonPrefiringProbToken_(produces("nonPrefiringProb")), + nonPrefiringProbUpToken_(produces("nonPrefiringProbUp")), + nonPrefiringProbDownToken_(produces("nonPrefiringProbDown")), + nonPrefiringProbJetToken_(produces("nonPrefiringProbJet")), + nonPrefiringProbJetUpToken_(produces("nonPrefiringProbJetUp")), + nonPrefiringProbJetDownToken_(produces("nonPrefiringProbJetDown")), + nonPrefiringProbPhotonToken_(produces("nonPrefiringProbPhoton")), + nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), + nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), + nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), + nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), + nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")) { + dataeraEcal_ = iConfig.getParameter("DataEraECAL"); dataeraMuon_ = iConfig.getParameter("DataEraMuon"); - useEMpt_ = iConfig.getParameter("UseJetEMPt"); - prefiringRateSystUnc_ = iConfig.getParameter("PrefiringRateSystematicUncty"); - jetMaxMuonFraction_ = iConfig.getParameter("JetMaxMuonFraction"); - skipwarnings_ = iConfig.getParameter("SkipWarnings"); + useEMpt_ = iConfig.getUntrackedParameter("UseJetEMPt"); + prefiringRateSystUncEcal_ = iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyECAL"); + prefiringRateSystUncMuon_ = iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyMuon"); + jetMaxMuonFraction_ = iConfig.getUntrackedParameter("JetMaxMuonFraction"); + skipwarnings_ = iConfig.getUntrackedParameter("SkipWarnings"); - TFile* file_prefiringmaps_; std::string fname = iConfig.getParameter("L1Maps"); edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); - file_prefiringmaps_ = new TFile(mapsfilepath.fullPath().c_str(), "read"); + file_prefiringmaps_ = std::make_unique(mapsfilepath.fullPath().c_str(), "read"); if (file_prefiringmaps_ == nullptr && !skipwarnings_) edm::LogWarning("L1PrefireWeightProducer") << "File with maps not found. All prefiring weights set to 0. " << std::endl; - TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataera_; + TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataeraEcal_; if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) edm::LogWarning("L1PrefireWeightProducer") << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; - h_prefmap_photon = (TH2F*)file_prefiringmaps_->Get(mapphotonfullname); + h_prefmap_photon_ = file_prefiringmaps_->Get(mapphotonfullname); - TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataera_ : "L1prefiring_jetptvseta_" + dataera_; + TString mapjetfullname = + (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataeraEcal_ : "L1prefiring_jetptvseta_" + dataeraEcal_; if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) edm::LogWarning("L1PrefireWeightProducer") << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; - h_prefmap_jet = (TH2F*)file_prefiringmaps_->Get(mapjetfullname); + h_prefmap_jet_ = file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); - delete file_prefiringmaps_; - TFile* file_prefiringparams_; std::string fnameMuon = iConfig.getParameter("L1MuonParametrizations"); edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon); - file_prefiringparams_ = new TFile(paramsfilepath.fullPath().c_str(), "read"); + file_prefiringparams_ = std::make_unique(paramsfilepath.fullPath().c_str(), "read"); if (file_prefiringparams_ == nullptr && !skipwarnings_) edm::LogWarning("L1PrefireWeightProducer") << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; - parametrization0p0To0p2_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization0p0To0p2_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_0.2To0.3_" + dataeraMuon_; - parametrization0p2To0p3_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization0p2To0p3_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_0.3To0.55_" + dataeraMuon_; - parametrization0p3To0p55_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization0p3To0p55_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_0.55To0.83_" + dataeraMuon_; - parametrization0p55To0p83_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization0p55To0p83_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_0.83To1.24_" + dataeraMuon_; - parametrization0p83To1p24_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization0p83To1p24_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_1.24To1.4_" + dataeraMuon_; - parametrization1p24To1p4_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization1p24To1p4_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_1.4To1.6_" + dataeraMuon_; - parametrization1p4To1p6_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization1p4To1p6_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_1.6To1.8_" + dataeraMuon_; - parametrization1p6To1p8_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization1p6To1p8_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_1.8To2.1_" + dataeraMuon_; - parametrization1p8To2p1_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization1p8To2p1_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_2.1To2.25_" + dataeraMuon_; - parametrization2p1To2p25_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization2p1To2p25_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_2.25To2.4_" + dataeraMuon_; - parametrization2p25To2p4_ = (TF1*)file_prefiringparams_->Get(paramName); + parametrization2p25To2p4_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_; - parametrizationHotSpot_ = (TF1*)file_prefiringparams_->Get(paramName); - - produces("nonPrefiringProb").setBranchAlias("nonPrefiringProb"); - produces("nonPrefiringProbUp").setBranchAlias("nonPrefiringProbUp"); - produces("nonPrefiringProbDown").setBranchAlias("nonPrefiringProbDown"); - - produces("nonPrefiringProbJet").setBranchAlias("nonPrefiringProbJet"); - produces("nonPrefiringProbJetUp").setBranchAlias("nonPrefiringProbJetUp"); - produces("nonPrefiringProbJetDown").setBranchAlias("nonPrefiringProbJetDown"); - - produces("nonPrefiringProbPhoton").setBranchAlias("nonPrefiringProbPhoton"); - produces("nonPrefiringProbPhotonUp").setBranchAlias("nonPrefiringProbPhotonUp"); - produces("nonPrefiringProbPhotonDown").setBranchAlias("nonPrefiringProbPhotonDown"); - - produces("nonPrefiringProbMuon").setBranchAlias("nonPrefiringProbMuon"); - produces("nonPrefiringProbMuonUp").setBranchAlias("nonPrefiringProbMuonUp"); - produces("nonPrefiringProbMuonDown").setBranchAlias("nonPrefiringProbMuonDown"); + parametrizationHotSpot_ = file_prefiringparams_->Get(paramName); + file_prefiringparams_->Close(); } L1PrefiringWeightProducer::~L1PrefiringWeightProducer() { - delete h_prefmap_photon; - delete h_prefmap_jet; + delete h_prefmap_photon_; + delete h_prefmap_jet_; delete parametrization0p0To0p2_; delete parametrization0p2To0p3_; delete parametrization0p3To0p55_; @@ -184,13 +199,13 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu using namespace edm; //Photons - std::vector thePhotons = iEvent.get(photons_token_); + const std::vector& thePhotons = iEvent.get(photons_token_); //Jets - std::vector theJets = iEvent.get(jets_token_); + const std::vector& theJets = iEvent.get(jets_token_); //Muons - std::vector theMuons = iEvent.get(muon_token_); + const std::vector& theMuons = iEvent.get(muon_token_); //Probability for the event NOT to prefire, computed with the prefiring maps per object. //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. @@ -209,7 +224,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu continue; if (fabs(eta_gam) > 3.) continue; - double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); + double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); } @@ -229,6 +244,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu continue; //Loop over photons to remove overlap double nonprefiringprobfromoverlappingphotons = 1.; + bool foundOverlappingPhotons = false; for (const auto& photon : thePhotons) { double pt_gam = photon.pt(); double eta_gam = photon.eta(); @@ -239,24 +255,25 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu continue; if (fabs(eta_gam) > 3.) continue; - double dR = reco::deltaR(eta_jet, phi_jet, eta_gam, phi_gam); - if (dR > 0.4) + double dR2 = reco::deltaR2(eta_jet, phi_jet, eta_gam, phi_gam); + if (dR2 > 0.16) continue; - double prefiringprob_gam = getPrefiringRate(eta_gam, pt_gam, h_prefmap_photon, fluct); + double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam); + foundOverlappingPhotons = true; } //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt. if (useEMpt_) pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction()); - double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRate(eta_jet, pt_jet, h_prefmap_jet, fluct); + double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct); - if (nonprefiringprobfromoverlappingphotons == 1.) { + if (!foundOverlappingPhotons) { nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; } //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { - if (nonprefiringprobfromoverlappingphotons != 0.) { + if (nonprefiringprobfromoverlappingphotons <= 0.) { nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; } else { @@ -266,6 +283,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu } //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. } + //Now calculate prefiring weights for muons for (const auto& muon : theMuons) { double pt = muon.pt(); double phi = muon.phi(); @@ -278,39 +296,28 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); } } - auto nonPrefiringProb = std::make_unique(nonPrefiringProba[0]); - auto nonPrefiringProbUp = std::make_unique(nonPrefiringProba[1]); - auto nonPrefiringProbDown = std::make_unique(nonPrefiringProba[2]); - iEvent.put(std::move(nonPrefiringProb), "nonPrefiringProb"); - iEvent.put(std::move(nonPrefiringProbUp), "nonPrefiringProbUp"); - iEvent.put(std::move(nonPrefiringProbDown), "nonPrefiringProbDown"); - - auto nonPrefiringProbJet = std::make_unique(nonPrefiringProbaJet[0]); - auto nonPrefiringProbJetUp = std::make_unique(nonPrefiringProbaJet[1]); - auto nonPrefiringProbJetDown = std::make_unique(nonPrefiringProbaJet[2]); - iEvent.put(std::move(nonPrefiringProbJet), "nonPrefiringProbJet"); - iEvent.put(std::move(nonPrefiringProbJetUp), "nonPrefiringProbJetUp"); - iEvent.put(std::move(nonPrefiringProbJetDown), "nonPrefiringProbJetDown"); - - auto nonPrefiringProbPhoton = std::make_unique(nonPrefiringProbaPhoton[0]); - auto nonPrefiringProbPhotonUp = std::make_unique(nonPrefiringProbaPhoton[1]); - auto nonPrefiringProbPhotonDown = std::make_unique(nonPrefiringProbaPhoton[2]); - iEvent.put(std::move(nonPrefiringProbPhoton), "nonPrefiringProbPhoton"); - iEvent.put(std::move(nonPrefiringProbPhotonUp), "nonPrefiringProbPhotonUp"); - iEvent.put(std::move(nonPrefiringProbPhotonDown), "nonPrefiringProbPhotonDown"); - - auto nonPrefiringProbMuon = std::make_unique(nonPrefiringProbaMuon[0]); - auto nonPrefiringProbMuonUp = std::make_unique(nonPrefiringProbaMuon[1]); - auto nonPrefiringProbMuonDown = std::make_unique(nonPrefiringProbaMuon[2]); - iEvent.put(std::move(nonPrefiringProbMuon), "nonPrefiringProbMuon"); - iEvent.put(std::move(nonPrefiringProbMuonUp), "nonPrefiringProbMuonUp"); - iEvent.put(std::move(nonPrefiringProbMuonDown), "nonPrefiringProbMuonDown"); + //Move global prefire weights, as well as those for muons, photons, and jets, to the event + iEvent.emplace(nonPrefiringProbToken_, nonPrefiringProba[0]); + iEvent.emplace(nonPrefiringProbUpToken_, nonPrefiringProba[1]); + iEvent.emplace(nonPrefiringProbDownToken_, nonPrefiringProba[2]); + + iEvent.emplace(nonPrefiringProbJetToken_, nonPrefiringProbaJet[0]); + iEvent.emplace(nonPrefiringProbJetUpToken_, nonPrefiringProbaJet[1]); + iEvent.emplace(nonPrefiringProbJetDownToken_, nonPrefiringProbaJet[2]); + + iEvent.emplace(nonPrefiringProbPhotonToken_, nonPrefiringProbaPhoton[0]); + iEvent.emplace(nonPrefiringProbPhotonUpToken_, nonPrefiringProbaPhoton[1]); + iEvent.emplace(nonPrefiringProbPhotonDownToken_, nonPrefiringProbaPhoton[2]); + + iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]); + iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]); + iEvent.emplace(nonPrefiringProbMuonDownToken_, nonPrefiringProbaMuon[2]); } -double L1PrefiringWeightProducer::getPrefiringRate(double eta, - double pt, - TH2F* h_prefmap, - fluctuations fluctuation) const { +double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, + double pt, + TH2F* h_prefmap, + fluctuations fluctuation) const { if (h_prefmap == nullptr && !skipwarnings_) edm::LogWarning("L1PrefireWeightProducer") << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; if (h_prefmap == nullptr) @@ -325,11 +332,11 @@ double L1PrefiringWeightProducer::getPrefiringRate(double eta, double prefrate = h_prefmap->GetBinContent(thebin); double statuncty = h_prefmap->GetBinError(thebin); - double systuncty = prefiringRateSystUnc_ * prefrate; + double systuncty = prefiringRateSystUncEcal_ * prefrate; if (fluctuation == up) prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - if (fluctuation == down) + else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); return prefrate; } @@ -448,11 +455,11 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, statuncty = parametrization2p25To2p4_->GetParError(2); } else return 0.; - double systuncty = prefiringRateSystUnc_ * prefrate; + double systuncty = prefiringRateSystUncMuon_ * prefrate; if (fluctuation == up) prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - if (fluctuation == down) + else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); return prefrate; } @@ -467,10 +474,11 @@ void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("L1MuonParametrizations", "L1MuonPrefiringParametriations.root"); desc.add("DataEraECAL", "2017BtoF"); desc.add("DataEraMuon", "2016"); - desc.add("UseJetEMPt", false); - desc.add("PrefiringRateSystematicUncty", 0.2); - desc.add("JetMaxMuonFraction", 0.5); - desc.add("SkipWarnings", true); + desc.addUntracked("UseJetEMPt", false); + desc.addUntracked("PrefiringRateSystematicUnctyECAL", 0.2); + desc.addUntracked("PrefiringRateSystematicUnctyMuon", 0.2); + desc.addUntracked("JetMaxMuonFraction", 0.5); + desc.addUntracked("SkipWarnings", true); descriptions.add("l1PrefiringWeightProducer", desc); } From 1de3d2e8d7d96d9ad78ec0b322daac76b37eb88d Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 21 May 2021 17:02:36 +0200 Subject: [PATCH 12/28] make more member variables const --- .../plugins/L1PrefiringWeightProducer.cc | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 0e144f9e71cdb..645a64b0cf3e0 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -90,13 +90,13 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { TH2F* h_prefmap_photon_; TH2F* h_prefmap_jet_; - std::string dataeraEcal_; - std::string dataeraMuon_; - bool useEMpt_; - double prefiringRateSystUncEcal_; - double prefiringRateSystUncMuon_; - double jetMaxMuonFraction_; - bool skipwarnings_; + const std::string dataeraEcal_; + const std::string dataeraMuon_; + const bool useEMpt_; + const double prefiringRateSystUncEcal_; + const double prefiringRateSystUncMuon_; + const double jetMaxMuonFraction_; + const bool skipwarnings_; }; L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig) @@ -114,15 +114,14 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), - nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")) { - dataeraEcal_ = iConfig.getParameter("DataEraECAL"); - dataeraMuon_ = iConfig.getParameter("DataEraMuon"); - useEMpt_ = iConfig.getUntrackedParameter("UseJetEMPt"); - prefiringRateSystUncEcal_ = iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyECAL"); - prefiringRateSystUncMuon_ = iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyMuon"); - jetMaxMuonFraction_ = iConfig.getUntrackedParameter("JetMaxMuonFraction"); - skipwarnings_ = iConfig.getUntrackedParameter("SkipWarnings"); - + nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), + dataeraEcal_(iConfig.getParameter("DataEraECAL")), + dataeraMuon_(iConfig.getParameter("DataEraMuon")), + useEMpt_(iConfig.getUntrackedParameter("UseJetEMPt")), + prefiringRateSystUncEcal_(iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyECAL")), + prefiringRateSystUncMuon_(iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyMuon")), + jetMaxMuonFraction_(iConfig.getUntrackedParameter("JetMaxMuonFraction")), + skipwarnings_(iConfig.getUntrackedParameter("SkipWarnings")) { std::string fname = iConfig.getParameter("L1Maps"); edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); file_prefiringmaps_ = std::make_unique(mapsfilepath.fullPath().c_str(), "read"); From 05f63aaeafae7dda7a425445ec855da39a7da706 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 21 May 2021 17:05:29 +0200 Subject: [PATCH 13/28] remove unnecessary deletes --- .../plugins/L1PrefiringWeightProducer.cc | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 645a64b0cf3e0..64c488d610608 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -177,22 +177,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC file_prefiringparams_->Close(); } -L1PrefiringWeightProducer::~L1PrefiringWeightProducer() { - delete h_prefmap_photon_; - delete h_prefmap_jet_; - delete parametrization0p0To0p2_; - delete parametrization0p2To0p3_; - delete parametrization0p3To0p55_; - delete parametrization0p55To0p83_; - delete parametrization0p83To1p24_; - delete parametrization1p24To1p4_; - delete parametrization1p4To1p6_; - delete parametrization1p6To1p8_; - delete parametrization1p8To2p1_; - delete parametrization2p1To2p25_; - delete parametrization2p25To2p4_; - delete parametrizationHotSpot_; -} +L1PrefiringWeightProducer::~L1PrefiringWeightProducer() {} void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { using namespace edm; From 1255d48f0c2dec14bacbdbc347195e688b84651f Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 21 May 2021 17:14:29 +0200 Subject: [PATCH 14/28] retrack some variables --- .../plugins/L1PrefiringWeightProducer.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 64c488d610608..2ae4d66590f2c 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -117,10 +117,10 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), dataeraEcal_(iConfig.getParameter("DataEraECAL")), dataeraMuon_(iConfig.getParameter("DataEraMuon")), - useEMpt_(iConfig.getUntrackedParameter("UseJetEMPt")), - prefiringRateSystUncEcal_(iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyECAL")), - prefiringRateSystUncMuon_(iConfig.getUntrackedParameter("PrefiringRateSystematicUnctyMuon")), - jetMaxMuonFraction_(iConfig.getUntrackedParameter("JetMaxMuonFraction")), + useEMpt_(iConfig.getParameter("UseJetEMPt")), + prefiringRateSystUncEcal_(iConfig.getParameter("PrefiringRateSystematicUnctyECAL")), + prefiringRateSystUncMuon_(iConfig.getParameter("PrefiringRateSystematicUnctyMuon")), + jetMaxMuonFraction_(iConfig.getParameter("JetMaxMuonFraction")), skipwarnings_(iConfig.getUntrackedParameter("SkipWarnings")) { std::string fname = iConfig.getParameter("L1Maps"); edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); @@ -458,10 +458,10 @@ void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("L1MuonParametrizations", "L1MuonPrefiringParametriations.root"); desc.add("DataEraECAL", "2017BtoF"); desc.add("DataEraMuon", "2016"); - desc.addUntracked("UseJetEMPt", false); - desc.addUntracked("PrefiringRateSystematicUnctyECAL", 0.2); - desc.addUntracked("PrefiringRateSystematicUnctyMuon", 0.2); - desc.addUntracked("JetMaxMuonFraction", 0.5); + desc.add("UseJetEMPt", false); + desc.add("PrefiringRateSystematicUnctyECAL", 0.2); + desc.add("PrefiringRateSystematicUnctyMuon", 0.2); + desc.add("JetMaxMuonFraction", 0.5); desc.addUntracked("SkipWarnings", true); descriptions.add("l1PrefiringWeightProducer", desc); } From 5704e9c02dee38cabfd3a46f5451239b6f617d63 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 24 May 2021 15:47:42 +0200 Subject: [PATCH 15/28] cleanup of log warnings --- .../plugins/L1PrefiringWeightProducer.cc | 276 ++++++++---------- 1 file changed, 122 insertions(+), 154 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 2ae4d66590f2c..c7036e77ef218 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -97,6 +97,8 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const double prefiringRateSystUncMuon_; const double jetMaxMuonFraction_; const bool skipwarnings_; + bool missingInputEcal_; + bool missingInputMuon_; }; L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iConfig) @@ -122,34 +124,46 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC prefiringRateSystUncMuon_(iConfig.getParameter("PrefiringRateSystematicUnctyMuon")), jetMaxMuonFraction_(iConfig.getParameter("JetMaxMuonFraction")), skipwarnings_(iConfig.getUntrackedParameter("SkipWarnings")) { + missingInputEcal_ = false; + missingInputMuon_ = false; + std::string fname = iConfig.getParameter("L1Maps"); edm::FileInPath mapsfilepath("PhysicsTools/PatUtils/data/" + fname); file_prefiringmaps_ = std::make_unique(mapsfilepath.fullPath().c_str(), "read"); - if (file_prefiringmaps_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "File with maps not found. All prefiring weights set to 0. " << std::endl; - + if (file_prefiringmaps_ == nullptr) { + missingInputEcal_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "File with maps not found. All prefiring weights set to 0. " << std::endl; + } TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataeraEcal_; - if (!file_prefiringmaps_->Get(mapphotonfullname) && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + if (!file_prefiringmaps_->Get(mapphotonfullname)) { + missingInputEcal_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + } h_prefmap_photon_ = file_prefiringmaps_->Get(mapphotonfullname); - TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataeraEcal_ : "L1prefiring_jetptvseta_" + dataeraEcal_; - if (!file_prefiringmaps_->Get(mapjetfullname) && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + if (!file_prefiringmaps_->Get(mapjetfullname)) { + missingInputEcal_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + } h_prefmap_jet_ = file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); std::string fnameMuon = iConfig.getParameter("L1MuonParametrizations"); edm::FileInPath paramsfilepath("PhysicsTools/PatUtils/data/" + fnameMuon); file_prefiringparams_ = std::make_unique(paramsfilepath.fullPath().c_str(), "read"); - if (file_prefiringparams_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; - + if (file_prefiringparams_ == nullptr) { + missingInputMuon_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; + } TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; parametrization0p0To0p2_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_0.2To0.3_" + dataeraMuon_; @@ -172,9 +186,29 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC parametrization2p1To2p25_ = file_prefiringparams_->Get(paramName); paramName = "L1prefiring_muonparam_2.25To2.4_" + dataeraMuon_; parametrization2p25To2p4_ = file_prefiringparams_->Get(paramName); + + if (parametrization0p0To0p2_ == nullptr || parametrization0p2To0p3_ == nullptr || + parametrization0p3To0p55_ == nullptr || parametrization0p55To0p83_ == nullptr || + parametrization0p83To1p24_ == nullptr || parametrization1p24To1p4_ == nullptr || + parametrization1p4To1p6_ == nullptr || parametrization1p6To1p8_ == nullptr || + parametrization1p8To2p1_ == nullptr || parametrization2p1To2p25_ == nullptr || + parametrization2p25To2p4_ == nullptr) { + missingInputMuon_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "Muon parametrization not found for at least one bin. All prefiring weights set to 0." << std::endl; + } + paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_; parametrizationHotSpot_ = file_prefiringparams_->Get(paramName); file_prefiringparams_->Close(); + if ((dataeraMuon_.find("2016") != std::string::npos) && parametrizationHotSpot_ == nullptr) { + missingInputMuon_ = true; + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "Year is 2016 and no Muon parametrization is found for hot spot. All prefiring weights set to 0." + << std::endl; + } } L1PrefiringWeightProducer::~L1PrefiringWeightProducer() {} @@ -199,85 +233,89 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { - for (const auto& photon : thePhotons) { - double pt_gam = photon.pt(); - double eta_gam = photon.eta(); - if (pt_gam < 20.) - continue; - if (fabs(eta_gam) < 2.) - continue; - if (fabs(eta_gam) > 3.) - continue; - double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); - nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); - nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); - } - - //Now applying the prefiring maps to jets in the affected regions. - for (const auto& jet : theJets) { - double pt_jet = jet.pt(); - double eta_jet = jet.eta(); - double phi_jet = jet.phi(); - if (pt_jet < 20.) - continue; - if (fabs(eta_jet) < 2.) - continue; - if (fabs(eta_jet) > 3.) - continue; - if (jetMaxMuonFraction_ > 0 && jet.muonEnergyFraction() > jetMaxMuonFraction_) - continue; - //Loop over photons to remove overlap - double nonprefiringprobfromoverlappingphotons = 1.; - bool foundOverlappingPhotons = false; + if (!missingInputEcal_) { for (const auto& photon : thePhotons) { double pt_gam = photon.pt(); double eta_gam = photon.eta(); - double phi_gam = photon.phi(); if (pt_gam < 20.) continue; if (fabs(eta_gam) < 2.) continue; if (fabs(eta_gam) > 3.) continue; - double dR2 = reco::deltaR2(eta_jet, phi_jet, eta_gam, phi_gam); - if (dR2 > 0.16) - continue; double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); - nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam); - foundOverlappingPhotons = true; + nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); + nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); } - //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt. - if (useEMpt_) - pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction()); - double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct); - - if (!foundOverlappingPhotons) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; - nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; - } - //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one - else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { - if (nonprefiringprobfromoverlappingphotons <= 0.) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; - nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; - } else { - nonPrefiringProba[fluct] = 0.; - nonPrefiringProbaJet[fluct] = 0.; + + //Now applying the prefiring maps to jets in the affected regions. + for (const auto& jet : theJets) { + double pt_jet = jet.pt(); + double eta_jet = jet.eta(); + double phi_jet = jet.phi(); + if (pt_jet < 20.) + continue; + if (fabs(eta_jet) < 2.) + continue; + if (fabs(eta_jet) > 3.) + continue; + if (jetMaxMuonFraction_ > 0 && jet.muonEnergyFraction() > jetMaxMuonFraction_) + continue; + //Loop over photons to remove overlap + double nonprefiringprobfromoverlappingphotons = 1.; + bool foundOverlappingPhotons = false; + for (const auto& photon : thePhotons) { + double pt_gam = photon.pt(); + double eta_gam = photon.eta(); + double phi_gam = photon.phi(); + if (pt_gam < 20.) + continue; + if (fabs(eta_gam) < 2.) + continue; + if (fabs(eta_gam) > 3.) + continue; + double dR2 = reco::deltaR2(eta_jet, phi_jet, eta_gam, phi_gam); + if (dR2 > 0.16) + continue; + double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); + nonprefiringprobfromoverlappingphotons *= (1. - prefiringprob_gam); + foundOverlappingPhotons = true; + } + //useEMpt =true if one wants to use maps parametrized vs Jet EM pt instead of pt. + if (useEMpt_) + pt_jet *= (jet.neutralEmEnergyFraction() + jet.chargedEmEnergyFraction()); + double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct); + + if (!foundOverlappingPhotons) { + nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; + nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; } + //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one + else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { + if (nonprefiringprobfromoverlappingphotons > 0.) { + nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; + nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; + } else { + nonPrefiringProba[fluct] = 0.; + nonPrefiringProbaJet[fluct] = 0.; + } + } + //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. } - //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. } //Now calculate prefiring weights for muons - for (const auto& muon : theMuons) { - double pt = muon.pt(); - double phi = muon.phi(); - double eta = muon.eta(); - // Remove crappy tracker muons which would not have prefired the L1 trigger - if (pt < 5 && !muon.isStandAloneMuon()) - continue; - double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); - nonPrefiringProba[fluct] *= (1. - prefiringprob_mu); - nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); + if (!missingInputMuon_) { + for (const auto& muon : theMuons) { + double pt = muon.pt(); + double phi = muon.phi(); + double eta = muon.eta(); + // Remove crappy tracker muons which would not have prefired the L1 trigger + if (pt < 5 && !muon.isStandAloneMuon()) + continue; + double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); + nonPrefiringProba[fluct] *= (1. - prefiringprob_mu); + nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); + } } } //Move global prefire weights, as well as those for muons, photons, and jets, to the event @@ -302,10 +340,6 @@ double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, double pt, TH2F* h_prefmap, fluctuations fluctuation) const { - if (h_prefmap == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") << "Prefiring map not found, setting prefiring rate to 0 " << std::endl; - if (h_prefmap == nullptr) - return 0.; //Check pt is not above map overflow int nbinsy = h_prefmap->GetNbinsY(); double maxy = h_prefmap->GetYaxis()->GetBinLowEdge(nbinsy + 1); @@ -332,113 +366,47 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, double statuncty; if ((dataeraMuon_.find("2016") != std::string::npos) && (eta > 1.24 && eta < 1.6) && (phi > 2.44346 && phi < 2.79253)) { - if (parametrizationHotSpot_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << phi << std::endl; - if (parametrizationHotSpot_ == nullptr) - return 0.; prefrate = parametrizationHotSpot_->Eval(pt); statuncty = parametrizationHotSpot_->GetParError(2); } else if (std::abs(eta) < 0.2) { - if (parametrization0p0To0p2_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p0To0p2_ == nullptr) - return 0.; prefrate = parametrization0p0To0p2_->Eval(pt); statuncty = parametrization0p0To0p2_->GetParError(2); } else if (std::abs(eta) < 0.3) { - if (parametrization0p2To0p3_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p2To0p3_ == nullptr) - return 0.; - prefrate = parametrization0p2To0p3_->Eval(pt); statuncty = parametrization0p2To0p3_->GetParError(2); } else if (std::abs(eta) < 0.55) { - if (parametrization0p3To0p55_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p3To0p55_ == nullptr) - return 0.; - prefrate = parametrization0p3To0p55_->Eval(pt); statuncty = parametrization0p3To0p55_->GetParError(2); } else if (std::abs(eta) < 0.83) { - if (parametrization0p55To0p83_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p55To0p83_ == nullptr) - return 0.; - prefrate = parametrization0p55To0p83_->Eval(pt); statuncty = parametrization0p55To0p83_->GetParError(2); } else if (std::abs(eta) < 1.24) { - if (parametrization0p83To1p24_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization0p83To1p24_ == nullptr) - return 0.; - prefrate = parametrization0p83To1p24_->Eval(pt); statuncty = parametrization0p83To1p24_->GetParError(2); } else if (std::abs(eta) < 1.4) { - if (parametrization1p24To1p4_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p24To1p4_ == nullptr) - return 0.; - prefrate = parametrization1p24To1p4_->Eval(pt); statuncty = parametrization1p24To1p4_->GetParError(2); } else if (std::abs(eta) < 1.6) { - if (parametrization1p4To1p6_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p4To1p6_ == nullptr) - return 0.; - prefrate = parametrization1p4To1p6_->Eval(pt); statuncty = parametrization1p4To1p6_->GetParError(2); } else if (std::abs(eta) < 1.8) { - if (parametrization1p6To1p8_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p6To1p8_ == nullptr) - return 0.; - prefrate = parametrization1p6To1p8_->Eval(pt); statuncty = parametrization1p6To1p8_->GetParError(2); } else if (std::abs(eta) < 2.1) { - if (parametrization1p8To2p1_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization1p8To2p1_ == nullptr) - return 0.; - prefrate = parametrization1p8To2p1_->Eval(pt); statuncty = parametrization1p8To2p1_->GetParError(2); } else if (std::abs(eta) < 2.25) { - if (parametrization2p1To2p25_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization2p1To2p25_ == nullptr) - return 0.; - prefrate = parametrization2p1To2p25_->Eval(pt); statuncty = parametrization2p1To2p25_->GetParError(2); } else if (std::abs(eta) < 2.4) { - if (parametrization2p25To2p4_ == nullptr && !skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Prefiring parametrization not found, setting prefiring rate to 0 " << eta << " " << std::endl; - if (parametrization2p25To2p4_ == nullptr) - return 0.; - prefrate = parametrization2p25To2p4_->Eval(pt); statuncty = parametrization2p25To2p4_->GetParError(2); - } else + } else { + if (!skipwarnings_) + edm::LogWarning("L1PrefireWeightProducer") + << "Muon outside of |eta| <= 2.4. Prefiring weight set to 0." << std::endl; return 0.; + } double systuncty = prefiringRateSystUncMuon_ * prefrate; if (fluctuation == up) From 816db5d73b4c99babaf9a4e45f789873c1b387d8 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 24 May 2021 17:13:19 +0200 Subject: [PATCH 16/28] split muon uncertainty into syst. and stat. --- .../NanoAOD/python/triggerObjects_cff.py | 9 ++-- .../plugins/L1PrefiringWeightProducer.cc | 47 +++++++++++++++---- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index bc5811e1640d5..37740f74b45ce 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -239,17 +239,16 @@ L1PreFiringWeight_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "double", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), L1PreFiringWeight_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "double", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), L1PreFiringWeightMuon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightMuon_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightMuon_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightMuon_SystUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. syst.", precision=8), + L1PreFiringWeightMuon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), + L1PreFiringWeightMuon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), + L1PreFiringWeightMuon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), L1PreFiringWeightJet_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJet"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability)", precision=8), L1PreFiringWeightJet_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetUp"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), up var.", precision=8), L1PreFiringWeightJet_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetDown"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), down var.", precision=8), L1PreFiringWeightPhoton_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhoton"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability)", precision=8), L1PreFiringWeightPhoton_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonUp"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), up var.", precision=8), L1PreFiringWeightPhoton_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonDown"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), down var.", precision=8), - - - ) ) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index c7036e77ef218..159f4732951d9 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -37,7 +37,7 @@ #include "TH2.h" #include -enum fluctuations { central = 0, up, down }; +enum fluctuations { central = 0, up, down, upStat, downStat, upSyst, downSyst }; class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { public: @@ -69,8 +69,10 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; const edm::EDPutTokenT nonPrefiringProbMuonToken_; - const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; - const edm::EDPutTokenT nonPrefiringProbMuonDownToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpSystToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownSystToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpStatToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownStatToken_; std::unique_ptr file_prefiringmaps_; std::unique_ptr file_prefiringparams_; @@ -115,8 +117,10 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), - nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), - nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), + nonPrefiringProbMuonUpSystToken_(produces("nonPrefiringProbMuonSystUp")), + nonPrefiringProbMuonDownSystToken_(produces("nonPrefiringProbMuonSystDown")), + nonPrefiringProbMuonUpStatToken_(produces("nonPrefiringProbMuonStatUp")), + nonPrefiringProbMuonDownStatToken_(produces("nonPrefiringProbMuonStatDown")), dataeraEcal_(iConfig.getParameter("DataEraECAL")), dataeraMuon_(iConfig.getParameter("DataEraMuon")), useEMpt_(iConfig.getParameter("UseJetEMPt")), @@ -230,7 +234,8 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaPhoton[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaMuon[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaMuon[7] = { + 1., 1., 1., 1., 1., 1., 1.}; //0: central, 1: up, 2: down, 3: up syst, 4: down syst, 5: up stat, 6: down stat for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { if (!missingInputEcal_) { @@ -318,6 +323,21 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu } } } + for (const auto fluct : + {fluctuations::upSyst, fluctuations::downSyst, fluctuations::upStat, fluctuations::downStat}) { + if (!missingInputMuon_) { + for (const auto& muon : theMuons) { + double pt = muon.pt(); + double phi = muon.phi(); + double eta = muon.eta(); + // Remove crappy tracker muons which would not have prefired the L1 trigger + if (pt < 5 && !muon.isStandAloneMuon()) + continue; + double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); + nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); + } + } + } //Move global prefire weights, as well as those for muons, photons, and jets, to the event iEvent.emplace(nonPrefiringProbToken_, nonPrefiringProba[0]); iEvent.emplace(nonPrefiringProbUpToken_, nonPrefiringProba[1]); @@ -332,8 +352,10 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu iEvent.emplace(nonPrefiringProbPhotonDownToken_, nonPrefiringProbaPhoton[2]); iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]); - iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]); - iEvent.emplace(nonPrefiringProbMuonDownToken_, nonPrefiringProbaMuon[2]); + iEvent.emplace(nonPrefiringProbMuonUpSystToken_, nonPrefiringProbaMuon[3]); + iEvent.emplace(nonPrefiringProbMuonDownSystToken_, nonPrefiringProbaMuon[4]); + iEvent.emplace(nonPrefiringProbMuonUpStatToken_, nonPrefiringProbaMuon[5]); + iEvent.emplace(nonPrefiringProbMuonDownStatToken_, nonPrefiringProbaMuon[6]); } double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, @@ -413,6 +435,15 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); + else if (fluctuation == upSyst) + prefrate = std::max(0., prefrate + systuncty); + else if (fluctuation == downSyst) + prefrate = std::max(0., prefrate - systuncty); + else if (fluctuation == upStat) + prefrate = std::max(0., prefrate + statuncty); + else if (fluctuation == downStat) + prefrate = std::max(0., prefrate - statuncty); + return prefrate; } From eb958e240b5e27947a45a6c00bde6e9eed12719a Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 24 May 2021 17:17:49 +0200 Subject: [PATCH 17/28] fix maximum weight conditions --- PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 159f4732951d9..ca10b5717716e 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -436,11 +436,11 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); else if (fluctuation == upSyst) - prefrate = std::max(0., prefrate + systuncty); + prefrate = std::min(1., prefrate + systuncty); else if (fluctuation == downSyst) prefrate = std::max(0., prefrate - systuncty); else if (fluctuation == upStat) - prefrate = std::max(0., prefrate + statuncty); + prefrate = std::min(1., prefrate + statuncty); else if (fluctuation == downStat) prefrate = std::max(0., prefrate - statuncty); From f93973f8b22029aac2c634002ab5e57ef6a387f0 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 24 May 2021 19:39:00 +0200 Subject: [PATCH 18/28] new round of comments --- .../plugins/L1PrefiringWeightProducer.cc | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index ca10b5717716e..ea4ea3d5f079a 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -69,6 +69,8 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; const edm::EDPutTokenT nonPrefiringProbMuonToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownToken_; const edm::EDPutTokenT nonPrefiringProbMuonUpSystToken_; const edm::EDPutTokenT nonPrefiringProbMuonDownSystToken_; const edm::EDPutTokenT nonPrefiringProbMuonUpStatToken_; @@ -98,7 +100,6 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const double prefiringRateSystUncEcal_; const double prefiringRateSystUncMuon_; const double jetMaxMuonFraction_; - const bool skipwarnings_; bool missingInputEcal_; bool missingInputMuon_; }; @@ -117,6 +118,8 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), + nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), + nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), nonPrefiringProbMuonUpSystToken_(produces("nonPrefiringProbMuonSystUp")), nonPrefiringProbMuonDownSystToken_(produces("nonPrefiringProbMuonSystDown")), nonPrefiringProbMuonUpStatToken_(produces("nonPrefiringProbMuonStatUp")), @@ -126,8 +129,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC useEMpt_(iConfig.getParameter("UseJetEMPt")), prefiringRateSystUncEcal_(iConfig.getParameter("PrefiringRateSystematicUnctyECAL")), prefiringRateSystUncMuon_(iConfig.getParameter("PrefiringRateSystematicUnctyMuon")), - jetMaxMuonFraction_(iConfig.getParameter("JetMaxMuonFraction")), - skipwarnings_(iConfig.getUntrackedParameter("SkipWarnings")) { + jetMaxMuonFraction_(iConfig.getParameter("JetMaxMuonFraction")) { missingInputEcal_ = false; missingInputMuon_ = false; @@ -136,25 +138,22 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC file_prefiringmaps_ = std::make_unique(mapsfilepath.fullPath().c_str(), "read"); if (file_prefiringmaps_ == nullptr) { missingInputEcal_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "File with maps not found. All prefiring weights set to 0. " << std::endl; + edm::LogError("L1PrefireWeightProducer") + << "File with maps not found. All prefiring weights set to 0. " << std::endl; } TString mapphotonfullname = "L1prefiring_photonptvseta_" + dataeraEcal_; if (!file_prefiringmaps_->Get(mapphotonfullname)) { missingInputEcal_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; + edm::LogError("L1PrefireWeightProducer") + << "Photon map not found. All photons prefiring weights set to 0. " << std::endl; } h_prefmap_photon_ = file_prefiringmaps_->Get(mapphotonfullname); TString mapjetfullname = (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataeraEcal_ : "L1prefiring_jetptvseta_" + dataeraEcal_; if (!file_prefiringmaps_->Get(mapjetfullname)) { missingInputEcal_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; } h_prefmap_jet_ = file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); @@ -164,9 +163,8 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC file_prefiringparams_ = std::make_unique(paramsfilepath.fullPath().c_str(), "read"); if (file_prefiringparams_ == nullptr) { missingInputMuon_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; + edm::LogWarning("L1PrefireWeightProducer") + << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; } TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; parametrization0p0To0p2_ = file_prefiringparams_->Get(paramName); @@ -198,9 +196,8 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC parametrization1p8To2p1_ == nullptr || parametrization2p1To2p25_ == nullptr || parametrization2p25To2p4_ == nullptr) { missingInputMuon_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Muon parametrization not found for at least one bin. All prefiring weights set to 0." << std::endl; + edm::LogError("L1PrefireWeightProducer") + << "Muon parametrization not found for at least one bin. All prefiring weights set to 0." << std::endl; } paramName = "L1prefiring_muonparam_HotSpot_" + dataeraMuon_; @@ -208,10 +205,9 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC file_prefiringparams_->Close(); if ((dataeraMuon_.find("2016") != std::string::npos) && parametrizationHotSpot_ == nullptr) { missingInputMuon_ = true; - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Year is 2016 and no Muon parametrization is found for hot spot. All prefiring weights set to 0." - << std::endl; + edm::LogError("L1PrefireWeightProducer") + << "Year is 2016 and no Muon parametrization is found for hot spot. All prefiring weights set to 0." + << std::endl; } } @@ -249,7 +245,6 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu if (fabs(eta_gam) > 3.) continue; double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); - nonPrefiringProba[fluct] *= (1. - prefiringprob_gam); nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); } @@ -292,16 +287,13 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct); if (!foundOverlappingPhotons) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet; nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; } //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { if (nonprefiringprobfromoverlappingphotons > 0.) { - nonPrefiringProba[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; } else { - nonPrefiringProba[fluct] = 0.; nonPrefiringProbaJet[fluct] = 0.; } } @@ -318,11 +310,16 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu if (pt < 5 && !muon.isStandAloneMuon()) continue; double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); - nonPrefiringProba[fluct] *= (1. - prefiringprob_mu); nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); } } } + // Calculate combined weight as product of the weight for individual objects + for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { + nonPrefiringProba[fluct] = + nonPrefiringProbaPhoton[fluct] * nonPrefiringProbaJet[fluct] * nonPrefiringProbaMuon[fluct]; + } + // Calculate statistical and systematic uncertainty separately in the muon case for (const auto fluct : {fluctuations::upSyst, fluctuations::downSyst, fluctuations::upStat, fluctuations::downStat}) { if (!missingInputMuon_) { @@ -352,6 +349,8 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu iEvent.emplace(nonPrefiringProbPhotonDownToken_, nonPrefiringProbaPhoton[2]); iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]); + iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]); + iEvent.emplace(nonPrefiringProbMuonDownToken_, nonPrefiringProbaMuon[2]); iEvent.emplace(nonPrefiringProbMuonUpSystToken_, nonPrefiringProbaMuon[3]); iEvent.emplace(nonPrefiringProbMuonDownSystToken_, nonPrefiringProbaMuon[4]); iEvent.emplace(nonPrefiringProbMuonUpStatToken_, nonPrefiringProbaMuon[5]); @@ -378,8 +377,9 @@ double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - return prefrate; + return std::min(1., prefrate); } + double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, double phi, double pt, @@ -424,9 +424,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, prefrate = parametrization2p25To2p4_->Eval(pt); statuncty = parametrization2p25To2p4_->GetParError(2); } else { - if (!skipwarnings_) - edm::LogWarning("L1PrefireWeightProducer") - << "Muon outside of |eta| <= 2.4. Prefiring weight set to 0." << std::endl; + LogDebug("L1PrefireWeightProducer") << "Muon outside of |eta| <= 2.4. Prefiring weight set to 0." << std::endl; return 0.; } double systuncty = prefiringRateSystUncMuon_ * prefrate; @@ -444,7 +442,7 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, else if (fluctuation == downStat) prefrate = std::max(0., prefrate - statuncty); - return prefrate; + return std::min(1., prefrate); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ @@ -461,7 +459,6 @@ void L1PrefiringWeightProducer::fillDescriptions(edm::ConfigurationDescriptions& desc.add("PrefiringRateSystematicUnctyECAL", 0.2); desc.add("PrefiringRateSystematicUnctyMuon", 0.2); desc.add("JetMaxMuonFraction", 0.5); - desc.addUntracked("SkipWarnings", true); descriptions.add("l1PrefiringWeightProducer", desc); } From 7a450d275d0b676657809d1a1df507a8823ba19a Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Mon, 24 May 2021 20:37:02 +0200 Subject: [PATCH 19/28] add logwarning for weights > 1 --- .../plugins/L1PrefiringWeightProducer.cc | 17 ++++++++++++----- .../python/L1PrefiringWeightProducer_cff.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index ea4ea3d5f079a..fb6979e73abd2 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -152,8 +152,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC (useEMpt_) ? "L1prefiring_jetemptvseta_" + dataeraEcal_ : "L1prefiring_jetptvseta_" + dataeraEcal_; if (!file_prefiringmaps_->Get(mapjetfullname)) { missingInputEcal_ = true; - edm::LogWarning("L1PrefireWeightProducer") - << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; + edm::LogError("L1PrefireWeightProducer") << "Jet map not found. All jets prefiring weights set to 0. " << std::endl; } h_prefmap_jet_ = file_prefiringmaps_->Get(mapjetfullname); file_prefiringmaps_->Close(); @@ -163,7 +162,7 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC file_prefiringparams_ = std::make_unique(paramsfilepath.fullPath().c_str(), "read"); if (file_prefiringparams_ == nullptr) { missingInputMuon_ = true; - edm::LogWarning("L1PrefireWeightProducer") + edm::LogError("L1PrefireWeightProducer") << "File with muon parametrizations not found. All prefiring weights set to 0." << std::endl; } TString paramName = "L1prefiring_muonparam_0.0To0.2_" + dataeraMuon_; @@ -377,7 +376,11 @@ double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, prefrate = std::min(1., prefrate + sqrt(pow(statuncty, 2) + pow(systuncty, 2))); else if (fluctuation == down) prefrate = std::max(0., prefrate - sqrt(pow(statuncty, 2) + pow(systuncty, 2))); - return std::min(1., prefrate); + if (prefrate > 1.) { + edm::LogWarning("L1PrefireWeightProducer") << "Found a prefiring probability > 1. Setting to 1." << std::endl; + return 1.; + } + return prefrate; } double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, @@ -442,7 +445,11 @@ double L1PrefiringWeightProducer::getPrefiringRateMuon(double eta, else if (fluctuation == downStat) prefrate = std::max(0., prefrate - statuncty); - return std::min(1., prefrate); + if (prefrate > 1.) { + edm::LogWarning("L1PrefireWeightProducer") << "Found a prefiring probability > 1. Setting to 1." << std::endl; + return 1.; + } + return prefrate; } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ diff --git a/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py b/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py index 47737b19a9d31..cb9ad47b5bcab 100644 --- a/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py +++ b/PhysicsTools/PatUtils/python/L1PrefiringWeightProducer_cff.py @@ -2,5 +2,5 @@ from PhysicsTools.PatUtils.l1PrefiringWeightProducer_cfi import l1PrefiringWeightProducer -prefiringweight = l1PrefiringWeightProducer.clone(SkipWarnings = False) +prefiringweight = l1PrefiringWeightProducer.clone() From 5484ca6855e6e31375ff98e10849bca6ca525aee Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 1 Jun 2021 17:59:56 +0200 Subject: [PATCH 20/28] update to 2016 UL prefiring maps for ECAL --- PhysicsTools/NanoAOD/python/triggerObjects_cff.py | 4 ++-- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 37740f74b45ce..588c776fc200a 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -218,8 +218,8 @@ from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight #Next line will be updated once we get UL2016 maps -(run2_muon_2016 & tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016preVFP")) -(run2_muon_2016 & ~tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("2016BtoH"), DataEraMuon = cms.string("2016postVFP")) +(run2_muon_2016 & tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("UL2016preVFP"), DataEraMuon = cms.string("2016preVFP")) +(run2_muon_2016 & ~tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("UL2016postVFP"), DataEraMuon = cms.string("2016postVFP")) #Next line is for UL2017 maps run2_jme_2017.toModify( prefiringweight, DataEraECAL = cms.string("UL2017BtoF"), DataEraMuon = cms.string("20172018")) #Next line is for UL2018 maps diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 2511a7d2cb0dd..7bf7cf784aed8 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -544,9 +544,9 @@ def _add_deepMET(process): from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018 from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016 process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") - (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016preVFP" ) - (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "2016BtoH", DataEraMuon = "2016postVFP" ) - stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "2017BtoF", DataEraMuon = "20172018") + (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" ) + (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" ) + stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018") stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight)) From fd1d685b8e53258db57f016b1db4ae14a09aa0c8 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Wed, 2 Jun 2021 14:23:04 +0200 Subject: [PATCH 21/28] fix swapped stat and syst uncertainties --- .../PatUtils/plugins/L1PrefiringWeightProducer.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index fb6979e73abd2..4b048146b7301 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -230,7 +230,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaPhoton[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaMuon[7] = { - 1., 1., 1., 1., 1., 1., 1.}; //0: central, 1: up, 2: down, 3: up syst, 4: down syst, 5: up stat, 6: down stat + 1., 1., 1., 1., 1., 1., 1.}; //0: central, 1: up, 2: down, 3: up stat, 4: down stat, 5: up syst, 6: down syst for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { if (!missingInputEcal_) { @@ -350,10 +350,10 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]); iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]); iEvent.emplace(nonPrefiringProbMuonDownToken_, nonPrefiringProbaMuon[2]); - iEvent.emplace(nonPrefiringProbMuonUpSystToken_, nonPrefiringProbaMuon[3]); - iEvent.emplace(nonPrefiringProbMuonDownSystToken_, nonPrefiringProbaMuon[4]); - iEvent.emplace(nonPrefiringProbMuonUpStatToken_, nonPrefiringProbaMuon[5]); - iEvent.emplace(nonPrefiringProbMuonDownStatToken_, nonPrefiringProbaMuon[6]); + iEvent.emplace(nonPrefiringProbMuonUpStatToken_, nonPrefiringProbaMuon[3]); + iEvent.emplace(nonPrefiringProbMuonDownStatToken_, nonPrefiringProbaMuon[4]); + iEvent.emplace(nonPrefiringProbMuonUpSystToken_, nonPrefiringProbaMuon[5]); + iEvent.emplace(nonPrefiringProbMuonDownSystToken_, nonPrefiringProbaMuon[6]); } double L1PrefiringWeightProducer::getPrefiringRateEcal(double eta, From fb3a0b3d6d82385f058f362a127b88aa37479ee1 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Wed, 2 Jun 2021 19:42:22 +0200 Subject: [PATCH 22/28] add prefiring weights to Nano DQM --- PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 12 ++++++++ .../NanoAOD/python/triggerObjects_cff.py | 29 ++++++++++--------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index ee2867025e2d6..41e19a93dce7c 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -809,5 +809,17 @@ Plot1D('rawMVAoldDMdR032017v2', 'rawMVAoldDMdR032017v2', 20, -1, 1, 'byIsolationMVArun2017v2DBoldDMdR0p3wLT raw output discriminator (2017v2)'), ) ), + L1PreFiringWeight = cms.PSet( + sels = cms.PSet(), + plots = cms.VPSet( + Plot1D('L1PreFiringWeight_Nom', 'L1PreFiringWeight_Nom', 20, 0.8, 1.0, 'L1 prefiring weight nominal'), + Plot1D('L1PreFiringWeight_Up', 'L1PreFiringWeight_Up', 20, 0.8, 1.0, 'L1 prefiring weight uncertainy up'), + Plot1D('L1PreFiringWeight_Dn', 'L1PreFiringWeight_Dn', 20, 0.8, 1.0, 'L1 prefiring weight uncertainty down'), + Plot1D('L1PreFiringWeightJet_Nom', 'L1PreFiringWeightJet_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for jets nominal'), + Plot1D('L1PreFiringWeightPhoton_Nom', 'L1PreFiringWeightPhoton_Nom', 20, 0.8, 1.0, 'L1 prefiring for photons weight nominal'), + Plot1D('L1PreFiringWeightMuon_Nom', 'L1PreFiringWeightMuon_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for muons nominal'), + ) + + ), ) ) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 588c776fc200a..c0e1cada83535 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -234,21 +234,22 @@ run2_nanoAOD_94X2016.toModify( prefiringweight, JetMaxMuonFraction = cms.double(-1.) ) l1PreFiringEventWeightTable = cms.EDProducer("GlobalVariablesTableProducer", + name = cms.string("L1PreFiringWeight"), variables = cms.PSet( - L1PreFiringWeight_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProb"), "double", doc = "L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeight_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "double", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeight_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "double", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), - L1PreFiringWeightMuon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightMuon_SystUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. syst.", precision=8), - L1PreFiringWeightMuon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), - L1PreFiringWeightMuon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), - L1PreFiringWeightMuon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "double", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), - L1PreFiringWeightJet_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJet"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightJet_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetUp"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightJet_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetDown"), "double", doc = "Jet L1 pre-firing event correction weight (1-probability), down var.", precision=8), - L1PreFiringWeightPhoton_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhoton"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightPhoton_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonUp"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightPhoton_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonDown"), "double", doc = "Photon L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeight_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProb"), "float", doc = "L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeight_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "float", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeight_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "float", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightMuon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightMuon_SystUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. syst.", precision=8), + L1PreFiringWeightMuon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), + L1PreFiringWeightMuon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), + L1PreFiringWeightMuon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), + L1PreFiringWeightJet_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJet"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightJet_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetUp"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightJet_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetDown"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightPhoton_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhoton"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightPhoton_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonUp"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightPhoton_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonDown"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability), down var.", precision=8), ) ) From d74deb98d9d7d88ea41e28fdde0af83c401cacfe Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Thu, 3 Jun 2021 17:26:58 +0200 Subject: [PATCH 23/28] make prefirng weights floats --- .../plugins/L1PrefiringWeightProducer.cc | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 4b048146b7301..54f739a62253b 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -56,25 +56,25 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const edm::EDGetTokenT > jets_token_; const edm::EDGetTokenT > muon_token_; - const edm::EDPutTokenT nonPrefiringProbToken_; - const edm::EDPutTokenT nonPrefiringProbUpToken_; - const edm::EDPutTokenT nonPrefiringProbDownToken_; - - const edm::EDPutTokenT nonPrefiringProbJetToken_; - const edm::EDPutTokenT nonPrefiringProbJetUpToken_; - const edm::EDPutTokenT nonPrefiringProbJetDownToken_; - - const edm::EDPutTokenT nonPrefiringProbPhotonToken_; - const edm::EDPutTokenT nonPrefiringProbPhotonUpToken_; - const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; - - const edm::EDPutTokenT nonPrefiringProbMuonToken_; - const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; - const edm::EDPutTokenT nonPrefiringProbMuonDownToken_; - const edm::EDPutTokenT nonPrefiringProbMuonUpSystToken_; - const edm::EDPutTokenT nonPrefiringProbMuonDownSystToken_; - const edm::EDPutTokenT nonPrefiringProbMuonUpStatToken_; - const edm::EDPutTokenT nonPrefiringProbMuonDownStatToken_; + const edm::EDPutTokenT nonPrefiringProbToken_; + const edm::EDPutTokenT nonPrefiringProbUpToken_; + const edm::EDPutTokenT nonPrefiringProbDownToken_; + + const edm::EDPutTokenT nonPrefiringProbJetToken_; + const edm::EDPutTokenT nonPrefiringProbJetUpToken_; + const edm::EDPutTokenT nonPrefiringProbJetDownToken_; + + const edm::EDPutTokenT nonPrefiringProbPhotonToken_; + const edm::EDPutTokenT nonPrefiringProbPhotonUpToken_; + const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; + + const edm::EDPutTokenT nonPrefiringProbMuonToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpSystToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownSystToken_; + const edm::EDPutTokenT nonPrefiringProbMuonUpStatToken_; + const edm::EDPutTokenT nonPrefiringProbMuonDownStatToken_; std::unique_ptr file_prefiringmaps_; std::unique_ptr file_prefiringparams_; @@ -108,22 +108,22 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC : photons_token_(consumes >(iConfig.getParameter("ThePhotons"))), jets_token_(consumes >(iConfig.getParameter("TheJets"))), muon_token_(consumes >(iConfig.getParameter("TheMuons"))), - nonPrefiringProbToken_(produces("nonPrefiringProb")), - nonPrefiringProbUpToken_(produces("nonPrefiringProbUp")), - nonPrefiringProbDownToken_(produces("nonPrefiringProbDown")), - nonPrefiringProbJetToken_(produces("nonPrefiringProbJet")), - nonPrefiringProbJetUpToken_(produces("nonPrefiringProbJetUp")), - nonPrefiringProbJetDownToken_(produces("nonPrefiringProbJetDown")), - nonPrefiringProbPhotonToken_(produces("nonPrefiringProbPhoton")), - nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), - nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), - nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), - nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), - nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), - nonPrefiringProbMuonUpSystToken_(produces("nonPrefiringProbMuonSystUp")), - nonPrefiringProbMuonDownSystToken_(produces("nonPrefiringProbMuonSystDown")), - nonPrefiringProbMuonUpStatToken_(produces("nonPrefiringProbMuonStatUp")), - nonPrefiringProbMuonDownStatToken_(produces("nonPrefiringProbMuonStatDown")), + nonPrefiringProbToken_(produces("nonPrefiringProb")), + nonPrefiringProbUpToken_(produces("nonPrefiringProbUp")), + nonPrefiringProbDownToken_(produces("nonPrefiringProbDown")), + nonPrefiringProbJetToken_(produces("nonPrefiringProbJet")), + nonPrefiringProbJetUpToken_(produces("nonPrefiringProbJetUp")), + nonPrefiringProbJetDownToken_(produces("nonPrefiringProbJetDown")), + nonPrefiringProbPhotonToken_(produces("nonPrefiringProbPhoton")), + nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), + nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), + nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), + nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), + nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), + nonPrefiringProbMuonUpSystToken_(produces("nonPrefiringProbMuonSystUp")), + nonPrefiringProbMuonDownSystToken_(produces("nonPrefiringProbMuonSystDown")), + nonPrefiringProbMuonUpStatToken_(produces("nonPrefiringProbMuonStatUp")), + nonPrefiringProbMuonDownStatToken_(produces("nonPrefiringProbMuonStatDown")), dataeraEcal_(iConfig.getParameter("DataEraECAL")), dataeraMuon_(iConfig.getParameter("DataEraMuon")), useEMpt_(iConfig.getParameter("UseJetEMPt")), From 03de4ace0c30445fa57270253e37b748852528e7 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 4 Jun 2021 16:29:42 +0200 Subject: [PATCH 24/28] corect eras for miniAOD --- PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py | 6 +++--- PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py index 7bf7cf784aed8..80614e2c9d1e2 100644 --- a/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py +++ b/PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py @@ -539,13 +539,13 @@ def _add_deepMET(process): # L1 pre-firing weights for 2016, 2017, and 2018 from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring - from Configuration.Eras.Modifier_stage1L1Trigger_cff import stage1L1Trigger + from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger from Configuration.Eras.Modifier_stage2L1Trigger_2017_cff import stage2L1Trigger_2017 from Configuration.Eras.Modifier_stage2L1Trigger_2018_cff import stage2L1Trigger_2018 from Configuration.Eras.Modifier_tracker_apv_vfp30_2016_cff import tracker_apv_vfp30_2016 process.load("PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff") - (stage1L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" ) - (stage1L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" ) + (stage2L1Trigger & tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016preVFP", DataEraMuon = "2016preVFP" ) + (stage2L1Trigger & ~tracker_apv_vfp30_2016).toModify(process.prefiringweight, DataEraECAL = "UL2016postVFP", DataEraMuon = "2016postVFP" ) stage2L1Trigger_2017.toModify(process.prefiringweight, DataEraECAL = "UL2017BtoF", DataEraMuon = "20172018") stage2L1Trigger_2018.toModify(process.prefiringweight, DataEraECAL = "None", DataEraMuon = "20172018") run2_L1prefiring.toModify(task, func=lambda t: t.add(process.prefiringweight)) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 54f739a62253b..3e14e38d900b4 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -292,6 +292,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { if (nonprefiringprobfromoverlappingphotons > 0.) { nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; + nonPrefiringProbaPhoton[fluct] *= 1 / nonprefiringprobfromoverlappingphotons; } else { nonPrefiringProbaJet[fluct] = 0.; } @@ -306,7 +307,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double phi = muon.phi(); double eta = muon.eta(); // Remove crappy tracker muons which would not have prefired the L1 trigger - if (pt < 5 && !muon.isStandAloneMuon()) + if (pt < 5 || !muon.isLooseMuon()) continue; double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); @@ -327,7 +328,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double phi = muon.phi(); double eta = muon.eta(); // Remove crappy tracker muons which would not have prefired the L1 trigger - if (pt < 5 && !muon.isStandAloneMuon()) + if (pt < 5 || !muon.isLooseMuon()) continue; double prefiringprob_mu = getPrefiringRateMuon(eta, phi, pt, fluct); nonPrefiringProbaMuon[fluct] *= (1. - prefiringprob_mu); From cb4759e1c23d692cf5982184d3d2b3a87acee709 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 4 Jun 2021 22:28:09 +0200 Subject: [PATCH 25/28] bug fix plus merge of photon and jet weights --- PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 3 +- .../NanoAOD/python/triggerObjects_cff.py | 9 ++-- .../plugins/L1PrefiringWeightProducer.cc | 43 +++++++------------ 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index 41e19a93dce7c..b0914352494d2 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -815,8 +815,7 @@ Plot1D('L1PreFiringWeight_Nom', 'L1PreFiringWeight_Nom', 20, 0.8, 1.0, 'L1 prefiring weight nominal'), Plot1D('L1PreFiringWeight_Up', 'L1PreFiringWeight_Up', 20, 0.8, 1.0, 'L1 prefiring weight uncertainy up'), Plot1D('L1PreFiringWeight_Dn', 'L1PreFiringWeight_Dn', 20, 0.8, 1.0, 'L1 prefiring weight uncertainty down'), - Plot1D('L1PreFiringWeightJet_Nom', 'L1PreFiringWeightJet_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for jets nominal'), - Plot1D('L1PreFiringWeightPhoton_Nom', 'L1PreFiringWeightPhoton_Nom', 20, 0.8, 1.0, 'L1 prefiring for photons weight nominal'), + Plot1D('L1PreFiringWeightECAL_Nom', 'L1PreFiringWeightECAL_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for ECAL objects nominal'), Plot1D('L1PreFiringWeightMuon_Nom', 'L1PreFiringWeightMuon_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for muons nominal'), ) diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index c0e1cada83535..6c11b5509b6ae 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -244,12 +244,9 @@ L1PreFiringWeightMuon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), L1PreFiringWeightMuon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), L1PreFiringWeightMuon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), - L1PreFiringWeightJet_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJet"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightJet_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetUp"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightJet_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbJetDown"), "float", doc = "Jet L1 pre-firing event correction weight (1-probability), down var.", precision=8), - L1PreFiringWeightPhoton_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhoton"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightPhoton_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonUp"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightPhoton_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbPhotonDown"), "float", doc = "Photon L1 pre-firing event correction weight (1-probability), down var.", precision=8), + L1PreFiringWeightECAL_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECAL"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability)", precision=8), + L1PreFiringWeightECAL_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALUp"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), up var.", precision=8), + L1PreFiringWeightECAL_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALDown"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), down var.", precision=8), ) ) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 3e14e38d900b4..027814dc0c7d1 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -60,13 +60,9 @@ class L1PrefiringWeightProducer : public edm::stream::EDProducer<> { const edm::EDPutTokenT nonPrefiringProbUpToken_; const edm::EDPutTokenT nonPrefiringProbDownToken_; - const edm::EDPutTokenT nonPrefiringProbJetToken_; - const edm::EDPutTokenT nonPrefiringProbJetUpToken_; - const edm::EDPutTokenT nonPrefiringProbJetDownToken_; - - const edm::EDPutTokenT nonPrefiringProbPhotonToken_; - const edm::EDPutTokenT nonPrefiringProbPhotonUpToken_; - const edm::EDPutTokenT nonPrefiringProbPhotonDownToken_; + const edm::EDPutTokenT nonPrefiringProbECALToken_; + const edm::EDPutTokenT nonPrefiringProbECALUpToken_; + const edm::EDPutTokenT nonPrefiringProbECALDownToken_; const edm::EDPutTokenT nonPrefiringProbMuonToken_; const edm::EDPutTokenT nonPrefiringProbMuonUpToken_; @@ -111,12 +107,9 @@ L1PrefiringWeightProducer::L1PrefiringWeightProducer(const edm::ParameterSet& iC nonPrefiringProbToken_(produces("nonPrefiringProb")), nonPrefiringProbUpToken_(produces("nonPrefiringProbUp")), nonPrefiringProbDownToken_(produces("nonPrefiringProbDown")), - nonPrefiringProbJetToken_(produces("nonPrefiringProbJet")), - nonPrefiringProbJetUpToken_(produces("nonPrefiringProbJetUp")), - nonPrefiringProbJetDownToken_(produces("nonPrefiringProbJetDown")), - nonPrefiringProbPhotonToken_(produces("nonPrefiringProbPhoton")), - nonPrefiringProbPhotonUpToken_(produces("nonPrefiringProbPhotonUp")), - nonPrefiringProbPhotonDownToken_(produces("nonPrefiringProbPhotonDown")), + nonPrefiringProbECALToken_(produces("nonPrefiringProbECAL")), + nonPrefiringProbECALUpToken_(produces("nonPrefiringProbECALUp")), + nonPrefiringProbECALDownToken_(produces("nonPrefiringProbECALDown")), nonPrefiringProbMuonToken_(produces("nonPrefiringProbMuon")), nonPrefiringProbMuonUpToken_(produces("nonPrefiringProbMuonUp")), nonPrefiringProbMuonDownToken_(produces("nonPrefiringProbMuonDown")), @@ -227,8 +220,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu //Probability for the event NOT to prefire, computed with the prefiring maps per object. //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaJet[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaPhoton[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaECAL[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaMuon[7] = { 1., 1., 1., 1., 1., 1., 1.}; //0: central, 1: up, 2: down, 3: up stat, 4: down stat, 5: up syst, 6: down syst @@ -244,7 +236,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu if (fabs(eta_gam) > 3.) continue; double prefiringprob_gam = getPrefiringRateEcal(eta_gam, pt_gam, h_prefmap_photon_, fluct); - nonPrefiringProbaPhoton[fluct] *= (1. - prefiringprob_gam); + nonPrefiringProbaECAL[fluct] *= (1. - prefiringprob_gam); } //Now applying the prefiring maps to jets in the affected regions. @@ -286,15 +278,14 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu double nonprefiringprobfromoverlappingjet = 1. - getPrefiringRateEcal(eta_jet, pt_jet, h_prefmap_jet_, fluct); if (!foundOverlappingPhotons) { - nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet; + nonPrefiringProbaECAL[fluct] *= nonprefiringprobfromoverlappingjet; } //If overlapping photons have a non prefiring rate larger than the jet, then replace these weights by the jet one else if (nonprefiringprobfromoverlappingphotons > nonprefiringprobfromoverlappingjet) { if (nonprefiringprobfromoverlappingphotons > 0.) { - nonPrefiringProbaJet[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; - nonPrefiringProbaPhoton[fluct] *= 1 / nonprefiringprobfromoverlappingphotons; + nonPrefiringProbaECAL[fluct] *= nonprefiringprobfromoverlappingjet / nonprefiringprobfromoverlappingphotons; } else { - nonPrefiringProbaJet[fluct] = 0.; + nonPrefiringProbaECAL[fluct] = 0.; } } //Last case: if overlapping photons have a non prefiring rate smaller than the jet, don't consider the jet in the event weight, and do nothing. @@ -317,7 +308,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu // Calculate combined weight as product of the weight for individual objects for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { nonPrefiringProba[fluct] = - nonPrefiringProbaPhoton[fluct] * nonPrefiringProbaJet[fluct] * nonPrefiringProbaMuon[fluct]; + nonPrefiringProbaECAL[fluct] * nonPrefiringProbaMuon[fluct]; } // Calculate statistical and systematic uncertainty separately in the muon case for (const auto fluct : @@ -340,13 +331,9 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu iEvent.emplace(nonPrefiringProbUpToken_, nonPrefiringProba[1]); iEvent.emplace(nonPrefiringProbDownToken_, nonPrefiringProba[2]); - iEvent.emplace(nonPrefiringProbJetToken_, nonPrefiringProbaJet[0]); - iEvent.emplace(nonPrefiringProbJetUpToken_, nonPrefiringProbaJet[1]); - iEvent.emplace(nonPrefiringProbJetDownToken_, nonPrefiringProbaJet[2]); - - iEvent.emplace(nonPrefiringProbPhotonToken_, nonPrefiringProbaPhoton[0]); - iEvent.emplace(nonPrefiringProbPhotonUpToken_, nonPrefiringProbaPhoton[1]); - iEvent.emplace(nonPrefiringProbPhotonDownToken_, nonPrefiringProbaPhoton[2]); + iEvent.emplace(nonPrefiringProbECALToken_, nonPrefiringProbaECAL[0]); + iEvent.emplace(nonPrefiringProbECALUpToken_, nonPrefiringProbaECAL[1]); + iEvent.emplace(nonPrefiringProbECALDownToken_, nonPrefiringProbaECAL[2]); iEvent.emplace(nonPrefiringProbMuonToken_, nonPrefiringProbaMuon[0]); iEvent.emplace(nonPrefiringProbMuonUpToken_, nonPrefiringProbaMuon[1]); From 343d7743bb1ac874f949a3921314e4ebc5e55e0f Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Fri, 4 Jun 2021 22:38:00 +0200 Subject: [PATCH 26/28] code format --- PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc index 027814dc0c7d1..81850eb09cd50 100644 --- a/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc +++ b/PhysicsTools/PatUtils/plugins/L1PrefiringWeightProducer.cc @@ -219,8 +219,8 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu //Probability for the event NOT to prefire, computed with the prefiring maps per object. //Up and down values correspond to the resulting value when shifting up/down all prefiring rates in prefiring maps. - double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down - double nonPrefiringProbaECAL[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProba[3] = {1., 1., 1.}; //0: central, 1: up, 2: down + double nonPrefiringProbaECAL[3] = {1., 1., 1.}; //0: central, 1: up, 2: down double nonPrefiringProbaMuon[7] = { 1., 1., 1., 1., 1., 1., 1.}; //0: central, 1: up, 2: down, 3: up stat, 4: down stat, 5: up syst, 6: down syst @@ -307,8 +307,7 @@ void L1PrefiringWeightProducer::produce(edm::Event& iEvent, const edm::EventSetu } // Calculate combined weight as product of the weight for individual objects for (const auto fluct : {fluctuations::central, fluctuations::up, fluctuations::down}) { - nonPrefiringProba[fluct] = - nonPrefiringProbaECAL[fluct] * nonPrefiringProbaMuon[fluct]; + nonPrefiringProba[fluct] = nonPrefiringProbaECAL[fluct] * nonPrefiringProbaMuon[fluct]; } // Calculate statistical and systematic uncertainty separately in the muon case for (const auto fluct : From 21f22a4d66868e150d11699917c086e023da98e5 Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Tue, 8 Jun 2021 16:05:13 +0200 Subject: [PATCH 27/28] fix DQM to not have weights of 1 in the overflow --- PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 10 +++++----- PhysicsTools/NanoAOD/python/triggerObjects_cff.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index b0914352494d2..080de3e0b233a 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -812,11 +812,11 @@ L1PreFiringWeight = cms.PSet( sels = cms.PSet(), plots = cms.VPSet( - Plot1D('L1PreFiringWeight_Nom', 'L1PreFiringWeight_Nom', 20, 0.8, 1.0, 'L1 prefiring weight nominal'), - Plot1D('L1PreFiringWeight_Up', 'L1PreFiringWeight_Up', 20, 0.8, 1.0, 'L1 prefiring weight uncertainy up'), - Plot1D('L1PreFiringWeight_Dn', 'L1PreFiringWeight_Dn', 20, 0.8, 1.0, 'L1 prefiring weight uncertainty down'), - Plot1D('L1PreFiringWeightECAL_Nom', 'L1PreFiringWeightECAL_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for ECAL objects nominal'), - Plot1D('L1PreFiringWeightMuon_Nom', 'L1PreFiringWeightMuon_Nom', 20, 0.8, 1.0, 'L1 prefiring weight for muons nominal'), + Plot1D('L1PreFiringWeight_Nom', 'L1PreFiringWeight_Nom', 21, 0.8, 1.01, 'L1 prefiring weight nominal'), + Plot1D('L1PreFiringWeight_Up', 'L1PreFiringWeight_Up', 21, 0.8, 1.01, 'L1 prefiring weight uncertainy up'), + Plot1D('L1PreFiringWeight_Dn', 'L1PreFiringWeight_Dn', 21, 0.8, 1.01, 'L1 prefiring weight uncertainty down'), + Plot1D('L1PreFiringWeightECAL_Nom', 'L1PreFiringWeightECAL_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for ECAL objects nominal'), + Plot1D('L1PreFiringWeightMuon_Nom', 'L1PreFiringWeightMuon_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for muons nominal'), ) ), diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 6c11b5509b6ae..27b1617f2018c 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -217,7 +217,7 @@ ) from PhysicsTools.PatUtils.L1PrefiringWeightProducer_cff import prefiringweight -#Next line will be updated once we get UL2016 maps +#Next lines are for UL2016 maps (run2_muon_2016 & tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("UL2016preVFP"), DataEraMuon = cms.string("2016preVFP")) (run2_muon_2016 & ~tracker_apv_vfp30_2016).toModify( prefiringweight, DataEraECAL = cms.string("UL2016postVFP"), DataEraMuon = cms.string("2016postVFP")) #Next line is for UL2017 maps From 1a4b06ff2fbd51107f7fbcd9d3a7098c9d0e3c0a Mon Sep 17 00:00:00 2001 From: Jan-Frederik Date: Wed, 9 Jun 2021 04:27:32 +0200 Subject: [PATCH 28/28] fix weight labels in nano --- PhysicsTools/NanoAOD/python/nanoDQM_cfi.py | 10 ++++----- .../NanoAOD/python/triggerObjects_cff.py | 22 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py index 080de3e0b233a..09c5c8169508b 100644 --- a/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py +++ b/PhysicsTools/NanoAOD/python/nanoDQM_cfi.py @@ -812,11 +812,11 @@ L1PreFiringWeight = cms.PSet( sels = cms.PSet(), plots = cms.VPSet( - Plot1D('L1PreFiringWeight_Nom', 'L1PreFiringWeight_Nom', 21, 0.8, 1.01, 'L1 prefiring weight nominal'), - Plot1D('L1PreFiringWeight_Up', 'L1PreFiringWeight_Up', 21, 0.8, 1.01, 'L1 prefiring weight uncertainy up'), - Plot1D('L1PreFiringWeight_Dn', 'L1PreFiringWeight_Dn', 21, 0.8, 1.01, 'L1 prefiring weight uncertainty down'), - Plot1D('L1PreFiringWeightECAL_Nom', 'L1PreFiringWeightECAL_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for ECAL objects nominal'), - Plot1D('L1PreFiringWeightMuon_Nom', 'L1PreFiringWeightMuon_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for muons nominal'), + Plot1D('Nom', 'Nom', 21, 0.8, 1.01, 'L1 prefiring weight nominal'), + Plot1D('Up', 'Up', 21, 0.8, 1.01, 'L1 prefiring weight uncertainy up'), + Plot1D('Dn', 'Dn', 21, 0.8, 1.01, 'L1 prefiring weight uncertainty down'), + Plot1D('ECAL_Nom', 'ECAL_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for ECAL objects nominal'), + Plot1D('Muon_Nom', 'Muon_Nom', 21, 0.8, 1.01, 'L1 prefiring weight for muons nominal'), ) ), diff --git a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py index 27b1617f2018c..b398cab6a20e1 100644 --- a/PhysicsTools/NanoAOD/python/triggerObjects_cff.py +++ b/PhysicsTools/NanoAOD/python/triggerObjects_cff.py @@ -236,17 +236,17 @@ l1PreFiringEventWeightTable = cms.EDProducer("GlobalVariablesTableProducer", name = cms.string("L1PreFiringWeight"), variables = cms.PSet( - L1PreFiringWeight_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProb"), "float", doc = "L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeight_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "float", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeight_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "float", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), - L1PreFiringWeightMuon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightMuon_SystUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. syst.", precision=8), - L1PreFiringWeightMuon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), - L1PreFiringWeightMuon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), - L1PreFiringWeightMuon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), - L1PreFiringWeightECAL_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECAL"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability)", precision=8), - L1PreFiringWeightECAL_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALUp"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), up var.", precision=8), - L1PreFiringWeightECAL_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALDown"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), down var.", precision=8), + Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProb"), "float", doc = "L1 pre-firing event correction weight (1-probability)", precision=8), + Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbUp"), "float", doc = "L1 pre-firing event correction weight (1-probability), up var.", precision=8), + Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbDown"), "float", doc = "L1 pre-firing event correction weight (1-probability), down var.", precision=8), + Muon_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuon"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability)", precision=8), + Muon_SystUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. syst.", precision=8), + Muon_SystDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonSystDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. syst.", precision=8), + Muon_StatUp = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatUp"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), up var. stat.", precision=8), + Muon_StatDn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbMuonStatDown"), "float", doc = "Muon L1 pre-firing event correction weight (1-probability), down var. stat.", precision=8), + ECAL_Nom = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECAL"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability)", precision=8), + ECAL_Up = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALUp"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), up var.", precision=8), + ECAL_Dn = ExtVar(cms.InputTag("prefiringweight:nonPrefiringProbECALDown"), "float", doc = "ECAL L1 pre-firing event correction weight (1-probability), down var.", precision=8), ) )