From 89b07096e5f4b6557920b550378d023f79484c4e Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 10 Feb 2022 02:24:56 -0600 Subject: [PATCH 01/14] Add quick UL production code Conflicts: Production/python/sampleConfig.py --- Production/python/Production.py | 11 +++++++++++ Production/python/runTauIdMVA.py | 6 ++++-- Production/python/sampleConfig.py | 12 ++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index 6b99820c323..1fd29876d5c 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -126,6 +126,7 @@ src = cms.InputTag("packedPFCandidates"), jetCollInstanceName = cms.string('subJetsForSeedingBoostedTausPAT') ) + """ process.cleanedSlimmedTausBoosted = cms.EDProducer("PATBoostedTauCleaner", src = cms.InputTag('slimmedTausBoosted'), pfcands = cms.InputTag('packedPFCandidates'), @@ -144,6 +145,16 @@ getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * getattr(process, updatedBoostedTauName)) boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) + """ + updatedBoostedTauName = "slimmedBoostedTausNewID" + runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="slimmedTausBoosted", + toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) + process.boostedSequence = cms.Sequence( + process.ca8PFJetsCHSprunedForBoostedTausPAT * + getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * + getattr(process, updatedBoostedTauName)) + boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) + # boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') if isRun2UL: diff --git a/Production/python/runTauIdMVA.py b/Production/python/runTauIdMVA.py index 5ff910ad619..2feace4b65f 100644 --- a/Production/python/runTauIdMVA.py +++ b/Production/python/runTauIdMVA.py @@ -84,8 +84,10 @@ def runTauID(process, outputTauCollection='slimmedTausNewID', inputTauCollection srcFootprintCorrection = 'footprintCorrectiondR03' srcPhotonPtSumOutsideSignalCone = 'photonPtSumOutsideSignalConedR03' elif isBoosted: - srcChargedIsoPtSum = 'chargedIsoPtSumNoOverLap' - srcNeutralIsoPtSum = 'neutralIsoPtSumNoOverLap' + #srcChargedIsoPtSum = 'chargedIsoPtSumNoOverLap' + #srcNeutralIsoPtSum = 'neutralIsoPtSumNoOverLap' + srcChargedIsoPtSum = 'chargedIsoPtSum' + srcNeutralIsoPtSum = 'neutralIsoPtSum' srcFootprintCorrection = 'footprintCorrection' srcPhotonPtSumOutsideSignalCone = 'photonPtSumOutsideSignalCone' else: diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index 9041760e5eb..0124f01484d 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -5,8 +5,8 @@ import FWCore.ParameterSet.Config as cms import os -mcSampleTypes = Set([ 'MC_16', 'MC_17', 'MC_18', 'MC_UL18', 'Emb_16', 'Emb_17', 'Emb_18ABC', 'Emb_18D', 'MC_Phase2_111X', 'MC_Phase2_110X']) -dataSampleTypes = Set([ 'Run2016' , 'Run2017', 'Run2018ABC', 'Run2018D', 'RunUL2018' ]) +mcSampleTypes = Set([ 'MC_16', 'MC_17', 'MC_18', 'MC_UL18', 'Emb_16', 'Emb_17', 'Emb_18ABC', 'Emb_18D', 'MC_Phase2_111X', 'MC_Phase2_110X', 'UL18', 'UL17','UL16','UL16APV']) +dataSampleTypes = Set([ 'Run2016' , 'Run2017', 'Run2018ABC', 'Run2018D' ]) periodDict = { 'MC_16' : 'Run2016', 'Run2016' : 'Run2016', @@ -23,6 +23,10 @@ 'Emb_18D' : 'Run2018', 'MC_Phase2_110X' : 'Phase2', 'MC_Phase2_111X' : 'Phase2', + 'UL18': 'Run2018', + 'UL17': 'Run2017', + 'UL16': 'Run2016', + 'UL16APV': 'Run2016', } globalTagMap = { 'MC_16' : '102X_mcRun2_asymptotic_v7', @@ -41,6 +45,10 @@ 'Emb_18D' : '102X_dataRun2_Prompt_v15', 'MC_Phase2_110X' : '110X_mcRun4_realistic_v3', 'MC_Phase2_111X' : 'auto:phase2_realistic_T15', + 'UL18': '106X_upgrade2018_realistic_v15_L1v1', + 'UL17': '106X_mc2017_realistic_v8', + 'UL16': '106X_mcRun2_asymptotic_v17', + 'UL16APV': '106X_mcRun2_asymptotic_preVFP_v11 ' } def IsEmbedded(sampleType): From c7c8c9dda0b3c20b5652c62ce505d229fcec7943 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Mon, 14 Feb 2022 15:00:31 -0600 Subject: [PATCH 02/14] Update bugged UL additions in productions --- Production/python/Production.py | 13 ++++++++++--- Production/python/sampleConfig.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index 1fd29876d5c..6b1187637fc 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,6 +115,7 @@ elif isRun2UL: boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') else: + from TauMLTools.Production.runTauIdMVA import runTauID updatedTauName = "slimmedTausNewID" runTauID(process, outputTauCollection = updatedTauName, inputTauCollection = tau_collection, @@ -134,7 +135,6 @@ ca8JetSrc = cms.InputTag('ca8PFJetsCHSprunedForBoostedTausPAT','subJetsForSeedingBoostedTausPAT'), removeOverLap = cms.bool(True), ) - updatedBoostedTauName = "slimmedBoostedTausNewID" runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="cleanedSlimmedTausBoosted", toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) @@ -153,8 +153,7 @@ process.ca8PFJetsCHSprunedForBoostedTausPAT * getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * getattr(process, updatedBoostedTauName)) - boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) - + boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) # boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') if isRun2UL: @@ -247,6 +246,14 @@ if isRun2PreUL: process.p.insert(2, process.boostedSequence) +if (options.sampleType == "UL16" + or options.sampleType == "UL16APV" + or options.sampleType == "UL17" + or options.sampletype == "UL18"): + print("inserting boosted tau sequence") + process.p.insert(2, process.boostedSequence) + + process.load('FWCore.MessageLogger.MessageLogger_cfi') x = process.maxEvents.input.value() x = x if x >= 0 else 10000 diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index 0124f01484d..730cdabc59b 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -48,7 +48,7 @@ 'UL18': '106X_upgrade2018_realistic_v15_L1v1', 'UL17': '106X_mc2017_realistic_v8', 'UL16': '106X_mcRun2_asymptotic_v17', - 'UL16APV': '106X_mcRun2_asymptotic_preVFP_v11 ' + 'UL16APV': '106X_mcRun2_asymptotic_preVFP_v11' } def IsEmbedded(sampleType): From f325d9c8342b1b7a28a169bc3b7e9f7a79e70750 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 20:31:52 -0600 Subject: [PATCH 03/14] Add boosted tau filter, and fix production configuration --- .../plugins/BoostedTauProductionFilter.cc | 156 ++++++++++++++++++ Production/python/Production.py | 12 +- 2 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 Production/plugins/BoostedTauProductionFilter.cc diff --git a/Production/plugins/BoostedTauProductionFilter.cc b/Production/plugins/BoostedTauProductionFilter.cc new file mode 100644 index 00000000000..6e781b4e7cc --- /dev/null +++ b/Production/plugins/BoostedTauProductionFilter.cc @@ -0,0 +1,156 @@ +// system include files +#include + +// user include files +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/stream/EDFilter.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/Tau.h" + +// +// class declaration +// + +class BoostedTauProductionFilter : public edm::stream::EDFilter<> { + public: + explicit BoostedTauProductionFilter(const edm::ParameterSet&); + ~BoostedTauProductionFilter(); + + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); + + private: + virtual void beginStream(edm::StreamID) override; + virtual bool filter(edm::Event&, const edm::EventSetup&) override; + virtual void endStream() override; + + //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; + //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; + + // ----------member data --------------------------- + edm::EDGetTokenT< std::vector > boostedTauCollection; + bool verboseDebug; +}; + +// +// constants, enums and typedefs +// + +// +// static data member definitions +// + +// +// constructors and destructor +// +BoostedTauProductionFilter::BoostedTauProductionFilter(const edm::ParameterSet& iConfig): + boostedTauCollection(consumes< std::vector >(iConfig.getParameter< edm::InputTag >("boostedTauCollection") ) ) +{ + //now do what ever initialization is needed + verboseDebug = iConfig.exists("verboseDebug") ? iConfig.getParameter("verboseDebug"): false; + if (verboseDebug) std::cout<<"Constructing boosted tau filter..."< pIn; + iEvent.getByLabel("example",pIn); +#endif + +#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE + ESHandle pSetup; + iSetup.get().get(pSetup); +#endif + return true; + */ + + edm::Handle< std::vector > boostedTauHandle; + iEvent.getByToken(boostedTauCollection, boostedTauHandle); + + //Our filter really only asks one very simple question. Is there a boosted tau in the event? + if (verboseDebug) std::cout<<"boosted taus empty? "<empty()<empty()) return false; + return true; + + +} + +// ------------ method called once each stream before processing any runs, lumis or events ------------ +void +BoostedTauProductionFilter::beginStream(edm::StreamID) +{ +} + +// ------------ method called once each stream after processing all runs, lumis and events ------------ +void +BoostedTauProductionFilter::endStream() { +} + +// ------------ method called when starting to processes a run ------------ +/* +void +BoostedTauProductionFilter::beginRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a run ------------ +/* +void +BoostedTauProductionFilter::endRun(edm::Run const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when starting to processes a luminosity block ------------ +/* +void +BoostedTauProductionFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method called when ending the processing of a luminosity block ------------ +/* +void +BoostedTauProductionFilter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) +{ +} +*/ + +// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ +void +BoostedTauProductionFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { + //The following says we do not know what parameters are allowed so do no validation + // Please change this to state exactly what you do use, even if it is no parameters + edm::ParameterSetDescription desc; + desc.setUnknown(); + descriptions.addDefault(desc); +} +//define this as a plug-in +DEFINE_FWK_MODULE(BoostedTauProductionFilter); diff --git a/Production/python/Production.py b/Production/python/Production.py index 6b1187637fc..d03a5e3974d 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -38,6 +38,8 @@ " If 'reclusterJets' set true a new collection of uncorrected ak4PFJets is built to seed taus (as at RECO), otherwise standard slimmedJets are used") options.register('rerunTauReco', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "If true, tau reconstruction is re-run on MINIAOD with a larger signal cone and no DM finding filter") +options.register('useBoostedTauFilter', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, + "Implement boosted tau filter in the boosted the process to get boosted tau enriched files.") options.parseArguments() sampleConfig = importlib.import_module('TauMLTools.Production.sampleConfig') @@ -249,10 +251,14 @@ if (options.sampleType == "UL16" or options.sampleType == "UL16APV" or options.sampleType == "UL17" - or options.sampletype == "UL18"): - print("inserting boosted tau sequence") + or options.sampleType == "UL18"): process.p.insert(2, process.boostedSequence) - + +if options.useBoostedTauFilter: + process.theBoostedTauFilter = cms.EDFilter('BoostedTauProductionFilter', + boostedTauCollection = cms.InputTag("slimmedTausBoosted"), + verboseDebug = cms.bool(False)) + process.p.insert(0, process.theBoostedTauFilter) process.load('FWCore.MessageLogger.MessageLogger_cfi') x = process.maxEvents.input.value() From 9404e643321cfe6233c5420db1adcccc0a189e23 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:23:43 -0600 Subject: [PATCH 04/14] Clean up UL production configuration a bit --- Production/python/Production.py | 39 ++++++++++++++++--------------- Production/python/sampleConfig.py | 2 +- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index d03a5e3974d..393d9208ca6 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,9 +115,26 @@ tauIdEmbedder.runTauID() # note here, that with the official CMSSW version of 'runTauIdMVA' slimmedTaus are hardcoded as input tau collection boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') elif isRun2UL: - boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') -else: - + #this reruns the ID process... + #but this shouldn't be necessary for UL + """ + from TauMLTools.Production.runTauIdMVA import runTauID + from RecoTauTag.Configuration.boostedHPSPFTaus_cff import ca8PFJetsCHSprunedForBoostedTaus + process.ca8PFJetsCHSprunedForBoostedTausPAT = ca8PFJetsCHSprunedForBoostedTaus.clone( + src = cms.InputTag("packedPFCandidates"), + jetCollInstanceName = cms.string('subJetsForSeedingBoostedTausPAT') + ) + updatedBoostedTauName = "slimmedBoostedTausNewID" + runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="slimmedTausBoosted", + toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) + process.boostedSequence = cms.Sequence( + process.ca8PFJetsCHSprunedForBoostedTausPAT * + getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * + getattr(process, updatedBoostedTauName)) + boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) + """ + boostedTaus_InputTag = cms.InputTag("slimmedTausBoosted") +else: from TauMLTools.Production.runTauIdMVA import runTauID updatedTauName = "slimmedTausNewID" runTauID(process, outputTauCollection = updatedTauName, inputTauCollection = tau_collection, @@ -129,7 +146,6 @@ src = cms.InputTag("packedPFCandidates"), jetCollInstanceName = cms.string('subJetsForSeedingBoostedTausPAT') ) - """ process.cleanedSlimmedTausBoosted = cms.EDProducer("PATBoostedTauCleaner", src = cms.InputTag('slimmedTausBoosted'), pfcands = cms.InputTag('packedPFCandidates'), @@ -147,15 +163,6 @@ getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * getattr(process, updatedBoostedTauName)) boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) - """ - updatedBoostedTauName = "slimmedBoostedTausNewID" - runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="slimmedTausBoosted", - toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) - process.boostedSequence = cms.Sequence( - process.ca8PFJetsCHSprunedForBoostedTausPAT * - getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * - getattr(process, updatedBoostedTauName)) - boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) # boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') if isRun2UL: @@ -248,12 +255,6 @@ if isRun2PreUL: process.p.insert(2, process.boostedSequence) -if (options.sampleType == "UL16" - or options.sampleType == "UL16APV" - or options.sampleType == "UL17" - or options.sampleType == "UL18"): - process.p.insert(2, process.boostedSequence) - if options.useBoostedTauFilter: process.theBoostedTauFilter = cms.EDFilter('BoostedTauProductionFilter', boostedTauCollection = cms.InputTag("slimmedTausBoosted"), diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index 730cdabc59b..889ba8abd7a 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -81,7 +81,7 @@ def isRun2UL(sampleType): if sampleType not in periodDict: print "ERROR: unknown sample type = '{}'".format(sampleType) sys.exit(1) - return sampleType in ['MC_UL18', 'RunUL2018'] + return sampleType in ['MC_UL18', 'RunUL2018', 'UL16', 'UL16APV', 'UL17', 'UL18'] def isPhase2(sampleType): if sampleType not in periodDict: From b0b2178dfffc8c70b4757e549c1f861aba92811a Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:35:44 -0600 Subject: [PATCH 05/14] Fix dropped data sample type in merge, and fix typo --- Production/python/Production.py | 2 +- Production/python/sampleConfig.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index 393d9208ca6..f7b2a534c1f 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -39,7 +39,7 @@ options.register('rerunTauReco', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "If true, tau reconstruction is re-run on MINIAOD with a larger signal cone and no DM finding filter") options.register('useBoostedTauFilter', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, - "Implement boosted tau filter in the boosted the process to get boosted tau enriched files.") + "Implement boosted tau filter in the process to only consider events with some boosted tau content") options.parseArguments() sampleConfig = importlib.import_module('TauMLTools.Production.sampleConfig') diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index 889ba8abd7a..47182bba0e7 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -6,7 +6,7 @@ import os mcSampleTypes = Set([ 'MC_16', 'MC_17', 'MC_18', 'MC_UL18', 'Emb_16', 'Emb_17', 'Emb_18ABC', 'Emb_18D', 'MC_Phase2_111X', 'MC_Phase2_110X', 'UL18', 'UL17','UL16','UL16APV']) -dataSampleTypes = Set([ 'Run2016' , 'Run2017', 'Run2018ABC', 'Run2018D' ]) +dataSampleTypes = Set([ 'Run2016' , 'Run2017', 'Run2018ABC', 'Run2018D', 'RunUL2018' ]) periodDict = { 'MC_16' : 'Run2016', 'Run2016' : 'Run2016', From d3f770fa8baecf0ee6ceb4df09774309056ad923 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:41:24 -0600 Subject: [PATCH 06/14] Remove tau ID running changes made irrelevant for Boosted Tau UL --- Production/python/runTauIdMVA.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Production/python/runTauIdMVA.py b/Production/python/runTauIdMVA.py index 2feace4b65f..5ff910ad619 100644 --- a/Production/python/runTauIdMVA.py +++ b/Production/python/runTauIdMVA.py @@ -84,10 +84,8 @@ def runTauID(process, outputTauCollection='slimmedTausNewID', inputTauCollection srcFootprintCorrection = 'footprintCorrectiondR03' srcPhotonPtSumOutsideSignalCone = 'photonPtSumOutsideSignalConedR03' elif isBoosted: - #srcChargedIsoPtSum = 'chargedIsoPtSumNoOverLap' - #srcNeutralIsoPtSum = 'neutralIsoPtSumNoOverLap' - srcChargedIsoPtSum = 'chargedIsoPtSum' - srcNeutralIsoPtSum = 'neutralIsoPtSum' + srcChargedIsoPtSum = 'chargedIsoPtSumNoOverLap' + srcNeutralIsoPtSum = 'neutralIsoPtSumNoOverLap' srcFootprintCorrection = 'footprintCorrection' srcPhotonPtSumOutsideSignalCone = 'photonPtSumOutsideSignalCone' else: From 7ec42564ada46b2989475367198be0fff6aa0d28 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:42:42 -0600 Subject: [PATCH 07/14] Remove some superfluous commented out code --- Production/python/Production.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index f7b2a534c1f..cecf841bc16 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,24 +115,6 @@ tauIdEmbedder.runTauID() # note here, that with the official CMSSW version of 'runTauIdMVA' slimmedTaus are hardcoded as input tau collection boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') elif isRun2UL: - #this reruns the ID process... - #but this shouldn't be necessary for UL - """ - from TauMLTools.Production.runTauIdMVA import runTauID - from RecoTauTag.Configuration.boostedHPSPFTaus_cff import ca8PFJetsCHSprunedForBoostedTaus - process.ca8PFJetsCHSprunedForBoostedTausPAT = ca8PFJetsCHSprunedForBoostedTaus.clone( - src = cms.InputTag("packedPFCandidates"), - jetCollInstanceName = cms.string('subJetsForSeedingBoostedTausPAT') - ) - updatedBoostedTauName = "slimmedBoostedTausNewID" - runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="slimmedTausBoosted", - toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) - process.boostedSequence = cms.Sequence( - process.ca8PFJetsCHSprunedForBoostedTausPAT * - getattr(process, updatedBoostedTauName + 'rerunMvaIsolationSequence') * - getattr(process, updatedBoostedTauName)) - boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) - """ boostedTaus_InputTag = cms.InputTag("slimmedTausBoosted") else: from TauMLTools.Production.runTauIdMVA import runTauID From 2f86b9d4360c98701a0a1ad637a18410015157f0 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:45:20 -0600 Subject: [PATCH 08/14] Remove additional extraneous changes --- Production/python/Production.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index cecf841bc16..d649b7c5d2e 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,8 +115,8 @@ tauIdEmbedder.runTauID() # note here, that with the official CMSSW version of 'runTauIdMVA' slimmedTaus are hardcoded as input tau collection boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') elif isRun2UL: - boostedTaus_InputTag = cms.InputTag("slimmedTausBoosted") -else: + boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') +else: from TauMLTools.Production.runTauIdMVA import runTauID updatedTauName = "slimmedTausNewID" runTauID(process, outputTauCollection = updatedTauName, inputTauCollection = tau_collection, @@ -135,6 +135,7 @@ ca8JetSrc = cms.InputTag('ca8PFJetsCHSprunedForBoostedTausPAT','subJetsForSeedingBoostedTausPAT'), removeOverLap = cms.bool(True), ) + updatedBoostedTauName = "slimmedBoostedTausNewID" runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="cleanedSlimmedTausBoosted", toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) From 5ba26d7aa362556919c03c470c3ff454e86b63c3 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Thu, 24 Feb 2022 21:45:20 -0600 Subject: [PATCH 09/14] Remove additional extraneous changes --- Production/python/Production.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index cecf841bc16..bd919ec6521 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,8 +115,8 @@ tauIdEmbedder.runTauID() # note here, that with the official CMSSW version of 'runTauIdMVA' slimmedTaus are hardcoded as input tau collection boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') elif isRun2UL: - boostedTaus_InputTag = cms.InputTag("slimmedTausBoosted") -else: + boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') +else: from TauMLTools.Production.runTauIdMVA import runTauID updatedTauName = "slimmedTausNewID" runTauID(process, outputTauCollection = updatedTauName, inputTauCollection = tau_collection, @@ -135,6 +135,7 @@ ca8JetSrc = cms.InputTag('ca8PFJetsCHSprunedForBoostedTausPAT','subJetsForSeedingBoostedTausPAT'), removeOverLap = cms.bool(True), ) + updatedBoostedTauName = "slimmedBoostedTausNewID" runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="cleanedSlimmedTausBoosted", toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) From a626eb042789b4544b18882374f965ab22121be2 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Wed, 6 Apr 2022 17:37:07 -0500 Subject: [PATCH 10/14] Modify boosted tau production filtering to happen directly in the production code. Removes the redundant ED filter infrastructure, and changes the configuration to make useBoostedTauFilter an option given to TauTupleProducer. This option should now remove all non boosted tau type tau jets --- Production/interface/TauJet.h | 4 +- .../plugins/BoostedTauProductionFilter.cc | 156 ------------------ Production/plugins/TauTupleProducer.cc | 5 +- Production/python/Production.py | 9 +- Production/src/TauJet.cc | 11 +- 5 files changed, 16 insertions(+), 169 deletions(-) delete mode 100644 Production/plugins/BoostedTauProductionFilter.cc diff --git a/Production/interface/TauJet.h b/Production/interface/TauJet.h index e9cddb58a63..ee3cf6a5ebd 100644 --- a/Production/interface/TauJet.h +++ b/Production/interface/TauJet.h @@ -109,7 +109,7 @@ class TauJetBuilder { const pat::ElectronCollection& electrons, const pat::MuonCollection& muons, const pat::IsolatedTrackCollection& isoTracks, const pat::PackedCandidateCollection& lostTracks, const reco::GenParticleCollection* genParticles, const reco::GenJetCollection* genJets, - bool requireGenMatch, bool requireGenORRecoTauMatch, bool applyRecoPtSieve); + bool requireGenMatch, bool requireGenORRecoTauMatch, bool applyRecoPtSieve, bool useBoostedTauFilter); TauJetBuilder(const TauJetBuilder&) = delete; TauJetBuilder& operator=(const TauJetBuilder&) = delete; @@ -139,7 +139,7 @@ class TauJetBuilder { const pat::PackedCandidateCollection& lostTracks_; const reco::GenParticleCollection* genParticles_; const reco::GenJetCollection* genJets_; - const bool requireGenMatch_, requireGenORRecoTauMatch_, applyRecoPtSieve_; + const bool requireGenMatch_, requireGenORRecoTauMatch_, applyRecoPtSieve_, useBoostedTauFilter_; std::deque tauJets_; std::vector genLeptons_; diff --git a/Production/plugins/BoostedTauProductionFilter.cc b/Production/plugins/BoostedTauProductionFilter.cc deleted file mode 100644 index 6e781b4e7cc..00000000000 --- a/Production/plugins/BoostedTauProductionFilter.cc +++ /dev/null @@ -1,156 +0,0 @@ -// system include files -#include - -// user include files -#include "FWCore/Framework/interface/Frameworkfwd.h" -#include "FWCore/Framework/interface/stream/EDFilter.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/Tau.h" - -// -// class declaration -// - -class BoostedTauProductionFilter : public edm::stream::EDFilter<> { - public: - explicit BoostedTauProductionFilter(const edm::ParameterSet&); - ~BoostedTauProductionFilter(); - - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); - - private: - virtual void beginStream(edm::StreamID) override; - virtual bool filter(edm::Event&, const edm::EventSetup&) override; - virtual void endStream() override; - - //virtual void beginRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void endRun(edm::Run const&, edm::EventSetup const&) override; - //virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - //virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override; - - // ----------member data --------------------------- - edm::EDGetTokenT< std::vector > boostedTauCollection; - bool verboseDebug; -}; - -// -// constants, enums and typedefs -// - -// -// static data member definitions -// - -// -// constructors and destructor -// -BoostedTauProductionFilter::BoostedTauProductionFilter(const edm::ParameterSet& iConfig): - boostedTauCollection(consumes< std::vector >(iConfig.getParameter< edm::InputTag >("boostedTauCollection") ) ) -{ - //now do what ever initialization is needed - verboseDebug = iConfig.exists("verboseDebug") ? iConfig.getParameter("verboseDebug"): false; - if (verboseDebug) std::cout<<"Constructing boosted tau filter..."< pIn; - iEvent.getByLabel("example",pIn); -#endif - -#ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE - ESHandle pSetup; - iSetup.get().get(pSetup); -#endif - return true; - */ - - edm::Handle< std::vector > boostedTauHandle; - iEvent.getByToken(boostedTauCollection, boostedTauHandle); - - //Our filter really only asks one very simple question. Is there a boosted tau in the event? - if (verboseDebug) std::cout<<"boosted taus empty? "<empty()<empty()) return false; - return true; - - -} - -// ------------ method called once each stream before processing any runs, lumis or events ------------ -void -BoostedTauProductionFilter::beginStream(edm::StreamID) -{ -} - -// ------------ method called once each stream after processing all runs, lumis and events ------------ -void -BoostedTauProductionFilter::endStream() { -} - -// ------------ method called when starting to processes a run ------------ -/* -void -BoostedTauProductionFilter::beginRun(edm::Run const&, edm::EventSetup const&) -{ -} -*/ - -// ------------ method called when ending the processing of a run ------------ -/* -void -BoostedTauProductionFilter::endRun(edm::Run const&, edm::EventSetup const&) -{ -} -*/ - -// ------------ method called when starting to processes a luminosity block ------------ -/* -void -BoostedTauProductionFilter::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) -{ -} -*/ - -// ------------ method called when ending the processing of a luminosity block ------------ -/* -void -BoostedTauProductionFilter::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) -{ -} -*/ - -// ------------ method fills 'descriptions' with the allowed parameters for the module ------------ -void -BoostedTauProductionFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) { - //The following says we do not know what parameters are allowed so do no validation - // Please change this to state exactly what you do use, even if it is no parameters - edm::ParameterSetDescription desc; - desc.setUnknown(); - descriptions.addDefault(desc); -} -//define this as a plug-in -DEFINE_FWK_MODULE(BoostedTauProductionFilter); diff --git a/Production/plugins/TauTupleProducer.cc b/Production/plugins/TauTupleProducer.cc index 03b6130feb3..4be47172877 100644 --- a/Production/plugins/TauTupleProducer.cc +++ b/Production/plugins/TauTupleProducer.cc @@ -127,6 +127,7 @@ class TauTupleProducer : public edm::EDAnalyzer { requireGenMatch(cfg.getParameter("requireGenMatch")), requireGenORRecoTauMatch(cfg.getParameter("requireGenORRecoTauMatch")), applyRecoPtSieve(cfg.getParameter("applyRecoPtSieve")), + useBoostedTauFilter(cfg.getParameter("useBoostedTauFilter")), genEvent_token(mayConsume(cfg.getParameter("genEvent"))), genParticles_token(mayConsume(cfg.getParameter("genParticles"))), genJets_token(mayConsume(cfg.getParameter("genJets"))), @@ -269,7 +270,7 @@ class TauTupleProducer : public edm::EDAnalyzer { TauJetBuilder builder(builderSetup, *taus, *boostedTaus, *jets, *fatJets, *cands, *electrons, *muons, *isoTracks, *lostTracks, genParticles, genJets, requireGenMatch, - requireGenORRecoTauMatch, applyRecoPtSieve); + requireGenORRecoTauMatch, applyRecoPtSieve, useBoostedTauFilter); const auto& tauJets = builder.GetTauJets(); tauTuple().total_entries = static_cast(tauJets.size()); for(size_t tauJetIndex = 0; tauJetIndex < tauJets.size(); ++tauJetIndex) { @@ -897,7 +898,7 @@ class TauTupleProducer : public edm::EDAnalyzer { } private: - const bool isMC, isEmbedded, requireGenMatch, requireGenORRecoTauMatch, applyRecoPtSieve; + const bool isMC, isEmbedded, requireGenMatch, requireGenORRecoTauMatch, applyRecoPtSieve, useBoostedTauFilter; TauJetBuilderSetup builderSetup; edm::EDGetTokenT genEvent_token; diff --git a/Production/python/Production.py b/Production/python/Production.py index bd919ec6521..202baeaabe3 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -39,7 +39,7 @@ options.register('rerunTauReco', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, "If true, tau reconstruction is re-run on MINIAOD with a larger signal cone and no DM finding filter") options.register('useBoostedTauFilter', False, VarParsing.multiplicity.singleton, VarParsing.varType.bool, - "Implement boosted tau filter in the process to only consider events with some boosted tau content") + "Implement boosted tau filter in the process to only consider tau jets that are boosted taus") options.parseArguments() sampleConfig = importlib.import_module('TauMLTools.Production.sampleConfig') @@ -194,6 +194,7 @@ requireGenMatch = cms.bool(options.requireGenMatch), requireGenORRecoTauMatch = cms.bool(options.requireGenORRecoTauMatch), applyRecoPtSieve = cms.bool(options.applyRecoPtSieve), + useBoostedTauFilter = cms.bool(options.useBoostedTauFilter), tauJetBuilderSetup = tauJetBuilderSetup, lheEventProduct = cms.InputTag('externalLHEProducer'), @@ -238,12 +239,6 @@ if isRun2PreUL: process.p.insert(2, process.boostedSequence) -if options.useBoostedTauFilter: - process.theBoostedTauFilter = cms.EDFilter('BoostedTauProductionFilter', - boostedTauCollection = cms.InputTag("slimmedTausBoosted"), - verboseDebug = cms.bool(False)) - process.p.insert(0, process.theBoostedTauFilter) - process.load('FWCore.MessageLogger.MessageLogger_cfi') x = process.maxEvents.input.value() x = x if x >= 0 else 10000 diff --git a/Production/src/TauJet.cc b/Production/src/TauJet.cc index bd8cc5d18c4..b0bac782051 100644 --- a/Production/src/TauJet.cc +++ b/Production/src/TauJet.cc @@ -93,11 +93,11 @@ TauJetBuilder::TauJetBuilder(const TauJetBuilderSetup& setup, const pat::TauColl const pat::ElectronCollection& electrons, const pat::MuonCollection& muons, const pat::IsolatedTrackCollection& isoTracks, const pat::PackedCandidateCollection& lostTracks, const reco::GenParticleCollection* genParticles, const reco::GenJetCollection* genJets, - bool requireGenMatch, bool requireGenORRecoTauMatch, bool applyRecoPtSieve) : + bool requireGenMatch, bool requireGenORRecoTauMatch, bool applyRecoPtSieve, bool useBoostedTauFilter) : setup_(setup), taus_(taus), boostedTaus_(boostedTaus), jets_(jets), fatJets_(fatJets), cands_(cands), electrons_(electrons), muons_(muons), isoTracks_(isoTracks), lostTracks_(lostTracks), genParticles_(genParticles), genJets_(genJets), requireGenMatch_(requireGenMatch), requireGenORRecoTauMatch_(requireGenORRecoTauMatch), - applyRecoPtSieve_(applyRecoPtSieve) + applyRecoPtSieve_(applyRecoPtSieve), useBoostedTauFilter_(useBoostedTauFilter) { if(genParticles) genLeptons_ = reco_tau::gen_truth::GenLepton::fromGenParticleCollection(*genParticles); @@ -305,6 +305,13 @@ void TauJetBuilder::Build() tauJets_ = prunedTauJets; } + if(useBoostedTauFilter_){ + std::deque boostedTauJets; + for(const TauJet& tauJet: tauJets_){ + if (tauJet.boostedTau) boostedTauJets.push_back(tauJet); + } + tauJets_ = boostedTauJets; + } for(TauJet& tauJet : tauJets_) { From 2be1a0e0e0645b6566f271eeacf9cab502d28117 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Wed, 6 Apr 2022 17:48:05 -0500 Subject: [PATCH 11/14] Add boosted tau MVA calculation back into UL sequence Ntuples otherwise seem to get empty MVA evaluations --- Production/python/Production.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Production/python/Production.py b/Production/python/Production.py index 202baeaabe3..ac94147f9b4 100644 --- a/Production/python/Production.py +++ b/Production/python/Production.py @@ -115,7 +115,15 @@ tauIdEmbedder.runTauID() # note here, that with the official CMSSW version of 'runTauIdMVA' slimmedTaus are hardcoded as input tau collection boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') elif isRun2UL: - boostedTaus_InputTag = cms.InputTag('slimmedTausBoosted') + from TauMLTools.Production.runTauIdMVA import runTauID + updatedBoostedTauName = "slimmedBoostedTausNewID" + runTauID(process, outputTauCollection=updatedBoostedTauName, inputTauCollection="slimmedTausBoosted", + toKeep = [ "2017v2", "dR0p32017v2", "newDM2017v2", "deepTau2017v2p1" ]) + process.boostedSequence = cms.Sequence( + getattr(process, updatedBoostedTauName+'rerunMvaIsolationSequence') * + getattr(process, updatedBoostedTauName) + ) + boostedTaus_InputTag = cms.InputTag(updatedBoostedTauName) else: from TauMLTools.Production.runTauIdMVA import runTauID updatedTauName = "slimmedTausNewID" @@ -239,6 +247,9 @@ if isRun2PreUL: process.p.insert(2, process.boostedSequence) +if isRun2UL: + process.p.insert(0, process.boostedSequence) + process.load('FWCore.MessageLogger.MessageLogger_cfi') x = process.maxEvents.input.value() x = x if x >= 0 else 10000 From adf1b1c92387a09bdc8529a12705d1f4288b598a Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Wed, 6 Apr 2022 17:56:23 -0500 Subject: [PATCH 12/14] Remove duplicate UL tags, and update global tags to latest(?) version in CondDB --- Production/python/sampleConfig.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index 47182bba0e7..d9167f54f44 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -15,7 +15,6 @@ 'Run2017' : 'Run2017', 'Emb_17' : 'Run2017', 'MC_18' : 'Run2018', - 'MC_UL18' : 'Run2018', 'Run2018ABC' : 'Run2018', 'Run2018D' : 'Run2018', 'RunUL2018' : 'Run2018', @@ -23,10 +22,10 @@ 'Emb_18D' : 'Run2018', 'MC_Phase2_110X' : 'Phase2', 'MC_Phase2_111X' : 'Phase2', - 'UL18': 'Run2018', - 'UL17': 'Run2017', - 'UL16': 'Run2016', - 'UL16APV': 'Run2016', + 'MC_UL18': 'Run2018', + 'MC_UL17': 'Run2017', + 'MC_UL16': 'Run2016', + 'MC_UL16APV': 'Run2016', } globalTagMap = { 'MC_16' : '102X_mcRun2_asymptotic_v7', @@ -37,7 +36,6 @@ 'Run2017' : '102X_dataRun2_v12', 'Emb_17' : '102X_dataRun2_v12', 'MC_18' : '102X_upgrade2018_realistic_v20', - 'MC_UL18' : '106X_upgrade2018_realistic_v16_L1v1', 'Run2018ABC' : '102X_dataRun2_v12', 'Run2018D' : '102X_dataRun2_Prompt_v15', 'RunUL2018' : '106X_dataRun2_v35', @@ -45,10 +43,10 @@ 'Emb_18D' : '102X_dataRun2_Prompt_v15', 'MC_Phase2_110X' : '110X_mcRun4_realistic_v3', 'MC_Phase2_111X' : 'auto:phase2_realistic_T15', - 'UL18': '106X_upgrade2018_realistic_v15_L1v1', - 'UL17': '106X_mc2017_realistic_v8', - 'UL16': '106X_mcRun2_asymptotic_v17', - 'UL16APV': '106X_mcRun2_asymptotic_preVFP_v11' + 'MC_UL18': '106X_upgrade2018_realistic_v16_L1v1', + 'MC_UL17': '106X_mc2017_realistic_v9', + 'MC_UL16': '106X_mcRun2_asymptotic_v17', + 'MC_UL16APV': '106X_mcRun2_asymptotic_preVFP_v11' } def IsEmbedded(sampleType): @@ -81,7 +79,7 @@ def isRun2UL(sampleType): if sampleType not in periodDict: print "ERROR: unknown sample type = '{}'".format(sampleType) sys.exit(1) - return sampleType in ['MC_UL18', 'RunUL2018', 'UL16', 'UL16APV', 'UL17', 'UL18'] + return sampleType in ['MC_UL18', 'RunUL2018'] def isPhase2(sampleType): if sampleType not in periodDict: From 41482200925dd9548226d9578b2063e453eee679 Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Wed, 6 Apr 2022 17:57:56 -0500 Subject: [PATCH 13/14] Add missing tags to isRun2UL --- Production/python/sampleConfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index d9167f54f44..f5f94922e79 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -79,7 +79,7 @@ def isRun2UL(sampleType): if sampleType not in periodDict: print "ERROR: unknown sample type = '{}'".format(sampleType) sys.exit(1) - return sampleType in ['MC_UL18', 'RunUL2018'] + return sampleType in ['MC_UL18', 'MC_UL17', 'MC_UL16APV', 'MC_UL16' 'RunUL2018'] def isPhase2(sampleType): if sampleType not in periodDict: From aa5732cfaa659512ac49ac60e8848a19f9af3a8d Mon Sep 17 00:00:00 2001 From: Andrew Loeliger Date: Wed, 6 Apr 2022 19:07:07 -0500 Subject: [PATCH 14/14] Add UL types to mcSampleTypes --- Production/python/sampleConfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Production/python/sampleConfig.py b/Production/python/sampleConfig.py index f5f94922e79..e1b2978b927 100644 --- a/Production/python/sampleConfig.py +++ b/Production/python/sampleConfig.py @@ -5,7 +5,7 @@ import FWCore.ParameterSet.Config as cms import os -mcSampleTypes = Set([ 'MC_16', 'MC_17', 'MC_18', 'MC_UL18', 'Emb_16', 'Emb_17', 'Emb_18ABC', 'Emb_18D', 'MC_Phase2_111X', 'MC_Phase2_110X', 'UL18', 'UL17','UL16','UL16APV']) +mcSampleTypes = Set([ 'MC_16', 'MC_17', 'MC_18', 'MC_UL18', 'Emb_16', 'Emb_17', 'Emb_18ABC', 'Emb_18D', 'MC_Phase2_111X', 'MC_Phase2_110X', 'MC_UL18', 'MC_UL17','MC_UL16','MC_UL16APV']) dataSampleTypes = Set([ 'Run2016' , 'Run2017', 'Run2018ABC', 'Run2018D', 'RunUL2018' ]) periodDict = { 'MC_16' : 'Run2016',