Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move "hybrid" tau production from nano to mini step #46196

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions PhysicsTools/NanoAOD/python/nano_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,25 @@ def nanoAOD_customizeCommon(process):

nanoAOD_tau_switch = cms.PSet(
idsToAdd = cms.vstring(),
addUParTInfo = cms.bool(True),
addPNet = cms.bool(True)
addUParTInfo = cms.bool(False),
addPNet = cms.bool(False)
)
(run2_nanoAOD_106Xv2).toModify(
nanoAOD_tau_switch, idsToAdd = ["deepTau2018v2p5"]
).toModify(
process, lambda p : nanoAOD_addTauIds(p, nanoAOD_tau_switch.idsToAdd.value())
)

# Don't add Unified Tagger for PUPPI jets for Run 2 (as different PUPPI tune
# and base jet algorithm) or early Run 3 eras
# Add Unified Tagger for CHS jets (PNet) for Run 2 era,
# but don't add Unified Tagger for PUPPI jets (as different PUPPI tune
# and base jet algorithm)
(run2_nanoAOD_106Xv2).toModify(
nanoAOD_tau_switch, addUParTInfo = False
nanoAOD_tau_switch, addPNet = True
)
# Add Unified Taggers for Run 3 pre 142X (pre v15) era (Unified taggers
# are already added to slimmedTaus in miniAOD for newer eras)
run3_nanoAOD_pre142X.toModify(
nanoAOD_tau_switch, addPNet = True, addUParTInfo = True
)

# Add Unified Tagger For CHS Jets (PNet 2023)
Expand Down
110 changes: 110 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,101 @@ def _add_deepMET(process):
process.load("RecoEgamma.EgammaTools.slimmedEgammaHGC_cff")
phase2_hgcal.toModify(task, func=lambda t: t.add(process.slimmedEgammaHGCTask))

#-- Produce a "hybrid" tau collection combining HPS-reconstructed taus with tau-tagged jets
# Run it at the end of customisation to ensure that jets sequences with unified taggers are already defined
def _addUTagToTaus(process, task,
storePNetCHSjets = False,
storeUParTPUPPIjets = False,
addGenJet = False):
if not (storePNetCHSjets or storeUParTPUPPIjets): return process
noUpdatedTauName = 'slimmedTausNoUTag'
updatedTauName = ''
addToProcessAndTask(noUpdatedTauName, process.slimmedTaus.clone(), process, task)
process.pfParticleNetFromMiniAODAK4CHSCentralTagInfosSlimmedDeepFlavour.taus = noUpdatedTauName
process.pfParticleNetFromMiniAODAK4PuppiCentralTagInfosSlimmedPuppiWithDeepTags.taus = noUpdatedTauName
process.pfParticleNetFromMiniAODAK4PuppiForwardTagInfosSlimmedPuppiWithDeepTags.taus = noUpdatedTauName
from PhysicsTools.PatAlgos.patTauHybridProducer_cfi import patTauHybridProducer
if storePNetCHSjets:
jetCollection = 'slimmedJets'
TagName = 'pfParticleNetFromMiniAODAK4CHSCentralJetTags'
tag_prefix = 'byUTagCHS'
updatedTauName = 'slimmedTausWithUTagCHS'
# PNet tagger used for CHS jets
from RecoBTag.ONNXRuntime.pfParticleNetFromMiniAODAK4_cff import pfParticleNetFromMiniAODAK4CHSCentralJetTags
Discriminators = [TagName+":"+tag for tag in pfParticleNetFromMiniAODAK4CHSCentralJetTags.flav_names.value()]
# Define "hybridTau" producer
setattr(process, updatedTauName,
patTauHybridProducer.clone(
src = noUpdatedTauName,
jetSource = jetCollection,
dRMax = 0.4,
jetPtMin = 15,
jetEtaMax = 2.5,
UTagLabel = TagName,
UTagScoreNames = Discriminators,
tagPrefix = tag_prefix,
tauScoreMin = -1,
vsJetMin = 0.05,
checkTauScoreIsBest = False,
chargeAssignmentProbMin = 0.2,
addGenJetMatch = addGenJet,
genJetMatch = ''
))
if addGenJet:
addToProcessAndTask('tauGenJetMatchCHSJet',
process.tauGenJetMatch.clone(src = jetCollection),
process, task)
getattr(process,updatedTauName).genJetMatch = 'tauGenJetMatchCHSJet'
if storeUParTPUPPIjets: task.add(getattr(process,updatedTauName))
if storeUParTPUPPIjets:
jetCollection = 'slimmedJetsPuppi'
TagName = 'pfUnifiedParticleTransformerAK4JetTags'
tag_prefix = 'byUTagPUPPI'
updatedTauName = 'slimmedTausWithUTagPUPPI' if not storePNetCHSjets else 'slimmedTausWithUTagCHSAndUTagPUPPI'
# Unified ParT Tagger used for PUPPI jets
from RecoBTag.ONNXRuntime.pfUnifiedParticleTransformerAK4JetTags_cfi import pfUnifiedParticleTransformerAK4JetTags
Discriminators = [TagName+":"+tag for tag in pfUnifiedParticleTransformerAK4JetTags.flav_names.value()]
# Define "hybridTau" producer
setattr(process, updatedTauName,
patTauHybridProducer.clone(
src = noUpdatedTauName if not storePNetCHSjets else 'slimmedTausWithUTagCHS',
jetSource = jetCollection,
dRMax = 0.4,
jetPtMin = 15,
jetEtaMax = 2.5,
UTagLabel = TagName,
UTagScoreNames = Discriminators,
tagPrefix = tag_prefix,
tauScoreMin = -1,
vsJetMin = 0.05,
checkTauScoreIsBest = False,
chargeAssignmentProbMin = 0.2,
addGenJetMatch = addGenJet,
genJetMatch = ''
))
if addGenJet:
addToProcessAndTask('tauGenJetMatchPUPPIJet',
process.tauGenJetMatch.clone(src = jetCollection),
process, task)
getattr(process,updatedTauName).genJetMatch = 'tauGenJetMatchPUPPIJet'
#add "hybridTau" producer to pat-task and replace slimmedTaus
delattr(process, 'slimmedTaus')
process.slimmedTaus = getattr(process, updatedTauName).clone()
task.add(process.slimmedTaus)
return process

_uTagToTaus_switches = cms.PSet(
storePNetCHSjets = cms.bool(True),
storeUParTPUPPIjets = cms.bool(True),
addGenJet = cms.bool(True)
)
pp_on_AA.toModify(_uTagToTaus_switches, storePNetCHSjets=False, storeUParTPUPPIjets=False)
_addUTagToTaus(process, task,
storePNetCHSjets = _uTagToTaus_switches.storePNetCHSjets.value(),
storeUParTPUPPIjets = _uTagToTaus_switches.storePNetCHSjets.value(),
addGenJet = _uTagToTaus_switches.addGenJet.value()
)

# L1 pre-firing weights for 2016, 2017, and 2018
from Configuration.Eras.Modifier_run2_L1prefiring_cff import run2_L1prefiring
from Configuration.Eras.Modifier_stage2L1Trigger_cff import stage2L1Trigger
Expand Down Expand Up @@ -557,6 +652,21 @@ def miniAOD_customizeOutput(out):
def miniAOD_customizeData(process):
from PhysicsTools.PatAlgos.tools.coreTools import runOnData
runOnData( process, outputModules = [] )
# hybrid taus
print('removing MC dependencies for hybrid taus')
modulesToDel = []
for postfix in ['','WithUTagCHS','WithUTagPUPPI','WithUTagCHSAndUTagPUPPI']:
if hasattr(process,'slimmedTaus'+postfix):
hybridTau = getattr(process,'slimmedTaus'+postfix)
if hasattr(hybridTau,'addGenJetMatch'):
hybridTau.addGenJetMatch = False
genJetModule = hybridTau.genJetMatch.getModuleLabel()
if not genJetModule in modulesToDel:
modulesToDel.append(genJetModule)
hybridTau.genJetMatch = ''
for module in modulesToDel:
if hasattr(process,module): delattr(process,module)

process.load("RecoPPS.Local.ctppsLocalTrackLiteProducer_cff")
process.load("RecoPPS.ProtonReconstruction.ctppsProtons_cff")
process.load("Geometry.VeryForwardGeometry.geometryRPFromDB_cfi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ cmsDriver.py \
--step NANO \
--data \
--conditions auto:run2_data \
--era Run2_2016,run2_nanoAOD_106Xv2 \
--era Run2_2016 \
--eventcontent NANOAODSIM \
--datatier NANOAODSIM \
--customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ cmsDriver.py \
--step NANO \
--data \
--conditions auto:run2_data \
--era Run2_2016_HIPM,run2_nanoAOD_106Xv2 \
--era Run2_2016_HIPM \
--eventcontent NANOAODSIM \
--datatier NANOAODSIM \
--customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ cmsDriver.py \
--step NANO \
--data \
--conditions auto:run2_data \
--era Run2_2017,run2_nanoAOD_106Xv2 \
--era Run2_2017 \
--eventcontent NANOAODSIM \
--datatier NANOAODSIM \
--customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ cmsDriver.py \
--step NANO \
--data \
--conditions auto:run2_data \
--era Run2_2018,run2_nanoAOD_106Xv2 \
--era Run2_2018 \
--eventcontent NANOAODSIM \
--datatier NANOAODSIM \
--customise TauAnalysis/MCEmbeddingTools/customisers.customiseNanoAOD \
Expand Down
30 changes: 20 additions & 10 deletions Validation/RecoTau/src/TauValidationMiniAOD.cc
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ void TauValidationMiniAOD::analyze(const edm::Event &iEvent, const edm::EventSet
string currentDiscriminator = it.getParameter<string>("discriminator");
double selectionCut = it.getParameter<double>("selectionCut");
summaryMap.find("Den")->second->Fill(j);
if (matchedTau->tauID(currentDiscriminator) >= selectionCut)
if (matchedTau->isTauIDAvailable(currentDiscriminator) &&
matchedTau->tauID(currentDiscriminator) >= selectionCut)
summaryMap.find("Num")->second->Fill(j);
j = j + 1;
}
Expand All @@ -631,23 +632,26 @@ void TauValidationMiniAOD::analyze(const edm::Event &iEvent, const edm::EventSet
if (extensionName_.compare(qcd) == 0 || extensionName_.compare(real_data) == 0 ||
extensionName_.compare(ztt) == 0) {
// vsJet/tight
if (matchedTau->tauID("byTightDeepTau2018v2p5VSjet") >= 0.5) {
if (matchedTau->isTauIDAvailable("byTightDeepTau2018v2p5VSjet") &&
matchedTau->tauID("byTightDeepTau2018v2p5VSjet") >= 0.5) {
ptTightvsJetMap.find("")->second->Fill(matchedTau->pt());
etaTightvsJetMap.find("")->second->Fill(matchedTau->eta());
phiTightvsJetMap.find("")->second->Fill(matchedTau->phi());
massTightvsJetMap.find("")->second->Fill(matchedTau->mass());
puTightvsJetMap.find("")->second->Fill(pvHandle->size());
}
// vsJet/medium
if (matchedTau->tauID("byMediumDeepTau2018v2p5VSjet") >= 0.5) {
if (matchedTau->isTauIDAvailable("byMediumDeepTau2018v2p5VSjet") &&
matchedTau->tauID("byMediumDeepTau2018v2p5VSjet") >= 0.5) {
ptMediumvsJetMap.find("")->second->Fill(matchedTau->pt());
etaMediumvsJetMap.find("")->second->Fill(matchedTau->eta());
phiMediumvsJetMap.find("")->second->Fill(matchedTau->phi());
massMediumvsJetMap.find("")->second->Fill(matchedTau->mass());
puMediumvsJetMap.find("")->second->Fill(pvHandle->size());
}
// vsJet/loose
if (matchedTau->tauID("byLooseDeepTau2018v2p5VSjet") >= 0.5) {
if (matchedTau->isTauIDAvailable("byLooseDeepTau2018v2p5VSjet") &&
matchedTau->tauID("byLooseDeepTau2018v2p5VSjet") >= 0.5) {
ptLoosevsJetMap.find("")->second->Fill(matchedTau->pt());
etaLoosevsJetMap.find("")->second->Fill(matchedTau->eta());
phiLoosevsJetMap.find("")->second->Fill(matchedTau->phi());
Expand All @@ -659,23 +663,26 @@ void TauValidationMiniAOD::analyze(const edm::Event &iEvent, const edm::EventSet
if (extensionName_.compare(real_eledata) == 0 || extensionName_.compare(zee) == 0 ||
extensionName_.compare(ztt) == 0) {
// vsEle/tight
if (matchedTau->tauID("byTightDeepTau2018v2p5VSe") >= 0.5) {
if (matchedTau->isTauIDAvailable("byTightDeepTau2018v2p5VSe") &&
matchedTau->tauID("byTightDeepTau2018v2p5VSe") >= 0.5) {
ptTightvsEleMap.find("")->second->Fill(matchedTau->pt());
etaTightvsEleMap.find("")->second->Fill(matchedTau->eta());
phiTightvsEleMap.find("")->second->Fill(matchedTau->phi());
massTightvsEleMap.find("")->second->Fill(matchedTau->mass());
puTightvsEleMap.find("")->second->Fill(pvHandle->size());
}
// vsEle/medium
if (matchedTau->tauID("byMediumDeepTau2018v2p5VSe") >= 0.5) {
if (matchedTau->isTauIDAvailable("byMediumDeepTau2018v2p5VSe") &&
matchedTau->tauID("byMediumDeepTau2018v2p5VSe") >= 0.5) {
ptMediumvsEleMap.find("")->second->Fill(matchedTau->pt());
etaMediumvsEleMap.find("")->second->Fill(matchedTau->eta());
phiMediumvsEleMap.find("")->second->Fill(matchedTau->phi());
massMediumvsEleMap.find("")->second->Fill(matchedTau->mass());
puMediumvsEleMap.find("")->second->Fill(pvHandle->size());
}
// vsEle/loose
if (matchedTau->tauID("byLooseDeepTau2018v2p5VSe") >= 0.5) {
if (matchedTau->isTauIDAvailable("byLooseDeepTau2018v2p5VSe") &&
matchedTau->tauID("byLooseDeepTau2018v2p5VSe") >= 0.5) {
ptLoosevsEleMap.find("")->second->Fill(matchedTau->pt());
etaLoosevsEleMap.find("")->second->Fill(matchedTau->eta());
phiLoosevsEleMap.find("")->second->Fill(matchedTau->phi());
Expand All @@ -687,23 +694,26 @@ void TauValidationMiniAOD::analyze(const edm::Event &iEvent, const edm::EventSet
if (extensionName_.compare(real_mudata) == 0 || extensionName_.compare(zmm) == 0 ||
extensionName_.compare(ztt) == 0) {
// vsMuo/tight
if (matchedTau->tauID("byTightDeepTau2018v2p5VSmu") >= 0.5) {
if (matchedTau->isTauIDAvailable("byTightDeepTau2018v2p5VSmu") &&
matchedTau->tauID("byTightDeepTau2018v2p5VSmu") >= 0.5) {
ptTightvsMuoMap.find("")->second->Fill(matchedTau->pt());
etaTightvsMuoMap.find("")->second->Fill(matchedTau->eta());
phiTightvsMuoMap.find("")->second->Fill(matchedTau->phi());
massTightvsMuoMap.find("")->second->Fill(matchedTau->mass());
puTightvsMuoMap.find("")->second->Fill(pvHandle->size());
}
// vsMuo/medium
if (matchedTau->tauID("byMediumDeepTau2018v2p5VSmu") >= 0.5) {
if (matchedTau->isTauIDAvailable("byMediumDeepTau2018v2p5VSmu") &&
matchedTau->tauID("byMediumDeepTau2018v2p5VSmu") >= 0.5) {
ptMediumvsMuoMap.find("")->second->Fill(matchedTau->pt());
etaMediumvsMuoMap.find("")->second->Fill(matchedTau->eta());
phiMediumvsMuoMap.find("")->second->Fill(matchedTau->phi());
massMediumvsMuoMap.find("")->second->Fill(matchedTau->mass());
puMediumvsMuoMap.find("")->second->Fill(pvHandle->size());
}
// vsMuo/loose
if (matchedTau->tauID("byLooseDeepTau2018v2p5VSmu") >= 0.5) {
if (matchedTau->isTauIDAvailable("byLooseDeepTau2018v2p5VSmu") &&
matchedTau->tauID("byLooseDeepTau2018v2p5VSmu") >= 0.5) {
ptLoosevsMuoMap.find("")->second->Fill(matchedTau->pt());
etaLoosevsMuoMap.find("")->second->Fill(matchedTau->eta());
phiLoosevsMuoMap.find("")->second->Fill(matchedTau->phi());
Expand Down