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

Developments to provide facilitated access to new TauID information (all high level changes) #18244

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dd670c7
Merge branch 'from-CMSSW_9_0_X_2017-02-22-2300' into CMSSW_9_0_X_tau-pog
roger-wolf Feb 24, 2017
229164f
Access to new MVA tauID trainings on full 2016 dataset + internal tes…
roger-wolf Feb 24, 2017
f9ea9d1
workaround by Anne-Catherine that allows manual track extrapolation t…
roger-wolf Feb 24, 2017
ca50fe2
enable re-embedding of new tauID info into an updated patTau object, …
roger-wolf Feb 24, 2017
fb09f6f
adding missing config to Reco cfi
roger-wolf Feb 24, 2017
0432ec5
adding missing file
roger-wolf Feb 24, 2017
f4d6d29
Merge branch 'from-CMSSW_9_0_X_2017-02-26-2300' into CMSSW_9_0_X_tau-pog
roger-wolf Mar 1, 2017
d550ac3
Merge branch 'CMSSW_9_0_X_tau-pog' into CMSSW_9_0_X_tau-pog_miniAOD-t…
roger-wolf Mar 1, 2017
54a1132
Merge branch 'CMSSW_9_0_X_tau-pog_miniAOD-tauMVAs' into CMSSW_9_1_X_t…
roger-wolf Mar 31, 2017
8917638
repairing the validation of minAOD branching by correct use of TFileS…
roger-wolf Apr 6, 2017
247debd
addressing requests and comment by RECO from last time this PR was made
roger-wolf Apr 6, 2017
7a2c1c4
removing whitespace
roger-wolf Apr 6, 2017
15c4358
Following requests by RECO
roger-wolf Apr 20, 2017
9b6b1f0
Merge branch 'from-CMSSW_9_1_X_2017-04-13-2300' into CMSSW_9_1_X_tau-…
roger-wolf Apr 20, 2017
9c34513
updating relval files to files which have not been deleted...
roger-wolf Apr 20, 2017
2ab25a0
moved plugin to PatAlgos on request by RECO
roger-wolf Apr 20, 2017
6423448
moved plugin to PatAlgos on request by RECO
roger-wolf Apr 20, 2017
bce6857
removing parameter w/o single use case -- cleanup requiested by RECO
roger-wolf Apr 20, 2017
b966f95
plus removing the obsolete existsAs...
roger-wolf Apr 20, 2017
b6bfaa5
Merge branch 'from-CMSSW_9_1_X_2017-04-24-1100' into CMSSW_9_1_X_tau-…
roger-wolf Apr 24, 2017
923271e
logic fixes - pickup Bfield from EventSetup instead of hard-coding...…
roger-wolf Apr 24, 2017
48fa4c5
moving readout of EventRecord for B-field from plugins to class AntiE…
roger-wolf Apr 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DataFormats/PatCandidates/src/classes_def_objects.xml
Expand Up @@ -550,6 +550,7 @@

<class name="std::pair<pat::TauRef, float>"/>
<class name="std::vector<std::pair<pat::TauRef, float> >" />
<class name="edm::RefProd<std::vector<pat::Tau> >"/>

</selection>
<exclusion>
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/PatCandidates/src/classes_objects.h
Expand Up @@ -190,7 +190,8 @@ namespace DataFormats_PatCandidates {
edm::Wrapper<pat::PATTauDiscriminator> pattdiscr_w;

std::pair<pat::TauRef, float> pattdiscr_p;
std::vector<std::pair<pat::TauRef, float> > pattdiscr_v;
std::vector<std::pair<pat::TauRef, float> > pattdiscr_v;
edm::RefProd<std::vector<pat::Tau> > patt_rp;
};

}
83 changes: 83 additions & 0 deletions PhysicsTools/PatAlgos/plugins/PATTauIDEmbedder.cc
@@ -0,0 +1,83 @@
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/PatCandidates/interface/PATTauDiscriminator.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "FWCore/Utilities/interface/transform.h"

class PATTauIDEmbedder : public edm::stream::EDProducer<>
{
public:

explicit PATTauIDEmbedder(const edm::ParameterSet&);
~PATTauIDEmbedder(){};

void produce(edm::Event&, const edm::EventSetup&);

private:

//--- configuration parameters
edm::EDGetTokenT<pat::TauCollection> src_;
typedef std::pair<std::string, edm::InputTag> NameTag;
std::vector<NameTag> tauIDSrcs_;
std::vector<edm::EDGetTokenT<pat::PATTauDiscriminator> > patTauIDTokens_;
};

PATTauIDEmbedder::PATTauIDEmbedder(const edm::ParameterSet& cfg)
{
src_ = consumes<pat::TauCollection>(cfg.getParameter<edm::InputTag>("src"));
// read the different tau ID names
edm::ParameterSet idps = cfg.getParameter<edm::ParameterSet>("tauIDSources");
std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
}
// but in any case at least once
if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
"PATTauProducer: id addTauID is true, you must specify:\n" <<
"\tPSet tauIDSources = { \n" <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
"\t}\n";
patTauIDTokens_ = edm::vector_transform(tauIDSrcs_, [this](NameTag const & tag){return mayConsume<pat::PATTauDiscriminator>(tag.second);});

produces<std::vector<pat::Tau> >();
}

void PATTauIDEmbedder::produce(edm::Event& evt, const edm::EventSetup& es)
{
edm::Handle<pat::TauCollection> inputTaus;
evt.getByToken(src_, inputTaus);

auto outputTaus = std::make_unique<std::vector<pat::Tau> >();
outputTaus->reserve(inputTaus->size());

int tau_idx = 0;
for(pat::TauCollection::const_iterator inputTau = inputTaus->begin(); inputTau != inputTaus->end(); ++inputTau, ++tau_idx){
pat::Tau outputTau(*inputTau);
pat::TauRef inputTauRef(inputTaus, tau_idx);
size_t nTauIds = inputTau->tauIDs().size();
std::vector<pat::Tau::IdPair> tauIds(nTauIds+tauIDSrcs_.size());

for(size_t i = 0; i < nTauIds; ++i){
tauIds[i] = inputTau->tauIDs().at(i);
}

edm::Handle<pat::PATTauDiscriminator> tauDiscr;
for(size_t i = 0; i < tauIDSrcs_.size(); ++i){
evt.getByToken(patTauIDTokens_[i], tauDiscr);
tauIds[nTauIds+i].first = tauIDSrcs_[i].first;
tauIds[nTauIds+i].second = (*tauDiscr)[inputTauRef];
}

outputTau.setTauIDs(tauIds);
outputTaus->push_back(outputTau);
}

evt.put(std::move(outputTaus));
}

#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(PATTauIDEmbedder);
22 changes: 5 additions & 17 deletions PhysicsTools/PatAlgos/plugins/PATTauProducer.cc
Expand Up @@ -72,27 +72,15 @@ PATTauProducer::PATTauProducer(const edm::ParameterSet & iConfig):
// tau ID configurables
addTauID_ = iConfig.getParameter<bool>( "addTauID" );
if ( addTauID_ ) {
// it might be a single tau ID
if (iConfig.existsAs<edm::InputTag>("tauIDSource")) {
tauIDSrcs_.push_back(NameTag("", iConfig.getParameter<edm::InputTag>("tauIDSource")));
}
// or there might be many of them
if (iConfig.existsAs<edm::ParameterSet>("tauIDSources")) {
// please don't configure me twice
if (!tauIDSrcs_.empty()){
throw cms::Exception("Configuration") << "PATTauProducer: you can't specify both 'tauIDSource' and 'tauIDSources'\n";
}
// read the different tau ID names
edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
}
// read the different tau ID names
edm::ParameterSet idps = iConfig.getParameter<edm::ParameterSet>("tauIDSources");
std::vector<std::string> names = idps.getParameterNamesForType<edm::InputTag>();
for (std::vector<std::string>::const_iterator it = names.begin(), ed = names.end(); it != ed; ++it) {
tauIDSrcs_.push_back(NameTag(*it, idps.getParameter<edm::InputTag>(*it)));
}
// but in any case at least once
if (tauIDSrcs_.empty()) throw cms::Exception("Configuration") <<
"PATTauProducer: id addTauID is true, you must specify either:\n" <<
"\tInputTag tauIDSource = <someTag>\n" << "or\n" <<
"\tPSet tauIDSources = { \n" <<
"\t\tInputTag <someName> = <someTag> // as many as you want \n " <<
"\t}\n";
Expand Down
Expand Up @@ -35,6 +35,10 @@
'tauIdMVADBdR03oldDMwLT' : "tauIdMVADBdR03oldDMwLT",
'tauIdMVAPWdR03oldDMwLT' : "tauIdMVAPWdR03oldDMwLT"
}
tauIdDiscrMVA_trainings_run2_2016 = {
'tauIdMVAIsoDBoldDMwLT2016' : "tauIdMVAIsoDBoldDMwLT2016",
'tauIdMVAIsoDBnewDMwLT2016' : "tauIdMVAIsoDBnewDMwLT2016"
}
tauIdDiscrMVA_WPs = {
'tauIdMVAoldDMwoLT' : {
'Eff90' : "oldDMwoLTEff90",
Expand Down Expand Up @@ -119,6 +123,24 @@
'Eff40' : "PWdR03oldDMwLTEff40"
}
}
tauIdDiscrMVA_WPs_run2_2016 = {
'tauIdMVAIsoDBoldDMwLT2016' : {
'Eff90' : "DBoldDMwLT2016Eff90",
'Eff80' : "DBoldDMwLT2016Eff80",
'Eff70' : "DBoldDMwLT2016Eff70",
'Eff60' : "DBoldDMwLT2016Eff60",
'Eff50' : "DBoldDMwLT2016Eff50",
'Eff40' : "DBoldDMwLT2016Eff40"
},
'tauIdMVAIsoDBnewDMwLT2016' : {
'Eff90' : "DBnewDMwLT2016Eff90",
'Eff80' : "DBnewDMwLT2016Eff80",
'Eff70' : "DBnewDMwLT2016Eff70",
'Eff60' : "DBnewDMwLT2016Eff60",
'Eff50' : "DBnewDMwLT2016Eff50",
'Eff40' : "DBnewDMwLT2016Eff40"
}
}
tauIdDiscrMVA_mvaOutput_normalizations = {
'tauIdMVAoldDMwoLT' : "mvaOutput_normalization_oldDMwoLT",
'tauIdMVAoldDMwLT' : "mvaOutput_normalization_oldDMwLT",
Expand All @@ -133,6 +155,10 @@
'tauIdMVADBdR03oldDMwLT' : "mvaOutput_normalization_DBdR03oldDMwLT",
'tauIdMVAPWdR03oldDMwLT' : "mvaOutput_normalization_PWdR03oldDMwLT"
}
tauIdDiscrMVA_mvaOutput_normalizations_run2_2016 = {
'tauIdMVAIsoDBoldDMwLT2016' : "mvaOutput_normalization_DBoldDMwLT2016",
'tauIdMVAIsoDBnewDMwLT2016' : "mvaOutput_normalization_DBnewDMwLT2016"
}
tauIdDiscrMVA_version = "v1"
for training, gbrForestName in tauIdDiscrMVA_trainings.items():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
Expand Down Expand Up @@ -180,6 +206,29 @@
label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_version))
)
)
for training, gbrForestName in tauIdDiscrMVA_trainings_run2_2016.items():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('GBRWrapperRcd'),
tag = cms.string("RecoTauTag_%s%s" % (gbrForestName, tauIdDiscrMVA_version)),
label = cms.untracked.string("RecoTauTag_%s%s" % (gbrForestName, tauIdDiscrMVA_version))
)
)
for WP in tauIdDiscrMVA_WPs_run2_2016[training].keys():
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('PhysicsTGraphPayloadRcd'),
tag = cms.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, tauIdDiscrMVA_version, WP)),
label = cms.untracked.string("RecoTauTag_%s%s_WP%s" % (gbrForestName, tauIdDiscrMVA_version, WP))
)
)
loadRecoTauTagMVAsFromPrepDB.toGet.append(
cms.PSet(
record = cms.string('PhysicsTFormulaPayloadRcd'),
tag = cms.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_version)),
label = cms.untracked.string("RecoTauTag_%s%s_mvaOutput_normalization" % (gbrForestName, tauIdDiscrMVA_version))
)
)

# register anti-electron discriminator MVA
antiElectronDiscrMVA5_categories = {
Expand Down
3 changes: 1 addition & 2 deletions RecoTauTag/Configuration/test/ZTT-validation.txt
@@ -1,2 +1 @@
/store/relval/CMSSW_9_0_0_pre4/RelValTTbar_13/GEN-SIM-RECO/PUpmx25ns_90X_mcRun2_asymptotic_v1-v1/10000/5C714DBC-65EE-E611-BCFB-0CC47A78A426.root
/store/relval/CMSSW_9_0_0_pre4/RelValTTbar_13/GEN-SIM-RECO/PUpmx25ns_90X_mcRun2_asymptotic_v1-v1/10000/A40BB4B4-65EE-E611-A3C2-0CC47A7C3412.root
/store/relval/CMSSW_8_0_0/RelValTTbar_13/GEN-SIM-RECO/PU25ns_80X_mcRun2_asymptotic_v4-v1/10000/42D6DF66-9DDA-E511-9200-0CC47A4D7670.root
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it still meaningful to set input EDM files from CMSSW_8_0_0 (it looks like going backwards)?
IIUC, this file (RecoTauTag/Configuration/test/ZTT-validation.txt) is used in some private validation testing.
So, I just need a confirmation that this is not made by some mistake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Slava,

i can confirm that the change of files is correct. This is the test file that is still used in PatAlgos/test/. Since I do not want to maintain after vanishing relval files over and over again I moved to this more persistent solution for the time being.

Cheers,
Roger

2 changes: 2 additions & 0 deletions RecoTauTag/RecoTau/BuildFile.xml
Expand Up @@ -24,6 +24,8 @@
<use name="TrackingTools/TrackAssociator"/>
<use name="PhysicsTools/JetMCUtils"/>
<use name="CommonTools/Utils"/>
<use name="FastSimulation/BaseParticlePropagator"/>
<use name="FastSimulation/Particle"/>
<use name="roottmva"/>
<export>
<lib name="1"/>
Expand Down
18 changes: 12 additions & 6 deletions RecoTauTag/RecoTau/interface/AntiElectronIDMVA6.h
Expand Up @@ -22,7 +22,10 @@
#include "CondFormats/EgammaObjects/interface/GBRForest.h"
#include "DataFormats/PatCandidates/interface/Tau.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
//#include "DataFormats/Candidate/interface/Candidate.h"

#include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h"
#include "FastSimulation/Particle/interface/RawParticle.h"
#include "DataFormats/PatCandidates/interface/PackedCandidate.h"

#include "TMVA/Tools.h"
#include "TMVA/Reader.h"
Expand Down Expand Up @@ -120,16 +123,18 @@ class AntiElectronIDMVA6

// this function can be called for all categories
double MVAValue(const reco::PFTau& thePFTau,
const reco::GsfElectron& theGsfEle);
const reco::GsfElectron& theGsfEle, bool usePhiAtEcalEntranceExtrapolation);
// this function can be called for category 1 only !!
double MVAValue(const reco::PFTau& thePFTau);
double MVAValue(const reco::PFTau& thePFTau, bool usePhiAtEcalEntranceExtrapolation);

// this function can be called for all categories
double MVAValue(const pat::Tau& theTau,
const pat::Electron& theEle);
const pat::Electron& theEle, bool usePhiAtEcalEntranceExtrapolation);
// this function can be called for category 1 only !!
double MVAValue(const pat::Tau& theTau);

double MVAValue(const pat::Tau& theTau, bool usePhiAtEcalEntranceExtrapolation);
// track extrapolation to ECAL entrance (used to re-calculate varibales that might not be available on miniAOD)
bool atECalEntrance(const reco::Candidate* part, math::XYZPoint &pos);

private:

double dCrackEta(double eta);
Expand Down Expand Up @@ -169,6 +174,7 @@ class AntiElectronIDMVA6

std::vector<TFile*> inputFilesToDelete_;

double bField_;
int verbosity_;
};

Expand Down
Expand Up @@ -31,6 +31,7 @@ class PATTauDiscriminationAgainstElectronMVA6 : public PATTauDiscriminationProdu
{
mva_ = std::make_unique<AntiElectronIDMVA6>(cfg);

usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter<bool>("usePhiAtEcalEntranceExtrapolation");
srcElectrons = cfg.getParameter<edm::InputTag>("srcElectrons");
electronToken = consumes<pat::ElectronCollection>(srcElectrons);
verbosity_ = ( cfg.exists("verbosity") ) ?
Expand Down Expand Up @@ -60,6 +61,7 @@ class PATTauDiscriminationAgainstElectronMVA6 : public PATTauDiscriminationProdu
edm::Handle<TauCollection> taus_;

std::unique_ptr<PATTauDiscriminator> category_output_;
bool usePhiAtEcalEntranceExtrapolation_;

int verbosity_;
};
Expand Down Expand Up @@ -102,7 +104,7 @@ double PATTauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTa
double deltaREleTau = deltaR(theElectron.p4(), theTauRef->p4());
deltaRDummy = deltaREleTau;
if( deltaREleTau < 0.3 ){
double mva_match = mva_->MVAValue(*theTauRef, theElectron);
double mva_match = mva_->MVAValue(*theTauRef, theElectron, usePhiAtEcalEntranceExtrapolation_);
bool hasGsfTrack = 0;
pat::PackedCandidate const* packedLeadTauCand = dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
if( abs(packedLeadTauCand->pdgId()) == 11 )
Expand Down Expand Up @@ -140,7 +142,7 @@ double PATTauDiscriminationAgainstElectronMVA6::discriminate(const TauRef& theTa
} // end of loop over electrons

if ( !isGsfElectronMatched ) {
mvaValue = mva_->MVAValue(*theTauRef);
mvaValue = mva_->MVAValue(*theTauRef, usePhiAtEcalEntranceExtrapolation_);
bool hasGsfTrack = 0;
pat::PackedCandidate const* packedLeadTauCand = dynamic_cast<pat::PackedCandidate const*>(theTauRef->leadChargedHadrCand().get());
if( abs(packedLeadTauCand->pdgId()) == 11 ) hasGsfTrack = 1;
Expand Down
Expand Up @@ -15,7 +15,6 @@
// - TauPFEssential
// - PFRecoTauDiscriminationByMVAIsolationRun2
// - Training of BDT
// todo 2: do we need/want to add PATTauIDEmbedder?

#include "RecoTauTag/RecoTau/interface/TauDiscriminationProducerBase.h"

Expand Down
Expand Up @@ -34,6 +34,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA6 : public PFTauDiscriminationPro
{
mva_ = new AntiElectronIDMVA6(cfg);

usePhiAtEcalEntranceExtrapolation_ = cfg.getParameter<bool>("usePhiAtEcalEntranceExtrapolation");
srcGsfElectrons_ = cfg.getParameter<edm::InputTag>("srcGsfElectrons");
GsfElectrons_token = consumes<reco::GsfElectronCollection>(srcGsfElectrons_);

Expand Down Expand Up @@ -69,6 +70,7 @@ class PFRecoTauDiscriminationAgainstElectronMVA6 : public PFTauDiscriminationPro
edm::Handle<TauCollection> taus_;

std::unique_ptr<PFTauDiscriminator> category_output_;
bool usePhiAtEcalEntranceExtrapolation_;

int verbosity_;
};
Expand Down Expand Up @@ -147,7 +149,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef&
double deltaREleTau = deltaR(theGsfElectron->p4(), thePFTauRef->p4());
deltaRDummy = deltaREleTau;
if ( deltaREleTau < 0.3 ) {
double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron);
double mva_match = mva_->MVAValue(*thePFTauRef, *theGsfElectron, usePhiAtEcalEntranceExtrapolation_);
bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();
if ( !hasGsfTrack )
hasGsfTrack = theGsfElectron->gsfTrack().isNonnull();
Expand Down Expand Up @@ -184,7 +186,7 @@ double PFRecoTauDiscriminationAgainstElectronMVA6::discriminate(const PFTauRef&
} // end of loop over electrons

if ( !isGsfElectronMatched ) {
mvaValue = mva_->MVAValue(*thePFTauRef);
mvaValue = mva_->MVAValue(*thePFTauRef, usePhiAtEcalEntranceExtrapolation_);
bool hasGsfTrack = thePFTauRef->leadPFChargedHadrCand()->gsfTrackRef().isNonnull();

//// Veto taus that go to Ecal crack
Expand Down
Expand Up @@ -33,5 +33,6 @@
minMVAWOgWgsfEC = cms.double(0.0),
minMVAWgWgsfEC = cms.double(0.0),

srcElectrons = cms.InputTag('slimmedElectrons')
srcElectrons = cms.InputTag('slimmedElectrons'),
usePhiAtEcalEntranceExtrapolation = cms.bool(False)
)
Expand Up @@ -34,5 +34,6 @@
minMVAWOgWgsfEC = cms.double(0.0),
minMVAWgWgsfEC = cms.double(0.0),

srcGsfElectrons = cms.InputTag('gedGsfElectrons')
srcGsfElectrons = cms.InputTag('gedGsfElectrons'),
usePhiAtEcalEntranceExtrapolation = cms.bool(False)
)