Skip to content

Commit

Permalink
Merge pull request #71 from mbluj/CMSSW_9_4_X_tauIdForMiniAODv2
Browse files Browse the repository at this point in the history
Modified MVAIso tau-id 2017v1 for miniAODv2 with 94X (X>3)
  • Loading branch information
roger-wolf authored Jan 26, 2018
2 parents 743dc14 + e8f62d5 commit 3f87478
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 8 deletions.
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 Down
4 changes: 4 additions & 0 deletions PhysicsTools/PatAlgos/python/slimming/miniAOD_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ def miniAOD_customizeCommon(process):
from RecoTauTag.Configuration.boostedHPSPFTaus_cfi import addBoostedTaus
addBoostedTaus(process)
#---------------------------------------------------------------------------
#Modify taus by adding MVAIso tau-Ids with 2017v1 training for 94X MiniAODv2
from RecoTauTag.Configuration.updateHPSPFTaus import cloneAndModifyMVAIsolationFor94XMiniAODv2
cloneAndModifyMVAIsolationFor94XMiniAODv2(process)
#---------------------------------------------------------------------------
#Adding tau reco for 80X legacy reMiniAOD
#make a copy of makePatTauTask to avoid labels and substitution problems
_makePatTausTaskWithTauReReco = process.makePatTausTask.copy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
'tauIdMVAIsoDBoldDMwLT2016' : "tauIdMVAIsoDBoldDMwLT2016",
'tauIdMVAIsoDBnewDMwLT2016' : "tauIdMVAIsoDBnewDMwLT2016"
}
tauIdDiscrMVA_trainings_run2_2017 = {
'tauIdMVAIsoDBoldDMwLT2017' : "tauIdMVAIsoDBoldDMwLT2017",
}
tauIdDiscrMVA_WPs = {
'tauIdMVAoldDMwoLT' : {
'Eff90' : "oldDMwoLTEff90",
Expand Down Expand Up @@ -141,6 +144,17 @@
'Eff40' : "DBnewDMwLT2016Eff40"
}
}
tauIdDiscrMVA_WPs_run2_2017 = {
'tauIdMVAIsoDBoldDMwLT2017' : {
'Eff95' : "DBoldDMwLTEff95",
'Eff90' : "DBoldDMwLTEff90",
'Eff80' : "DBoldDMwLTEff80",
'Eff70' : "DBoldDMwLTEff70",
'Eff60' : "DBoldDMwLTEff60",
'Eff50' : "DBoldDMwLTEff50",
'Eff40' : "DBoldDMwLTEff40"
}
}
tauIdDiscrMVA_mvaOutput_normalizations = {
'tauIdMVAoldDMwoLT' : "mvaOutput_normalization_oldDMwoLT",
'tauIdMVAoldDMwLT' : "mvaOutput_normalization_oldDMwLT",
Expand All @@ -159,6 +173,9 @@
'tauIdMVAIsoDBoldDMwLT2016' : "mvaOutput_normalization_DBoldDMwLT2016",
'tauIdMVAIsoDBnewDMwLT2016' : "mvaOutput_normalization_DBnewDMwLT2016"
}
tauIdDiscrMVA_mvaOutput_normalizations_run2_2017 = {
'tauIdMVAIsoDBoldDMwLT2017' : "mvaOutput_normalization"
}
tauIdDiscrMVA_version = "v1"
for training, gbrForestName in tauIdDiscrMVA_trainings.items():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
Expand Down Expand Up @@ -229,7 +246,32 @@
label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_version))
)
)
tauIdDiscrMVA_2017_version = "v1"
for training, gbrForestName in tauIdDiscrMVA_trainings_run2_2017.items():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('GBRWrapperRcd'),
tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, tauIdDiscrMVA_2017_version)),
label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, tauIdDiscrMVA_2017_version))
)
)
for WP in tauIdDiscrMVA_WPs_run2_2017[training].keys():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('PhysicsTGraphPayloadRcd'),
tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, tauIdDiscrMVA_2017_version, WP)),
label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, tauIdDiscrMVA_2017_version, WP))
)
)
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('PhysicsTFormulaPayloadRcd'),
tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_2017_version)),
label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_2017_version))
)
)

####
# register anti-electron discriminator MVA
antiElectronDiscrMVA5_categories = {
'0' : "gbr_NoEleMatch_woGwoGSF_BL",
Expand Down
53 changes: 53 additions & 0 deletions RecoTauTag/Configuration/python/updateHPSPFTaus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import FWCore.ParameterSet.Config as cms

'''
Tools to update tau configuration for special runs like re-MiniAOD production
'''

# Update MVAIso tau-Id for MiniAODv2 production with CMSSW_9_4_X (X>3)
def cloneAndModifyMVAIsolationFor94XMiniAODv2(process):
process.load("RecoTauTag.Configuration.RecoPFTauTag_cff")
##Clone and modify modules of interest
process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTrawMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTraw.clone(
mvaName = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1"),
mvaOpt = cms.string("DBoldDMwLTwGJ")
)
process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLT.clone(
mvaOutput_normalization = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_mvaOutput_normalization"),
key = cms.InputTag("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTrawMVAIsoFor94XMiniv2","category"),
toMultiplex = cms.InputTag("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTrawMVAIsoFor94XMiniv2")
)
process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff90")
process.hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff95")
process.hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff80")
process.hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff70")
process.hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff60")
process.hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff50")
process.hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2 = process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.clone()
process.hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2.mapping[0].cut = cms.string("RecoTauTag_tauIdMVAIsoDBoldDMwLT2017v1_WPEff40")
#create a new task and put the moduled therin
process.hpsPFTauMVAIsoFor94XMiniv2Task = cms.Task()
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTrawMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
process.hpsPFTauMVAIsoFor94XMiniv2Task.add(process.hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2)
#Add all this to makePatTausTask
process.makePatTausTask.add(process.hpsPFTauMVAIsoFor94XMiniv2Task)
#Now modify patTau by replacing old by new discriminats
process.patTaus.tauIDSources.byIsolationMVArun2v1DBoldDMwLTraw = cms.InputTag("hpsPFTauDiscriminationByIsolationMVArun2v1DBoldDMwLTrawMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byVVLooseIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byVLooseIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byLooseIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByLooseIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byMediumIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByMediumIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byTightIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byVTightIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")
process.patTaus.tauIDSources.byVVTightIsolationMVArun2v1DBoldDMwLT = cms.InputTag("hpsPFTauDiscriminationByVVTightIsolationMVArun2v1DBoldDMwLTMVAIsoFor94XMiniv2")

0 comments on commit 3f87478

Please sign in to comment.