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

Boosted Tau Production Changes for Ultra Legacy #87

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Production/interface/TauJet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TauJet> tauJets_;
std::vector<reco_tau::gen_truth::GenLepton> genLeptons_;
Expand Down
5 changes: 3 additions & 2 deletions Production/plugins/TauTupleProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class TauTupleProducer : public edm::EDAnalyzer {
requireGenMatch(cfg.getParameter<bool>("requireGenMatch")),
requireGenORRecoTauMatch(cfg.getParameter<bool>("requireGenORRecoTauMatch")),
applyRecoPtSieve(cfg.getParameter<bool>("applyRecoPtSieve")),
useBoostedTauFilter(cfg.getParameter<bool>("useBoostedTauFilter")),
genEvent_token(mayConsume<GenEventInfoProduct>(cfg.getParameter<edm::InputTag>("genEvent"))),
genParticles_token(mayConsume<reco::GenParticleCollection>(cfg.getParameter<edm::InputTag>("genParticles"))),
genJets_token(mayConsume<reco::GenJetCollection>(cfg.getParameter<edm::InputTag>("genJets"))),
Expand Down Expand Up @@ -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<int>(tauJets.size());
for(size_t tauJetIndex = 0; tauJetIndex < tauJets.size(); ++tauJetIndex) {
Expand Down Expand Up @@ -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<GenEventInfoProduct> genEvent_token;
Expand Down
16 changes: 15 additions & 1 deletion Production/python/Production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 process to only consider tau jets that are boosted taus")
options.parseArguments()

sampleConfig = importlib.import_module('TauMLTools.Production.sampleConfig')
Expand Down Expand Up @@ -113,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)
Comment on lines +118 to +126
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you rerun boosted tau ids for Run2 UL? It should be already included in miniAOD. At least it is the recommended way, as far as I know

Copy link
Author

@aloeliger aloeliger Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried running UL Ntuples without these lines, the MVA branches ended up empty (all 0), and it was causing issues with validation (I need to rerun a few ntuples now). These lines remedy the problem.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange. Perhaps the name of the stored mva ID is different? I think it is worth looking at more closely because if there are some problems with boosted taus in UL miniAODs, we need to make sure that it is documented.

else:
from TauMLTools.Production.runTauIdMVA import runTauID
updatedTauName = "slimmedTausNewID"
Expand Down Expand Up @@ -192,6 +202,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'),
Expand Down Expand Up @@ -236,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
Expand Down
14 changes: 10 additions & 4 deletions Production/python/sampleConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
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',
Expand All @@ -15,14 +15,17 @@
'Run2017' : 'Run2017',
'Emb_17' : 'Run2017',
'MC_18' : 'Run2018',
'MC_UL18' : 'Run2018',
'Run2018ABC' : 'Run2018',
'Run2018D' : 'Run2018',
'RunUL2018' : 'Run2018',
'Emb_18ABC' : 'Run2018',
'Emb_18D' : 'Run2018',
'MC_Phase2_110X' : 'Phase2',
'MC_Phase2_111X' : 'Phase2',
'MC_UL18': 'Run2018',
'MC_UL17': 'Run2017',
'MC_UL16': 'Run2016',
'MC_UL16APV': 'Run2016',
}

globalTagMap = { 'MC_16' : '102X_mcRun2_asymptotic_v7',
Expand All @@ -33,14 +36,17 @@
'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',
'Emb_18ABC' : '102X_dataRun2_v12',
'Emb_18D' : '102X_dataRun2_Prompt_v15',
'MC_Phase2_110X' : '110X_mcRun4_realistic_v3',
'MC_Phase2_111X' : 'auto:phase2_realistic_T15',
'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):
Expand Down Expand Up @@ -73,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:
Expand Down
11 changes: 9 additions & 2 deletions Production/src/TauJet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -305,6 +305,13 @@ void TauJetBuilder::Build()
tauJets_ = prunedTauJets;
}

if(useBoostedTauFilter_){
std::deque<TauJet> boostedTauJets;
for(const TauJet& tauJet: tauJets_){
if (tauJet.boostedTau) boostedTauJets.push_back(tauJet);
}
tauJets_ = boostedTauJets;
}

for(TauJet& tauJet : tauJets_) {

Expand Down