Skip to content

Commit

Permalink
Merge pull request #21977 from cms-tau-pog/CMSSW_9_4_X_tau-pog_newTau…
Browse files Browse the repository at this point in the history
…ID-MCv1

New trainings for mvaTauID + one backport from CMSSW_10_0_X
  • Loading branch information
cmsbuild authored Mar 5, 2018
2 parents b3a4506 + e30e6ef commit 7c9aed8
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FWCore.ParameterSet.Config as cms

run2_miniAOD_94XFall17 = cms.Modifier()
2 changes: 1 addition & 1 deletion Configuration/StandardSequences/python/Eras.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
'phase2_hgcal', 'phase2_muon', 'phase2_timing',
'phase2_timing_layer','phase2_hcal',
'trackingLowPU', 'trackingPhase1', 'trackingPhase1QuadProp', 'ctpps_2016', 'trackingPhase2PU140',
'tracker_apv_vfp30_2016', 'run2_miniAOD_80XLegacy', 'run2_nanoAOD_92X',
'tracker_apv_vfp30_2016', 'run2_miniAOD_80XLegacy', 'run2_miniAOD_94XFall17', 'run2_nanoAOD_92X',
'hcalHardcodeConditions', 'hcalSkipPacker']
internalUseModChains = ['run2_2017_noTrackingModifier']

Expand Down
31 changes: 28 additions & 3 deletions PhysicsTools/PatAlgos/plugins/PATTauProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ PATTauProducer::PATTauProducer(const edm::ParameterSet & iConfig):
isolator_(iConfig.exists("userIsolation") ? iConfig.getParameter<edm::ParameterSet>("userIsolation") : edm::ParameterSet(), consumesCollector(), false) ,
useUserData_(iConfig.exists("userData"))
{
firstOccurence_=true;
// initialize the configurables
baseTauToken_ = consumes<edm::View<reco::BaseTau> >(iConfig.getParameter<edm::InputTag>( "tauSource" ));
tauTransverseImpactParameterSrc_ = iConfig.getParameter<edm::InputTag>( "tauTransverseImpactParameterSource" );
Expand Down Expand Up @@ -87,6 +88,7 @@ PATTauProducer::PATTauProducer(const edm::ParameterSet & iConfig):
}
caloTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::CaloTauDiscriminator>(tag.second);});
pfTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<reco::PFTauDiscriminator>(tag.second);});
skipMissingTauID_ = iConfig.getParameter<bool>( "skipMissingTauID" );
// IsoDeposit configurables
if (iConfig.exists("isoDeposits")) {
edm::ParameterSet depconf = iConfig.getParameter<edm::ParameterSet>("isoDeposits");
Expand Down Expand Up @@ -305,6 +307,7 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup

// prepare ID extraction
if ( addTauID_ ) {
std::string missingDiscriminators;
std::vector<pat::Tau::IdPair> ids(tauIDSrcs_.size());
for ( size_t i = 0; i < tauIDSrcs_.size(); ++i ) {
if ( typeid(*tausRef) == typeid(reco::PFTau) ) {
Expand All @@ -315,6 +318,13 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
edm::Handle<reco::PFTauDiscriminator> pfTauIdDiscr;
iEvent.getByToken(pfTauIDTokens_[i], pfTauIdDiscr);

if(skipMissingTauID_ && !pfTauIdDiscr.isValid()){
if(!missingDiscriminators.empty()){
missingDiscriminators+=", ";
}
missingDiscriminators+=tauIDSrcs_[i].first;
continue;
}
ids[i].first = tauIDSrcs_[i].first;
ids[i].second = getTauIdDiscriminator(pfTauCollection, idx, pfTauIdDiscr);
} else if ( typeid(*tausRef) == typeid(reco::CaloTau) ) {
Expand All @@ -325,14 +335,27 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
edm::Handle<reco::CaloTauDiscriminator> caloTauIdDiscr;
iEvent.getByToken(caloTauIDTokens_[i], caloTauIdDiscr);

if(skipMissingTauID_ && !caloTauIdDiscr.isValid()){
if(!missingDiscriminators.empty()){
missingDiscriminators+=", ";
}
missingDiscriminators+=tauIDSrcs_[i].first;
continue;
}
ids[i].first = tauIDSrcs_[i].first;
ids[i].second = getTauIdDiscriminator(caloTauCollection, idx, caloTauIdDiscr);
} else {
throw cms::Exception("Type Mismatch") <<
"PATTauProducer: unsupported datatype '" << typeid(*tausRef).name() << "' for tauSource\n";
}
}

if(!missingDiscriminators.empty() && firstOccurence_){
edm::LogWarning("DataSource") << "The following tau discriminators have not been found in the event:\n"
<< missingDiscriminators <<"\n"
<< "They will not be embedded into the pat::Tau object.\n"
<< "Note: this message will be printed only at first occurence.";
firstOccurence_=false;
}
aTau.setTauIDs(ids);
}

Expand Down Expand Up @@ -367,7 +390,7 @@ void PATTauProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup
sumPhiTimesEnergy += icand->positionAtECALEntrance().phi()*icand->energy();
sumEtaTimesEnergy += icand->positionAtECALEntrance().eta()*icand->energy();
sumEnergy += icand->energy();
const reco::Track* track = 0;
const reco::Track* track = nullptr;
if ( icand->trackRef().isNonnull() ) track = icand->trackRef().get();
else if ( icand->muonRef().isNonnull() && icand->muonRef()->innerTrack().isNonnull() ) track = icand->muonRef()->innerTrack().get();
else if ( icand->muonRef().isNonnull() && icand->muonRef()->globalTrack().isNonnull() ) track = icand->muonRef()->globalTrack().get();
Expand Down Expand Up @@ -522,7 +545,9 @@ void PATTauProducer::fillDescriptions(edm::ConfigurationDescriptions & descripti
tauIDSourcesPSet.setAllowAnything();
iDesc.addNode( edm::ParameterDescription<edm::InputTag>("tauIDSource", edm::InputTag(), true) xor
edm::ParameterDescription<edm::ParameterSetDescription>("tauIDSources", tauIDSourcesPSet, true)
)->setComment("input with electron ID variables");
)->setComment("input with tau ID variables");
// (Dis)allow to skip missing tauId sources
iDesc.add<bool>("skipMissingTauID", false)->setComment("allow to skip a tau ID variable when not present in the event");

// IsoDeposit configurables
edm::ParameterSetDescription isoDepositsPSet;
Expand Down
9 changes: 5 additions & 4 deletions PhysicsTools/PatAlgos/plugins/PATTauProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,15 @@ namespace pat {
public:

explicit PATTauProducer(const edm::ParameterSet & iConfig);
~PATTauProducer();
~PATTauProducer() override;

virtual void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;
void produce(edm::Event & iEvent, const edm::EventSetup& iSetup) override;

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);

private:

bool firstOccurence_; // used to print LogWarnings only at first occurnece in the event loop

// configurables
edm::EDGetTokenT<edm::View<reco::BaseTau> > baseTauToken_;
edm::EDGetTokenT<PFTauTIPAssociationByRef> tauTransverseImpactParameterToken_;
Expand Down Expand Up @@ -93,7 +94,7 @@ namespace pat {
std::vector<NameTag> tauIDSrcs_;
std::vector<edm::EDGetTokenT<reco::CaloTauDiscriminator> > caloTauIDTokens_;
std::vector<edm::EDGetTokenT<reco::PFTauDiscriminator> > pfTauIDTokens_;

bool skipMissingTauID_;
// tools
GreaterByPt<Tau> pTTauComparator_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
againstElectronTightMVA6 = cms.InputTag("hpsPFTauDiscriminationByMVA6TightElectronRejection"),
againstElectronVTightMVA6 = cms.InputTag("hpsPFTauDiscriminationByMVA6VTightElectronRejection"),
),

skipMissingTauID = cms.bool(False), #Allow to skip a tau ID variable when not present in the event"
# mc matching configurables
addGenMatch = cms.bool(True),
embedGenMatch = cms.bool(True),
Expand All @@ -151,3 +151,9 @@
resolutions = cms.PSet()
)

from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
for era in [ run2_miniAOD_80XLegacy, run2_miniAOD_94XFall17]:
_extTauIDSources = patTaus.tauIDSources.clone()
_extTauIDSources.byVVLooseIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLT")
era.toModify(patTaus, tauIDSources = _extTauIDSources)
22 changes: 13 additions & 9 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,25 @@ def miniAOD_customizeCommon(process):
for idmod in photon_ids:
setupAllVIDIdsInModule(process,idmod,setupVIDPhotonSelection,None,False,task)

#---------------------------------------------------------------------------
#Adding Boosted Subjets taus
#-- Adding boosted taus
from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
addBoostedTaus(process)
#---------------------------------------------------------------------------
#Adding tau reco for 80X legacy reMiniAOD
#make a copy of makePatTauTask to avoid labels and substitution problems
_makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
#add PFTau reco modules to cloned makePatTauTask
process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
_makePatTausTaskWithTauReReco.add(process.PFTauTask)
#replace original task by extended one for the miniAOD_80XLegacy era
process.load("RecoTauTag.Configuration.HPSPFTaus_cff")
#-- Adding customization for 94X 2017 legacy reMniAOD
from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
_makePatTausTaskWithRetrainedMVATauID = process.makePatTausTask.copy()
_makePatTausTaskWithRetrainedMVATauID.add(process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTTask)
run2_miniAOD_94XFall17.toReplaceWith(
process.makePatTausTask, _makePatTausTaskWithRetrainedMVATauID
)
#-- Adding custimization for 80X 2016 legacy reMiniAOD
from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
_makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
_makePatTausTaskWithTauReReco.add(process.PFTauTask)
run2_miniAOD_80XLegacy.toReplaceWith(
process.makePatTausTask, _makePatTausTaskWithTauReReco)

# Adding puppi jets
if not hasattr(process, 'ak4PFJetsPuppi'): #MM: avoid confilct with substructure call
process.load('RecoJets.JetProducers.ak4PFJetsPuppi_cfi')
Expand Down
8 changes: 8 additions & 0 deletions PhysicsTools/PatAlgos/python/tools/tauTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ def switchToPFTauHPS(process,
if hasattr(process, "cleanPatTaus" + patTauLabel + postfix):
getattr(process, "cleanPatTaus" + patTauLabel + postfix).preselection = preselection

from Configuration.Eras.Modifier_run2_miniAOD_80XLegacy_cff import run2_miniAOD_80XLegacy
from Configuration.Eras.Modifier_run2_miniAOD_94XFall17_cff import run2_miniAOD_94XFall17
for era in [ run2_miniAOD_80XLegacy, run2_miniAOD_94XFall17]:
_patTaus = getattr(process, "patTaus"+patTauLabel+postfix)
_extTauIDSources = _patTaus.tauIDSources.clone()
_extTauIDSources.byVVLooseIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLT")
era.toModify(_patTaus, tauIDSources = _extTauIDSources)

# Select switcher by string
def switchToPFTauByType(process,
pfTauType = None,
Expand Down
Loading

0 comments on commit 7c9aed8

Please sign in to comment.